ukui-app-widget/0000775000175000017500000000000014461714413013043 5ustar adminadminukui-app-widget/man/0000775000175000017500000000000014456706513013624 5ustar adminadminukui-app-widget/man/appwidgetprovider-search-demo.10000664000175000017500000000373314456706513021640 0ustar adminadmin.\" ukui-app-widget manual page .\" .\" This is free software; you may redistribute it and/or modify .\" it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2, .\" or (at your option) any later version. .\" .\" This is distributed in the hope that it will be useful, but .\" WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\"You should have received a copy of the GNU General Public License along .\"with this program; if not, write to the Free Software Foundation, Inc., .\"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. .\" .TH UKUI-APP-WIDGET 1 "05 Apr 2023" "UKUI Desktop Environment" .\" Please adjust this date whenever revising the manpage. .\" .SH "NAME" ukui-app-widget \- The UKUI Desktop for qml .SH "SYNOPSIS" .B ukui-app-widget [OPTIONS] .SH "DESCRIPTION" ukui-app-widget is a qml appwidget framework. It can display a view for quick browsing, which is mainly to display the most important data and functions of the application. .SH "OPTIONS" .TP \fB\-\-display=DISPLAY\fR X display to use. .TP \fB\-\-no\-daemon\fR Don't start as a daemon .TP \fB\-\-debug\fR Enable debugging messages for \fBukui-screensaver\fP .TP \fB\-\-version\fR Output version information and exit. .TP \fB\-h, \-\-help\fR Print standard command line options. .TP \fB\-\-help\-all\fR Print all command line options. .P This program also accepts the standard GTK options. .SH "BUGS" .SS Should you encounter any bugs, they may be reported at: https://gitee.com/openkylin/ukui-app-widget/issues .SH "AUTHORS" .SS ukui-app-widget is maintained by: .nf Yan Wang .fi .SS This Man Page has been updated for the UKUI Desktop Environment by: Yan Wang (2023) .SH "SEE ALSO" .SS Further information may also be available at: http://wiki.ukui-desktop.org/docs .P .BR gtk-options (7) ukui-app-widget/man/appwidgetprovider-clock-demo.10000664000175000017500000000373314456706513021466 0ustar adminadmin.\" ukui-app-widget manual page .\" .\" This is free software; you may redistribute it and/or modify .\" it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2, .\" or (at your option) any later version. .\" .\" This is distributed in the hope that it will be useful, but .\" WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\"You should have received a copy of the GNU General Public License along .\"with this program; if not, write to the Free Software Foundation, Inc., .\"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. .\" .TH UKUI-APP-WIDGET 1 "05 Apr 2023" "UKUI Desktop Environment" .\" Please adjust this date whenever revising the manpage. .\" .SH "NAME" ukui-app-widget \- The UKUI Desktop for qml .SH "SYNOPSIS" .B ukui-app-widget [OPTIONS] .SH "DESCRIPTION" ukui-app-widget is a qml appwidget framework. It can display a view for quick browsing, which is mainly to display the most important data and functions of the application. .SH "OPTIONS" .TP \fB\-\-display=DISPLAY\fR X display to use. .TP \fB\-\-no\-daemon\fR Don't start as a daemon .TP \fB\-\-debug\fR Enable debugging messages for \fBukui-screensaver\fP .TP \fB\-\-version\fR Output version information and exit. .TP \fB\-h, \-\-help\fR Print standard command line options. .TP \fB\-\-help\-all\fR Print all command line options. .P This program also accepts the standard GTK options. .SH "BUGS" .SS Should you encounter any bugs, they may be reported at: https://gitee.com/openkylin/ukui-app-widget/issues .SH "AUTHORS" .SS ukui-app-widget is maintained by: .nf Yan Wang .fi .SS This Man Page has been updated for the UKUI Desktop Environment by: Yan Wang (2023) .SH "SEE ALSO" .SS Further information may also be available at: http://wiki.ukui-desktop.org/docs .P .BR gtk-options (7) ukui-app-widget/man/ukui-appwidget-manager.10000664000175000017500000000373314456706513020263 0ustar adminadmin.\" ukui-app-widget manual page .\" .\" This is free software; you may redistribute it and/or modify .\" it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2, .\" or (at your option) any later version. .\" .\" This is distributed in the hope that it will be useful, but .\" WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\"You should have received a copy of the GNU General Public License along .\"with this program; if not, write to the Free Software Foundation, Inc., .\"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. .\" .TH UKUI-APP-WIDGET 1 "05 Apr 2023" "UKUI Desktop Environment" .\" Please adjust this date whenever revising the manpage. .\" .SH "NAME" ukui-app-widget \- The UKUI Desktop for qml .SH "SYNOPSIS" .B ukui-app-widget [OPTIONS] .SH "DESCRIPTION" ukui-app-widget is a qml appwidget framework. It can display a view for quick browsing, which is mainly to display the most important data and functions of the application. .SH "OPTIONS" .TP \fB\-\-display=DISPLAY\fR X display to use. .TP \fB\-\-no\-daemon\fR Don't start as a daemon .TP \fB\-\-debug\fR Enable debugging messages for \fBukui-screensaver\fP .TP \fB\-\-version\fR Output version information and exit. .TP \fB\-h, \-\-help\fR Print standard command line options. .TP \fB\-\-help\-all\fR Print all command line options. .P This program also accepts the standard GTK options. .SH "BUGS" .SS Should you encounter any bugs, they may be reported at: https://gitee.com/openkylin/ukui-app-widget/issues .SH "AUTHORS" .SS ukui-app-widget is maintained by: .nf Yan Wang .fi .SS This Man Page has been updated for the UKUI Desktop Environment by: Yan Wang (2023) .SH "SEE ALSO" .SS Further information may also be available at: http://wiki.ukui-desktop.org/docs .P .BR gtk-options (7) ukui-app-widget/man/appwidgetuser-demo.10000664000175000017500000000373314456706513017521 0ustar adminadmin.\" ukui-app-widget manual page .\" .\" This is free software; you may redistribute it and/or modify .\" it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2, .\" or (at your option) any later version. .\" .\" This is distributed in the hope that it will be useful, but .\" WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\"You should have received a copy of the GNU General Public License along .\"with this program; if not, write to the Free Software Foundation, Inc., .\"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. .\" .TH UKUI-APP-WIDGET 1 "05 Apr 2023" "UKUI Desktop Environment" .\" Please adjust this date whenever revising the manpage. .\" .SH "NAME" ukui-app-widget \- The UKUI Desktop for qml .SH "SYNOPSIS" .B ukui-app-widget [OPTIONS] .SH "DESCRIPTION" ukui-app-widget is a qml appwidget framework. It can display a view for quick browsing, which is mainly to display the most important data and functions of the application. .SH "OPTIONS" .TP \fB\-\-display=DISPLAY\fR X display to use. .TP \fB\-\-no\-daemon\fR Don't start as a daemon .TP \fB\-\-debug\fR Enable debugging messages for \fBukui-screensaver\fP .TP \fB\-\-version\fR Output version information and exit. .TP \fB\-h, \-\-help\fR Print standard command line options. .TP \fB\-\-help\-all\fR Print all command line options. .P This program also accepts the standard GTK options. .SH "BUGS" .SS Should you encounter any bugs, they may be reported at: https://gitee.com/openkylin/ukui-app-widget/issues .SH "AUTHORS" .SS ukui-app-widget is maintained by: .nf Yan Wang .fi .SS This Man Page has been updated for the UKUI Desktop Environment by: Yan Wang (2023) .SH "SEE ALSO" .SS Further information may also be available at: http://wiki.ukui-desktop.org/docs .P .BR gtk-options (7) ukui-app-widget/man/appwidgetprovider-clock-service.10000664000175000017500000000373314456706513022202 0ustar adminadmin.\" ukui-app-widget manual page .\" .\" This is free software; you may redistribute it and/or modify .\" it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2, .\" or (at your option) any later version. .\" .\" This is distributed in the hope that it will be useful, but .\" WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\"You should have received a copy of the GNU General Public License along .\"with this program; if not, write to the Free Software Foundation, Inc., .\"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. .\" .TH UKUI-APP-WIDGET 1 "05 Apr 2023" "UKUI Desktop Environment" .\" Please adjust this date whenever revising the manpage. .\" .SH "NAME" ukui-app-widget \- The UKUI Desktop for qml .SH "SYNOPSIS" .B ukui-app-widget [OPTIONS] .SH "DESCRIPTION" ukui-app-widget is a qml appwidget framework. It can display a view for quick browsing, which is mainly to display the most important data and functions of the application. .SH "OPTIONS" .TP \fB\-\-display=DISPLAY\fR X display to use. .TP \fB\-\-no\-daemon\fR Don't start as a daemon .TP \fB\-\-debug\fR Enable debugging messages for \fBukui-screensaver\fP .TP \fB\-\-version\fR Output version information and exit. .TP \fB\-h, \-\-help\fR Print standard command line options. .TP \fB\-\-help\-all\fR Print all command line options. .P This program also accepts the standard GTK options. .SH "BUGS" .SS Should you encounter any bugs, they may be reported at: https://gitee.com/openkylin/ukui-app-widget/issues .SH "AUTHORS" .SS ukui-app-widget is maintained by: .nf Yan Wang .fi .SS This Man Page has been updated for the UKUI Desktop Environment by: Yan Wang (2023) .SH "SEE ALSO" .SS Further information may also be available at: http://wiki.ukui-desktop.org/docs .P .BR gtk-options (7) ukui-app-widget/LICENSE0000664000175000017500000010575514461605317014067 0ustar adminadmin GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ukui-app-widget/libukui-appwidget-common/0000775000175000017500000000000014461615267017766 5ustar adminadminukui-app-widget/libukui-appwidget-common/kappwidgetcommon.h0000664000175000017500000000557314461615267023521 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef KAPPWIDGETCOMMON_H #define KAPPWIDGETCOMMON_H #include "libukui-appwidget-common_global.h" #include namespace AppWidget { /** * @defgroup 公共接口模块 */ class LIBUKUIAPPWIDGETCOMMON_EXPORT KAppWidgetCommon : public QObject { Q_OBJECT public: explicit KAppWidgetCommon(QObject *parent = nullptr); /** * @brief 获取Providername的提供端Dbus Object name * @param providername * @return Provider dbus object name */ static QString getProviderDbusObject(const QString &providername); /** * @brief 获取Providername的提供端Dbus Path * @param providername * @return Provider dbus path name */ static QString getProviderDbusPath(const QString &providername); /** * @brief 获取Providername的提供端Dbus Interface * @param providername * @return Provider dbus interface name */ static QString getProviderDbusInterface(const QString &providername); /** * @brief 获取Manager的提供端Dbus Object name * @return Manager dbus object name */ static QString getManagerDbusObject(); /** * @brief 获取Manager的提供端Dbus Path * @return Manager dbus path name */ static QString getManagerDbusPath(); /** * @brief 获取Manager的提供端Dbus Interface * @return Manager dbus interface name */ static QString getManagerDbusInterface(); /** * @brief 获取AppWidget的提供端Dbus Object name * @param username appwidget`id * @return Widget dbus object name */ static QString getAppWidgetDbusObject(const QString &username, const int &id); /** * @brief 获取AppWidget的提供端Dbus Object name * @param username appwidget`id * @return Widget dbus path name */ static QString getAppWidgetDbusPath(const QString &username, const int &id); /** * @brief 获取AppWidget的提供端Dbus Object name * @param username appwidget`id * @return Widget dbus interface name */ static QString getAppWidgetDbusInterface(const QString &username, const int &id); }; }// namespace AppWidget #endif // KAPPWIDGETCOMMON_H ukui-app-widget/libukui-appwidget-common/kappwidgetcommon.cpp0000664000175000017500000000534214461615267024046 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "kappwidgetcommon.h" #include namespace AppWidget { KAppWidgetCommon::KAppWidgetCommon(QObject *parent) : QObject(parent) { } QString KAppWidgetCommon::getProviderDbusObject(const QString &providername) { if(providername.isEmpty()) { qWarning() << "providername isEmpty!"; return QString(); } QString object = QString("org.ukui.appwidget.provider.%1").arg(providername); return object; } QString KAppWidgetCommon::getProviderDbusPath(const QString &providername) { if(providername.isEmpty()) { qWarning() << "providername isEmpty!"; return QString(); } QString objectpath = QString("/org/ukui/appwidget/provider"); return objectpath; } QString KAppWidgetCommon::getProviderDbusInterface(const QString &providername) { if(providername.isEmpty()) { qWarning() << "providername isEmpty!"; return QString(); } QString interface = QString("org.ukui.appwidget.provider.%1").arg(providername); return interface; } QString KAppWidgetCommon::getManagerDbusObject() { QString object = QString("org.ukui.appwidget.manager"); return object; } QString KAppWidgetCommon::getManagerDbusPath() { QString objectpath = QString("/"); return objectpath; } QString KAppWidgetCommon::getManagerDbusInterface() { QString interface = QString("org.ukui.appwidget.manager"); return interface; } QString KAppWidgetCommon::getAppWidgetDbusObject(const QString &username, const int &id) { Q_UNUSED(id); QString object = QString("org.ukui.appwidget.%1").arg(username); return object; } QString KAppWidgetCommon::getAppWidgetDbusPath(const QString &username, const int &id) { Q_UNUSED(username); QString objectpath = QString("/%1").arg(id); return objectpath; } QString KAppWidgetCommon::getAppWidgetDbusInterface(const QString &username, const int &id) { Q_UNUSED(username); Q_UNUSED(id); QString interface = QString("org.ukui.appwidget"); return interface; } }// namespace AppWidget ukui-app-widget/libukui-appwidget-common/libukui-appwidget-common.pri0000664000175000017500000000024614456706513025417 0ustar adminadminINCLUDEPATH += $$PWD SOURCES += \ $$PWD/kappwidgetcommon.cpp HEADERS += \ $$PWD/libukui-appwidget-common_global.h \ $$PWD/kappwidgetcommon.h ukui-app-widget/libukui-appwidget-common/libukui-appwidget-common_global.h0000664000175000017500000000205214461615267026372 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef LIBUKUIAPPWIDGETCOMMON_GLOBAL_H #define LIBUKUIAPPWIDGETCOMMON_GLOBAL_H #include #if defined(LIBUKUIAPPWIDGETCOMMON_LIBRARY) # define LIBUKUIAPPWIDGETCOMMON_EXPORT Q_DECL_EXPORT #else # define LIBUKUIAPPWIDGETCOMMON_EXPORT Q_DECL_IMPORT #endif #endif // LIBUKUIAPPWIDGETCOMMON_GLOBAL_H ukui-app-widget/ukui-appwidget-test/0000775000175000017500000000000014456463654016773 5ustar adminadminukui-app-widget/ukui-appwidget-test/ukui-appwidget-test.pro0000664000175000017500000000017714413425621023417 0ustar adminadminTEMPLATE = subdirs SUBDIRS += \ appwidgetuser-demo \ appwidgetprovider-clock-demo \ appwidgetprovider-search-demo ukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/0000775000175000017500000000000014461605317022566 5ustar adminadminukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/main.qml0000664000175000017500000001031014461605317024220 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ import QtQuick 2.12 import QtQuick.Controls 2.5 import QtQuick.Window 2.12 import QtQuick.Layouts 1.12 ApplicationWindow { id: root visible: true width: screen.width height: screen.height title: qsTr("qmlWindow") property int intervalx: 40 property int intervaly: 20 Rectangle { id: rec1 width: parent.width height: (2*(parent.height))/3 anchors.margins: 10 color: "teal" border.color: "black" ListView { id: listview1 orientation: ListView.Horizontal width: rec1.width-2*intervalx height: rec1.height-2*intervaly anchors.verticalCenter: rec1.verticalCenter model: AppWidgetModel spacing: 20 delegate: Rectangle { id: rectangle1 width: 500 height: 500 color:"transparent" Loader { id: loader anchors.fill: rectangle1 asynchronous: false source: "file://" + appQml onLoaded: { item.register(item.appname, "user"); } } } } } Rectangle { id: rec2 y: (2*(parent.height))/3 width: parent.width height: (parent.height)/3 anchors.margins: 10 border.color: "black" Button { id: but2 x: intervalx y: 2*intervaly text: "Iconlist" onClicked: pop.open() } Popup { id: pop width: rec2.width-2*intervalx height: rec2.height-2*intervaly x: intervalx y: intervaly ListView { orientation: ListView.Horizontal id: listview width: rec2.width-2*intervalx height: rec2.height-2*intervaly model: KListModel spacing: 20 delegate: Rectangle { id: wraper width: 200 height: 200 MouseArea { id: mouse anchors.fill: parent hoverEnabled: true onEntered: { parent.color = "blue" } onExited: { parent.color = "lightblue" } onClicked: { console.log("onclicked" + text1.text) console.log("onclicked" + itemName) AppWidgetModel.insert(text1.text,text1.text) } } Text { id: text1 anchors.bottom: wraper.bottom anchors.horizontalCenter: wraper.horizontalCenter text: itemName Layout.preferredWidth: 120 color: "black" font.pointSize: 15 } Image { id: image1 width: 100 height:100 anchors.centerIn: wraper source: "file://" + itemIcon } } } } } } ukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/qml.qrc0000664000175000017500000000012714413425621024061 0ustar adminadmin main.qml ukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/appwidgetmodel.h0000664000175000017500000000352214461605317025746 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef APPWIDGETMODEL_H #define APPWIDGETMODEL_H #include #include struct LIST_APPWIDGET_ITEM_INFO { QString appItemQml; QString appItemName; }; class AppWidgetModel : public QAbstractListModel { Q_OBJECT public: explicit AppWidgetModel(QObject *parent = nullptr); enum LIST_APPWIDGET_ITEM_ROLE { appWidgetItemQmlRole = Qt::UserRole + 1, appWidgetItemNameRole, }; // Header: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; // Basic functionality: int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; // Add data: Q_INVOKABLE void insert(QString appItemQml, QString appItemName) ; int count() const; QHash roleNames() const override; private: QList m_date; QHash m_roleName; AppWidget::KAppWidgetManager * appwidgetinterface = nullptr; }; #endif // APPWIDGETMODEL_H ukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/main.cpp0000664000175000017500000000311414461605317024215 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include #include #include #include "listmodel.h" #include "appwidgetmodel.h" #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QQmlApplicationEngine engine; ListModel listModel; AppWidgetModel appwidgetModel; engine.rootContext()->setContextProperty("AppWidgetModel", &appwidgetModel); engine.rootContext()->setContextProperty("KListModel", &listModel); QQuickStyle::setStyle("org.ukui.style"); const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); } ukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/appwidgetmodel.cpp0000664000175000017500000000465214461605317026306 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "appwidgetmodel.h" #include AppWidgetModel::AppWidgetModel(QObject *parent) : QAbstractListModel(parent) { m_roleName.insert(appWidgetItemQmlRole, "appQml"); m_roleName.insert(appWidgetItemNameRole, "appName"); appwidgetinterface = new AppWidget::KAppWidgetManager(this); } QVariant AppWidgetModel::headerData(int section, Qt::Orientation orientation, int role) const { // FIXME: Implement me! Q_UNUSED(section); Q_UNUSED(orientation); Q_UNUSED(role); return QVariant(); } int AppWidgetModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; // FIXME: Implement me! return m_date.size(); } QVariant AppWidgetModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); // FIXME: Implement me! switch (role) { case appWidgetItemQmlRole: return m_date.value(index.row()).appItemQml; case appWidgetItemNameRole: return m_date.value(index.row()).appItemName; default: break; } return QVariant(); } QHash AppWidgetModel::roleNames() const { return m_roleName; } int AppWidgetModel::count() const { return rowCount(QModelIndex()); } void AppWidgetModel::insert(QString appItemQml, QString appItemName) { int index = count(); emit beginInsertRows(QModelIndex(), index, index); LIST_APPWIDGET_ITEM_INFO list; qDebug() << __FILE__ << __FUNCTION__ << ": appItemQml = " << appItemQml << ", itemname = " << appItemName; list.appItemQml = appwidgetinterface->getAppWidgetUiFile(appItemQml); list.appItemName = appItemName; m_date.insert(index, list); emit endInsertRows(); } ukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/appwidgetuser-demo.pro0000664000175000017500000000302514461605317027115 0ustar adminadminQT += quick quickcontrols2 widgets core gui qml dbus greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 link_pkgconfig # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Refer to the documentation for the # deprecated API to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ appwidgetmodel.cpp \ listmodel.cpp \ main.cpp \ RESOURCES += qml.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. qnx: target.path = /usr/bin/ else: unix:!android: target.path = /usr/bin/ INSTALLS += target HEADERS += \ appwidgetmodel.h \ listmodel.h #QMAKE_LFLAGS += -Wl,-rpath=$$OUT_PWD/../../libukui-app-widget/libukui-appwidget-manager LIBS += -L$$OUT_PWD/../../libukui-app-widget/libukui-appwidget-manager -lukui-appwidget-manager INCLUDEPATH += $$PWD/../../libukui-app-widget/libukui-appwidget-manager DEPENDPATH += $$PWD/../../libukui-app-widget/libukui-appwidget-manager ukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/listmodel.h0000664000175000017500000000377414461605317024746 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef LISTMODEL_H #define LISTMODEL_H #include struct LIST_ITEM_INFO { QString qsItemIcon; QString qsItemName; }; namespace AppWidget { class KAppWidgetManager; } class ListModel : public QAbstractListModel { Q_OBJECT public: explicit ListModel(QObject *parent = nullptr); enum LIST_ITEM_ROLE { itemIconRole = Qt::UserRole + 1, itemTextRole, }; // Header: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; // Basic functionality: int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; // Add data: Q_INVOKABLE void insert(QString qsItemIcon, QString qsItemName) ; // Remove data: Q_INVOKABLE void remove(int index); int count() const; QHash roleNames() const override; QList getIconAndText(); QStringList getAppWidgetList(); private: QStringList m_applist; QStringList m_iconlist; QStringList m_textlist; QList m_date; QHash m_roleName; AppWidget::KAppWidgetManager * appwidgetinterface = nullptr; }; #endif // LISTMODEL_H ukui-app-widget/ukui-appwidget-test/appwidgetuser-demo/listmodel.cpp0000664000175000017500000000665214461605317025277 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "listmodel.h" #include #include ListModel::ListModel(QObject *parent) : QAbstractListModel(parent) { m_roleName.insert(itemIconRole, "itemIcon"); m_roleName.insert(itemTextRole, "itemName"); appwidgetinterface = new AppWidget::KAppWidgetManager(this); getIconAndText(); } QVariant ListModel::headerData(int section, Qt::Orientation orientation, int role) const { Q_UNUSED(section); Q_UNUSED(orientation); Q_UNUSED(role); // FIXME: Implement me! return QVariant(); } int ListModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; return m_date.size(); } QVariant ListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); switch (role) { case itemIconRole: return m_date.value(index.row()).qsItemIcon; case itemTextRole: return m_date.value(index.row()).qsItemName; default: break; } return QVariant(); } QHash ListModel::roleNames() const { return m_roleName; } void ListModel::insert(QString qsItemIcon, QString qsItemName) { int index = count(); emit beginInsertRows(QModelIndex(), index, index); LIST_ITEM_INFO list; list.qsItemIcon = qsItemIcon; list.qsItemName = qsItemName; m_date.insert(index, list); emit endInsertRows(); } void ListModel::remove(int index) { if(index < 0 || index >= m_date.count()) { return; } beginRemoveRows(QModelIndex(), index, index); m_date.removeAt(index); endRemoveRows(); } int ListModel::count() const { return rowCount(QModelIndex()); } QList ListModel::getIconAndText() { m_applist = getAppWidgetList(); LIST_ITEM_INFO list; for (int var = 0; var < m_applist.count(); var++) { QString appwidgetname = m_applist.at(var); list.qsItemIcon = appwidgetinterface->getAppWidgetConfig(appwidgetname, AppWidget::PREVIEW_PATH); list.qsItemName = appwidgetinterface->getAppWidgetConfig(appwidgetname, AppWidget::NAME); //用于打印查看所有小插件的属性 // QMap a = appwidgetinterface->getAppWidgetConfigs(appwidgetname); // qDebug() << "a" << a.count(); // QMap::const_iterator it = a.constBegin(); // while (it != a.constEnd()) // { // qDebug() << it.key() << ": " << it.value() ; // it++; // } m_date.append(list); } return m_date; } QStringList ListModel::getAppWidgetList() { QStringList list = appwidgetinterface->getAppWidgetList(); qDebug() << __FILE__ << __FUNCTION__ << ": " << list; return list; } ukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/0000775000175000017500000000000014456463654024545 5ustar adminadminukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/0000775000175000017500000000000014461605317033021 5ustar adminadmin././@LongLink0000644000000000000000000000020500000000000011600 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/appwidgetprovider-clock-service.proukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/app0000664000175000017500000000341414456706513033532 0ustar adminadminQT -= gui QT += dbus CONFIG += c++11 console CONFIG -= app_bundle # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ clockprovider.cpp \ main.cpp \ # Default rules for deployment. qnx: target.path = /usr/bin else: unix:!android: target.path = /usr/bin clockservice.files += provider/org.ukui.appwidget.provider.democlock.service clockservice.path += /usr/share/dbus-1/services/ !isEmpty(target.path): INSTALLS += target clockservice HEADERS += \ clockprovider.h \ RESOURCES += \ provider/src.qrc #QMAKE_LFLAGS += -Wl,-rpath=$$OUT_PWD/../../../libukui-app-widget/libukui-appwidget-manager/ #QMAKE_LFLAGS += -Wl,-rpath=$$OUT_PWD/../../../libukui-app-widget/libukui-appwidget-provider/ LIBS += -L$$OUT_PWD/../../../libukui-app-widget/libukui-appwidget-manager -lukui-appwidget-manager LIBS += -L$$OUT_PWD/../../../libukui-app-widget/libukui-appwidget-provider -lukui-appwidget-provider INCLUDEPATH += $$PWD/../../../libukui-app-widget/libukui-appwidget-manager DEPENDPATH += $$PWD/../../../libukui-app-widget/libukui-appwidget-manager INCLUDEPATH += $$PWD/../../../libukui-app-widget/libukui-appwidget-provider DEPENDPATH += $$PWD/../../../libukui-app-widget/libukui-appwidget-provider ././@LongLink0000644000000000000000000000015300000000000011602 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/provider/ukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/pro0000775000175000017500000000000014456706513033546 5ustar adminadmin././@LongLink0000644000000000000000000000023000000000000011576 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/provider/org.ukui.appwidget.provider.democlock.serviceukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/pro0000664000175000017500000000015114456706513033545 0ustar adminadmin[D-BUS Service] Name=org.ukui.appwidget.provider.democlock Exec=/usr/bin/appwidgetprovider-clock-service ././@LongLink0000644000000000000000000000016200000000000011602 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/provider/src.qrcukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/pro0000664000175000017500000000017414456706513033552 0ustar adminadmin org.ukui.appwidget.provider.democlock.service ././@LongLink0000644000000000000000000000016300000000000011603 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/clockprovider.cppukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/clo0000664000175000017500000000556614461605317033535 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "clockprovider.h" #include #include #include #include #include #include ClockProvider::ClockProvider(QString providername ,QObject *parent) : KAppWidgetProvider(providername , parent) { if(manager) { manager = new AppWidget::KAppWidgetManager(this); } } void ClockProvider::appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value) { Q_UNUSED(eventname); Q_UNUSED(widgetname); Q_UNUSED(value); qDebug() << "TestProvider::appWidgetRecevie"; } void ClockProvider::appWidgetUpdate() { qDebug() << "TestProvider::appWidgetUpdate"; QStringList message; QString path = QDir::homePath() + "/.config/appwidgetclock/config.ini"; setting = new QSettings(path, QSettings::IniFormat); dateTime = QDateTime::currentDateTime(); setting->beginGroup("AlarmClock"); QStringList ll = setting->allKeys(); for (int var = 0; var < ll.count(); var++) { message << ll.at(var); } setting->endGroup(); setting->sync(); //需要将传递的消息用QDBusVariant封装,并用QVariant封装传递出去 QVariantMap m; m.insert("date" , dateTime.toString("yyyy-MM-dd")); m.insert("AlarmClock" , message); qDebug() << "QVariantMap:" << m; if(manager) { manager->updateAppWidget("democlock", m); qDebug() << "更新"; } if(setting) { delete setting; } } void ClockProvider::appWidgetDisable() { qDebug() << "TestProvider::appWidgetDisable"; if(manager) { delete manager; } qApp->exit(); } void ClockProvider::appWidgetDeleted() { qDebug() << "TestProvider::appWidgetDeleted"; } void ClockProvider::appWidgetEnable() { qDebug() << "TestProvider::appWidgetEnable"; if(!manager) { manager = new AppWidget::KAppWidgetManager(this); } } void ClockProvider::appWidgetClicked(const QString &widgetname, const QDBusVariant &value) { qDebug() << "TestProvider::appWidgetClicked"; Q_UNUSED(widgetname); Q_UNUSED(value); QProcess::startDetached("appwidgetprovider-clock-demo"); } ././@LongLink0000644000000000000000000000016100000000000011601 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/clockprovider.hukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/clo0000664000175000017500000000317714461605317033531 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef CLOCKPROVIDER_H #define CLOCKPROVIDER_H #include #include #include namespace AppWidget { class KAppWidgetManager; } class QTimer; class QSettings; class QDBusInterface; class ClockProvider:public AppWidget::KAppWidgetProvider { public: ClockProvider(QString providername = "democlock",QObject *parent = nullptr); void appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value); void appWidgetUpdate(); void appWidgetDisable(); void appWidgetDeleted(); void appWidgetEnable(); void appWidgetClicked(const QString &widgetname, const QDBusVariant &value); private: AppWidget::KAppWidgetManager * manager = nullptr; QDBusInterface *searchinterface = nullptr; QVariant m_date; QDateTime dateTime; QTimer *timer; QSettings *setting = nullptr; }; #endif // CLOCKPROVIDER_H ././@LongLink0000644000000000000000000000015200000000000011601 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/main.cppukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-service/mai0000664000175000017500000000162714461605317033520 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include #include "clockprovider.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); ClockProvider p; return a.exec(); } ukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/0000775000175000017500000000000014461605317032305 5ustar adminadmin././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/translations/ukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/transl0000775000175000017500000000000014461605317033531 5ustar adminadmin././@LongLink0000644000000000000000000000017600000000000011607 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/translations/democlock_bo_CN.tsukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/transl0000664000175000017500000000216414461605317033536 0ustar adminadmin MainWindow MainWindow : 设置 设置闹钟: 闹钟记录: ././@LongLink0000644000000000000000000000017600000000000011607 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/translations/democlock_zh_CN.tsukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/transl0000664000175000017500000000216414461605317033536 0ustar adminadmin MainWindow MainWindow : 设置 设置闹钟: 闹钟记录: ././@LongLink0000644000000000000000000000015300000000000011602 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/mainwindow.hukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/mainwi0000664000175000017500000000264414461605317033522 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include #include #include #include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: void on_pushButton_clicked(); void on_pushButton_2_clicked(); private: Ui::MainWindow *ui; QWidget * wid = nullptr; QTimer *timer = nullptr; QSettings * setting = nullptr; QDBusInterface *appwidgetinterface = nullptr; QStandardItemModel * itemmode = nullptr; }; #endif // MAINWINDOW_H ././@LongLink0000644000000000000000000000014600000000000011604 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/src.qrcukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/src.qr0000664000175000017500000000032214456706513033441 0ustar adminadmin config.ini data/democlock.qml data/democlock.png data/democlock.conf ././@LongLink0000644000000000000000000000015100000000000011600 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/config.iniukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/config0000664000175000017500000000001514413425621033464 0ustar adminadmin[AlarmClock] ././@LongLink0000644000000000000000000000014700000000000011605 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/main.cppukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/main.c0000664000175000017500000000216114461605317033375 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "mainwindow.h" #include #include int main(int argc, char *argv[]) { QtSingleApplication a("appwidgetprovider-clock-demo", argc, argv); if(a.isRunning()) { a.sendMessage("raise_window_noop"); return EXIT_SUCCESS; } MainWindow w; a.setActivationWindow(&w);//单例 w.show(); return a.exec(); } ukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/data/0000775000175000017500000000000014461605317033216 5ustar adminadmin././@LongLink0000644000000000000000000000016100000000000011601 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/data/democlock.qmlukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/data/d0000664000175000017500000002240214461605317033364 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ import QtQuick 2.6 import QtQuick.Window 2.2 import org.ukui.appwidget 1.0 AppWidget { id: window //注1:appname必须赋值 appname: "democlock" //注2:小插件的位置应该设置为居中 anchors.centerIn: parent //注3:小插件应考虑在不同缩放以及分辨率下的适配 //可以采用如下方式计算缩放比scalefactor(仅供参考,只要能实现小插件根据父类窗口缩放即可) width: 740 * scalefactor height: 680 * scalefactor property double scalefactor: 1.00 visible: true //注4:clickable为当前小插件是否可以进行操作的标志,当clickable为 false时, //小插件不可点击,不能接收焦点等。该状态的决定由使用端传递并更新 property bool clickable: true property var date : "" property var aclock : "" Canvas { id: canvas anchors.fill: parent width: 740 * scalefactor height: 680 * scalefactor onPaint: { var ctx = getContext("2d"); drawBack(ctx); drawDot(ctx); var date = new Date(); var hours = date.getHours() hours = hours % 12; var minutes = date.getMinutes() var seconds = date.getUTCSeconds(); var timestr = date.toLocaleString("yyyy-MM-dd hh:mm:ss"); drawSecond(seconds, ctx); drawHour(hours, minutes, ctx); drawMinute(minutes, seconds, ctx); drawSecond(seconds, ctx); } Text { id: datetext color: "black" text: qsTr("日期:" + date) anchors.horizontalCenter: parent.horizontalCenter anchors.leftMargin: 1 y : 350 * scalefactor font.pointSize: 12 * scalefactor font.bold: true } Text { id: clocktext color: "black" text: qsTr("日期:" + aclock) wrapMode: Text.WordWrap anchors.horizontalCenter: parent.horizontalCenter anchors.leftMargin: 1 y : 370 * scalefactor font.pointSize: 12 * scalefactor font.bold: true } } MouseArea { id: mousearea anchors.fill: parent //注5:如果使用MouseArea需要注意enabled需要与window.clickable一致 enabled: window.clickable //注6:事件透传,在小插件中部分事件需要透传到使用端处理,如onPressAndHold,其他的暂时未发现需要设置 //如需要实现onClicked,则注意onPressed一定不要透传,否则小插件自身将不能得到点击事件 propagateComposedEvents: true onClicked: { //点击需要进行的跳转 window.qmlclickedsignal("democlock", "clicked"); mouse.accepted = false } //注7:onPressAndHold事件需要透传,否则将不能实现长按进入编辑状态(不能长按进行拖动) onPressAndHold: { mouse.accepted = false } } function drawBack(ctx) { var r = 200 * scalefactor; ctx.save(); ctx.beginPath(); ctx.translate(width / 2,height / 2); ctx.clearRect(-r, -r, r * 2, r * 2); ctx.lineWidth = 10; ctx.arc(0, 0, r - 5, 0, Math.PI * 2, false); //外圆 ctx.stroke(); //画文本 var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; ctx.font = "18px Arial"; ctx.textAlign = "center"; ctx.textBaseline = "middle"; for(var i = 0; i < 12; ++i) { var rad = 2 * Math.PI / 12 * numbers[i] - 3.14 / 2; var x = Math.cos(rad) * (r-30); var y = Math.sin(rad) * (r-30); ctx.fillText(numbers[i], x, y); } //画刻度 ctx.lineWidth = 2; for(var i = 0; i < 60; ++i) { ctx.beginPath(); var rad = 2 * Math.PI / 60 * i; var x = Math.cos(rad) * (r - 15); var y = Math.sin(rad) * (r - 15); var x2 = Math.cos(rad) * (r - 10); var y2 = Math.sin(rad) * (r - 10); //通过画线也可以 if(i%5 === 0) { ctx.strokeStyle = "#000000"; }else { ctx.strokeStyle = "#989898"; } ctx.moveTo(x, y); ctx.lineTo(x2, y2); ctx.stroke(); } ctx.restore(); } function drawHour(hour, minute, ctx) { var r = 200 * scalefactor; ctx.save(); ctx.beginPath(); //必须写 ctx.lineWidth = 7; ctx.lineCap = "round"; ctx.translate(width / 2,height / 2); var rad = Math.PI * 2 / 12 * hour + Math.PI * 2 * minute / 12 / 60 - Math.PI; ctx.rotate(rad); ctx.moveTo(0, -10); ctx.lineTo(0, r / 2 - 10); ctx.stroke(); //必须写(填充方式) ctx.restore(); } function drawMinute(minute, second, ctx) { var r = 200 * scalefactor; ctx.save(); ctx.beginPath(); //必须写 ctx.lineWidth = 5; ctx.lineCap = "round"; ctx.translate(width / 2,height / 2); var rad = Math.PI * 2 * minute / 60 + Math.PI * 2 * second / 60 / 60 - Math.PI; ctx.rotate(rad); ctx.moveTo(0, -10); ctx.lineTo(-10, r * 3 / 5 - 10); ctx.stroke(); //必须写(填充方式) ctx.restore(); } function drawSecond(second, ctx) { var r = 200 * scalefactor; ctx.save(); ctx.beginPath(); //必须写 ctx.lineWidth = 3; ctx.lineCap = "round"; ctx.translate(width / 2, height / 2); ctx.strokeStyle="#ff0000"; var rad = Math.PI * 2 * second / 60 - Math.PI; ctx.rotate(rad); ctx.moveTo(0, -20); ctx.lineTo(0, r * 4 / 5 - 10); ctx.stroke(); //必须写(填充方式) ctx.restore(); } function drawDot(ctx) { ctx.save(); ctx.beginPath(); //必须写 ctx.translate(width / 2, height / 2); ctx.fillStyle = "#ffffff"; ctx.arc(0, 0, 3, 0, Math.PI * 2); ctx.fill(); //必须写(填充方式) ctx.restore(); } Component.onCompleted: { console.log("qml 接收到数据更新信号"); window.update.connect(window.onupdate); //注8:初始化缩放比 initScalefactor() //注9:监听使用端状态改变信号,用于更新clickable userStatusChangedSignal.connect(onUserStatusChanged) } function onupdate() { for (var i in window.datavalue) { var info = window.datavalue[i]; if( i === "date") { console.log("date", info); datetext.text = qsTr("日期:" + info) } if( i === "AlarmClock") { console.log("alarmClock", info); clocktext.text = qsTr("闹钟" + info) } } } //定时器 Timer { interval: 1000; running: true; repeat: true onTriggered: canvas.requestPaint(); } function initScalefactor() { //注10:按宽计算缩放比例,计算在这个比例系数下的小插件宽高,如果高超出父类的高,则更换比例系数的计算方式,按高计算缩放比例 //console.log("父类窗口大小", window.parent.width,window.parent.height); if(window.parent.width == 0 || window.parent.height == 0) { window.scalefactor = 1.0 console.log("父类窗口大小为 0 默认缩放比为1.0") return } //注11:640为默认情况下demosearch的宽度 window.scalefactor = window.parent.width / 740 //console.log("当前比例系数", window.scalefactor); //注12:100为默认情况下demosearch的高度 var tw = window.scalefactor * 740 var th = window.scalefactor * 680 //console.log("大小:", tw,th ,window.height); //注13:当按宽缩放时,父类窗口的高小于小插件缩放后实际的高时则重新以高度计算缩放比 if(th > window.parent.height) { window.scalefactor = window.parent.height / 680 //console.log("以宽度计算比例系数", appwidget.scalefactor); } } function onUserStatusChanged(status) { console.log("qml Appwidget demosearch user status changed ", status); if(status === "Normal") { window.clickable = true; }else if(status === "Editable") { window.clickable = false; } } } ././@LongLink0000644000000000000000000000016100000000000011601 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/data/democlock.pngukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/data/d0000664000175000017500000004473614456706513033406 0ustar adminadminPNG  IHDRL> pHYs+ IDATxy\. , 7,)&hbx`摚)}+ -Kjٷ_g%QZ ʍ(%}-{]Waewχ{w絳s|>(@G !Ð#rrXCab9 9B,!G0!Ð#rrXCab9 9B,!G0!Ð#rrXCab9 9B,!G0!Ð#rrXCab9 @Q__]RRXA]]]U`hhh^(he! p|6---%%%999%%eee*KKAYPWÐwEegg<23vXPHF@!jΝxbQQyN߾}'Lonnr aȵуN:Gi2eܹs5]jCE*++=Z:h .3gkAO`5O"9s&444""B,k .|Wutt4]NO!BCC>Ƶy.\Zz. Puu]~]ӵ_|1i$N(2XOO|}}} bX,DՏ?.//ɹ{nNNNnnn pvv^f͜9sx  Z,`kk $IfeefddiW~뭷| WZw!?bŊ=<|][}.~Ym?]QQѮ]9C.^dɒ'zzz;vPkd+ܓwVee̙3NWpϟҥÇhޙz*[ͧ[}:]dK#F|{H$ 5kV3_;;:::AAAEIڵkjjJJJڡ􂂂]vd2233,Yҁ*BUbܓwIOutt>|{n5uvv[U5wkkV_3wttܳgÇ~Ak- yG<~xڴi+WJ?3!!᧟~QrssskjjT]fTWWx<'''666?SBBkJ}Y``ǏU]iϠիW׮7* ;w䜜5CdvvvJJJswAĔ)Sޕԯ_W}8ЮA,]رc`iiYYYItp'NXti xjEt3vضm[<^^^qqq54?'ʧŵK۷k%t;r$Wn޼Y**$99\7222SNٳѣG,ݻ;8]*nڴ]w^+ C6D;(Ĵj:KP]`ׯ_?pZA_:7&&UyDmw_6O6M-/((hׯ_tرC&ӧGGGkٳ]7644hpmИTVVGFF*0ݴiӺu(JMMUU 李e7ɡï_~ƍJt5 UVV*b~\jժ޽{m3[m==_.w}}+W?V:eLL/u ӦMk.|}}ƌCݽn;˗/߻w D666nnn$___eؕ5vg>^FDYf5666[C}}}llVR<&rvv~*'H_躱NZUo7Gŋ٪ϛ]'Bƍstt *EQ 3fȑ#KMD*~J|x]%ȱիWoܸQ%n*Fj_ ZE~=A\.nFOp8 zBBB|||CCÊ+Y~ׯꪺt5b$ _~eAܼyj3xOg\|6'ݻAk?27nذTCm݈~wСO>|#G>ѣG+W:E;B|ѣӧ ?m~Wgg۷wf%׮]{{K)L?>|pge']oϏАXQQѬ2̙SYY)o)mjj?tc(lHԙ9sLLLMf' .߿رc;Skkq8A'ށݻ|>_(` {{{kkNdذaÇW6KyasH\hQaaaKϳfj9O>]Pj={vHHH-,,ǁ肺 9l۶ԩSuVGC7iҤ[ةS:zzo޼LUV  .* 55ŋ`ժUm.ũ*m5]TVV+m*///))IS5|) TCokrrrb^rE޶ i-L&cXFOO/==AmUix⍢e˖yW1݂w}ǼH$Z|z6=1䑑m^3 R8lAAczu~~N>l߾P(LOOj+O= ~'''$SNu'}'TT+gX%ԦSNݼy('';w2wa%z֞<33Ņy͛W\ yyyэnnn/Rǟux|Æ۠ŭ;ׯ 6oOKKӆGgՌ$fmKZR` dɝ}%)X|~Ri)N4Gu ӃB%D,O< (ڼرc.S}zJțlmm?Kva?Su>0z=%{a{feQzzr]t=Xeee"ݻWeI8$JUPеOcYNnee믿1wLNnǙ(\|/xsSS˟ػw/_bEUU=壏>bo֬,9IWMutt >˹-CtL&{\1X͜!b" d}?aT~m6\9s挦kZl9ImE9Nfff{Wvq mv鎔(Qx3$]v!33ycǪfmKh ̣ϝ;ѱ]댎^lڵk666k mw$$/ӧڽVyΝѣGv` o׮]KHHh݁eвe˘_K:0&iYY3Ç?3FB 7\̞=ٳXT*,o ˗/Wiڅ{rDr!߿۷owxSVVֱ $';ѯXwzlcc[8p=:$H:^vcmϜ9^7렷=('%%P[o~{f@ׯ_oIl2w­[QQµ;Ck.5M]y~Q,,,ƌCoy+W:uq㲳US_prÇ &M0aB'o7.++c1_UUZ!=z4g9}t>[&᪫+i@ c̘1*Y۰ۃbccx뭷T?`„'ЙzY^Li0>Sh!<,,aI8r>;9EZoԩ&&& >|XmŨ CWTF SSSe|O>zԆm]2[ZZ2wG;99v{g| <)&###;;s823335ض'?wC­}}}AuuuRRRNPHJ›:>))E $y}!iğ1Y?|⸸8  d;Cu$ɛ7oȧ̛7a#Yp ړSuE[[[1R8qᒒ4]SA}AK.\u ˪1,jɓߞ-ѐт1͠ynU!v\=}P|Փjj4ZPw5`3,!u; yLL \??6Gv o2YY ..8Lj3gސrU҅ݳo Z6##akkN5g>>_CXOAډ={dC qqq~2LL % ૯_?`ɬ8q@ 7:t(̛SS_|>)Rac {cdbb(yO!Fgvcf8›ǼIdffƒVhuuu |~cc#0۞=ý{`cтL&b|7ڀ%}NN\;;;6'{wc#pmr 0oTK6}C(ggݪٙN$x؀Nb00%;;a!CrrrqxҺ{{m4Z(,''gȐ! K2oTK.0̵pᡖ.* << %@cc+ƍƼQu#,ٓ3&M&IͿpO{P p ,,l۶mOga;ư0kB#9W> [@J \F=zTӕiU΢aĚ=*Ѭ;;1Vs皑={00or0c#&&&FFF;4DpB``X|E,7ܹCߏ0`رc;p滛Yڔ%?כɻ4Vڝ;w/^`6#eBSSӍ7nܸA[֞߸qc}}w.+ŚU6%_X,.--9rdbbb'S O˞w+{{{{xx4Ը'2'|ȹ\$9'E=Fd}}ѯZZZ 3(###cbbDt1Oqywo&!C4޽{BPWWhO(^4W wF2DիWVEݱ]D"IMMyf\\ӧKKK@ $(4γz5|py{AU'Nlذ!>>o;wn{P]]pԔ>/ݱ$֏=zܲUJR - mmm#c+pSuOԿ;///5 gaaCfPVVfeekXr;;g':uSOv} 7E@5^?U899{#Gkwcggǎ&, n%K. RݣG{ 6LU$o߾%66V%kVịk*/3hMybOCsROo>>jM{,Yd˖-UXd*puN:uT(qqqIDN[٦]zzz󨫫p8=c(wQwC~>DEᐔ/Mo@SSSJJ6mSkPW^ya9y T <558p "K/=Q]M>2ёaIKKtaz0I8%==Iw10p [aRqnEsbqVV:fÇwssSw'lU[Zeee1$ʊ ք 0|Bolswsӧ]g̴kOmt5ީOT$UVVv}Ek=a<~8""n۷5P\T9]_:9dddUWWϚ5Kmi333fɧٳ7O T֕Ο?_YYillleeeii^thl yړ>x𠺺c)ܹs X(===W]]°<Խ:2 qY+++SSS|Q4ܓk/P[(bofԩ$ɟzԃy3۷ڊQV &0, t)*..ySvK|>…S˲n޼Y\\,]!WNb%4ÇϟַnΦc>} :wmvUƍFT=*WTTDDBa%%%/Z]jO WJJJ\rΝFSSSOOO4B!C3Fq Nyxx444ܹsի p8,O4ĵ 1V\y튊 ME~wŷIw1SQQq֭+W2lZ׳0ewvvvd,3{lG`=]y LT*ݿ͛o. ͛8Y sP^^ӻw0 a4n7nܹsGSŴv~=1c g6, 94,̩S:yGBBߙ3g0FF8E{v7C?+++;}4̛Mΐϙ3R#GTWWS,ZMMM/Tk]b RUUiӦg(j6ޑ#G՝={vn i`` z 9 ӧOpp0;N[`7cb4dʕ|M@>rș3g)#4t,;Cm􊋋tRxxɓ'\nmmkD/rׯ^3771cb~XXO?4}􂂂vqcǎ]t)>>ayV&'Hpdɒ#Fggg'''===%לAG}nu…'KDvvo(>dd Ga-D;w744۷EKZZZ訠h-]jٲe̯2k޼y端:gH5E&5믿tQEQd{T*maU[VasoݺΟ?+'IR,Z-7(ERTEQEwm^} K6l9I̭9Nff.yyy`={VEuJff&s_cǎt]' /a$7mڤzuqF$`H@2]$I///w$AxxxLE)E&ݻwOqJnn.4?n6AD"ٲe wEEG}~TMxY7.f߾}...˗/e`/dYLd Njj;j)e O"''n[v-߶SSS9;;wJSuAo:OOO|ĉ3ZNqㆦRJjj*AGjp!M׫="ESL9qΩ+"Z-YDǧN;::jcr[z52/z Ǽի\z0M˨ISS-[tRMEjkk k(e}̟]SST'>uVev܆G144lvXw#..n׮]lݺ]woQ$K8DekPVVmee+jN,_|YWT)O4[\,PֶBkUffX,fXft999W\DI؃/}] Mñ͛7 iiiTW׳Bk׮]n\.ʕ+666~~~jGcc˗Օ$I___>doV]j'''~`\]]鶇nnnj uLrrr\\ݶm"B0==] 6mSN ~y7nb»ww@;?SOK8iӘ`{u mԩӦMSO=Z\eee9;;D"e\ntt4ƣg6V!`e뗔xV977rذa*,C޴;widH7\HR/`(弼?0<<𸸸D9r9s &&&~ךAc^z?{ ƎJN8Tf+--ݶm[bbuU{ܯ_?}}6xQQQ4vynݚE5[׮]뢕}hffgWÇ?2?t/rJ&yE/tQ kD"qpp5|^SNQ(_~mn4A=z :Ye'נ=BBB.]$lwfUGQZ?~ܙggx3LKnEQ ,8wě7o}Tx盚:thɒ%ʌR?6뻪Ð?gԨQMMM111m.yiP3j('''5yov]]SƏrfnn RSS?cez5ktua݌fO h!$/^价jժgjj)S4]EIUV)q,YO䭐Jzdd2 Ϝ9͆7ohhHLL֞!CCCJKK.]8FI$8OOfsD7|{hǎc*g[ƌǎ x| EQ.]JKKqFnt7ӧOt9ϡ7E, @Ʉa[!o@ TӈaÆɏ䓓 Gѕ5U@@׌3;S3ooo==dzJLLG-OhnnnE׋`_4::ZyaaMJJJSZٍ7p@ZU ???{ƍ}}}l=J񉎎6551<&oCcco9,Y䥗^rrrz饗\_Κ5K4{ؽ{*02F=-H$ϷKLLLZf޽{58H$R\d2ݻ׮]k׮(>/^v.r$hj\M]]KLLr|>z!u=8]*nڴ]׬YW˔!o۷+W\\ƍ+Vh%hܲe`„ )ųv?_B!o: A|AeeѣGʪJ/B***>?^QQW&剦_D7!oW*.Uɓ _[]gRRRVVk~$VAL:ʪ]oc~^x Ǝd?ӧO{zzzA1>>hpf555.\o_~ɓʯsʔ)IIIcǎU]=#,,,"""vt}Gppp^^tL& emmmR;w{zz޾}[x~!22R G\0p>Ә;;;%HBBB*wixxxHHHhm"I~~~qqq/<;;Z{OG Nْi\\Ç;nIOO['*r ?LOOo8}M0;$$D5[yyyuuA޽[>*""⯿xʡzc@ O|qHH USNMOO'J`Uɓ'NhQ\|||ppp>}O.ՎH,++lu ބTezJJ -g ʲ{c B!deeDpzbˆȞ92aX``;wˎ5Jgӧ_edd^^^.LLLZ> EQnݺqFA ^4=66Փ޺R\^z9rO>gώl7]6==g.ܥ ov…gϞJl~O 0(}](N;\H$jlll٨ʪEQÇ/?URRұ(7iҤ;v 8AwFEEߟ|I RRRrÇ@ƏOot!,,,y&삂n:c <:؞ˉ?sƍqUqrrruu:t݊+''ٳBpҤI-Eg=***//W_)dԻw捻4W^`꾂0j"JE|P(2d.􉺆z\Ǐegg߽{7'''//rqqYfٳK6I֭k}1|/"00] P'a5sέ[NQaر_|񅿿?{\BCC:TVVZ.\n! a5O"={644ĉZSr.\pҤI3D!"Whh5]K3f…g>\=x ,,7olop8#G>>cǎS[KKKKIIINNNNNlWiJ8pʟu5 9Kdgg:O :҆/O}c[[[[0qC֤{ z/ޝ\0[\f}/gwa9{JptM|y!o{7r8|#۱50VQ"O+}.72ccLY!oyYp<}+ ^OSԿpҎ2Y}kgp#NV]BEQr!7&f"w3?[r 8<>diF<01~1{!Lӧ`Hz* 4lYɒ~.f|wkZG{, |ơ!Hi]Qz;?̼ew1c0 z5v¿{򦄯熗QKCj@Q[ߥ)"s~7uB9I'm>ULQGgWM\sDJQTCFCFx)EQT͍&|x'!3nKz(_ :1#@>k0hL;u>}77M P zy~:w4c @}^f Oϖ٘ ͉ (WE_Q_;3Ƴ?֓޻F4Qu7)x&9.W~;[5KJ.y.X3;Fr۳S}G bƋ\,#O78y{*j5?0uqs$=AƊ=.c}R0uHJt-Y[{Ҋ{wz t4&^?ΤNG5Ѷg %Mw[oNlޝz\[!o+Ɲn}N)TC^wȢ2 Ie>k*OĮ~q~?}[QSck@e4g]ښz^/'FP U"Ő}<ѯiH:p[yRF cdjH&{+jz?}bǑ.<ʔhYo&F&#,yx4щ?#J !W Lph6ĞMjtWtdub0(DJQՒ@?PA=M|%zF "I 8տ3kW) u]wM=l-#_Y"_/~猙$Iy'iH1w_N,CG&n(1CgsOޜx|K0:yw:J^CɉZXO5~: `5#(G8}(;p_s|Ghs^/?H*! \AՏqd @-v(E} -J DBtܾI}ƦGrCr<ɪ*_^3M5:og,C70){;T |wWts4Gb͉#={ #'ۙޠ߫-{Y>_KxmrbGΜӯH|iH$4eԃ!px:\RDx `~q$I>kVA_?KyTmo/Ocև4-Ӎ{ra-*FQ$ ~aӋm ΠOb)* Ss=;"""GX'053158co/7t]WREUp0c>o[5ݔ 뵭DY8uE^X pw0qR!W^;nkjn~3@[RD8){s\S˯ 3]o]ȁOp-^ٖ/My: <O?.e 8nW__[-Y$a>,z|}`t({ZGo~Uy/8&(y#v-t7{g6}i~b( y{T !|ωy $;i%eoٻa#ߦc YzsHk~B&FFRTy?A0MVgHePXJ٤ f>rZyjcuJj% +A/@Pma"aQ-k`yH9}񖪾_b=Ũ{.򔳱 Ax1u% 9B,;XCab9 9B,!G0!Ð#rrXCab9 9B,!G0!Ð#rrX rq5IENDB`././@LongLink0000644000000000000000000000016200000000000011602 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/data/democlock.confukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/data/d0000664000175000017500000000074614461605317033373 0ustar adminadmin[AppWidget] name = democlock providerName = democlock previewPath = /usr/share/appwidgetdemo/clock/democlock.png qmlFile = /usr/share/appwidget/qml/democlock.qml zoom = false rightButton = false repeatPlacement = false minWidget = 400 minHeight = 400 targetCellWidth = 2 targetCellHeight = 2 updatePeriodMillis = 0 describe = this is a alarm clock [LanguageFiles] zh_CN = /usr/share/appwidget/translations/democlock_zh_CN.qm bo_CN = /usr/share/appwidget/translations/democlock_bo_CN.qm ././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/mainwindow.uiukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/mainwi0000664000175000017500000001022414413425621033506 0ustar adminadmin MainWindow 0 0 800 600 0 0 MainWindow 20 16777215 : 20 16777215 : 设置 Qt::Horizontal 40 20 设置闹钟: 设置 0 0 Qt::Horizontal 40 20 闹钟记录: 0 0 800 28 ././@LongLink0000644000000000000000000000015500000000000011604 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/mainwindow.cppukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/mainwi0000664000175000017500000001450214461605317033516 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); //初始化界面 for (int h = 0; h < 24; h++) { ui->comboBox->addItem(QString::number(h)); } for (int m = 0; m < 60; m++) { ui->comboBox_2->addItem(QString::number(m)); } for (int s = 0; s < 60; s++) { ui->comboBox_3->addItem(QString::number(s)); } ui->dateEdit->setDate(QDate::currentDate()); ui->comboBox->setCurrentText(QString::number(QTime::currentTime().hour())); ui->comboBox_2->setCurrentText(QString::number(QTime::currentTime().minute())); ui->comboBox_3->setCurrentText(QString::number(QTime::currentTime().second())); //加载小插件demo的qml ui,但是加上后启动太慢,先去掉 // QQuickView *p=new QQuickView(); // QString path=QString("qrc:/clock.qml"); // qDebug()<<"path"<setSource(url); // QWidget*w= QWidget::createWindowContainer(p,this); // w->setFixedSize(370,340); // ui->verticalLayout_3->addWidget(w); timer = new QTimer(this); connect(timer, &QTimer::timeout, this, [=](){ // qDebug()<<"timer update"; ui->dateEdit->setDate(QDate::currentDate()); ui->comboBox->setCurrentText(QString::number(QTime::currentTime().hour())); ui->comboBox_2->setCurrentText(QString::number(QTime::currentTime().minute())); ui->comboBox_3->setCurrentText(QString::number(QTime::currentTime().second())); }); timer->start(1000); //闹钟记录的数据存放位置 QString path1 = QDir::homePath() + "/.config/appwidgetclock/config.ini"; setting = new QSettings(path1, QSettings::IniFormat); //clcok小插件的后台服务dbus接口 appwidgetinterface = new QDBusInterface("org.ukui.appwidget.provider.democlock", "/org/ukui/appwidget/provider", "org.ukui.appwidget.provider.democlock", QDBusConnection::sessionBus()); //初始化闹钟列表 ui->listView->setViewMode(QListView::ListMode); itemmode = new QStandardItemModel(this); ui->listView->setModel(itemmode); setting->beginGroup("AlarmClock"); QStringList AlarmClocklist = setting->allKeys(); for (int i = 0; iappendRow(item); } setting->endGroup(); setting->sync(); //监控闹钟列表的点击事件,进行删除闹钟 connect(ui->listView, &QListView::pressed, this, [=]() { QString key = itemmode->item(ui->listView->currentIndex().row())->text(); setting->beginGroup("AlarmClock"); setting->remove(key); setting->endGroup(); setting->sync(); appwidgetinterface->asyncCall("appWidgetUpdate"); ui->listView->model()->removeRow(ui->listView->currentIndex().row()); }); } MainWindow::~MainWindow() { delete ui; delete appwidgetinterface; delete setting; delete itemmode; } void MainWindow::on_pushButton_clicked() { //设置修改日期和时间,qml的图形钟表会自动根据系统时间进行更改,在qml中内部有逻辑处理,这里更改后通知小插件更改的主要是日期 QDate date = ui->dateEdit->date();// 日期 int year = date.year(); // 年 int month = date.month(); // 月 int day = date.day(); // 日 int hour = ui->comboBox->currentText().toInt(); int min = ui->comboBox_2->currentText().toInt(); int sss = ui->comboBox_3->currentText().toInt(); qDebug() << "日期and时间" << year << month << day << hour << min << sss; QString m_qstrDateTime = QString("%1%2%3%4%5.%6"). arg(month, 2, 10, QChar('0')). /*月份,必须两位*/ arg(QString("%1").arg(day, 2, 10, QChar('0')))./*日,必须两位*/ arg(hour, 2, 10, QChar('0')). /*小时,必须两位*/ arg(min, 2, 10, QChar('0')). /*分钟,必须两位*/ arg(year). /*年份,必须4位*/ arg(sss, 2, 10, QChar('0')); /*秒,必须两位*/ //设置时间需要提权,对应电脑的密码需要改一下。 qDebug() << m_qstrDateTime; QString qstrDateTime = QString("/bin/sh -c \"echo \"%1\" | sudo -S date %2\"").arg("123123.."/*电脑密码*/).arg(m_qstrDateTime); qDebug() << qstrDateTime; QProcess::execute(qstrDateTime); QString qstrSaveTime = QString("/bin/sh -c \"echo \"%1\" | sudo -S hwclock --systohc\"").arg("123123.."/*电脑密码*/); QProcess::execute(qstrSaveTime); //通过后台服务通知管理服务更新 appwidgetinterface->asyncCall("appWidgetUpdate"); } void MainWindow::on_pushButton_2_clicked() { setting->beginGroup("AlarmClock"); QString value = ui->timeEdit->text(); if(setting->contains(value)) { qDebug()<<" 已经存在该时间的闹钟"; QMessageBox::critical(this, "提示","已经存在该时间的闹钟,请换一个时间点"); setting->endGroup(); setting->sync(); return ; } setting->setValue(value, true); setting->endGroup(); setting->sync(); QStandardItem *item = new QStandardItem(value); itemmode->appendRow(item); appwidgetinterface->asyncCall("appWidgetUpdate"); } ././@LongLink0000644000000000000000000000017700000000000011610 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo.proukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo/appwid0000664000175000017500000000320514461605317033514 0ustar adminadminQT += core gui widgets dbus qml quick greaterThan(QT_MAJOR_VERSION, 4): QT += widgets include(../../../ukui-appwidget-manager/QtSingleApplication/qtsingleapplication.pri) CONFIG += C++11 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ mainwindow.cpp HEADERS += \ mainwindow.h FORMS += \ mainwindow.ui TRANSLATIONS += \ translations/democlock_zh_CN.ts \ translations/democlock_bo_CN.ts # Default rules for deployment. qnx: target.path = /usr/bin/ else: unix:!android: target.path = /usr/bin/ qml.files += data/democlock.qml qml.path = /usr/share/appwidget/qml/ appwidgetcong.files += data/democlock.conf appwidgetcong.path = /usr/share/appwidget/config/ preview.files += data/democlock.png preview.path = /usr/share/appwidgetdemo/clock/ qm_files.files += translations/* qm_files.path = /usr/share/appwidget/translations/ INSTALLS += target qml appwidgetcong preview qm_files RESOURCES += \ src.qrc DISTFILES += \ \ QtSingleApplication/qtsingleapplication.pri \ QtSingleApplication/qtsinglecoreapplication.pri ukui-app-widget/ukui-appwidget-test/appwidgetprovider-clock-demo/appwidgetprovider-clock-demo.pro0000664000175000017500000000015014413425621033016 0ustar adminadminTEMPLATE = subdirs SUBDIRS += \ appwidgetprovider-clock-demo \ appwidgetprovider-clock-service ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/0000775000175000017500000000000014461605317024705 5ustar adminadminukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/0000775000175000017500000000000014456706513026543 5ustar adminadminukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/src.qrc0000664000175000017500000000044314456706513030042 0ustar adminadmin data/demosearch.conf data/demosearch.png data/ukui-search.svg data/demosearch.qml org.ukui.appwidget.provider.demosearch.service ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/data/0000775000175000017500000000000014461616310027443 5ustar adminadminukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/data/ukui-search.svg0000664000175000017500000000322014413425621032401 0ustar adminadmin ukui-global search-search ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/data/demosearch.conf0000664000175000017500000000076114461605317032435 0ustar adminadmin[AppWidget] name = demosearch providerName = demosearch previewPath = /usr/share/appwidgetdemo/demosearch/demosearch.png qmlFile = /usr/share/appwidget/qml/demosearch.qml zoom = false rightButton = false repeatPlacement = false minWidget = 640 minHeight = 100 targetCellWidth = 3 targetCellHeight = 1 updatePeriodMillis = 0 describe = this is a search demo [LanguageFiles] zh_CN = /usr/share/appwidget/translations/demosearch_zh_CN.qm bo_CN = /usr/share/appwidget/translations/demosearch_bo_CN.qm ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/data/demosearch.qml0000664000175000017500000001321114461616310032266 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ import QtQuick 2.6 import QtQuick.Window 2.2 import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import org.ukui.appwidget 1.0 AppWidget { id: window //注1:appname需要小插件赋值 appname: "demosearch" //小插件的位置应该设置为居中 anchors.centerIn: parent //注2:小插件应考虑在不同缩放以及分辨率下的适配 //可以采用如下方式计算缩放比scalefactor(仅供参考,只要能实现小插件根据父类窗口缩放即可) width: 640 * scalefactor height: 100 * scalefactor property double scalefactor: 1.00 visible: true //注3:qmlenable为当前小插件是否可以进行操作的标志,当clickable为 false时, //小插件不可点击,不能接收焦点等。该状态的决定由使用端传递并更新 property bool clickable: true Rectangle { id: searchBar anchors.centerIn: parent width: 400 * scalefactor height: 35 * scalefactor border.color: "#fc5531" border.width: 1 radius: searchBar.height / 2 Rectangle { id: btn width: 80 * scalefactor height: searchBar.height anchors.right: parent.right anchors.top: parent.top color: "#fc5531" layer.enabled: true layer.effect: OpacityMask { maskSource: Rectangle { width: 80 * scalefactor height: btn.height radius: btn.height / 2 //左侧 Rectangle { width: 20 * scalefactor height: btn.height } } } Image { id: image_search width: 20 * scalefactor height: 20 * scalefactor x: 10 anchors.verticalCenter: parent.verticalCenter source: "file:///usr/share/appwidgetdemo/search/ukui-search.svg" } Text { id: searchTxt color: "White" text: qsTr("search") anchors.verticalCenter: parent.verticalCenter anchors.left: image_search.right anchors.leftMargin: 1 font.pointSize: 12 * scalefactor font.bold: true } } } MouseArea { anchors.fill: parent //注4:如果使用MouseArea需要注意enabled需要与window.clickable一致 enabled: window.clickable //注5:事件透传,在小插件中部分事件需要透传到使用端处理,如onPressAndHold,其他的暂时未发现需要设置 //如需要实现onClicked,则注意onPressed一定不要透传,否则小插件自身将不能得到点击事件 propagateComposedEvents: true onClicked: { //点击需要进行的跳转 qmlclickedsignal("demosearch", "clicked"); mouse.accepted = false } //注6:onPressAndHold事件需要透传,否则将不能实现长按进入编辑状态(不能长按进行拖动) onPressAndHold: { mouse.accepted = false } } Component.onCompleted: { //注7:初始化缩放比 initScalefactor() //监听使用端状态改变信号,用于更新clickable userStatusChangedSignal.connect(onUserStatusChanged) } function initScalefactor() { //按宽计算缩放比例,计算在这个比例系数下的小插件宽高,如果高超出父类的高,则更换比例系数的计算方式,按高计算缩放比例 //console.log("父类窗口大小", window.parent.width,window.parent.height); if(window.parent.width == 0 || window.parent.height == 0) { window.scalefactor = 1.0 console.log("父类窗口大小为 0 默认缩放比为1.0") return } //640为默认情况下demosearch的宽度 window.scalefactor = window.parent.width / 640 //console.log("当前比例系数", window.scalefactor); //100为默认情况下demosearch的高度 var tw = window.scalefactor * 640 var th = window.scalefactor * 100 //console.log("大小:", tw,th ,window.height); //当按宽缩放时,父类窗口的高小于小插件缩放后实际的高时则重新以高度计算缩放比 if(th > window.parent.height) { window.scalefactor = window.parent.height / 100 //console.log("以宽度计算比例系数", appwidget.scalefactor); } } function onUserStatusChanged(status) { console.log("qml Appwidget demosearch user status changed ", status); if(status === "Normal") { window.clickable = true; }else if(status === "Editable") { window.clickable = false; } } } ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/data/demosearch.png0000664000175000017500000000500014456706513032267 0ustar adminadminPNG  IHDRdOX pHYs+ IDATxkpU]`  T1JpK"-TXDE2o8Uk(`+bD+A20*(v(s> %f=V֧oKTDD1{DDGD.bEl#"}D"\>"rGD.bEl#"}D"\>"rGD.bEl#"}D"\>"rGD.bEl#"}D"\lku6-/C8fD" I@f^m0r =--IL,韅An_^ӽ7IFNh4k_ʾXVHN ϗaZ":E:TM2M\rxͯ$ɐ&!>"WM7WF14}y|L6F.yxH0?wh4ۧ~m)F1X%-7qͯ >"j?tf!>ҕ`2GD툵3C#ϾXI>EDt5~2~onQ;kk=}%SYWV{= gqiYrHŸͰI_r|feSlMCD[5WEپ\;zrW^Y~@D3̓HEy @|3a|nܬ$ӊدaqʋg|zk<zs:&@-*vE+&<70/:<{iyޗ.] ߛFʭoޚJD%FRd|,Tng7c4:S@2)j`b -r'X>OC^zI7kvٻɿ3C+_jM {n؄@V$G]00[uh !.a4t}O^Dp*;57~O'MdH\2P`ɝO;'iv2|?K" PMu %Lt S3YA{ƁcCU R;uZ[0C»ힰ$36(GM>ד^Z_sD/7هҏdfq5cvZ瑾Ϟ4 ل7^mM<*0><)1&w5Eki _%ȑg,l3Lz,'=:)2Llۂ[>Qgˤrbsv{-;C̘9 Z3N_JL ϷK3VDt\M-rgٝPqr3,oʕvk^Ft;#"sJʌhU#P!LsdJCNyC&y=Svi=ϗ}=*yD .>4xk  iب@bӄ# iäAs[(D$ ?$3m Cspe}N?oKq]>}r{%wݪ%b+#":EL@&N>DG 5iW,`1 } 沝v1Sf6& c&ݘѵGMW.e2~iE&N{w{%Te_,u+$@?ClS85}[Z%Y2 $GNtcoME wLCHwe(/Cm6PCLD.A ]$-&w"rGD.bEl#"}D"\>"rGD.bEl#"}D"\>"rGD.bEl#"}D"\>"rGD.bEl#"}D_{IENDB`././@LongLink0000644000000000000000000000017200000000000011603 Lustar rootrootukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/org.ukui.appwidget.provider.demosearch.serviceukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/provider/org.ukui.appwidget.provid0000664000175000017500000000015014456706513033512 0ustar adminadmin[D-BUS Service] Name=org.ukui.appwidget.provider.demosearch Exec=/usr/bin/appwidgetprovider-search-demo ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/translations/0000775000175000017500000000000014461605317027426 5ustar adminadminukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/translations/demosearch_bo_CN.qm0000664000175000017500000000013114461605317033132 0ustar adminadmin demosearch search 搜索 搜索 ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/translations/demosearch_bo_CN.ts0000664000175000017500000000057414461605317033156 0ustar adminadmin demosearch search undefined undefined ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/translations/demosearch_zh_CN.qm0000664000175000017500000000011314461605317033153 0ustar adminadmin. * * Authors: wangyan * */ #ifndef SEARCHPROVIDER_H #define SEARCHPROVIDER_H #include class QDBusInterface; class SearchProvider : public AppWidget::KAppWidgetProvider { public: SearchProvider(QString providername = "demosearch",QObject *parent = nullptr); void appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value); void appWidgetUpdate(); void appWidgetDisable(); void appWidgetDeleted(); void appWidgetEnable(); void appWidgetClicked(const QString &widgetname, const QDBusVariant &value); private: QDBusInterface *searchinterface = nullptr; }; #endif // SEARCHPROVIDER_H ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/searchprovider.cpp0000664000175000017500000000404114461605317030430 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "searchprovider.h" #include #include #include SearchProvider::SearchProvider(QString providername ,QObject *parent) : KAppWidgetProvider(providername , parent) { searchinterface = new QDBusInterface("com.ukui.search.service", "/", "org.ukui.search.service", QDBusConnection::sessionBus()); } void SearchProvider::appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value) { Q_UNUSED(eventname); Q_UNUSED(widgetname); Q_UNUSED(value); qDebug() << "TestProvider::appWidgetRecevie"; } void SearchProvider::appWidgetUpdate() { qDebug() << "TestProvider::appWidgetUpdate"; } void SearchProvider::appWidgetDisable() { qDebug() << "TestProvider::appWidgetDisable"; } void SearchProvider::appWidgetDeleted() { qDebug() << "TestProvider::appWidgetDeleted"; } void SearchProvider::appWidgetEnable() { qDebug() << "TestProvider::appWidgetEnable"; } void SearchProvider::appWidgetClicked(const QString &widgetname, const QDBusVariant &value) { qDebug() << "TestProvider::appWidgetClicked"; qDebug() << widgetname << value.variant(); searchinterface->asyncCall("showWindow"); } ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/main.cpp0000664000175000017500000000163214461605317026337 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include #include "searchprovider.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); SearchProvider p ; return a.exec(); } ukui-app-widget/ukui-appwidget-test/appwidgetprovider-search-demo/appwidgetprovider-search-demo.pro0000664000175000017500000000431714461605317033360 0ustar adminadminQT -= gui QT += dbus widgets CONFIG += c++11 console CONFIG -= app_bundle # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ searchprovider.cpp TRANSLATIONS += \ translations/demosearch_zh_CN.ts \ translations/demosearch_bo_CN.ts # Default rules for deployment. qnx: target.path = /usr/bin else: unix:!android: target.path = /usr/bin qm_files.files += translations/* qm_files.path = /usr/share/appwidget/translations/ qml.files += provider/data/demosearch.qml qml.path = /usr/share/appwidget/qml/ appwidgetcong.files += provider/data/demosearch.conf appwidgetcong.path = /usr/share/appwidget/config/ service.files += provider/org.ukui.appwidget.provider.demosearch.service service.path += /usr/share/dbus-1/services/ preview.files += provider/data/demosearch.png preview.path = /usr/share/appwidgetdemo/search/ svg.files += provider/data/ukui-search.svg svg.path = /usr/share/appwidgetdemo/search/ INSTALLS += target qml appwidgetcong service preview svg qm_files HEADERS += \ searchprovider.h RESOURCES += \ provider/src.qrc #QMAKE_LFLAGS += -Wl,-rpath=$$OUT_PWD/../../libukui-app-widget/libukui-appwidget-provider/ LIBS += -L$$OUT_PWD/../../libukui-app-widget/libukui-appwidget-manager -lukui-appwidget-manager LIBS += -L$$OUT_PWD/../../libukui-app-widget/libukui-appwidget-provider -lukui-appwidget-provider INCLUDEPATH += $$PWD/../../libukui-app-widget/libukui-appwidget-manager DEPENDPATH += $$PWD/../../libukui-app-widget/libukui-appwidget-manager INCLUDEPATH += $$PWD/../../libukui-app-widget/libukui-appwidget-provider DEPENDPATH += $$PWD/../../libukui-app-widget/libukui-appwidget-provider ukui-app-widget/libukui-app-widget/0000775000175000017500000000000014456706513016554 5ustar adminadminukui-app-widget/libukui-app-widget/libukui-appwidget-provider/0000775000175000017500000000000014461615267024033 5ustar adminadminukui-app-widget/libukui-app-widget/libukui-appwidget-provider/kappwidgetprovider.h0000664000175000017500000000352714461615267030125 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef KAPPWIDGETPROVIDER_H #define KAPPWIDGETPROVIDER_H #include "libukui-appwidget-provider_global.h" #include class QDBusVariant; namespace AppWidget { /** @defgroup 小插件提供端模块 * @{ */ class LIBUKUIAPPWIDGETPROVIDER_EXPORT KAppWidgetProvider : public QObject { Q_OBJECT public: KAppWidgetProvider(QString providername, QObject *parent = nullptr) ; public slots: /** * @brief 小插件自定义事件 */ virtual void appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value); /** * @brief 小插件更新函数 */ virtual void appWidgetUpdate(); /** * @brief 小插件禁用函数 */ virtual void appWidgetDisable(); /** * @brief 小插件删除函数 */ virtual void appWidgetDeleted(); /** * @brief 小插件启用函数 */ virtual void appWidgetEnable(); /** * @brief 小插件点击函数 */ virtual void appWidgetClicked(const QString &widgetname, const QDBusVariant &value); }; }// namespace AppWidget #endif // KAPPWIDGETPROVIDER_H ukui-app-widget/libukui-app-widget/libukui-appwidget-provider/kappwidgetprovider.cpp0000664000175000017500000000507614461615267030461 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "kappwidgetprovider.h" #include #include #include #include namespace AppWidget { KAppWidgetProvider::KAppWidgetProvider(QString providername, QObject *parent): QObject(parent) { if(providername.isEmpty()) { qWarning() << "providername isEmpty!"; return; } QString servicename = KAppWidgetCommon::getProviderDbusObject(providername); QString objectpath = KAppWidgetCommon::getProviderDbusPath(providername); QString objectinterface = KAppWidgetCommon::getProviderDbusInterface(providername); QDBusConnection connection = QDBusConnection::sessionBus(); if (connection.registerService(servicename)) { connection.registerObject(objectpath, objectinterface, this, QDBusConnection::ExportAllSlots); qDebug() << "Regist Dbus Service success"; }else { qCritical() << "Register DBus Service Error:" << connection.lastError().message(); } } void KAppWidgetProvider::appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value) { Q_UNUSED(eventname); Q_UNUSED(widgetname); Q_UNUSED(value); qDebug() << "KAppWidgetProvider::appWidgetRecevie"; } void KAppWidgetProvider::appWidgetUpdate() { qDebug() << "KAppWidgetProvider::appWidgetUpdate"; } void KAppWidgetProvider::appWidgetDisable() { qDebug() << "KAppWidgetProvider::appWidgetDisable"; } void KAppWidgetProvider::appWidgetDeleted() { qDebug() << "KAppWidgetProvider::appWidgetDeleted"; } void KAppWidgetProvider::appWidgetEnable() { qDebug() << "KAppWidgetProvider::appWidgetEnable"; } void KAppWidgetProvider::appWidgetClicked(const QString &widgetname, const QDBusVariant &value) { Q_UNUSED(widgetname); Q_UNUSED(value); qDebug() << "KAppWidgetProvider::appWidgetClicked"; } }// namespace AppWidget ukui-app-widget/libukui-app-widget/libukui-appwidget-provider/libukui-appwidget-provider.pro0000664000175000017500000000217014456706513032032 0ustar adminadminQT -= gui QT += dbus TEMPLATE = lib DEFINES += LIBUKUIAPPWIDGETPROVIDER_LIBRARY TARGET = ukui-appwidget-provider VERSION = 0.0.0 CONFIG += c++11 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 include(../../libukui-appwidget-common/libukui-appwidget-common.pri) SOURCES += \ kappwidgetprovider.cpp HEADERS += \ libukui-appwidget-provider_global.h \ kappwidgetprovider.h # Default rules for deployment. unix { target.path = /usr/lib apifile.files = *.h apifile.path = /usr/include/ukui/ } !isEmpty(target.path): INSTALLS += target apifile ukui-app-widget/libukui-app-widget/libukui-appwidget-provider/libukui-appwidget-provider_global.h0000664000175000017500000000206614461615267033006 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef LIBUKUIAPPWIDGETPROVIDER_GLOBAL_H #define LIBUKUIAPPWIDGETPROVIDER_GLOBAL_H #include #if defined(LIBUKUIAPPWIDGETPROVIDER_LIBRARY) # define LIBUKUIAPPWIDGETPROVIDER_EXPORT Q_DECL_EXPORT #else # define LIBUKUIAPPWIDGETPROVIDER_EXPORT Q_DECL_IMPORT #endif #endif // LIBUKUIAPPWIDGETPROVIDER_GLOBAL_H ukui-app-widget/libukui-app-widget/libukui-appwidget-manager/0000775000175000017500000000000014461615267023613 5ustar adminadminukui-app-widget/libukui-app-widget/libukui-appwidget-manager/libukui-appwidget-manager_global.h0000664000175000017500000000206014461615267032340 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef LIBUKUIAPPWIDGETMANAGER_GLOBAL_H #define LIBUKUIAPPWIDGETMANAGER_GLOBAL_H #include #if defined(LIBUKUIAPPWIDGETMANAGER_LIBRARY) # define LIBUKUIAPPWIDGETMANAGER_EXPORT Q_DECL_EXPORT #else # define LIBUKUIAPPWIDGETMANAGER_EXPORT Q_DECL_IMPORT #endif #endif // LIBUKUIAPPWIDGETMANAGER_GLOBAL_H ukui-app-widget/libukui-app-widget/libukui-appwidget-manager/kappwidgetmanager.h0000664000175000017500000001105614461615267027461 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef KAPPWIDGETMANAGER_H #define KAPPWIDGETMANAGER_H #include "libukui-appwidget-manager_global.h" #include namespace AppWidget { /** * @defgroup 小插件管理服务接口模块 */ /** * @brief 小插件属性枚举 */ enum AppWidgetConfig { NAME = 1, //小插件名字 PROVIDER_NAME, //提供端名 PREVIEW_PATH, //预览图 ZOOM, //是否支持缩放 RIGHT_BUTTON, //是否支持右键 REPEAT_PLACEMENT, //是否可以重复放置 MIN_WIDTH, //最小宽度 MIN_HEIGHT, //最小高度 TARGET_CELL_WIDTH, //小插件默认宽度所占屏幕的单位格数 TARGET_CELL_HEIGHT, //小插件默认高度所占屏幕的单位格数 UPDATE_PERIODMILLIS, //是否定时更新 DESCRIBE, //小插件描述 }; /** * @brief 使用端状态属性枚举 */ enum UserStatus { NORMAL = 1, //正常状态 EDITABLE = 2, //编辑状态 }; class LIBUKUIAPPWIDGETMANAGER_EXPORT KAppWidgetManager : public QDBusInterface { Q_OBJECT public: KAppWidgetManager(QObject *parent = nullptr); static KAppWidgetManager* getInstance() { static KAppWidgetManager s_instance; return &s_instance; } /** * @brief 获取小插件列表 * @return app widget list */ QStringList getAppWidgetList(); /** * @brief 获取小插件ui文件路径 * @param appwidgetname * @return path of ui file */ QString getAppWidgetUiFile(const QString &appwidgetname); /** * @brief 获取小插件的config属性 * @param appwidgetname config * @return config value of appwidgetname */ QString getAppWidgetConfig(const QString &appwidgetname, const AppWidgetConfig& config); /** * @brief 获取小插件的所有属性 * @param appwidgetname * @return config list of widget */ QMap getAppWidgetConfigs(const QString &appwidgetname); /** * @brief 注册小插件 * @param appwidgetname username * @return appwidget id */ int registerAppWidget(const QString &appwidgetname, const QString &username); /** * @brief 注销小插件 * @param appwidgetid * @return unregister success return true, else false */ bool unregisterAppWidget(const int &appwidgetid); /** * @brief 获取小插件共享数据 * @param appwidgetid * @return data from provider */ QMap getAppWidgetData(const int &appwidgetid); /** * @brief 更新小插件共享数据 * @param providername data */ void updateAppWidget(const QString &providername, const QMap &data); /** *@brief 更新使用端状态 *@param username userstatus * */ void updateUserStatus(const QString &username, const UserStatus& userstatus); void notifyProviderUpdate(int id); QMap getAppWidgetLanguageFiles(const QString &appwidgetname); signals: /** * @brief 小插件资源文件增加信号 * @param appwidget name */ void appWidgetFileAdded(const QString &appwidgetname); /** * @brief 小插件资源文件删除信号 * @param appwidget name */ void appWidgetFileDeleted (const QString &appwidgetname); private: /** * @brief 转换AppWidgetConfig枚举为字符串 * @param AppWidgetConfig config * @return config of string */ static QString enumToSTring(const AppWidgetConfig& config); /** * @brief 转换UserStatus枚举为字符串 * @param UserStatus config * @return config of string */ static QString enumUserStatusToSTring(const UserStatus& userstatus); }; }// namespace AppWidget #endif // KAPPWIDGETMANAGER_H ukui-app-widget/libukui-app-widget/libukui-appwidget-manager/kappwidgetmanager.cpp0000664000175000017500000002042314461615267030012 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "kappwidgetmanager.h" #include #include #include #include #include namespace AppWidget { KAppWidgetManager::KAppWidgetManager(QObject *parent) :QDBusInterface(KAppWidgetCommon::getManagerDbusObject(), KAppWidgetCommon::getManagerDbusPath(), KAppWidgetCommon::getManagerDbusInterface(),QDBusConnection::sessionBus(),parent) { qDBusRegisterMetaType>(); } QStringList KAppWidgetManager::getAppWidgetList() { qDebug() << "KAppWidgetManager::getAppWidgetList"; QStringList appWidgetList; QDBusMessage response = call("getAppWidgetList"); if (response.type() == QDBusMessage::ErrorMessage ) { qCritical() << "ERROR" << response.errorMessage(); return QStringList(); } if (response.type() == QDBusMessage::ReplyMessage) { appWidgetList = response.arguments().takeFirst().toStringList(); } return appWidgetList; } QString KAppWidgetManager::getAppWidgetUiFile(const QString &appwidgetname) { qDebug() << "KAppWidgetManager::getAppWidgetUiFile"; if(appwidgetname.isEmpty()) { qWarning() << "parameter is empty"; return QString(); } QString uiFile; QDBusMessage response = call("getAppWidgetUiFile", appwidgetname); if (response.type() == QDBusMessage::ErrorMessage ) { qCritical() << "ERROR" << response.errorMessage(); return QString(); } if (response.type() == QDBusMessage::ReplyMessage) { uiFile = response.arguments().takeFirst().toString(); } return uiFile; } QString KAppWidgetManager::getAppWidgetConfig(const QString &appwidgetname, const AppWidgetConfig& config) { qDebug() << "KAppWidgetManager::getAppWidgetConfig"; if(appwidgetname.isEmpty()) { qWarning() << "parameter is empty"; return QString(); } QString uiFile; QDBusMessage response = call("getAppWidgetConfig", appwidgetname, enumToSTring(config)); if (response.type() == QDBusMessage::ErrorMessage ) { qCritical() << "ERROR" << response.errorMessage(); return QString(); } if (response.type() == QDBusMessage::ReplyMessage) { uiFile = response.arguments().takeFirst().toString(); } return uiFile; } QMap KAppWidgetManager::getAppWidgetConfigs(const QString &appwidgetname) { qDebug() << "KAppWidgetManager::getAppWidgetConfigs"; if(appwidgetname.isEmpty()) { qWarning() << "parameter is empty"; return QMap(); } QMap confs; QDBusPendingReply> reply = call("getAppWidgetConfigs", appwidgetname); confs =reply.value(); return confs; } int KAppWidgetManager::registerAppWidget(const QString &appwidgetname, const QString &username) { qDebug() << "KAppWidgetManager::registerAppWidget"; if(appwidgetname.isEmpty() || username.isEmpty()) { qWarning() << "parameter is empty"; return -1; } int id = -1; QDBusMessage response = call("registerAppWidget", appwidgetname, username); if (response.type() == QDBusMessage::ErrorMessage ) { qCritical() << "ERROR" << response.errorMessage(); return -1; } if (response.type() == QDBusMessage::ReplyMessage) { id = response.arguments().takeFirst().toInt(); } return id; } bool KAppWidgetManager::unregisterAppWidget(const int &appwidgetid) { qDebug() << "KAppWidgetManager::unregisterAppWidget"; if(appwidgetid < 0) { qWarning() << "parameter is error"; return false; } bool unregister = false; QDBusMessage response = call("unregisterAppWidget", appwidgetid); if (response.type() == QDBusMessage::ErrorMessage ) { qCritical() << __FUNCTION__ << __LINE__ << response.errorMessage(); return false; } if (response.type() == QDBusMessage::ReplyMessage) { unregister = response.arguments().takeFirst().toBool(); } return unregister; } QMap KAppWidgetManager::getAppWidgetData(const int &appwidgetid) { qDebug() << "KAppWidgetManager::getAppWidgetData"; if(appwidgetid < 0) { qWarning() << __FUNCTION__ << __LINE__ << "get invalid id :" << appwidgetid; return QMap(); } QDBusPendingReply> reply = asyncCall("getAppWidgetData", appwidgetid); reply.waitForFinished(); if (reply.isError()) { qDebug() << __FUNCTION__ << __LINE__ << reply.error().message(); return QMap(); } QMap map = reply.value(); return map; } void KAppWidgetManager::updateAppWidget(const QString &providername, const QMap &data) { qDebug() << "KAppWidgetManager::updateAppWidget" << providername << data; if(providername.isEmpty()) { qWarning() << "parameter is empty"; return ; } asyncCall("updateAppWidget", providername, data); } QString KAppWidgetManager::enumToSTring(const AppWidgetConfig& config) { QString conf; switch (config) { case AppWidgetConfig::NAME: conf = "name"; break; case AppWidgetConfig::PROVIDER_NAME: conf = "providerName"; break; case AppWidgetConfig::PREVIEW_PATH: conf = "previewPath"; break; case AppWidgetConfig::ZOOM: conf = "zoom"; break; case AppWidgetConfig::RIGHT_BUTTON: conf = "rightButton"; break; case AppWidgetConfig::REPEAT_PLACEMENT: conf = "repeatPlacement"; break; case AppWidgetConfig::MIN_WIDTH: conf = "minWidget"; break; case AppWidgetConfig::MIN_HEIGHT: conf = "minHeight"; break; case AppWidgetConfig::TARGET_CELL_WIDTH: conf = "targetCellWidth"; break; case AppWidgetConfig::TARGET_CELL_HEIGHT: conf = "targetCellHeight"; break; case AppWidgetConfig::UPDATE_PERIODMILLIS: conf = "updatePeriodMillis"; break; case AppWidgetConfig::DESCRIBE: conf = "describe"; break; default: break; } return conf; } QString KAppWidgetManager::enumUserStatusToSTring(const UserStatus& userstatus) { QString status = "Normal"; switch (userstatus) { case UserStatus::NORMAL: status = "Normal"; break; case UserStatus::EDITABLE: status = "Editable"; break; default: break; } return status; } void KAppWidgetManager::updateUserStatus(const QString &username, const UserStatus& userstatus) { if(username.isEmpty()) { qWarning() << __FUNCTION__ << __LINE__ << "参数不能为空"; return; } QString status = enumUserStatusToSTring(userstatus); asyncCall("updateUserStatus", username, status); } void KAppWidgetManager::notifyProviderUpdate(int id) { asyncCall("notifyProviderUpdate", id); } QMap KAppWidgetManager::getAppWidgetLanguageFiles(const QString &appwidgetname) { if(appwidgetname.isEmpty()) { qWarning() << __FILE__ << __FUNCTION__ << "appwidgetname is empty"; return QMap(); } QDBusReply> reply = call("getAppWidgetLanguageFiles", appwidgetname); if (!reply.isValid()) { qWarning() << __FUNCTION__ << __LINE__ << reply.error(); return QMap(); } return reply.value(); } }// namespace AppWidget ukui-app-widget/libukui-app-widget/libukui-appwidget-manager/libukui-appwidget-manager.pro0000664000175000017500000000216014456706513031371 0ustar adminadminQT -= gui QT += dbus TEMPLATE = lib DEFINES += LIBUKUIAPPWIDGETMANAGER_LIBRARY TARGET = ukui-appwidget-manager VERSION = 0.0.0 CONFIG += c++11 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS include(../../libukui-appwidget-common/libukui-appwidget-common.pri) # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ kappwidgetmanager.cpp HEADERS += \ libukui-appwidget-manager_global.h \ kappwidgetmanager.h # Default rules for deployment. unix { target.path = /usr/lib apifile.files = *.h apifile.path = /usr/include/ukui/ } !isEmpty(target.path): INSTALLS += target apifile ukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/0000775000175000017500000000000014461615267023477 5ustar adminadminukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/kappwidgetplugin.h0000664000175000017500000000205514461615267027230 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef LIBUKUIAPPWIDGET_PLUGIN_H #define LIBUKUIAPPWIDGET_PLUGIN_H #include class KAppWidgetPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) public: void registerTypes(const char *uri) override; }; #endif // LIBUKUIAPPWIDGET_PLUGIN_H ukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/kappwidgetconnect.cpp0000664000175000017500000001340514461615267027717 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "kappwidgetconnect.h" #include #include #include #include #include using namespace AppWidget; KAppWidgetConnect::KAppWidgetConnect(QObject *parent) : QObject(parent) { } KAppWidgetConnect::~KAppWidgetConnect() { KAppWidgetManager::getInstance()->unregisterAppWidget(m_id); if(m_gsettingmap.count() > 0) { qDeleteAll(m_gsettingmap); m_gsettingmap.clear(); } } void KAppWidgetConnect::onClickedEvent(const QString &widgetname, const QVariant &value) { qDebug() << __FILE__ << __FUNCTION__ << widgetname << " send clicked signal"; QDBusVariant variant; variant.setVariant(value); Q_EMIT clickedSignal(widgetname, variant); } void KAppWidgetConnect::onDefineEvent(const QString &eventname, const QString &widgetname, const QVariant &value) { qDebug() << __FILE__ << __FUNCTION__ << widgetname << "Send DefineEvent Signal" << value; QDBusVariant variant; variant.setVariant(value); Q_EMIT defineEventSignal(eventname, widgetname, variant); } void KAppWidgetConnect::registerAppWidget(const QString &appname, const QString &username) { initConnToManager(appname, username); registerAppWidgetDbus(username); KAppWidgetManager::getInstance()->notifyProviderUpdate(m_id); } void KAppWidgetConnect::initConnToManager(const QString &appname, const QString &username) { qDebug() << __FILE__ << __FUNCTION__ << "Register Appwidget Service: " << username << "," << appname; m_appname = appname; m_username = username; m_id = KAppWidgetManager::getInstance()->registerAppWidget(m_appname, m_username); updateAppWidget(); } void KAppWidgetConnect::registerAppWidgetDbus(const QString &username) { if (m_id == -1) { qCritical() << __FILE__ << __FUNCTION__ << "Init AppWidget Id Error: id = " << m_id; } QString object = KAppWidgetCommon::getAppWidgetDbusObject(username, m_id); QString objectpath = KAppWidgetCommon::getAppWidgetDbusPath(username, m_id); QDBusConnection sessionBus = QDBusConnection::sessionBus(); if (sessionBus.registerService(object)) { qDebug() << "Regist Dbus Service success"; sessionBus.registerObject(objectpath, this, QDBusConnection :: ExportAllSlots | QDBusConnection :: ExportAllSignals | QDBusConnection::ExportAllInvokables); } else { qCritical() << "Register DBus Service Error:" << sessionBus.lastError().message(); } } QMap KAppWidgetConnect::getData() { QMap reply = KAppWidgetManager::getInstance()->getAppWidgetData(m_id); qDebug() << __FILE__ << __FUNCTION__ << ": " << reply; return reply; } void KAppWidgetConnect::updateAppWidget() { Q_EMIT updatesignal(); } void KAppWidgetConnect::updateUserStatus(const QString &status) { Q_EMIT userStatusChanged(status); } bool KAppWidgetConnect::creatGsetting(const QString &gsetting) { if(gsetting.isEmpty()) { qWarning() << __FILE__ << __FUNCTION__ << "parameter is null"; return false; } if(m_gsettingmap.contains(gsetting)) { qWarning() << __FILE__ << __FUNCTION__ << gsetting << " gsetting isalready exists"; return false; } QByteArray id(gsetting.toLatin1()); if(QGSettings::isSchemaInstalled(id)) { QGSettings *gsettings = new QGSettings(id); m_gsettingmap.insert(gsetting, gsettings); connect(gsettings, &QGSettings::changed, [ = ](const QString & key) { qDebug() << "gsettings changed" << key; emit gsettingChanged(key, gsettings->get(key)); }); return true; } else { qDebug() << __FILE__ << __FUNCTION__ << gsetting << " gsetting is not install"; return false; } return true; } bool KAppWidgetConnect::deleteGsetting(const QString &gsetting) { if(gsetting.isEmpty()) { qWarning() << __FILE__ << __FUNCTION__ << "parameter is null"; return false; } if(!m_gsettingmap.contains(gsetting)) { qWarning() << __FILE__ << __FUNCTION__ << gsetting << " gsetting is not exists"; return false; } QGSettings *gsettings = m_gsettingmap.value(gsetting); gsettings->disconnect(); gsettings->deleteLater(); m_gsettingmap.remove(gsetting); return true; } QVariant KAppWidgetConnect::getGsettingValue(const QString &gsetting , const QString &key) { if(gsetting.isEmpty()) { qWarning() << __FILE__ << __FUNCTION__ << "first parameter is null"; return QVariant(); } if(key.isEmpty()) { qWarning() << __FILE__ << __FUNCTION__ << "second parameter is null"; return QVariant(); } QVariant value; QByteArray id(gsetting.toLatin1()); if(QGSettings::isSchemaInstalled(id)) { QGSettings *gsettings = new QGSettings(id); value = gsettings->get(key); gsettings->deleteLater(); }else { qWarning() << __FILE__ << __FUNCTION__ << gsetting << " gsetting is uninstall"; } return value; } ukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/qmldir0000664000175000017500000000007714413425621024704 0ustar adminadminmodule org.ukui.appwidget.private plugin ukui-appwidget-plugin ukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/translatorhelper.cpp0000664000175000017500000000254714461615267027604 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "translatorhelper.h" #include #include #include #include using namespace AppWidget; TranslatorHelper::TranslatorHelper(QObject *parent) : QObject(parent) { } void TranslatorHelper::installTranslators(const QString &appname) { QTranslator* translator = new QTranslator(this); QString key = QLocale::system().name(); QMap languageFiles = KAppWidgetManager::getInstance()->getAppWidgetLanguageFiles(appname); QString qmFile = languageFiles.value(key); translator->load(qmFile); qApp->installTranslator(translator); } ukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/translatorhelper.h0000664000175000017500000000217514461615267027246 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef TRANSLATORHELPER_H #define TRANSLATORHELPER_H #include namespace AppWidget { class KAppWidgetManager; class TranslatorHelper : public QObject { Q_OBJECT public: explicit TranslatorHelper(QObject *parent = nullptr); ~TranslatorHelper() = default; Q_INVOKABLE void installTranslators(const QString &appname); }; } //namespace AppWidget #endif // TRANSLATORHELPER_H ukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/kappwidgetplugin.cpp0000664000175000017500000000224414461615267027563 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "kappwidgetplugin.h" #include #include "kappwidgetconnect.h" #include "translatorhelper.h" void KAppWidgetPlugin::registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == QLatin1String("org.ukui.appwidget.private")); // @uri org.ukui.appwidget.private qmlRegisterType(uri, 1, 0, "Connection"); qmlRegisterType(uri, 1, 0, "Translator"); } ukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/kappwidgetconnect.h0000664000175000017500000000476714461615267027377 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef KAPPWIDGETCOMMUNICATION_H #define KAPPWIDGETCOMMUNICATION_H #include #include class QGSettings; namespace AppWidget { class KAppWidgetManager; class KAppWidgetConnect : public QObject { Q_OBJECT public: Q_CLASSINFO("D-Bus Interface", "org.ukui.appwidget") explicit KAppWidgetConnect(QObject *parent = nullptr); ~KAppWidgetConnect(); Q_INVOKABLE QMap getData(); Q_INVOKABLE bool creatGsetting(const QString &gsetting); Q_INVOKABLE bool deleteGsetting(const QString &gsetting); Q_INVOKABLE QVariant getGsettingValue(const QString &gsetting , const QString &key); Q_INVOKABLE void registerAppWidget(const QString &appname, const QString &username); signals: void clickedSignal(const QString &widgetname, const QDBusVariant &value); void defineEventSignal(const QString &eventname, const QString &widgetname, const QDBusVariant &value); void updatesignal(); void gsettingChanged(const QString &key, const QVariant &value); void userStatusChanged(const QString &status); public slots: void onClickedEvent(const QString &widgetname, const QVariant &value); void onDefineEvent(const QString &eventname, const QString &widgetname, const QVariant &value); void updateAppWidget(); void updateUserStatus(const QString &status); private: void initConnToManager(const QString &appname, const QString &username); void registerAppWidgetDbus(const QString &username); QString m_appname; QString m_username; int m_id = -1; /** * @brief gsettings容器,QMap键值对说明<生成的QGSettings的schema_id, 生成的QGSettings *对象> */ QMap m_gsettingmap; }; } // namespace AppWidget #endif // KAPPWIDGETCOMMUNICATION_H ukui-app-widget/libukui-app-widget/libukui-appwidget-plugin/libukui-appwidget-plugin.pro0000664000175000017500000000232114461605317031134 0ustar adminadminTEMPLATE = lib TARGET = ukui-appwidget-plugin VERSION = 0.0.0 QT += qml quick dbus CONFIG += plugin c++11 link_pkgconfig PKGCONFIG += gsettings-qt LIBS +=-L../libukui-appwidget-manager/ -lukui-appwidget-manager INCLUDEPATH += ../libukui-appwidget-manager/ DEPENDPATH += ../libukui-appwidget-manager/ TARGET = $$qtLibraryTarget($$TARGET) uri = org.ukui.appwidget.private include(../../libukui-appwidget-common/libukui-appwidget-common.pri) # Input SOURCES += \ kappwidgetconnect.cpp \ kappwidgetplugin.cpp \ translatorhelper.cpp HEADERS += \ kappwidgetconnect.h \ kappwidgetplugin.h \ translatorhelper.h DISTFILES = qmldir !equals(_PRO_FILE_PWD_, $$OUT_PWD) { copy_qmldir.target = $$OUT_PWD/qmldir copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir copy_qmldir.commands = $(COPY_FILE) "$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)" "$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)" QMAKE_EXTRA_TARGETS += copy_qmldir PRE_TARGETDEPS += $$copy_qmldir.target } qmldir.files = qmldir unix { installPath = $$[QT_INSTALL_LIBS]/qt5/qml/org/ukui/appwidget/private qmldir.path = $$installPath target.path = $$installPath INSTALLS += target qmldir } ukui-app-widget/libukui-app-widget/org.ukui.appwidget/0000775000175000017500000000000014461615267022303 5ustar adminadminukui-app-widget/libukui-app-widget/org.ukui.appwidget/qmldir0000664000175000017500000000006614413425621023506 0ustar adminadminmodule org.ukui.appwidget AppWidget 1.0 AppWidget.qml ukui-app-widget/libukui-app-widget/org.ukui.appwidget/AppWidget.qml0000664000175000017500000000642114461615267024705 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ import QtQuick 2.0 import org.ukui.appwidget.private 1.0 as UKUIAppWidget Item { id:controlroot UKUIAppWidget.Connection { id:appwidget } UKUIAppWidget.Translator { id:translator } signal qmldefineeventchangedsignal(string eventname, string widgetname, var value); signal qmlclickedsignal(string widgetname, var value); signal update(); signal gsettingUpdate(string key, var value); signal userStatusChangedSignal(string status); property string appname property string username property var datavalue property string userstatus: "Normal" onAppnameChanged: { translator.installTranslators(appname) } Component.onCompleted: { appwidget.updatesignal.connect(controlroot.qmlUpdate) qmlclickedsignal.connect(appwidget.onClickedEvent) qmldefineeventchangedsignal.connect(appwidget.onDefineEvent) appwidget.gsettingChanged.connect(controlroot.gsettingChanged) appwidget.userStatusChanged.connect(controlroot.userStatusChanged) } function qmlUpdate() { datavalue = appwidget.getData(); update(); } function register(appname, username) { appwidget.registerAppWidget(appname, username); console.log(" QML AppWidget register dbus"); } function creatGsetting(gsettingname) { console.log(" QML AppWidget creatGsetting", gsettingname); if(appwidget.creatGsetting(gsettingname)) { console.log(" QML AppWidget register gsetting successful"); }else { console.log(" QML AppWidget register gsetting fail"); } } function deleteGsetting(gsettingname) { console.log(" QML AppWidget deleteGsetting", gsettingname); if(appwidget.deleteGsetting(gsettingname)) { console.log(" QML AppWidget delete gsetting successful"); }else { console.log(" QML AppWidget delete gsetting fail"); } } function getGsettingValue(gsettingname, key) { console.log(" QML AppWidget getGsettingValue", gsettingname, key, appwidget.getGsettingValue(gsettingname, key)); return appwidget.getGsettingValue(gsettingname, key); } function gsettingChanged(key, value) { console.log(" QML AppWidget gsettingChanged", key,value) gsettingUpdate(key, value); } function userStatusChanged(status) { console.log(" QML AppWidget usersStatusChanged", status, " appname: ", appwidget.appname) userStatusChangedSignal(status) userstatus = status } } ukui-app-widget/libukui-app-widget/libukui-app-widget.pro0000664000175000017500000000065714456706513023011 0ustar adminadminTEMPLATE = subdirs SUBDIRS += \ libukui-appwidget-plugin \ libukui-appwidget-manager \ libukui-appwidget-provider #编译依赖顺序 libukui-appwidget-plugin.depends += libukui-appwidget-manager unix { installPath = $$[QT_INSTALL_LIBS]/qt5/qml/org/ukui/appwidget/ # installPath = /usr/share/appwidget/qml/ template.files = org.ukui.appwidget/* template.path = $$installPath INSTALLS += template } ukui-app-widget/ukui-appwidget-manager/0000775000175000017500000000000014461615267017421 5ustar adminadminukui-app-widget/ukui-appwidget-manager/appwidgetmanager.cpp0000664000175000017500000002032414461615267023445 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "appwidgetmanager.h" #include "appwidgetproviderproxy.h" #include "appwidgetproxy.h" #include "mappingmanager.h" #include "appwidgetconfiguration.h" #include #include #include #include namespace AppWidget { AppWidgetManager::AppWidgetManager(QObject *parent) : QObject(parent), m_mappingmanager(new MappingManager(this)), m_configmanager(new AppWidgetConfiguration(this)) { qDBusRegisterMetaType>(); registerCommunicationService(); } AppWidgetManager::~AppWidgetManager() { } //public slots QStringList AppWidgetManager::getAppWidgetList() { QStringList appwidgetlist; QDir dirinfo = QDir(APP_WIDGET_LIST); if (!dirinfo.exists()) { return QStringList(); } QStringList filename ; filename << "*.qml"; QStringList results; results = dirinfo.entryList(filename, QDir::Files, QDir::Name); for(int i=0; igetAppWidgetUiFile(appwidgetname); } QString AppWidgetManager::getAppWidgetConfig(QString appwidgetname, QString config) { if (appwidgetname.isEmpty() || config.isEmpty()) { return QString(); } return m_configmanager->getAppWidgetConfig(appwidgetname, config); } QMap AppWidgetManager::getAppWidgetConfigs(QString appwidgetname) { if (appwidgetname.isEmpty()) { return QMap(); } return m_configmanager->getAppWidgetConfigs(appwidgetname, "AppWidget"); } QMap AppWidgetManager::getAppWidgetLanguageFiles(QString appwidgetname) { if (appwidgetname.isEmpty()) { return QMap(); } QMap languageFiles = m_configmanager->getAppWidgetConfigs(appwidgetname, "LanguageFiles"); QMap appWidgetLanguageFiles; for (auto it = languageFiles.begin(); it != languageFiles.end(); ++it) { appWidgetLanguageFiles.insert(it.key(), it.value().toString()); } return appWidgetLanguageFiles; } int AppWidgetManager::registerAppWidget(QString appwidgetname,QString username) { if (appwidgetname.isEmpty() | username.isEmpty()) { return -1; } QString providername = m_configmanager->getProviderNameByAppWidgetName(appwidgetname); if (providername==NULL) { return -1; } AppWidgetProviderProxy* providerproxy = m_mappingmanager->findProviderProxyByProviderName(providername); if (!providerproxy) { providerproxy = createProviderProxy(providername); } AppWidgetProxy* appwidget = createAppWidgetProxy(providerproxy, appwidgetname, username); if (!appwidget) { return -1; } return appwidget->getAppWidgetProxyId(); } bool AppWidgetManager::unregisterAppWidget(int appwidgetid) { AppWidgetProviderProxy* providerproxy = m_mappingmanager->findProviderProxyByAppWidgetId(appwidgetid); if (!providerproxy) { qWarning() << __FILE__ << __FUNCTION__ << "Providerproxy is null"; return true; } if (deleteAppWidgetProxy(providerproxy, appwidgetid)) { if (providerproxy->appWidgetProxyIsEmpty()) { deleteProviderProxy(providerproxy); } }else { return false; } return true; } QMap AppWidgetManager::getAppWidgetData(int appwidgetid) { AppWidgetProviderProxy* providerproxy = m_mappingmanager->findProviderProxyByAppWidgetId(appwidgetid); if (!providerproxy) { return QMap(); } return providerproxy->getAppWidgetProviderProxyData(); } void AppWidgetManager::updateAppWidget(QString providername, QMap data) { qDebug() << __FILE__ << __FUNCTION__ << ": Providername = " << providername; AppWidgetProviderProxy * providerproxy = m_mappingmanager->findProviderProxyByProviderName(providername); if (!providerproxy) { return ; } providerproxy->updateAppWidgetProviderProxyData(data); } void AppWidgetManager::updateUserStatus(QString username, QString status) { QVector appvec = m_mappingmanager->findAppWidgetProxyByUserName(username); for (int var = 0; var < appvec.size(); ++var) { appvec.at(var)->updateUserStatus(status); } } void AppWidgetManager::notifyProviderUpdate(int id) { AppWidgetProviderProxy* providerproxy = m_mappingmanager->findProviderProxyByAppWidgetId(id); providerproxy->appWidgetUpdate(); } void AppWidgetManager::registerCommunicationService() { QDBusConnection systembus = QDBusConnection::sessionBus(); QString object = KAppWidgetCommon::getManagerDbusObject(); QString objectPath = KAppWidgetCommon::getManagerDbusPath(); QString interface = KAppWidgetCommon::getManagerDbusInterface(); if (systembus.registerService(object)) { qDebug() << "Regist Dbus Service success"; systembus.registerObject(objectPath, interface, this, QDBusConnection :: ExportAllSlots | QDBusConnection :: ExportAllSignals); } else qCritical() << "Register DBus Service Error:" << systembus.lastError().message(); } bool AppWidgetManager::registerScheduledUpdate(AppWidgetProviderProxy* providerproxy , int timingperiod) { //! \todo init Q_UNUSED(providerproxy); Q_UNUSED(timingperiod); return false; } bool AppWidgetManager::unregisterScheduledUpdate(AppWidgetProviderProxy* providerproxy) { //! \todo init Q_UNUSED(providerproxy); return false; } AppWidgetProviderProxy* AppWidgetManager::createProviderProxy(QString providername) { AppWidgetProviderProxy* providerproxy = m_mappingmanager->createProviderProxy(providername); if (!providerproxy) { qWarning() << __FILE__ << __FUNCTION__ << "providerproxy is null"; return nullptr; } providerproxy->appWidgetEnable(); return providerproxy; } void AppWidgetManager::deleteProviderProxy(AppWidgetProviderProxy* providerproxy) { if (!providerproxy) { qWarning() << __FILE__ << __FUNCTION__ << "providerproxy is null"; return; } providerproxy->appWidgetDisable(); // if(通过配置管理查看配置是否注册定时任务){ // unregisterScheduledUpdate(providerproxy); // } m_mappingmanager->destroyProviderProxy(providerproxy); } AppWidgetProxy* AppWidgetManager::createAppWidgetProxy(AppWidgetProviderProxy* providerproxy, QString appwidgetname, QString username) { if (!providerproxy) { qWarning() << __FILE__ << __FUNCTION__ << "providerproxy is null"; return nullptr ; } AppWidgetProxy* appwidgetproxy = providerproxy->createAppWidgetProxy(appwidgetname, username); if (!appwidgetproxy) { qWarning() << __FILE__ << __FUNCTION__ << "appwidgetproxy is null"; return nullptr; } appwidgetproxy->setProviderProxy(providerproxy); return appwidgetproxy; } bool AppWidgetManager::deleteAppWidgetProxy(AppWidgetProviderProxy* providerproxy, int id) { qDebug() << __FILE__ << __FUNCTION__ << "delete appwidget`s id:" << id; if (!providerproxy) { qWarning() << __FILE__ << __FUNCTION__ << "providerproxy is null"; return false; } if (providerproxy->destroyAppWidgetProxy(id)) { providerproxy->appWidgetDeleted(); } else { return false; } return true; } } // namespace AppWidget ukui-app-widget/ukui-appwidget-manager/appwidgetproviderproxy.h0000664000175000017500000000426314461615267024440 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef APPWIDGETPROVIDERPROXY_H #define APPWIDGETPROVIDERPROXY_H #include #include namespace AppWidget { class AppWidgetProxy; class AppWidgetProviderProxy : public QDBusInterface { Q_OBJECT public: AppWidgetProviderProxy(int id, QString providerName); ~AppWidgetProviderProxy(); void updateAppWidgetProviderProxyData(QMap data); QMap getAppWidgetProviderProxyData(); AppWidgetProxy* createAppWidgetProxy(QString appwidgetname, QString username); bool destroyAppWidgetProxy(int id); int* getAllAppWidgetIds(); void appWidgetRecevie(QString eventname, QString widgetname, QDBusVariant value); void appWidgetUpdate(); void appWidgetDisable(); void appWidgetDeleted(); void appWidgetEnable(); void appWidgetClicked(QString widgetname, QDBusVariant value); bool appWidgetProxyIsEmpty(); AppWidgetProxy* getAppWidgetProxy(int id); int getAppWidgetProviderProxyIndex(); QString getAppWidgetProviderProxyProviderName(); QVector getAppwidgetProxyByUser(QString username); private: bool addAppWidgetProxy(int index, AppWidgetProxy* appwidgetproxy); bool deleteAppWidgetProxy(int index); int getUsableIndex(); private: QMap m_data; QVector m_appwidgetproxy; int m_index; QString m_providername; }; } // namespace AppWidget #endif // APPWIDGETPROVIDERPROXY_H ukui-app-widget/ukui-appwidget-manager/ukui-appwidget-manager.pro0000664000175000017500000000321314461605317024504 0ustar adminadminQT += core gui dbus greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 link_pkgconfig # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS DEFINES += APP_WIDGET_LIST=\\\"/usr/share/appwidget/qml\\\" # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 include(QtSingleApplication/qtsingleapplication.pri) include(../libukui-appwidget-common/libukui-appwidget-common.pri) SOURCES += \ appwidgetconfiguration.cpp \ appwidgetproviderproxy.cpp \ appwidgetproxy.cpp \ main.cpp \ appwidgetmanager.cpp \ mappingmanager.cpp HEADERS += \ appwidgetcommon.h \ appwidgetconfiguration.h \ appwidgetmanager.h \ appwidgetproviderproxy.h \ appwidgetproxy.h \ mappingmanager.h # Default rules for deployment. target.path = /usr/bin/ managerservice.files += data/org.ukui.appwidget.manager.service managerservice.path += /usr/share/dbus-1/services/ desktop.files += data/ukui-appwidget-manager.desktop desktop.path += /etc/xdg/autostart/ INSTALLS += target managerservice desktop DISTFILES += \ data/org.ukui.appwidget.manager.service \ data/ukui-appwidget-manager.desktop LIBS += -lukui-log4qt ukui-app-widget/ukui-appwidget-manager/appwidgetmanager.h0000664000175000017500000000545414461615267023121 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef APPWIDGETMANAGER_H #define APPWIDGETMANAGER_H #include #include namespace AppWidget { class AppWidgetProviderProxy; class AppWidgetProxy; class MappingManager; class AppWidgetConfiguration; class AppWidgetManager : public QObject { Q_OBJECT public: explicit AppWidgetManager(QObject *parent = nullptr); ~AppWidgetManager(); public slots: QStringList getAppWidgetList(); QString getAppWidgetUiFile(QString appwidgetname); QString getAppWidgetConfig(QString appwidgetname, QString config); QMap getAppWidgetConfigs(QString appwidgetname); QMap getAppWidgetLanguageFiles(QString appwidgetname); int registerAppWidget(QString appwidgetname, QString username); bool unregisterAppWidget(int appwidgetid); QMap getAppWidgetData(int appwidgetid); void updateAppWidget(QString providername, QMap data); void updateUserStatus(QString username, QString status); void notifyProviderUpdate(int id); signals: void appWidgetFileAdded(QString appwidgetname); void appWidgetFileDeleted (QString appwidgetname); //void appWidgetDataChanged(int ids); private: void registerCommunicationService();//注册dbus服务 bool registerScheduledUpdate(AppWidgetProviderProxy* providerproxy, int timingperiod);//注册定时更新 bool unregisterScheduledUpdate(AppWidgetProviderProxy* providerproxy);//注销定时更新 AppWidgetProviderProxy* createProviderProxy(QString providername); void deleteProviderProxy(AppWidgetProviderProxy* providerproxy); AppWidgetProxy* createAppWidgetProxy(AppWidgetProviderProxy* providerproxy, QString appwidgetname, QString username); bool deleteAppWidgetProxy(AppWidgetProviderProxy* providerproxy, int id); //定时更新 //映射管理 MappingManager* m_mappingmanager = nullptr; //小插件列表管理 //小插件配置管理 AppWidgetConfiguration * m_configmanager = nullptr; }; } // namespace AppWidget Q_DECLARE_METATYPE(QString) #endif // APPWIDGETMANAGER_H ukui-app-widget/ukui-appwidget-manager/appwidgetconfiguration.cpp0000664000175000017500000000745514461615267024714 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "appwidgetconfiguration.h" #include #include #include namespace AppWidget { AppWidgetConfiguration::AppWidgetConfiguration(QObject *parent) : QObject(parent) { //! \todo init } QString AppWidgetConfiguration::getProviderNameByAppWidgetName(const QString &appwidgetname) { if(appwidgetname.isEmpty()) { qWarning() << __FILE__ << __FUNCTION__ << "parameter is empty"; return QString(); } QString path = QString("/usr/share/appwidget/config/%1.conf").arg(appwidgetname); QSettings setting(path, QSettings::IniFormat); setting.beginGroup("AppWidget"); QString providerName = setting.value("providerName").toString(); qDebug() << __FILE__ << __FUNCTION__ << appwidgetname << " `s appwidgetname is :" < AppWidgetConfiguration::getAppWidgetConfigs(const QString &appwidgetname, QString begianName) { if(appwidgetname.isEmpty()) { qWarning() << __FILE__ << __FUNCTION__ << "parameter is empty"; return QMap(); } QMap configs; QString path = QString("/usr/share/appwidget/config/%1.conf").arg(appwidgetname); QSettings setting(path, QSettings::IniFormat); setting.beginGroup(begianName); QStringList keylist = setting.allKeys(); for (int i = 0; i < keylist.count(); i++) { configs.insert(keylist.at(i),setting.value(keylist.at(i))); } setting.endGroup(); setting.sync(); return configs; } QString AppWidgetConfiguration::getConfigurationByKey(const QString &path, const QString &key) { if(path.isEmpty() || key.isEmpty()) { qWarning() << __FILE__ << __FUNCTION__ << "parameter is empty"; return QString(); } QSettings setting(path, QSettings::IniFormat); setting.setIniCodec(QTextCodec::codecForName("utf-8")); setting.beginGroup("AppWidget"); QString value = setting.value(key).toString(); setting.endGroup(); setting.sync(); return value; } } // namespace AppWidget ukui-app-widget/ukui-appwidget-manager/mappingmanager.h0000664000175000017500000000335414461615267022565 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef MAPPINGMANAGER_H #define MAPPINGMANAGER_H #include #include #include namespace AppWidget { class AppWidgetProviderProxy; class AppWidgetProxy; class MappingManager:public QObject { Q_OBJECT public: MappingManager(QObject *parent = nullptr); ~MappingManager(); AppWidgetProviderProxy* findProviderProxyByProviderName(const QString providername); AppWidgetProviderProxy* findProviderProxyByAppWidgetId(int id); AppWidgetProxy* findAppWidgetProxyByAppWidgetId(int id); QVector findAppWidgetProxyByUserName(QString username); AppWidgetProviderProxy* createProviderProxy(QString providername); void destroyProviderProxy(AppWidgetProviderProxy* providerproxy); private: int getUsableIndex(); void addProviderProxy(int index, AppWidgetProviderProxy* providerproxy); void deleteProviderProxy(int index); private: QVector m_providerproxy; }; } // namespace AppWidget #endif // MAPPINGMANAGER_H ukui-app-widget/ukui-appwidget-manager/appwidgetproxy.h0000664000175000017500000000355514461615267022670 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef APPWIDGETPROXY_H #define APPWIDGETPROXY_H #include namespace AppWidget { class AppWidgetProviderProxy; class AppWidgetProxy : public QDBusInterface { Q_OBJECT public: AppWidgetProxy(int id, QString appwidgetname, QString appwidgetuser); ~AppWidgetProxy(); void updateAppWidget(); void updateUserStatus(QString status); void updateAppWidgetOptions(QVariant key, QVariant value); bool updateAppWidgetSize(QSize); int getAppWidgetProxyId(); QString getAppWidgetProxyAppWidgetName(); QString getAppWidgetProxyUserName(); void setProviderProxy(AppWidgetProviderProxy * providerproxy); public slots: void onClicked(QString widgetname, QDBusVariant value); void onDefineSignalType(QString eventname, QString widgetname, QDBusVariant value); private: int m_id ; QString m_appwidgetname; QString m_username; AppWidgetProviderProxy* m_provider; signals: void clickedSignal(QString widgetname, QDBusVariant value); void defineEventSignal(QString eventname, QString widgetname, QDBusVariant value); }; } // namespace AppWidget #endif // APPWIDGETPROXY_H ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/0000775000175000017500000000000014456706513023332 5ustar adminadminukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtlockedfile_unix.cpp0000664000175000017500000000661414456706513027556 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include #include #include #include "qtlockedfile.h" bool QtLockedFile::lock(LockMode mode, bool block) { if (!isOpen()) { qWarning("QtLockedFile::lock(): file is not opened"); return false; } if (mode == NoLock) return unlock(); if (mode == m_lock_mode) return true; if (m_lock_mode != NoLock) unlock(); struct flock fl; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; int cmd = block ? F_SETLKW : F_SETLK; int ret = fcntl(handle(), cmd, &fl); if (ret == -1) { if (errno != EINTR && errno != EAGAIN) qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); return false; } m_lock_mode = mode; return true; } bool QtLockedFile::unlock() { if (!isOpen()) { qWarning("QtLockedFile::unlock(): file is not opened"); return false; } if (!isLocked()) return true; struct flock fl; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; fl.l_type = F_UNLCK; int ret = fcntl(handle(), F_SETLKW, &fl); if (ret == -1) { qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); return false; } m_lock_mode = NoLock; return true; } QtLockedFile::~QtLockedFile() { if (isOpen()) unlock(); } ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtsingleapplication.pri0000664000175000017500000000106114456706513030116 0ustar adminadminINCLUDEPATH += $$PWD DEPENDPATH += $$PWD QT *= network greaterThan(QT_MAJOR_VERSION, 4): QT *= widgets qtsingleapplication-uselib:!qtsingleapplication-buildlib { LIBS += -L$$QTSINGLEAPPLICATION_LIBDIR -l$$QTSINGLEAPPLICATION_LIBNAME } else { SOURCES += $$PWD/qtsingleapplication.cpp $$PWD/qtlocalpeer.cpp HEADERS += $$PWD/qtsingleapplication.h $$PWD/qtlocalpeer.h } win32 { contains(TEMPLATE, lib):contains(CONFIG, shared):DEFINES += QT_QTSINGLEAPPLICATION_EXPORT else:qtsingleapplication-uselib:DEFINES += QT_QTSINGLEAPPLICATION_IMPORT } ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/QtLockedFile0000664000175000017500000000003214456706513025556 0ustar adminadmin#include "qtlockedfile.h" ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtlocalpeer.h0000664000175000017500000000520514456706513026020 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QTLOCALPEER_H #define QTLOCALPEER_H #include #include #include #include "qtlockedfile.h" class QtLocalPeer : public QObject { Q_OBJECT public: QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); bool isClient(); bool sendMessage(const QString &message, int timeout); QString applicationId() const { return id; } Q_SIGNALS: void messageReceived(const QString &message); protected Q_SLOTS: void receiveConnection(); protected: QString id; QString socketName; QLocalServer* server; QtLP_Private::QtLockedFile lockFile; private: static const char* ack; }; #endif // QTLOCALPEER_H ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtsinglecoreapplication.h0000664000175000017500000000502514456706513030430 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QTSINGLECOREAPPLICATION_H #define QTSINGLECOREAPPLICATION_H #include class QtLocalPeer; class QtSingleCoreApplication : public QCoreApplication { Q_OBJECT public: QtSingleCoreApplication(int &argc, char **argv); QtSingleCoreApplication(const QString &id, int &argc, char **argv); bool isRunning(); QString id() const; public Q_SLOTS: bool sendMessage(const QString &message, int timeout = 5000); Q_SIGNALS: void messageReceived(const QString &message); private: QtLocalPeer* peer; }; #endif // QTSINGLECOREAPPLICATION_H ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtlocalpeer.cpp0000664000175000017500000001543614456706513026362 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qtlocalpeer.h" #include #include #include #if defined(Q_OS_WIN) #include #include typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*); static PProcessIdToSessionId pProcessIdToSessionId = 0; #endif #if defined(Q_OS_UNIX) #include #include #include #endif namespace QtLP_Private { #include "qtlockedfile.cpp" #if defined(Q_OS_WIN) #include "qtlockedfile_win.cpp" #else #include "qtlockedfile_unix.cpp" #endif } const char* QtLocalPeer::ack = "ack"; QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) : QObject(parent), id(appId) { QString prefix = id; if (id.isEmpty()) { id = QCoreApplication::applicationFilePath(); #if defined(Q_OS_WIN) id = id.toLower(); #endif prefix = id.section(QLatin1Char('/'), -1); } prefix.remove(QRegExp("[^a-zA-Z]")); prefix.truncate(6); QByteArray idc = id.toUtf8(); quint16 idNum = qChecksum(idc.constData(), idc.size()); socketName = QLatin1String("qtsingleapp-") + prefix + QLatin1Char('-') + QString::number(idNum, 16); #if defined(Q_OS_WIN) if (!pProcessIdToSessionId) { QLibrary lib("kernel32"); pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId"); } if (pProcessIdToSessionId) { DWORD sessionId = 0; pProcessIdToSessionId(GetCurrentProcessId(), &sessionId); socketName += QLatin1Char('-') + QString::number(sessionId, 16); } #else socketName += QLatin1Char('-') + QString::number(::getuid(), 16); #endif server = new QLocalServer(this); QString lockName = QDir(QDir::tempPath()).absolutePath() + QLatin1Char('/') + socketName + QLatin1String("-lockfile"); lockFile.setFileName(lockName); lockFile.open(QIODevice::ReadWrite); } bool QtLocalPeer::isClient() { if (lockFile.isLocked()) return false; if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) return true; bool res = server->listen(socketName); #if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) // ### Workaround if (!res && server->serverError() == QAbstractSocket::AddressInUseError) { QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName); res = server->listen(socketName); } #endif if (!res) qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection())); return false; } bool QtLocalPeer::sendMessage(const QString &message, int timeout) { if (!isClient()) return false; QLocalSocket socket; bool connOk = false; for(int i = 0; i < 2; i++) { // Try twice, in case the other instance is just starting up socket.connectToServer(socketName); connOk = socket.waitForConnected(timeout/2); if (connOk || i) break; int ms = 250; #if defined(Q_OS_WIN) Sleep(DWORD(ms)); #else struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; nanosleep(&ts, NULL); #endif } if (!connOk) return false; QByteArray uMsg(message.toUtf8()); QDataStream ds(&socket); ds.writeBytes(uMsg.constData(), uMsg.size()); bool res = socket.waitForBytesWritten(timeout); if (res) { res &= socket.waitForReadyRead(timeout); // wait for ack if (res) res &= (socket.read(qstrlen(ack)) == ack); } return res; } void QtLocalPeer::receiveConnection() { QLocalSocket* socket = server->nextPendingConnection(); if (!socket) return; while (true) { if (socket->state() == QLocalSocket::UnconnectedState) { qWarning("QtLocalPeer: Peer disconnected"); delete socket; return; } if (socket->bytesAvailable() >= qint64(sizeof(quint32))) break; socket->waitForReadyRead(); } QDataStream ds(socket); QByteArray uMsg; quint32 remaining; ds >> remaining; uMsg.resize(remaining); int got = 0; char* uMsgBuf = uMsg.data(); do { got = ds.readRawData(uMsgBuf, remaining); remaining -= got; uMsgBuf += got; } while (remaining && got >= 0 && socket->waitForReadyRead(2000)); if (got < 0) { qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData()); delete socket; return; } QString message(QString::fromUtf8(uMsg)); socket->write(ack, qstrlen(ack)); socket->waitForBytesWritten(1000); socket->waitForDisconnected(1000); // make sure client reads ack delete socket; Q_EMIT messageReceived(message); //### (might take a long time to return) } ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtsinglecoreapplication.cpp0000664000175000017500000001235514456706513030767 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qtsinglecoreapplication.h" #include "qtlocalpeer.h" /*! \class QtSingleCoreApplication qtsinglecoreapplication.h \brief A variant of the QtSingleApplication class for non-GUI applications. This class is a variant of QtSingleApplication suited for use in console (non-GUI) applications. It is an extension of QCoreApplication (instead of QApplication). It does not require the QtGui library. The API and usage is identical to QtSingleApplication, except that functions relating to the "activation window" are not present, for obvious reasons. Please refer to the QtSingleApplication documentation for explanation of the usage. A QtSingleCoreApplication instance can communicate to a QtSingleApplication instance if they share the same application id. Hence, this class can be used to create a light-weight command-line tool that sends commands to a GUI application. \sa QtSingleApplication */ /*! Creates a QtSingleCoreApplication object. The application identifier will be QCoreApplication::applicationFilePath(). \a argc and \a argv are passed on to the QCoreAppliation constructor. */ QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv) : QCoreApplication(argc, argv) { peer = new QtLocalPeer(this); connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); } /*! Creates a QtSingleCoreApplication object with the application identifier \a appId. \a argc and \a argv are passed on to the QCoreAppliation constructor. */ QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv) : QCoreApplication(argc, argv) { peer = new QtLocalPeer(this, appId); connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); } /*! Returns true if another instance of this application is running; otherwise false. This function does not find instances of this application that are being run by a different user (on Windows: that are running in another session). \sa sendMessage() */ bool QtSingleCoreApplication::isRunning() { return peer->isClient(); } /*! Tries to send the text \a message to the currently running instance. The QtSingleCoreApplication object in the running instance will emit the messageReceived() signal when it receives the message. This function returns true if the message has been sent to, and processed by, the current instance. If there is no instance currently running, or if the running instance fails to process the message within \a timeout milliseconds, this function return false. \sa isRunning(), messageReceived() */ bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout) { return peer->sendMessage(message, timeout); } /*! Returns the application identifier. Two processes with the same identifier will be regarded as instances of the same application. */ QString QtSingleCoreApplication::id() const { return peer->applicationId(); } /*! \fn void QtSingleCoreApplication::messageReceived(const QString& message) This signal is emitted when the current instance receives a \a message from another instance of this application. \sa sendMessage() */ ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/QtSingleApplication0000664000175000017500000000004114456706513027162 0ustar adminadmin#include "qtsingleapplication.h" ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtsingleapplication.cpp0000664000175000017500000002674214456706513030123 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qtsingleapplication.h" #include "qtlocalpeer.h" //#include #include #include #include #include #include /*! \class QtSingleApplication qtsingleapplication.h \brief The QtSingleApplication class provides an API to detect and communicate with running instances of an application. This class allows you to create applications where only one instance should be running at a time. I.e., if the user tries to launch another instance, the already running instance will be activated instead. Another usecase is a client-server system, where the first started instance will assume the role of server, and the later instances will act as clients of that server. By default, the full path of the executable file is used to determine whether two processes are instances of the same application. You can also provide an explicit identifier string that will be compared instead. The application should create the QtSingleApplication object early in the startup phase, and call isRunning() to find out if another instance of this application is already running. If isRunning() returns false, it means that no other instance is running, and this instance has assumed the role as the running instance. In this case, the application should continue with the initialization of the application user interface before entering the event loop with exec(), as normal. The messageReceived() signal will be emitted when the running application receives messages from another instance of the same application. When a message is received it might be helpful to the user to raise the application so that it becomes visible. To facilitate this, QtSingleApplication provides the setActivationWindow() function and the activateWindow() slot. If isRunning() returns true, another instance is already running. It may be alerted to the fact that another instance has started by using the sendMessage() function. Also data such as startup parameters (e.g. the name of the file the user wanted this new instance to open) can be passed to the running instance with this function. Then, the application should terminate (or enter client mode). If isRunning() returns true, but sendMessage() fails, that is an indication that the running instance is frozen. Here's an example that shows how to convert an existing application to use QtSingleApplication. It is very simple and does not make use of all QtSingleApplication's functionality (see the examples for that). \code // Original int main(int argc, char **argv) { QApplication app(argc, argv); MyMainWidget mmw; mmw.show(); return app.exec(); } // Single instance int main(int argc, char **argv) { QtSingleApplication app(argc, argv); if (app.isRunning()) return !app.sendMessage(someDataString); MyMainWidget mmw; app.setActivationWindow(&mmw); mmw.show(); return app.exec(); } \endcode Once this QtSingleApplication instance is destroyed (normally when the process exits or crashes), when the user next attempts to run the application this instance will not, of course, be encountered. The next instance to call isRunning() or sendMessage() will assume the role as the new running instance. For console (non-GUI) applications, QtSingleCoreApplication may be used instead of this class, to avoid the dependency on the QtGui library. \sa QtSingleCoreApplication */ void QtSingleApplication::sysInit(const QString &appId) { actObj = 0; peer = new QtLocalPeer(this, appId); connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); } /*! Creates a QtSingleApplication object. The application identifier will be QCoreApplication::applicationFilePath(). \a argc, \a argv, and \a GUIenabled are passed on to the QAppliation constructor. If you are creating a console application (i.e. setting \a GUIenabled to false), you may consider using QtSingleCoreApplication instead. */ QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled) : QApplication(argc, argv, GUIenabled) { sysInit(); } /*! Creates a QtSingleApplication object with the application identifier \a appId. \a argc and \a argv are passed on to the QAppliation constructor. */ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv) : QApplication(argc, argv) { sysInit(appId); } #if QT_VERSION < 0x050000 /*! Creates a QtSingleApplication object. The application identifier will be QCoreApplication::applicationFilePath(). \a argc, \a argv, and \a type are passed on to the QAppliation constructor. */ QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) : QApplication(argc, argv, type) { sysInit(); } # if defined(Q_WS_X11) /*! Special constructor for X11, ref. the documentation of QApplication's corresponding constructor. The application identifier will be QCoreApplication::applicationFilePath(). \a dpy, \a visual, and \a cmap are passed on to the QApplication constructor. */ QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap) : QApplication(dpy, visual, cmap) { sysInit(); } /*! Special constructor for X11, ref. the documentation of QApplication's corresponding constructor. The application identifier will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a argv, \a visual, and \a cmap are passed on to the QApplication constructor. */ QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) : QApplication(dpy, argc, argv, visual, cmap) { sysInit(); } /*! Special constructor for X11, ref. the documentation of QApplication's corresponding constructor. The application identifier will be \a appId. \a dpy, \a argc, \a argv, \a visual, and \a cmap are passed on to the QApplication constructor. */ QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) : QApplication(dpy, argc, argv, visual, cmap) { sysInit(appId); } # endif // Q_WS_X11 #endif // QT_VERSION < 0x050000 /*! Returns true if another instance of this application is running; otherwise false. This function does not find instances of this application that are being run by a different user (on Windows: that are running in another session). \sa sendMessage() */ bool QtSingleApplication::isRunning() { return peer->isClient(); } /*! Tries to send the text \a message to the currently running instance. The QtSingleApplication object in the running instance will emit the messageReceived() signal when it receives the message. This function returns true if the message has been sent to, and processed by, the current instance. If there is no instance currently running, or if the running instance fails to process the message within \a timeout milliseconds, this function return false. \sa isRunning(), messageReceived() */ bool QtSingleApplication::sendMessage(const QString &message, int timeout) { return peer->sendMessage(message, timeout); } /*! Returns the application identifier. Two processes with the same identifier will be regarded as instances of the same application. */ QString QtSingleApplication::id() const { return peer->applicationId(); } /*! Sets the activation window of this application to \a aw. The activation window is the widget that will be activated by activateWindow(). This is typically the application's main window. If \a activateOnMessage is true (the default), the window will be activated automatically every time a message is received, just prior to the messageReceived() signal being emitted. \sa activateWindow(), messageReceived() */ void QtSingleApplication::setActivationWindow(QObject* aw, bool activateOnMessage) { actObj = aw; if (activateOnMessage) connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); else disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); } /*! Returns the applications activation window if one has been set by calling setActivationWindow(), otherwise returns 0. \sa setActivationWindow() */ QObject* QtSingleApplication::activationWindow() const { return actObj; } /*! De-minimizes, raises, and activates this application's activation window. This function does nothing if no activation window has been set. This is a convenience function to show the user that this application instance has been activated when he has tried to start another instance. This function should typically be called in response to the messageReceived() signal. By default, that will happen automatically, if an activation window has been set. \sa setActivationWindow(), messageReceived(), initialize() */ void QtSingleApplication::activateWindow() { } /*! \fn void QtSingleApplication::messageReceived(const QString& message) This signal is emitted when the current instance receives a \a message from another instance of this application. \sa sendMessage(), setActivationWindow(), activateWindow() */ /*! \fn void QtSingleApplication::initialize(bool dummy = true) \obsolete */ ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtlockedfile_win.cpp0000664000175000017500000001466314456706513027373 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qtlockedfile.h" #include #include #define MUTEX_PREFIX "QtLockedFile mutex " // Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS #define MAX_READERS MAXIMUM_WAIT_OBJECTS #if QT_VERSION >= 0x050000 #define QT_WA(unicode, ansi) unicode #endif Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) { if (mutexname.isEmpty()) { QFileInfo fi(*this); mutexname = QString::fromLatin1(MUTEX_PREFIX) + fi.absoluteFilePath().toLower(); } QString mname(mutexname); if (idx >= 0) mname += QString::number(idx); Qt::HANDLE mutex; if (doCreate) { QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } ); if (!mutex) { qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); return 0; } } else { QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } ); if (!mutex) { if (GetLastError() != ERROR_FILE_NOT_FOUND) qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); return 0; } } return mutex; } bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock) { Q_ASSERT(mutex); DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0); switch (res) { case WAIT_OBJECT_0: case WAIT_ABANDONED: return true; break; case WAIT_TIMEOUT: break; default: qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed"); } return false; } bool QtLockedFile::lock(LockMode mode, bool block) { if (!isOpen()) { qWarning("QtLockedFile::lock(): file is not opened"); return false; } if (mode == NoLock) return unlock(); if (mode == m_lock_mode) return true; if (m_lock_mode != NoLock) unlock(); if (!wmutex && !(wmutex = getMutexHandle(-1, true))) return false; if (!waitMutex(wmutex, block)) return false; if (mode == ReadLock) { int idx = 0; for (; idx < MAX_READERS; idx++) { rmutex = getMutexHandle(idx, false); if (!rmutex || waitMutex(rmutex, false)) break; CloseHandle(rmutex); } bool ok = true; if (idx >= MAX_READERS) { qWarning("QtLockedFile::lock(): too many readers"); rmutex = 0; ok = false; } else if (!rmutex) { rmutex = getMutexHandle(idx, true); if (!rmutex || !waitMutex(rmutex, false)) ok = false; } if (!ok && rmutex) { CloseHandle(rmutex); rmutex = 0; } ReleaseMutex(wmutex); if (!ok) return false; } else { Q_ASSERT(rmutexes.isEmpty()); for (int i = 0; i < MAX_READERS; i++) { Qt::HANDLE mutex = getMutexHandle(i, false); if (mutex) rmutexes.append(mutex); } if (rmutexes.size()) { DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(), TRUE, block ? INFINITE : 0); if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) { if (res != WAIT_TIMEOUT) qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed"); m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky unlock(); return false; } } } m_lock_mode = mode; return true; } bool QtLockedFile::unlock() { if (!isOpen()) { qWarning("QtLockedFile::unlock(): file is not opened"); return false; } if (!isLocked()) return true; if (m_lock_mode == ReadLock) { ReleaseMutex(rmutex); CloseHandle(rmutex); rmutex = 0; } else { Q_FOREACH(Qt::HANDLE mutex, rmutexes) { ReleaseMutex(mutex); CloseHandle(mutex); } rmutexes.clear(); ReleaseMutex(wmutex); } m_lock_mode = QtLockedFile::NoLock; return true; } QtLockedFile::~QtLockedFile() { if (isOpen()) unlock(); if (wmutex) CloseHandle(wmutex); } ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtsinglecoreapplication.pri0000664000175000017500000000050414456706513030770 0ustar adminadminINCLUDEPATH += $$PWD DEPENDPATH += $$PWD HEADERS += $$PWD/qtsinglecoreapplication.h $$PWD/qtlocalpeer.h SOURCES += $$PWD/qtsinglecoreapplication.cpp $$PWD/qtlocalpeer.cpp QT *= network win32:contains(TEMPLATE, lib):contains(CONFIG, shared) { DEFINES += QT_QTSINGLECOREAPPLICATION_EXPORT=__declspec(dllexport) } ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtlockedfile.cpp0000664000175000017500000001374214456706513026513 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qtlockedfile.h" /*! \class QtLockedFile \brief The QtLockedFile class extends QFile with advisory locking functions. A file may be locked in read or write mode. Multiple instances of \e QtLockedFile, created in multiple processes running on the same machine, may have a file locked in read mode. Exactly one instance may have it locked in write mode. A read and a write lock cannot exist simultaneously on the same file. The file locks are advisory. This means that nothing prevents another process from manipulating a locked file using QFile or file system functions offered by the OS. Serialization is only guaranteed if all processes that access the file use QLockedFile. Also, while holding a lock on a file, a process must not open the same file again (through any API), or locks can be unexpectedly lost. The lock provided by an instance of \e QtLockedFile is released whenever the program terminates. This is true even when the program crashes and no destructors are called. */ /*! \enum QtLockedFile::LockMode This enum describes the available lock modes. \value ReadLock A read lock. \value WriteLock A write lock. \value NoLock Neither a read lock nor a write lock. */ /*! Constructs an unlocked \e QtLockedFile object. This constructor behaves in the same way as \e QFile::QFile(). \sa QFile::QFile() */ QtLockedFile::QtLockedFile() : QFile() { #ifdef Q_OS_WIN wmutex = 0; rmutex = 0; #endif m_lock_mode = NoLock; } /*! Constructs an unlocked QtLockedFile object with file \a name. This constructor behaves in the same way as \e QFile::QFile(const QString&). \sa QFile::QFile() */ QtLockedFile::QtLockedFile(const QString &name) : QFile(name) { #ifdef Q_OS_WIN wmutex = 0; rmutex = 0; #endif m_lock_mode = NoLock; } /*! Opens the file in OpenMode \a mode. This is identical to QFile::open(), with the one exception that the Truncate mode flag is disallowed. Truncation would conflict with the advisory file locking, since the file would be modified before the write lock is obtained. If truncation is required, use resize(0) after obtaining the write lock. Returns true if successful; otherwise false. \sa QFile::open(), QFile::resize() */ bool QtLockedFile::open(OpenMode mode) { if (mode & QIODevice::Truncate) { qWarning("QtLockedFile::open(): Truncate mode not allowed."); return false; } return QFile::open(mode); } /*! Returns \e true if this object has a in read or write lock; otherwise returns \e false. \sa lockMode() */ bool QtLockedFile::isLocked() const { return m_lock_mode != NoLock; } /*! Returns the type of lock currently held by this object, or \e QtLockedFile::NoLock. \sa isLocked() */ QtLockedFile::LockMode QtLockedFile::lockMode() const { return m_lock_mode; } /*! \fn bool QtLockedFile::lock(LockMode mode, bool block = true) Obtains a lock of type \a mode. The file must be opened before it can be locked. If \a block is true, this function will block until the lock is aquired. If \a block is false, this function returns \e false immediately if the lock cannot be aquired. If this object already has a lock of type \a mode, this function returns \e true immediately. If this object has a lock of a different type than \a mode, the lock is first released and then a new lock is obtained. This function returns \e true if, after it executes, the file is locked by this object, and \e false otherwise. \sa unlock(), isLocked(), lockMode() */ /*! \fn bool QtLockedFile::unlock() Releases a lock. If the object has no lock, this function returns immediately. This function returns \e true if, after it executes, the file is not locked by this object, and \e false otherwise. \sa lock(), isLocked(), lockMode() */ /*! \fn QtLockedFile::~QtLockedFile() Destroys the \e QtLockedFile object. If any locks were held, they are released. */ ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtlockedfile.h0000664000175000017500000000630714456706513026157 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QTLOCKEDFILE_H #define QTLOCKEDFILE_H #include #ifdef Q_OS_WIN #include #endif #if defined(Q_OS_WIN) # if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT) # define QT_QTLOCKEDFILE_EXPORT # elif defined(QT_QTLOCKEDFILE_IMPORT) # if defined(QT_QTLOCKEDFILE_EXPORT) # undef QT_QTLOCKEDFILE_EXPORT # endif # define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport) # elif defined(QT_QTLOCKEDFILE_EXPORT) # undef QT_QTLOCKEDFILE_EXPORT # define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport) # endif #else # define QT_QTLOCKEDFILE_EXPORT #endif namespace QtLP_Private { class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile { public: enum LockMode { NoLock = 0, ReadLock, WriteLock }; QtLockedFile(); QtLockedFile(const QString &name); ~QtLockedFile(); bool open(OpenMode mode); bool lock(LockMode mode, bool block = true); bool unlock(); bool isLocked() const; LockMode lockMode() const; private: #ifdef Q_OS_WIN Qt::HANDLE wmutex; Qt::HANDLE rmutex; QVector rmutexes; QString mutexname; Qt::HANDLE getMutexHandle(int idx, bool doCreate); bool waitMutex(Qt::HANDLE mutex, bool doBlock); #endif LockMode m_lock_mode; }; } #endif ukui-app-widget/ukui-appwidget-manager/QtSingleApplication/qtsingleapplication.h0000664000175000017500000000763214456706513027565 0ustar adminadmin/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Solutions component. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names ** of its contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QTSINGLEAPPLICATION_H #define QTSINGLEAPPLICATION_H #include class QtLocalPeer; #if defined(Q_OS_WIN) # if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) # define QT_QTSINGLEAPPLICATION_EXPORT # elif defined(QT_QTSINGLEAPPLICATION_IMPORT) # if defined(QT_QTSINGLEAPPLICATION_EXPORT) # undef QT_QTSINGLEAPPLICATION_EXPORT # endif # define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport) # elif defined(QT_QTSINGLEAPPLICATION_EXPORT) # undef QT_QTSINGLEAPPLICATION_EXPORT # define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport) # endif #else # define QT_QTSINGLEAPPLICATION_EXPORT #endif class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication { Q_OBJECT public: QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); QtSingleApplication(const QString &id, int &argc, char **argv); #if QT_VERSION < 0x050000 QtSingleApplication(int &argc, char **argv, Type type); # if defined(Q_WS_X11) QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); # endif // Q_WS_X11 #endif // QT_VERSION < 0x050000 bool isRunning(); QString id() const; void setActivationWindow(QObject* aw, bool activateOnMessage = true); QObject* activationWindow() const; // Obsolete: void initialize(bool dummy = true) { isRunning(); Q_UNUSED(dummy) } public Q_SLOTS: bool sendMessage(const QString &message, int timeout = 5000); void activateWindow(); Q_SIGNALS: void messageReceived(const QString &message); private: void sysInit(const QString &appId = QString()); QtLocalPeer *peer; QObject *actObj = nullptr; }; #endif // QTSINGLEAPPLICATION_H ukui-app-widget/ukui-appwidget-manager/appwidgetproxy.cpp0000664000175000017500000000502514461615267023215 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "appwidgetproxy.h" #include "appwidgetproviderproxy.h" #include "appwidgetcommon.h" #include #include #include namespace AppWidget { AppWidgetProxy::AppWidgetProxy(int id, QString appwidgetname, QString appwidgetuser) :QDBusInterface(KAppWidgetCommon::getAppWidgetDbusObject(appwidgetuser,id), KAppWidgetCommon::getAppWidgetDbusPath(appwidgetuser,id), KAppWidgetCommon::getAppWidgetDbusInterface(appwidgetuser,id)), m_id(id), m_appwidgetname(appwidgetname), m_username(appwidgetuser), m_provider(nullptr) { connect(this, &AppWidgetProxy::clickedSignal, this, &AppWidgetProxy::onClicked); connect(this, &AppWidgetProxy::defineEventSignal, this, &AppWidgetProxy::onDefineSignalType); } AppWidgetProxy::~AppWidgetProxy() { } void AppWidgetProxy::setProviderProxy(AppWidgetProviderProxy * providerproxy) { m_provider = providerproxy; } int AppWidgetProxy::getAppWidgetProxyId() { return m_id; } QString AppWidgetProxy::getAppWidgetProxyAppWidgetName() { return m_appwidgetname; } QString AppWidgetProxy::getAppWidgetProxyUserName() { return m_username; } void AppWidgetProxy::updateAppWidget() { qDebug() << "dbus 调用提供端小插件代理" << m_id; this->asyncCall("updateAppWidget"); } void AppWidgetProxy::updateUserStatus(QString status) { qDebug() << "dbus updateUserStatus" << status; this->asyncCall("updateUserStatus", status); } void AppWidgetProxy::onClicked(QString widgetname, QDBusVariant value) { m_provider->appWidgetClicked(widgetname, value); } void AppWidgetProxy::onDefineSignalType(QString eventname, QString widgetname, QDBusVariant value) { m_provider->appWidgetRecevie(eventname, widgetname, value); } } // namespace AppWidget ukui-app-widget/ukui-appwidget-manager/appwidgetcommon.h0000664000175000017500000000270214461615267022770 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef APPWIDGETCOMMON_H #define APPWIDGETCOMMON_H namespace AppWidget { class AppWidgetCommon { public: static int getProviderIndexFromdecodeAppWidgetId(const int id) { int sum = id; int index = (sum >> 16) & (int)0xffff; return index; } static int getWidgetIndexFromdecodeAppWidgetId(const int id) { int sum = id; int index = sum & (int)0xffff; return index; } static int createAppWidgetId(const int providerindex, const int appwidgetindex) { int index1 = providerindex; int index2 = appwidgetindex; int id; id = (index1 << 16) | index2; return id; } }; } // namespace AppWidget #endif // APPWIDGETCOMMON_H ukui-app-widget/ukui-appwidget-manager/mappingmanager.cpp0000664000175000017500000001162514461615267023120 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "mappingmanager.h" #include "appwidgetproviderproxy.h" #include "appwidgetcommon.h" #include #include namespace AppWidget { MappingManager::MappingManager(QObject *parent) :QObject(parent) { } MappingManager::~MappingManager() { for (int i = 0; i < m_providerproxy.count(); i++) { if (m_providerproxy.at(i) != nullptr) { delete m_providerproxy.at(i); } } } AppWidgetProviderProxy* MappingManager::findProviderProxyByProviderName(const QString providername) { //通过名字从提供端容器查找到提供端代理 for (int i = 0 ; i < m_providerproxy.size(); i++) { if (m_providerproxy.at(i)) { if (m_providerproxy.at(i)->getAppWidgetProviderProxyProviderName() == providername) { return m_providerproxy.at(i); } } } return nullptr; } AppWidgetProviderProxy* MappingManager::findProviderProxyByAppWidgetId(int id) { int index = AppWidgetCommon::getProviderIndexFromdecodeAppWidgetId(id); if (index < m_providerproxy.size()) { return m_providerproxy.at(index); } return nullptr; } AppWidgetProxy* MappingManager::findAppWidgetProxyByAppWidgetId(int id) { qDebug() << __FILE__ << __FUNCTION__ << "appwidget`s id :" << id; int index1 = AppWidgetCommon::getProviderIndexFromdecodeAppWidgetId(id); AppWidgetProviderProxy* providerproxy; if (index1 < m_providerproxy.size()) { providerproxy = m_providerproxy.at(index1); if (!providerproxy) { qWarning() << __FILE__ << __FUNCTION__ << "providerproxy is null"; return nullptr; } } AppWidgetProxy* appwidgetproxy = providerproxy->getAppWidgetProxy(id); if (appwidgetproxy) { return appwidgetproxy; }else { qWarning() << __FILE__ << __FUNCTION__ << "appwidgetproxy is null"; return nullptr; } } QVector MappingManager::findAppWidgetProxyByUserName(QString username) { qDebug() << __FILE__ << __FUNCTION__ << "UserName`s :" << username; QVector appwidgetlist; AppWidgetProviderProxy* providerproxy; for (int i = 0; i < m_providerproxy.size(); ++i) { providerproxy = m_providerproxy.at(i); if (!providerproxy) { qWarning() << __FILE__ << __FUNCTION__ << "providerproxy is null"; continue; } QVector appvec(providerproxy->getAppwidgetProxyByUser(username)); for (int var = 0; var < appvec.size(); ++var) { appwidgetlist.append(appvec.at(var)); } } return appwidgetlist; } AppWidgetProviderProxy* MappingManager::createProviderProxy(QString providername) { qDebug() << __FILE__ << __FUNCTION__ << "providername :" << providername; int index = getUsableIndex(); AppWidgetProviderProxy* providerproxy = new AppWidgetProviderProxy(index, providername); if (providerproxy) { addProviderProxy(index, providerproxy); return providerproxy; } return nullptr; } void MappingManager::destroyProviderProxy(AppWidgetProviderProxy* providerproxy) { if (!providerproxy) { qWarning() << __FILE__ << __FUNCTION__ << "providerproxy is null"; return ; } int index = providerproxy->getAppWidgetProviderProxyIndex(); deleteProviderProxy(index); } int MappingManager::getUsableIndex() { int size = m_providerproxy.size(); for (int i = 0; i < size; i++) { if (m_providerproxy.at(i) == nullptr) { return i; } } return size; } void MappingManager::addProviderProxy(int index, AppWidgetProviderProxy* providerproxy) { int size = m_providerproxy.size(); if (index < size){ m_providerproxy.replace(index, providerproxy); } else { m_providerproxy.append(providerproxy); } } void MappingManager::deleteProviderProxy(int index) { qDebug() << __FILE__ << __FUNCTION__; int size = m_providerproxy.size(); if (index < size) { AppWidgetProviderProxy * providerproxy = m_providerproxy.at(index); m_providerproxy.replace(index, nullptr); if (providerproxy) { delete providerproxy; } } } } // namespace AppWidget ukui-app-widget/ukui-appwidget-manager/main.cpp0000664000175000017500000000227714461605317021054 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "appwidgetmanager.h" #include #include "ukui-log4qt.h" int main(int argc, char *argv[]) { QtSingleApplication a("ukui-appwidget-manager", argc, argv); if(a.isRunning()) { a.sendMessage("Process already exists"); return EXIT_SUCCESS; } #ifndef QT_DEBUG initUkuiLog4qt("ukui-appwidget-manager"); #endif AppWidget::AppWidgetManager w; a.setActivationWindow(&w);//单例 return a.exec(); } ukui-app-widget/ukui-appwidget-manager/data/0000775000175000017500000000000014461605317020325 5ustar adminadminukui-app-widget/ukui-appwidget-manager/data/org.ukui.appwidget.manager.service0000664000175000017500000000012514413425621027037 0ustar adminadmin[D-BUS Service] Name=org.ukui.appwidget.manager Exec=/usr/bin/ukui-appwidget-manager ukui-app-widget/ukui-appwidget-manager/data/ukui-appwidget-manager.desktop0000664000175000017500000000045014461605317026266 0ustar adminadmin[Desktop Entry] Name=ukui-appwidget-manager Name[zh_CN]=小插框架件 Comment=ukui-appwidget-manager Comment[zh_CN]=小插框架件 Exec=/usr/bin/ukui-appwidget-manager Terminal=false Type=Application NoDisplay=true OnlyShowIn=UKUI X-UKUI-Autostart-Phase=Initialization X-UKUI-AutoRestart=true ukui-app-widget/ukui-appwidget-manager/appwidgetproviderproxy.cpp0000664000175000017500000001347214461615267024775 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #include "appwidgetproviderproxy.h" #include "appwidgetcommon.h" #include "appwidgetproxy.h" #include #include #include #include namespace AppWidget { AppWidgetProviderProxy::AppWidgetProviderProxy(int id, QString providername) :QDBusInterface(KAppWidgetCommon::getProviderDbusObject(providername), KAppWidgetCommon::getProviderDbusPath(providername), KAppWidgetCommon::getProviderDbusInterface(providername)), m_index(id), m_providername(providername) { } AppWidgetProviderProxy::~AppWidgetProviderProxy() { for (int i = 0; i < m_appwidgetproxy.count(); i++) { if(m_appwidgetproxy.at(i) != nullptr) { delete m_appwidgetproxy.at(i); } } } int AppWidgetProviderProxy::getAppWidgetProviderProxyIndex() { return m_index; } QString AppWidgetProviderProxy::getAppWidgetProviderProxyProviderName() { return m_providername; } QVector AppWidgetProviderProxy::getAppwidgetProxyByUser(QString username) { QVector appwidgetvec; for (int i = 0; i < m_appwidgetproxy.size(); ++i) { if (m_appwidgetproxy.at(i) == nullptr || !m_appwidgetproxy.at(i)->isValid()) { continue; } if(m_appwidgetproxy.at(i)->getAppWidgetProxyUserName() == username) { appwidgetvec.append(m_appwidgetproxy.at(i)); } } return appwidgetvec; } QMap AppWidgetProviderProxy::getAppWidgetProviderProxyData() { return m_data; } AppWidgetProxy* AppWidgetProviderProxy::getAppWidgetProxy(int id) { int index = AppWidgetCommon::getWidgetIndexFromdecodeAppWidgetId(id); if(m_appwidgetproxy.at(index)) { return m_appwidgetproxy.at(index); }else { return nullptr; } } void AppWidgetProviderProxy::updateAppWidgetProviderProxyData(QMap data) { m_data = data; int size = m_appwidgetproxy.size(); for(int i = 0; i < size; i++) { if(m_appwidgetproxy.at(i)) { m_appwidgetproxy.at(i)->updateAppWidget(); } } } void AppWidgetProviderProxy::appWidgetRecevie(QString eventname, QString controlname, QDBusVariant value) { QVariant date; date.setValue(value); asyncCall("appWidgetRecevie", eventname, controlname, date); } void AppWidgetProviderProxy::appWidgetUpdate() { asyncCall("appWidgetUpdate"); } void AppWidgetProviderProxy::appWidgetDisable() { asyncCall("appWidgetDisable"); } void AppWidgetProviderProxy::appWidgetEnable() { asyncCall("appWidgetEnable"); } void AppWidgetProviderProxy::appWidgetDeleted() { asyncCall("appWidgetDeleted"); } void AppWidgetProviderProxy::appWidgetClicked(QString cotrolname, QDBusVariant value) { qDebug() << __FILE__ << __FUNCTION__ << ": Appwidgetname: " << cotrolname; QVariant date; date.setValue(value); asyncCall("appWidgetClicked", cotrolname, date); // system("ukui-control-center"); } bool AppWidgetProviderProxy::appWidgetProxyIsEmpty() { int size = m_appwidgetproxy.size(); for(int i = 0; i < size; i++) { if(m_appwidgetproxy.at(i) != nullptr) { return false; } } return true; } AppWidgetProxy* AppWidgetProviderProxy::createAppWidgetProxy(QString appwidgetname, QString username) { int index1 = m_index; int index2 = getUsableIndex(); int id = AppWidgetCommon::createAppWidgetId(index1, index2); AppWidgetProxy* appwidgetproxy = new AppWidgetProxy(id, appwidgetname, username); addAppWidgetProxy(index2, appwidgetproxy); return appwidgetproxy; } bool AppWidgetProviderProxy::destroyAppWidgetProxy(int id) { int index = AppWidgetCommon::getWidgetIndexFromdecodeAppWidgetId(id); return deleteAppWidgetProxy(index); } int* AppWidgetProviderProxy::getAllAppWidgetIds() { //! \todo init return nullptr; } bool AppWidgetProviderProxy::addAppWidgetProxy(int index, AppWidgetProxy* appwidgetproxy) { if(appwidgetproxy) { int size = m_appwidgetproxy.size(); if(index < size) { m_appwidgetproxy.replace(index, appwidgetproxy); }else { m_appwidgetproxy.append(appwidgetproxy); } return true; } qWarning() << __FILE__ << __FUNCTION__ << "Appwidgetproxy is nullptr"; return false; } bool AppWidgetProviderProxy::deleteAppWidgetProxy(int index) { int size = m_appwidgetproxy.size(); if(index < size) { if(m_appwidgetproxy.at(index)) { AppWidgetProxy* appwidgetproxy = m_appwidgetproxy.at(index); m_appwidgetproxy.replace(index, nullptr); if(appwidgetproxy != nullptr) { delete appwidgetproxy; appwidgetproxy = nullptr; } return true; } } qWarning() << __FILE__ << __FUNCTION__ << "Appwidgetproxy deleted failed"; return false; } int AppWidgetProviderProxy::getUsableIndex() { int size = m_appwidgetproxy.size(); for(int i = 0; i < size; i++) { if(m_appwidgetproxy.at(i) == nullptr) { return i; } } return size; } } // namespace AppWidget ukui-app-widget/ukui-appwidget-manager/appwidgetconfiguration.h0000664000175000017500000000301314461615267024343 0ustar adminadmin/* * Copyright (C) 2023, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authors: wangyan * */ #ifndef APPWIDGETCONFIGURATION_H #define APPWIDGETCONFIGURATION_H #include namespace AppWidget{ class AppWidgetConfiguration : public QObject { Q_OBJECT public: explicit AppWidgetConfiguration(QObject *parent = nullptr); QString getProviderNameByAppWidgetName(const QString &appwidgetname); //获取ui文件 QString getAppWidgetUiFile(const QString &appwidgetname); //获取属性 QString getAppWidgetConfig(const QString &appwidgetname, const QString &config); //获取所有属性 QMap getAppWidgetConfigs(const QString &appwidgetname, QString begianName); //各个属性的获取函数 QString getConfigurationByKey(const QString &path, const QString &key); }; } // namespace AppWidget #endif // APPWIDGETCONFIGURATION_H ukui-app-widget/README.md0000664000175000017500000001114614456706513014333 0ustar adminadmin## ukui-app-widget ukui-app-widget是UKUI桌面环境的小插件框架, 插件用户可以使用小插件框架实现桌面环境小插件UI; ### 依赖 ------ ### 编译依赖 - debhelper-compat - qt5-qmake - qtbase5-dev - qtbase5-dev-tools - qtdeclarative5-dev - qtquickcontrols2-5-dev - libglib2.0-dev - libgsettings-qt-dev - libukui-log4qt-dev ### 编译 ------ ```shell $ cd ukui-app-widget $ mkdir build $ cd build $ qmake .. $ make ``` ### 安装 ------ ```shell $ sudo make install ``` ### 框架组成 - **InProgress** - 小插件管理服务 - 小插件使用端 - 小插件提供端 - **TROUBLE** - 无 ### SDK组成 - **InProgress** - libukui-appwidget-manager - libukui-appwidget-plugin - libukui-appwidget-provider - AppWidget.qml - **TROUBLE** - 无 ### 模块介绍 #### 框架 - **管理服务模块** 小插件框架中的后台管理服务,主要提供提供端与使用端 的通信能力。 - **使用端** 用于显示小插件的应用组件,使用端可以不唯一,小插件使 用端可以通过小插件框架提供的sdk获取到对应的小插件信息 以及ui文件。 - **提供端** 应用组件作为提供端为小插件服务提供小插件ui界面,小插件 的配置信息,小插件的更新数据服务。 - **ukui-appwidget-test** 小插件框架应用的demo ##### SDK - **libukui-appwidget-manager** 小插件管理服务接口SDK,用户可以通过该接口获取到小插件 的信息,提供端可以通过管理服务接口推送更新数据。 - **libukui-appwidget-plugin** 封装为qml可以使用的内部插件库,由Appwidget.qml控件导入 使用,是qml与小插件使用端的通信类,封装为点击事件消息、 自定义事件消息、使用端注册dbus的接口以及数据更新的函数。 - **libukui-appwidget-provider** 小插件提供端SDK,提供端可以通过继承该类实现提供端的服务。 接收由管理服务传来的消息。 - **AppWidget.qml** qml控件的封装,用于小插件实例使用,负责连接qml与内部插件 库函数,作为中间控件实现小插件实例与使用端的通信。 ### 接口使用 #### 使用端接口 - **获取小插件列表** QStringList getAppWidgetList(); 功能说明:获取可加载的小插件列表(列表形式如:("clock", "search"),列表内容为小插件名字)。 - **获取小插件ui文件路径** QString getAppWidgetUiFile(const QString &appwidgetname); 功能说明:通过小插件名字获取小插件qml ui布局文件(ui路径如:"/usr/share/appwidget/qml/search.qml") - **获取小插件的config属性** QString getAppWidgetConfig(const QString &appwidgetname,const AppWidgetConfig& config) 功能说明:通过小插件名称,以及小插件的属性config获取小插件的配置信息 - **获取小插件的所有属性** QMap getAppWidgetConfigs(const QString &appwidgetname); 功能说明:用于一次性获取小插件的所有配置信息 - **更新使用端状态** void updateUserStatus(const QString &username, const UserStatus& userstatus); 功能说明:用于使用端通知小插件使用端状态 - **使用端注册小插件** register(QString appname, QString usrname); 功能说明:用户使用端qml界面注册小插件,在使用端加载小插件时调用 #### 提供端接口 创建提供端类,该类需要继承KAppWidgetProvider类 - **小插件自定义事件** void appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value); 功能说明:用于响应小插件qml中发送的自定义事件 - **小插件更新函数** void appWidgetUpdate(); 功能说明:用于响应由管理服务发送来的更新通知 - **小插件禁用函数** void appWidgetDisable(); 功能说明:用于响应由管理服务发送来的小插件禁用通知(当该提供端的所有小插件都被移除后发送) - **小插件删除函数** void appWidgetDeleted(); 功能说明:用于响应由管理服务发送来的使用端小插件删除通知 - **小插件启用函数** void appWidgetEnable(); 功能说明:用于响应由管理服务发送来的小插件通知(当该提供端的小插件第一次被添加时发送) - **小插件点击函数** void appWidgetClicked(const QString &widgetname, const QDBusVariant &value); 功能说明:用于响应由管理服务发送来的小插件点击事件通知 ukui-app-widget/ukui-app-widget.pro0000664000175000017500000000032714456706513016611 0ustar adminadminTEMPLATE = subdirs SUBDIRS += \ libukui-app-widget \ ukui-appwidget-test \ ukui-appwidget-manager ukui-appwidget-test.depends += libukui-app-widget ukui-appwidget-manager.depends += libukui-app-widget