diff options
255 files changed, 12318 insertions, 3438 deletions
diff --git a/LICENSE.GPL3 b/LICENSE.GPL3 new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/LICENSE.GPL3 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/examples/examples.pro b/examples/examples.pro deleted file mode 100644 index 18801a2..0000000 --- a/examples/examples.pro +++ /dev/null @@ -1,3 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += wifi diff --git a/examples/wifi/wifi-cpp/doc/images/wifi-cpp.jpg b/examples/wifi/wifi-cpp/doc/images/wifi-cpp.jpg Binary files differdeleted file mode 100644 index 90feb20..0000000 --- a/examples/wifi/wifi-cpp/doc/images/wifi-cpp.jpg +++ /dev/null diff --git a/examples/wifi/wifi-cpp/doc/src/wifi-cpp.qdoc b/examples/wifi/wifi-cpp/doc/src/wifi-cpp.qdoc deleted file mode 100644 index 334dba7..0000000 --- a/examples/wifi/wifi-cpp/doc/src/wifi-cpp.qdoc +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -/*! - \title Getting Started with B2Qt.Wifi in C++ - \example wifi/wifi-cpp - \ingroup wifi-examples - \brief Guide to getting started with B2Qt.Wifi using C++. - - \section1 Preparing the Application - - Use the following \c include statement to access the C++ classes: - - \code - #include <B2QtWifi> - \endcode - - Before building your application, add the following statement to your - \c .pro file to link against the B2Qt.Wifi library: - - \code - QT += b2qtwifi - \endcode - - This guide will demonstrate how to create a Qt Widget-based application - that utilizes the B2Qt.Wifi API to set up a wifi network connection. We - will start by looking at how to scan for wifi access points, and how to - display and process this data in the application. At the end of the guide - we will show how to connect directly to a known wifi network configuration. - - \image wifi-cpp.jpg - - \section1 Listing Wifi Networks - - First we need to set up QListView widget which we will use to list wifi - networks that can be detected by the device. The detected network access - points are packed as a list-based data model and can be retrieved using - QWifiManager::networks. Here we also set a custom item delegate and - connect to two QWifiManager signals. - - \snippet wifi/wifi-cpp/main.cpp 0 - - \section1 Creating a Delegate - - The Wifi network model has many data roles that describe the different - properties of Wifi network. This data can be used by an application to list - detailed network information and/or to create QWifiConfiguration objects. - In this example we are interested in the network name. In the paint() - method we check if the network name is equal to the currently active - network connection, and append appropriate network state information. - - \snippet wifi/wifi-cpp/main.cpp 1 - - \section1 Connecting to a Selected Network - - On press of the \uicontrol Connect button, connetToNetwork() slot gets - invoked. In this slot we query network properties for the selected network - and create a QWifiConfiguration object, which we later pass to the - QWifiManager::connect function to set up a connection. During this - operation any changes in the network state is reported by QWifiManager - asynchronously. - - \snippet wifi/wifi-cpp/main.cpp 2 - - We use QWifiManager::NetworkState change event handler to trigger the - repainting of the delegate. This way, we can present a current network - state to the user. - - \snippet wifi/wifi-cpp/main.cpp 4 - - \section1 Connecting To a Known Network - - If you already know the network configuration beforehand, you can skip the - network scanning, listing and selection steps. This can be a valid use-case - for devices that do not change their physical location. - - QWifiManager::BackendState change events are reported asynchronously, so we - must connect the signal to a slot that connects to the network access point - after the backend initialization is complete. - - \snippet wifi/wifi-cpp/main.cpp 3 - */ diff --git a/examples/wifi/wifi-cpp/main.cpp b/examples/wifi/wifi-cpp/main.cpp deleted file mode 100644 index 54a35e9..0000000 --- a/examples/wifi/wifi-cpp/main.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include <QtCore> -#include <QtWidgets> -#include <B2QtWifi> - -class NetworkDelegate : public QStyledItemDelegate -{ - Q_OBJECT -//! [1] -public: - NetworkDelegate(QObject *parent = 0) - : QStyledItemDelegate(parent) - { - m_wifiManager = QWifiManager::instance(); - } - - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const - { - QStyledItemDelegate::paint(painter, option, index); - painter->save(); - QString ssid = qvariant_cast<QString>(index.data(QWifiManager::SSID)); - if (ssid == m_wifiManager->currentSSID()) - ssid += networkStateText(); - painter->drawText(option.rect, Qt::AlignVCenter, ssid); - painter->restore(); - } - - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const - { - QFont font = QApplication::font(); - QFontMetrics fm(font); - return QSize(option.rect.width(), fm.height() * 2); - } - -protected: - QString networkStateText() const - { - QWifiManager::NetworkState networkState = m_wifiManager->networkState(); - switch (networkState) { - case QWifiManager::Disconnected: - return QStringLiteral(""); - break; - case QWifiManager::Authenticating: - return QStringLiteral(" (authenticating)"); - break; - case QWifiManager::HandshakeFailed: - return QStringLiteral(" (handshake failed)"); - break; - case QWifiManager::ObtainingIPAddress: - return QStringLiteral(" (obtaining IP address)"); - break; - case QWifiManager::DhcpRequestFailed: - return QStringLiteral(" (dhcp request failed)"); - break; - case QWifiManager::Connected: - return QStringLiteral(" (connected)"); - break; - } - } -//! [1] -private: - QWifiManager *m_wifiManager; -}; - -class WifiSettings : public QWidget -{ - Q_OBJECT -public: - //! [0] - WifiSettings(QWidget *parent = 0) - : QWidget(parent) - , m_listView(new QListView(this)) - , m_networkDelegate(new NetworkDelegate(this)) - { - m_wifiManager = QWifiManager::instance(); - m_listView->setModel(m_wifiManager->networks()); - m_listView->setItemDelegate(m_networkDelegate); - - connect(m_wifiManager, &QWifiManager::backendStateChanged, - this, &WifiSettings::handleBackendStateChanged); - connect(m_wifiManager, &QWifiManager::networkStateChanged, - this, &WifiSettings::handleNetworkStateChanged); - - setupWidgets(); - } - //! [0] -protected: - void setupWidgets() - { - m_backendStateReporter = new QLabel(this); - handleBackendStateChanged(m_wifiManager->backendState()); - m_passwordInput = new QLineEdit(this); - m_passwordInput->setPlaceholderText("Enter Password"); - - QPushButton *connectButton = new QPushButton("Connect", this); - QPushButton *disconnectButton = new QPushButton("Disconnect", this); - QPushButton *startBackendButton = new QPushButton("Switch On", this); - QPushButton *stopBackendButton = new QPushButton("Switch Off", this); - - connect(startBackendButton, &QPushButton::clicked, m_wifiManager, &QWifiManager::start); - connect(stopBackendButton, &QPushButton::clicked, m_wifiManager, &QWifiManager::stop); - connect(connectButton, &QPushButton::clicked, this, &WifiSettings::connectToNetwork); - connect(disconnectButton, &QPushButton::clicked, m_wifiManager, &QWifiManager::disconnect); - - QGridLayout *grid = new QGridLayout(this); - grid->addWidget(connectButton, 0, 0); - grid->addWidget(disconnectButton, 0, 1); - grid->addWidget(startBackendButton, 1, 0); - grid->addWidget(stopBackendButton, 1, 1); - grid->addWidget(m_listView, 2, 0, 1, 2); - grid->addWidget(m_passwordInput, 3, 0, 1, 2); - grid->addWidget(m_backendStateReporter, 4, 0, 1, 2); - setLayout(grid); - } - - -protected slots: - void handleBackendStateChanged(QWifiManager::BackendState state) - { - switch (state) { - case QWifiManager::Running: - m_wifiManager->setScanning(true); - m_backendStateReporter->setText("wifi backend state: <b>running<\b>"); - break; - case QWifiManager::NotRunning: - m_wifiManager->setScanning(false); - m_backendStateReporter->setText("wifi backend state: <b>stopped<\b>"); - break; - case QWifiManager::Initializing: - m_backendStateReporter->setText("wifi backend state: <b>initializing<\b>"); - break; - case QWifiManager::Terminating: - m_backendStateReporter->setText("wifi backend state: <b>terminating<\b>"); - break; - } - } - //! [4] - void handleNetworkStateChanged(QWifiManager::NetworkState state) - { - m_listView->viewport()->repaint(); - } - //! [4] - //! [2] - void connectToNetwork() - { - QModelIndex index = m_listView->currentIndex(); - QWifiConfiguration config; - if (index.isValid()) { - QString ssid = qvariant_cast<QString>(index.data(QWifiManager::SSID)); - config.setSsid(ssid); - config.setPassphrase(m_passwordInput->text()); - m_wifiManager->connect(&config); - } - } - //! [2] -private: - QWifiManager *m_wifiManager; - QListView *m_listView; - NetworkDelegate *m_networkDelegate; - QLabel *m_backendStateReporter; - QLineEdit *m_passwordInput; -}; - -//! [3] -class WifiConnectionHandler : public QObject -{ - Q_OBJECT -public: - WifiConnectionHandler() - { - // replace with a valid network configuration - m_config.setSsid("my-local-wifi"); - m_config.setPassphrase("helloworld123"); - m_config.setProtocol("WPA"); - m_manager = QWifiManager::instance(); - if (m_manager->backendState() == QWifiManager::Running) { - m_manager->connect(&m_config); - } else { - connect(m_manager, &QWifiManager::backendStateChanged, - this, &WifiConnectionHandler::connectToNetwork); - m_manager->start(); - } - } - -protected slots: - void connectToNetwork(QWifiManager::BackendState state) - { - if (state == QWifiManager::Running) - m_manager->connect(&m_config); - } - -private: - QWifiManager *m_manager; - QWifiConfiguration m_config; -}; -//! [3] - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - WifiSettings wifiSettingsWindow; - wifiSettingsWindow.show(); - - // disable the above 2 lines before enabling this - // WifiConnectionHandler connectionHandler; - - return a.exec(); -} - -#include "main.moc" diff --git a/examples/wifi/wifi-cpp/wifi-cpp.pro b/examples/wifi/wifi-cpp/wifi-cpp.pro deleted file mode 100644 index f457df3..0000000 --- a/examples/wifi/wifi-cpp/wifi-cpp.pro +++ /dev/null @@ -1,9 +0,0 @@ -QT += core widgets b2qtwifi - -TARGET = wifi-cpp -TEMPLATE = app - -target.path = /data/user/qt/$$TARGET -INSTALLS += target - -SOURCES += main.cpp diff --git a/examples/wifi/wifi-qml/WifiConnectionHandler.qml b/examples/wifi/wifi-qml/WifiConnectionHandler.qml deleted file mode 100644 index f3f2c10..0000000 --- a/examples/wifi/wifi-qml/WifiConnectionHandler.qml +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -import QtQuick 2.3 -import B2Qt.Wifi 1.0 - -//! [0] -Item { - WifiConfiguration { - id: localConfig - ssid: "network-for-my-device" - passphrase: "password123" - protocol: "WPA2" - } - - Connections { - target: WifiManager - onBackendStateChanged: { - if (WifiManager.backendState === WifiManager.Running) - WifiManager.connect(localConfig) - } - onNetworkStateChanged: { - if (WifiManager.networkState === WifiManager.Connected) - print("successfully connected to: " + WifiManager.currentSSID) - } - } - - Component.onCompleted: { - if (WifiManager.backendState === WifiManager.Running) { - WifiManager.connect(localConfig) - } else { - WifiManager.start() - } - } -} -//! [0] diff --git a/examples/wifi/wifi-qml/WifiScanner.qml b/examples/wifi/wifi-qml/WifiScanner.qml deleted file mode 100644 index 45fe8e7..0000000 --- a/examples/wifi/wifi-qml/WifiScanner.qml +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -import QtQuick 2.3 -import QtQuick.Controls 1.2 -import B2Qt.Wifi 1.0 - -Item { - anchors.fill: parent - - Binding { - target: WifiManager - property: "scanning" - value: networkView.visible - } - - Button { - id: wifiOnOffButton - anchors.top: parent.top - anchors.topMargin: 20 - anchors.left: parent.left - anchors.right: parent.right - onClicked: { - if (WifiManager.backendState === WifiManager.Running) { - if (networkView.visible) - networkView.visible = false - WifiManager.stop() - } else if (WifiManager.backendState === WifiManager.NotRunning) { - WifiManager.start() - } - } - - Component.onCompleted: updateButtonText(WifiManager.backendState) - Connections { - target: WifiManager - onBackendStateChanged: wifiOnOffButton.updateButtonText(backendState) - } - - function updateButtonText(backendState) - { - if (backendState === WifiManager.Initializing) - wifiOnOffButton.text = "Initializing..." - if (backendState === WifiManager.Terminating) - wifiOnOffButton.text = "Terminating..." - if (backendState === WifiManager.NotRunning) - wifiOnOffButton.text = "Switch On" - if (backendState === WifiManager.Running) - wifiOnOffButton.text = "Switch Off" - } - } - - Button { - id: listNetworksButton - anchors.top: wifiOnOffButton.bottom - anchors.topMargin: 30 - anchors.left: parent.left - anchors.right: parent.right - visible: WifiManager.backendState === WifiManager.Running - text: networkView.visible ? "Hide wifi networks" - : "List available wifi networks" - onClicked: networkView.visible = !networkView.visible - } - //! [0] - ListView { - id: networkView - model: WifiManager.networks - delegate: listDelegate - implicitHeight: 800 - anchors.top: listNetworksButton.bottom - anchors.topMargin: 30 - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - visible: false - clip: true - - property string networkStateText: "" - property QtObject expandedNetworkBox: null - property bool hasExpandedNetworkBox: expandedNetworkBox !== null - - function setNetworkStateText(networkState) { - if (networkState === WifiManager.ObtainingIPAddress) - networkView.networkStateText = " (obtaining ip..)" - else if (networkState === WifiManager.DhcpRequestFailed) - networkView.networkStateText = " (dhcp request failed)" - else if (networkState === WifiManager.Connected) - networkView.networkStateText = " (connected)" - else if (networkState === WifiManager.Authenticating) - networkView.networkStateText = " (authenticating..)" - else if (networkState === WifiManager.HandshakeFailed) - networkView.networkStateText = " (wrong password)" - else if (networkState === WifiManager.Disconnected) - networkView.networkStateText = "" - } - - Connections { - target: WifiManager - onNetworkStateChanged: networkView.setNetworkStateText(networkState) - } - - Component.onCompleted: { - if (WifiManager.backendState == WifiManager.Running) - networkView.visible = true - } - } - //! [0] - //! [2] - WifiConfiguration { id: config } - //! [2] - Component { - id: listDelegate - Rectangle { - id: networkBox - property bool expanded: false - property bool isCurrentNetwork: WifiManager.currentSSID === ssid - property bool connected: isCurrentNetwork && WifiManager.networkState === WifiManager.Connected - property int notExpandedHeight: ssidLabel.height + bssidLabel.height + 20 - property int expandedHeight: notExpandedHeight + passwordInput.height + connectionButton.height + 54 - property int connectedExpandedHeight: notExpandedHeight + connectionButton.height + 30 - height: expanded ? (connected ? connectedExpandedHeight : expandedHeight) : notExpandedHeight - width: parent.width - clip: true - border.color: "black" - border.width: 1 - - Component.onDestruction: if (expanded) networkView.expandedNetworkBox = null - onHeightChanged: if (expanded) networkView.positionViewAtIndex(index, ListView.Contain) - - Behavior on height { NumberAnimation { duration: 500; easing.type: Easing.InOutCubic } } - //! [1] - Text { - id: ssidLabel - anchors.top: parent.top - anchors.left: parent.left - anchors.margins: 5 - anchors.leftMargin: 10 - font.pixelSize: 26 - font.bold: true - text: isCurrentNetwork ? ssid + networkView.networkStateText : ssid - Component.onCompleted: networkView.setNetworkStateText(WifiManager.networkState) - } - - Text { - id: bssidLabel - anchors.top: ssidLabel.bottom - anchors.left: parent.left - anchors.margins: 5 - anchors.leftMargin: 30 - text: bssid - font.pixelSize: ssidLabel.font.pixelSize * 0.8 - } - - Text { - id: flagsLabel - anchors.top: bssidLabel.top - anchors.left: bssidLabel.right - anchors.leftMargin: 35 - text: (supportsWPA2 ? "WPA2 " : "") - + (supportsWPA ? "WPA " : "") - + (supportsWEP ? "WEP " : "") - + (supportsWPS ? "WPS " : ""); - font.pixelSize: ssidLabel.font.pixelSize * 0.8 - font.italic: true - } - - ProgressBar { - id: signalStrengthBar - height: 20 - width: networkBox.width * 0.5 - anchors.margins: 10 - anchors.right: parent.right - anchors.top: parent.top - minimumValue: 0 - maximumValue: 100 - value : signalStrength - } - //! [1] - MouseArea { - anchors.fill: parent - onClicked: handleNetworkBoxExpanding() - } - - function handleNetworkBoxExpanding() - { - expanded = !expanded - if (expanded) { - if (networkView.hasExpandedNetworkBox) - networkView.expandedNetworkBox.expanded = false - networkView.expandedNetworkBox = networkBox - } else { - networkView.expandedNetworkBox = null - } - } - - TextField { - id: passwordInput - anchors.top: flagsLabel.bottom - anchors.topMargin: 15 - anchors.horizontalCenter: parent.horizontalCenter - width: parent.width * 0.36 - height: connectionButton.height * 1.1 - placeholderText: "Enter Password" - visible: !connected - font.pixelSize: 16 - echoMode: TextInput.Password - inputMethodHints: Qt.ImhNoPredictiveText - } - - Button { - id: connectionButton - y: connected ? passwordInput.y - : passwordInput.y + passwordInput.height + 10 - width: passwordInput.width - anchors.horizontalCenter: parent.horizontalCenter - text: connected ? "Disconnect" : "Connect" - //! [3] - onClicked: { - if (connected) { - WifiManager.disconnect() - } else { - config.ssid = ssid; - config.passphrase = passwordInput.text - if (!WifiManager.connect(config)) - print("failed to connect: " + WifiManager.lastError) - } - } - //! [3] - } - } - } -} diff --git a/examples/wifi/wifi-qml/doc/images/wifi-qml.jpg b/examples/wifi/wifi-qml/doc/images/wifi-qml.jpg Binary files differdeleted file mode 100644 index 649707f..0000000 --- a/examples/wifi/wifi-qml/doc/images/wifi-qml.jpg +++ /dev/null diff --git a/examples/wifi/wifi-qml/doc/src/wifi-qml.qdoc b/examples/wifi/wifi-qml/doc/src/wifi-qml.qdoc deleted file mode 100644 index ba77c1e..0000000 --- a/examples/wifi/wifi-qml/doc/src/wifi-qml.qdoc +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -/*! - - \title Getting Started with B2Qt.Wifi in QML - \example wifi/wifi-qml - \ingroup wifi-examples - \brief Guide to getting started with B2Qt.Wifi using QML. - - \section1 Preparing the Application - - Use the following \c import statement in the QML files to access the B2Qt.Wifi QML types: - - \code - import B2Qt.Wifi 1.0 - \endcode - - This guide will demonstrate how to create a QML based application that utilizes - B2Qt.Wifi API to set up a wifi network connection. We will start by looking at how to scan the - surroundings for wifi access points and how to display and process this data in the application. - At the end of the guide we will show how to connect directly to a known wifi network configuration. - - \image wifi-qml.jpg - - \section1 Listing Wifi Networks - - First we need to set up ListView which we will use to list wifi networks - that can be sensed by the device. The sensed network access points are packed as a list-based - data model and can be retrieved from WifiManager::networks. Here we also set a custom item - delegate and connect to WifiManager::networkStateChanged signal. - - \snippet wifi/wifi-qml/WifiScanner.qml 0 - - \section1 Creating a Delegate - - The wifi network model has many data roles that describe the different properties of wifi networks. - This data can be used by an application to list detailed network information and/or to set up - WifiConfiguration objects. We use these network data roles in our delegate for listing - ssid, bssid, supported security protocols and for signal strengh representation. - - \snippet wifi/wifi-qml/WifiScanner.qml 1 - - \section1 Connecting To a Selected Network - - WifiConfiguration element will be used to describe the network that we want to connect to, - selected from the network list. - - \snippet wifi/wifi-qml/WifiScanner.qml 2 - - When \uicontrol Connect button is clicked we set the network name and password properties on - the \c config and pass it to WifiManager::connect, which sets up a wifi connection behind-the-scenes. - During this operation or whenever there are changes in the network state, QWifiManager provides - asynchronous QWifiManager::NetworkState change events. - - \snippet wifi/wifi-qml/WifiScanner.qml 3 - - \section1 Connecting To a Known Network - - If you are not interested in scanning the environment for wifi network access points and you already - know the network configuration beforehand, the network scanning, listing and selection steps can be - entirely skipped. This can be a valid use-case for devices that won't be changing their physical location. - - QWifiManager::BackendState change events are delivered asynchronously. Therefore we have to add a signal handler - that will connect to the network access point after the backend initialization process has been completed, - if the backend is not already in the initialized state at the time of running this code. - - \snippet wifi/wifi-qml/WifiConnectionHandler.qml 0 - - */ diff --git a/examples/wifi/wifi-qml/main.cpp b/examples/wifi/wifi-qml/main.cpp deleted file mode 100644 index 32c6b74..0000000 --- a/examples/wifi/wifi-qml/main.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include <QGuiApplication> -#include <QQmlApplicationEngine> - -int main(int argc, char *argv[]) -{ - QGuiApplication app(argc, argv); - - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - - return app.exec(); -} diff --git a/examples/wifi/wifi-qml/main.qml b/examples/wifi/wifi-qml/main.qml deleted file mode 100644 index 9c8726d..0000000 --- a/examples/wifi/wifi-qml/main.qml +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -import QtQuick 2.3 -import QtQuick.Window 2.2 - -Window { - visible: true - width: Screen.width - height: Screen.height - color: "#D9D9D9" - - WifiScanner {} - - // disable the above line before enabling WifiConnectionHandler - // WifiConnectionHandler {} -} diff --git a/examples/wifi/wifi-qml/qml.qrc b/examples/wifi/wifi-qml/qml.qrc deleted file mode 100644 index 3c36973..0000000 --- a/examples/wifi/wifi-qml/qml.qrc +++ /dev/null @@ -1,7 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>main.qml</file> - <file>WifiScanner.qml</file> - <file>WifiConnectionHandler.qml</file> - </qresource> -</RCC> diff --git a/examples/wifi/wifi-qml/wifi-qml.pro b/examples/wifi/wifi-qml/wifi-qml.pro deleted file mode 100644 index 70fc76a..0000000 --- a/examples/wifi/wifi-qml/wifi-qml.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app - -QT += qml quick - -SOURCES += main.cpp - -RESOURCES += qml.qrc - -target.path = /data/user/qt -export(target.path) -INSTALLS += target diff --git a/examples/wifi/wifi.pro b/examples/wifi/wifi.pro deleted file mode 100644 index 9e03f0e..0000000 --- a/examples/wifi/wifi.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += wifi-cpp \ - wifi-qml diff --git a/src/bluetoothsettings/bluetoothdevice.cpp b/src/bluetoothsettings/bluetoothdevice.cpp new file mode 100644 index 0000000..932d8f6 --- /dev/null +++ b/src/bluetoothsettings/bluetoothdevice.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <discoverymodel.h> +#include "bluetoothdevice.h" +#include "bluez/bluetoothdevice_p.h" + +BluetoothDevice::BluetoothDevice(QObject *parent) : QObject(parent) + ,m_localDevice(new QBluetoothLocalDevice(this)) + ,m_deviceModel(new DiscoveryModel(this)) + ,m_powered(false) + ,m_scanning(true) +{ + m_powered = m_localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff; + + connect(m_localDevice, &QBluetoothLocalDevice::hostModeStateChanged, this, &BluetoothDevice::deviceStateChanged); + connect(m_localDevice, &QBluetoothLocalDevice::deviceConnected, this, &BluetoothDevice::deviceConnected); + connect(m_localDevice, &QBluetoothLocalDevice::deviceDisconnected, this, &BluetoothDevice::deviceDisconnected); + connect(m_deviceModel, &DiscoveryModel::scanFinished, this, &BluetoothDevice::scanFinished); + + if (m_powered) { + m_deviceModel->scanDevices(); + } + +} + +void BluetoothDevice::deviceStateChanged(QBluetoothLocalDevice::HostMode state) +{ + m_powered = state != QBluetoothLocalDevice::HostPoweredOff; + emit poweredChanged(); +} + +bool BluetoothDevice::powered() const +{ + return m_powered; +} + +void BluetoothDevice::setPowered(const bool& aPowered) +{ + if (aPowered) { + m_localDevice->powerOn(); + } + else { + m_localDevice->setHostMode(QBluetoothLocalDevice::HostPoweredOff); + } +} + +QObject* BluetoothDevice::deviceModel() const +{ + return static_cast<QObject*>(m_deviceModel); +} + +void BluetoothDevice::scanFinished() +{ + m_scanning = false; + emit scanningChanged(); + updateConnectionStatuses(); +} + +bool BluetoothDevice::scanning() const +{ + return m_scanning; +} + +void BluetoothDevice::setScanning(const bool& aScan) +{ + if (m_scanning && !aScan) { + //TODO m_deviceModel->cancel(); + } + else if (aScan && !m_scanning) { + m_deviceModel->scanDevices(); + m_scanning = true; + emit scanningChanged(); + } +} + +void BluetoothDevice::updateConnectionStatuses() +{ + QList<QBluetoothAddress> connectedDevices = + m_localDevice->connectedDevices(); + + foreach (QBluetoothAddress addr, connectedDevices) { + m_deviceModel->setConnected(addr.toString(), true); + } +} + +void BluetoothDevice::requestPairing(const QString& address) +{ + QBluetoothAddress addr(address); + m_localDevice->requestPairing(addr, QBluetoothLocalDevice::Paired); + connect(m_localDevice, &QBluetoothLocalDevice::pairingDisplayConfirmation, this, &BluetoothDevice::pairingDisplayConfirmation); + + connect(m_localDevice, &QBluetoothLocalDevice::pairingDisplayPinCode, this, &BluetoothDevice::pairingDisplayPinCode); + + connect(m_localDevice, &QBluetoothLocalDevice::pairingFinished, this, &BluetoothDevice::pairingFinished); +} + +void BluetoothDevice::requestConnect(const QString &address) +{ + QScopedPointer<BluetoothDevicePrivate> connectionHandler(new BluetoothDevicePrivate(address)); + connectionHandler->connectDevice(); +} + +void BluetoothDevice::requestDisconnect(const QString& address) +{ + QScopedPointer<BluetoothDevicePrivate> connectionHandler(new BluetoothDevicePrivate(address)); + connectionHandler->disconnectDevice(); +} + +void BluetoothDevice::pairingDisplayConfirmation(const QBluetoothAddress & address, QString pin) +{ + Q_UNUSED(address); + Q_UNUSED(pin); +} + +void BluetoothDevice::pairingDisplayPinCode(const QBluetoothAddress & address, QString pin) +{ + Q_UNUSED(address); + Q_UNUSED(pin); +} + +void BluetoothDevice::pairingFinished(const QBluetoothAddress & address, QBluetoothLocalDevice::Pairing pairing) +{ + if (pairing == QBluetoothLocalDevice::Paired) { + requestConnect(address.toString()); + } +} + +void BluetoothDevice::deviceConnected(const QBluetoothAddress & address) +{ + m_deviceModel->setConnected(address.toString(), true); +} + +void BluetoothDevice::deviceDisconnected(const QBluetoothAddress & address) +{ + m_deviceModel->setConnected(address.toString(), false); +} diff --git a/src/bluetoothsettings/bluetoothdevice.h b/src/bluetoothsettings/bluetoothdevice.h new file mode 100644 index 0000000..a38cde7 --- /dev/null +++ b/src/bluetoothsettings/bluetoothdevice.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BLUETOOTHDEVICE_H +#define BLUETOOTHDEVICE_H + +#include <QObject> +#include <QBluetoothLocalDevice> + +class DiscoveryModel; + +class Q_DECL_EXPORT BluetoothDevice : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool scanning READ scanning WRITE setScanning NOTIFY scanningChanged) + Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) + Q_PROPERTY(QObject* deviceModel READ deviceModel CONSTANT) +public: + explicit BluetoothDevice(QObject *parent = 0); + bool powered() const; + void setPowered(const bool& aPowered); + QObject* deviceModel() const; + bool scanning() const; + void setScanning(const bool& aScan); + Q_INVOKABLE void requestPairing(const QString& address); + Q_INVOKABLE void requestConnect(const QString& address); + Q_INVOKABLE void requestDisconnect(const QString& address); +signals: + void poweredChanged(); + void scanningChanged(); + +public slots: + void deviceStateChanged(QBluetoothLocalDevice::HostMode state); + void scanFinished(); + //These are not yet signaled + //See bug https://bugreports.qt.io/browse/QTBUG-38401 + void pairingDisplayConfirmation(const QBluetoothAddress & address, QString pin); + void pairingDisplayPinCode(const QBluetoothAddress & address, QString pin); + void pairingFinished(const QBluetoothAddress & address, QBluetoothLocalDevice::Pairing pairing); + void deviceConnected(const QBluetoothAddress & address); + void deviceDisconnected(const QBluetoothAddress & address); + +private: + void updateConnectionStatuses(); + +private: + QBluetoothLocalDevice* m_localDevice; + DiscoveryModel *m_deviceModel; + bool m_powered; + bool m_scanning; +}; + +#endif // BLUETOOTHDEVICE_H diff --git a/src/bluetoothsettings/bluetoothsettings.pro b/src/bluetoothsettings/bluetoothsettings.pro new file mode 100644 index 0000000..cb98ccb --- /dev/null +++ b/src/bluetoothsettings/bluetoothsettings.pro @@ -0,0 +1,19 @@ +load(qt_build_config) + +TARGET = QtBluetoothSettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT += core bluetooth + +MODULE = bluetoothsettings +load(qt_module) + +include(bluez/bluez.pri) + +HEADERS += \ + bluetoothdevice.h \ + discoverymodel.h + +SOURCES += bluetoothdevice.cpp \ + discoverymodel.cpp diff --git a/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp b/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp new file mode 100644 index 0000000..d5e6288 --- /dev/null +++ b/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "bluetoothdevice_p.h" +#include "datatypes.h" +#include "objectmanager_interface.cpp" +#include "moc_objectmanager_interface.cpp" +#include "device1_interface.h" + + +BluetoothDevicePrivate::BluetoothDevicePrivate(const QString& address, QObject *parent) + :QObject(parent) + ,m_address(address) +{ + +} + +OrgBluezDevice1Interface* BluetoothDevicePrivate::findDevice() +{ + OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"), + QStringLiteral("/"), + QDBusConnection::systemBus()); + QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects(); + reply.waitForFinished(); + if (reply.isError()) { + qWarning() << "Failed to get objects"; + return NULL; + } + + ManagedObjectList managedObjectList = reply.value(); + for (ManagedObjectList::const_iterator it = managedObjectList.constBegin(); it != managedObjectList.constEnd(); ++it) { + const QDBusObjectPath &path = it.key(); + + const InterfaceList &ifaceList = it.value(); + for (InterfaceList::const_iterator jt = ifaceList.constBegin(); jt != ifaceList.constEnd(); ++jt) { + const QString &iface = jt.key(); + const QVariantMap &ifaceValues = jt.value(); + if (iface == QStringLiteral("org.bluez.Device1")) { + if (ifaceValues[QStringLiteral("Address")] == m_address) { + OrgBluezDevice1Interface *devIf = new OrgBluezDevice1Interface(QStringLiteral("org.bluez"), path.path(), QDBusConnection::systemBus()); + return devIf; + } + } + } + } + return NULL; +} + +void BluetoothDevicePrivate::connectDevice() +{ + OrgBluezDevice1Interface *dev = findDevice(); + if (dev) { + dev->Connect(); + dev->deleteLater(); + } +} + +void BluetoothDevicePrivate::disconnectDevice() +{ + OrgBluezDevice1Interface *dev = findDevice(); + if (dev) { + dev->Disconnect(); + dev->deleteLater(); + } +} diff --git a/src/bluetoothsettings/bluez/bluetoothdevice_p.h b/src/bluetoothsettings/bluez/bluetoothdevice_p.h new file mode 100644 index 0000000..adc283b --- /dev/null +++ b/src/bluetoothsettings/bluez/bluetoothdevice_p.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BLUETOOTHDEVICE__P_H +#define BLUETOOTHDEVICE__P_H + +#include <QObject> + +class OrgBluezDevice1Interface; + +class BluetoothDevicePrivate : public QObject +{ +public: + explicit BluetoothDevicePrivate(const QString& address, QObject *parent=0); + void connectDevice(); + void disconnectDevice(); + +private: + OrgBluezDevice1Interface* findDevice(); + QString m_address; +}; + +#endif // BLUETOOTHDEVICE__P_H diff --git a/src/bluetoothsettings/bluez/bluez.pri b/src/bluetoothsettings/bluez/bluez.pri new file mode 100644 index 0000000..ea4929c --- /dev/null +++ b/src/bluetoothsettings/bluez/bluez.pri @@ -0,0 +1,15 @@ +QT += core dbus + +INCLUDEPATH += $${PWD} +INCLUDEPATH += $${PWD}/bluez + +DBUS_INTERFACES = \ + $${PWD}/objectmanager.xml \ + $${PWD}/device1.xml \ + +HEADERS += \ + $$PWD/bluetoothdevice_p.h \ + $$PWD/datatypes.h + +SOURCES += \ + $$PWD/bluetoothdevice_p.cpp diff --git a/src/bluetoothsettings/bluez/datatypes.h b/src/bluetoothsettings/bluez/datatypes.h new file mode 100644 index 0000000..e172378 --- /dev/null +++ b/src/bluetoothsettings/bluez/datatypes.h @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef DATATYPES_H +#define DATATYPES_H + +#include <QObject> +#include <QtDBus> +#include <QMap> +#include <QVariantMap> +#include <QtDBus/QDBusObjectPath> +#include <QtCore/QMetaType> + +typedef QMap<QString, QVariantMap> InterfaceList; +typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList; + +Q_DECLARE_METATYPE(InterfaceList) +Q_DECLARE_METATYPE(ManagedObjectList) + + +#endif // DATATYPES_H diff --git a/src/bluetoothsettings/bluez/device1.xml b/src/bluetoothsettings/bluez/device1.xml new file mode 100644 index 0000000..5b16992 --- /dev/null +++ b/src/bluetoothsettings/bluez/device1.xml @@ -0,0 +1,31 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="org.bluez.Device1"> + <method name="Disconnect"></method> + <method name="Connect"></method> + <method name="ConnectProfile"> + <arg name="UUID" type="s" direction="in"/> + </method> + <method name="DisconnectProfile"> + <arg name="UUID" type="s" direction="in"/> + </method> + <method name="Pair"></method> + <method name="CancelPairing"></method> + <property name="Address" type="s" access="read"></property> + <property name="Name" type="s" access="read"></property> + <property name="Alias" type="s" access="readwrite"></property> + <property name="Appearance" type="q" access="read"></property> + <property name="Icon" type="s" access="read"></property> + <property name="Paired" type="b" access="read"></property> + <property name="Trusted" type="b" access="readwrite"></property> + <property name="Blocked" type="b" access="readwrite"></property> + <property name="LegacyPairing" type="b" access="read"></property> + <property name="RSSI" type="n" access="read"></property> + <property name="Connected" type="b" access="read"></property> + <property name="UUIDs" type="as" access="read"></property> + <property name="Modalias" type="s" access="read"></property> + <property name="Adapter" type="o" access="read"></property> + </interface> +</node> + diff --git a/src/bluetoothsettings/bluez/objectmanager.xml b/src/bluetoothsettings/bluez/objectmanager.xml new file mode 100644 index 0000000..e52d6fe --- /dev/null +++ b/src/bluetoothsettings/bluez/objectmanager.xml @@ -0,0 +1,20 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="org.freedesktop.DBus.ObjectManager"> + <method name="GetManagedObjects"> + <arg type="a{oa{sa{sv}}}" name="object_paths_interfaces_and_properties" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ManagedObjectList"/> + </method> + <signal name="InterfacesAdded"> + <arg type="o" name="object_path"/> + <arg type="a{sa{sv}}" name="interfaces_and_properties"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="InterfaceList"/> + </signal> + <signal name="InterfacesRemoved"> + <arg type="o" name="object_path"/> + <arg type="as" name="interfaces"/> + </signal> + </interface> +</node> + diff --git a/src/bluetoothsettings/discoverymodel.cpp b/src/bluetoothsettings/discoverymodel.cpp new file mode 100644 index 0000000..00dbb0c --- /dev/null +++ b/src/bluetoothsettings/discoverymodel.cpp @@ -0,0 +1,238 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QBluetoothAddress> +#include "discoverymodel.h" + +BtDeviceItem::BtDeviceItem(const QBluetoothDeviceInfo& bt, QObject *parent) + : QObject(parent) + ,m_name(bt.name()) + ,m_address(bt.address().toString()) + ,m_connected(false) +{ + m_type = getDeviceType(bt.majorDeviceClass(), bt.minorDeviceClass()); +} + +QString BtDeviceItem::name() const +{ + return m_name; +} + +QString BtDeviceItem::address() const +{ + return m_address; +} + +bool BtDeviceItem::connected() const +{ + return m_connected; +} + +void BtDeviceItem::setConnected(bool aConnected) +{ + m_connected = aConnected; + emit connectedChanged(); +} + +BtDeviceItem::DeviceType BtDeviceItem::type() const +{ + return m_type; +} + +BtDeviceItem::DeviceType BtDeviceItem::getDeviceType(const QBluetoothDeviceInfo::MajorDeviceClass major, const quint8 minor) const +{ + switch (major) { + case QBluetoothDeviceInfo::ComputerDevice: + return getComputerDeviceType(minor); + break; + case QBluetoothDeviceInfo::PhoneDevice: + return getPhoneDeviceType(minor); + break; + case QBluetoothDeviceInfo::AudioVideoDevice: + return getAudioDeviceType(minor); + break; + case QBluetoothDeviceInfo::PeripheralDevice: + return getPeripheralDeviceType(minor); + break; + case QBluetoothDeviceInfo::ImagingDevice: + return getImagingDeviceType(minor); + break; + default: + return GenericDevice; + } + return GenericDevice; +} + +BtDeviceItem::DeviceType BtDeviceItem::getComputerDeviceType(const quint8 minor) const +{ + Q_UNUSED(minor); + return Computer; +} + +BtDeviceItem::DeviceType BtDeviceItem::getAudioDeviceType(const quint8 minor) const +{ + switch (minor) { + case QBluetoothDeviceInfo::Microphone: + return Microphone; + break; + case QBluetoothDeviceInfo::WearableHeadsetDevice: + case QBluetoothDeviceInfo::Headphones: + return Headphones; + break; + case QBluetoothDeviceInfo::Camcorder: + case QBluetoothDeviceInfo::VideoCamera: + return Camcorder; + break; + default: + return GenericDevice; + break; + } +} + +BtDeviceItem::DeviceType BtDeviceItem::getPeripheralDeviceType(const quint8 minor) const +{ + switch (minor) { + case QBluetoothDeviceInfo::KeyboardPeripheral: + return Keyboard; + break; + case QBluetoothDeviceInfo::PointingDevicePeripheral: + return Mouse; + break; + default: + return GenericDevice; + break; + } +} + +BtDeviceItem::DeviceType BtDeviceItem::getImagingDeviceType(const quint8 minor) const +{ + switch (minor) { + case QBluetoothDeviceInfo::ImageCamera: + return Camera; + break; + default: + return GenericDevice; + break; + } +} + +BtDeviceItem::DeviceType BtDeviceItem::getPhoneDeviceType(const quint8 minor) const +{ + Q_UNUSED(minor); + return Phone; +} + + +DiscoveryModel::DiscoveryModel(QObject *parent) + : QAbstractListModel(parent) + ,m_discoveryAgent(new QBluetoothDeviceDiscoveryAgent(this)) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Address, "address"); + m_roleNames.insert(Name, "name"); + m_roleNames.insert(Type, "type"); + m_roleNames.insert(Connected, "connected"); + + connect(m_discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), + this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); + + connect(m_discoveryAgent, SIGNAL(finished()), + this, SIGNAL(scanFinished())); + +} + +void DiscoveryModel::deviceDiscovered(const QBluetoothDeviceInfo &device) +{ + beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); + BtDeviceItem *item = new BtDeviceItem(device); + m_items.append(item); + endInsertRows(); +} + +DiscoveryModel::~DiscoveryModel() +{ + +} + +void DiscoveryModel::scanDevices() +{ + m_discoveryAgent->start(); +} + +QHash<int, QByteArray> DiscoveryModel::roleNames() const +{ + return m_roleNames; +} + +int DiscoveryModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant DiscoveryModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + BtDeviceItem *item = m_items[index.row()]; + + switch (role) { + case DiscoveryModel::Name: + return item->name(); + break; + case DiscoveryModel::Address: + return item->address(); + break; + case DiscoveryModel::Type: + return item->type(); + break; + case DiscoveryModel::Connected: + return item->connected(); + default: + return QVariant(); + } +} + +void DiscoveryModel::setConnected(const QString &aAddress, bool connected) +{ + bool found = false; + int i = 0; + QVector<int> role; + role.append(DiscoveryModel::Connected); + foreach (BtDeviceItem *item, m_items) { + if (item->address() == aAddress) { + item->setConnected(connected); + found = true; + break; + } + i++; + } + + if (found) + emit dataChanged(index(i, 0), index(i, 0), role); +} diff --git a/src/bluetoothsettings/discoverymodel.h b/src/bluetoothsettings/discoverymodel.h new file mode 100644 index 0000000..d9678a3 --- /dev/null +++ b/src/bluetoothsettings/discoverymodel.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef DISCOVERYMODEL_H +#define DISCOVERYMODEL_H + + +#include <QObject> +#include <QAbstractListModel> +#include <QBluetoothDeviceInfo> +#include <QBluetoothDeviceDiscoveryAgent> + +class Q_DECL_EXPORT BtDeviceItem : public QObject +{ + Q_OBJECT + Q_ENUMS(DeviceType) + Q_PROPERTY(QString address READ address CONSTANT) + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) + Q_PROPERTY(DeviceType type READ type CONSTANT) +public: + explicit BtDeviceItem(const QBluetoothDeviceInfo& id, QObject *parent=0); + //The list of device type we want to show the icon + enum DeviceType { + Phone, + Computer, + Mouse, + Keyboard, + Headphones, + Microphone, + Camera, + Camcorder, + Clock, + HealthDevice, + GenericDevice=1000 + }; + QString name() const; + QString address() const; + DeviceType type() const; + bool connected() const; + void setConnected(bool aConnected); + +signals: + void connectedChanged(); + +protected: + DeviceType getDeviceType(const QBluetoothDeviceInfo::MajorDeviceClass major, + const quint8 minor) const; + DeviceType getComputerDeviceType(const quint8 minor) const; + DeviceType getAudioDeviceType(const quint8 minor) const; + DeviceType getPeripheralDeviceType(const quint8 minor) const; + DeviceType getImagingDeviceType(const quint8 minor) const; + DeviceType getHealthDeviceType(const quint8 minor) const; + DeviceType getPhoneDeviceType(const quint8 minor) const; + +private: + QString m_name; + QString m_address; + bool m_connected; + DeviceType m_type; +}; + +class Q_DECL_EXPORT DiscoveryModel : public QAbstractListModel +{ + Q_OBJECT + Q_ENUMS(DeviceType) +public: + explicit DiscoveryModel(QObject *parent=0); + virtual ~DiscoveryModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + void setConnected(const QString& aAddress, bool connected); + void scanDevices(); + + enum Roles { + Name = Qt::UserRole, + Address, + Type, + Connected + }; + +signals: + void scanFinished(); + +private slots: + void deviceDiscovered(const QBluetoothDeviceInfo &device); +private: + QList<BtDeviceItem*> m_items; + QHash<int, QByteArray> m_roleNames; + QBluetoothDeviceDiscoveryAgent *m_discoveryAgent; +}; +#endif // DISCOVERYMODEL_H diff --git a/src/displaysettings/displaysettings.cpp b/src/displaysettings/displaysettings.cpp new file mode 100644 index 0000000..0ab5177 --- /dev/null +++ b/src/displaysettings/displaysettings.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "displaysettings.h" +#include "displaysettings_p.h" + +DisplaySettings::DisplaySettings(QObject *parent) + : QObject(parent) + ,d_ptr(new DisplaySettingsPrivate(this)) +{ +} + +DisplaySettings::~DisplaySettings() +{ +} + + +/*! + * Sets the display brightness (i.e. the intensity of the backlight) + * to \a value. A value of 255 requests maximum brightness, while 0 requests + * minimum (typically, the backlight turned off). + * + * Returns true on success. + */ +bool DisplaySettings::setDisplayBrightness(int v) +{ + Q_D(DisplaySettings); + return d->setDisplayBrightness(v); +} + + +/*! + * Returns the current backlight intensity. + * \sa setDisplayBrightness + */ +int DisplaySettings::displayBrightness() +{ + Q_D(DisplaySettings); + return d->displayBrightness(); +} + + +int DisplaySettings::physicalScreenSizeInch() const +{ + Q_D(const DisplaySettings); + return d->physicalScreenSizeInch(); +} + +void DisplaySettings::setPhysicalScreenSizeInch(int inches) +{ + Q_D(DisplaySettings); + d->setPhysicalScreenSizeInch(inches); +} + +bool DisplaySettings::physicalScreenSizeOverride() const +{ + Q_D(const DisplaySettings); + return d->physicalScreenSizeOverride(); +} + +void DisplaySettings::setPhysicalScreenSizeOverride(bool enable) +{ + Q_D(DisplaySettings); + d->setPhysicalScreenSizeOverride(enable); +} diff --git a/src/displaysettings/displaysettings.h b/src/displaysettings/displaysettings.h new file mode 100644 index 0000000..c0032d8 --- /dev/null +++ b/src/displaysettings/displaysettings.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef DISPLAYSETTINGS_H +#define DISPLAYSETTINGS_H + +#include <qobject.h> + +class DisplaySettingsPrivate; + +class Q_DECL_EXPORT DisplaySettings : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int displayBrightness READ displayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged) + Q_PROPERTY(int physicalScreenSizeInch READ physicalScreenSizeInch WRITE setPhysicalScreenSizeInch NOTIFY physicalScreenSizeInchChanged) + Q_PROPERTY(bool physicalScreenSizeOverride READ physicalScreenSizeOverride WRITE setPhysicalScreenSizeOverride NOTIFY physicalScreenSizeOverrideChanged) + +public: + DisplaySettings(QObject *parent = 0); + ~DisplaySettings(); + + int displayBrightness(); + int physicalScreenSizeInch() const; + bool physicalScreenSizeOverride() const; + +public Q_SLOTS: + bool setDisplayBrightness(int value); + void setPhysicalScreenSizeInch(int inches); + void setPhysicalScreenSizeOverride(bool enable); + +signals: + void displayBrightnessChanged(int newValue); + void physicalScreenSizeInchChanged(int newInches); + void physicalScreenSizeOverrideChanged(bool newValue); + +protected: + DisplaySettingsPrivate *d_ptr; + + Q_DISABLE_COPY(DisplaySettings) + Q_DECLARE_PRIVATE(DisplaySettings) +}; + +#endif // DISPLAYSETTINGS_H diff --git a/src/displaysettings/displaysettings.pro b/src/displaysettings/displaysettings.pro new file mode 100644 index 0000000..c03168d --- /dev/null +++ b/src/displaysettings/displaysettings.pro @@ -0,0 +1,17 @@ +load(qt_build_config) + +TARGET = QtDisplaySettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core + +MODULE = displaysettings +load(qt_module) + +SOURCES += displaysettings.cpp \ + displaysettings_p.cpp + +HEADERS += displaysettings.h \ + displaysettings_p.h + diff --git a/src/displaysettings/displaysettings_p.cpp b/src/displaysettings/displaysettings_p.cpp new file mode 100644 index 0000000..7e4cb58 --- /dev/null +++ b/src/displaysettings/displaysettings_p.cpp @@ -0,0 +1,241 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtMath> +#include <QDirIterator> +#include "displaysettings_p.h" + +DisplaySettingsPrivate::DisplaySettingsPrivate(DisplaySettings *qq) + :q_ptr(qq) + ,m_brightness(255) + ,m_lightDevicesInitialized(false) + ,m_physScreenSize(new PhysicalScreenSize(qq)) +{ + +} + +void DisplaySettingsPrivate::initLightDevices() +{ + if (m_lightDevicesInitialized) + return; + QDirIterator it(QStringLiteral("/sys/class/backlight")); + while (it.hasNext()) { + LightDevice ld; + ld.deviceFile = it.next() + QStringLiteral("/brightness"); + QFile maxFile(it.filePath() + QStringLiteral("/max_brightness")); + if (!maxFile.open(QIODevice::ReadOnly)) + continue; + bool ok = false; + ld.maxValue = maxFile.read(10).simplified().toUInt(&ok); + if (!ok || !ld.maxValue) + continue; + QFile valFile(ld.deviceFile); + if (!valFile.open(QIODevice::ReadOnly)) + continue; + ok = false; + uint val = valFile.read(10).simplified().toUInt(&ok); + if (!ok) + continue; + // map max->max as that is a common case, otherwise choose a reasonable value + ld.value = (val == ld.maxValue) ? 255 : (val * 256)/(ld.maxValue+1); + ld.name = it.fileName(); + m_lightDevices.append(ld); + } + if (!m_lightDevices.isEmpty()) + m_brightness = m_lightDevices.at(0).value; + m_lightDevicesInitialized = true; +} + + +bool DisplaySettingsPrivate::setDisplayBrightness(int v) +{ + Q_Q(DisplaySettings); + quint8 value = qBound(0, v, 255); + initLightDevices(); + for (int i = 0; i < m_lightDevices.size(); i++) { + LightDevice &ld = m_lightDevices[i]; + QFile devFile(ld.deviceFile); + if (!devFile.open(QIODevice::WriteOnly)) + continue; + // Maps only 0 to 0, since 0 often means "off"; other values are degrees of "on". + uint newVal = value ? 1 + ((value * ld.maxValue) / 256) : 0; + devFile.write(QByteArray::number(newVal)); + ld.value = value; + } + m_brightness = value; + return true; +} + +int DisplaySettingsPrivate::displayBrightness() +{ + initLightDevices(); + return m_brightness; +} + +int DisplaySettingsPrivate::physicalScreenSizeInch() const +{ + return m_physScreenSize->size(); +} + +void DisplaySettingsPrivate::setPhysicalScreenSizeInch(int inches) +{ + Q_Q(DisplaySettings); + if (m_physScreenSize->size() != inches) { + m_physScreenSize->setSize(inches); + emit q->physicalScreenSizeInchChanged(inches); + } +} + +bool DisplaySettingsPrivate::physicalScreenSizeOverride() const +{ + return m_physScreenSize->enabled(); +} + +void DisplaySettingsPrivate::setPhysicalScreenSizeOverride(bool enable) +{ + Q_Q(DisplaySettings); + if (m_physScreenSize->enabled() != enable) { + m_physScreenSize->setEnabled(enable); + emit q->physicalScreenSizeOverrideChanged(enable); + } +} + +PhysicalScreenSize::PhysicalScreenSize(QObject *parent) + : QObject(parent) + ,physScreenSizeEnabled(false), physScreenSizeInch(7) +{ + physWriteTimer.setSingleShot(true); + physWriteTimer.setInterval(1000); + QObject::connect(&physWriteTimer, SIGNAL(timeout()), this, SLOT(onTimeout())); + + read(QStringLiteral("/etc/appcontroller.conf")); + read(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf")); +} + +PhysicalScreenSize::~PhysicalScreenSize() +{ + +} + +void PhysicalScreenSize::read(const QString &filename) +{ + QFile f(filename); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + int physScreenWidth = 154, physScreenHeight = 90; + int found = 0; + while (!f.atEnd()) { + QByteArray line = f.readLine().trimmed(); + if (line.startsWith(QByteArrayLiteral("env="))) { + QByteArrayList values = line.split('='); + if (values.count() == 3) { + bool ok; + if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_WIDTH")) { + int val = values[2].toInt(&ok); + if (ok) { + ++found; + physScreenWidth = val; + } + } else if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_HEIGHT")) { + int val = values[2].toInt(&ok); + if (ok) { + ++found; + physScreenHeight = val; + } + } + } + } + } + if (found == 2) + physScreenSizeEnabled = true; + + const qreal diagMM = qSqrt(physScreenWidth * physScreenWidth + physScreenHeight * physScreenHeight); + physScreenSizeInch = qRound(diagMM / 25.4); +} + +void PhysicalScreenSize::onTimeout() +{ + write(); +} + +void PhysicalScreenSize::write(bool includePhysSize) +{ + QDir(QStringLiteral("/var/lib")).mkpath(QStringLiteral("b2qt/appcontroller.conf.d")); + write(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf"), includePhysSize); +} + +void PhysicalScreenSize::write(const QString &filename, bool includePhysSize) +{ + QFile f(filename); + + QByteArrayList lines; + if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { + while (!f.atEnd()) { + QByteArray line = f.readLine().trimmed(); + if (!line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=")) + && !line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_HEIGHT="))) + lines.append(line); + } + f.close(); + } + + if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) + return; + + const qreal diagMM = physScreenSizeInch * 25.4; + // Assume 16:9 aspect ratio + const int physScreenHeight = qRound(diagMM / 1.975); + const int physScreenWidth = qRound(physScreenHeight * 1.777); + + foreach (const QByteArray &line, lines) + f.write(line + QByteArrayLiteral("\n")); + + if (includePhysSize) + f.write(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=") + QByteArray::number(physScreenWidth) + + QByteArrayLiteral("\nenv=QT_QPA_EGLFS_PHYSICAL_HEIGHT=") + QByteArray::number(physScreenHeight) + + QByteArrayLiteral("\n")); +} + +void PhysicalScreenSize::setSize(int inches) +{ + physScreenSizeInch = inches; + physWriteTimer.start(); +} + +bool PhysicalScreenSize::enabled() const +{ + return physScreenSizeEnabled; +} + +void PhysicalScreenSize::setEnabled(bool enable) +{ + physScreenSizeEnabled = enable; + // Rewrite appcontroller.conf with or without the physical width/height lines. + write(enable); +} diff --git a/src/displaysettings/displaysettings_p.h b/src/displaysettings/displaysettings_p.h new file mode 100644 index 0000000..672eb95 --- /dev/null +++ b/src/displaysettings/displaysettings_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef DISPLAYSETTINGSPRIVATE_H +#define DISPLAYSETTINGSPRIVATE_H + +#include <QTimer> +#include "displaysettings.h" + +class PhysicalScreenSize : public QObject +{ + Q_OBJECT + +public: + explicit PhysicalScreenSize(QObject *parent=0); + virtual ~PhysicalScreenSize(); + + void setSize(int inches); + int size() const { return physScreenSizeInch; } + bool enabled() const; + void setEnabled(bool enable); + +private slots: + void onTimeout(); + +private: + void read(const QString &filename); + void write(bool includePhysSize = true); + void write(const QString &filename, bool includePhysSize = true); + + bool physScreenSizeEnabled; + int physScreenSizeInch; + QTimer physWriteTimer; +}; + +class LightDevice +{ +public: + QString name; + QString deviceFile; + quint8 value; + uint maxValue; +}; + +class DisplaySettingsPrivate +{ + Q_DECLARE_PUBLIC(DisplaySettings) +public: + DisplaySettingsPrivate(DisplaySettings* qq); + int displayBrightness(); + int physicalScreenSizeInch() const; + bool physicalScreenSizeOverride() const; + + bool setDisplayBrightness(int value); + void setPhysicalScreenSizeInch(int inches); + void setPhysicalScreenSizeOverride(bool enable); +private: + void initLightDevices(); + DisplaySettings *q_ptr; + int m_brightness; + int m_screenSizeInch; + bool m_sizeOverride; + QList<LightDevice> m_lightDevices; + bool m_lightDevicesInitialized; + PhysicalScreenSize *m_physScreenSize; +}; + +#endif // DISPLAYSETTINGSPRIVATE_H diff --git a/src/doc/src/devices/qtee-drive-cx.qdoc b/src/doc/src/devices/qtee-drive-cx.qdoc new file mode 100644 index 0000000..439d2a4 --- /dev/null +++ b/src/doc/src/devices/qtee-drive-cx.qdoc @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** All rights reserved. +** For any questions to The Qt Company, please use the contact form at +** http://www.qt.io/contact-us +** +** This file is part of Qt for Device Creation. +** +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +****************************************************************************/ +/*! + \page qtee-preparing-hardware-drivecx.html + \title NVIDIA DRIVE CX + \previouspage qtee-installation-guide.html + + Take the following steps when preparing \l {http://www.nvidia.com/object/drive-cx.html} + {NVIDIA DRIVE CX} for \B2Q: + + \note It is important that you repeat the steps in this section after you + update \QAS. + + The image containing the \B2Q stack for the device, as well as the + flashing tool are included in \QAS. + + \section1 Installing the \B2Q Image + + Connect the DRIVE CX board to the development host via USB, and set it in + \e {recovery mode} by changing the position of J9 jumper on the board. + + Then, run the flashing tool: + + \badcode + cd <INSTALL_DIR> + sudo 5.7/Automotive/tegra-t18x/flash-nvidia/flash_device.sh + \endcode + + After the installation is complete, replace the J9 jumper to its original + position, and restart the device. After reboot, check that the automotive + UI appears. + + \section1 Setting up USB Access + + \include b2qt-post-install-setup.qdocinc setting up usb access + + \section1 Configuring a Device Kit in Qt Creator + + After you have prepared the hardware, you must perform one final step + to set up the development tools in Qt Creator for your device. Run the + following command: + + \badcode + cd <INSTALL_DIR> + 5.7/Automotive/tegra-t18x/toolchain/configure-qtcreator.sh + \endcode + + You are now ready to start developing for your device. For more information, + see \l{Building and Running an Example}. +*/ diff --git a/src/doc/src/devices/qtee-intel-nuc.qdoc b/src/doc/src/devices/qtee-intel-nuc.qdoc new file mode 100644 index 0000000..7213e3b --- /dev/null +++ b/src/doc/src/devices/qtee-intel-nuc.qdoc @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** All rights reserved. +** For any questions to The Qt Company, please use the contact form at +** http://www.qt.io/contact-us +** +** This file is part of Qt for Device Creation. +** +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +****************************************************************************/ +/*! + \page qtee-preparing-hardware-nuc.html + \title Intel NUC + \previouspage qtee-installation-guide.html + + Take the following steps when preparing an + \l {http://www.intel.com/content/www/us/en/nuc/overview.html}{Intel NUC} + for \B2Q: + + \note It is important that you repeat the steps in this section after you + update \SDK. + + The images containing the \B2Q stack for the device are included + in \SDK. In these instructions, we prepare a USB device (a flash drive + or an external USB hard drive) to boot from. + + \section1 Preparing a USB Boot Device + + For \B2Q, a USB drive of at least 2 GB capacity is needed. + + \include detect-sd-card-device-name.qdocinc instructions-usbdevice + + \section1 Installing the \B2Q Image + + \include common.qdocinc wizard + + Install the \B2Q image onto the USB device. First, ensure that no + partitions are mounted: + + \include detect-sd-card-device-name.qdocinc unmount + + Then, use the following command to install the image: + + \badcode + cd <INSTALL_DIR> + sudo dd bs=4k if=5.7/Automotive/intel-corei7-64/images/b2qt-embedded-qt5-image-intel-corei7-64.img of=/dev/<device_name> + \endcode + + After the installation is complete, connect the USB drive to the device, + power it on, and enter the BIOS setup (\b F2). Follow the instructions on + \l {http://www.intel.com/content/www/us/en/support/boards-and-kits/000005471.html} + {Operating System Installation for Intel® NUC} for how to select the + USB drive as a boot device. + + Press \b F10 to save your changes and exit BIOS setup. After reboot, check that the + \B2Q welcome screen and/or demo appear. + + \section1 Setting up USB Access + + \include b2qt-post-install-setup.qdocinc setting up usb access + + \section1 Configuring a Device Kit in Qt Creator + + \include b2qt-post-install-setup.qdocinc configuring device kit linux + + You are now ready to start developing for your device. For more information, + see \l{Building and Running an Example}. +*/ diff --git a/src/doc/src/qtee-build-emulator.qdoc b/src/doc/src/qtee-build-emulator.qdoc new file mode 100644 index 0000000..f87354d --- /dev/null +++ b/src/doc/src/qtee-build-emulator.qdoc @@ -0,0 +1,207 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** All rights reserved. +** For any questions to The Qt Company, please use the contact form at +** http://www.qt.io/contact-us +** +** This file is part of Qt for Device Creation. +** +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +****************************************************************************/ + +/*! + \page qtee-build-emulator.html + \title Building the Emulator from Sources + \previouspage qtee-static-linking.html + \nextpage qtee-changelog.html + + To build the emulator from source, you need to build the emulator host part + and an emulator device image for a VirtualBox virtual machine. + + \section1 Building Emulator Host Part from Sources + + To build the emulator host part from sources: + + \list 1 + \li Create a directory for the emulator parts: + + \badcode + mkdir emulator + cd emulator + \endcode + + \li Clone the emulator repositories: + + \badcode + git clone ssh://codereview.qt-project.org/tqtc-boot2qt/emulator-scripts.git scripts + git clone ssh://codereview.qt-project.org/tqtc-boot2qt/emulator emulator + cd emulator + git submodule update --init + cd .. + \endcode + + \li Create a build directory for a shadow build: + + \badcode + mkdir build + cd build + \endcode + + \li Build the QtSystems module: + + \badcode + mkdir qtsystems + pushd qtsystems + qmake "${EMULATOR_SOURCE_DIR}"/src/qtsystems + make + make install + popd + \endcode + + \li Build the QtSimulator module: + + \badcode + mkdir simulator + pushd simulator + qmake "${EMULATOR_SOURCE_DIR}"/src/qtsimulator + make + make install + popd + \endcode + + \li Build the QtGlesStream component: + + \badcode + mkdir qtglesstream + pushd qtglesstream + qmake "${EMULATOR_SOURCE_DIR}"/src/qtglesstream + make + make install + popd + \endcode + + \li Build the emulator: + + \badcode + mkdir emulator + pushd emulator + EMULATOR_INSTALL_DIR=../install/ + qmake "${EMULATOR_SOURCE_DIR}" PREFIX="${EMULATOR_INSTALL_DIR}" + make + make install + popd + \endcode + + \endlist + + \section1 Building Emulator Device Image for VirtualBox VM + + To build the emulator device image for a VirtualBox VM: + + \list 1 + \li Make sure that your Qt library is built with GLES support and + defaults to eglfs. + \li Make sure that the virtual machine is reachable with the IP address + \c 192.168.56.101. + \li Create a shared folder on the virtual machine and mount it to + \c /var/vqvideo by using the \c vboxsf kernel module and a mount + tool for the folder. You can get these from the VirtualBox addons + provided by Oracle or compile them yourself from the VirtualBox + sources. + + \badcode + mkdir -p /var/vqvideo + mount.vboxsf vqvideo /var/vqvideo + \endcode + + \li Set up \c appcontroller, as instructed in + \l{Setting Up appcontroller}. + \li Build the \c emulatorproxy daemon that is located in the emulator + sources in the \c src/helperlibs/proxy directory: + + \badcode + cd "${EMULATOR_SOURCE_DIR}"/src/helperlibs/proxy + sdk-qmake && make + \endcode + + \li Start the \c emulatorproxy daemon on the device to enable the + emulator to perform several tasks on the running machine. The daemon + will fork itself. + \li Clone the QtSimulator module from + \c ssh://codereview.qt-project.org/tqtc-boot2qt/qtsimulator, and + then build and deploy it on the device as any Qt module: + + \badcode + git clone ssh://codereview.qt-project.org:29418/tqtc-boot2qt/qtsimulator + cd qtsimulator + sdk-qmake && make && make install + \endcode + + \li Clone the QtGlesStream module from + \c ssh://codereview.qt-project.org/qt/tqtc-qtglesstream, and then + build and deploy it on the device: + + \badcode + git clone ssh://codereview.qt-project.org:29418/qt/tqtc-qtglesstream + tqtc-qtglesstream + sdk-qmake && make && make install + \endcode + + \li To enable handling touch and keyboard input, build the emulator + specific input plugin from the emulator sources in the + \c src/helperlibs/vinput directory using qmake and deploy it to the + Qt input plugin folder on the device: + + \badcode + cd "${EMULATOR_SOURCE_DIR}"/src/helperlibs/vinput + sdk-qmake && make && make install + \endcode + + \endlist + + \section2 Setting Up appcontroller + + To set up \c appcontroller: + + \list 1 + \li Clone the \c appcontroller sources from + \c git://codereview.qt-project.org/tqtc-boot2qt/appcontroller. + \li Build \c appcontroller using qmake and make. + \li Set \c appcontroller in the PATH. + \li Create a configuration file for \c appcontroller to configure device + specific variables for your application. + \endlist + + An example \c /etc/appcontroller.conf configuration file looks like this: + + \badcode + env=QT_QPA_GENERIC_PLUGINS=simulator + env=QT_QPA_EGLFS_HIDECURSOR=1 + env=QML2_IMPORT_PATH=/data/user/qt/qmlplugins + env=QT_IM_MODULE=qtvirtualkeyboard + env=QTGLESSTREAM_DISPLAY=192.168.56.1 + env=QT_QUICK_CONTROLS_STYLE=Flat + base=linux + platform=emulator + \endcode + + \table + \row + \li \c base + \li Has to be \c linux + \row + \li \c platform + \li Has to be \c emulator + \row + \li \c env + \li All these variables will be added to the environment before + starting the application. + \endtable +*/ diff --git a/src/imports/bluetoothsettings/bluetoothsettings.pro b/src/imports/bluetoothsettings/bluetoothsettings.pro new file mode 100644 index 0000000..3e6e6b5 --- /dev/null +++ b/src/imports/bluetoothsettings/bluetoothsettings.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml bluetooth bluetoothsettings +uri = QtDeviceUtilities.BluetoothSettings + +TARGET = btsettingsplugin + +pluginfiles.files += \ + qmldir \ + +SOURCES += plugin.cpp + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles diff --git a/src/imports/bluetoothsettings/plugin.cpp b/src/imports/bluetoothsettings/plugin.cpp new file mode 100644 index 0000000..abd6ec3 --- /dev/null +++ b/src/imports/bluetoothsettings/plugin.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <qcoreapplication.h> +#include <QQmlEngine> +#include <QQmlContext> + +#include "bluetoothdevice.h" +#include "discoverymodel.h" + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class BluetoothSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("QtDeviceUtilities.BluetoothSettings")); + qmlRegisterUncreatableType<BtDeviceItem>(uri, 1, 0, "BtDeviceItem", "Cannot be instantiated directly."); + qmlRegisterSingletonType<BluetoothDevice>(uri, 1, 0, "BtDevice", &instance<BluetoothDevice>); + } +}; + +#include "plugin.moc" diff --git a/src/imports/bluetoothsettings/qmldir b/src/imports/bluetoothsettings/qmldir new file mode 100644 index 0000000..eda1c88 --- /dev/null +++ b/src/imports/bluetoothsettings/qmldir @@ -0,0 +1,2 @@ +module QtDeviceUtilities.BluetoothSettings +plugin btsettingsplugin diff --git a/src/imports/displaysettings/displaysettings.pro b/src/imports/displaysettings/displaysettings.pro new file mode 100644 index 0000000..c148227 --- /dev/null +++ b/src/imports/displaysettings/displaysettings.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml displaysettings + +uri = QtDeviceUtilities.DisplaySettings + +TARGET = qmldisplaysettingsplugin + +SOURCES += plugin.cpp \ + +pluginfiles.files += \ + qmldir \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles diff --git a/src/imports/displaysettings/plugin.cpp b/src/imports/displaysettings/plugin.cpp new file mode 100644 index 0000000..a57b340 --- /dev/null +++ b/src/imports/displaysettings/plugin.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <QQmlEngine> +#include <qcoreapplication.h> +#include "displaysettings.h" + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class GeneralSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + qmlRegisterType(QUrl("qrc:/Display.qml"), uri, 1, 0, "Display"); + qmlRegisterSingletonType<DisplaySettings>(uri, 1, 0, "DisplaySettings", &instance<DisplaySettings>); + } +}; + +#include "plugin.moc" diff --git a/src/imports/displaysettings/qmldir b/src/imports/displaysettings/qmldir new file mode 100644 index 0000000..35c1462 --- /dev/null +++ b/src/imports/displaysettings/qmldir @@ -0,0 +1,2 @@ +module QtDeviceUtilities.DisplaySettings +plugin qmldisplaysettingsplugin diff --git a/src/imports/imports.pro b/src/imports/imports.pro index 0b5a551..f34be18 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,2 +1,7 @@ TEMPLATE = subdirs -SUBDIRS += utils wifi +SUBDIRS += networksettings \ + bluetoothsettings \ + localesettings \ + timedatesettings \ + localdevice \ + displaysettings diff --git a/src/imports/localdevice/localdevice.pro b/src/imports/localdevice/localdevice.pro new file mode 100644 index 0000000..0ef1980 --- /dev/null +++ b/src/imports/localdevice/localdevice.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +CONFIG += plugin +TARGET = localdeviceplugin +uri = QtDeviceUtilities.LocalDeviceSettings + +QT += qml localdevice + +pluginfiles.files += \ + qmldir \ + +SOURCES += plugin.cpp + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles diff --git a/src/imports/localdevice/plugin.cpp b/src/imports/localdevice/plugin.cpp new file mode 100644 index 0000000..4ede971 --- /dev/null +++ b/src/imports/localdevice/plugin.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <qlocaldevice.h> +#include <QtQml> + +/*! + \qmlmodule QtDeviceUtilities.LocalDeviceSettings 1.0 + \title Qt Local Device QML Module + \ingroup qtee-qmlmodules + \brief A collection of the local device related utility functions, accessible from QML. +*/ + +/*! + \page b2qt-addon-utils.html + \title Qt Local Device Module + \ingroup qtee-modules + \brief A collection of the local device realted utility functions, accessible from QML. + + Provides utility functions for controlling an embedded + device, such as device shutdown/reboot. + + Import the module as follows: + + \badcode + import QtDeviceUtilities.LocalDeviceSettings 1.0 + \endcode + + This will give you access to the singleton QML type LocalDevice. + + \note Some functions are currently only implemented for one of + the platforms. + + \section1 QML Types + + \annotatedlist utils-qmltypes +*/ + +/*! + \qmltype LocalDevice + \inqmlmodule QtDeviceUtilities.LocalDeviceSettings + \ingroup utils-qmltypes + \brief Singleton QML type providing access to utility functions. + + LocalDevice QML type is the interface to various utility + functions. + + There is no need to create an instance of this object. To use it, + simply import the \c {LocalDevice} module: + + \qml + QtDeviceUtilities.LocalDeviceSettings + + \endqml + + \note Some functions are currently only implemented for one of + the platforms. +*/ + +/*! + \qmlmethod LocalDevice::reboot() + + Reboots the system. Does not return. + + \sa powerOff() +*/ + +/*! + \qmlmethod LocalDevice::powerOff() + + Shuts down the system. Does not return. + + \sa reboot() +*/ + +static QObject *module_api_factory(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + QLocalDevice *api = new QLocalDevice(); + + return api; +} + +class B2QtUtilsPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + B2QtUtilsPlugin() + { + } + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "QtDeviceUtilities.LocalDeviceSettings"); + qmlRegisterSingletonType<QLocalDevice>(uri, 1, 0, "LocalDevice", module_api_factory); + } +}; + +#include "plugin.moc" diff --git a/src/imports/utils/plugins.qmltypes b/src/imports/localdevice/plugins.qmltypes index 88acb66..88acb66 100644 --- a/src/imports/utils/plugins.qmltypes +++ b/src/imports/localdevice/plugins.qmltypes diff --git a/src/imports/localdevice/qmldir b/src/imports/localdevice/qmldir new file mode 100644 index 0000000..1d9791b --- /dev/null +++ b/src/imports/localdevice/qmldir @@ -0,0 +1,3 @@ +module QtDeviceUtilities.LocalDeviceSettings +plugin localdeviceplugin +typeinfo plugins.qmltypes diff --git a/src/imports/localesettings/locale.xml b/src/imports/localesettings/locale.xml new file mode 100644 index 0000000..b722456 --- /dev/null +++ b/src/imports/localesettings/locale.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> +<node> + <interface name="org.freedesktop.locale1"> + <property name="Locale" type="as" access="read"/> + <method name="SetLocale"> + <arg name="locale" type="as" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + </interface> +</node> + diff --git a/src/imports/localesettings/localesettings.pro b/src/imports/localesettings/localesettings.pro new file mode 100644 index 0000000..35656ea --- /dev/null +++ b/src/imports/localesettings/localesettings.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml localesettings + +uri = QtDeviceUtilities.LocaleSettings + +TARGET = localesettingsplugin + +SOURCES += plugin.cpp + +pluginfiles.files += \ + qmldir \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles diff --git a/src/imports/localesettings/plugin.cpp b/src/imports/localesettings/plugin.cpp new file mode 100644 index 0000000..737ff0c --- /dev/null +++ b/src/imports/localesettings/plugin.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <qcoreapplication.h> +#include <QQmlEngine> +#include <QQmlContext> + +#include <systemlocale.h> +#include "localefiltermodel.h" + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class LanguageSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + qmlRegisterSingletonType<SystemLocale>(uri, 1, 0, "LocaleManager", &instance<SystemLocale>); + qmlRegisterSingletonType<LocaleFilterModel>(uri, 1, 0, "LocaleFilter", &instance<LocaleFilterModel>); + } +}; + +#include "plugin.moc" diff --git a/src/imports/localesettings/qmldir b/src/imports/localesettings/qmldir new file mode 100644 index 0000000..e02d748 --- /dev/null +++ b/src/imports/localesettings/qmldir @@ -0,0 +1,2 @@ +module QtDeviceUtilities.LocaleSettings +plugin localesettingsplugin diff --git a/src/imports/networksettings/networksettings.pro b/src/imports/networksettings/networksettings.pro new file mode 100644 index 0000000..1b16421 --- /dev/null +++ b/src/imports/networksettings/networksettings.pro @@ -0,0 +1,34 @@ +TEMPLATE = lib +TARGET = networksettingsplugin +QT += qml quick networksettings +CONFIG += qt plugin + +uri = QtDeviceUtilities.NetworkSettings + +SOURCES += \ + plugin.cpp \ + +HEADERS += \ + plugin.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 + +pluginfiles.files += \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +pluginfiles.path = $$installPath +qmldir.path = $$installPath +target.path = $$installPath +INSTALLS += target qmldir pluginfiles + diff --git a/src/imports/networksettings/plugin.cpp b/src/imports/networksettings/plugin.cpp new file mode 100644 index 0000000..5427082 --- /dev/null +++ b/src/imports/networksettings/plugin.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "plugin.h" +#include <qnetworksettings.h> +#include <qnetworksettingsmanager.h> +#include <qnetworksettingsservice.h> +#include <qnetworksettingsuseragent.h> + +#include <qqml.h> +#include <QQmlEngine> +#include <QQmlContext> + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +void NetworksettingspluginPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("QtDeviceUtilities.NetworkSettings")); + qmlRegisterUncreatableType<QNetworkSettingsService>(uri, 1, 0, "NetworkService", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsIPv4>(uri, 1, 0, "NetworkSettingsIPv4", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsIPv6>(uri, 1, 0, "NetworkSettingsIPv6", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsProxy>(uri, 1, 0, "NetworkSettingsProxy", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsType>(uri, 1, 0, "NetworkSettingsType", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<QNetworkSettingsState>(uri, 1, 0, "NetworkSettingsState", "Cannot be instantiated directly."); + + qRegisterMetaType<QNetworkSettingsUserAgent*>("QNetworkSettingsUserAgent*"); + qmlRegisterSingletonType<QNetworkSettingsManager>(uri, 1, 0, "NetworkSettingsManager", &instance<QNetworkSettingsManager>); +} diff --git a/src/imports/networksettings/plugin.h b/src/imports/networksettings/plugin.h new file mode 100644 index 0000000..61f148c --- /dev/null +++ b/src/imports/networksettings/plugin.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef NETWORKSETTINGSPLUGIN_PLUGIN_H +#define NETWORKSETTINGSPLUGIN_PLUGIN_H + +#include <QQmlExtensionPlugin> + +class NetworksettingspluginPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri); +}; + +#endif // NETWORKSETTINGSPLUGIN_PLUGIN_H + diff --git a/src/imports/networksettings/qmldir b/src/imports/networksettings/qmldir new file mode 100644 index 0000000..c2c0dec --- /dev/null +++ b/src/imports/networksettings/qmldir @@ -0,0 +1,3 @@ +module QtDeviceUtilities.NetworkSettings +plugin networksettingsplugin + diff --git a/src/imports/timedatesettings/plugin.cpp b/src/imports/timedatesettings/plugin.cpp new file mode 100644 index 0000000..c725a10 --- /dev/null +++ b/src/imports/timedatesettings/plugin.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <qcoreapplication.h> +#include <QQmlEngine> +#include <QQmlContext> + +#include <systemtime.h> +#include "timezonefiltermodel.h" + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +class TimeDateSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + qmlRegisterSingletonType<SystemTime>(uri, 1, 0, "TimeManager", &instance<SystemTime>); + qmlRegisterSingletonType<TimezoneFilterModel>(uri, 1, 0, "TimezonesFilter", &instance<TimezoneFilterModel>); + } +}; + +#include "plugin.moc" diff --git a/src/imports/timedatesettings/qmldir b/src/imports/timedatesettings/qmldir new file mode 100644 index 0000000..cd39356 --- /dev/null +++ b/src/imports/timedatesettings/qmldir @@ -0,0 +1,2 @@ +module QtDeviceUtilities.TimeDateSettings +plugin qmltimedatesettingsplugin diff --git a/src/imports/timedatesettings/timedatesettings.pro b/src/imports/timedatesettings/timedatesettings.pro new file mode 100644 index 0000000..5e5f913 --- /dev/null +++ b/src/imports/timedatesettings/timedatesettings.pro @@ -0,0 +1,19 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml timedatesettings + +uri = QtDeviceUtilities.TimeDateSettings + +DESTDIR = imports/TimeDate +TARGET = qmltimedatesettingsplugin + +SOURCES += plugin.cpp + +pluginfiles.files += qmldir + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles + diff --git a/src/imports/utils/plugin.cpp b/src/imports/utils/plugin.cpp deleted file mode 100644 index a4f8810..0000000 --- a/src/imports/utils/plugin.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include <b2qtdevice.h> -#include <QtQml> - -/*! - \qmlmodule B2Qt.Utils 1.0 - \title B2Qt Utils QML Module - \ingroup qtee-qmlmodules - \brief A collection of utility functions, accessible from QML. -*/ - -/*! - \page b2qt-addon-utils.html - \title B2Qt Utils Module - \ingroup qtee-modules - \brief A collection of utility functions, accessible from QML. - - Provides various utility functions for controlling an embedded - device, such as display brightness, IP address and hostname, and - device shutdown/reboot. - - Import the module as follows: - - \badcode - import B2Qt.Utils 1.0 - \endcode - - This will give you access to the singleton QML type B2QtDevice. - - \note Some functions are currently only implemented for one of - the platforms. - - \section1 QML Types - - \annotatedlist utils-qmltypes -*/ - -/*! - \qmltype B2QtDevice - \inqmlmodule B2Qt.Utils - \ingroup utils-qmltypes - \brief Singleton QML type providing access to utility functions. - - B2QtDevice QML type is the interface to various utility - functions. - - There is no need to create an instance of this object. To use it, - simply import the \c {B2Qt.Utils} module: - - \qml - import B2Qt.Utils 1.0 - - Text { - text: qsTr("IP Address:") + B2QtDevice.ipAddress - } - \endqml - - \note Some functions are currently only implemented for one of - the platforms. -*/ - -/*! - \qmlmethod B2Qt.Utils::B2QtDevice::reboot() - - Reboots the system. Does not return. - - \sa powerOff() -*/ - -/*! - \qmlmethod B2Qt.Utils::B2QtDevice::powerOff() - - Shuts down the system. Does not return. - - \sa reboot() -*/ - -/*! - \qmlproperty int B2Qt.Utils::B2QtDevice::masterVolume - - This property holds the master volume of the device. - The volume can range from \c 0 to \c 100 and is linear. - Changing the master volume will affect all audio streams. - - \note Currently implemented only for \B2QA. -*/ - -/*! - \qmlproperty int B2Qt.Utils::B2QtDevice::displayBrightness - This property holds the display brightness (the intensity of the backlight). - The value is in the range from \c 0 to \c 255, where 255 is the maximum - brightness, and 0 is the minimum (typically, the backlight is turned off). - - \note Currently implemented only for \B2QA. -*/ - -/*! - \qmlproperty string B2Qt.Utils::B2QtDevice::ipAddress - \readonly - - This property holds the current IP address(es) of the device - for all active network interfaces. If multiple IP addresses are defined, - this property holds a comma-separated list. The localhost (loopback) - IP addresses are omitted. - - \sa hostname -*/ - -/*! - \qmlproperty string B2Qt.Utils::B2QtDevice::hostname - - This property holds the current hostname of the device. - - \sa ipAddress -*/ - -static QObject *module_api_factory(QQmlEngine *engine, QJSEngine *scriptEngine) -{ - Q_UNUSED(engine) - Q_UNUSED(scriptEngine) - B2QtDevice *api = new B2QtDevice(); - - return api; -} - -class B2QtUtilsPlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") - -public: - B2QtUtilsPlugin() - { - } - - void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == "B2Qt.Utils"); - qmlRegisterSingletonType<B2QtDevice>(uri, 1, 0, "B2QtDevice", module_api_factory); - } -}; - -#include "plugin.moc" diff --git a/src/imports/utils/qmldir b/src/imports/utils/qmldir deleted file mode 100644 index e5e0b31..0000000 --- a/src/imports/utils/qmldir +++ /dev/null @@ -1,3 +0,0 @@ -module B2Qt.Utils -plugin b2qtutilsplugin -typeinfo plugins.qmltypes diff --git a/src/imports/utils/utils.pro b/src/imports/utils/utils.pro deleted file mode 100644 index a580643..0000000 --- a/src/imports/utils/utils.pro +++ /dev/null @@ -1,10 +0,0 @@ -CXX_MODULE = qml -TARGET = b2qtutilsplugin -TARGETPATH = B2Qt/Utils -IMPORT_VERSION = 1.0 - -QT += qml b2qtutils - -SOURCES += plugin.cpp - -load(qml_plugin) diff --git a/src/imports/wifi/pluginmain.cpp b/src/imports/wifi/pluginmain.cpp deleted file mode 100644 index b498b66..0000000 --- a/src/imports/wifi/pluginmain.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include <B2QtWifi/QWifiManager> -#include <B2QtWifi/QWifiDevice> -#include <B2QtWifi/QWifiConfiguration> - -#include <QtQml> - -QT_BEGIN_NAMESPACE - -/*! - \qmlmodule B2Qt.Wifi 1.0 - \title B2Qt Wifi QML Module - \ingroup qtee-qmlmodules - \brief A module for managing wireless network connectivity. - -*/ - -/*! - \page b2qt-addon-wifi.html - \title B2Qt Wifi Module - \ingroup qtee-modules - \brief A module for managing wireless network connectivity. - - B2Qt.Wifi provides QML types and C++ classes for: - - \list - \li Wifi backend handling - \li Retrieval of information from Wifi network access points - \li Wifi connection handling - \li System's network interface configuration - \li Other tasks that allow the device to access network - \endlist - - \section1 Writing the Code - - Depending on what fits best with the application, you can choose to use - either C++ or QML for accessing Wifi functionality. If the majority of the - user interface is written in QML, it is recommended that you use the QML - types, which provide a simpler and declarative way to handle Wifi networks. - - \list - \li \l{Getting Started with B2Qt.Wifi in QML} - \li \l{Getting Started with B2Qt.Wifi in C++} - \endlist - - \section1 API Reference - - \section2 QML Types - - \annotatedlist wifi-qmltypes - - \section2 C++ Classes - - \annotatedlist wifi-cppclasses -*/ - -/*! - \module B2Qt.Wifi.Cpp 1.0 - \title B2Qt Wifi C++ Module - \ingroup qtee-cppmodules - \brief A module for managing wireless network connectivity. -*/ - -/*! - \qmltype WifiManager - \inqmlmodule B2Qt.Wifi - \ingroup wifi-qmltypes - \brief Main interface to the Wifi functionality. - - WifiManager is a singleton type that is a central point for handling Wifi functionality - related tasks. You can use WifiManager's API to control the Wifi backend, scan surroundings for - Wifi access points and connect a device to a wireless network. - - When scanning for networks, WifiManager packs the results in a list-based data model which can - be used with Qt's Model/View classes. Information about the Wifi networks is supplied via the model's - interface, accessed with the following roles: - - \list - \li \e ssid - informal (human) name of a Wifi network (string) - \li \e bssid - basic service set identification of a network, used to uniquely identify BSS (string) - \li \e signalStrength - strength of a Wifi signal represented as percentage (0-100) (int) - \li \e supportsWPA - holds whether network access point supports WPA security protocol (bool) - \li \e supportsWPA2 - holds whether network access point supports WPA2 security protocol (bool) - \li \e supportsWEP - holds whether network access point supports WEP security protocol (bool) - \li \e supportsWPS - holds whether network access point supports WPS security protocol (bool) - \endlist - */ - -/*! - \qmlproperty enumeration WifiManager::NetworkState - \readonly - - This property holds the current state of the network connection. - - \list - \li \e WifiManager.Disconnected - Not connected to any network - \li \e WifiManager.Authenticating - Verifying password with the network provider - \li \e WifiManager.HandshakeFailed - Incorrect password provided - \li \e WifiManager.ObtainingIPAddress - Requesting IP address from DHCP server - \li \e WifiManager.DhcpRequestFailed - Could not retrieve IP address - \li \e WifiManager.Connected - Ready to process network requests - \endlist -*/ - -/*! - \qmlproperty enumeration WifiManager::BackendState - \readonly - - This property holds the current state of the Wifi backend. - - \list - \li \e WifiManager.Initializing - Wireless supplicant is starting up - \li \e WifiManager.Running - Supplicant is initialized and ready to process commands - \li \e WifiManager.Terminating - Shutting down wireless supplicant - \li \e WifiManager.NotRunning - Wireless supplicant process is not running - \endlist -*/ - -/*! - \qmlsignal WifiManager::networkStateChanged(NetworkState networkState) - - This signal is emitted whenever changes in a network state occur. The network name for - which the NetworkState change events are send can be obtained from currentSSID. - - \sa NetworkState, currentSSID -*/ - -/*! - \qmlsignal WifiManager::backendStateChanged(BackendState backendState) - - This signal is emitted whenever changes in a backend state occur. - - \sa start, stop -*/ - -/*! - \qmlsignal WifiManager::currentSSIDChanged(string currentSSID) - - This signal is emitted when switching between different Wifi networks. - - \sa start, stop -*/ - -/*! - \qmlsignal WifiManager::scanningChanged(bool scanning) - - This signal is emitted when device starts or stops to scan for available Wifi networks. - - \sa scanning -*/ - -/*! - \qmlsignal WifiManager::lastErrorChanged(string error) - - This signal is emitted if some internal process has failed, \a error contains - a message on what has failed. - - \sa connect -*/ - -/*! - \qmlproperty model WifiManager::networks - \readonly - - This property holds a list-based data model of networks that can be sensed by a device. - Model can be used with Qt's Model/View classes like ListView. Data in the model is updated - every 5 seconds if scanning is enabled. - - \sa scanning -*/ - -/*! - \qmlproperty string WifiManager::currentSSID - \readonly - - This property holds a network name of last selected network, the network for - which the NetworkState change events are sent. Property can contain an empty - string when no active network connection exists. -*/ - -/*! - \qmlmethod WifiManager::start() - - Start the Wifi backend. This function returns immediately, the BackendState - change events are delivered asynchronously. - - \sa stop, BackendState -*/ - -/*! - \qmlmethod WifiManager::stop() - - Stop the Wifi backend and if connected to any network shut down the network connection. - This function returns immediately, the BackendState change events are delivered asynchronously. - - \sa start, BackendState -*/ - -/*! - \qmlproperty bool WifiManager::scanning - - This property holds whether or not the backend is scanning for Wifi networks. To - preserve battery energy, set this property to false when scanning is not required. - When enabled, new readings are taken every 5 seconds. - - For scanning to work, first you need to initialize the Wifi backend. - - \sa start -*/ - -/*! - \qmlproperty string WifiManager::lastError - \readonly - - This property holds an error message if some internal process has failed. - - \sa connect -*/ - -/*! - \qmlmethod bool WifiManager::connect(WifiConfiguration config) - - Connect a device to a network using the \a config network configuration. - This method returns \a true if the network with provoded configuration could be - successfully added by the backend or \a false on failure, to obtain an error message - read lastError property. - - \sa disconnect, NetworkState, lastError -*/ - -/*! - \qmlmethod WifiManager::disconnect() - - Disconnect from currently connected network connection. - - \sa connect, NetworkState -*/ - -/*! - \qmltype WifiDevice - \inqmlmodule B2Qt.Wifi - \ingroup wifi-qmltypes - \brief Represents a physical device. - - Use this element to query if a device is Wifi capable, before attempting - to use the functionality of WifiManager. - - \qml - import B2Qt.Wifi 1.0 - - GroupBox { - id: wifiOptions - title: "Wifi" - visible: false - - Component.onCompleted: { - if (WifiDevice.wifiSupported()) { - var component = Qt.createComponent("WifiGroupBoxContent.qml") - var wifi = component.createObject(wifiOptions.contentItem) - if (wifi) - wifiOptions.visible = true - } else { - print("Wifi functionality not available on this device.") - } - } - } - \endqml -*/ - -/*! - \qmlmethod bool WifiDevice::wifiSupported() - - Returns \a true if a device is Wifi capable - Wifi driver and firmware has been - successfully loaded by the system, otherwise returns \a false. -*/ - -/*! - \qmltype WifiConfiguration - \inqmlmodule B2Qt.Wifi - \ingroup wifi-qmltypes - \brief Used to define a network configuration. - - WifiConfiguration object represents a single network configuration. Use this object - to configure a properties of your network, for example what passphrase and security - protocol to use. WifiManager's connect() function takes this object and connects a - device to a network that matches the provided configuration. -*/ - -/*! - \qmlproperty string WifiConfiguration::ssid - - This property holds informal (human) name of a Wifi network. -*/ - -/*! - \qmlproperty string WifiConfiguration::passphrase - - This property holds the passphrase to use for authenticating with a network. -*/ - -/*! - \qmlproperty string WifiConfiguration::protocol - - This property holds the security protocols to use for Wifi connection. - WPA is used by default if property is not set, supported values are: WPA, WPA2, WEP, WPS. -*/ - -/*! - \qmlproperty bool WifiConfiguration::ssidHidden - - If a Wifi access point does not broadcast its SSID, setting this property - to \c true ensures that the Wifi backend can detect the specified network. - - By default this property is set to \c false. -*/ - -static QObject *globalWifiDevice(QQmlEngine *, QJSEngine *) -{ - return new QWifiDevice; -} - -static QObject *globalWifiManager(QQmlEngine *, QJSEngine *) -{ - return QWifiManager::instance(); -} - -class QWifiPlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") - -public: - virtual void registerTypes(const char *uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("B2Qt.Wifi")); - - qmlRegisterType<QAbstractListModel>(); - qmlRegisterSingletonType<QWifiManager>(uri, 1, 0, "WifiManager", globalWifiManager); - qmlRegisterSingletonType<QWifiDevice>(uri, 1, 0, "WifiDevice", globalWifiDevice); - qmlRegisterType<QWifiConfiguration>(uri, 1, 0, "WifiConfiguration"); - } -}; - -QT_END_NAMESPACE - -#include "pluginmain.moc" diff --git a/src/imports/wifi/plugins.qmltypes b/src/imports/wifi/plugins.qmltypes deleted file mode 100644 index c59d12c..0000000 --- a/src/imports/wifi/plugins.qmltypes +++ /dev/null @@ -1,90 +0,0 @@ -import QtQuick.tooling 1.1
-
-// This file describes the plugin-supplied types contained in the library.
-// It is used for QML tooling purposes only.
-//
-// This file was auto-generated by:
-// 'qmlplugindump -nonrelocatable B2Qt.Wifi 1.0 /system/qml/B2Qt/Wifi/'
-
-Module {
- Component {
- name: "QWifiConfiguration"
- prototype: "QObject"
- exports: ["B2Qt.Wifi/WifiConfiguration 1.0"]
- exportMetaObjectRevisions: [0]
- Property { name: "ssid"; type: "string" }
- Property { name: "passphrase"; type: "string" }
- Property { name: "protocol"; type: "string" }
- }
- Component {
- name: "QWifiDevice"
- prototype: "QObject"
- exports: ["B2Qt.Wifi/WifiDevice 1.0"]
- isCreatable: false
- isSingleton: true
- exportMetaObjectRevisions: [0]
- Method { name: "wifiSupported"; type: "bool" }
- }
- Component {
- name: "QWifiManager"
- prototype: "QObject"
- exports: ["B2Qt.Wifi/WifiManager 1.0"]
- isCreatable: false
- isSingleton: true
- exportMetaObjectRevisions: [0]
- Enum {
- name: "NetworkState"
- values: {
- "Disconnected": 0,
- "Authenticating": 1,
- "HandshakeFailed": 2,
- "ObtainingIPAddress": 3,
- "DhcpRequestFailed": 4,
- "Connected": 5
- }
- }
- Enum {
- name: "BackendState"
- values: {
- "Initializing": 0,
- "Running": 1,
- "Terminating": 2,
- "NotRunning": 3
- }
- }
- Property { name: "networkState"; type: "NetworkState"; isReadonly: true }
- Property { name: "backendState"; type: "BackendState"; isReadonly: true }
- Property { name: "scanning"; type: "bool" }
- Property { name: "currentSSID"; type: "string"; isReadonly: true }
- Property { name: "lastError"; type: "string"; isReadonly: true }
- Property { name: "networks"; type: "QAbstractListModel"; isReadonly: true; isPointer: true }
- Signal {
- name: "scanningChanged"
- Parameter { name: "scanning"; type: "bool" }
- }
- Signal {
- name: "networkStateChanged"
- Parameter { name: "networkState"; type: "NetworkState" }
- }
- Signal {
- name: "backendStateChanged"
- Parameter { name: "backendState"; type: "BackendState" }
- }
- Signal {
- name: "currentSSIDChanged"
- Parameter { name: "currentSSID"; type: "string" }
- }
- Signal {
- name: "lastErrorChanged"
- Parameter { name: "error"; type: "string" }
- }
- Method { name: "start" }
- Method { name: "stop" }
- Method {
- name: "connect"
- type: "bool"
- Parameter { name: "config"; type: "QWifiConfiguration"; isPointer: true }
- }
- Method { name: "disconnect" }
- }
-}
diff --git a/src/imports/wifi/qmldir b/src/imports/wifi/qmldir deleted file mode 100644 index 7e99b56..0000000 --- a/src/imports/wifi/qmldir +++ /dev/null @@ -1,3 +0,0 @@ -module B2Qt.Wifi -plugin b2qtwifiplugin -typeinfo plugins.qmltypes diff --git a/src/imports/wifi/wifi.pro b/src/imports/wifi/wifi.pro deleted file mode 100644 index b130587..0000000 --- a/src/imports/wifi/wifi.pro +++ /dev/null @@ -1,12 +0,0 @@ -CXX_MODULE = qml -TARGET = b2qtwifiplugin -TARGETPATH = B2Qt/Wifi -IMPORT_VERSION = 1.0 - -QT += qml b2qtwifi - -SOURCES += pluginmain.cpp - -OTHER_FILES += qmldir - -load(qml_plugin) diff --git a/src/localdevice/localdevice.pro b/src/localdevice/localdevice.pro new file mode 100644 index 0000000..e6e5bc9 --- /dev/null +++ b/src/localdevice/localdevice.pro @@ -0,0 +1,16 @@ +load(qt_build_config) + +TARGET = QtLocalDevice +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core + +MODULE = localdevice +load(qt_module) + +HEADERS += \ + $$PWD/qlocaldevice.h + +SOURCES += \ + $$PWD/qlocaldevice.cpp diff --git a/src/localdevice/qlocaldevice.cpp b/src/localdevice/qlocaldevice.cpp new file mode 100644 index 0000000..d778f20 --- /dev/null +++ b/src/localdevice/qlocaldevice.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qlocaldevice.h" +#include <unistd.h> +#include <sys/reboot.h> + +QLocalDevice::QLocalDevice(QObject *parent) + : QObject(parent) +{ +} + +QLocalDevice::~QLocalDevice() +{ +} + +/*! + * Reboots the system. Does not return. + * + * \sa powerOff() + */ +void QLocalDevice::reboot() +{ + sync(); + ::reboot(RB_AUTOBOOT); + qWarning("reboot returned"); +} + + +/*! + * Shuts down the system. Does not return. + * + * \sa reboot() + */ +void QLocalDevice::powerOff() +{ + sync(); + ::reboot(RB_POWER_OFF); + qWarning("powerOff returned"); +} + diff --git a/src/localdevice/qlocaldevice.h b/src/localdevice/qlocaldevice.h new file mode 100644 index 0000000..7376527 --- /dev/null +++ b/src/localdevice/qlocaldevice.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QLOCALDEVICE_H +#define QLOCALDEVICE_H + +#include <qobject.h> + +class Q_DECL_EXPORT QLocalDevice : public QObject +{ + Q_OBJECT + +public: + QLocalDevice(QObject *parent = 0); + ~QLocalDevice(); + +public Q_SLOTS: + void reboot(); + void powerOff(); +}; + +#endif // QLOCALDEVICE_H diff --git a/src/localesettings/locale.xml b/src/localesettings/locale.xml new file mode 100644 index 0000000..b722456 --- /dev/null +++ b/src/localesettings/locale.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> +<node> + <interface name="org.freedesktop.locale1"> + <property name="Locale" type="as" access="read"/> + <method name="SetLocale"> + <arg name="locale" type="as" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + </interface> +</node> + diff --git a/src/localesettings/localefiltermodel.cpp b/src/localesettings/localefiltermodel.cpp new file mode 100644 index 0000000..d45fac6 --- /dev/null +++ b/src/localesettings/localefiltermodel.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "localemodel.h" +#include "localefiltermodel.h" + +LocaleFilterModel::LocaleFilterModel(QObject* parent) + :QSortFilterProxyModel(parent) +{ + connect(this, &LocaleFilterModel::filterChanged, this, &LocaleFilterModel::invalidate); + LocaleModel *localeModel = new LocaleModel(this); + setSourceModel(localeModel); +} + +LocaleFilterModel::~LocaleFilterModel() +{ + +} + +QString LocaleFilterModel::filter() const +{ + return m_filter; +} + +void LocaleFilterModel::setFilter(const QString& aFilter) +{ + m_filter = aFilter; + emit filterChanged(); +} + +bool LocaleFilterModel::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const +{ + bool ret = false; + if (this->sourceModel()) + { + QModelIndex index = this->sourceModel()->index( source_row, 0, source_parent ); + if (index.isValid()) + { + QVariant nameRole = index.data(LocaleModel::Country); + if (nameRole.isValid()) + { + QString name = nameRole.toString(); + if (name.contains(m_filter, Qt::CaseInsensitive)) { + ret = true; + } + } + } + } + return ret; +} + +QVariant LocaleFilterModel::itemFromRow(const int row) const +{ + QModelIndex idx = index(row, 0); + QModelIndex mapped = mapToSource(idx); + if (mapped.isValid()) + { + QVariant nameRole = mapped.data(LocaleModel::Code); + if (nameRole.isValid()) + { + return nameRole; + } + } + return QVariant(); +} + diff --git a/src/localesettings/localefiltermodel.h b/src/localesettings/localefiltermodel.h new file mode 100644 index 0000000..c885dd3 --- /dev/null +++ b/src/localesettings/localefiltermodel.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LOCALEFILTERMODEL_H +#define LOCALEFILTERMODEL_H + +#include <QSortFilterProxyModel> + +class Q_DECL_EXPORT LocaleFilterModel : public QSortFilterProxyModel +{ + Q_OBJECT + Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) +public: + explicit LocaleFilterModel(QObject* parent); + virtual ~LocaleFilterModel(); + bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; + QString filter() const; + void setFilter(const QString& aFilter); + Q_INVOKABLE QVariant itemFromRow(const int row) const; +signals: + void filterChanged(); +private: + QString m_filter; + +}; + +#endif // LOCALEFILTERMODEL_H diff --git a/src/localesettings/localemodel.cpp b/src/localesettings/localemodel.cpp new file mode 100644 index 0000000..b5a934b --- /dev/null +++ b/src/localesettings/localemodel.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QLocale> +#include <QFuture> +#include <QFutureWatcher> +#include <QThread> +#include <QtConcurrent/QtConcurrentRun> +#include "localemodel.h" + + +LocaleItem::LocaleItem(const QLocale& locale, QObject *parent) + :QObject(parent) +{ + m_code = locale.name(); + m_country = locale.nativeCountryName(); + if (m_country.isEmpty()) { + m_country = locale.countryToString(locale.country()); + } + + m_language = locale.nativeLanguageName(); + if (m_language.isEmpty()) { + m_language = locale.languageToString(locale.language()); + } +} + +QString LocaleItem::language() const +{ + return m_language; +} + +QString LocaleItem::country() const +{ + return m_country; +} + +QString LocaleItem::code() const +{ + return m_code; +} + +LocaleModel::LocaleModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Country, "country"); + m_roleNames.insert(Language, "language"); + m_roleNames.insert(Code, "code"); + + QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this); + QFuture<void> future = QtConcurrent::run(LocaleModel::generateModel, this); + watcher->setFuture(future); + connect(watcher, SIGNAL(finished()), this, SLOT(modelReady())); +} + +void LocaleModel::modelReady() +{ + beginResetModel(); + sort(0); + endResetModel(); +} + +void LocaleModel::generateModel(LocaleModel* model) +{ + QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); + + for (const QLocale &locale : allLocales) { + if (locale.name() != QStringLiteral("C")) { + LocaleItem *l = new LocaleItem(locale); + l->moveToThread(model->thread()); + QMetaObject::invokeMethod(model, "addNewItem", Q_ARG( QObject*, qobject_cast<QObject*>(l))); + } + } +} + +void LocaleModel::addNewItem(QObject *item) +{ + beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); + LocaleItem* newItem = qobject_cast<LocaleItem*>(item); + if (newItem) + m_items.append(newItem); + endInsertRows(); +} + +LocaleModel::~LocaleModel() +{ + qDeleteAll(m_items); +} + +QHash<int, QByteArray> LocaleModel::roleNames() const +{ + return m_roleNames; +} + +int LocaleModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant LocaleModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + LocaleItem *item = m_items[index.row()]; + + switch (role) { + case Qt::UserRole: + return QVariant::fromValue(static_cast<QObject*>(item)); + break; + case Country: + return item->country(); + break; + case Language: + return item->language(); + break; + case Code: + return item->code(); + break; + default: + return QVariant(); + } +} + +bool LocaleModel::variantLessThan(const LocaleItem* v1, const LocaleItem* v2) +{ + return v1->language() < v2->language(); +} + +void LocaleModel::sort(int column, Qt::SortOrder order) +{ + Q_UNUSED(column); + Q_UNUSED(order); + std::sort(m_items.begin(), m_items.end(), LocaleModel::variantLessThan); +} diff --git a/src/localesettings/localemodel.h b/src/localesettings/localemodel.h new file mode 100644 index 0000000..b77bea6 --- /dev/null +++ b/src/localesettings/localemodel.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LOCALEMODEL_H +#define LOCALEMODEL_H + +#include <QObject> +#include <QAbstractListModel> +#include <QLocale> +#include <QMutex> + +class LocaleItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString code READ code CONSTANT) + Q_PROPERTY(QString country READ country CONSTANT) + Q_PROPERTY(QString language READ language CONSTANT) +public: + explicit LocaleItem(const QLocale &locale, QObject *parent=0); + QString country() const; + QString language() const; + QString code() const; + +private: + QString m_country; + QString m_language; + QString m_code; +}; + +class Q_DECL_EXPORT LocaleModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit LocaleModel(QObject *parent=0); + virtual ~LocaleModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + void sort(int column, Qt::SortOrder order=Qt::AscendingOrder); + static bool variantLessThan(const LocaleItem* v1, const LocaleItem* v2); + + enum Roles { + Language = Qt::UserRole + 1, + Country, + Code + }; + + static void generateModel(LocaleModel* model); + +signals: + void addItem(LocaleItem* item); + +private slots: + void addNewItem(QObject* item); + void modelReady(); + +private: + QList<LocaleItem*> m_items; + QHash<int, QByteArray> m_roleNames; +}; +#endif // LOCALEMODEL_H diff --git a/src/localesettings/localesettings.pro b/src/localesettings/localesettings.pro new file mode 100644 index 0000000..808477d --- /dev/null +++ b/src/localesettings/localesettings.pro @@ -0,0 +1,22 @@ +load(qt_build_config) + +TARGET = QtLocaleSettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core dbus + +MODULE = localesettings +load(qt_module) + +DBUS_INTERFACES = locale.xml + +HEADERS = \ + systemlocale.h \ + systemlocale_p.h \ + localemodel.h \ + localefiltermodel.h +SOURCES += systemlocale.cpp \ + localemodel.cpp \ + localefiltermodel.cpp + diff --git a/src/localesettings/systemlocale.cpp b/src/localesettings/systemlocale.cpp new file mode 100644 index 0000000..37f157b --- /dev/null +++ b/src/localesettings/systemlocale.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QLocale> +#include "systemlocale.h" +#include "systemlocale_p.h" + +SystemLocale::SystemLocale(QObject *parent) + :QObject(parent) + ,d_ptr(new SystemLocalePrivate(this)) +{ +} + +QString SystemLocale::locale() const +{ + Q_D(const SystemLocale); + return d->locale(); +} + +void SystemLocale::setLocale(const QString& aLocale) +{ + Q_D(SystemLocale); + d->setLocale(aLocale); + emit localeChanged(); +} diff --git a/src/localesettings/systemlocale.h b/src/localesettings/systemlocale.h new file mode 100644 index 0000000..bc2e9cd --- /dev/null +++ b/src/localesettings/systemlocale.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LOCALE_H +#define LOCALE_H + +#include <QObject> + +class SystemLocalePrivate; + +class Q_DECL_EXPORT SystemLocale : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString locale READ locale WRITE setLocale NOTIFY localeChanged) +public: + explicit SystemLocale(QObject *parent = 0); + QString locale() const; + void setLocale(const QString& aLocale); +signals: + void localeChanged(); +public slots: + +protected: + SystemLocalePrivate *d_ptr; + + Q_DISABLE_COPY(SystemLocale) + Q_DECLARE_PRIVATE(SystemLocale) +}; + +#endif // LOCALE_H diff --git a/src/localesettings/systemlocale_p.h b/src/localesettings/systemlocale_p.h new file mode 100644 index 0000000..f5caed9 --- /dev/null +++ b/src/localesettings/systemlocale_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LOCALE_P_H +#define LOCALE_P_H + +#include "systemlocale.h" +#include "locale_interface.h" + +class SystemLocalePrivate +{ + Q_DECLARE_PUBLIC(SystemLocale) +public: + SystemLocalePrivate(SystemLocale *qq) + :q_ptr(qq) + { + m_localeInterface = new OrgFreedesktopLocale1Interface(QStringLiteral("org.freedesktop.locale1"), + QStringLiteral("/org/freedesktop/locale1"), + QDBusConnection::systemBus(), qq); + + QStringList locale = m_localeInterface->locale(); + foreach (QString l, locale) { + QStringList nameValue = l.split('='); + if (nameValue.length() == 2) + m_localeCache[nameValue.at(0)] = nameValue.at(1); + } + } + + QString locale() const { + return m_localeCache[QStringLiteral("LANG")]; + } + + void setLocale(const QString& aLocale) { + m_localeCache[QStringLiteral("LANG")] = aLocale; + updateLocale(); + } + + void updateLocale() { + QStringList newLocale; + QMap<QString, QString>::iterator i; + for (i = m_localeCache.begin(); i != m_localeCache.end(); ++i) { + QString val = i.key() + "=" + i.value(); + newLocale.append(val); + } + m_localeInterface->SetLocale(newLocale, true); + } + + +private: + QMap<QString, QString> m_localeCache; + OrgFreedesktopLocale1Interface *m_localeInterface; + SystemLocale *q_ptr; +}; + +#endif // LOCALE_P_H diff --git a/src/networksettings/connman.pri b/src/networksettings/connman.pri new file mode 100644 index 0000000..957f2f0 --- /dev/null +++ b/src/networksettings/connman.pri @@ -0,0 +1,22 @@ +QT += core network dbus + +INCLUDEPATH += $${PWD}/connman + +DBUS_INTERFACES = \ + connman/connman_manager.xml \ + connman/connman_service.xml \ + connman/connman_technology.xml + +SOURCES += \ + $$PWD/connman/qnetworksettingsinterface_p.cpp \ + $$PWD/connman/qnetworksettingsservice_p.cpp \ + $$PWD/connman/qnetworksettingsuseragent_p.cpp \ + $$PWD/connman/qnetworksettingsmanager_p.cpp \ + $$PWD/connman/connmancommon.cpp + +HEADERS += \ + $$PWD/connman/qnetworksettingsinterface_p.h \ + $$PWD/connman/qnetworksettingsservice_p.h \ + $$PWD/connman/qnetworksettingsuseragent_p.h \ + $$PWD/connman/qnetworksettingsmanager_p.h \ + $$PWD/connman/connmancommon.h diff --git a/src/networksettings/connman/connman_manager.xml b/src/networksettings/connman/connman_manager.xml new file mode 100644 index 0000000..c6ed244 --- /dev/null +++ b/src/networksettings/connman/connman_manager.xml @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Manager" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Manager"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="GetTechnologies" tp:name-for-bindings="Get_Technologies"> + <arg name="technologies" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapStructList"/> + </method> + + <method name="GetServices" tp:name-for-bindings="Get_Services"> + <arg name="services" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapStructList"/> + </method> + + <method name="GetSavedServices" tp:name-for-bindings="Get_Saved_Services"> + <arg name="services" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapStructList"/> + </method> + + <method name="RemoveSavedService" tp:name-for-bindings="Remove_Saved_Services"> + <arg name="identifier" type="s" direction="in"/> + </method> + + <method name="RegisterAgent" tp:name-for-bindings="Register_Agent"> + <arg name="path" type="o"/> + </method> + + <method name="UnregisterAgent" tp:name-for-bindings="Unregister_Agent"> + <arg name="path" type="o"/> + </method> + + <method name="RegisterCounter" tp:name-for-bindings="Register_Counter"> + <arg name="path" type="o"/> + <arg name="accuracy" type="u"/> + <arg name="period" type="u"/> + </method> + + <method name="UnregisterCounter" tp:name-for-bindings="Unregister_Counter"> + <arg name="path" type="o"/> + </method> + + <method name="ResetCounters" tp:name-for-bindings="Reset_Counters"> + <arg name="type" type="s"/> + </method> + + <method name="CreateSession" tp:name-for-bindings="Create_Session"> + <arg name="settings" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + <arg name="notifier" type="o"/> + <arg name="session" type="o" direction="out"/> + </method> + + <method name="DestroySession" tp:name-for-bindings="Destroy_Session"> + <arg name="session" type="o"/> + </method> + + <method name="RequestPrivateNetwork" tp:name-for-bindings="Request_Private_Network"> + <arg name="options" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + <arg name="path" type="o" direction="out"/> + <arg name="dict" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/> + <arg name="fd" type="i" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + </method> + + <method name="ReleasePrivateNetwork" tp:name-for-bindings="Release_Private_Network"> + <arg name="path" type="o"/> + </method> + + <signal name="NetworkTypeAdded" tp:name-for-bindings="NetworkType_Added"> + <arg name="technology" type="o"/> + <arg name="properties" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> + </signal> + + <signal name="NetworkTypeRemoved" tp:name-for-bindings="NetworkType_Removed"> + <arg name="technology" type="o"/> + </signal> + + <signal name="ServicesChanged" tp:name-for-bindings="Services_Changed"> + <arg name="changed" type="a(oa{sv})"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ConnmanMapStructList"/> + <arg name="removed" type="ao"/> + </signal> + + <signal name="SavedServicesChanged" tp:name-for-bindings="SavedServices_Changed"> + <arg name="changed" type="a(oa{sv})"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ConnmanMapStructList"/> + </signal> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/networksettings/connman/connman_service.xml b/src/networksettings/connman/connman_service.xml new file mode 100644 index 0000000..c41aca4 --- /dev/null +++ b/src/networksettings/connman/connman_service.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Service"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="ClearProperty" tp:name-for-bindings="Clear_Property"> + <arg name="name" type="s" /> + </method> + + <method name="Connect" tp:name-for-bindings="Connect" /> + + <method name="Disconnect" tp:name-for-bindings="Disconnect" /> + + <method name="Remove" tp:name-for-bindings="Remove" /> + + <method name="MoveBefore" tp:name-for-bindings="Move_Before"> + <arg name="service" type="o"/> + </method> + + <method name="MoveAfter" tp:name-for-bindings="Move_After"> + <arg name="service" type="o"/> + </method> + + <method name="ResetCounters" tp:name-for-bindings="Reset_Counters" /> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/networksettings/connman/connman_technology.xml b/src/networksettings/connman/connman_technology.xml new file mode 100644 index 0000000..08d780f --- /dev/null +++ b/src/networksettings/connman/connman_technology.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Technology"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="Scan" tp:name-for-bindings="Scan"/> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/networksettings/connman/connmancommon.cpp b/src/networksettings/connman/connmancommon.cpp new file mode 100644 index 0000000..f609f22 --- /dev/null +++ b/src/networksettings/connman/connmancommon.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "connmancommon.h" + +//Conversion operations for datatypes +const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMapStruct &obj) +{ + argument.beginStructure(); + argument >> obj.objectPath >> obj.propertyMap; + argument.endStructure(); + return argument; +} + +QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMapStruct &obj) +{ + argument.beginStructure(); + argument << obj.objectPath << obj.propertyMap; + argument.endStructure(); + return argument; +} + +const QString &operator>>(const QString &argument, QNetworkSettingsType &obj) +{ + if (argument == AttributeEthernet) { + obj.setType(QNetworkSettingsType::Wired); + } + else if (argument == AttributeWifi) { + obj.setType(QNetworkSettingsType::Wifi); + } + else { + obj.setType(QNetworkSettingsType::Unknown); + } + + return argument; +} + +const QString &operator>>(const QString &argument, QNetworkSettingsState &obj) +{ + if (argument == AttributeIdle) { + obj.setState(QNetworkSettingsState::Idle); + } + else if (argument == AttributeFailure) { + obj.setState(QNetworkSettingsState::Failure); + } + else if (argument == AttributeAssociation) { + obj.setState(QNetworkSettingsState::Association); + } + else if (argument == AttributeConfiguration) { + obj.setState(QNetworkSettingsState::Configuration); + } + else if (argument == AttributeReady) { + obj.setState(QNetworkSettingsState::Ready); + } + else if (argument == AttributeDisconnect) { + obj.setState(QNetworkSettingsState::Disconnect); + } + else if (argument == AttributeOneline) { + obj.setState(QNetworkSettingsState::Online); + } + else { + obj.setState(QNetworkSettingsState::Undefined); + } + return argument; +} diff --git a/src/networksettings/connman/connmancommon.h b/src/networksettings/connman/connmancommon.h new file mode 100644 index 0000000..b50a11d --- /dev/null +++ b/src/networksettings/connman/connmancommon.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef CONNMANCOMMON_H +#define CONNMANCOMMON_H + +#include <QtCore/QMetaType> +#include <QtDBus> +#include <qnetworksettings.h> + +#define AgentPath "/ConnmanAgent" +#define PropertyState QStringLiteral("State") +#define PropertyName QStringLiteral("Name") +#define PropertyType QStringLiteral("Type") +#define PropertyConnected QStringLiteral("Connected") +#define PropertyPowered QStringLiteral("Powered") + +#define AttributeWifi QStringLiteral("wifi") +#define AttributeEthernet QStringLiteral("ethernet") +#define AttributeIdle QStringLiteral("idle") +#define AttributeFailure QStringLiteral("failure") +#define AttributeAssociation QStringLiteral("association") +#define AttributeConfiguration QStringLiteral("configuration") +#define AttributeReady QStringLiteral("ready") +#define AttributeDisconnect QStringLiteral("disconnect") +#define AttributeOneline QStringLiteral("online") + +struct ConnmanMapStruct { + QDBusObjectPath objectPath; + QVariantMap propertyMap; +}; + +QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMapStruct &obj); +const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMapStruct &obj); + +const QString &operator>>(const QString &argument, QNetworkSettingsType &obj); +const QString &operator>>(const QString &argument, QNetworkSettingsState &obj); + +typedef QList<ConnmanMapStruct> ConnmanMapStructList; + +Q_DECLARE_METATYPE( ConnmanMapStruct ) +Q_DECLARE_METATYPE( ConnmanMapStructList ) + + +#endif // CONNMANCOMMON_H diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.cpp b/src/networksettings/connman/qnetworksettingsinterface_p.cpp new file mode 100644 index 0000000..3525aa7 --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsinterface_p.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsinterface.h" +#include "connman_technology_interface.h" +#include "connmancommon.h" + +QNetworkSettingsInterfacePrivate::QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent) + : QObject(parent) + ,q_ptr(parent) +{ + +} + +void QNetworkSettingsInterfacePrivate::initialize(const QString& path, const QVariantMap& properties) +{ + m_technology = new NetConnmanTechnologyInterface(QStringLiteral("net.connman"), path, + QDBusConnection::systemBus(), this); + connect(m_technology, SIGNAL(PropertyChanged(QString,QDBusVariant)), + this, SLOT(updateProperty(QString,QDBusVariant))); + + updateProperty(PropertyName, properties[PropertyName]); + updateProperty(PropertyType, properties[PropertyType]); + updateProperty(PropertyConnected, properties[PropertyConnected]); + updateProperty(PropertyPowered, properties[PropertyPowered]); +} + +void QNetworkSettingsInterfacePrivate::updateProperty(const QString &name, const QDBusVariant &value) +{ + updateProperty(name, value.variant()); +} + +void QNetworkSettingsInterfacePrivate::updateProperty(const QString &name, const QVariant &value) +{ + Q_Q(QNetworkSettingsInterface); + if (name == PropertyName) { + m_name = qdbus_cast<QString>(value); + } + else if (name == PropertyType) { + qdbus_cast<QString>(value) >> m_type; + emit q->typeChanged(); + } + else if (name == PropertyConnected) { + bool connected = qdbus_cast<bool>(value); + if (connected) + m_state.setState(QNetworkSettingsState::Online); + else + m_state.setState(QNetworkSettingsState::Disconnect); + emit q->stateChanged(); + } + else if (name == PropertyPowered) { + m_powered = qdbus_cast<bool>(value); + emit q->poweredChanged(); + } +} + +void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::States aState) +{ + Q_Q(QNetworkSettingsInterface); + m_state.setState(aState); + emit q->stateChanged(); +} + +void QNetworkSettingsInterfacePrivate::setPowered(const bool aPowered) +{ + m_technology->SetProperty(PropertyPowered, QDBusVariant(QVariant(aPowered))); +} + +void QNetworkSettingsInterfacePrivate::scan() +{ + m_technology->Scan(); +} diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.h b/src/networksettings/connman/qnetworksettingsinterface_p.h new file mode 100644 index 0000000..275e751 --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsinterface_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSINTERFACEPRIVATE_H +#define QNETWORKSETTINGSINTERFACEPRIVATE_H + +#include <QObject> +#include <QtDBus> +#include "qnetworksettings.h" +#include "qnetworksettingsinterface.h" + +class NetConnmanTechnologyInterface; + +class QNetworkSettingsInterfacePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsInterface) +public: + explicit QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent); + void initialize(const QString& path, const QVariantMap& properties); + void setPowered(const bool power); + void setState(QNetworkSettingsState::States aState); + void scan(); + +public slots: + void updateProperty(const QString &name, const QDBusVariant &value); +protected: + void updateProperty(const QString &name, const QVariant &value); + +protected: + NetConnmanTechnologyInterface *m_technology; + QString m_name; + QNetworkSettingsType m_type; + QNetworkSettingsState m_state; + bool m_powered; + QNetworkSettingsInterface *q_ptr; +}; + + +class ConnmanSettingsInterface : public QNetworkSettingsInterface +{ + Q_OBJECT +public: + ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent=0) + :QNetworkSettingsInterface(parent) + { + if (d_ptr) + d_ptr->initialize(path, properties); + } + + void setState(QNetworkSettingsState::States aState) { + Q_D(QNetworkSettingsInterface); + d->setState(aState); + } + + virtual ~ConnmanSettingsInterface() { + + } +}; +#endif // QNETWORKSETTINGSINTERFACEPRIVATE_H diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.cpp b/src/networksettings/connman/qnetworksettingsmanager_p.cpp new file mode 100644 index 0000000..875be9b --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsmanager_p.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsmanager_p.h" +#include "connman_manager_interface.cpp" +#include "moc_connman_manager_interface.cpp" +#include "qnetworksettingsinterface.h" +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsservicemodel.h" +#include "qnetworksettingsuseragent.h" + +QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent) + :QObject(parent) + ,q_ptr(parent) +{ + qDBusRegisterMetaType<ConnmanMapStruct>(); + qDBusRegisterMetaType<ConnmanMapStructList>(); + + QNetworkSettingsUserAgent* userAgent = new QNetworkSettingsUserAgent(this); + this->setUserAgent(userAgent); + + m_serviceModel = new QNetworkSettingsServiceModel(this); + m_serviceFilter = new QNetworkSettingsServiceFilter(this); + m_serviceFilter->setSourceModel(m_serviceModel); + m_manager = new NetConnmanManagerInterface(QStringLiteral("net.connman"), QStringLiteral("/"), + QDBusConnection::systemBus(), this); + + if (m_manager->isValid()) { + //List technologies + QDBusPendingReply<ConnmanMapStructList> reply = m_manager->GetTechnologies(); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(getTechnologiesFinished(QDBusPendingCallWatcher*))); + + reply = m_manager->GetServices(); + watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(getServicesFinished(QDBusPendingCallWatcher*))); + + connect(m_manager, &NetConnmanManagerInterface::ServicesChanged, this, &QNetworkSettingsManagerPrivate::onServicesChanged); + + m_manager->RegisterAgent(QDBusObjectPath(AgentPath)); + } + else { + delete m_manager; + m_manager = NULL; + } +} + +void QNetworkSettingsManagerPrivate::requestInput(const QString& service, const QString& type) +{ + Q_UNUSED(type); + foreach (QNetworkSettingsService* servicePtr, m_serviceModel->getModel()) { + if (servicePtr->id() == service) + emit servicePtr->showCrendentialInput(); + } + m_agent->showUserCredentialsInput(); +} + +void QNetworkSettingsManagerPrivate::getServicesFinished(QDBusPendingCallWatcher *watcher) +{ + Q_Q(QNetworkSettingsManager); + QDBusPendingReply<ConnmanMapStructList> reply = *watcher; + watcher->deleteLater(); + + if (reply.isError()) + return; + + foreach (const ConnmanMapStruct &object, reply.value()) { + const QString servicePath = object.objectPath.path(); + QNetworkSettingsService *service = new QNetworkSettingsService(servicePath, this); + m_serviceModel->append(service); + + //Update status property + QString n = qdbus_cast<QString>(object.propertyMap[PropertyName]); + QString t = qdbus_cast<QString>(object.propertyMap[PropertyType]); + QString s = qdbus_cast<QString>(object.propertyMap[PropertyState]); + + QNetworkSettingsType type; + t >> type; + QNetworkSettingsState state; + s >> state; + + foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) { + ConnmanSettingsInterface* technology = qobject_cast<ConnmanSettingsInterface*>(item); + if (technology->name() == n && technology->type() == type.type()) { + technology->setState(state.state()); + } + } + } + emit q->servicesChanged(); +} + +void QNetworkSettingsManagerPrivate::getTechnologiesFinished(QDBusPendingCallWatcher *watcher) +{ + Q_Q(QNetworkSettingsManager); + + QDBusPendingReply<ConnmanMapStructList> reply = *watcher; + watcher->deleteLater(); + if (reply.isError()) + return; + + foreach (const ConnmanMapStruct &object, reply.value()) { + ConnmanSettingsInterface *item = new ConnmanSettingsInterface(object.objectPath.path(), object.propertyMap, this); + + if (item->type() == QNetworkSettingsType::Wired) { + m_interfaceModel.insert(0, item); + } + else if (item->type() == QNetworkSettingsType::Wifi) { + m_interfaceModel.append(item); + } + emit q->interfacesChanged(); + } +} + +void QNetworkSettingsManagerPrivate::onServicesChanged(ConnmanMapStructList changed, const QList<QDBusObjectPath> &removed) +{ + foreach (QDBusObjectPath path, removed) { + m_serviceModel->removeService(path.path()); + } + + QStringList newServices; + foreach (ConnmanMapStruct map, changed) { + bool found = false; + foreach (QNetworkSettingsService* service, m_serviceModel->getModel()) { + if (service->id() == map.objectPath.path()) { + found =true; + break; + } + } + if (!found) + newServices.append(map.objectPath.path()); + } + foreach (QString newService, newServices) { + QNetworkSettingsService *service = new QNetworkSettingsService(newService, this); + m_serviceModel->append(service); + } +} + +void QNetworkSettingsManagerPrivate::setUserAgent(QNetworkSettingsUserAgent *agent) +{ + m_agent = agent; +} diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.h b/src/networksettings/connman/qnetworksettingsmanager_p.h new file mode 100644 index 0000000..cb42654 --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsmanager_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSMANAGERPRIVATE_H +#define QNETWORKSETTINGSMANAGERPRIVATE_H + +#include <QObject> +#include <QtDBus> +#include "connmancommon.h" +#include "qnetworksettingsmanager.h" +#include "qnetworksettingsinterfacemodel.h" + +class NetConnmanManagerInterface; +class QNetworkSettingsServiceModel; +class QNetworkSettingsServiceFilter; + +class QNetworkSettingsManagerPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsManager) +public: + explicit QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent); + QNetworkSettingsManager *q_ptr; + void setUserAgent(QNetworkSettingsUserAgent *agent); + QNetworkSettingsUserAgent *getUserAgent() {return m_agent;} +public slots: + void getServicesFinished(QDBusPendingCallWatcher *watcher); + void getTechnologiesFinished(QDBusPendingCallWatcher *watcher); + void requestInput(const QString& service, const QString& type); + void onServicesChanged(ConnmanMapStructList changed, const QList<QDBusObjectPath> &removed); + +protected: + QNetworkSettingsInterfaceModel m_interfaceModel; + QNetworkSettingsServiceModel *m_serviceModel; + QNetworkSettingsServiceFilter *m_serviceFilter; +private: + NetConnmanManagerInterface *m_manager; + QNetworkSettingsUserAgent *m_agent; +}; + +#endif // QNETWORKSETTINGSMANAGERPRIVATE_H diff --git a/src/networksettings/connman/qnetworksettingsservice_p.cpp b/src/networksettings/connman/qnetworksettingsservice_p.cpp new file mode 100644 index 0000000..8a7b2cf --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsservice_p.cpp @@ -0,0 +1,395 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsservice_p.h" +#include "connman_service_interface.h" +#include "connmancommon.h" + +const QString PropertyIPv4(QStringLiteral("IPv4")); +const QString PropertyQNetworkSettingsIPv4(QStringLiteral("IPv4.Configuration")); +const QString PropertyIPv6(QStringLiteral("IPv6")); +const QString PropertyQNetworkSettingsIPv6(QStringLiteral("IPv6.Configuration")); +const QString PropertyNameservers(QStringLiteral("Nameservers")); +const QString PropertyNameserversConfig(QStringLiteral("Nameservers.Configuration")); +const QString PropertyDomains(QStringLiteral("Domains")); +const QString PropertyDomainsConfig(QStringLiteral("Domains.Configuration")); +const QString PropertyProxy(QStringLiteral("Proxy")); +const QString PropertyQNetworkSettingsProxy(QStringLiteral("Proxy.Configuration")); +const QString PropertyAddress(QStringLiteral("Address")); +const QString PropertyNetMask(QStringLiteral("Netmask")); +const QString PropertyGateway(QStringLiteral("Gateway")); +const QString PropertyPrefixLength(QStringLiteral("PrefixLength")); +const QString PropertyMethod(QStringLiteral("Method")); +const QString PropertyPrivacy(QStringLiteral("Privacy")); +const QString PropertyUrl(QStringLiteral("Url")); +const QString PropertyServers(QStringLiteral("Servers")); +const QString PropertyExcludes(QStringLiteral("Excludes")); +const QString PropertyStrength(QStringLiteral("Strength")); +const QString PropertySecurity(QStringLiteral("Security")); + +const QString AttributeAuto(QStringLiteral("auto")); +const QString AttributeDhcp(QStringLiteral("dhcp")); +const QString AttributeManual(QStringLiteral("manual")); +const QString AttributeOff(QStringLiteral("off")); +const QString AttributeDisabled(QStringLiteral("disabled")); +const QString AttributeEnabled(QStringLiteral("enabled")); +const QString AttributePreferred(QStringLiteral("preferred")); +const QString AttributeDirect(QStringLiteral("direct")); +const QString AttributeNone(QStringLiteral("none")); +const QString AttributeWep(QStringLiteral("wep")); +const QString AttributePsk(QStringLiteral("psk")); +const QString AttributeIeee(QStringLiteral("ieee8021x")); +const QString AttributeWps(QStringLiteral("wps")); +const QString AttributeInvalidKey(QStringLiteral("invalid-key")); + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsIPv4 &obj) +{ + obj.setAddress(argument[PropertyAddress].toString()); + obj.setMask(argument[PropertyNetMask].toString()); + obj.setGateway(argument[PropertyGateway].toString()); + + QString method = argument[PropertyMethod].toString(); + + if (method == AttributeDhcp) { + obj.setMethod(QNetworkSettingsIPv4::Dhcp); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsIPv4::Manual); + } + else if (method == AttributeOff) { + obj.setMethod(QNetworkSettingsIPv4::Off); + } + else { + obj.setMethod(QNetworkSettingsIPv4::Off); + } + return argument; +} + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsIPv4 &obj) +{ + argument.insert(PropertyAddress, QVariant::fromValue(obj.address())); + + argument.insert(PropertyNetMask, QVariant::fromValue(obj.mask())); + + argument.insert(PropertyGateway, QVariant::fromValue(obj.gateway())); + + QString method; + switch (obj.method()) { + case QNetworkSettingsIPv4::Dhcp: + method = AttributeDhcp; + break; + case QNetworkSettingsIPv4::Manual: + method = AttributeManual; + break; + case QNetworkSettingsIPv4::Off: + method = AttributeOff; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + return argument; +} + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsIPv6 &obj) +{ + obj.setAddress(argument[PropertyAddress].toString()); + obj.setGateway(argument[PropertyGateway].toString()); + obj.setPrefixLength(argument[PropertyPrefixLength].toInt()); + QString method = argument[PropertyMethod].toString(); + if (method == AttributeAuto) { + obj.setMethod(QNetworkSettingsIPv6::Auto); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsIPv6::Manual); + } + else if (method == AttributeOff) { + obj.setMethod(QNetworkSettingsIPv6::Off); + } + QString privacy = argument[PropertyPrivacy].toString(); + + if (privacy == AttributeDisabled) { + obj.setPrivacy(QNetworkSettingsIPv6::Disabled); + } + else if (privacy == AttributeEnabled) { + obj.setPrivacy(QNetworkSettingsIPv6::Enabled); + } + else if (privacy == AttributePreferred) { + obj.setPrivacy(QNetworkSettingsIPv6::Preferred); + } + return argument; +} + + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsIPv6 &obj) +{ + argument.insert(PropertyAddress, QVariant::fromValue(obj.address())); + argument.insert(PropertyGateway, QVariant::fromValue(obj.address())); + argument.insert(PropertyPrefixLength, QVariant::fromValue(obj.prefixLength())); + + QString method; + switch (obj.method()) { + case QNetworkSettingsIPv6::Auto: + method = AttributeAuto; + break; + case QNetworkSettingsIPv6::Manual: + method = AttributeManual; + break; + case QNetworkSettingsIPv6::Off: + method = AttributeOff; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + + QString privacy; + switch (obj.privacy()) { + case QNetworkSettingsIPv6::Disabled: + method = AttributeDisabled; + break; + case QNetworkSettingsIPv6::Enabled: + method = AttributeEnabled; + break; + case QNetworkSettingsIPv6::Preferred: + method = AttributePreferred; + break; + default: + break; + } + argument.insert(PropertyPrivacy, QVariant::fromValue(privacy)); + + return argument; +} + + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsProxy &obj) +{ + QString method = argument[PropertyMethod].toString(); + if (method == AttributeDirect) { + obj.setMethod(QNetworkSettingsProxy::Direct); + } + else if (method == AttributeAuto) { + obj.setMethod(QNetworkSettingsProxy::Auto); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsProxy::Manual); + } + + QString urlStr = argument[PropertyUrl].toString(); + obj.setUrl(QUrl(urlStr)); + + obj.setServers(argument[PropertyServers].toStringList()); + obj.setExcludes(argument[PropertyExcludes].toStringList()); + + return argument; +} + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsProxy &obj) +{ + QString method; + switch (obj.method()) { + case QNetworkSettingsProxy::Direct: + method = AttributeDirect; + break; + case QNetworkSettingsProxy::Auto: + method = AttributeAuto; + break; + case QNetworkSettingsProxy::Manual: + method = AttributeManual; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + argument.insert(PropertyUrl, QVariant::fromValue(obj.url().toString())); + argument.insert(PropertyServers, QVariant::fromValue(obj.servers())); + argument.insert(PropertyServers, QVariant::fromValue(obj.excludes())); + + return argument; +} + +QNetworkSettingsServicePrivate::QNetworkSettingsServicePrivate(const QString& id, QNetworkSettingsService *parent) : + QObject(parent) + ,q_ptr(parent) + ,m_id(id) +{ + qDBusRegisterMetaType<ConnmanMapStruct>(); + qDBusRegisterMetaType<ConnmanMapStructList>(); + + m_service = new NetConnmanServiceInterface(QStringLiteral("net.connman"), m_id, + QDBusConnection::systemBus(), this); + + connect(m_service, SIGNAL(PropertyChanged(QString,QDBusVariant)), + this, SLOT(updateProperty(QString,QDBusVariant))); + + QDBusPendingReply<QVariantMap> reply = m_service->GetProperties(); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(propertiesUpdated(QDBusPendingCallWatcher*))); +} + +void QNetworkSettingsServicePrivate::setupIpv6Config() +{ + QVariantMap param; + param << m_ipv6config; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsIPv6, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupNameserversConfig() +{ + QVariant param = QVariant::fromValue(m_nameserverConfig.stringList()); + if (m_service) + m_service->SetProperty(PropertyNameserversConfig, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupDomainsConfig() +{ + QVariant param = QVariant::fromValue(m_domainsConfig.stringList()); + if (m_service) + m_service->SetProperty(PropertyDomainsConfig, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupQNetworkSettingsProxy() +{ + QVariantMap param; + param << m_proxyConfig; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsProxy, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupIpv4Config() +{ + QVariantMap param; + param << m_ipv4config; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsIPv4, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::connectService() +{ + if (m_service) { + m_service->Connect(); + } +} + +void QNetworkSettingsServicePrivate::disconnectService() +{ + if (m_service) + m_service->Disconnect(); + +} + +void QNetworkSettingsServicePrivate::propertiesUpdated(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply<QVariantMap> reply = *call; + call->deleteLater(); + + if (!reply.isError()) + setupConfiguration(reply.value()); +} + +void QNetworkSettingsServicePrivate::updateProperty(const QString &name, const QDBusVariant &value) +{ + updateProperty(name, value.variant()); +} + +void QNetworkSettingsServicePrivate::updateProperty(const QString& key, const QVariant& val) +{ + Q_Q(QNetworkSettingsService); + + if (key == PropertyIPv4) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_ipv4config; + emit q->ipv4Changed(); + } + else if (key == PropertyIPv6) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_ipv6config; + emit q->ipv6Changed(); + } + else if (key == PropertyNameservers) { + QStringList value = qdbus_cast<QStringList>(val); + m_nameserverConfig.setStringList(value); + emit q->nameserversChanged(); + } + else if (key == PropertyDomains) { + QStringList value = qdbus_cast<QStringList>(val); + m_domainsConfig.setStringList(value); + emit q->domainsChanged(); + } + else if (key == PropertyProxy) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_proxyConfig; + emit q->proxyChanged(); + } + else if (key == PropertyState) { + QString value = qdbus_cast<QString>(val); + value >> m_state; + emit q->stateChanged(); + } + else if (key == PropertyName) { + m_name = qdbus_cast<QString>(val); + emit q->nameChanged(); + } + else if (key == PropertyType) { + QString value = qdbus_cast<QString>(val); + value >> m_type; + } + else if (key == PropertyStrength) { + m_wifiConfig.setSignalStrength(val.toInt()); + } + else if (key == PropertySecurity) { + QStringList value = qdbus_cast<QStringList>(val); + foreach (const QString str, value) { + if (str == AttributeNone || str == AttributeWps) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::None); + } + else if (str == AttributeWep) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WEP); + } + else if (str == AttributePsk) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA); + } + else if (str == AttributeIeee) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA2); + } + } + } +} + +void QNetworkSettingsServicePrivate::setupConfiguration(const QVariantMap &properties) +{ + QVariantMap::const_iterator it = properties.constBegin(), end = properties.constEnd(); + for ( ; it != end; ++it) { + updateProperty(it.key(), it.value()); + } +} + diff --git a/src/networksettings/connman/qnetworksettingsservice_p.h b/src/networksettings/connman/qnetworksettingsservice_p.h new file mode 100644 index 0000000..942a871 --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsservice_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICEPRIVATE_H +#define QNETWORKSETTINGSSERVICEPRIVATE_H + +#include <QtDBus> +#include "qnetworksettingsservice.h" +#include "qnetworksettings.h" + +class NetConnmanServiceInterface; + +class QNetworkSettingsServicePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsService) +public: + QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent=0); + + QNetworkSettingsService *q_ptr; +private slots: + void propertiesUpdated(QDBusPendingCallWatcher *call); + void updateProperty(const QString &name, const QDBusVariant &value); + +private: + void setupConfiguration(const QVariantMap &properties); + void updateProperty(const QString& key, const QVariant& value); + +protected: + void setAutoConnect(const bool autoconnect); + void setupIpv4Config(); + void setupIpv6Config(); + void setupNameserversConfig(); + void setupDomainsConfig(); + void setupQNetworkSettingsProxy(); + void connectService(); + void disconnectService(); + + QString m_id; + QString m_name; + QNetworkSettingsState m_state; + QNetworkSettingsIPv4 m_ipv4config; + QNetworkSettingsIPv6 m_ipv6config; + QNetworkSettingsAddressModel m_domainsConfig; + QNetworkSettingsAddressModel m_nameserverConfig; + QNetworkSettingsProxy m_proxyConfig; + QNetworkSettingsWireless m_wifiConfig; + QNetworkSettingsType m_type; + NetConnmanServiceInterface *m_service; +}; + +#endif // QNETWORKSETTINGSSERVICEPRIVATE_H diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.cpp b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp new file mode 100644 index 0000000..4791c6e --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsuseragent_p.h" +#include "connmancommon.h" + +const QString PropertyPassphrase(QStringLiteral("Passphrase")); + +QNetworkSettingsUserAgentPrivate::QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent) + :QDBusAbstractAdaptor(parent) + ,q_ptr(parent) + ,m_pendingReply(false) +{ + + setAutoRelaySignals(true); + QMetaObject::invokeMethod(this, "registerAgent", Qt::QueuedConnection); +} + +void QNetworkSettingsUserAgentPrivate::cancel() +{ + // handle method call net.connman.Agent.Cancel + m_pendingReply = false; + QMetaObject::invokeMethod(parent(), "Cancel"); +} + +void QNetworkSettingsUserAgentPrivate::release() +{ + // handle method call net.connman.Agent.Release + QMetaObject::invokeMethod(parent(), "Release"); +} + +void QNetworkSettingsUserAgentPrivate::ReportError(const QDBusObjectPath &path, const QString ¶m) +{ + Q_Q(QNetworkSettingsUserAgent); + Q_UNUSED(path); + Q_UNUSED(param); + emit q->error(); +} + +void QNetworkSettingsUserAgentPrivate::registerAgent() +{ + Q_Q(QNetworkSettingsUserAgent); + QDBusConnection::systemBus().registerObject(QStringLiteral(AgentPath), q); +} + +QVariantMap QNetworkSettingsUserAgentPrivate::RequestInput(const QDBusObjectPath &path, const QVariantMap ¶ms, const QDBusMessage &msg) +{ + Q_Q(QNetworkSettingsUserAgent); + Q_UNUSED(path); + Q_UNUSED(params); + msg.setDelayedReply(true); + m_reply = msg.createReply(); + m_pendingReply = true; + emit q->showUserCredentialsInput(); + return QVariantMap(); +} + +void QNetworkSettingsUserAgentPrivate::setUserCredentials(const QString& username, + const QString& password) +{ + m_username = username; + m_passphrase = password; + QVariantMap response; + response[PropertyName] = m_username; + response[PropertyPassphrase] = m_passphrase; + m_reply << response; + m_pendingReply = false; + QDBusConnection::systemBus().send(m_reply); +} diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.h b/src/networksettings/connman/qnetworksettingsuseragent_p.h new file mode 100644 index 0000000..e05525b --- /dev/null +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSUSERAGENTPRIVATE_H +#define QNETWORKSETTINGSUSERAGENTPRIVATE_H + +#include <QtCore/QObject> +#include <QtDBus/QtDBus> +#include "qnetworksettingsuseragent.h" + +QT_BEGIN_NAMESPACE +class QByteArray; +template<class T> class QList; +template<class Key, class Value> class QMap; +class QString; +class QStringList; +class QVariant; +QT_END_NAMESPACE + +const QString AgentPath(QStringLiteral("/ConnmanAgent")); + +class QNetworkSettingsUserAgentPrivate : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "net.connman.Agent") + Q_DECLARE_PUBLIC(QNetworkSettingsUserAgent) +public: + QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent=0); + void setUserCredentials(const QString& aUsername, const QString& aPassword); + void cancel(); + void release(); +public Q_SLOTS: // Dbus methods + void ReportError(const QDBusObjectPath &path, const QString ¶m); + QVariantMap RequestInput(const QDBusObjectPath &path, const QVariantMap ¶ms, + const QDBusMessage &message); + void registerAgent(); +private: + QNetworkSettingsUserAgent *q_ptr; + QDBusMessage m_reply; + bool m_pendingReply; + QString m_passphrase; + QString m_username; +}; + +#endif // QNETWORKSETTINGSUSERAGENTPRIVATE_H diff --git a/src/networksettings/networksettings.pro b/src/networksettings/networksettings.pro new file mode 100644 index 0000000..9ae1bb3 --- /dev/null +++ b/src/networksettings/networksettings.pro @@ -0,0 +1,37 @@ +load(qt_build_config) + +TARGET = QtNetworkSettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core network + +MODULE = networksettings +load(qt_module) + +wpasupplicant { + include(wpasupplicant.pri) +} +else { + include(connman.pri) +} + +# Input +SOURCES += \ + qnetworksettingsinterfacemodel.cpp \ + qnetworksettingsmanager.cpp \ + qnetworksettingsaddressmodel.cpp \ + qnetworksettingsservicemodel.cpp \ + qnetworksettingsservice.cpp \ + qnetworksettingsuseragent.cpp \ + qnetworksettingsinterface.cpp \ + +HEADERS += \ + qnetworksettingsinterfacemodel.h \ + qnetworksettings.h \ + qnetworksettingsmanager.h \ + qnetworksettingsaddressmodel.h \ + qnetworksettingsservicemodel.h \ + qnetworksettingsservice.h \ + qnetworksettingsuseragent.h \ + qnetworksettingsinterface.h \ diff --git a/src/networksettings/qnetworksettings.h b/src/networksettings/qnetworksettings.h new file mode 100644 index 0000000..e5dbbc5 --- /dev/null +++ b/src/networksettings/qnetworksettings.h @@ -0,0 +1,404 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGS_H +#define QNETWORKSETTINGS_H + +#include <QObject> +#include <QUrl> +#include <QVariantMap> +#include "qnetworksettingsaddressmodel.h" + +class Q_DECL_EXPORT QNetworkSettingsState : public QObject +{ + Q_OBJECT + Q_ENUMS(States) + Q_PROPERTY(States state READ state WRITE setState NOTIFY stateChanged) + +public: + enum States {Idle, Failure, Association, Configuration, Ready, Disconnect, Online, Undefined}; + + explicit QNetworkSettingsState(States state, QObject *parent = 0) + : QObject(parent) + { + m_state = state; + } + + explicit QNetworkSettingsState(QObject *parent = 0) + : QObject(parent) + { + m_state = Undefined; + } + + States state() const { + return m_state; + } + + void setState(const States state) { + m_state = state; + emit stateChanged(); + } + +signals: + void stateChanged(); + +private: + States m_state; +}; + +class Q_DECL_EXPORT QNetworkSettingsType : public QObject +{ + Q_OBJECT + Q_ENUMS(Types) + Q_PROPERTY(Types type READ type WRITE setType NOTIFY typeChanged) + +public: + enum Types { + Wired, + Wifi, + Bluetooth, + Unknown + }; + + explicit QNetworkSettingsType(Types type, QObject *parent = 0) + : QObject(parent) + { + m_type = type; + } + + explicit QNetworkSettingsType(QObject *parent = 0) + : QObject(parent) + { + m_type = Unknown; + } + + + Types type() const { + return m_type; + } + + void setType(const Types type) { + m_type = type; + emit typeChanged(); + } + +signals: + void typeChanged(); + +private: + Types m_type; +}; + +class Q_DECL_EXPORT QNetworkSettingsIPv4 : public QObject +{ + Q_OBJECT + Q_ENUMS(MethodType) + Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged) + Q_PROPERTY(QString gateway READ gateway WRITE setGateway NOTIFY gatewayChanged) + Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) + Q_PROPERTY(QString mask READ mask WRITE setMask NOTIFY maskChanged) + +public: + explicit QNetworkSettingsIPv4(QObject *parent = 0) + : QObject(parent) + { + + } + + enum MethodType {Dhcp, Manual, Off}; + + QString address() const { + return m_address; + } + void setAddress(const QString& adderess) { + m_address = adderess; + emit addressChanged(); + } + + QString gateway() const { + return m_gateway; + } + + void setGateway(const QString& gateway) { + m_gateway = gateway; + emit gatewayChanged(); + } + + MethodType method() const { + return m_method; + } + + void setMethod(const MethodType method) { + m_method = method; + emit methodChanged(); + } + + QString mask() const { + return m_mask; + } + + void setMask(const QString& mask) { + m_mask = mask; + emit maskChanged(); + } + +signals: + void addressChanged(); + void gatewayChanged(); + void methodChanged(); + void maskChanged(); + +private: + QString m_address; + QString m_gateway; + MethodType m_method; + QString m_mask; +}; + + +class Q_DECL_EXPORT QNetworkSettingsIPv6 : public QObject +{ + Q_OBJECT + Q_ENUMS(MethodType PrivacyType) + Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged) + Q_PROPERTY(QString gateway READ gateway WRITE setGateway NOTIFY gatewayChanged) + Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) + Q_PROPERTY(PrivacyType privacy READ privacy WRITE setPrivacy NOTIFY privacyChanged) + Q_PROPERTY(int prefixLength READ prefixLength WRITE setPrefixLength NOTIFY prefixLengthChanged) + +public: + explicit QNetworkSettingsIPv6(QObject *parent = 0) + : QObject(parent) + { + + } + + enum MethodType {Auto, Manual, Off}; + enum PrivacyType {Disabled, Enabled, Preferred}; + + QString address() const { + return m_address; + } + void setAddress(const QString& adderess) { + m_address = adderess; + emit addressChanged(); + } + + QString gateway() const { + return m_gateway; + } + + void setGateway(const QString& gateway) { + m_gateway = gateway; + emit gatewayChanged(); + } + + MethodType method() const { + return m_method; + } + + void setMethod(const MethodType method) { + m_method = method; + emit methodChanged(); + } + + PrivacyType privacy() const { + return m_privacy; + } + + void setPrivacy(const PrivacyType privacy) { + m_privacy = privacy; + emit privacyChanged(); + } + + int prefixLength() const { + return m_prefixLength; + } + + void setPrefixLength(const int& prefixLength) { + m_prefixLength = prefixLength; + emit prefixLengthChanged(); + } + +signals: + void addressChanged(); + void gatewayChanged(); + void methodChanged(); + void privacyChanged(); + void prefixLengthChanged(); + +private: + QString m_address; + QString m_gateway; + MethodType m_method; + PrivacyType m_privacy; + int m_prefixLength; +}; + +class Q_DECL_EXPORT QNetworkSettingsProxy : public QObject +{ + Q_OBJECT + Q_ENUMS(MethodType) +public: + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(QAbstractItemModel* servers READ servers NOTIFY serversChanged) + Q_PROPERTY(QAbstractItemModel* excludes READ excludes NOTIFY excludesChanged) + Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) + + explicit QNetworkSettingsProxy(QObject *parent=NULL) + : QObject(parent) + { + + } + + enum MethodType {Direct, Auto, Manual}; + + QUrl url() const { + return m_url; + } + + void setUrl(const QUrl& url) { + m_url = url; + emit urlChanged(); + } + + QAbstractItemModel* servers(void) { + return &m_servers; + } + + void setServers(const QStringList& servers) { + m_servers.setStringList(servers); + emit serversChanged(); + } + + QStringList servers() const { + return m_servers.stringList(); + } + + QAbstractItemModel* excludes(void) { + return &m_excludes; + } + + QStringList excludes() const { + return m_excludes.stringList(); + } + + void setExcludes(const QStringList& excludes) { + m_excludes.setStringList(excludes); + emit excludesChanged(); + } + + MethodType method(void) const { + return m_method; + } + + void setMethod(const MethodType& method) { + m_method = method; + emit methodChanged(); + } + +signals: + void urlChanged(); + void serversChanged(); + void excludesChanged(); + void methodChanged(); +private: + QUrl m_url; + QNetworkSettingsAddressModel m_servers; + QNetworkSettingsAddressModel m_excludes; + MethodType m_method; +}; + +class Q_DECL_EXPORT QNetworkSettingsWireless : public QObject +{ + Q_OBJECT + Q_PROPERTY(int signalStrength READ signalStrength WRITE setSignalStrength NOTIFY signalStrengthChanged) + Q_PROPERTY(bool hidden READ hidden NOTIFY hiddenChanged) + Q_PROPERTY(bool isOutOfRange READ outOfRange WRITE setOutOfRange NOTIFY outOfRangeChanged) +public: + explicit QNetworkSettingsWireless(QObject* parent = 0) : + QObject(parent) { + } + + enum SecurityFlags {None=1, WEP=2, WPA=4, WPA2=8}; + + Q_INVOKABLE bool supportsSecurity(SecurityFlags security) { + if (m_securityFlags & security) { + return true; + } + return false; + } + + bool hidden() const { + return m_hidden; + } + + void setHidden(const bool hidden) { + m_hidden = hidden; + emit hiddenChanged(); + } + + int signalStrength() const { + return m_signalStrength; + } + + void setSignalStrength(const int signalStrength) { + m_signalStrength = signalStrength; + emit signalStrengthChanged(); + } + + void setSecurity(const SecurityFlags security) { + if (security == None) { + m_securityFlags = None; + } + else { + m_securityFlags |= security; + } + } + + void setOutOfRange(const bool aOutOfRange) { + m_isOutOfRange = aOutOfRange; + emit outOfRangeChanged(); + } + + bool outOfRange() const { + return m_isOutOfRange; + } + +signals: + void hiddenChanged(); + void signalStrengthChanged(); + void passwordChanged(); + void outOfRangeChanged(); +private: + quint16 m_securityFlags; + bool m_hidden; + int m_signalStrength; + bool m_isOutOfRange; +}; +#endif //QNETWORKSETTINGS_H diff --git a/src/networksettings/qnetworksettingsaddressmodel.cpp b/src/networksettings/qnetworksettingsaddressmodel.cpp new file mode 100644 index 0000000..5b72d46 --- /dev/null +++ b/src/networksettings/qnetworksettingsaddressmodel.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsaddressmodel.h" + +QNetworkSettingsAddressModel::QNetworkSettingsAddressModel(QObject *parent) + :QStringListModel(parent) +{ +} + +QNetworkSettingsAddressModel::QNetworkSettingsAddressModel(const QStringList &strings, QObject *parent) + :QStringListModel(parent) +{ + setStringList(strings); +} + +void QNetworkSettingsAddressModel::setStringList(const QStringList &addresses) +{ + m_addresses = addresses; + QStringListModel::setStringList(m_addresses); + emit countChanged(); +} + +void QNetworkSettingsAddressModel::append(const QString& address) +{ + int row = rowCount(); + + bool succeed = insertRows(row, 1); + if (succeed) + succeed = setData(index(row), QVariant::fromValue(address)); + + Q_ASSERT(succeed == true); + + emit countChanged(); +} + +void QNetworkSettingsAddressModel::remove(int index) +{ + removeRows(index, 1); + emit countChanged(); +} + +int QNetworkSettingsAddressModel::count() const +{ + return rowCount(); +} + +void QNetworkSettingsAddressModel::resetChanges() +{ + QStringListModel::setStringList(m_addresses); +} diff --git a/src/networksettings/qnetworksettingsaddressmodel.h b/src/networksettings/qnetworksettingsaddressmodel.h new file mode 100644 index 0000000..5164fc4 --- /dev/null +++ b/src/networksettings/qnetworksettingsaddressmodel.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSADDRESSMODEL_H +#define QNETWORKSETTINGSADDRESSMODEL_H + +#include <QStringListModel> + +class Q_DECL_EXPORT QNetworkSettingsAddressModel : public QStringListModel +{ + Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged) +public: + explicit QNetworkSettingsAddressModel(QObject *parent = 0); + explicit QNetworkSettingsAddressModel(const QStringList &strings, QObject *parent = 0); + Q_INVOKABLE void append(const QString& address); + Q_INVOKABLE void remove(int index); + Q_INVOKABLE void resetChanges(); + void setStringList(const QStringList &addresses); + int count() const; + +signals: + void countChanged(); +private: + QStringList m_addresses; +}; + +#endif // QNETWORKSETTINGSADDRESSMODEL_H diff --git a/src/networksettings/qnetworksettingsinterface.cpp b/src/networksettings/qnetworksettingsinterface.cpp new file mode 100644 index 0000000..91a8fa5 --- /dev/null +++ b/src/networksettings/qnetworksettingsinterface.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterface.h" +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettings.h" + +QNetworkSettingsInterface::QNetworkSettingsInterface(QObject *parent) : + QObject(parent) + ,d_ptr(new QNetworkSettingsInterfacePrivate(this)) +{ + +} + +QString QNetworkSettingsInterface::name() const +{ + Q_D(const QNetworkSettingsInterface); + return d->m_name; +} + +QNetworkSettingsState::States QNetworkSettingsInterface::state() +{ + Q_D(QNetworkSettingsInterface); + return d->m_state.state(); +} + +QNetworkSettingsType::Types QNetworkSettingsInterface::type() +{ + Q_D(QNetworkSettingsInterface); + return d->m_type.type(); +} + +bool QNetworkSettingsInterface::powered() const +{ + Q_D(const QNetworkSettingsInterface); + return d->m_powered; +} + +void QNetworkSettingsInterface::setPowered(const bool powered) +{ + Q_D(QNetworkSettingsInterface); + d->setPowered(powered); +} + +void QNetworkSettingsInterface::scanServices() +{ + Q_D(QNetworkSettingsInterface); + d->scan(); +} diff --git a/src/networksettings/qnetworksettingsinterface.h b/src/networksettings/qnetworksettingsinterface.h new file mode 100644 index 0000000..385d1ed --- /dev/null +++ b/src/networksettings/qnetworksettingsinterface.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSINTERFACE_H +#define QNETWORKSETTINGSINTERFACE_H + +#include <QObject> +#include "qnetworksettings.h" + +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsInterfacePrivate) + +class Q_DECL_EXPORT QNetworkSettingsInterface : public QObject { + Q_OBJECT + Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QNetworkSettingsState::States state READ state NOTIFY stateChanged) + Q_PROPERTY(QNetworkSettingsType::Types type READ type NOTIFY typeChanged) + Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) + +public: + explicit QNetworkSettingsInterface(QObject* parent=0); + QString name() const; + QNetworkSettingsState::States state(); + QNetworkSettingsType::Types type(); + bool powered() const; + void setPowered(const bool powered); + Q_INVOKABLE void scanServices(); + +signals: + void nameChanged(); + void stateChanged(); + void typeChanged(); + void poweredChanged(); + +protected: + friend class NetworksInterfaceModel; + QNetworkSettingsInterfacePrivate *d_ptr; + + Q_DISABLE_COPY(QNetworkSettingsInterface) + Q_DECLARE_PRIVATE(QNetworkSettingsInterface) +}; + +#endif // QNETWORKSETTINGSINTERFACE_H diff --git a/src/networksettings/qnetworksettingsinterfacemodel.cpp b/src/networksettings/qnetworksettingsinterfacemodel.cpp new file mode 100644 index 0000000..700db10 --- /dev/null +++ b/src/networksettings/qnetworksettingsinterfacemodel.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterfacemodel.h" +#include "qnetworksettingsinterface.h" + +QNetworkSettingsInterfaceModel::QNetworkSettingsInterfaceModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Type, "type"); + m_roleNames.insert(Status, "status"); + m_roleNames.insert(Name, "name"); +} + +QHash<int, QByteArray> QNetworkSettingsInterfaceModel::roleNames() const +{ + return m_roleNames; +} + + +int QNetworkSettingsInterfaceModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant QNetworkSettingsInterfaceModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + QNetworkSettingsInterface *item = m_items[index.row()]; + if (role == Qt::UserRole) { + return QVariant::fromValue(static_cast<QObject*>(item)); + } + + switch (role) { + case Type: + return item->type(); + break; + case Name: + return item->name(); + break; + case Status: + return item->state(); + break; + default: + return QStringLiteral(""); + } + +} + +void QNetworkSettingsInterfaceModel::append(QNetworkSettingsInterface* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_items.append(item); + endInsertRows(); +} + +void QNetworkSettingsInterfaceModel::insert(int row, QNetworkSettingsInterface* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), row, row); + m_items.insert(row, item); + endInsertRows(); +} + +void QNetworkSettingsInterfaceModel::remove(int row) +{ + beginRemoveRows(QModelIndex(), row, row); + m_items.removeFirst(); + endRemoveRows(); +} + +QList<QNetworkSettingsInterface*> QNetworkSettingsInterfaceModel::getModel() +{ + return m_items; +} diff --git a/src/networksettings/qnetworksettingsinterfacemodel.h b/src/networksettings/qnetworksettingsinterfacemodel.h new file mode 100644 index 0000000..7282657 --- /dev/null +++ b/src/networksettings/qnetworksettingsinterfacemodel.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSINTERFACEMODEL_H +#define QNETWORKSETTINGSINTERFACEMODEL_H + +#include <QAbstractListModel> +#include "qnetworksettings.h" + +class QNetworkSettingsInterface; + +class Q_DECL_EXPORT QNetworkSettingsInterfaceModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit QNetworkSettingsInterfaceModel(QObject *parent=0); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + + void append(QNetworkSettingsInterface* networkInterface); + void insert(int row, QNetworkSettingsInterface* networkInterface); + void remove(int row); + QList<QNetworkSettingsInterface*> getModel(); + + enum Roles { + Type = Qt::UserRole + 1, + Status, + Name + }; + +private: + QList<QNetworkSettingsInterface*> m_items; + QHash<int, QByteArray> m_roleNames; +}; + +#endif // QNETWORKSETTINGSINTERFACEMODEL_H diff --git a/src/networksettings/qnetworksettingsmanager.cpp b/src/networksettings/qnetworksettingsmanager.cpp new file mode 100644 index 0000000..787a382 --- /dev/null +++ b/src/networksettings/qnetworksettingsmanager.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsmanager.h" +#include "qnetworksettingsservice.h" +#include "qnetworksettingsservicemodel.h" +#include "qnetworksettingsinterfacemodel.h" +#include "qnetworksettingsmanager_p.h" +#include <QStringListModel> + +QNetworkSettingsManager::QNetworkSettingsManager(QObject *parent) : + QObject(parent) + ,d_ptr(new QNetworkSettingsManagerPrivate(this)) +{ +} + +QAbstractItemModel* QNetworkSettingsManager::services() +{ + Q_D(QNetworkSettingsManager); + return d->m_serviceFilter; +} + +QAbstractItemModel* QNetworkSettingsManager::interfaces() +{ + Q_D(QNetworkSettingsManager); + return &d->m_interfaceModel; +} + +QNetworkSettingsService* QNetworkSettingsManager::getService(const QString& name, const int type) +{ + Q_D(QNetworkSettingsManager); + + foreach (QNetworkSettingsService* service, d->m_serviceModel->getModel()) { + if (service->name() == name && service->type() == type) { + return service; + } + } + return NULL; +} + +void QNetworkSettingsManager::setUserAgent(QNetworkSettingsUserAgent *agent) +{ + Q_D(QNetworkSettingsManager); + d->setUserAgent(agent); +} + +QNetworkSettingsUserAgent* QNetworkSettingsManager::getUserAgent() +{ + Q_D(QNetworkSettingsManager); + return d->getUserAgent(); +} diff --git a/src/networksettings/qnetworksettingsmanager.h b/src/networksettings/qnetworksettingsmanager.h new file mode 100644 index 0000000..5d2ad13 --- /dev/null +++ b/src/networksettings/qnetworksettingsmanager.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSMANAGER_H +#define QNETWORKSETTINGSMANAGER_H + +#include "qnetworksettings.h" +#include <QObject> +#include <QStringListModel> + +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsManagerPrivate) +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsService) +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsUserAgent) + +class Q_DECL_EXPORT QNetworkSettingsManager : public QObject +{ + Q_OBJECT + Q_ENUMS(StateTypes NetworkTypeTypes) + Q_PROPERTY(QAbstractItemModel* services READ services NOTIFY servicesChanged) + Q_PROPERTY(QAbstractItemModel* interfaces READ interfaces NOTIFY interfacesChanged) + Q_PROPERTY(QNetworkSettingsUserAgent* userAgent READ getUserAgent CONSTANT) + +public: + explicit QNetworkSettingsManager(QObject* parent = 0); + QAbstractItemModel* services(); + QAbstractItemModel* interfaces(); + void setUserAgent(QNetworkSettingsUserAgent *agent); + QNetworkSettingsUserAgent* getUserAgent(); + + Q_INVOKABLE QNetworkSettingsService* getService(const QString& name, const int type); + +Q_SIGNALS: + void servicesChanged(); + void interfacesChanged(); + +protected: + QNetworkSettingsManagerPrivate *d_ptr; + +private: + Q_DISABLE_COPY(QNetworkSettingsManager) + Q_DECLARE_PRIVATE(QNetworkSettingsManager) +}; + +#endif // QNETWORKSETTINGSMANAGER_H diff --git a/src/networksettings/qnetworksettingsservice.cpp b/src/networksettings/qnetworksettingsservice.cpp new file mode 100644 index 0000000..4634496 --- /dev/null +++ b/src/networksettings/qnetworksettingsservice.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsservice.h" +#include "qnetworksettingsservice_p.h" + +QNetworkSettingsService::QNetworkSettingsService(const QString& aServiceId, QObject* parent) : + QObject(parent) + ,d_ptr(new QNetworkSettingsServicePrivate(aServiceId, this)) +{ + +} + +QString QNetworkSettingsService::id() const +{ + Q_D(const QNetworkSettingsService); + return d->m_id; +} + +QString QNetworkSettingsService::name() const +{ + Q_D(const QNetworkSettingsService); + return d->m_name; +} + +void QNetworkSettingsService::setAutoConnect(const bool autoconnect) +{ + Q_UNUSED(autoconnect); +} + +QNetworkSettingsState::States QNetworkSettingsService::state() +{ + Q_D(QNetworkSettingsService); + return d->m_state.state(); +} + +QNetworkSettingsType::Types QNetworkSettingsService::type() +{ + Q_D(QNetworkSettingsService); + return d->m_type.type(); +} + +QNetworkSettingsIPv4* QNetworkSettingsService::ipv4() +{ + Q_D(QNetworkSettingsService); + return &d->m_ipv4config; +} + +QNetworkSettingsIPv6* QNetworkSettingsService::ipv6() +{ + Q_D(QNetworkSettingsService); + return &d->m_ipv6config; +} + +QNetworkSettingsProxy* QNetworkSettingsService::proxy() +{ + Q_D(QNetworkSettingsService); + return &d->m_proxyConfig; +} + +QNetworkSettingsWireless* QNetworkSettingsService::wirelessConfig() +{ + Q_D(QNetworkSettingsService); + return &d->m_wifiConfig; +} + +QAbstractItemModel* QNetworkSettingsService::domains() +{ + Q_D(QNetworkSettingsService); + return &d->m_domainsConfig; +} + +QAbstractItemModel* QNetworkSettingsService::nameservers() +{ + Q_D(QNetworkSettingsService); + return &d->m_nameserverConfig; +} + +void QNetworkSettingsService::setupIpv4Config() +{ + Q_D(QNetworkSettingsService); + d->setupIpv4Config(); +} + +void QNetworkSettingsService::setupIpv6Config() +{ + Q_D(QNetworkSettingsService); + d->setupIpv6Config(); +} + +void QNetworkSettingsService::setupNameserversConfig() +{ + Q_D(QNetworkSettingsService); + d->setupNameserversConfig(); +} + +void QNetworkSettingsService::setupDomainsConfig() +{ + Q_D(QNetworkSettingsService); + d->setupDomainsConfig(); +} + +void QNetworkSettingsService::setupNetworkSettingsProxy() +{ + Q_D(QNetworkSettingsService); + d->setupQNetworkSettingsProxy(); +} + +void QNetworkSettingsService::connectService() +{ + Q_D(QNetworkSettingsService); + d->connectService(); +} + +void QNetworkSettingsService::disconnectService() +{ + Q_D(QNetworkSettingsService); + d->disconnectService(); +} diff --git a/src/networksettings/qnetworksettingsservice.h b/src/networksettings/qnetworksettingsservice.h new file mode 100644 index 0000000..44c433a --- /dev/null +++ b/src/networksettings/qnetworksettingsservice.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICE_H +#define QNETWORKSETTINGSSERVICE_H + +#include <QObject> +#include "qnetworksettings.h" + +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServicePrivate) + +class Q_DECL_EXPORT QNetworkSettingsService : public QObject +{ + Q_OBJECT + Q_ENUMS(StateTypes) + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QNetworkSettingsState::States state READ state NOTIFY stateChanged) + Q_PROPERTY(QNetworkSettingsType::Types type READ type NOTIFY typeChanged) + Q_PROPERTY(QNetworkSettingsIPv4* ipv4 READ ipv4 NOTIFY ipv4Changed) + Q_PROPERTY(QNetworkSettingsIPv6* ipv6 READ ipv6 NOTIFY ipv6Changed) + Q_PROPERTY(QNetworkSettingsProxy* proxy READ proxy NOTIFY proxyChanged) + Q_PROPERTY(QNetworkSettingsWireless* wirelessConfig READ wirelessConfig NOTIFY wirelessChanged) + Q_PROPERTY(QAbstractItemModel* domains READ domains NOTIFY domainsChanged) + Q_PROPERTY(QAbstractItemModel* nameservers READ nameservers NOTIFY nameserversChanged) +public: + explicit QNetworkSettingsService(const QString& aServiceId, QObject* parent = 0); + + QString id() const; + QString name() const; + QNetworkSettingsState::States state(); + QNetworkSettingsType::Types type(); + QNetworkSettingsIPv4* ipv4(); + QNetworkSettingsIPv6* ipv6(); + QNetworkSettingsProxy* proxy(); + QAbstractItemModel* domains(); + QAbstractItemModel* nameservers(); + QNetworkSettingsWireless* wirelessConfig(); + + Q_INVOKABLE void setAutoConnect(const bool autoconnect); + Q_INVOKABLE void setupIpv4Config(); + Q_INVOKABLE void setupIpv6Config(); + Q_INVOKABLE void setupNameserversConfig(); + Q_INVOKABLE void setupDomainsConfig(); + Q_INVOKABLE void setupNetworkSettingsProxy(); + //Wireless config + Q_INVOKABLE void connectService(); + Q_INVOKABLE void disconnectService(); +Q_SIGNALS: + void nameChanged(); + void stateChanged(); + void typeChanged(); + void proxyChanged(); + void ipv4Changed(); + void ipv6Changed(); + void domainsChanged(); + void nameserversChanged(); + void wirelessChanged(); + void showCrendentialInput(); +protected: + QNetworkSettingsServicePrivate *d_ptr; + + Q_DISABLE_COPY(QNetworkSettingsService) + Q_DECLARE_PRIVATE(QNetworkSettingsService) +}; + +#endif // QNETWORKSETTINGSSERVICE_H diff --git a/src/networksettings/qnetworksettingsservicemodel.cpp b/src/networksettings/qnetworksettingsservicemodel.cpp new file mode 100644 index 0000000..868cfa3 --- /dev/null +++ b/src/networksettings/qnetworksettingsservicemodel.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsservicemodel.h" +#include "qnetworksettings.h" + +QNetworkSettingsServiceModel::QNetworkSettingsServiceModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Name, "name"); + m_roleNames.insert(SignalStrength, "signalStrength"); + m_roleNames.insert(Connected, "connected"); +} + +QNetworkSettingsServiceModel::~QNetworkSettingsServiceModel() +{ + +} + +QHash<int, QByteArray> QNetworkSettingsServiceModel::roleNames() const +{ + return m_roleNames; +} + + +int QNetworkSettingsServiceModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant QNetworkSettingsServiceModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + QNetworkSettingsService *item = m_items[index.row()]; + if (role == Qt::UserRole) { + return QVariant::fromValue(static_cast<QObject*>(item)); + } + else if (role == Name) { + return item->name(); + } + else if (role == SignalStrength) { + return item->wirelessConfig()->signalStrength(); + } + else if (role == Connected) { + return item->state() == QNetworkSettingsState::Online || item->state() == QNetworkSettingsState::Ready; + } + return QVariant(); +} + +void QNetworkSettingsServiceModel::append(QNetworkSettingsService* item) +{ + item->setParent(this); + + beginResetModel(); + m_items.append(item); + endResetModel(); +} + +void QNetworkSettingsServiceModel::insert(int row, QNetworkSettingsService* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), row, row); + m_items.insert(row, item); + endInsertRows(); +} + +void QNetworkSettingsServiceModel::remove(int row) +{ + beginRemoveRows(QModelIndex(), row, row); + m_items.removeAt(row); + endRemoveRows(); +} + +bool QNetworkSettingsServiceModel::removeService(const QString &id) +{ + bool ret = false; + for (int i=0; i < m_items.count(); i++) { + if (m_items.at(i)->id() == id) { + remove(i); + ret = true; + break; + } + } + return ret; +} + +void QNetworkSettingsServiceModel::updated(int row) +{ + dataChanged(createIndex(row, 0), createIndex(row, 0)); +} + +QList<QNetworkSettingsService*> QNetworkSettingsServiceModel::getModel() +{ + return m_items; +} + +//Filter model + +QNetworkSettingsServiceFilter::QNetworkSettingsServiceFilter(QObject* parent) + :QSortFilterProxyModel(parent) +{ + connect(this, &QNetworkSettingsServiceFilter::typeChanged, this, &QNetworkSettingsServiceFilter::invalidate); +} + +QNetworkSettingsServiceFilter::~QNetworkSettingsServiceFilter() +{ + +} + +QNetworkSettingsType::Types QNetworkSettingsServiceFilter::type() const +{ + return m_type; +} + +void QNetworkSettingsServiceFilter::setType(const QNetworkSettingsType::Types type) +{ + m_type = type; + emit typeChanged(); +} + +bool QNetworkSettingsServiceFilter::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const +{ + if (this->sourceModel()) + { + QModelIndex index = this->sourceModel()->index( source_row, 0, source_parent ); + if (index.isValid()) + { + if (index.isValid()) + { + QObject * obj = qvariant_cast<QObject *>(index.data(Qt::UserRole)); + QNetworkSettingsService * service = qobject_cast<QNetworkSettingsService *>(obj); + if (service->type() == m_type) + return true; + } + } + } + return false; +} + +QVariant QNetworkSettingsServiceFilter::itemFromRow(const int row) const +{ + QModelIndex idx = index(row, 0); + QModelIndex mapped = mapToSource(idx); + if (mapped.isValid()) + { + QVariant serviceItem = mapped.data(Qt::UserRole); + if (serviceItem.isValid()) + { + return serviceItem; + } + } + return QVariant::fromValue(QStringLiteral("")); +} + diff --git a/src/networksettings/qnetworksettingsservicemodel.h b/src/networksettings/qnetworksettingsservicemodel.h new file mode 100644 index 0000000..0cf1601 --- /dev/null +++ b/src/networksettings/qnetworksettingsservicemodel.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICEMODEL_H +#define QNETWORKSETTINGSSERVICEMODEL_H + +#include <QSortFilterProxyModel> +#include "qnetworksettings.h" +#include "qnetworksettingsservice.h" + +class Q_DECL_EXPORT QNetworkSettingsServiceModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit QNetworkSettingsServiceModel(QObject *parent=0); + virtual ~QNetworkSettingsServiceModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + + void append(QNetworkSettingsService* networkService); + void insert(int row, QNetworkSettingsService* networkInterface); + void remove(int row); + bool removeService(const QString &id); + void updated(int row); + QList<QNetworkSettingsService*> getModel(); + + enum Roles { + Type = Qt::UserRole + 1, + Name, + SignalStrength, + Connected + }; + +private: + QList<QNetworkSettingsService*> m_items; + QHash<int, QByteArray> m_roleNames; +}; + +class QNetworkSettingsServiceFilter : public QSortFilterProxyModel +{ + Q_OBJECT + Q_PROPERTY(QNetworkSettingsType::Types type READ type WRITE setType NOTIFY typeChanged) +public: + explicit QNetworkSettingsServiceFilter(QObject* parent=0); + virtual ~QNetworkSettingsServiceFilter(); + bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; + QNetworkSettingsType::Types type() const; + void setType(QNetworkSettingsType::Types type); + Q_INVOKABLE QVariant itemFromRow(const int row) const; +signals: + void typeChanged(); +private: + QNetworkSettingsType::Types m_type; +}; + +#endif // QNETWORKSETTINGSSERVICEMODEL_H diff --git a/src/networksettings/qnetworksettingsuseragent.cpp b/src/networksettings/qnetworksettingsuseragent.cpp new file mode 100644 index 0000000..709b4d2 --- /dev/null +++ b/src/networksettings/qnetworksettingsuseragent.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsuseragent.h" +#include "qnetworksettingsuseragent_p.h" + +QNetworkSettingsUserAgent::QNetworkSettingsUserAgent(QObject *parent) + :QObject(parent) + ,d_ptr(new QNetworkSettingsUserAgentPrivate(this)) +{ +} + +void QNetworkSettingsUserAgent::setUserCredentials(const QString& username, const QString& passphrase) +{ + Q_D(QNetworkSettingsUserAgent); + d->setUserCredentials(username, passphrase); +} + +void QNetworkSettingsUserAgent::cancelInput() +{ + Q_D(QNetworkSettingsUserAgent); + d->cancel(); +} + +QString QNetworkSettingsUserAgent::passPhrase() const +{ + Q_D(const QNetworkSettingsUserAgent); + return d->m_passphrase; +} + +QString QNetworkSettingsUserAgent::userName() const +{ + Q_D(const QNetworkSettingsUserAgent); + return d->m_username; +} diff --git a/src/networksettings/qnetworksettingsuseragent.h b/src/networksettings/qnetworksettingsuseragent.h new file mode 100644 index 0000000..ff4c030 --- /dev/null +++ b/src/networksettings/qnetworksettingsuseragent.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSUSERAGENT_H +#define QNETWORKSETTINGSUSERAGENT_H + +#include <QObject> + +QT_FORWARD_DECLARE_CLASS(QNetworkSettingsUserAgentPrivate) + +class Q_DECL_EXPORT QNetworkSettingsUserAgent : public QObject +{ + Q_OBJECT +public: + explicit QNetworkSettingsUserAgent(QObject *parent = 0); + Q_INVOKABLE void setUserCredentials(const QString& username, const QString& passphrase); + Q_INVOKABLE void cancelInput(); + QString passPhrase() const; + QString userName() const; + +signals: + void showUserCredentialsInput(); + void error(); + void ready(bool cancel); +private: + QNetworkSettingsUserAgentPrivate *d_ptr; + + Q_DISABLE_COPY(QNetworkSettingsUserAgent) + Q_DECLARE_PRIVATE(QNetworkSettingsUserAgent) +}; +#endif // QNETWORKSETTINGSUSERAGENT_H diff --git a/src/networksettings/wpasupplicant.pri b/src/networksettings/wpasupplicant.pri new file mode 100644 index 0000000..db89315 --- /dev/null +++ b/src/networksettings/wpasupplicant.pri @@ -0,0 +1,28 @@ +QT += core network + +INCLUDEPATH += $${PWD}/wpasupplicant + +HEADERS += \ + $$PWD/wpasupplicant/qnetworksettingsinterface_p.h \ + $$PWD/wpasupplicant/qnetworksettingsmanager_p.h \ + $$PWD/wpasupplicant/qwifisupplicant_p.h \ + $$PWD/wpasupplicant/qwificontroller_p.h \ + $$PWD/wpasupplicant/qnetworksettingsservice_p.h \ + $$PWD/wpasupplicant/qnetworksettingsuseragent_p.h \ + $$PWD/wpasupplicant/qwifidevice.h + +SOURCES += \ + $$PWD/wpasupplicant/qnetworksettingsinterface_p.cpp \ + $$PWD/wpasupplicant/qnetworksettingsmanager_p.cpp \ + $$[QT_SYSROOT]/usr/include/wpa-supplicant/wpa_ctrl.c \ + $$[QT_SYSROOT]/usr/include/wpa-supplicant/os_unix.c \ + $$PWD/wpasupplicant/qwifisupplicant.cpp \ + $$PWD/wpasupplicant/qwificontroller.cpp \ + $$PWD/wpasupplicant/qnetworksettingsservice_p.cpp \ + $$PWD/wpasupplicant/qnetworksettingsuseragent_p.cpp \ + $$PWD/wpasupplicant/qwifidevice.cpp + +DEFINES += \ + CONFIG_CTRL_IFACE \ + CONFIG_CTRL_IFACE_UNIX + diff --git a/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.cpp b/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.cpp new file mode 100644 index 0000000..a2440a1 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsmanager_p.h" +#include "qwifidevice.h" + +QNetworkSettingsInterfacePrivate::QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent) + :QObject(parent) + ,q_ptr(parent) +{ + m_name = QString::fromLatin1(QWifiDevice::wifiInterfaceName()); + m_type.setType(QNetworkSettingsType::Wifi); + m_powered = true; //We don't really know +} + +void QNetworkSettingsInterfacePrivate::setManager(QNetworkSettingsManagerPrivate *manager) +{ + m_manager = manager; +} + +void QNetworkSettingsInterfacePrivate::setPowered(const bool power) +{ + //Not supported + Q_UNUSED(power); +} + +void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::States aState) +{ + Q_Q(QNetworkSettingsInterface); + m_state.setState(aState); + emit q->stateChanged(); +} + +void QNetworkSettingsInterfacePrivate::scan() +{ + m_manager->call(QStringLiteral("SCAN")); +} diff --git a/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.h b/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.h new file mode 100644 index 0000000..0cce23a --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsinterface_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSINTERFACEPRIVATE_H +#define QNETWORKSETTINGSINTERFACEPRIVATE_H + +#include <QObject> +#include "qnetworksettings.h" +#include "qnetworksettingsinterface.h" +#include "qnetworksettingsmanager_p.h" + +class QNetworkSettingsInterfacePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsInterface) +public: + explicit QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent); + void initialize(const QString& path, const QVariantMap& properties); + void setPowered(const bool power); + void setState(QNetworkSettingsState::States aState); + void setManager(QNetworkSettingsManagerPrivate *manager); + void scan(); + +signals: + +protected: + QString m_name; + QNetworkSettingsType m_type; + QNetworkSettingsState m_state; + bool m_powered; + QNetworkSettingsManagerPrivate *m_manager; //not owned + QNetworkSettingsInterface *q_ptr; +}; + +class WpaSupplicantSettingsInterface : public QNetworkSettingsInterface +{ + Q_OBJECT +public: + WpaSupplicantSettingsInterface(QNetworkSettingsManagerPrivate* manager) + :QNetworkSettingsInterface(manager) + { + Q_D(QNetworkSettingsInterface); + d->setManager(manager); + } + + void setState(QNetworkSettingsState::States aState) { + Q_D(QNetworkSettingsInterface); + d->setState(aState); + } + + virtual ~WpaSupplicantSettingsInterface() { + } +}; + +#endif // QNETWORKSETTINGSINTERFACEPRIVATE_H + diff --git a/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.cpp b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.cpp new file mode 100644 index 0000000..30f3f61 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.cpp @@ -0,0 +1,433 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QProcess> +#include "qnetworksettingsmanager_p.h" +#include "qwificontroller_p.h" +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsservice_p.h" +#include "qnetworksettingsuseragent.h" +#include "qwifisupplicant_p.h" + +QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent) + :QObject(parent) + ,q_ptr(parent) +{ + + QNetworkSettingsUserAgent* userAgent = new QNetworkSettingsUserAgent(this); + this->setUserAgent(userAgent); + + m_serviceModel = new QNetworkSettingsServiceModel(this); + m_serviceFilter = new QNetworkSettingsServiceFilter(this); + m_serviceFilter->setSourceModel(m_serviceModel); + + m_wifiController = new QWifiController(this); + m_wifiController->asyncCall(QWifiController::InitializeBackend); + + QObject::connect(m_wifiController, &QWifiController::backendStateChanged, + this, &QNetworkSettingsManagerPrivate::handleBackendStateChanged); + QObject::connect(m_wifiController, &QWifiController::dhcpRequestFinished, + this, &QNetworkSettingsManagerPrivate::handleDhcpRequestFinished); + + QObject::connect(m_wifiController, &QWifiController::raiseError, this, &QNetworkSettingsManagerPrivate::updateLastError); + m_wifiController->start(); + + updateWifiState(); +} + +QNetworkSettingsManagerPrivate::~QNetworkSettingsManagerPrivate() +{ + m_wifiController->asyncCall(QWifiController::ExitEventLoop); + m_wifiController->wait(); + delete m_wifiController; +} + +bool QNetworkSettingsManagerPrivate::event(QEvent *event) +{ + switch ((int) event->type()) { + case WIFI_SCAN_RESULTS: + parseScanResults(call(QStringLiteral("SCAN_RESULTS"))); + return true; + case WIFI_CONNECTED: + handleConnected(); + return true; + case WIFI_DISCONNECTED: + handleDisconneced(); + return true; + case WIFI_AUTHENTICATING: + handleAuthenticating(static_cast<QWifiEvent *>(event)); + return true; + case WIFI_HANDSHAKE_FAILED: + updateNetworkState(QNetworkSettingsState::Failure); + return true; + } + return QObject::event(event); +} + +void QNetworkSettingsManagerPrivate::connectNetwork(const QString& ssid) +{ + if (m_backendState != QWifiController::Running) { + qCWarning(B2QT_WIFI) << "start wifi backend before calling connect()"; + return; + } + + call(QStringLiteral("DISABLE_NETWORK all")); + m_currentSSID = ssid; + emit m_agent->showUserCredentialsInput(); +} + +void QNetworkSettingsManagerPrivate::userInteractionReady(bool cancel) +{ + if (cancel) { + m_currentSSID = QStringLiteral(""); + return; + } + bool networkKnown = false; + QString id; + const QStringList configuredNetworks = call(QStringLiteral("LIST_NETWORKS")).split('\n'); + for (int i = 1; i < configuredNetworks.length(); ++i) { + const QStringList networkFields = configuredNetworks.at(i).split('\t'); + const QString ssid = QWifiSupplicant::decodeSsid(networkFields.at(1)); + if (ssid == m_currentSSID) { + id = networkFields.at(0); + networkKnown = true; + break; + } + } + + if (!networkKnown) { + bool ok; + id = call(QStringLiteral("ADD_NETWORK")); + id.toInt(&ok); + if (!ok) { + updateLastError(QStringLiteral("failed to add network")); + return; + } + } + + bool ok = true; + QChar q = QLatin1Char('"'); + QString setNetworkCommand = QLatin1String("SET_NETWORK ") + id; + if (!networkKnown) { + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" ssid ") + q + m_currentSSID + q); + } + + QString key_mgmt; + WpaSupplicantService *service = networkForSSID(m_currentSSID); + if (!service) { + return; + } + QString psk = m_agent->passPhrase(); + + // --------------------- configure network ------------------------------ + // ref: http://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf + // ref: https://www.freebsd.org/cgi/man.cgi?wpa_supplicant.conf + // ---------------------------------------------------------------------- + if (service->wirelessConfig()->supportsSecurity(QNetworkSettingsWireless::WPA) || + service->wirelessConfig()->supportsSecurity(QNetworkSettingsWireless::WPA2)) { + // ### TODO - password length has limits (see IEEE 802.11), we need to check + // for those limits here. Supplicant gives only a meaningless "fail" message. + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" psk ") + q + psk + q); + key_mgmt = QLatin1String("WPA-PSK"); + } else if (service->wirelessConfig()->supportsSecurity(QNetworkSettingsWireless::WEP)) { + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" wep_key0 ") + q + psk + q); + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" auth_alg OPEN SHARED")); + key_mgmt = QLatin1String("NONE"); + } else if (service->wirelessConfig()->supportsSecurity(QNetworkSettingsWireless::None)) { + // open network + key_mgmt = QLatin1String("NONE"); + } + + if (service->wirelessConfig()->hidden()) + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" scan_ssid 1")); + + ok = ok && checkedCall(setNetworkCommand + QLatin1String(" key_mgmt ") + key_mgmt); + if (!ok) { + if (!networkKnown) + call(QLatin1String("REMOVE_NETWORK ") + id); + updateLastError(QLatin1String("failed to set properties on network: ") + id); + return; + } + + call(QLatin1String("SELECT_NETWORK ") + id); + call(QStringLiteral("RECONNECT")); +} + +void QNetworkSettingsManagerPrivate::disconnectNetwork() +{ + call(QStringLiteral("DISCONNECT")); + m_wifiController->asyncCall(QWifiController::StopDhcp); +} + +void QNetworkSettingsManagerPrivate::handleBackendStateChanged(QWifiController::BackendState backendState) +{ + switch (backendState) { + case QWifiController::NotRunning: + updateNetworkState(QNetworkSettingsState::Disconnect); + break; + default: + break; + } + updateBackendState(backendState); +} + +void QNetworkSettingsManagerPrivate::handleDhcpRequestFinished(const QString &status) +{ + qCDebug(B2QT_WIFI) << "handleDhcpRequestFinished: " << status << " for " << m_currentSSID; + if (status == QLatin1String("success")) { + updateNetworkState(QNetworkSettingsState::Online); + call(QStringLiteral("SAVE_CONFIG")); + } else { + updateNetworkState(QNetworkSettingsState::Failure); + } +} + +void QNetworkSettingsManagerPrivate::setUserAgent(QNetworkSettingsUserAgent *agent) +{ + m_agent = agent; + connect(m_agent, &QNetworkSettingsUserAgent::ready, this, &QNetworkSettingsManagerPrivate::userInteractionReady); +} + +void QNetworkSettingsManagerPrivate::setCurrentSSID(const QString &ssid) +{ + qCDebug(B2QT_WIFI) << "current SSID: " << m_currentSSID << " -> " << ssid; + if (m_currentSSID == ssid) + return; + + m_currentSSID = ssid; +} + +void QNetworkSettingsManagerPrivate::handleAuthenticating(QWifiEvent *event) +{ + QString data = event->data().trimmed(); + QString ssid = data.mid(data.indexOf(QLatin1String("SSID")) + 6); + ssid = ssid.left(ssid.lastIndexOf(QLatin1Char('\''))); + + setCurrentSSID(QWifiSupplicant::decodeSsid(ssid)); + updateNetworkState(QNetworkSettingsState::Association); +} + +void QNetworkSettingsManagerPrivate::handleConnected() +{ + qCDebug(B2QT_WIFI) << "connected network: " << m_currentSSID; + updateNetworkState(QNetworkSettingsState::Ready); + m_wifiController->asyncCall(QWifiController::AcquireIPAddress); +} + +void QNetworkSettingsManagerPrivate::handleDisconneced() +{ + updateNetworkState(QNetworkSettingsState::Disconnect); +} + +void QNetworkSettingsManagerPrivate::updateNetworkState(QNetworkSettingsState::States networkState) +{ + //Update interface + if (!m_interfaceModel.getModel().isEmpty()) { + WpaSupplicantSettingsInterface* interface = qobject_cast<WpaSupplicantSettingsInterface*>(m_interfaceModel.getModel().first()); + if (interface && interface->state() != networkState) { + interface->setState(networkState); + } + } + + //Update service state + WpaSupplicantService *service = networkForSSID(m_currentSSID); + if (service) { + service->setState(networkState); + } +} + +void QNetworkSettingsManagerPrivate::updateBackendState(QWifiController::BackendState backendState) +{ + if (m_backendState == backendState) + return; + + m_backendState = backendState; + + if (m_backendState == QWifiController::Running && m_interfaceModel.getModel().isEmpty()) { + WpaSupplicantSettingsInterface *interface = new WpaSupplicantSettingsInterface(this); + m_interfaceModel.append(interface); + } else if (m_backendState == QWifiController::NotRunning && m_interfaceModel.getModel().size() > 0){ + m_interfaceModel.remove(0); + } +} + +void QNetworkSettingsManagerPrivate::updateWifiState() +{ + QProcess ps; + ps.start(QStringLiteral("ps")); + if (!ps.waitForStarted()) { + updateLastError(ps.program() + QLatin1String(": ") + ps.errorString()); + return; + } + + ps.waitForFinished(); + bool supplicantRunning = ps.readAll().contains("wpa_supplicant"); + if (supplicantRunning && m_wifiController->resetSupplicantSocket()) + m_backendState = QWifiController::Running; +} + +QString QNetworkSettingsManagerPrivate::call(const QString &command) +{ + if (m_backendState != QWifiController::Running) + return QString(); + + QByteArray reply; + bool success = m_wifiController->supplicant()->sendCommand(command, &reply); + if (!success) { + qCDebug(B2QT_WIFI) << "call to supplicant failed"; + return QString(); + } + + return QLatin1String(reply.trimmed()); +} + +bool QNetworkSettingsManagerPrivate::checkedCall(const QString &command) +{ + return call(command).toUpper() == QLatin1String("OK"); +} + +void QNetworkSettingsManagerPrivate::updateLastError(const QString &error) +{ + qCWarning(B2QT_WIFI) << error; + if (!m_interfaceModel.getModel().isEmpty()) { + WpaSupplicantSettingsInterface* interface = qobject_cast<WpaSupplicantSettingsInterface*>(m_interfaceModel.getModel().first()); + if (interface) { + interface->setState(QNetworkSettingsState::Failure); + } + } +} + +WpaSupplicantService* QNetworkSettingsManagerPrivate::networkForSSID(const QString& ssid) +{ + int pos = 0; + return networkForSSID(ssid, pos); +} + +WpaSupplicantService* QNetworkSettingsManagerPrivate::networkForSSID(const QString& ssid, int& pos) +{ + QList<QNetworkSettingsService*> services = m_serviceModel->getModel(); + pos = 0; + foreach (QNetworkSettingsService *service, services) { + if (service->name() == ssid) { + return qobject_cast<WpaSupplicantService*>(service); + } + pos++; + } + pos = -1; + return NULL; +} + +WpaSupplicantService* QNetworkSettingsManagerPrivate::outOfRangeListContains(const QString& ssid) +{ + QList<QNetworkSettingsService*> services = m_outOfRangeServiceModel.getModel(); + foreach (QNetworkSettingsService *service, services) { + if (service->name() == ssid) { + return qobject_cast<WpaSupplicantService*>(service); + } + } + return NULL; +} + +void QNetworkSettingsManagerPrivate::parseScanResults(const QString &results) +{ + QStringList lines = results.split('\n'); + QSet<QString> sensibleNetworks; + + for (int i = 1; i < lines.size(); ++i) { + QStringList info = lines.at(i).split('\t'); + if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty()) + continue; + int pos = 0; + + QString ssid = QWifiSupplicant::decodeSsid(info.at(4)); + if (ssid.isEmpty()) + continue; + + sensibleNetworks.insert(ssid); + WpaSupplicantService *knownNetwork = networkForSSID(ssid, pos); + + if (!knownNetwork) { + knownNetwork = outOfRangeListContains(ssid); + m_outOfRangeServiceModel.getModel().removeOne(knownNetwork); + } + + int signalStrength = info.at(2).trimmed().toInt(); + if (signalStrength < 0) { + // signal is reported in dBm, rough conversion: best = -40, worst = -100 + int val = qAbs(qMax(-100, qMin(signalStrength, -40)) + 40); // clamp and normalize to 0 + signalStrength = 100 - (int) ((100.0 * (double) val) / 60.0); + } else if (signalStrength > 100) { + qCWarning(B2QT_WIFI) << "unexpected value for a signal level: " << signalStrength; + } + + if (!knownNetwork) { + WpaSupplicantService *network = new WpaSupplicantService(this); + network->setId(info.at(0)); + network->setFlags(info.at(3)); + network->wirelessConfig()->setSignalStrength(signalStrength); + network->setName(ssid); + m_serviceModel->append(network); + } else { + if (knownNetwork->wirelessConfig()->outOfRange()) { + // known network has come back into a range + knownNetwork->wirelessConfig()->setOutOfRange(false); + m_serviceModel->append(knownNetwork); + pos = m_serviceModel->getModel().size() - 1; + } + // ssids are the same, compare bssids.. + if (knownNetwork->id() == info.at(0)) { + // same access point, simply update the signal strength + knownNetwork->wirelessConfig()->setSignalStrength(signalStrength); + knownNetwork->wirelessConfig()->setOutOfRange(false); + m_serviceModel->updated(pos); + } else if (knownNetwork->wirelessConfig()->signalStrength() < signalStrength) { + // replace with a stronger access point within the same network + knownNetwork->wirelessConfig()->setOutOfRange(false); + knownNetwork->setId(info.at(0)); + knownNetwork->setFlags(info.at(3)); + knownNetwork->wirelessConfig()->setSignalStrength(signalStrength); + knownNetwork->setName(ssid); + m_serviceModel->updated(pos); + } + } + } + // remove out-of-range networks from the data model + QList<QNetworkSettingsService*> networks; + for (int i = 0; i < networks.size();) { + if (!sensibleNetworks.contains(networks.at(i)->name())) { + WpaSupplicantService *n = qobject_cast<WpaSupplicantService*>(networks.at(i)); + m_serviceModel->remove(i); + if (n) { + n->wirelessConfig()->setOutOfRange(true); + m_outOfRangeServiceModel.append(n); + } + } else { + ++i; + } + } +} diff --git a/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h new file mode 100644 index 0000000..d042ece --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsmanager_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSMANAGERPRIVATE_H +#define QNETWORKSETTINGSMANAGERPRIVATE_H + +#include <QObject> +#include "qnetworksettings.h" +#include "qnetworksettingsmanager.h" +#include "qnetworksettingsinterfacemodel.h" +#include "qnetworksettingsservicemodel.h" +#include "qwificontroller_p.h" + +class WpaSupplicantService; + +class QNetworkSettingsManagerPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsManager) +public: + explicit QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent); + virtual ~QNetworkSettingsManagerPrivate(); + QNetworkSettingsManager *q_ptr; + void setUserAgent(QNetworkSettingsUserAgent *agent); + void connectNetwork(const QString& ssid); + void disconnectNetwork(); + QString call(const QString &command); + bool checkedCall(const QString &command); + QNetworkSettingsUserAgent *getUserAgent() {return m_agent;} +protected: + bool event(QEvent *event); + +private slots: + void handleBackendStateChanged(QWifiController::BackendState backendState); + void handleDhcpRequestFinished(const QString &status); + void userInteractionReady(bool cancel); + void updateLastError(const QString &error); +private: + void setCurrentSSID(const QString &ssid); + void handleConnected(); + void handleDisconneced(); + void handleAuthenticating(QWifiEvent *event); + void updateNetworkState(QNetworkSettingsState::States networkState); + void updateBackendState(QWifiController::BackendState backendState); + void updateWifiState(); + void parseScanResults(const QString &results); + WpaSupplicantService* networkForSSID(const QString& ssid); + WpaSupplicantService* networkForSSID(const QString& ssid, int& pos); + WpaSupplicantService* outOfRangeListContains(const QString& ssid); + + QNetworkSettingsInterfaceModel m_interfaceModel; + QNetworkSettingsServiceModel *m_serviceModel; + QNetworkSettingsServiceModel m_outOfRangeServiceModel; + QNetworkSettingsServiceFilter *m_serviceFilter; + QWifiController *m_wifiController; + QNetworkSettingsUserAgent *m_agent; + + QWifiController::BackendState m_backendState; + QString m_currentSSID; +}; + + +#endif // QNETWORKSETTINGSMANAGERPRIVATE_H diff --git a/src/networksettings/wpasupplicant/qnetworksettingsservice_p.cpp b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.cpp new file mode 100644 index 0000000..974f85b --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsservice_p.h" +#include "qnetworksettingsmanager_p.h" + +QNetworkSettingsServicePrivate::QNetworkSettingsServicePrivate(const QString& bssid, QNetworkSettingsService *parent) : + QObject(parent) + ,q_ptr(parent) + ,m_id(bssid) +{ + m_type.setType(QNetworkSettingsType::Wifi); +} + +void QNetworkSettingsServicePrivate::setManager(QNetworkSettingsManagerPrivate *manager) +{ + m_manager = manager; +} + +void QNetworkSettingsServicePrivate::connectService() +{ + m_manager->connectNetwork(m_name); +} + +void QNetworkSettingsServicePrivate::disconnectService() +{ + m_manager->disconnectNetwork(); +} + +void QNetworkSettingsServicePrivate::setupIpv6Config() +{ + //Not supported +} + +void QNetworkSettingsServicePrivate::setupNameserversConfig() +{ + //Not supported +} + +void QNetworkSettingsServicePrivate::setupDomainsConfig() +{ + //Not supported +} + +void QNetworkSettingsServicePrivate::setupQNetworkSettingsProxy() +{ + //Not supported +} + +void QNetworkSettingsServicePrivate::setupIpv4Config() +{ + //Not supported +} + +WpaSupplicantService::WpaSupplicantService(QNetworkSettingsManagerPrivate* manager, QObject* parent) + :QNetworkSettingsService(QStringLiteral(""), parent) +{ + Q_D(QNetworkSettingsService); + d->setManager(manager); +} + +void WpaSupplicantService::setId(const QString& aId) +{ + Q_D(QNetworkSettingsService); + d->m_id = aId; +} + +void WpaSupplicantService::setName(const QString& aName) +{ + Q_D(QNetworkSettingsService); + d->m_name = aName; + emit nameChanged(); +} + +void WpaSupplicantService::setFlags(const QString& aFlags) +{ + Q_D(QNetworkSettingsService); + + if (aFlags.contains(QStringLiteral("WPA-"))) { + d->m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA); + } + if (aFlags.contains(QStringLiteral("WPA2-"))) { + d->m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA2); + } + if (aFlags.contains(QStringLiteral("WEP-"))) { + d->m_wifiConfig.setSecurity(QNetworkSettingsWireless::WEP); + } +} + +void WpaSupplicantService::setState(QNetworkSettingsState::States aState) +{ + Q_D(QNetworkSettingsService); + d->m_state.setState(aState); + emit stateChanged(); +} diff --git a/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h new file mode 100644 index 0000000..3920f61 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsservice_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICEPRIVATE_H +#define QNETWORKSETTINGSSERVICEPRIVATE_H + +#include <QObject> +#include "qnetworksettings.h" +#include "qnetworksettingsservice.h" + +class QNetworkSettingsManagerPrivate; + +class QNetworkSettingsServicePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsService) +public: + QNetworkSettingsServicePrivate(const QString& aServiceId, QNetworkSettingsService *parent=0); + void setManager(QNetworkSettingsManagerPrivate *manager); + QNetworkSettingsService *q_ptr; + + void setAutoConnect(const bool autoconnect); + void setupIpv4Config(); + void setupIpv6Config(); + void setupNameserversConfig(); + void setupDomainsConfig(); + void setupQNetworkSettingsProxy(); + void connectService(); + void disconnectService(); + + QString m_id; + QString m_name; + QNetworkSettingsState m_state; + QNetworkSettingsIPv4 m_ipv4config; + QNetworkSettingsIPv6 m_ipv6config; + QNetworkSettingsAddressModel m_domainsConfig; + QNetworkSettingsAddressModel m_nameserverConfig; + QNetworkSettingsProxy m_proxyConfig; + QNetworkSettingsWireless m_wifiConfig; + QNetworkSettingsType m_type; + QNetworkSettingsManagerPrivate *m_manager; //Not owned +}; + +class WpaSupplicantService : public QNetworkSettingsService +{ + Q_OBJECT +public: + explicit WpaSupplicantService(QNetworkSettingsManagerPrivate* manager, QObject* parent=0); + void setId(const QString& aId); + void setName(const QString& aName); + void setFlags(const QString& aFlags); + void setState(QNetworkSettingsState::States aState); +}; + +#endif // QNETWORKSETTINGSSERVICEPRIVATE_H diff --git a/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.cpp b/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.cpp new file mode 100644 index 0000000..b463606 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsuseragent_p.h" + +QNetworkSettingsUserAgentPrivate::QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent* parent) + :QObject(parent) + ,q_ptr(parent) +{ + +} + +void QNetworkSettingsUserAgentPrivate::setUserCredentials(const QString& aUsername, const QString& aPassword) +{ + Q_Q(QNetworkSettingsUserAgent); + m_passphrase = aPassword; + m_username = aUsername; + emit q->ready(false); +} + +void QNetworkSettingsUserAgentPrivate::cancel() +{ + Q_Q(QNetworkSettingsUserAgent); + emit q->ready(true); +} diff --git a/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.h b/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.h new file mode 100644 index 0000000..0b1a149 --- /dev/null +++ b/src/networksettings/wpasupplicant/qnetworksettingsuseragent_p.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSUSERAGENTPRIVATE_H +#define QNETWORKSETTINGSUSERAGENTPRIVATE_H + +#include <QObject> +#include "qnetworksettingsuseragent.h" + +class QNetworkSettingsUserAgentPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsUserAgent) +public: + explicit QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent* parent); + virtual ~QNetworkSettingsUserAgentPrivate() {} + void setUserCredentials(const QString& aUsername, const QString& aPassword); + void cancel(); + QString m_passphrase; + QString m_username; + QNetworkSettingsUserAgent *q_ptr; +}; + +#endif // QNETWORKSETTINGSUSERAGENTPRIVATE_H diff --git a/src/wifi/qwificontroller.cpp b/src/networksettings/wpasupplicant/qwificontroller.cpp index f5ed741..0e76da0 100644 --- a/src/wifi/qwificontroller.cpp +++ b/src/networksettings/wpasupplicant/qwificontroller.cpp @@ -1,23 +1,33 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** -** This file is part of Qt Enterprise Embedded. +** This file is part of the Device Utilities module of the Qt Toolkit. ** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qwificontroller_p.h" -#include "qwifimanager_p.h" +#include "qnetworksettingsmanager_p.h" #include "qwifisupplicant_p.h" #include "qwifidevice.h" @@ -69,8 +79,9 @@ public: event = new QWifiEvent(WIFI_HANDSHAKE_FAILED); } - if (event) - QCoreApplication::postEvent(m_controller->wifiManager(), event); + if (event) { + QCoreApplication::postEvent(m_controller->manager(), event); + } } } } @@ -80,15 +91,15 @@ private: }; -QWifiController::QWifiController(QWifiManager *manager, QWifiManagerPrivate *managerPrivate) : +QWifiController::QWifiController(QNetworkSettingsManagerPrivate *manager) : m_manager(manager), - m_managerPrivate(managerPrivate), m_exitEventThread(false), m_interface(QWifiDevice::wifiInterfaceName()), m_eventThread(new QWifiEventThread(this)), - m_supplicant(new QWifiSupplicant(this, m_managerPrivate)) + m_supplicant(new QWifiSupplicant(this)) { - qRegisterMetaType<QWifiManager::BackendState>("QWifiManager::BackendState"); + qRegisterMetaType<QWifiController::BackendState>("BackendState"); + connect(m_supplicant, &QWifiSupplicant::raiseError, this, &QWifiController::raiseError); } QWifiController::~QWifiController() @@ -137,7 +148,7 @@ void QWifiController::asyncCall(Method method) void QWifiController::initializeBackend() { qCDebug(B2QT_WIFI) << "initializing wifi backend"; - emit backendStateChanged(QWifiManager::Initializing); + emit backendStateChanged(QWifiController::Initializing); QProcess rfkill; rfkill.start(QStringLiteral("rfkill"), @@ -148,7 +159,7 @@ void QWifiController::initializeBackend() ifconfig.start(QStringLiteral("ifconfig"), QStringList() << QLatin1String(m_interface) << QStringLiteral("up")); if (!ifconfig.waitForStarted()) { - m_managerPrivate->updateLastError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); + emit raiseError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); return; } @@ -156,13 +167,13 @@ void QWifiController::initializeBackend() bool initFailed = false; QByteArray error = ifconfig.readAllStandardError(); if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("failed to bring up wifi interface: " + error)); + emit raiseError(QLatin1String("failed to bring up wifi interface: " + error)); initFailed = true; } if (!initFailed && resetSupplicantSocket()) - emit backendStateChanged(QWifiManager::Running); + emit backendStateChanged(QWifiController::Running); else - emit backendStateChanged(QWifiManager::NotRunning); + emit backendStateChanged(QWifiController::NotRunning); } bool QWifiController::resetSupplicantSocket() @@ -183,7 +194,7 @@ bool QWifiController::resetSupplicantSocket() void QWifiController::terminateBackend() { qCDebug(B2QT_WIFI) << "terminating wifi backend"; - emit backendStateChanged(QWifiManager::Terminating); + emit backendStateChanged(QWifiController::Terminating); exitWifiEventThread(); m_supplicant->stopSupplicant(); @@ -193,17 +204,17 @@ void QWifiController::terminateBackend() ifconfig.start(QStringLiteral("ifconfig"), QStringList() << QLatin1String(m_interface) << QStringLiteral("down")); if (!ifconfig.waitForStarted()) { - m_managerPrivate->updateLastError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); + emit raiseError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); return; } ifconfig.waitForFinished(); QByteArray error = ifconfig.readAllStandardError(); if (!error.isEmpty()) - m_managerPrivate->updateLastError(QLatin1String("failed to bring down wifi interface: " + error)); + emit raiseError(QLatin1String("failed to bring down wifi interface: " + error)); stopDhcp(); - emit backendStateChanged(QWifiManager::NotRunning); + emit backendStateChanged(QWifiController::NotRunning); } void QWifiController::startWifiEventThread() @@ -216,7 +227,7 @@ void QWifiController::exitWifiEventThread() { if (m_eventThread->isRunning()) { m_exitEventThread = true; - m_managerPrivate->call(QStringLiteral("SCAN")); + m_manager->call(QStringLiteral("SCAN")); if (!m_eventThread->wait(8000)) qCWarning(B2QT_WIFI, "timed out waiting for wifi event thread to exit"); } @@ -255,7 +266,7 @@ void QWifiController::acquireIPAddress() QProcess udhcpc; udhcpc.start(QStringLiteral("udhcpc"), args); if (!udhcpc.waitForStarted()) { - m_managerPrivate->updateLastError(udhcpc.program() + QLatin1String(": ") + udhcpc.errorString()); + emit raiseError(udhcpc.program() + QLatin1String(": ") + udhcpc.errorString()); emit dhcpRequestFinished(QLatin1String("failed")); return; } @@ -264,7 +275,7 @@ void QWifiController::acquireIPAddress() QByteArray error = udhcpc.readAllStandardError(); QString status = QLatin1String("success"); if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("udhcpc failed: " + error)); + emit raiseError(QLatin1String("udhcpc failed: " + error)); status = QLatin1String("failed"); } else { if (udhcpc.readAllStandardOutput().contains("No lease")) diff --git a/src/wifi/qwificontroller_p.h b/src/networksettings/wpasupplicant/qwificontroller_p.h index 45751fa..0bb4c9a 100644 --- a/src/wifi/qwificontroller_p.h +++ b/src/networksettings/wpasupplicant/qwificontroller_p.h @@ -1,26 +1,34 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** -** This file is part of Qt Enterprise Embedded. +** This file is part of the Device Utilities module of the Qt Toolkit. ** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef QWIFICONTROLLER_H #define QWIFICONTROLLER_H -#include "qwifimanager.h" - #include <QtCore/QEvent> #include <QtCore/QVector> #include <QtCore/QThread> @@ -38,10 +46,9 @@ const QEvent::Type WIFI_HANDSHAKE_FAILED = (QEvent::Type) (QEvent::User + 2003); const QEvent::Type WIFI_AUTHENTICATING = (QEvent::Type) (QEvent::User + 2004); const QEvent::Type WIFI_DISCONNECTED = (QEvent::Type) (QEvent::User + 2005); -class QWifiManager; -class QWifiManagerPrivate; class QWifiEventThread; class QWifiSupplicant; +class QNetworkSettingsManagerPrivate; class QWifiEvent : public QEvent { @@ -60,6 +67,7 @@ private: class QWifiController : public QThread { Q_OBJECT + Q_ENUMS(BackendState) public: enum Method { InitializeBackend, @@ -69,11 +77,18 @@ public: ExitEventLoop }; - explicit QWifiController(QWifiManager *manager, QWifiManagerPrivate *managerPrivate); + enum BackendState { + Initializing, + Running, + Terminating, + NotRunning + }; + + explicit QWifiController(QNetworkSettingsManagerPrivate *manager); ~QWifiController(); void asyncCall(Method method); - QWifiManager *wifiManager() const { return m_manager; } + QNetworkSettingsManagerPrivate *manager() const { return m_manager; } bool isWifiThreadExitRequested() const { return m_exitEventThread; } void startWifiEventThread(); void acquireIPAddress(); @@ -82,8 +97,9 @@ public: QWifiSupplicant *supplicant() const { return m_supplicant; } signals: - void backendStateChanged(QWifiManager::BackendState backendState); + void backendStateChanged(BackendState backendState); void dhcpRequestFinished(const QString &status); + void raiseError(const QString &error); protected: void run(); @@ -93,8 +109,7 @@ protected: void killDhcpProcess(const QString &path) const; private: - QWifiManager *m_manager; - QWifiManagerPrivate *const m_managerPrivate; + QNetworkSettingsManagerPrivate *m_manager; //not owned bool m_exitEventThread; QByteArray m_interface; QVector<Method> m_methods; @@ -104,6 +119,8 @@ private: QWifiSupplicant *m_supplicant; }; +Q_DECLARE_METATYPE(QWifiController::BackendState) + QT_END_NAMESPACE #endif // QWIFICONTROLLER_H diff --git a/src/wifi/qwifidevice.cpp b/src/networksettings/wpasupplicant/qwifidevice.cpp index a6812e7..3b6fdd1 100644 --- a/src/wifi/qwifidevice.cpp +++ b/src/networksettings/wpasupplicant/qwifidevice.cpp @@ -1,23 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** -** This file is part of Qt Enterprise Embedded. +** This file is part of the Device Utilities module of the Qt Toolkit. ** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qwifidevice.h" - #include <QtCore/QString> #include <QtCore/QByteArray> #include <QtCore/QDir> diff --git a/src/networksettings/wpasupplicant/qwifidevice.h b/src/networksettings/wpasupplicant/qwifidevice.h new file mode 100644 index 0000000..43cf697 --- /dev/null +++ b/src/networksettings/wpasupplicant/qwifidevice.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QWIFIDEVICE_H +#define QWIFIDEVICE_H + +#include <QtCore/QObject> +#include <QtCore/QByteArray> +#include <QtCore/QLoggingCategory> + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) + +class Q_DECL_EXPORT QWifiDevice : public QObject +{ + Q_OBJECT +public: + explicit QWifiDevice(); + virtual ~QWifiDevice(); + + Q_INVOKABLE static bool wifiSupported(); + static QByteArray wifiInterfaceName(); + static void setWifiInterfaceName(const QByteArray &name); +}; + +QT_END_NAMESPACE + +#endif // QWIFIDEVICE_H diff --git a/src/wifi/qwifisupplicant.cpp b/src/networksettings/wpasupplicant/qwifisupplicant.cpp index d87ac80..e8a88a8 100644 --- a/src/wifi/qwifisupplicant.cpp +++ b/src/networksettings/wpasupplicant/qwifisupplicant.cpp @@ -1,28 +1,38 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** -** This file is part of Qt Enterprise Embedded. +** This file is part of the Device Utilities module of the Qt Toolkit. ** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qwifisupplicant_p.h" #include "qwifidevice.h" -#include "qwifimanager_p.h" #include <poll.h> #include <unistd.h> #include <sys/socket.h> +#include <errno.h> #include <QtCore/QFile> #include <QtCore/QProcess> @@ -34,17 +44,16 @@ Q_LOGGING_CATEGORY(B2QT_WIFI_VERBOSE, "qt.b2qt.wifi.verbose") #define CONFIG_FILE "/etc/wpa_supplicant.qtwifi.conf" #define CONTROL_INTERFACE_PATH "/var/run/wpa_supplicant/" -QWifiSupplicant::QWifiSupplicant(QObject *parent, QWifiManagerPrivate *managerPrivate) : +QWifiSupplicant::QWifiSupplicant(QObject *parent) : QObject(parent), ctrl_conn(0), monitor_conn(0), - interface(QWifiDevice::wifiInterfaceName()), - m_managerPrivate(managerPrivate) + interface(QWifiDevice::wifiInterfaceName()) { createSupplicantConfig(); } -void QWifiSupplicant::createSupplicantConfig() const +void QWifiSupplicant::createSupplicantConfig() { QFile supplicantConfig(QLatin1String(CONFIG_FILE)); if (supplicantConfig.exists()) @@ -55,7 +64,7 @@ void QWifiSupplicant::createSupplicantConfig() const "ctrl_interface_group=0\n" "update_config=1\n"); } else { - m_managerPrivate->updateLastError(QLatin1String("failed to create wpa_supplicant configuration file.")); + emit raiseError(QLatin1String("failed to create wpa_supplicant configuration file.")); } } @@ -76,13 +85,13 @@ bool QWifiSupplicant::startSupplicant() startStopDaemon.setProcessChannelMode(QProcess::MergedChannels); startStopDaemon.start(QStringLiteral("start-stop-daemon"), arg); if (!startStopDaemon.waitForStarted()) { - m_managerPrivate->updateLastError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); + emit raiseError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); return false; } startStopDaemon.waitForFinished(); // if the interface socket exists then wpa-supplicant was invoked successfully if (!QFile(QLatin1String(CONTROL_INTERFACE_PATH + interface)).exists()) { - m_managerPrivate->updateLastError(QLatin1String("failed to invoke wpa_supplicant: " + emit raiseError(QLatin1String("failed to invoke wpa_supplicant: " + startStopDaemon.readAll())); return false; } @@ -103,13 +112,13 @@ bool QWifiSupplicant::stopSupplicant() QProcess startStopDaemon; startStopDaemon.start(QStringLiteral("start-stop-daemon"), arg); if (!startStopDaemon.waitForStarted()) { - m_managerPrivate->updateLastError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); + emit raiseError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); return false; } startStopDaemon.waitForFinished(); QByteArray error = startStopDaemon.readAllStandardError(); if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("failed to stop a wpa_supplicant process" + error)); + emit raiseError(QLatin1String("failed to stop a wpa_supplicant process" + error)); return false; } @@ -165,7 +174,7 @@ bool QWifiSupplicant::connectToSupplicant() } if (!connected) - m_managerPrivate->updateLastError(QLatin1String("failed to connect to wpa_supplicant")); + emit raiseError(QLatin1String("failed to connect to wpa_supplicant")); return connected; } diff --git a/src/networksettings/wpasupplicant/qwifisupplicant_p.h b/src/networksettings/wpasupplicant/qwifisupplicant_p.h new file mode 100644 index 0000000..713ab6d --- /dev/null +++ b/src/networksettings/wpasupplicant/qwifisupplicant_p.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QWIFISUPPLICANT_H +#define QWIFISUPPLICANT_H + +#include <QObject> +#include <QByteArray> +#include <QLoggingCategory> + +#include "wpa-supplicant/wpa_ctrl.h" + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) +Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI_VERBOSE) + +class QWifiManagerPrivate; + +class QWifiSupplicant : public QObject +{ + Q_OBJECT +public: + explicit QWifiSupplicant(QObject *parent); + + void createSupplicantConfig(); + bool startSupplicant(); + bool stopSupplicant(); + bool connectToSupplicant(); + void closeSupplicantConnection(); + int waitForEvent(char *buf, size_t buflen); + bool sendCommand(const QString &command, QByteArray *reply); + static QString decodeSsid(const QString &encoded); + +signals: + void raiseError(const QString& error); + +protected: + int receiveEvent(char *reply, size_t *reply_len); + +private: + wpa_ctrl *ctrl_conn; + wpa_ctrl *monitor_conn; + int exit_sockets[2]; + QByteArray interface; +}; + +QT_END_NAMESPACE + +#endif // QWIFISUPPLICANT_H diff --git a/src/settingsui/AutoScroller.qml b/src/settingsui/AutoScroller.qml new file mode 100644 index 0000000..0ece105 --- /dev/null +++ b/src/settingsui/AutoScroller.qml @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.VirtualKeyboard 2.0 + +Item { + + property var innerFlickable + property var outerFlickable + property var inputItem: InputContext.inputItem + + onInputItemChanged: { + innerFlickable = null + outerFlickable = null + if (inputItem !== null) { + var parent_ = inputItem.parent + while (parent_) { + if (parent_.maximumFlickVelocity) { + if (innerFlickable) { + outerFlickable = parent_ + break + } else { + innerFlickable = parent_ + } + } + parent_ = parent_.parent + } + delayedLoading.triggered() + } + } + + function ensureVisible(flickable) { + if (Qt.inputMethod.visible && inputItem && flickable && flickable.visible && flickable.interactive) { + + var verticallyFlickable = (flickable.flickableDirection === Flickable.HorizontalAndVerticalFlick || flickable.flickableDirection === Flickable.VerticalFlick + || (flickable.flickableDirection === Flickable.AutoFlickDirection && flickable.contentHeight > flickable.height)) + var horizontallyFlickable = (flickable.flickableDirection === Flickable.HorizontalAndVerticalFlick || flickable.flickableDirection === Flickable.HorizontalFlick + || (flickable.flickableDirection === Flickable.AutoFlickDirection && flickable.contentWidth > flickable.width)) + + if ((!verticallyFlickable && !horizontallyFlickable) || !inputItem.hasOwnProperty("cursorRectangle")) + return + + var cursorRectangle = flickable.contentItem.mapFromItem(inputItem, inputItem.cursorRectangle.x, inputItem.cursorRectangle.y) + + var oldContentY = flickable.contentY + if (verticallyFlickable) { + var scrollMarginVertical = (flickable && flickable.scrollMarginVertical) ? flickable.scrollMarginVertical : 10 + if (flickable.contentY >= cursorRectangle.y - scrollMarginVertical) + flickable.contentY = Math.max(0, cursorRectangle.y - scrollMarginVertical) + else if (flickable.contentY + flickable.height <= cursorRectangle.y + inputItem.cursorRectangle.height + scrollMarginVertical) + flickable.contentY = Math.min(flickable.contentHeight - flickable.height, cursorRectangle.y + inputItem.cursorRectangle.height - flickable.height + scrollMarginVertical) + } + if (horizontallyFlickable) { + var scrollMarginHorizontal = (flickable && flickable.scrollMarginHorizontal) ? flickable.scrollMarginHorizontal : 10 + if (flickable.contentX >= cursorRectangle.x - scrollMarginHorizontal) + flickable.contentX = Math.max(0, cursorRectangle.x - scrollMarginHorizontal) + else if (flickable.contentX + flickable.width <= cursorRectangle.x + inputItem.cursorRectangle.width + scrollMarginHorizontal) + flickable.contentX = Math.min(flickable.contentWidth - flickable.width, cursorRectangle.x + inputItem.cursorRectangle.width - flickable.width + scrollMarginHorizontal) + } + } + } + Timer { + id: delayedLoading + interval: 10 + onTriggered: { + ensureVisible(innerFlickable) + ensureVisible(outerFlickable) + } + } + Connections { + ignoreUnknownSignals: true + target: inputItem && !Qt.inputMethod.animating ? Qt.inputMethod : null + onKeyboardRectangleChanged: delayedLoading.triggered() + } + Connections { + ignoreUnknownSignals: true + target: inputItem && inputItem.activeFocus ? inputItem : null + onCursorRectangleChanged: delayedLoading.triggered() + } +} diff --git a/src/settingsui/bluetooth/Bluetooth.qml b/src/settingsui/bluetooth/Bluetooth.qml new file mode 100644 index 0000000..309f978 --- /dev/null +++ b/src/settingsui/bluetooth/Bluetooth.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.BluetoothSettings 1.0 + +Item { + id: root + property string title: qsTr("Bluetooth Settings") + + ColumnLayout { + anchors.margins: 20 + anchors.fill: parent + id: content + spacing: 20 + + GroupBox { + id: groupBox + width: parent.width + title: qsTr("Bluetooth status") + Layout.fillWidth: true + Layout.alignment: Qt.AlignTop + + RowLayout { + spacing: 10 + Label { + id: off + text: qsTr("Off") + } + Switch { + checked: BtDevice.powered + onCheckedChanged: BtDevice.powered = checked + } + Label { + text: qsTr("On") + } + } + } + Discovery { + id: discovery + visible: BtDevice.powered + Layout.fillWidth: true + Layout.fillHeight: true + } + } +} diff --git a/src/settingsui/bluetooth/Discovery.qml b/src/settingsui/bluetooth/Discovery.qml new file mode 100644 index 0000000..4daa469 --- /dev/null +++ b/src/settingsui/bluetooth/Discovery.qml @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.BluetoothSettings 1.0 + +Item { + id: top + + GroupBox { + id: groupBox + title: qsTr("Devices") + anchors.fill: parent + + ListView { + id: mainList + anchors.fill: parent + opacity: BtDevice.scanning ? .5 : 1.0 + interactive: !BtDevice.scanning + clip: true + model: BtDevice.deviceModel + + function getIcon(deviceType) { + switch (deviceType) { + case BtDeviceItem.Computer: + return "../icons/Laptop_qt_1x.png" + case BtDeviceItem.Headphones: + return "../icons/Headphones_qt_1x.png" + case BtDeviceItem.Microphone: + return "../icons/Microphone_qt_1x.png" + case BtDeviceItem.Mouse: + return "../icons/Mouse_qt_1x.png" + case BtDeviceItem.Keyboard: + return "../icons/Keyboard_qt_1x.png" + default: + return "../icons/Bluetooth_qt_1x.png" + } + } + + delegate: Item { + id: btDelegate + width: parent.width + height: expanded || connected ? column.height + 10 : bttext.height + 10 + property bool expanded: false; + + MouseArea { + anchors.fill: parent + onClicked: { + if (!connected) + btDelegate.expanded = !btDelegate.expanded + } + } + Image { + id: bticon + anchors.left: parent.left + anchors.top: parent.top + anchors.topMargin: 4 + source: mainList.getIcon(deviceType) + } + Column { + id: column + anchors.left: bticon.right + anchors.leftMargin: 10 + anchors.right: connectButton.left + anchors.rightMargin: 10 + + Label { + id: bttext + text: name + } + Label { + id: details + opacity: btDelegate.expanded || connected ? 1 : 0.0 + text: address + Behavior on opacity { NumberAnimation { duration: 200} } + } + } + Button { + id: connectButton + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + visible: (expanded || connected) && !BtDevice.scanning + text: connected ? qsTr("Disconnect") : qsTr("Connect") + onClicked : connected ? BtDevice.requestDisconnect(address) : BtDevice.requestPairing(address); + } + Behavior on height { NumberAnimation { duration: 200} } + } + focus: true + } + } + BusyIndicator { + anchors.centerIn: parent + running: BtDevice.scanning + } +} diff --git a/src/settingsui/common/CustomTableView.qml b/src/settingsui/common/CustomTableView.qml new file mode 100644 index 0000000..6b0505a --- /dev/null +++ b/src/settingsui/common/CustomTableView.qml @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 + +ColumnLayout { + id: root + spacing: 0 + Layout.fillHeight: true + Layout.fillWidth: true + + property var headerTexts: [] + property var roleNames: [] + property alias model: listView.model + signal clicked(int index) + + Rectangle { + height: 40 + Layout.fillWidth: true + color: "#80c342" + + Row { + anchors.fill: parent + anchors.leftMargin: 10 + spacing: 10 + + Repeater { + model: root.headerTexts.length + Text { + width: parent.width / root.headerTexts.length + text: root.headerTexts[index] + color: "white" + font.bold: true + anchors.verticalCenter: parent.verticalCenter + } + } + } + } + ListView { + id: listView + Layout.fillHeight: true + Layout.fillWidth: true + clip: true + + Rectangle { + anchors.fill: parent + border.color: "#bdbebf" + border.width: 1 + color: "transparent" + } + + ScrollBar.vertical: ScrollBar {} + + delegate: Rectangle { + width: parent.width + height: 30 + color: index % 2 ? "#e3e3e3" : "white" + property var delegateData: modelData + + Row { + anchors.fill: parent + anchors.leftMargin: 10 + spacing: 10 + + Repeater { + model: root.roleNames.length + + Text { + width: parent.width / root.roleNames.length + text: delegateData[root.roleNames[index]] + anchors.verticalCenter: parent.verticalCenter + antialiasing: false + smooth: false + renderType: listView.moving ? Text.NativeRendering : Text.QtRendering + } + } + } + MouseArea { + anchors.fill: parent + onClicked: root.clicked(index) + } + } + } +} diff --git a/src/settingsui/common/HandwritingModeButton.qml b/src/settingsui/common/HandwritingModeButton.qml new file mode 100644 index 0000000..411892e --- /dev/null +++ b/src/settingsui/common/HandwritingModeButton.qml @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 + +Item { + id: handwritingModeButton + state: "unavailable" + property bool floating + property bool flipable + readonly property real __minWidthHeight: Math.min(width, height) + + signal clicked() + signal doubleClicked() + + Flipable { + id: flipableImage + anchors.fill: parent + + property bool flipped + + front: Image { + sourceSize.width: handwritingModeButton.__minWidthHeight + sourceSize.height: handwritingModeButton.__minWidthHeight + smooth: false + source: "qrc:/icons/FloatingButton_Unavailable.png" + } + + back: Image { + id: buttonImage + sourceSize.width: handwritingModeButton.__minWidthHeight + sourceSize.height: handwritingModeButton.__minWidthHeight + smooth: false + source: "qrc:/icons/FloatingButton_Available.png" + } + + states: State { + PropertyChanges { target: rotation; angle: 180 } + when: flipableImage.flipped + } + + transform: Rotation { + id: rotation + origin.x: flipableImage.width / 2 + origin.y: flipableImage.height / 2 + axis { x: 0; y: 1; z: 0 } + angle: 0 + } + + transitions: Transition { + enabled: handwritingModeButton.flipable + NumberAnimation { target: rotation; property: "angle"; duration: 400 } + } + } + + states: [ + State { + name: "available" + PropertyChanges { target: flipableImage; flipped: true } + }, + State { + name: "active" + PropertyChanges { target: flipableImage; flipped: true } + PropertyChanges { target: buttonImage; source: "qrc:/icons/FloatingButton_Active.png" } + } + ] + + function snapHorizontal() { + if (!floating) + return + if (mouseArea.drag.maximumX > mouseArea.drag.minimumX) { + if (x + 20 >= mouseArea.drag.maximumX) { + anchors.left = undefined + anchors.right = parent.right + } else if (x - 20 <= mouseArea.drag.minimumX) { + anchors.right = undefined + anchors.left = parent.left + } + } + } + + function snapVertical() { + if (!floating) + return + if (mouseArea.drag.maximumY > mouseArea.drag.minimumY) { + if (y + 20 >= mouseArea.drag.maximumY) { + anchors.top = undefined + anchors.bottom = parent.bottom + } else if (y - 20 <= mouseArea.drag.minimumY) { + anchors.bottom = undefined + anchors.top = parent.top + } + } + } + + MouseArea { + id: mouseArea + anchors.fill: parent + drag { + target: handwritingModeButton.floating ? handwritingModeButton : undefined + axis: Drag.XAxis | Drag.YAxis + minimumX: 0 + maximumX: handwritingModeButton.parent.width - handwritingModeButton.width + onMaximumXChanged: !mouseArea.drag.active && handwritingModeButton.snapHorizontal() + minimumY: 0 + maximumY: handwritingModeButton.parent.height - handwritingModeButton.height + onMaximumYChanged: !mouseArea.drag.active && handwritingModeButton.snapVertical() + } + onPressed: { + if (!handwritingModeButton.floating) + return + handwritingModeButton.anchors.left = undefined + handwritingModeButton.anchors.top = undefined + handwritingModeButton.anchors.right = undefined + handwritingModeButton.anchors.bottom = undefined + } + onReleased: { + handwritingModeButton.snapHorizontal() + handwritingModeButton.snapVertical() + } + onClicked: { + handwritingModeButton.snapHorizontal() + handwritingModeButton.snapVertical() + clickTimer.restart() + } + onDoubleClicked: { + clickTimer.stop() + handwritingModeButton.snapHorizontal() + handwritingModeButton.snapVertical() + handwritingModeButton.doubleClicked() + } + Timer { + id: clickTimer + interval: Qt.styleHints ? Qt.styleHints.mouseDoubleClickInterval / 3 : 0 + repeat: false + onTriggered: handwritingModeButton.clicked() + } + } +} diff --git a/src/settingsui/deployment.pri b/src/settingsui/deployment.pri new file mode 100644 index 0000000..696c6f5 --- /dev/null +++ b/src/settingsui/deployment.pri @@ -0,0 +1,27 @@ +android-no-sdk { + target.path = /data/user/qt + export(target.path) + INSTALLS += target +} else:android { + x86 { + target.path = /libs/x86 + } else: armeabi-v7a { + target.path = /libs/armeabi-v7a + } else { + target.path = /libs/armeabi + } + export(target.path) + INSTALLS += target +} else:unix { + isEmpty(target.path) { + qnx { + target.path = /tmp/$${TARGET}/bin + } else { + target.path = $$[QT_INSTALL_BINS] + } + export(target.path) + } + INSTALLS += target +} + +export(INSTALLS) diff --git a/src/settingsui/display/Display.qml b/src/settingsui/display/Display.qml new file mode 100644 index 0000000..450ac41 --- /dev/null +++ b/src/settingsui/display/Display.qml @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.DisplaySettings 1.0 + +Item { + id: root + property string title: qsTr("Display Settings") + property int titleWidth: width * 0.382 + + GroupBox { + title: qsTr("Display Settings") + anchors.margins: 20 + anchors.left: parent.left + anchors.top: parent.top + anchors.right:parent.right + + ColumnLayout { + anchors.fill: parent + + RowLayout { + width: parent.width + spacing: 10 + + Label { + text: qsTr("Brightness:") + Layout.preferredWidth: root.titleWidth + Layout.alignment: Qt.AlignVCenter + horizontalAlignment: Text.AlignRight + } + Slider { + id: brightnessSlider + value: DisplaySettings.displayBrightness + Layout.alignment: Qt.AlignVCenter + Layout.fillWidth: true + from: 0 + to: 255 + } + } + Binding { + target: DisplaySettings + property: "displayBrightness" + value: brightnessSlider.position * brightnessSlider.to + } + GridLayout { + columns: 2 + rows: 3 + rowSpacing: 10 + + Label { + text: qsTr("Physical screen size:") + Layout.preferredWidth: root.titleWidth + Layout.alignment: Qt.AlignVCenter + horizontalAlignment: Text.AlignRight + wrapMode: Label.WordWrap + } + RadioButton { + text: qsTr("Default") + checked: !DisplaySettings.physicalScreenSizeOverride + } + RadioButton { + id: custom + Layout.column: 1 + Layout.row: 1 + text: qsTr("Custom") + checked: DisplaySettings.physicalScreenSizeOverride + onCheckedChanged: DisplaySettings.physicalScreenSizeOverride = checked + } + GroupBox { + title: qsTr("Size (in inches): %1").arg(DisplaySettings.physicalScreenSizeInch) + Layout.column: 1 + Layout.row: 2 + Layout.fillWidth: true + visible: custom.checked + + RowLayout { + spacing: 10 + width: parent.width + + Label { + text: sizeSlider.from + Layout.alignment: Qt.AlignVCenter + } + Slider { + id: sizeSlider + value: DisplaySettings.physicalScreenSizeInch + Layout.fillWidth: true + stepSize: 1 + from: 4 + to: 60 + onPositionChanged: DisplaySettings.physicalScreenSizeInch = sizeSlider.from + Math.floor(sizeSlider.position * (sizeSlider.to - sizeSlider.from)) + } + Label { + text: sizeSlider.to + Layout.alignment: Qt.AlignVCenter | Qt.AlignRight + } + } + } + } + } + } +} diff --git a/src/settingsui/locale/Language.qml b/src/settingsui/locale/Language.qml new file mode 100644 index 0000000..d4257c3 --- /dev/null +++ b/src/settingsui/locale/Language.qml @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.LocaleSettings 1.0 +import QtQml 2.2 + +Item { + id: root + property string title: qsTr("Language and Region") + + GroupBox { + id: groupBox + title: qsTr("Regional Format") + anchors.left: parent.left + anchors.top: parent.top + anchors.right: parent.right + anchors.margins: 20 + property var currentRegion: Qt.locale(LocaleManager.locale) + + ColumnLayout { + width: parent.width + + Component { + id: regionSelect + RegionSelect {} + } + GroupBox { + width: parent.width + title: { + if (groupBox.currentRegion.name === "C" || groupBox.currentRegion.name === "POSIX") { + return qsTr("Default"); + } + else if (groupBox.currentRegion.name !== "") { + return qsTr("%L1/%L2").arg(groupBox.currentRegion.nativeLanguageName).arg(groupBox.currentRegion.nativeCountryName) + } + else { + return qsTr("Region not set"); + } + } + ColumnLayout { + spacing: 10 + Layout.fillWidth: true + width: parent.width + + Label { + text: Date().toLocaleString(groupBox.currentRegion) + } + Label { + text: Number(2343.34).toLocaleString(groupBox.currentRegion) + } + Label { + text: Number(41334.34).toLocaleCurrencyString(groupBox.currentRegion) + } + } + } + Button { + text: qsTr("Change region") + onClicked: stackView.push(regionSelect) + } + } + } +} diff --git a/src/settingsui/locale/RegionSelect.qml b/src/settingsui/locale/RegionSelect.qml new file mode 100644 index 0000000..89042b6 --- /dev/null +++ b/src/settingsui/locale/RegionSelect.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.LocaleSettings 1.0 +import "../common" + +Item { + id: root + property string title: qsTr("Select language") + + Component.onCompleted: country.text = LocaleFilter.filter + + ColumnLayout { + id: content + anchors.fill: parent + anchors.margins: 20 + spacing: 10 + RowLayout { + spacing: 10 + + Label { + text: qsTr("Search region: ") + Layout.alignment: Qt.AlignVCenter + } + TextField { + id: country + text: "" + onTextChanged: LocaleFilter.filter = country.text + Layout.alignment: Qt.AlignVCenter + } + } + CustomTableView { + headerTexts: [qsTr("Language"), qsTr("Country")] + roleNames: ["language", "country"] + model: LocaleFilter + onClicked: { + var val = model.itemFromRow(index); + if (val !== "") { + LocaleManager.locale = val; + stackView.pop(); + } + } + } + } +} diff --git a/src/settingsui/main.cpp b/src/settingsui/main.cpp new file mode 100644 index 0000000..40e4428 --- /dev/null +++ b/src/settingsui/main.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/src/settingsui/main.qml b/src/settingsui/main.qml new file mode 100644 index 0000000..874e0eb --- /dev/null +++ b/src/settingsui/main.qml @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Window 2.2 +import QtDeviceUtilities.SettingsUI 1.0 +import QtQuick.VirtualKeyboard 2.0 +import "common" + +Window { + id: window + visible: true + + Item { + id: root + anchors.fill: parent + + SettingsUI { + id: settingsUI + anchors.fill: parent + anchors.bottomMargin: parent.height - inputPanel.y + } + + /* Handwriting input panel for full screen handwriting input. + + This component is an optional add-on for the InputPanel component, that + is, its use does not affect the operation of the InputPanel component, + but it also can not be used as a standalone component. + + The handwriting input panel is positioned to cover the entire area of + application. The panel itself is transparent, but once it is active the + user can draw handwriting on it. + */ + + HandwritingInputPanel { + z: 79 + id: handwritingInputPanel + anchors.fill: parent + inputPanel: inputPanel + Rectangle { + z: -1 + anchors.fill: parent + color: "black" + opacity: 0.10 + } + } + + /* Container area for the handwriting mode button. + + Handwriting mode button can be moved freely within the container area. + In this example, a single click changes the handwriting mode and a + double-click changes the availability of the full screen handwriting input. + */ + Item { + z: 89 + visible: handwritingInputPanel.enabled && Qt.inputMethod.visible + anchors { left: parent.left; top: parent.top; right: parent.right; bottom: inputPanel.top; } + HandwritingModeButton { + id: handwritingModeButton + anchors.top: parent.top + anchors.right: parent.right + anchors.margins: 10 + floating: true + flipable: true + width: 76 + height: width + state: handwritingInputPanel.state + onClicked: handwritingInputPanel.active = !handwritingInputPanel.active + onDoubleClicked: handwritingInputPanel.available = !handwritingInputPanel.available + } + } + + /* Keyboard input panel. + The keyboard is anchored to the bottom of the application. + */ + InputPanel { + id: inputPanel + z: 99 + y: root.height + anchors.left: root.left + anchors.right: root.right + + states: State { + name: "visible" + /* The visibility of the InputPanel can be bound to the Qt.inputMethod.visible property, + but then the handwriting input panel and the keyboard input panel can be visible + at the same time. Here the visibility is bound to InputPanel.active property instead, + which allows the handwriting panel to control the visibility when necessary. + */ + when: inputPanel.active + PropertyChanges { + target: inputPanel + y: root.height - inputPanel.height + } + } + transitions: Transition { + from: "" + to: "visible" + reversible: true + ParallelAnimation { + NumberAnimation { + properties: "y" + duration: 250 + easing.type: Easing.InOutQuad + } + } + } + AutoScroller {} + } + } +} diff --git a/src/settingsui/network/AddressListEntry.qml b/src/settingsui/network/AddressListEntry.qml new file mode 100644 index 0000000..9612778 --- /dev/null +++ b/src/settingsui/network/AddressListEntry.qml @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 + +RowLayout { + id: root + spacing: 10 + property alias model: repeater.model + property bool modified: false + property alias title: label.text + + Label { + id: label + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + Layout.alignment: Qt.AlignTop + Layout.topMargin: 10 + } + ColumnLayout { + spacing: 10 + Layout.fillWidth: true + + Repeater { + id: repeater + visible: count > 0 + RowLayout { + spacing: 10 + TextField { + text: edit + Layout.fillWidth: true + onEditingFinished: { + root.modified = true; + edit = text; + } + } + Button { + Layout.preferredWidth: height + text: "-" + visible: repeater.count > 0 + onClicked: { + root.modified = true; + root.model.remove(index); + } + } + Button { + Layout.preferredWidth: height + visible: index === repeater.count - 1 + text: "+" + onClicked: root.model.append("") + + Layout.alignment: Qt.AlignRight + } + } + } + RowLayout { + visible: repeater.count === 0 + spacing: 10 + TextField { + id: nameServerEntryItem + Layout.fillWidth: true + text: "" + onAccepted: root.model.append(text) + } + Button { + Layout.preferredWidth: height + text: "+" + onClicked: nameServerEntryItem.accepted() + } + } + } +} diff --git a/src/settingsui/network/ComboBoxEntry.qml b/src/settingsui/network/ComboBoxEntry.qml new file mode 100644 index 0000000..71b997c --- /dev/null +++ b/src/settingsui/network/ComboBoxEntry.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 + +RowLayout { + id: root + spacing: 10 + width: parent.width + + property alias title: label.text + property alias currentIndex: cb.currentIndex + property alias delegate: cb.delegate + property alias textRole: cb.textRole + property alias model: cb.model + property alias count: cb.count + property int titleWidth: -1 + + Label { + id: label + Layout.preferredWidth: root.titleWidth + horizontalAlignment: Text.AlignRight + Layout.alignment: Qt.AlignVCenter + } + ComboBox { + id: cb + textRole: "text" + Layout.fillWidth: true + } +} diff --git a/src/settingsui/network/EditWiredSettings.qml b/src/settingsui/network/EditWiredSettings.qml new file mode 100644 index 0000000..97f04dd --- /dev/null +++ b/src/settingsui/network/EditWiredSettings.qml @@ -0,0 +1,363 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.NetworkSettings 1.0 + +Item { + id: root + property string title: qsTr("Ethernet Settings") + property var service: undefined + property bool ipv4Changed: false + property bool ipv6Changed: false + property bool nameserversChanged: false + property bool domainsChanged: false + property bool proxyChanged: false + + Component.onDestruction: { + //Clear all unsaved changes from models + service.proxy.excludes.resetChanges(); + service.nameservers.resetChanges(); + service.domains.resetChanges(); + } + + Component.onCompleted: titlebar.title = service.name; + + Flickable { + anchors.fill: parent + anchors.top: saveButton.bottom + anchors.margins: 20 + contentHeight: content.height + contentWidth: width + + Column { + id: content + width: parent.width + spacing: 10 + property int titleWidth: width * 0.382 + property int groupWidth: width - saveButton.width - 10 + + //IPv4 Config + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("IPv4") + + ColumnLayout { + anchors.fill: parent + + ComboBoxEntry { + title: qsTr("Connection method:") + titleWidth: content.titleWidth + model: ListModel { + id: methodsModel + + ListElement { + text: "DHCP" + method: NetworkSettingsIPv4.Dhcp + } + ListElement { + text: "Manual" + method: NetworkSettingsIPv4.Manual + } + ListElement { + text: "Off" + method: NetworkSettingsIPv4.Off + } + } + Component.onCompleted: currentIndex = service.ipv4.method + onCurrentIndexChanged: { + ipv4Changed = true; + service.ipv4.method = model.get(currentIndex).method; + } + } + + GridLayout { + columnSpacing: 10 + rows: 3 + columns: 2 + visible: service.ipv4.method !== NetworkSettingsIPv4.Off + width: parent.width + + Label { + text: qsTr("Address:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Address + text: service.ipv4.address + onTextChanged: ipv4Changed = true; + onAccepted: if (text.length > 0) service.ipv4.address = text + enabled: service.ipv4.method === NetworkSettingsIPv4.Manual + } + Label { + text: qsTr("Mask:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Mask + text: service.ipv4.mask + onTextChanged: ipv4Changed = true; + onAccepted: if (text.length > 0) service.ipv4.mask = text + enabled: service.ipv4.method === NetworkSettingsIPv4.Manual + } + Label { + text: qsTr("Router:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Gateway + text: service.ipv4.gateway + onTextChanged: ipv4Changed = true + onAccepted: if (text.length > 0) service.ipv4.gateway = text + enabled: service.ipv4.method === NetworkSettingsIPv4.Manual + } + } + } + } + + //IPv6 Config + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("IPv6") + + ColumnLayout { + anchors.fill: parent + + ComboBoxEntry { + title: qsTr("Connection method:") + titleWidth: content.titleWidth + model: ListModel { + id: ipv6methodsmodel + + ListElement { + text: qsTr("Auto") + method: NetworkSettingsIPv6.Auto + } + ListElement { + text: qsTr("Manual") + method: NetworkSettingsIPv6.Manual + } + ListElement { + text: qsTr("Off") + method: NetworkSettingsIPv6.Off + } + } + + Component.onCompleted: currentIndex = service.ipv6.method + + onCurrentIndexChanged: { + ipv6Changed = true; + service.ipv6.method = model.get(currentIndex).method; + } + } + GridLayout { + columnSpacing: 10 + rows: 3 + columns: 2 + visible: service.ipv6.method !== NetworkSettingsIPv6.Off + + Label { + text: qsTr("Address:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6Address + text: service.ipv6.address + Layout.fillWidth: true + onTextChanged: ipv6Changed = true; + onAccepted: if (text.length > 0) service.ipv6.address = text + enabled: service.ipv6.method === NetworkSettingsIPv6.Manual + } + Label { + text: qsTr("Router:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6Gateway + text: service.ipv6.gateway + Layout.fillWidth: true + onTextChanged: ipv6Changed = true; + onAccepted: if (text.length > 0) service.ipv4.gateway = text + enabled: service.ipv6.method === NetworkSettingsIPv6.Manual + } + Label { + text: qsTr("Prefix length:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6PrefixLength + text: service.ipv6.prefixLength + Layout.fillWidth: true + validator: IntValidator { bottom: 0; top: 255 } + onTextChanged: ipv6Changed = true + onAccepted: if (text.length > 0) service.ipv6.prefixLength = parseInt(text) + enabled: service.ipv6.method === NetworkSettingsIPv6.Manual + } + } + } + } + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Name servers") + + ColumnLayout { + anchors.fill: parent + AddressListEntry { + title: qsTr("Address:") + model: service.nameservers + modified: nameserversChanged + } + } + } + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Domains") + + ColumnLayout { + anchors.fill: parent + AddressListEntry { + title: qsTr("Address:") + model: service.domains + modified: domainsChanged + } + } + } + GroupBox { + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Proxy Settings") + + ColumnLayout { + id: proxyLayout + width: parent.width + + ComboBoxEntry { + title: qsTr("Configuration:") + titleWidth: content.titleWidth + model: ListModel { + id: proxyMethodModel + + ListElement { + text: qsTr("Direct") + method: NetworkSettingsProxy.Direct + } + ListElement { + text: qsTr("Auto") + method: NetworkSettingsProxy.Auto + } + ListElement { + text: qsTr("Manual") + method: NetworkSettingsProxy.Manual + } + } + Component.onCompleted: currentIndex = service.proxy.method + + onCurrentIndexChanged: { + proxyChanged = true; + service.proxy.method = model.get(currentIndex).method; + } + } + RowLayout { + spacing: 10 + visible: service.proxy.method !== NetworkSettingsProxy.Direct + + Label { + text: service.proxy.method === NetworkSettingsProxy.Manual ? qsTr("Proxy address:") : qsTr("Configuration URL:") + Layout.preferredWidth: content.titleWidth + horizontalAlignment: Text.AlignRight + Layout.alignment: Qt.AlignVCenter + elide: Label.ElideRight + } + TextField { + id: proxyUrl + text: service.proxy.url + Layout.fillWidth: true + onTextChanged: proxyChanged = true; + onAccepted: service.proxy.url = text; + } + } + AddressListEntry { + model: service.proxy.excludes + modified: proxyChanged + title: qsTr("No proxy for:") + visible: service.proxy.method === NetworkSettingsProxy.Manual + } + } + } + } + } + Button { + id: saveButton + anchors.right: parent.right + anchors.top: parent.top + anchors.margins: 20 + text: qsTr("Save") + + onClicked: { + if (ipv4Changed) { + ipv4Address.accepted(); + ipv4Mask.accepted(); + ipv4Gateway.accepted(); + service.setupIpv4Config(); + } + + if (ipv6Changed) { + ipv6Address.accepted(); + ipv6Gateway.accepted(); + ipv6PrefixLength.accepted(); + service.setupIpv6Config(); + } + + if (nameserversChanged) { + service.setupNameserversConfig(); + } + + if (domainsChanged) { + service.setupDomainsConfig(); + } + + if (proxyChanged) { + proxyUrl.accepted(); + service.setupNetworkSettingsProxy(); + } + stackView.pop(); + } + } +} diff --git a/src/settingsui/network/IpAddressTextField.qml b/src/settingsui/network/IpAddressTextField.qml new file mode 100644 index 0000000..dcf8771 --- /dev/null +++ b/src/settingsui/network/IpAddressTextField.qml @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 + +TextField { + Layout.fillWidth: true + validator: RegExpValidator { regExp: /^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/ } +} diff --git a/src/settingsui/network/NetworkDetails.qml b/src/settingsui/network/NetworkDetails.qml new file mode 100644 index 0000000..6e9ee4c --- /dev/null +++ b/src/settingsui/network/NetworkDetails.qml @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 + +Loader { + id: root + property var selectedInterface:undefined + anchors.fill: parent +} diff --git a/src/settingsui/network/NetworkSettings.qml b/src/settingsui/network/NetworkSettings.qml new file mode 100644 index 0000000..52ab1af --- /dev/null +++ b/src/settingsui/network/NetworkSettings.qml @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.NetworkSettings 1.0 + +Item { + property string title: qsTr("Network Settings") + GroupBox { + id: networkSelect + anchors.rightMargin: parent.width * 0.618 + anchors.leftMargin: 20 + anchors.topMargin: 20 + anchors.bottomMargin: 20 + anchors.fill: parent + title: qsTr("Select Connection") + + function stateToStr(serviceState) { + switch (serviceState) { + case NetworkService.Idle: + return qsTr("Idle"); + case NetworkService.Failure: + return qsTr("Failure"); + case NetworkService.Association: + return qsTr("Association"); + case NetworkService.Configuration: + return qsTr("Configuration"); + case NetworkService.Ready: + return qsTr("Ready"); + case NetworkService.Disconnect: + return qsTr("Disconnect"); + case NetworkService.Online: + return qsTr("Online"); + default: + return qsTr("Undefined"); + } + } + ColumnLayout { + width: parent.width + + Repeater { + model: NetworkSettingsManager.interfaces + + RadioButton { + id: btn + Layout.fillWidth: true + implicitHeight: 54 + + contentItem: Rectangle { + color: checked ? "#80c342" : "white" + border.color: "#bdbebf" + border.width: 1 + anchors.fill: parent + + Row { + anchors.fill: parent + spacing: 10 + + Image { + id: typeId + height: parent.height + width: height + } + Column { + height: parent.height * .7 + spacing: 0 + anchors.verticalCenter: parent.verticalCenter + Label { + text: name + } + Label { + text: networkSelect.stateToStr(modelData.state) + font.pixelSize: 12 + } + } + } + } + + onCheckedChanged: { + if (checked) { + networkDetails.selectedInterface = modelData + networkDetails.selectedInterface.scanServices() + if (type === NetworkSettingsType.Wired) { + networkDetails.source = "WiredSettings.qml"; + } + else if (type === NetworkSettingsType.Wifi) { + networkDetails.source = "WifiSettings.qml"; + } + } + } + } + } + } + } + + NetworkDetails { + id: networkDetails + anchors.leftMargin: networkSelect.width + 40 + anchors.topMargin: 20 + anchors.rightMargin: 20 + anchors.bottomMargin: 20 + anchors.fill: parent + } +} diff --git a/src/settingsui/network/WifiSelectorDelegate.qml b/src/settingsui/network/WifiSelectorDelegate.qml new file mode 100644 index 0000000..ea044f6 --- /dev/null +++ b/src/settingsui/network/WifiSelectorDelegate.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.NetworkSettings 1.0 + +ItemDelegate { + id: root + autoExclusive: true + property bool connect: connected + contentItem: Item { + width: root.width + + Label { + id: text + leftPadding: root.spacing + anchors.left: parent.left + anchors.top:parent.top + anchors.right: signalMonitor.left + anchors.bottom:parent.bottom + elide: Text.ElideRight + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + text: modelData["name"] + } + WifiSignalMonitor { + id: signalMonitor + anchors.right: parent.right + height: parent.height + width: height + signalStrength: modelData.wirelessConfig["signalStrength"] + connected: connected + } + } +} diff --git a/src/settingsui/network/WifiSettings.qml b/src/settingsui/network/WifiSettings.qml new file mode 100644 index 0000000..7a0735c --- /dev/null +++ b/src/settingsui/network/WifiSettings.qml @@ -0,0 +1,238 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.NetworkSettings 1.0 + +Item { + id: root + anchors.fill: parent + Component.onCompleted: NetworkSettingsManager.services.type = NetworkSettingsType.Wifi; + property bool connecting: false + + GroupBox { + id: content + title: qsTr("Wireless Settings") + anchors.fill: parent + + ColumnLayout { + spacing: 20 + width: parent.width + + RowLayout { + spacing: 10 + id: enableSwitch + width: parent.width + + Label { + Layout.preferredWidth: root.width * 0.382 + Layout.alignment: Qt.AlignVCenter + horizontalAlignment: Text.AlignRight + text: selectedInterface.powered ? qsTr("Wi-Fi ON") : qsTr("Wi-Fi OFF") + } + Switch { + checked: selectedInterface.powered + onCheckedChanged: { + selectedInterface.powered = checked + root.connecting = false + connectView.visible = false + } + } + } + RowLayout { + spacing: 10 + width: parent.width + + visible: selectedInterface.powered && networkSelection.count > 0 + Label { + Layout.preferredWidth: root.width * 0.382 + text: qsTr("Current network") + horizontalAlignment: Text.AlignRight + Layout.alignment: Qt.AlignVCenter + + } + ComboBoxEntry { + id: networkSelection + model: NetworkSettingsManager.services + + textRole: "name" + Layout.fillWidth: true + onCurrentIndexChanged: { + if (currentIndex >= 0) { + connectView.visible = false + + var service = model.itemFromRow(currentIndex) + if (service) { + root.connecting = true + service.connectService(); + } + } + } + + onCountChanged: { + if (count === 0) { + root.connecting = false + connectView.visible = false + } + } + + delegate: WifiSelectorDelegate { + width: networkSelection.width + onConnectChanged: if (connect) networkSelection.currentIndex = index + } + } + } + + Row { + id: infoRow + spacing: 10 + width: parent.width + visible: selectedInterface.powered && selectedInterface.state !== NetworkSettingsState.Online && (networkSelection.count == 0 || root.connecting) + Label { + id: scanningText + text: root.connecting ? qsTr("Connecting to the network...") : qsTr("Searching for Wi-Fi networks...") + horizontalAlignment: Text.AlignLeft + } + WifiSignalMonitor { + id: scanningIcon + scanning: true + height: scanningText.height + width: height + } + } + + GroupBox { + id: connectView + title: qsTr("Enter a password") + visible: false + Layout.fillWidth: true + ColumnLayout { + width: parent.width + + RowLayout { + id: errorView + visible: text.text !== "" + spacing: 10 + property alias text: text.text + + Image { + source: "../icons/Alert_yellow_1x.png" + Layout.alignment: Qt.AlignVCenter + } + Text { + id: text + color: "#face20" + text: "" + Layout.alignment: Qt.AlignVCenter + } + } + RowLayout { + spacing: 10 + visible: false + width: parent.width + + Label { + text: qsTr("User name:") + horizontalAlignment: Text.AlignRight + Layout.preferredWidth: root.width * 0.382 + Layout.alignment: Qt.AlignVCenter + } + TextField { + text: "" + inputMethodHints: Qt.ImhNoPredictiveText + Layout.alignment: Qt.AlignVCenter + Layout.fillWidth: true + } + } + RowLayout { + spacing: 10 + width: parent.width + + Label { + text: qsTr("Password:") + horizontalAlignment: Text.AlignRight + Layout.preferredWidth: root.width * 0.382 + Layout.alignment: Qt.AlignVCenter + } + TextField { + id: password + text: "" + echoMode: TextInput.Password + inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase | Qt.ImhPreferLowercase | Qt.ImhSensitiveData + Layout.alignment: Qt.AlignVCenter + Layout.fillWidth: true + } + } + RowLayout { + spacing: 10 + + Button { + text: qsTr("Connect") + onClicked: { + connectView.visible = false + NetworkSettingsManager.userAgent.setUserCredentials("", password.text) + } + } + Button { + text: qsTr("Cancel") + onClicked: { + networkSelection.currentIndex = -1 + connectView.visible = false + } + } + } + } + } + Button { + id: disconnect + text: qsTr("Disconnect") + visible: selectedInterface.state === NetworkSettingsState.Online || + selectedInterface.state === NetworkSettingsState.Ready + onClicked: { + console.log("disconnect"); + NetworkSettingsManager.services.itemFromRow(networkSelection.selectedIndex).disconnectService(); + networkSelection.selectedIndex = -1; + } + } + } + Connections { + target: NetworkSettingsManager.userAgent + onShowUserCredentialsInput : { + connectView.visible = true + root.connecting = false + } + onError: { + errorView.visible = true + connectView.visible = true + root.connecting = false + } + } + } +} diff --git a/src/settingsui/network/WifiSignalMonitor.qml b/src/settingsui/network/WifiSignalMonitor.qml new file mode 100644 index 0000000..06afca4 --- /dev/null +++ b/src/settingsui/network/WifiSignalMonitor.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 + +Item { + id: root + property bool scanning: false + property int signalStrength: 100 + property bool connected: false + + onSignalStrengthChanged: { + sprite.visible = true; + + if (signalStrength < 10) { + sprite.visible = false; + } + else if (signalStrength < 30) { + sprite.currentFrame = 0; + } + else if (signalStrength < 60) { + sprite.currentFrame = 1; + } + else if (signalStrength < 80) { + sprite.currentFrame = 2; + } + else if (signalStrength <= 100) { + sprite.currentFrame = 3; + } + } + + Image { + id: sprite + property int currentFrame: 0 + anchors.fill: parent + source: "../icons/Wifi_lightgray_2x.png" + clip: true + + Timer { + id: scanningTimer + running: scanning + interval: 250 + repeat: true + onTriggered: { + if (sprite.currentFrame < 4) + sprite.currentFrame++ + else + sprite.currentFrame = 0 + } + } + + Image { + height: parent.height + width: parent.width * 4 + source: "../icons/WifiAnim_black_2x.png" + x: -parent.currentFrame * width / 4 + } + } +} diff --git a/src/settingsui/network/WiredSettings.qml b/src/settingsui/network/WiredSettings.qml new file mode 100644 index 0000000..c55d2b7 --- /dev/null +++ b/src/settingsui/network/WiredSettings.qml @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.NetworkSettings 1.0 + +Item { + id: root + anchors.fill: parent + property bool editMode: false + property var service: null + property string title: qsTr("Network"); + + Component.onCompleted: { + NetworkSettingsManager.services.type = NetworkSettingsType.Wired; + root.service = NetworkSettingsManager.services.itemFromRow(0); + ipv4Method.currentIndex = service.ipv4.method + } + + GroupBox { + title: qsTr("Ethernet Connection") + anchors.fill: parent + + Column { + spacing: 10 + width: parent.width + + ComboBoxEntry { + id: ipv4Method + title: qsTr("Connection method:") + model: ListModel { + id: methodsModel + + ListElement { + text: "DHCP" + method: NetworkSettingsIPv4.Dhcp + } + ListElement { + text: "Manual" + method: NetworkSettingsIPv4.Manual + } + ListElement { + text: "Off" + method: NetworkSettingsIPv4.Off + } + } + + Component.onCompleted: currentIndex = service.ipv4.method + onCurrentIndexChanged: { + if (model.get(currentIndex).method !== NetworkSettingsIPv4.Dhcp) { + service.ipv4.method = model.get(currentIndex).method; + editMode = true; + } + else if (service){ + //Enable DHCP + if (service.ipv4.method !== model.get(currentIndex).method) { + service.ipv4.method = model.get(currentIndex).method; + service.setupIpv4Config(); + } + editMode = false; + } + } + } + GridLayout { + columns: 2 + rows: 4 + width: parent.width + visible: service.ipv4.method !== NetworkSettingsIPv4.Off + + Label { + text: qsTr("IP Address: ") + width: parent.width * .3 + } + IpAddressTextField { + id: ipv4Address + text: service.ipv4.address + enabled: editMode + onAccepted: if (text.length > 0) service.ipv4.address = text + } + Label { + text: qsTr("Mask: ") + } + IpAddressTextField { + id: ipv4Mask + text: service.ipv4.mask + enabled: editMode + onAccepted: if (text.length > 0) service.ipv4.mask = text + } + Label { + text: qsTr("Router: ") + } + IpAddressTextField { + id: ipv4Gateway + text: service.ipv4.gateway + enabled: editMode + onAccepted: if (text.length > 0) service.ipv4.gateway = text + } + Label { + Layout.alignment: Qt.AlignTop + text: qsTr("DNS server: ") + } + Column { + spacing: 10 + Layout.fillWidth: true + Layout.alignment: Qt.AlignTop + + Repeater { + model: service.nameservers + + Label { + text: display + } + } + } + } + Row { + spacing: 10 + Button { + text: qsTr("Save") + visible: editMode + + onClicked: { + ipv4Address.accepted(); + ipv4Mask.accepted(); + ipv4Gateway.accepted(); + service.setupIpv4Config(); + editMode = false; + } + } + Button { + text: qsTr("Cancel") + visible: editMode + onClicked: { + editMode = false; + ipv4Method.currentIndex = service.ipv4.method + } + } + } + Button { + text: qsTr("Edit") + visible: !editMode + onClicked: stackView.push(Qt.resolvedUrl("EditWiredSettings.qml"), {service: root.service}); + } + } + } +} diff --git a/src/settingsui/settingsui.pro b/src/settingsui/settingsui.pro new file mode 100644 index 0000000..51b6dca --- /dev/null +++ b/src/settingsui/settingsui.pro @@ -0,0 +1,13 @@ +TEMPLATE = app + +QT += qml quick +SOURCES += main.cpp + +RESOURCES += \ + settingsuiapp.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Default rules for deployment. +include(deployment.pri) diff --git a/src/settingsui/settingsuiapp.qrc b/src/settingsui/settingsuiapp.qrc new file mode 100644 index 0000000..58687e0 --- /dev/null +++ b/src/settingsui/settingsuiapp.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>common/HandwritingModeButton.qml</file> + <file>AutoScroller.qml</file> + </qresource> +</RCC> diff --git a/src/settingsui/settingsuiplugin/icons.qrc b/src/settingsui/settingsuiplugin/icons.qrc new file mode 100644 index 0000000..88bdeac --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons.qrc @@ -0,0 +1,34 @@ +<RCC> + <qresource prefix="/"> + <file>icons/Alert_yellow_1x.png</file> + <file>icons/Audio_qt_6x.png</file> + <file>icons/Bluetooth_qt_1x.png</file> + <file>icons/Bluetooth_qt_6x.png</file> + <file>icons/Camcorder_qt_1x.png</file> + <file>icons/Camera_qt_1x.png</file> + <file>icons/Clock_qt_1x.png</file> + <file>icons/Clock_qt_6x.png</file> + <file>icons/Display_qt_6x.png</file> + <file>icons/Flag_qt_6x.png</file> + <file>icons/FloatingButton_Active.png</file> + <file>icons/FloatingButton_Available.png</file> + <file>icons/FloatingButton_Unavailable.png</file> + <file>icons/Headphones_qt_1x.png</file> + <file>icons/Heartbeat_qt_1x.png</file> + <file>icons/Keyboard_qt_1x.png</file> + <file>icons/Laptop_qt_1x.png</file> + <file>icons/Microphone_qt_1x.png</file> + <file>icons/MobilePhone_qt_1x.png</file> + <file>icons/Mouse_qt_1x.png</file> + <file>icons/Tablet_qt_1x.png</file> + <file>icons/Volume_down_qt_1x.png</file> + <file>icons/Volume_mute_qt_1x.png</file> + <file>icons/Volume_up_qt_1x.png</file> + <file>icons/WifiAnim_black_2x.png</file> + <file>icons/Wifi_lightgray_2x.png</file> + <file>icons/World_qt_6x.png</file> + <file>icons/Chevron-left_black_6x.png</file> + <file>icons/Chevron-left_black.png</file> + <file>icons/Power_black_6x.png</file> + </qresource> +</RCC> diff --git a/src/settingsui/settingsuiplugin/icons/Alert_yellow_1x.png b/src/settingsui/settingsuiplugin/icons/Alert_yellow_1x.png Binary files differnew file mode 100644 index 0000000..6fd25cb --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Alert_yellow_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Audio_qt_6x.png b/src/settingsui/settingsuiplugin/icons/Audio_qt_6x.png Binary files differnew file mode 100644 index 0000000..a33b286 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Audio_qt_6x.png diff --git a/src/settingsui/settingsuiplugin/icons/Bluetooth_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Bluetooth_qt_1x.png Binary files differnew file mode 100644 index 0000000..d9378b4 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Bluetooth_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Bluetooth_qt_6x.png b/src/settingsui/settingsuiplugin/icons/Bluetooth_qt_6x.png Binary files differnew file mode 100644 index 0000000..87d80cd --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Bluetooth_qt_6x.png diff --git a/src/settingsui/settingsuiplugin/icons/Camcorder_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Camcorder_qt_1x.png Binary files differnew file mode 100644 index 0000000..79db562 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Camcorder_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Camera_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Camera_qt_1x.png Binary files differnew file mode 100644 index 0000000..0b831c5 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Camera_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Chevron-left_black.png b/src/settingsui/settingsuiplugin/icons/Chevron-left_black.png Binary files differnew file mode 100644 index 0000000..0ebc3f4 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Chevron-left_black.png diff --git a/src/settingsui/settingsuiplugin/icons/Chevron-left_black_6x.png b/src/settingsui/settingsuiplugin/icons/Chevron-left_black_6x.png Binary files differnew file mode 100644 index 0000000..c1a8cff --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Chevron-left_black_6x.png diff --git a/src/settingsui/settingsuiplugin/icons/Clock_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Clock_qt_1x.png Binary files differnew file mode 100644 index 0000000..d4b220d --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Clock_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Clock_qt_6x.png b/src/settingsui/settingsuiplugin/icons/Clock_qt_6x.png Binary files differnew file mode 100644 index 0000000..b351887 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Clock_qt_6x.png diff --git a/src/settingsui/settingsuiplugin/icons/Display_qt_6x.png b/src/settingsui/settingsuiplugin/icons/Display_qt_6x.png Binary files differnew file mode 100644 index 0000000..89d1845 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Display_qt_6x.png diff --git a/src/settingsui/settingsuiplugin/icons/Flag_qt_6x.png b/src/settingsui/settingsuiplugin/icons/Flag_qt_6x.png Binary files differnew file mode 100644 index 0000000..32212da --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Flag_qt_6x.png diff --git a/src/settingsui/settingsuiplugin/icons/FloatingButton_Active.png b/src/settingsui/settingsuiplugin/icons/FloatingButton_Active.png Binary files differnew file mode 100755 index 0000000..9b55146 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/FloatingButton_Active.png diff --git a/src/settingsui/settingsuiplugin/icons/FloatingButton_Available.png b/src/settingsui/settingsuiplugin/icons/FloatingButton_Available.png Binary files differnew file mode 100755 index 0000000..1479881 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/FloatingButton_Available.png diff --git a/src/settingsui/settingsuiplugin/icons/FloatingButton_Unavailable.png b/src/settingsui/settingsuiplugin/icons/FloatingButton_Unavailable.png Binary files differnew file mode 100755 index 0000000..33aa87d --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/FloatingButton_Unavailable.png diff --git a/src/settingsui/settingsuiplugin/icons/Headphones_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Headphones_qt_1x.png Binary files differnew file mode 100644 index 0000000..da86427 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Headphones_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Heartbeat_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Heartbeat_qt_1x.png Binary files differnew file mode 100644 index 0000000..9599158 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Heartbeat_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Keyboard_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Keyboard_qt_1x.png Binary files differnew file mode 100644 index 0000000..5911e06 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Keyboard_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Laptop_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Laptop_qt_1x.png Binary files differnew file mode 100644 index 0000000..4708259 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Laptop_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Microphone_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Microphone_qt_1x.png Binary files differnew file mode 100644 index 0000000..9182212 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Microphone_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/MobilePhone_qt_1x.png b/src/settingsui/settingsuiplugin/icons/MobilePhone_qt_1x.png Binary files differnew file mode 100644 index 0000000..50fcc0a --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/MobilePhone_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Mouse_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Mouse_qt_1x.png Binary files differnew file mode 100644 index 0000000..a1eefe5 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Mouse_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Power_black_6x.png b/src/settingsui/settingsuiplugin/icons/Power_black_6x.png Binary files differnew file mode 100644 index 0000000..d6add07 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Power_black_6x.png diff --git a/src/settingsui/settingsuiplugin/icons/Tablet_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Tablet_qt_1x.png Binary files differnew file mode 100644 index 0000000..1d0bc4f --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Tablet_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Volume_down_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Volume_down_qt_1x.png Binary files differnew file mode 100644 index 0000000..05c2ce4 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Volume_down_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Volume_mute_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Volume_mute_qt_1x.png Binary files differnew file mode 100644 index 0000000..ca14213 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Volume_mute_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/Volume_up_qt_1x.png b/src/settingsui/settingsuiplugin/icons/Volume_up_qt_1x.png Binary files differnew file mode 100644 index 0000000..08f6221 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Volume_up_qt_1x.png diff --git a/src/settingsui/settingsuiplugin/icons/WifiAnim_black_2x.png b/src/settingsui/settingsuiplugin/icons/WifiAnim_black_2x.png Binary files differnew file mode 100644 index 0000000..c2dc8c5 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/WifiAnim_black_2x.png diff --git a/src/settingsui/settingsuiplugin/icons/Wifi_lightgray_2x.png b/src/settingsui/settingsuiplugin/icons/Wifi_lightgray_2x.png Binary files differnew file mode 100644 index 0000000..b71b22e --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/Wifi_lightgray_2x.png diff --git a/src/settingsui/settingsuiplugin/icons/World_qt_6x.png b/src/settingsui/settingsuiplugin/icons/World_qt_6x.png Binary files differnew file mode 100644 index 0000000..2aee655 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/World_qt_6x.png diff --git a/src/settingsui/settingsuiplugin/icons/generate_icons.sh b/src/settingsui/settingsuiplugin/icons/generate_icons.sh new file mode 100755 index 0000000..55867b8 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/generate_icons.sh @@ -0,0 +1,27 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash +# +# This script resizes and sets correct brand colors for the icons in ref folder +# + +./scripts/cimages.sh ./ref/*.png +./scripts/cimage.sh ./ref/extra/Alert.png red +./scripts/cimage.sh ./ref/extra/Alert.png yellow +./scripts/rimages.sh *.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Audio.png b/src/settingsui/settingsuiplugin/icons/ref/Audio.png Binary files differnew file mode 100644 index 0000000..8434f0a --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Audio.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Back.png b/src/settingsui/settingsuiplugin/icons/ref/Back.png Binary files differnew file mode 100644 index 0000000..9029fd0 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Back.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Bluetooth.png b/src/settingsui/settingsuiplugin/icons/ref/Bluetooth.png Binary files differnew file mode 100644 index 0000000..e7c80a9 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Bluetooth.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Camcorder.png b/src/settingsui/settingsuiplugin/icons/ref/Camcorder.png Binary files differnew file mode 100644 index 0000000..8c317a2 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Camcorder.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Camera.png b/src/settingsui/settingsuiplugin/icons/ref/Camera.png Binary files differnew file mode 100644 index 0000000..c71ab25 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Camera.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Chevron-left.png b/src/settingsui/settingsuiplugin/icons/ref/Chevron-left.png Binary files differnew file mode 100644 index 0000000..95006f4 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Chevron-left.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Chevron-right.png b/src/settingsui/settingsuiplugin/icons/ref/Chevron-right.png Binary files differnew file mode 100644 index 0000000..2860e9a --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Chevron-right.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Circle-x.png b/src/settingsui/settingsuiplugin/icons/ref/Circle-x.png Binary files differnew file mode 100644 index 0000000..2bbfa97 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Circle-x.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Clock.png b/src/settingsui/settingsuiplugin/icons/ref/Clock.png Binary files differnew file mode 100644 index 0000000..1dae63e --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Clock.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Cogs.png b/src/settingsui/settingsuiplugin/icons/ref/Cogs.png Binary files differnew file mode 100644 index 0000000..feaae50 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Cogs.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Connections.png b/src/settingsui/settingsuiplugin/icons/ref/Connections.png Binary files differnew file mode 100644 index 0000000..b042d3c --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Connections.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Display.png b/src/settingsui/settingsuiplugin/icons/ref/Display.png Binary files differnew file mode 100644 index 0000000..cf1251a --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Display.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Flag.png b/src/settingsui/settingsuiplugin/icons/ref/Flag.png Binary files differnew file mode 100644 index 0000000..485ed48 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Flag.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Headphones.png b/src/settingsui/settingsuiplugin/icons/ref/Headphones.png Binary files differnew file mode 100644 index 0000000..9e5c483 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Headphones.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Heartbeat.png b/src/settingsui/settingsuiplugin/icons/ref/Heartbeat.png Binary files differnew file mode 100644 index 0000000..168135e --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Heartbeat.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Keyboard.png b/src/settingsui/settingsuiplugin/icons/ref/Keyboard.png Binary files differnew file mode 100644 index 0000000..c814e8e --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Keyboard.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Laptop.png b/src/settingsui/settingsuiplugin/icons/ref/Laptop.png Binary files differnew file mode 100644 index 0000000..465bb54 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Laptop.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Lock.png b/src/settingsui/settingsuiplugin/icons/ref/Lock.png Binary files differnew file mode 100644 index 0000000..6afb6ac --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Lock.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Microphone.png b/src/settingsui/settingsuiplugin/icons/ref/Microphone.png Binary files differnew file mode 100644 index 0000000..63cb500 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Microphone.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/MobilePhone.png b/src/settingsui/settingsuiplugin/icons/ref/MobilePhone.png Binary files differnew file mode 100644 index 0000000..b186c09 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/MobilePhone.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Mouse.png b/src/settingsui/settingsuiplugin/icons/ref/Mouse.png Binary files differnew file mode 100644 index 0000000..146305b --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Mouse.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Plus.png b/src/settingsui/settingsuiplugin/icons/ref/Plus.png Binary files differnew file mode 100644 index 0000000..391fe94 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Plus.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Power.png b/src/settingsui/settingsuiplugin/icons/ref/Power.png Binary files differnew file mode 100644 index 0000000..b54a084 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Power.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Settings.png b/src/settingsui/settingsuiplugin/icons/ref/Settings.png Binary files differnew file mode 100644 index 0000000..d8b255c --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Settings.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Tablet.png b/src/settingsui/settingsuiplugin/icons/ref/Tablet.png Binary files differnew file mode 100644 index 0000000..71b0065 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Tablet.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Volume_down.png b/src/settingsui/settingsuiplugin/icons/ref/Volume_down.png Binary files differnew file mode 100644 index 0000000..0773b1d --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Volume_down.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Volume_mute.png b/src/settingsui/settingsuiplugin/icons/ref/Volume_mute.png Binary files differnew file mode 100644 index 0000000..36ab384 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Volume_mute.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Volume_up.png b/src/settingsui/settingsuiplugin/icons/ref/Volume_up.png Binary files differnew file mode 100644 index 0000000..61eebbd --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Volume_up.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Wifi.png b/src/settingsui/settingsuiplugin/icons/ref/Wifi.png Binary files differnew file mode 100644 index 0000000..5d1e0d9 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Wifi.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Wifi1.png b/src/settingsui/settingsuiplugin/icons/ref/Wifi1.png Binary files differnew file mode 100644 index 0000000..f1b1489 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Wifi1.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Wifi2.png b/src/settingsui/settingsuiplugin/icons/ref/Wifi2.png Binary files differnew file mode 100644 index 0000000..a22b472 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Wifi2.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Wifi3.png b/src/settingsui/settingsuiplugin/icons/ref/Wifi3.png Binary files differnew file mode 100644 index 0000000..76d412b --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Wifi3.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Wifi4.png b/src/settingsui/settingsuiplugin/icons/ref/Wifi4.png Binary files differnew file mode 100644 index 0000000..5d1e0d9 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Wifi4.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/WifiAnim.png b/src/settingsui/settingsuiplugin/icons/ref/WifiAnim.png Binary files differnew file mode 100644 index 0000000..0694f63 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/WifiAnim.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/World.png b/src/settingsui/settingsuiplugin/icons/ref/World.png Binary files differnew file mode 100644 index 0000000..cf6eaf0 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/World.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/Wrench.png b/src/settingsui/settingsuiplugin/icons/ref/Wrench.png Binary files differnew file mode 100644 index 0000000..5b6e1c6 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/Wrench.png diff --git a/src/settingsui/settingsuiplugin/icons/ref/extra/Alert.png b/src/settingsui/settingsuiplugin/icons/ref/extra/Alert.png Binary files differnew file mode 100644 index 0000000..80914fc --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/ref/extra/Alert.png diff --git a/src/settingsui/settingsuiplugin/icons/scripts/cimage.sh b/src/settingsui/settingsuiplugin/icons/scripts/cimage.sh new file mode 100755 index 0000000..ae73622 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/scripts/cimage.sh @@ -0,0 +1,45 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash + +fullfile=$1 +filename=$(basename "$fullfile") +extension="${filename##*.}" +filename="${filename%.*}" + +color=$2 +if [ "$color" = "qt" ]; then + fill='rgb(128,195,66)' +elif [ "$color" = "black" ]; then + fill='rgb(32,40,42)' +elif [ "$color" = "white" ]; then + fill='rgb(255,255,255)' +elif [ "$color" = "lightgray" ]; then + fill='rgb(214,214,214)' +elif [ "$color" = "red" ]; then + fill='rgb(228,30,37)' +elif [ "$color" = "yellow" ]; then + fill='rgb(250,206,32)' +else + fill="black" +fi + +separator="_" + +convert $fullfile -fuzz 100% -fill $fill -opaque black $filename$separator$color.$extension diff --git a/src/settingsui/settingsuiplugin/icons/scripts/cimages.sh b/src/settingsui/settingsuiplugin/icons/scripts/cimages.sh new file mode 100755 index 0000000..94ac1cd --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/scripts/cimages.sh @@ -0,0 +1,28 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash + +for dir in "$@" +do + echo "$dir" + scripts/cimage.sh $dir qt + scripts/cimage.sh $dir black + scripts/cimage.sh $dir white + scripts/cimage.sh $dir lightgray +done diff --git a/src/settingsui/settingsuiplugin/icons/scripts/rimage.sh b/src/settingsui/settingsuiplugin/icons/scripts/rimage.sh new file mode 100755 index 0000000..d98088f --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/scripts/rimage.sh @@ -0,0 +1,37 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash +fullfile=$1 +filename=$(basename "$fullfile") +extension="${filename##*.}" +filename="${filename%.*}" + +postix="_1x" +convert $fullfile -resize x16 $filename$postix.$extension +postix="_2x" +convert $fullfile -resize x32 $filename$postix.$extension +postix="_3x" +convert $fullfile -resize x48 $filename$postix.$extension +postix="_4x" +convert $fullfile -resize x64 $filename$postix.$extension +postix="_5x" +convert $fullfile -resize x80 $filename$postix.$extension +postix="_6x" +convert $fullfile -resize x96 $filename$postix.$extension + diff --git a/src/settingsui/settingsuiplugin/icons/scripts/rimages.sh b/src/settingsui/settingsuiplugin/icons/scripts/rimages.sh new file mode 100755 index 0000000..7b76da8 --- /dev/null +++ b/src/settingsui/settingsuiplugin/icons/scripts/rimages.sh @@ -0,0 +1,25 @@ +############################################################################ +## +## Copyright (C) 2015 Digia Plc +## All rights reserved. +## For any questions to Digia, please use the contact form at +## http://www.qt.io +## +## This file is part of Qt Enterprise Embedded. +## +## Licensees holding valid Qt Enterprise licenses may use this file in +## accordance with the Qt Enterprise License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. +## +## If you have questions regarding the use of this file, please use +## the contact form at http://www.qt.io +## +############################################################################# +#!/bin/bash + +for dir in "$@" +do + echo "$dir" + scripts/rimage.sh $dir +done diff --git a/src/settingsui/settingsuiplugin/plugin.qrc b/src/settingsui/settingsuiplugin/plugin.qrc new file mode 100644 index 0000000..58cb4af --- /dev/null +++ b/src/settingsui/settingsuiplugin/plugin.qrc @@ -0,0 +1,28 @@ +<RCC> + <qresource prefix="/"> + <file>pluginMain.qml</file> + <file>../bluetooth/Bluetooth.qml</file> + <file>../bluetooth/Discovery.qml</file> + <file>../common/CustomTableView.qml</file> + <file>../common/HandwritingModeButton.qml</file> + <file>../display/Display.qml</file> + <file>../locale/Language.qml</file> + <file>../locale/RegionSelect.qml</file> + <file>../network/AddressListEntry.qml</file> + <file>../network/ComboBoxEntry.qml</file> + <file>../network/EditWiredSettings.qml</file> + <file>../network/IpAddressTextField.qml</file> + <file>../network/NetworkDetails.qml</file> + <file>../network/NetworkSettings.qml</file> + <file>../network/WifiSelectorDelegate.qml</file> + <file>../network/WifiSettings.qml</file> + <file>../network/WifiSignalMonitor.qml</file> + <file>../network/WiredSettings.qml</file> + <file>../timedate/AnalogClock.qml</file> + <file>../timedate/ClockHand.qml</file> + <file>../timedate/CustomCalendar.qml</file> + <file>../timedate/TimeDate.qml</file> + <file>../timedate/TimezonesView.qml</file> + <file>settingsview.xml</file> + </qresource> +</RCC> diff --git a/src/settingsui/settingsuiplugin/pluginMain.qml b/src/settingsui/settingsuiplugin/pluginMain.qml new file mode 100644 index 0000000..3f15c57 --- /dev/null +++ b/src/settingsui/settingsuiplugin/pluginMain.qml @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.0 +import Qt.labs.settings 1.0 +import QtQuick.XmlListModel 2.0 +import QtDeviceUtilities.LocalDeviceSettings 1.0 + +Rectangle { + id: root + anchors.fill: parent + color: "white" + visible: true + property var service + + ToolBar { + id: titlebar + property string title: "" + width: parent.width + height: 40 + z: 2 + + ToolButton { + height: parent.height + width: height + contentItem: Image { + fillMode: Image.PreserveAspectFit + source: "../icons/Chevron-left_black_6x.png" + anchors.fill: parent + anchors.margins: parent.height * .2 + } + + visible: stackView.depth > 1 + onClicked: stackView.pop(); + } + Label { + id: titleText + font.pixelSize: 20 + text: stackView.currentItem.title + horizontalAlignment: Qt.AlignHCenter + verticalAlignment: Qt.AlignVCenter + anchors.centerIn: parent + } + ToolButton { + height: parent.height + width: height + contentItem: Image { + fillMode: Image.PreserveAspectFit + source: "../icons/Power_black_6x.png" + anchors.fill: parent + anchors.margins: parent.height * .2 + } + anchors.right: parent.right + + visible: stackView.depth === 1 + onClicked: menu.open(); + + Menu { + id: menu + x: parent.width - width + + MenuItem { + text: qsTr("Reboot") + onTriggered: LocalDevice.reboot() + } + MenuItem { + text: qsTr("Shutdown") + onTriggered: LocalDevice.powerOff() + } + } + } + } + + StackView { + id: stackView + initialItem: mainView + anchors.top: titlebar.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + + Component { + id: mainView + + Item { + property string title: qsTr("Device Settings") + + XmlListModel { + id: xmlModel + source: "settingsview.xml" + query: "/xml/settings/item" + XmlRole { name: "title"; query: "title/string()"} + XmlRole { name: "icon"; query: "icon/string()"} + XmlRole { name: "view"; query: "view/string()"} + XmlRole { name: "path"; query: "path/string()"} + } + GridView { + id: grid + anchors.fill: parent + anchors.margins: 40 + cellHeight: 133 + spacing + cellWidth: 117 + spacing + model: xmlModel + property int spacing: 20 + delegate: MouseArea { + width: grid.cellWidth - grid.spacing + height: grid.cellHeight - grid.spacing + + Rectangle { + anchors.fill: parent + color: "#d6d6d6" + radius: 5 + visible: pressed + } + Column { + anchors.fill: parent + anchors.topMargin: 10 + Image { + id: image + source: icon + anchors.horizontalCenter: parent.horizontalCenter + width: grid.cellWidth + fillMode: Image.PreserveAspectFit + } + Label { + text: title + anchors.horizontalCenter: parent.horizontalCenter + font.pixelSize: grid.cellHeight * .1 + } + } + onClicked: { + var component = Qt.createComponent(path+'/'+view+'.qml'); + stackView.push(component.createObject(stackView)); + } + } + } + } + } + } +} diff --git a/src/settingsui/settingsuiplugin/qmldir b/src/settingsui/settingsuiplugin/qmldir new file mode 100644 index 0000000..542b7fe --- /dev/null +++ b/src/settingsui/settingsuiplugin/qmldir @@ -0,0 +1,2 @@ +module QtDeviceUtilities.SettingsUI +plugin settingsuiplugin diff --git a/src/settingsui/settingsuiplugin/settingsuiplugin.pro b/src/settingsui/settingsuiplugin/settingsuiplugin.pro new file mode 100644 index 0000000..5b11241 --- /dev/null +++ b/src/settingsui/settingsuiplugin/settingsuiplugin.pro @@ -0,0 +1,38 @@ +TEMPLATE = lib +TARGET = settingsuiplugin +QT += qml quick +CONFIG += qt plugin c++11 + +TARGET = $$qtLibraryTarget($$TARGET) +uri = QtDeviceUtilities.SettingsUI + +# Input +SOURCES += \ + settingsuiplugin_plugin.cpp + +HEADERS += \ + settingsuiplugin_plugin.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_QML]/$$replace(uri, \\., /) + qmldir.path = $$installPath + target.path = $$installPath + INSTALLS += target qmldir +} + +RESOURCES += \ + icons.qrc \ + plugin.qrc diff --git a/src/settingsui/settingsuiplugin/settingsuiplugin_plugin.cpp b/src/settingsui/settingsuiplugin/settingsuiplugin_plugin.cpp new file mode 100644 index 0000000..8b141e3 --- /dev/null +++ b/src/settingsui/settingsuiplugin/settingsuiplugin_plugin.cpp @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "settingsuiplugin_plugin.h" +#include <qqml.h> + +void SettingsuipluginPlugin::registerTypes(const char *uri) +{ + // @uri QtDeviceUtilities.SettingsUI + Q_ASSERT(uri == QLatin1String("QtDeviceUtilities.SettingsUI")); + qmlRegisterType(QUrl("qrc:/pluginMain.qml"), uri, 1, 0, "SettingsUI"); +} diff --git a/src/settingsui/settingsuiplugin/settingsuiplugin_plugin.h b/src/settingsui/settingsuiplugin/settingsuiplugin_plugin.h new file mode 100644 index 0000000..4ab42ad --- /dev/null +++ b/src/settingsui/settingsuiplugin/settingsuiplugin_plugin.h @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SETTINGSUIPLUGIN_PLUGIN_H +#define SETTINGSUIPLUGIN_PLUGIN_H + +#include <QQmlExtensionPlugin> + +class SettingsuipluginPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri); +}; + +#endif // SETTINGSUIPLUGIN_PLUGIN_H diff --git a/src/settingsui/settingsuiplugin/settingsview.xml b/src/settingsui/settingsuiplugin/settingsview.xml new file mode 100644 index 0000000..23915db --- /dev/null +++ b/src/settingsui/settingsuiplugin/settingsview.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<xml> + <settings> + <item> + <title>Network</title> + <view>NetworkSettings</view> + <path>network</path> + <icon>icons/World_qt_6x.png</icon> + </item> + <item> + <title>Display</title> + <view>Display</view> + <path>display</path> + <icon>icons/Display_qt_6x.png</icon> + </item> + <item> + <title>Date and Time</title> + <view>TimeDate</view> + <path>timedate</path> + <icon>icons/Clock_qt_6x.png</icon> + </item> + <item> + <title>Language</title> + <view>Language</view> + <path>locale</path> + <icon>icons/Flag_qt_6x.png</icon> + </item> + <item> + <title>Bluetooth</title> + <view>Bluetooth</view> + <path>bluetooth</path> + <icon>icons/Bluetooth_qt_6x.png</icon> + </item> + </settings> +</xml> diff --git a/src/settingsui/timedate/AnalogClock.qml b/src/settingsui/timedate/AnalogClock.qml new file mode 100644 index 0000000..6ddb91c --- /dev/null +++ b/src/settingsui/timedate/AnalogClock.qml @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.TimeDateSettings 1.0 + +Item { + property var currentTime: TimeManager.time + property var newTime: new Date + property bool editMode: false + property alias handPressed: mouseArea.pressed + + onEditModeChanged: if (editMode) newTime = new Date + + Rectangle { + border.color: "#bdbebf" + border.width: 1 + color: "white" + anchors.fill: parent + + Connections { + target: TimeManager + onTimeChanged: if (!mouseArea.pressed) newTime.setSeconds(currentTime.getSeconds()) + onTimeZoneChanged: Date.timeZoneUpdated() + } + Label { + id: timeLabel + anchors.horizontalCenter: parent.horizontalCenter + anchors.topMargin: 10 + anchors.top: parent.top + text: currentTime.toTimeString() + } + Rectangle { + id: root + anchors.fill: parent + anchors.margins: 40 + color: "white" + border.color: editMode ? "#d6d6d6" : "#5caa15" + border.width: Math.round(root.width * 0.120) + radius: parent.width / 2 + property int handOffset: Math.round(root.width * 0.040) + antialiasing: true + + MouseArea { + id: mouseArea + anchors.fill: parent + enabled: editMode + property var handleItem: undefined + + function findHandle(item, point) { + if (item.objectName === "handle") { + var mapped = mouseArea.mapToItem(item, point.x, point.y) + if (item.contains(mapped)) { + return item.parent; + } + } + + for (var i=0; i < item.children.length; i++) { + var ret = findHandle(item.children[i], point) + if (ret) + return ret; + } + return undefined; + } + + onPressed: { + handleItem = findHandle(root, Qt.point(mouse.x, mouse.y)) + currentTime.setSeconds(0); + currentTime.setMilliseconds(0); + newTime.setSeconds(0); + newTime.setMilliseconds(0); + } + + onReleased: { + handleItem = undefined + } + + onPositionChanged: { + if (!handleItem) + return; + + var angle = (90 + Math.atan2((mouse.y-mouseArea.height/2), (mouse.x-mouseArea.width/2))*180/Math.PI) + + if (handleItem.angle < 60 && handleItem.angle > 0 && angle <= 0) { + + if (handleItem === hours) { + hours.pm = !hours.pm + } else { + var a = hours.angle - 30 + if (a > 360) a -= 360 + hours.angle = a + } + + } else if (handleItem.angle > 300 && handleItem.angle < 360 && angle >= 0) { + + if (handleItem === hours) { + hours.pm = !hours.pm + } else { + var a = hours.angle + 30 + if (a < 0) a += 360 + hours.angle = a + } + } + + if (angle < 0) { + angle += 360 + } else if (angle > 360) { + angle -= 360 + } + + handleItem.angle = angle + + var newhours = Math.floor(hours.angle / 30); + if (hours.pm) + newhours += 12 + + newTime.setHours(newhours); + newTime.setMinutes(Math.round(minutes.angle / 6)); + + newTime.setSeconds(0); + newTime.setMilliseconds(0); + + TimeManager.time = newTime; + } + } + ClockHand { + id: minutes + value: currentTime.getMinutes() * 6 + } + ClockHand { + id: hours + height: root.height / 2 * 0.4 + root.handOffset + value: (currentTime.getHours() * 30) + (currentTime.getMinutes() * 0.5) + property bool pm: false + } + ClockHand { + id: seconds + visible: !editMode + color: "#46a2da" + width: root.width * 0.0128 + height: root.height / 2 * 0.74 + value: currentTime.getSeconds() * 6 + } + } + } +} diff --git a/src/settingsui/timedate/ClockHand.qml b/src/settingsui/timedate/ClockHand.qml new file mode 100644 index 0000000..56fa314 --- /dev/null +++ b/src/settingsui/timedate/ClockHand.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 + +Rectangle { + id: hand + objectName: "hand" + x: root.height / 2 - width / 2 + y: root.height / 2 - height + root.handOffset + color: editMode ? "#d6d6d6" : "#5caa15" + width: root.width * 0.080 + height: root.height / 2 * 0.65 + root.handOffset + antialiasing: true + property alias angle: handRotation.angle + property alias value: angleBinding.value + transform: Rotation { + id: handRotation + origin.x: Math.round(hand.width / 2) + origin.y: Math.round(hand.height - root.handOffset) + Behavior on angle { + enabled: !mouseArea.pressed + SpringAnimation { spring: 2; damping: 0.2; modulus: 360 } + } + + Binding on angle { + id: angleBinding + when: !mouseArea.pressed + } + } + Item { + objectName: "handle" + anchors.verticalCenter: parent.top + anchors.horizontalCenter: parent.horizontalCenter + height: parent.width * 3 + width: parent.width * 3 + visible: editMode + Rectangle { + anchors.fill: parent + anchors.margins: parent.width * .1 + radius: width / 2 + color: "#5caa15" + } + } +} diff --git a/src/settingsui/timedate/CustomCalendar.qml b/src/settingsui/timedate/CustomCalendar.qml new file mode 100644 index 0000000..a1deff0 --- /dev/null +++ b/src/settingsui/timedate/CustomCalendar.qml @@ -0,0 +1,216 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import Qt.labs.calendar 1.0 +import QtQml 2.2 +import QtDeviceUtilities.TimeDateSettings 1.0 + +Rectangle { + id: root + border.color: "#bdbebf" + border.width: 1 + color: "white" + height: cal.height + + function updateDate() { + var date = new Date() + grid.month = date.getMonth() + grid.date = date.getDate() + grid.year = date.getFullYear() + } + + ColumnLayout { + id: cal + width: root.width + spacing: 10 + enabled: !automatic.checked + + RowLayout { + spacing: 0 + Layout.alignment: Qt.AlignTop + + Button { + id: previousMonth + Layout.preferredWidth: height + visible: enabled + contentItem: Rectangle { + anchors.fill: parent + color: "#d6d6d6" + + Image { + anchors.fill: parent + anchors.margins: parent.height * .2 + source: "../icons/Chevron-left_black.png" + fillMode: Image.PreserveAspectFit + } + } + onClicked: { + if (grid.month === Calendar.January) { + grid.year-- + grid.month = Calendar.December + return; + } + grid.month-- + } + } + Rectangle { + Layout.fillWidth: true + color: enabled ? "#d6d6d6" : "#80c342" + height: previousMonth.height + + Label { + id: title + text: Qt.locale().monthName(grid.month, Locale.LongFormat) + " " + grid.year + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + } + Button { + id: nextMonth + Layout.preferredWidth: height + visible: enabled + contentItem: Rectangle { + anchors.fill: parent + color: "#d6d6d6" + + Image { + anchors.fill: parent + anchors.margins: parent.height * .2 + source: "../icons/Chevron-left_black.png" + mirror: true + fillMode: Image.PreserveAspectFit + } + } + onClicked: { + if (grid.month === Calendar.December) { + grid.year++ + grid.month = Calendar.January + } + grid.month++ + } + } + } + DayOfWeekRow { + locale: grid.locale + Layout.column: 1 + Layout.fillWidth: true + Layout.alignment: Qt.AlignTop + delegate: Text { + text: model.narrowName.charAt(0) + font.bold: true + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + } + MonthGrid { + id: grid + Layout.alignment: Qt.AlignTop + Layout.fillWidth: true + property int date: -1 + property Item currentItem: null + delegate: Label { + id: gridDelegate + objectName: "gridDelegate" + text: delegateDay + opacity: model.month === grid.month ? 1 : .2 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + font.bold: delegateDay === grid.date && delegateMonth === grid.month + color: delegateDay === grid.date && delegateMonth === grid.month && enabled ? "white" : "black" + property int delegateDay: model.day + property int delegateMonth: model.month + } + Component.onCompleted: updateDate() + + Rectangle { + z: -1 + id: highlight + x: grid.currentItem ? grid.currentItem.x + grid.currentItem.width / 2 - width / 2: 0 + y: grid.currentItem ? grid.currentItem.y + grid.currentItem.height / 2- height / 2: 0 + width: grid.currentItem ? grid.currentItem.width : 0 + visible: grid.currentItem + height: width + color: enabled? "#80c342" : "#d6d6d6" + radius: width / 2 + } + + onMonthChanged: updateHighlightPosition() + onYearChanged: updateHighlightPosition() + onDateChanged: updateHighlightPosition() + + function updateHighlightPosition() { + var date = new Date() + + date.setFullYear(grid.year) + date.setMonth(grid.month) + date.setDate(grid.date) + + var index = grid.source.indexOf(date) + var delegate = grid.contentItem.children[index] + + if (delegate) + grid.currentItem = delegate + } + + MouseArea { + anchors.fill: parent + + onClicked: { + var item = grid.contentItem.childAt(mouse.x, mouse.y) + + if (item) { + if (item.objectName !== "gridDelegate") + item = grid.contentItem.children[0] + + if (!item) + return; + + grid.currentItem = item + grid.date = item.delegateDay + grid.month = item.delegateMonth + + var currentTime = TimeManager.time; + var newDate = new Date(); + + newDate.setFullYear(grid.year) + newDate.setMonth(grid.month) + newDate.setDate(grid.date) + newDate.setHours(currentTime.getHours()); + newDate.setMinutes(currentTime.getMinutes()); + newDate.setSeconds(currentTime.getSeconds()); + TimeManager.time = newDate; + } + } + } + } + } +} diff --git a/src/settingsui/timedate/TimeDate.qml b/src/settingsui/timedate/TimeDate.qml new file mode 100644 index 0000000..e269fa5 --- /dev/null +++ b/src/settingsui/timedate/TimeDate.qml @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.TimeDateSettings 1.0 + +Item { + id: root + property string title: qsTr("Time and Date settings") + + Flickable { + id: flickable + anchors.margins: 20 + anchors.fill: parent + contentHeight: content.height + contentWidth: width + interactive: !clock.handPressed + + ColumnLayout { + id: content + spacing: 20 + width: parent.width + + GroupBox { + width: parent.width + title: qsTr("Time Settings") + Layout.fillWidth: true + + ColumnLayout { + spacing: 10 + width: parent.width + Layout.fillWidth: true + + RadioButton { + id: automatic + text: qsTr("Automatic time set") + checked: TimeManager.ntp + onCheckedChanged: if (checked) updateTimer.restart() + + Timer { + id: updateTimer + interval: 300 + onTriggered: calendar.updateDate() + } + } + RadioButton { + id: custom + text: qsTr("Manual") + checked: !TimeManager.ntp + onCheckedChanged: TimeManager.ntp = !checked + } + RowLayout + { + id: layout + spacing: 10 + + CustomCalendar { + id: calendar + width: height + } + AnalogClock { + id: clock + height: calendar.height + width: height + editMode: !automatic.checked + } + } + Component { + id: zoneselect + TimezonesView { } + } + } + } + GroupBox { + title: qsTr("Timezone Settings") + Layout.fillWidth: true + width: parent.width + visible: true + + RowLayout { + spacing: 10 + Label { + text: TimeManager.timeZone + Layout.alignment: Qt.AlignVCenter + } + Button { + text: qsTr("Change") + onClicked : stackView.push(zoneselect) + } + } + } + } + } +} diff --git a/src/settingsui/timedate/TimezonesView.qml b/src/settingsui/timedate/TimezonesView.qml new file mode 100644 index 0000000..bbcffe4 --- /dev/null +++ b/src/settingsui/timedate/TimezonesView.qml @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.0 +import QtDeviceUtilities.TimeDateSettings 1.0 +import "../common" +Item { + id: root + property string title: qsTr("Timezone settings") + Component.onCompleted: timezone.text = TimezonesFilter.filter + + ColumnLayout { + id: content + anchors.fill: parent + anchors.margins: 20 + spacing: 10 + + RowLayout { + spacing: 10 + + Label { + text: qsTr("Search area: ") + Layout.alignment: Qt.AlignVCenter + } + TextField { + id: timezone + text: "" + onTextChanged: TimezonesFilter.filter = timezone.text + Layout.alignment: Qt.AlignVCenter + } + } + CustomTableView { + headerTexts: [qsTr("Timezone"), qsTr("Country")] + roleNames: ["id", "country"] + model: TimezonesFilter + onClicked: { + var val = model.itemFromRow(index); + if (val !== "") { + TimeManager.timeZone = val; + stackView.pop(); + } + } + } + } +} diff --git a/src/src.pro b/src/src.pro index ebe58b5..faa9a6d 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,7 +1,13 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS += \ - utils \ - wifi \ + networksettings \ + bluetoothsettings \ + localesettings \ + displaysettings \ + timedatesettings \ + localdevice \ + settingsui/settingsuiplugin \ + settingsui \ imports \ - doc + doc \ diff --git a/src/timedatesettings/systemtime.cpp b/src/timedatesettings/systemtime.cpp new file mode 100644 index 0000000..32e6e51 --- /dev/null +++ b/src/timedatesettings/systemtime.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "systemtime.h" +#include "systemtime_p.h" + +SystemTime::SystemTime(QObject *parent) : + QObject(parent) + ,d_ptr(new SystemTimePrivate(this)) +{ + QTimer *secTimer = new QTimer(this); + connect(secTimer, &QTimer::timeout, this, &SystemTime::timeChanged); + secTimer->setInterval(1001); + secTimer->setSingleShot(false); + secTimer->start(); +} + +bool SystemTime::ntp() const +{ + const Q_D(SystemTime); + return d->ntp(); +} + +void SystemTime::setNtp(const bool aNtp) +{ + Q_D(SystemTime); + d->setNtp(aNtp); +} + +void SystemTime::setTime(const QDateTime& aTime) +{ + Q_D(SystemTime); + d->setTime(aTime.toMSecsSinceEpoch()*1000); + emit timeChanged(); +} + +QString SystemTime::timeZone() const +{ + Q_D(const SystemTime); + return d->timeZone(); +} + +void SystemTime::setTimeZone(const QString& aTimeZone) +{ + Q_D(SystemTime); + d->setTimeZone(aTimeZone); + emit timeZoneChanged(); +} + +QDateTime SystemTime::time() const +{ + return QDateTime::currentDateTime(); +} diff --git a/src/timedatesettings/systemtime.h b/src/timedatesettings/systemtime.h new file mode 100644 index 0000000..178e6a6 --- /dev/null +++ b/src/timedatesettings/systemtime.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SYSTEMTIME_H +#define SYSTEMTIME_H + +#include <QObject> +#include <QTime> + +class SystemTimePrivate; + +class Q_DECL_EXPORT SystemTime : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString timeZone READ timeZone WRITE setTimeZone NOTIFY timeZoneChanged) + Q_PROPERTY(bool ntp READ ntp WRITE setNtp NOTIFY ntpChanged) + Q_PROPERTY(QDateTime time READ time WRITE setTime NOTIFY timeChanged) +public: + explicit SystemTime(QObject *parent = 0); + bool ntp() const; + void setNtp(const bool aNtp); + void setTime(const QDateTime& aTime); + QString timeZone() const; + QDateTime time() const; + void setTimeZone(const QString& aTimeZone); + +signals: + void timeZoneChanged(); + void ntpChanged(); + void timeChanged(); + +public slots: + +protected: + SystemTimePrivate *d_ptr; + + Q_DISABLE_COPY(SystemTime) + Q_DECLARE_PRIVATE(SystemTime) +}; + +#endif // SYSTEMTIME_H diff --git a/src/timedatesettings/systemtime_p.h b/src/timedatesettings/systemtime_p.h new file mode 100644 index 0000000..d4ff4d4 --- /dev/null +++ b/src/timedatesettings/systemtime_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SYSTEMTIME_P_H +#define SYSTEMTIME_P_H + +#include "systemtime.h" +#include "timedated_interface.h" + +class SystemTimePrivate +{ + Q_DECLARE_PUBLIC(SystemTime) +public: + SystemTimePrivate(SystemTime *qq) + :q_ptr(qq) + { + m_timeInterface = new OrgFreedesktopTimedate1Interface(QStringLiteral("org.freedesktop.timedate1"), + QStringLiteral("/org/freedesktop/timedate1"), + QDBusConnection::systemBus(), qq); + + } + + bool ntp() const { + if (m_timeInterface) + return m_timeInterface->nTP(); + return false; + } + + void setNtp(bool val) { + if (m_timeInterface) + m_timeInterface->SetNTP(val, true); + } + + QString timeZone() const { + if (m_timeInterface) + return m_timeInterface->timezone(); + return QString(); + } + + void setTimeZone(const QString& aTimeZone) { + if (m_timeInterface) + m_timeInterface->SetTimezone(aTimeZone, true); + } + + void setTime(qlonglong usecsSinceEpoch) { + if (m_timeInterface) + m_timeInterface->SetTime(usecsSinceEpoch, false, true); + } + +private: + OrgFreedesktopTimedate1Interface *m_timeInterface; + SystemTime *q_ptr; +}; + + +#endif // SYSTEMTIME_P_H diff --git a/src/timedatesettings/timedated.xml b/src/timedatesettings/timedated.xml new file mode 100644 index 0000000..95bafb8 --- /dev/null +++ b/src/timedatesettings/timedated.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> +<node> + <interface name="org.freedesktop.timedate1"> + <property name="Timezone" type="s" access="read"/> + <property name="LocalRTC" type="b" access="read"/> + <property name="CanNTP" type="b" access="read"/> + <property name="NTP" type="b" access="read"/> + <method name="SetTime"> + <arg name="usec_utc" type="x" direction="in"/> + <arg name="relative" type="b" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + <method name="SetTimezone"> + <arg name="timezone" type="s" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + <method name="SetLocalRTC"> + <arg name="local_rtc" type="b" direction="in"/> + <arg name="fix_system" type="b" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + <method name="SetNTP"> + <arg name="use_ntp" type="b" direction="in"/> + <arg name="user_interaction" type="b" direction="in"/> + </method> + </interface> +</node> + + diff --git a/src/timedatesettings/timedateplugin.pro b/src/timedatesettings/timedateplugin.pro new file mode 100644 index 0000000..d82529d --- /dev/null +++ b/src/timedatesettings/timedateplugin.pro @@ -0,0 +1,42 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml dbus + +uri = com.theqtcompany.settings.timedate + +DBUS_INTERFACES = timedated.xml + +DESTDIR = imports/TimeDate +TARGET = qmltimedatesettingsplugin + +SOURCES += plugin.cpp \ + systemtime.cpp \ + timezonemodel.cpp \ + timezonefiltermodel.cpp + +pluginfiles.files += \ + qmldir + + +pluginfiles.files += \ + AnalogClock.qml \ + TimeDate.qml \ + TimezonesView.qml \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles + + +RESOURCES += \ + icons.qrc + +HEADERS += \ + systemtime.h \ + systemtime_p.h \ + timezonemodel.h \ + timezonefiltermodel.h + + diff --git a/src/timedatesettings/timedatesettings.pro b/src/timedatesettings/timedatesettings.pro new file mode 100644 index 0000000..6f3f4e9 --- /dev/null +++ b/src/timedatesettings/timedatesettings.pro @@ -0,0 +1,23 @@ +load(qt_build_config) + +TARGET = QtTimeDateSettings +VERSION = 1.0 +CONFIG += dll warn_on + +QT = core dbus + +MODULE = timedatesettings +load(qt_module) + +DBUS_INTERFACES = timedated.xml + +SOURCES += systemtime.cpp \ + timezonemodel.cpp \ + timezonefiltermodel.cpp + +HEADERS += \ + systemtime.h \ + systemtime_p.h \ + timezonemodel.h \ + timezonefiltermodel.h + diff --git a/src/timedatesettings/timezonefiltermodel.cpp b/src/timedatesettings/timezonefiltermodel.cpp new file mode 100644 index 0000000..c1614ef --- /dev/null +++ b/src/timedatesettings/timezonefiltermodel.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "timezonemodel.h" +#include "timezonefiltermodel.h" + +TimezoneFilterModel::TimezoneFilterModel(QObject* parent) + :QSortFilterProxyModel(parent) +{ + connect(this, &TimezoneFilterModel::filterChanged, this, &TimezoneFilterModel::invalidate); + TimezoneModel* timezoneModel = new TimezoneModel(this); + setSourceModel(timezoneModel); +} + +TimezoneFilterModel::~TimezoneFilterModel() +{ + +} + +QString TimezoneFilterModel::filter() const +{ + return m_filter; +} + +void TimezoneFilterModel::setFilter(const QString& aFilter) +{ + m_filter = aFilter; + emit filterChanged(); +} + +bool TimezoneFilterModel::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const +{ + bool ret = false; + if (this->sourceModel()) + { + QModelIndex index = this->sourceModel()->index( source_row, 0, source_parent ); + if (index.isValid()) + { + QVariant nameRole = index.data(TimezoneModel::Name); + if (nameRole.isValid()) + { + QString name = nameRole.toString(); + if (name.contains(m_filter, Qt::CaseInsensitive)) { + ret = true; + } + } + QVariant countryRole = index.data(TimezoneModel::Country); + if (ret == false && countryRole.isValid()) + { + QString country = countryRole.toString(); + if (country.contains(m_filter, Qt::CaseInsensitive)) { + ret = true; + } + } + } + } + return ret; +} + +QVariant TimezoneFilterModel::itemFromRow(const int row) const +{ + QModelIndex idx = index(row, 0); + QModelIndex mapped = mapToSource(idx); + if (mapped.isValid()) + { + QVariant nameRole = mapped.data(TimezoneModel::Name); + if (nameRole.isValid()) + { + return nameRole; + } + } + return QVariant(); +} + diff --git a/src/timedatesettings/timezonefiltermodel.h b/src/timedatesettings/timezonefiltermodel.h new file mode 100644 index 0000000..164f8c0 --- /dev/null +++ b/src/timedatesettings/timezonefiltermodel.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TIMEZONEFILTERMODEL_H +#define TIMEZONEFILTERMODEL_H + +#include <QSortFilterProxyModel> + +class Q_DECL_EXPORT TimezoneFilterModel : public QSortFilterProxyModel +{ + Q_OBJECT + Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) +public: + explicit TimezoneFilterModel(QObject* parent); + virtual ~TimezoneFilterModel(); + bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; + QString filter() const; + void setFilter(const QString& aFilter); + Q_INVOKABLE QVariant itemFromRow(const int row) const; +signals: + void filterChanged(); +private: + QString m_filter; + +}; + +#endif // TIMEZONEFILTERMODEL_H diff --git a/src/timedatesettings/timezonemodel.cpp b/src/timedatesettings/timezonemodel.cpp new file mode 100644 index 0000000..4273df9 --- /dev/null +++ b/src/timedatesettings/timezonemodel.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QLocale> +#include <QFuture> +#include <QThread> +#include <QtConcurrent/QtConcurrentRun> +#include "timezonemodel.h" + +TimezoneItem::TimezoneItem(const QByteArray& id, QObject *parent) + :QObject(parent) +{ + QTimeZone tz = QTimeZone(id); + m_name = tz.displayName(QTimeZone::StandardTime); + m_country = QLocale::countryToString(tz.country()); + m_id = QString::fromUtf8(id); +} + +QString TimezoneItem::name() const +{ + return m_name; +} + +QString TimezoneItem::country() const +{ + return m_country; +} + +QString TimezoneItem::id() const +{ + return m_id; +} + +TimezoneModel::TimezoneModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Country, "country"); + m_roleNames.insert(Name, "name"); + m_roleNames.insert(Id, "id"); + + QFuture<void> t1 = QtConcurrent::run(TimezoneModel::generateModel, this); +} + +void TimezoneModel::generateModel(TimezoneModel* model) +{ + QList<QByteArray> ids = QTimeZone::availableTimeZoneIds(); + foreach (QByteArray id, ids) { + TimezoneItem *zone = new TimezoneItem(id); + zone->moveToThread(model->thread()); + QMetaObject::invokeMethod(model, "addNewItem", Q_ARG( QObject*, qobject_cast<QObject*>(zone))); + } +} + +void TimezoneModel::addNewItem(QObject* item) +{ + beginInsertRows(QModelIndex(), m_items.count(), m_items.count()); + TimezoneItem* newItem = qobject_cast<TimezoneItem*>(item); + if (newItem) + m_items.append(newItem); + endInsertRows(); +} + +TimezoneModel::~TimezoneModel() +{ + qDeleteAll(m_items); +} + +QHash<int, QByteArray> TimezoneModel::roleNames() const +{ + return m_roleNames; +} + + +int TimezoneModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant TimezoneModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + TimezoneItem *item = m_items[index.row()]; + + switch (role) { + case Qt::UserRole: + return QVariant::fromValue(static_cast<QObject*>(item)); + break; + case Name: + return item->id(); + break; + case Country: + return item->country(); + break; + case Id: + return item->id(); + break; + case Qt::DisplayRole: + return item->id(); + break; + default: + return QVariant(); + } +} diff --git a/src/timedatesettings/timezonemodel.h b/src/timedatesettings/timezonemodel.h new file mode 100644 index 0000000..efa0e22 --- /dev/null +++ b/src/timedatesettings/timezonemodel.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TIMEZONEMODEL_H +#define TIMEZONEMODEL_H + +#include <QObject> +#include <QAbstractListModel> +#include <QTimeZone> +#include <QMutex> + +class TimezoneItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString country READ country CONSTANT) +public: + explicit TimezoneItem(const QByteArray& id, QObject *parent=0); + QString name() const; + QString country() const; + QString id() const; + +private: + QString m_name; + QString m_country; + QString m_id; +}; + +class Q_DECL_EXPORT TimezoneModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit TimezoneModel(QObject *parent=0); + virtual ~TimezoneModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + + enum Roles { + Name = Qt::UserRole + 1, + Country, + Id + }; + + static void generateModel(TimezoneModel* model); + +private slots: + void addNewItem(QObject* item); + +private: + QList<TimezoneItem*> m_items; + QHash<int, QByteArray> m_roleNames; +}; + +#endif // TIMEZONEMODEL_H diff --git a/src/utils/b2qtdevice.cpp b/src/utils/b2qtdevice.cpp deleted file mode 100644 index 85006f8..0000000 --- a/src/utils/b2qtdevice.cpp +++ /dev/null @@ -1,393 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "b2qtdevice.h" -#include <unistd.h> -#include <QDebug> -#include <math.h> -#include <sys/reboot.h> -#include <QNetworkInterface> -#include <QHostInfo> -#include <QFile> -#include <QDirIterator> -#include <QTimer> -#include <QtCore/qmath.h> - -// When we can't query directly, at least remember what we have set it to -static quint8 knownBrightness = 255; - -B2QtDevice::B2QtDevice(QObject *parent) - : QObject(parent) -{ -} - -B2QtDevice::~B2QtDevice() -{ -} - -/*! - * Reboots the system. Does not return. - * - * \sa powerOff() - */ -void B2QtDevice::reboot() -{ - sync(); - ::reboot(RB_AUTOBOOT); - qWarning("reboot returned"); -} - - -/*! - * Shuts down the system. Does not return. - * - * \sa reboot() - */ -void B2QtDevice::powerOff() -{ - sync(); - ::reboot(RB_POWER_OFF); - qWarning("powerOff returned"); -} - - -class LightDevice -{ -public: - QString name; - QString deviceFile; - quint8 value; - uint maxValue; -}; - -static QList<LightDevice> lightDevices; -static bool lightDevicesInitialized = false; - -static void initLightDevices() -{ - if (lightDevicesInitialized) - return; - QDirIterator it(QStringLiteral("/sys/class/backlight")); - while (it.hasNext()) { - LightDevice ld; - ld.deviceFile = it.next() + QStringLiteral("/brightness"); - QFile maxFile(it.filePath() + QStringLiteral("/max_brightness")); - if (!maxFile.open(QIODevice::ReadOnly)) - continue; - bool ok = false; - ld.maxValue = maxFile.read(10).simplified().toUInt(&ok); - if (!ok || !ld.maxValue) - continue; - QFile valFile(ld.deviceFile); - if (!valFile.open(QIODevice::ReadOnly)) - continue; - ok = false; - uint val = valFile.read(10).simplified().toUInt(&ok); - if (!ok) - continue; - // map max->max as that is a common case, otherwise choose a reasonable value - ld.value = (val == ld.maxValue) ? 255 : (val * 256)/(ld.maxValue+1); - ld.name = it.fileName(); - lightDevices.append(ld); - } - if (!lightDevices.isEmpty()) - knownBrightness = lightDevices.at(0).value; - lightDevicesInitialized = true; -} - -/*! - * Sets the display brightness (i.e. the intensity of the backlight) - * to \a value. A value of 255 requests maximum brightness, while 0 requests - * minimum (typically, the backlight turned off). - * - * Returns true on success. - */ -bool B2QtDevice::setDisplayBrightness(int v) -{ - quint8 value = qBound(0, v, 255); - initLightDevices(); - for (int i = 0; i < lightDevices.size(); i++) { - LightDevice &ld = lightDevices[i]; - QFile devFile(ld.deviceFile); - if (!devFile.open(QIODevice::WriteOnly)) - continue; - // Maps only 0 to 0, since 0 often means "off"; other values are degrees of "on". - uint newVal = value ? 1 + ((value * ld.maxValue) / 256) : 0; - devFile.write(QByteArray::number(newVal)); - ld.value = value; - } - knownBrightness = value; - return true; -} - - -/*! - * Returns the current backlight intensity. - * \sa setDisplayBrightness - */ -int B2QtDevice::displayBrightness() const -{ - initLightDevices(); - return knownBrightness; -} - - -/*! - * Gets the current IP address(es) of the device - */ -QString B2QtDevice::getIPAddress() const -{ - QStringList addresses; - foreach (const QNetworkInterface &interface, QNetworkInterface::allInterfaces()) { - QNetworkInterface::InterfaceFlags flags = interface.flags(); - if (flags.testFlag(QNetworkInterface::IsRunning) && !flags.testFlag(QNetworkInterface::IsLoopBack)) { - foreach (const QNetworkAddressEntry &entry, interface.addressEntries()) - addresses.append(entry.ip().toString().split('%').first()); - } - } - return addresses.join(QStringLiteral(", ")); -} - - -/*! - * Gets the current hostname of the device - */ -QString B2QtDevice::hostname() const -{ - QString name; - name = QHostInfo::localHostName(); - return name; -} - - -/*! - * Sets new hostname for the device - */ -bool B2QtDevice::setHostname(const QString &name) -{ - QByteArray lname = name.toLocal8Bit(); - if (::sethostname(lname.constData(), lname.length())) { - qWarning("Could not set system hostname"); - return false; - } - // Also store it for next boot: - QFile file(QStringLiteral("/etc/hostname")); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - qWarning("Could not write to /etc/hostname"); - return false; - } - file.write(lname.append('\n')); - file.close(); - - emit hostnameChanged(name); - return true; -} - - -/*! - * Sets the master volume to \a volume. - * The volume can range from 0 to 100 and is linear. - */ -void B2QtDevice::setMasterVolume(int volume) -{ - Q_UNUSED(volume) -} - - -/*! - * Returns the current master volume. - * The volume can range from 0 to 100 and is linear. - */ -int B2QtDevice::masterVolume() const -{ - return 0; -} - - -/*! - * Initializes the audio subsystem, setting the volume to max. - * This is done during system startup, so there is normally no need to call this function from applications. - */ -void B2QtDevice::initAudio() -{ -} - - -class PhysicalScreenSize : public QObject -{ - Q_OBJECT - -public: - PhysicalScreenSize(); - - void setSize(int inches); - int size() const { return physScreenSizeInch; } - bool enabled() const; - void setEnabled(bool enable); - -private slots: - void onTimeout(); - -private: - void read(const QString &filename); - void write(bool includePhysSize = true); - void write(const QString &filename, bool includePhysSize = true); - - bool physScreenSizeEnabled; - int physScreenSizeInch; - QTimer physWriteTimer; -}; - -Q_GLOBAL_STATIC(PhysicalScreenSize, physScreenSize) - -PhysicalScreenSize::PhysicalScreenSize() - : physScreenSizeEnabled(false), physScreenSizeInch(7) -{ - physWriteTimer.setSingleShot(true); - physWriteTimer.setInterval(1000); - QObject::connect(&physWriteTimer, SIGNAL(timeout()), this, SLOT(onTimeout())); - - read(QStringLiteral("/etc/appcontroller.conf")); - read(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf")); -} - -void PhysicalScreenSize::read(const QString &filename) -{ - QFile f(filename); - if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) - return; - - int physScreenWidth = 154, physScreenHeight = 90; - int found = 0; - while (!f.atEnd()) { - QByteArray line = f.readLine().trimmed(); - if (line.startsWith(QByteArrayLiteral("env="))) { - QByteArrayList values = line.split('='); - if (values.count() == 3) { - bool ok; - if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_WIDTH")) { - int val = values[2].toInt(&ok); - if (ok) { - ++found; - physScreenWidth = val; - } - } else if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_HEIGHT")) { - int val = values[2].toInt(&ok); - if (ok) { - ++found; - physScreenHeight = val; - } - } - } - } - } - if (found == 2) - physScreenSizeEnabled = true; - - const qreal diagMM = qSqrt(physScreenWidth * physScreenWidth + physScreenHeight * physScreenHeight); - physScreenSizeInch = qRound(diagMM / 25.4); -} - -void PhysicalScreenSize::onTimeout() -{ - write(); -} - -void PhysicalScreenSize::write(bool includePhysSize) -{ - QDir(QStringLiteral("/var/lib")).mkpath(QStringLiteral("b2qt/appcontroller.conf.d")); - write(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf"), includePhysSize); -} - -void PhysicalScreenSize::write(const QString &filename, bool includePhysSize) -{ - QFile f(filename); - - QByteArrayList lines; - if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { - while (!f.atEnd()) { - QByteArray line = f.readLine().trimmed(); - if (!line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=")) - && !line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_HEIGHT="))) - lines.append(line); - } - f.close(); - } - - if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) - return; - - const qreal diagMM = physScreenSizeInch * 25.4; - // Assume 16:9 aspect ratio - const int physScreenHeight = qRound(diagMM / 1.975); - const int physScreenWidth = qRound(physScreenHeight * 1.777); - - foreach (const QByteArray &line, lines) - f.write(line + QByteArrayLiteral("\n")); - - if (includePhysSize) - f.write(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=") + QByteArray::number(physScreenWidth) - + QByteArrayLiteral("\nenv=QT_QPA_EGLFS_PHYSICAL_HEIGHT=") + QByteArray::number(physScreenHeight) - + QByteArrayLiteral("\n")); -} - -void PhysicalScreenSize::setSize(int inches) -{ - physScreenSizeInch = inches; - physWriteTimer.start(); -} - -bool PhysicalScreenSize::enabled() const -{ - return physScreenSizeEnabled; -} - -void PhysicalScreenSize::setEnabled(bool enable) -{ - physScreenSizeEnabled = enable; - // Rewrite appcontroller.conf with or without the physical width/height lines. - write(enable); -} - -int B2QtDevice::physicalScreenSizeInch() const -{ - return physScreenSize()->size(); -} - -void B2QtDevice::setPhysicalScreenSizeInch(int inches) -{ - if (physScreenSize()->size() != inches) { - physScreenSize()->setSize(inches); - emit physicalScreenSizeInchChanged(inches); - } -} - -bool B2QtDevice::physicalScreenSizeOverride() const -{ - return physScreenSize()->enabled(); -} - -void B2QtDevice::setPhysicalScreenSizeOverride(bool enable) -{ - if (physScreenSize()->enabled() != enable) { - physScreenSize()->setEnabled(enable); - emit physicalScreenSizeOverrideChanged(enable); - } -} - -#include "b2qtdevice.moc" diff --git a/src/utils/b2qtdevice.h b/src/utils/b2qtdevice.h deleted file mode 100644 index 288f62d..0000000 --- a/src/utils/b2qtdevice.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef B2QTDEVICE_H -#define B2QTDEVICE_H - -#include <qobject.h> - -class Q_DECL_EXPORT B2QtDevice : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int displayBrightness READ displayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged) - Q_PROPERTY(QString hostname READ hostname WRITE setHostname NOTIFY hostnameChanged) - Q_PROPERTY(QString ipAddress READ getIPAddress NOTIFY ipAddressChanged) - Q_PROPERTY(int masterVolume READ masterVolume WRITE setMasterVolume NOTIFY masterVolumeChanged) - Q_PROPERTY(int physicalScreenSizeInch READ physicalScreenSizeInch WRITE setPhysicalScreenSizeInch NOTIFY physicalScreenSizeInchChanged) - Q_PROPERTY(bool physicalScreenSizeOverride READ physicalScreenSizeOverride WRITE setPhysicalScreenSizeOverride NOTIFY physicalScreenSizeOverrideChanged) - -public: - B2QtDevice(QObject *parent = 0); - ~B2QtDevice(); - - int displayBrightness() const; - QString hostname() const; - QString getIPAddress() const; - int masterVolume() const; - int physicalScreenSizeInch() const; - bool physicalScreenSizeOverride() const; - - void initAudio(); - -public Q_SLOTS: - void reboot(); - void powerOff(); - - bool setDisplayBrightness(int value); - bool setHostname(const QString &name); - void setMasterVolume(int volume); - void setPhysicalScreenSizeInch(int inches); - void setPhysicalScreenSizeOverride(bool enable); - -signals: - void displayBrightnessChanged(int newValue); - void hostnameChanged(const QString &newName); - void ipAddressChanged(const QString &newAddress); - void masterVolumeChanged(int newVolume); - void physicalScreenSizeInchChanged(int newInches); - void physicalScreenSizeOverrideChanged(bool newValue); -}; - -#endif // B2QTDEVICE_H diff --git a/src/utils/utils.pro b/src/utils/utils.pro deleted file mode 100644 index a9f6041..0000000 --- a/src/utils/utils.pro +++ /dev/null @@ -1,16 +0,0 @@ -load(qt_build_config) - -TARGET = B2QtUtils -VERSION = 1.0 -CONFIG += dll warn_on - -QT = core network - -MODULE = b2qtutils -load(qt_module) - -HEADERS += \ - $$PWD/b2qtdevice.h - -SOURCES += \ - $$PWD/b2qtdevice.cpp diff --git a/src/wifi/qwificonfiguration.cpp b/src/wifi/qwificonfiguration.cpp deleted file mode 100644 index b532620..0000000 --- a/src/wifi/qwificonfiguration.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwificonfiguration.h" - -QT_BEGIN_NAMESPACE - -class QWifiConfigurationPrivate -{ - Q_DECLARE_PUBLIC(QWifiConfiguration) -public: - QWifiConfigurationPrivate(QWifiConfiguration *config); - - // member variables - QWifiConfiguration *const q_ptr; - QString m_ssid; - QString m_psk; - QString m_protocol; - bool m_ssidHidden; -}; - -QWifiConfigurationPrivate::QWifiConfigurationPrivate(QWifiConfiguration *config) - : q_ptr(config) - , m_ssidHidden(false) -{ -} - -/*! - \class QWifiConfiguration - \inmodule B2Qt.Wifi.Cpp - \ingroup wifi-cppclasses - \brief Used to define a network configuration. - - QWifiConfiguration object represents a single network configuration. Use it - to configure properties of your network. For example, passphrase, security - protocol to use, and so on. QWifiManager::connect() function uses this - information to find a network that matches the provided configuration, before - establishing a connection. - */ - -/*! - Constructs a configuration object with parent \a parent. -*/ -QWifiConfiguration::QWifiConfiguration(QObject *parent) - : QObject(parent) - , d_ptr(new QWifiConfigurationPrivate(this)) -{ -} - -/*! - Destroys the configuration object. -*/ -QWifiConfiguration::~QWifiConfiguration() -{ - delete d_ptr; -} - -/*! - \property QWifiConfiguration::ssid - \brief a human-readable name of a Wifi network -*/ -QString QWifiConfiguration::ssid() const -{ - Q_D(const QWifiConfiguration); - return d->m_ssid; -} - -void QWifiConfiguration::setSsid(const QString &ssid) -{ - Q_D(QWifiConfiguration); - d->m_ssid = ssid; -} - -/*! - \property QWifiConfiguration::passphrase - \brief a passphrase to use for authenticating access to a network -*/ -QString QWifiConfiguration::passphrase() const -{ - Q_D(const QWifiConfiguration); - return d->m_psk; -} - -void QWifiConfiguration::setPassphrase(const QString &passphrase) -{ - Q_D(QWifiConfiguration); - d->m_psk = passphrase; -} - -/*! - \property QWifiConfiguration::protocol - \brief a security protocol to use for Wifi connection - - WPA is used by default if protocol is not explicitly set. - Supported values are: WPA, WPA2, WEP, WPS. -*/ -QString QWifiConfiguration::protocol() const -{ - Q_D(const QWifiConfiguration); - return d->m_protocol; -} - -void QWifiConfiguration::setProtocol(const QString &protocol) -{ - Q_D(QWifiConfiguration); - d->m_protocol = protocol; -} - -/*! - \property QWifiConfiguration::ssidHidden - \brief Holds whether a Wifi access point broadcasts its SSID - - If a Wifi access point does not broadcast its SSID, setting this - property to \c true ensures that the Wifi backend can detect the - specified network. - - By default this property is set to \c false. -*/ -bool QWifiConfiguration::isSsidHidden() const -{ - Q_D(const QWifiConfiguration); - return d->m_ssidHidden; -} - -void QWifiConfiguration::setSsidHidden(bool hidden) -{ - Q_D(QWifiConfiguration); - d->m_ssidHidden = hidden; -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwificonfiguration.h b/src/wifi/qwificonfiguration.h deleted file mode 100644 index cdeb453..0000000 --- a/src/wifi/qwificonfiguration.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFICONFIGURATION_H -#define QWIFICONFIGURATION_H - -#include <QtCore/QObject> -#include <QtCore/QString> - -class QWifiConfigurationPrivate; - -QT_BEGIN_NAMESPACE - -class Q_DECL_EXPORT QWifiConfiguration : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString ssid READ ssid WRITE setSsid) - Q_PROPERTY(QString passphrase READ passphrase WRITE setPassphrase) - Q_PROPERTY(QString protocol READ protocol WRITE setProtocol) - Q_PROPERTY(bool ssidHidden READ isSsidHidden WRITE setSsidHidden) -public: - explicit QWifiConfiguration(QObject *parent = 0); - virtual ~QWifiConfiguration(); - - void setSsid(const QString &ssid); - QString ssid() const; - void setPassphrase(const QString &passphrase); - QString passphrase() const; - void setProtocol(const QString &protocol); - QString protocol() const; - void setSsidHidden(bool hidden); - bool isSsidHidden() const; - -private: - Q_DISABLE_COPY(QWifiConfiguration) - Q_DECLARE_PRIVATE(QWifiConfiguration) - QWifiConfigurationPrivate *const d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QWIFICONFIGURATION_H diff --git a/src/wifi/qwifidevice.h b/src/wifi/qwifidevice.h deleted file mode 100644 index 80b4891..0000000 --- a/src/wifi/qwifidevice.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFIDEVICE_H -#define QWIFIDEVICE_H - -#include <QtCore/QObject> -#include <QtCore/QByteArray> -#include <QtCore/QLoggingCategory> - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -class Q_DECL_EXPORT QWifiDevice : public QObject -{ - Q_OBJECT -public: - explicit QWifiDevice(); - virtual ~QWifiDevice(); - - Q_INVOKABLE static bool wifiSupported(); - static QByteArray wifiInterfaceName(); - static void setWifiInterfaceName(const QByteArray &name); -}; - -QT_END_NAMESPACE - -#endif // QWIFIDEVICE_H diff --git a/src/wifi/qwifimanager.cpp b/src/wifi/qwifimanager.cpp deleted file mode 100644 index 0448ec7..0000000 --- a/src/wifi/qwifimanager.cpp +++ /dev/null @@ -1,534 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwificontroller_p.h" -#include "qwifinetworklistmodel_p.h" -#include "qwifinetwork_p.h" -#include "qwifimanager_p.h" -#include "qwifisupplicant_p.h" - -#include "qwifidevice.h" - -#include <QtCore/QFile> -#include <QtCore/QProcess> - -QT_BEGIN_NAMESPACE - -// must be in the same order as in enum {} definiton -const char *nsText[] = { "Disconnected", "Authenticating", "HandshakeFailed", - "ObtainingIPAddress", "DhcpRequestFailed", "Connected" }; -const char *bsText[] = { "Initializing", "Running", "Terminating", "NotRunning" }; - -QWifiManagerPrivate::QWifiManagerPrivate(QWifiManager *manager) - : q_ptr(manager) - , m_networkListModel(new QWifiNetworkListModel(manager)) - , m_scanTimer(0) - , m_scanning(false) - , m_interface(QWifiDevice::wifiInterfaceName()) - , m_backendState(QWifiManager::NotRunning) - , m_networkState(QWifiManager::Disconnected) -{ - qCDebug(B2QT_WIFI) << "using wifi interface: " << m_interface; -} - -QWifiManagerPrivate::~QWifiManagerPrivate() -{ - delete m_wifiController; -} - -void QWifiManagerPrivate::setCurrentSSID(const QString &ssid) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI) << "current SSID: " << m_currentSSID << " -> " << ssid; - if (m_currentSSID == ssid) - return; - - m_currentSSID = ssid; - emit q->currentSSIDChanged(m_currentSSID); -} - -void QWifiManagerPrivate::handleAuthenticating(QWifiEvent *event) -{ - QString data = event->data().trimmed(); - QString ssid = data.mid(data.indexOf(QLatin1String("SSID")) + 6); - ssid = ssid.left(ssid.lastIndexOf(QLatin1Char('\''))); - - setCurrentSSID(QWifiSupplicant::decodeSsid(ssid)); - updateNetworkState(QWifiManager::Authenticating); -} - -void QWifiManagerPrivate::handleConnected() -{ - qCDebug(B2QT_WIFI) << "connected network: " << m_currentSSID; - updateNetworkState(QWifiManager::ObtainingIPAddress); - m_wifiController->asyncCall(QWifiController::AcquireIPAddress); -} - -void QWifiManagerPrivate::handleDisconneced() -{ - updateNetworkState(QWifiManager::Disconnected); -} - -void QWifiManagerPrivate::updateNetworkState(QWifiManager::NetworkState networkState) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI, "network state: %s -> %s", nsText[m_networkState], nsText[networkState]); - if (m_networkState == networkState) - return; - - m_networkState = networkState; - emit q->networkStateChanged(m_networkState); -} - -void QWifiManagerPrivate::updateBackendState(QWifiManager::BackendState backendState) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI, "backend state: %s -> %s", bsText[m_backendState], bsText[backendState]); - if (m_backendState == backendState) - return; - - m_backendState = backendState; - emit q->backendStateChanged(m_backendState); -} - -void QWifiManagerPrivate::updateWifiState() -{ - QProcess ps; - ps.start(QStringLiteral("ps")); - if (!ps.waitForStarted()) { - updateLastError(ps.program() + QLatin1String(": ") + ps.errorString()); - return; - } - - ps.waitForFinished(); - bool supplicantRunning = ps.readAll().contains("wpa_supplicant"); - if (supplicantRunning && m_wifiController->resetSupplicantSocket()) - m_backendState = QWifiManager::Running; -} - -QString QWifiManagerPrivate::call(const QString &command) -{ - if (m_backendState != QWifiManager::Running) - return QString(); - - QByteArray reply; - bool success = m_wifiController->supplicant()->sendCommand(command, &reply); - if (!success) { - qCDebug(B2QT_WIFI) << "call to supplicant failed"; - return QString(); - } - - return QLatin1String(reply.trimmed()); -} - -bool QWifiManagerPrivate::checkedCall(const QString &command) -{ - return call(command).toUpper() == QLatin1String("OK"); -} - -void QWifiManagerPrivate::updateLastError(const QString &error) -{ - Q_Q(QWifiManager); - qCWarning(B2QT_WIFI) << error; - m_lastError = error; - emit q->lastErrorChanged(m_lastError); -} - -/*! - \class QWifiManager - \inmodule B2Qt.Wifi.Cpp - \ingroup wifi-cppclasses - \brief Enables an application to be Wifi-capable. - - QWifiManager is a singleton class that handles Wifi-related tasks. You can - use QWifiManager to control the Wifi backend, scan for Wifi access points, - and connect to a wireless network. - - QWifiManager packs the scan results in a list-based data model, which can - be used with Qt's Model/View classes. Information about a Wifi network can - be accessed using the QWifiManager::Roles data roles. -*/ - -/*! - \enum QWifiManager::NetworkState - - Describes current state of the network connection. - - \value Disconnected Not connected to any network - \value Authenticating Verifying password with the network provider - \value HandshakeFailed Incorrect password provided - \value ObtainingIPAddress Requesting IP address from DHCP server - \value DhcpRequestFailed Could not retrieve IP address - \value Connected Ready to process network requests -*/ - -/*! - \enum QWifiManager::BackendState - - Describes current state of the Wifi backend. - - \value Initializing Wireless supplicant is starting up - \value Running Supplicant is initialized and ready to process commands - \value Terminating Shutting down wireless supplicant - \value NotRunning Wireless supplicant process is not running -*/ - -/*! - \enum QWifiManager::Roles - - Data roles supported by the data model returned from QWifiManager::networks() - - \value SSID informal (human) name of a Wifi network (QString) - \value BSSID basic service set identification of a network, used to uniquely identify BSS (QString) - \value SignalStrength strength of a Wifi signal represented as percentage (0-100) (int) - \value WPASupported holds whether network access point supports WPA security protocol (bool) - \value WPA2Supported holds whether network access point supports WPA2 security protocol (bool) - \value WEPSupported holds whether network access point supports WEP security protocol (bool) - \value WPSSupported holds whether network access point supports WPS security protocol (bool) -*/ - -QWifiManager* QWifiManager::m_instance = 0; - -/*! - Returns a singleton instance of QWifiManager. -*/ -QWifiManager* QWifiManager::instance() -{ - if (!m_instance) - m_instance = new QWifiManager(); - return m_instance; -} - -QWifiManager::QWifiManager() - : d_ptr(new QWifiManagerPrivate(this)) -{ - Q_D(QWifiManager); - - if (!QWifiDevice::wifiSupported()) - qCWarning(B2QT_WIFI) << "WifiManager may not work as expected on this device. Use the API provided by QtWifi " - "library to verify if device has support for Wi-Fi before creating an instance of wifi manager"; - - d->m_wifiController = new QWifiController(this, d_ptr); - QObject::connect(d->m_wifiController, &QWifiController::backendStateChanged, - this, &QWifiManager::handleBackendStateChanged); - QObject::connect(d->m_wifiController, &QWifiController::dhcpRequestFinished, - this, &QWifiManager::handleDhcpRequestFinished); - d->m_wifiController->start(); - - d->updateWifiState(); -} - -/*! - Destroys the QWifiManager singleton instance. - */ -QWifiManager::~QWifiManager() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::ExitEventLoop); - d->m_wifiController->wait(); - delete d_ptr; -} - -/*! - \property QWifiManager::networks - \brief a list-based data model of networks - - Returns a list-based data model of networks that can be sensed by a device. - Model can be used with Qt's Model/View classes such as QListView. Data in - the model is updated every 5 seconds if scanning is enabled. - - \sa isScanning() -*/ -QAbstractListModel *QWifiManager::networks() const -{ - Q_D(const QWifiManager); - return d->m_networkListModel; -} - -/*! - \property QWifiManager::currentSSID - \brief a network name of the last selected network - - The network for which the NetworkState change signals are emitted. - Property can contain an empty string when there is no active network - connection. -*/ -QString QWifiManager::currentSSID() const -{ - Q_D(const QWifiManager); - return d->m_currentSSID; -} - -/*! - \property QWifiManager::networkState - \brief the current network state - - Returns the current network state. -*/ -QWifiManager::NetworkState QWifiManager::networkState() const -{ - Q_D(const QWifiManager); - return d->m_networkState; -} - -/*! - \property QWifiManager::backendState - \brief the current backend state. - - Returns the current backend state. -*/ -QWifiManager::BackendState QWifiManager::backendState() const -{ - Q_D(const QWifiManager); - return d->m_backendState; -} - -/*! - Start the Wifi backend. This function returns immediately, the BackendState - change events are delivered asynchronously. - - \sa stop(), BackendState -*/ -void QWifiManager::start() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::InitializeBackend); -} - -/*! - Stop the Wifi backend. Closes the open network connection if any. - This function returns immediately, and the BackendState change events are - delivered asynchronously. - - \sa start(), BackendState -*/ -void QWifiManager::stop() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::TerminateBackend); -} - -/*! - \property QWifiManager::scanning - \brief whether the backend is scanning for Wifi networks. - - Sets whether to scan the environment for Wifi access points. - - To preserve battery energy, set this property to false when scanning is not required. - When enabled, new readings are taken every 5 seconds. - - \note You must initialize the Wifi backend to scan for networks. - - \sa start() -*/ -bool QWifiManager::isScanning() const -{ - Q_D(const QWifiManager); - return d->m_scanning; -} - -void QWifiManager::setScanning(bool scanning) -{ - Q_D(QWifiManager); - if (d->m_scanning == scanning) - return; - - d->m_scanning = scanning; - emit scanningChanged(d->m_scanning); - if (d->m_scanning) { - d->call(QStringLiteral("SCAN")); - // ### TODO expose this with a property - d->m_scanTimer = startTimer(5000); - } else { - killTimer(d->m_scanTimer); - } -} - -/*! - \property QWifiManager::lastError - \brief a QString containing the last error message set by QWifiManager. - - Returns a QString containing the last error message set by QWifiManager. - This helps in diagnosing the internal process failures. - - \sa connect() -*/ -QString QWifiManager::lastError() const -{ - Q_D(const QWifiManager); - return d->m_lastError; -} - -/*! \reimp */ -bool QWifiManager::event(QEvent *event) -{ - Q_D(QWifiManager); - switch ((int) event->type()) { - case WIFI_SCAN_RESULTS: - d->m_networkListModel->parseScanResults(d->call(QStringLiteral("SCAN_RESULTS"))); - return true; - case WIFI_CONNECTED: - d->handleConnected(); - return true; - case WIFI_DISCONNECTED: - d->handleDisconneced(); - return true; - case WIFI_AUTHENTICATING: - d->handleAuthenticating(static_cast<QWifiEvent *>(event)); - return true; - case WIFI_HANDSHAKE_FAILED: - d->updateNetworkState(QWifiManager::HandshakeFailed); - return true; - case QEvent::Timer: { - int tid = static_cast<QTimerEvent *>(event)->timerId(); - if (tid == d->m_scanTimer) { - d->call(QStringLiteral("SCAN")); - return true; - } - break; - } - } - return QObject::event(event); -} - -/*! - Connect a device to a network using the \a config network configuration. - This method returns \c true if the network with the provided configuration - could be successfully added by the backend or \c false on failure. - Use lastError() to obtain the error message on failure. - - \sa disconnect(), NetworkState, lastError() -*/ -bool QWifiManager::connect(QWifiConfiguration *config) -{ - Q_D(QWifiManager); - if (d->m_backendState != Running) { - qCWarning(B2QT_WIFI) << "start wifi backend before calling connect()"; - return false; - } - - d->call(QStringLiteral("DISABLE_NETWORK all")); - d->setCurrentSSID(config->ssid()); - - bool networkKnown = false; - QString id; - const QStringList configuredNetworks = d->call(QStringLiteral("LIST_NETWORKS")).split('\n'); - for (int i = 1; i < configuredNetworks.length(); ++i) { - const QStringList networkFields = configuredNetworks.at(i).split('\t'); - const QString ssid = QWifiSupplicant::decodeSsid(networkFields.at(1)); - if (ssid == d->m_currentSSID) { - id = networkFields.at(0); - networkKnown = true; - break; - } - } - - if (!networkKnown) { - bool ok; - id = d->call(QStringLiteral("ADD_NETWORK")); - id.toInt(&ok); - if (!ok) { - d->updateLastError(QStringLiteral("failed to add network")); - return false; - } - } - - bool ok = true; - QChar q = QLatin1Char('"'); - QString setNetworkCommand = QLatin1String("SET_NETWORK ") + id; - if (!networkKnown) { - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" ssid ") + q + d->m_currentSSID + q); - } - - QString key_mgmt; - QString protocol = config->protocol().toUpper(); - QString psk = config->passphrase(); - - // --------------------- configure network ------------------------------ - // ref: http://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf - // ref: https://www.freebsd.org/cgi/man.cgi?wpa_supplicant.conf - // ---------------------------------------------------------------------- - if (protocol.isEmpty() || protocol.contains(QStringLiteral("WPA"))) { - // ### TODO - password length has limits (see IEEE 802.11), we need to check - // for those limits here. Supplicant gives only a meaningless "fail" message. - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" psk ") + q + psk + q); - key_mgmt = QLatin1String("WPA-PSK"); - } else if (protocol.contains(QStringLiteral("WEP"))) { - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" wep_key0 ") + q + psk + q); - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" auth_alg OPEN SHARED")); - key_mgmt = QLatin1String("NONE"); - } else if (protocol.contains(QStringLiteral("WPS")) && psk.length() == 0) { - // open network - key_mgmt = QLatin1String("NONE"); - } - - if (config->isSsidHidden()) - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" scan_ssid 1")); - - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" key_mgmt ") + key_mgmt); - if (!ok) { - if (!networkKnown) - d->call(QLatin1String("REMOVE_NETWORK ") + id); - d->updateLastError(QLatin1String("failed to set properties on network: ") + id); - return false; - } - - d->call(QLatin1String("SELECT_NETWORK ") + id); - d->call(QStringLiteral("RECONNECT")); - - return true; -} - -/*! - Disconnect from currently connected network connection. - - \sa connect(), networkState() -*/ -void QWifiManager::disconnect() -{ - Q_D(QWifiManager); - d->call(QStringLiteral("DISCONNECT")); - d->m_wifiController->asyncCall(QWifiController::StopDhcp); -} - -void QWifiManager::handleBackendStateChanged(BackendState backendState) -{ - Q_D(QWifiManager); - switch (backendState) { - case NotRunning: - d->updateNetworkState(Disconnected); - break; - default: - break; - } - d->updateBackendState(backendState); -} - -void QWifiManager::handleDhcpRequestFinished(const QString &status) -{ - Q_D(QWifiManager); - qCDebug(B2QT_WIFI) << "handleDhcpRequestFinished: " << status << " for " << d->m_currentSSID; - if (status == QLatin1String("success")) { - d->updateNetworkState(Connected); - d->call(QStringLiteral("SAVE_CONFIG")); - } else { - d->updateNetworkState(DhcpRequestFailed); - } -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifimanager.h b/src/wifi/qwifimanager.h deleted file mode 100644 index 7fc658c..0000000 --- a/src/wifi/qwifimanager.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFIMANAGER_H -#define QWIFIMANAGER_H - -#include "qwificonfiguration.h" - -#include <QtCore/QObject> -#include <QtCore/QString> -#include <QtCore/QByteArray> -#include <QtCore/QLoggingCategory> - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -class QWifiManagerPrivate; -class QAbstractListModel; -class QWifiController; -class QWifiNetworkListModel; - -class Q_DECL_EXPORT QWifiManager : public QObject -{ - Q_OBJECT - Q_ENUMS(NetworkState) - Q_ENUMS(BackendState) - Q_PROPERTY(NetworkState networkState READ networkState NOTIFY networkStateChanged) - Q_PROPERTY(BackendState backendState READ backendState NOTIFY backendStateChanged) - Q_PROPERTY(bool scanning READ isScanning WRITE setScanning NOTIFY scanningChanged) - Q_PROPERTY(QString currentSSID READ currentSSID NOTIFY currentSSIDChanged) - Q_PROPERTY(QString lastError READ lastError NOTIFY lastErrorChanged) - Q_PROPERTY(QAbstractListModel *networks READ networks CONSTANT) -public: - enum NetworkState { - Disconnected, - Authenticating, - HandshakeFailed, - ObtainingIPAddress, - DhcpRequestFailed, - Connected - }; - - enum BackendState { - Initializing, - Running, - Terminating, - NotRunning - }; - - enum Roles { - SSID = Qt::UserRole + 1, - BSSID = Qt::UserRole + 2, - SignalStrength = Qt::UserRole + 3, - WPASupported = Qt::UserRole + 4, - WPA2Supported = Qt::UserRole + 5, - WEPSupported = Qt::UserRole + 6, - WPSSupported = Qt::UserRole + 7 - }; - - static QWifiManager *instance(); - virtual ~QWifiManager(); - - QAbstractListModel *networks() const; - QString currentSSID() const; - bool isScanning() const; - void setScanning(bool scanning); - NetworkState networkState() const; - BackendState backendState() const; - QString lastError() const; - -public slots: - void start(); - void stop(); - bool connect(QWifiConfiguration *config); - void disconnect(); - -signals: - void scanningChanged(bool scanning); - void networkStateChanged(NetworkState networkState); - void backendStateChanged(BackendState backendState); - void currentSSIDChanged(const QString ¤tSSID); - void lastErrorChanged(const QString &error); - -protected: - bool event(QEvent *event); - -private slots: - void handleBackendStateChanged(BackendState backendState); - void handleDhcpRequestFinished(const QString &status); - -private: - QWifiManager(); - static QWifiManager* m_instance; - friend class QWifiController; - Q_DISABLE_COPY(QWifiManager) - Q_DECLARE_PRIVATE(QWifiManager) - QWifiManagerPrivate *const d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QWIFIMANAGER_H diff --git a/src/wifi/qwifimanager_p.h b/src/wifi/qwifimanager_p.h deleted file mode 100644 index 5449551..0000000 --- a/src/wifi/qwifimanager_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFIMANAGER_P_H -#define QWIFIMANAGER_P_H - -#include "qwifimanager.h" -#include "qwifidevice.h" - -#include <QtCore/QString> - -QT_BEGIN_NAMESPACE - -class QWifiEvent; - -class QWifiManagerPrivate -{ - Q_DECLARE_PUBLIC(QWifiManager) -public: - QWifiManagerPrivate(QWifiManager *manager); - virtual ~QWifiManagerPrivate(); - - // methods - void setCurrentSSID(const QString &ssid); - void handleConnected(); - void handleDisconneced(); - void handleAuthenticating(QWifiEvent *event); - - void updateNetworkState(QWifiManager::NetworkState networkState); - void updateBackendState(QWifiManager::BackendState backendState); - void updateWifiState(); - - QString call(const QString &command); - bool checkedCall(const QString &command); - void updateLastError(const QString &error); - - // member variables - QWifiManager *const q_ptr; - QWifiController *m_wifiController; - QWifiNetworkListModel *m_networkListModel; - - int m_scanTimer; - bool m_scanning; - QByteArray m_interface; - QWifiManager::BackendState m_backendState; - QWifiManager::NetworkState m_networkState; - QString m_currentSSID; - QString m_lastError; -}; - -QT_END_NAMESPACE - -#endif // QWIFIMANAGER_P_H diff --git a/src/wifi/qwifinetwork.cpp b/src/wifi/qwifinetwork.cpp deleted file mode 100644 index eb2b669..0000000 --- a/src/wifi/qwifinetwork.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwifinetwork_p.h" - -QT_BEGIN_NAMESPACE - -QWifiNetwork::QWifiNetwork(QObject *parent) - : QObject(parent) - , m_isOutOfRange(false) -{ -} - -QWifiNetwork::~QWifiNetwork() -{ -} - -void QWifiNetwork::setSsid(const QString &ssid) -{ - m_ssid = ssid; -} - -void QWifiNetwork::setSignalStrength(int strength) -{ - m_signalStrength = strength; -} - -void QWifiNetwork::setOutOfRange(bool outOfRange) -{ - m_isOutOfRange = outOfRange; -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifinetwork_p.h b/src/wifi/qwifinetwork_p.h deleted file mode 100644 index db65e2d..0000000 --- a/src/wifi/qwifinetwork_p.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFINETWORK_H -#define QWIFINETWORK_H - -#include <QtCore/QObject> -#include <QtCore/QString> - -QT_BEGIN_NAMESPACE - -class QWifiNetwork : public QObject -{ - Q_OBJECT -public: - explicit QWifiNetwork(QObject *parent = 0); - virtual ~QWifiNetwork(); - - void setBssid(const QString &bssid) { m_bssid = bssid; } - QString bssid() const { return m_bssid; } - void setSsid(const QString &ssid); - QString ssid() const { return m_ssid; } - - void setSignalStrength(int strength); - int signalStrength() const { return m_signalStrength; } - - void setOutOfRange(bool isOutOfRange); - // this could be exposed in QWifiManager::Roles, - // if there is a use case for it, this would require keeping - // the out of range networks in data model, currently they are - // removed from the model. - bool isOutOfRange() const { return m_isOutOfRange; } - - void setFlags(const QString &flags) { m_flags = flags; } - QString flags() const { return m_flags; } - bool supportsWPA2() const { return m_flags.contains(QStringLiteral("WPA2")); } - bool supportsWPA() const { return m_flags.contains(QStringLiteral("WPA")); } - bool supportsWEP() const { return m_flags.contains(QStringLiteral("WEP")); } - bool supportsWPS() const { return m_flags.contains(QStringLiteral("WPS")); } - -private: - QString m_bssid; - QString m_ssid; - int m_signalStrength; - QString m_flags; - bool m_isOutOfRange; -}; - -QT_END_NAMESPACE - -#endif // QWIFINETWORK_H diff --git a/src/wifi/qwifinetworklistmodel.cpp b/src/wifi/qwifinetworklistmodel.cpp deleted file mode 100644 index fa3f7dc..0000000 --- a/src/wifi/qwifinetworklistmodel.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwifinetworklistmodel_p.h" -#include "qwifinetwork_p.h" -#include "qwifisupplicant_p.h" - -#include "qwifimanager.h" - -#include <QtCore/QSet> -#include <QtCore/QString> -#include <QtCore/QByteArray> - -QT_BEGIN_NAMESPACE - -QWifiNetworkListModel::QWifiNetworkListModel(QObject *parent) - : QAbstractListModel(parent) -{ -} - -QWifiNetworkListModel::~QWifiNetworkListModel() -{ - qDeleteAll(m_networks); - qDeleteAll(m_outOfRangeNetworks); - m_networks.clear(); - m_outOfRangeNetworks.clear(); -} - -QHash<int, QByteArray> QWifiNetworkListModel::roleNames() const -{ - QHash<int, QByteArray> names; - names.insert(QWifiManager::SSID, "ssid"); - names.insert(QWifiManager::BSSID, "bssid"); - names.insert(QWifiManager::SignalStrength, "signalStrength"); - names.insert(QWifiManager::WPASupported, "supportsWPA"); - names.insert(QWifiManager::WPA2Supported, "supportsWPA2"); - names.insert(QWifiManager::WEPSupported, "supportsWEP"); - names.insert(QWifiManager::WPSSupported, "supportsWPS"); - return names; -} - -QVariant QWifiNetworkListModel::data(const QModelIndex &index, int role) const -{ - QWifiNetwork *n = m_networks.at(index.row()); - - switch (role) { - case QWifiManager::SSID: - return n->ssid(); - break; - case QWifiManager::BSSID: - return n->bssid(); - break; - case QWifiManager::SignalStrength: - return n->signalStrength(); - break; - case QWifiManager::WPASupported: - return n->supportsWPA(); - break; - case QWifiManager::WPA2Supported: - return n->supportsWPA2(); - break; - case QWifiManager::WEPSupported: - return n->supportsWEP(); - break; - case QWifiManager::WPSSupported: - return n->supportsWPS(); - break; - default: - break; - } - - return QVariant(); -} - -QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QString &ssid) -{ - int pos = 0; // unused - return networkForSSID(ssid, &pos); -} - -QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QString &ssid, int *pos) -{ - for (int i = 0; i < m_networks.size(); ++i) { - if (m_networks.at(i)->ssid() == ssid) { - if (pos) - *pos = i; - return m_networks.at(i); - } - } - return 0; -} - -QWifiNetwork *QWifiNetworkListModel::outOfRangeListContains(const QString &ssid) -{ - for (int i = 0; i < m_outOfRangeNetworks.length(); ++i) - if (m_outOfRangeNetworks.at(i)->ssid() == ssid) - return m_outOfRangeNetworks.takeAt(i); - return 0; -} - -void QWifiNetworkListModel::parseScanResults(const QString &results) -{ - QStringList lines = results.split('\n'); - QSet<QString> sensibleNetworks; - - for (int i = 1; i < lines.size(); ++i) { - QStringList info = lines.at(i).split('\t'); - if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty()) - continue; - int pos = 0; - - QString ssid = QWifiSupplicant::decodeSsid(info.at(4)); - if (ssid.isEmpty()) - continue; - - sensibleNetworks.insert(ssid); - QWifiNetwork *knownNetwork = networkForSSID(ssid, &pos); - if (!knownNetwork) - knownNetwork = outOfRangeListContains(ssid); - - int signalStrength = info.at(2).trimmed().toInt(); - if (signalStrength < 0) { - // signal is reported in dBm, rough conversion: best = -40, worst = -100 - int val = qAbs(qMax(-100, qMin(signalStrength, -40)) + 40); // clamp and normalize to 0 - signalStrength = 100 - (int) ((100.0 * (double) val) / 60.0); - } else if (signalStrength > 100) { - qCWarning(B2QT_WIFI) << "unexpected value for a signal level: " << signalStrength; - } - - if (!knownNetwork) { - QWifiNetwork *network = new QWifiNetwork(); - network->setOutOfRange(false); - network->setBssid(info.at(0)); - network->setFlags(info.at(3)); - network->setSignalStrength(signalStrength); - network->setSsid(ssid); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << network; - endInsertRows(); - } else { - if (knownNetwork->isOutOfRange()) { - // known network has come back into a range - knownNetwork->setOutOfRange(false); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << knownNetwork; - endInsertRows(); - pos = m_networks.length() - 1; - } - // ssids are the same, compare bssids.. - if (knownNetwork->bssid() == info.at(0)) { - // same access point, simply update the signal strength - knownNetwork->setSignalStrength(signalStrength); - knownNetwork->setOutOfRange(false); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } else if (knownNetwork->signalStrength() < signalStrength) { - // replace with a stronger access point within the same network - m_networks.at(pos)->setOutOfRange(false); - m_networks.at(pos)->setBssid(info.at(0)); - m_networks.at(pos)->setFlags(info.at(3)); - m_networks.at(pos)->setSignalStrength(signalStrength); - m_networks.at(pos)->setSsid(ssid); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } - } - } - // remove out-of-range networks from the data model - for (int i = 0; i < m_networks.size();) { - if (!sensibleNetworks.contains(m_networks.at(i)->ssid())) { - beginRemoveRows(QModelIndex(), i, i); - QWifiNetwork *n = m_networks.takeAt(i); - n->setOutOfRange(true); - m_outOfRangeNetworks.append(n); - endRemoveRows(); - } else { - ++i; - } - } -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifinetworklistmodel_p.h b/src/wifi/qwifinetworklistmodel_p.h deleted file mode 100644 index 25a2b31..0000000 --- a/src/wifi/qwifinetworklistmodel_p.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFINETWORKLISTMODEL_H -#define QWIFINETWORKLISTMODEL_H - -#include <QtCore/QAbstractListModel> -#include <QtCore/QVariant> -#include <QtCore/QList> -#include <QtCore/QHash> -#include <QtCore/QLoggingCategory> - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -class QWifiNetwork; - -class QWifiNetworkListModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit QWifiNetworkListModel(QObject *parent = 0); - virtual ~QWifiNetworkListModel(); - - int rowCount(const QModelIndex &) const { return m_networks.size(); } - QVariant data(const QModelIndex &index, int role) const; - QHash<int,QByteArray> roleNames() const; - - void parseScanResults(const QString &data); - QWifiNetwork *networkForSSID(const QString &ssid); - QWifiNetwork *networkForSSID(const QString &ssid, int *pos); - QWifiNetwork *outOfRangeListContains(const QString &ssid); - -private: - QList<QWifiNetwork *> m_networks; - QList<QWifiNetwork *> m_outOfRangeNetworks; -}; - -QT_END_NAMESPACE - -#endif // QWIFINETWORKLISTMODEL_H diff --git a/src/wifi/qwifisupplicant_p.h b/src/wifi/qwifisupplicant_p.h deleted file mode 100644 index 0a6a964..0000000 --- a/src/wifi/qwifisupplicant_p.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFISUPPLICANT_H -#define QWIFISUPPLICANT_H - -#include <QObject> -#include <QByteArray> -#include <QLoggingCategory> - -#include "wpa-supplicant/wpa_ctrl.h" - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI_VERBOSE) - -class QWifiManagerPrivate; - -class QWifiSupplicant : public QObject -{ - Q_OBJECT -public: - explicit QWifiSupplicant(QObject *parent, QWifiManagerPrivate *managerPrivate); - - void createSupplicantConfig() const; - bool startSupplicant(); - bool stopSupplicant(); - bool connectToSupplicant(); - void closeSupplicantConnection(); - int waitForEvent(char *buf, size_t buflen); - bool sendCommand(const QString &command, QByteArray *reply); - static QString decodeSsid(const QString &encoded); - -protected: - int receiveEvent(char *reply, size_t *reply_len); - -private: - wpa_ctrl *ctrl_conn; - wpa_ctrl *monitor_conn; - int exit_sockets[2]; - QByteArray interface; - QWifiManagerPrivate *const m_managerPrivate; -}; - -QT_END_NAMESPACE - -#endif // QWIFISUPPLICANT_H diff --git a/src/wifi/wifi.pro b/src/wifi/wifi.pro deleted file mode 100644 index faf15f2..0000000 --- a/src/wifi/wifi.pro +++ /dev/null @@ -1,36 +0,0 @@ -load(qt_build_config) - -TARGET = B2QtWifi -VERSION = 1.0 -CONFIG += dll warn_on - -QT += core network - -MODULE = b2qtwifi -load(qt_module) - -HEADERS += \ - $$PWD/qwifimanager.h \ - $$PWD/qwifimanager_p.h \ - $$PWD/qwifinetwork_p.h \ - $$PWD/qwifinetworklistmodel_p.h \ - $$PWD/qwificontroller_p.h \ - $$PWD/qwifidevice.h \ - $$PWD/qwificonfiguration.h \ - $$PWD/qwifisupplicant_p.h - -SOURCES += \ - $$PWD/qwifimanager.cpp \ - $$PWD/qwifinetwork.cpp \ - $$PWD/qwifinetworklistmodel.cpp \ - $$PWD/qwificontroller.cpp \ - $$PWD/qwifidevice.cpp \ - $$PWD/qwificonfiguration.cpp \ - $$PWD/qwifisupplicant.cpp \ - $$[QT_SYSROOT]/usr/include/wpa-supplicant/wpa_ctrl.c \ - $$[QT_SYSROOT]/usr/include/wpa-supplicant/os_unix.c - -DEFINES += \ - CONFIG_CTRL_IFACE \ - CONFIG_CTRL_IFACE_UNIX - diff --git a/sync.profile b/sync.profile index 26efc65..9e75dde 100644 --- a/sync.profile +++ b/sync.profile @@ -1,6 +1,10 @@ %modules = ( # path to module name map - "B2QtUtils" => "$basedir/src/utils", - "B2QtWifi" => "$basedir/src/wifi" + "QtNetworkSettings" => "$basedir/src/networksettings", + "QtBluetoothSettings" => "$basedir/src/bluetoothsettings", + "QtLocaleSettings" => "$basedir/src/localesettings", + "QtTimeDateSettings" => "$basedir/src/timedatesettings", + "QtDisplaySettings" => "$basedir/src/displaysettings", + "QtLocalDevice" => "$basedir/src/localdevice" ); %moduleheaders = ( # restrict the module headers to those found in relative path ); |