diff --git a/LICENSES/LGPL-2.1-only.txt b/LICENSES/LGPL-2.1-only.txt new file mode 100644 index 000000000..130dffb31 --- /dev/null +++ b/LICENSES/LGPL-2.1-only.txt @@ -0,0 +1,467 @@ +GNU LESSER GENERAL PUBLIC LICENSE + +Version 2.1, February 1999 + +Copyright (C) 1991, 1999 Free Software Foundation, Inc. + +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts as the +successor of the GNU Library Public License, version 2, hence the version +number 2.1.] + +Preamble + +The licenses for most software are designed to take away your freedom to share +and change it. By contrast, the GNU General Public Licenses are intended to +guarantee your freedom to share and change free software--to make sure the +software is free for all its users. + +This license, the Lesser General Public License, applies to some specially +designated software packages--typically libraries--of the Free Software Foundation +and other authors who decide to use it. You can use it too, but we suggest +you first think carefully about whether this license or the ordinary General +Public License is the better strategy to use in any particular case, based +on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. +Our General Public Licenses are designed to make sure that you have the freedom +to distribute copies of free software (and charge for this service if you +wish); that you receive source code or can get it if you want it; that you +can change the software and use pieces of it in new free programs; and that +you are informed that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors +to deny you these rights or to ask you to surrender these rights. These restrictions +translate to certain responsibilities for you if you distribute copies of +the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for +a fee, you must give the recipients all the rights that we gave you. You must +make sure that they, too, receive or can get the source code. If you link +other code with the library, you must provide complete object files to the +recipients, so that they can relink them with the library after making changes +to the library and recompiling it. And you must show them these terms so they +know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, +and (2) we offer you this license, which gives you legal permission to copy, +distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no +warranty for the free library. Also, if the library is modified by someone +else and passed on, the recipients should know that what they have is not +the original version, so that the original author's reputation will not be +affected by problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free +program. We wish to make sure that a company cannot effectively restrict the +users of a free program by obtaining a restrictive license from a patent holder. +Therefore, we insist that any patent license obtained for a version of the +library must be consistent with the full freedom of use specified in this +license. + +Most GNU software, including some libraries, is covered by the ordinary GNU +General Public License. This license, the GNU Lesser General Public License, +applies to certain designated libraries, and is quite different from the ordinary +General Public License. We use this license for certain libraries in order +to permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared +library, the combination of the two is legally speaking a combined work, a +derivative of the original library. The ordinary General Public License therefore +permits such linking only if the entire combination fits its criteria of freedom. +The Lesser General Public License permits more lax criteria for linking other +code with the library. + +We call this license the "Lesser" General Public License because it does Less +to protect the user's freedom than the ordinary General Public License. It +also provides other free software developers Less of an advantage over competing +non-free programs. These disadvantages are the reason we use the ordinary +General Public License for many libraries. However, the Lesser license provides +advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the +widest possible use of a certain library, so that it becomes a de-facto standard. +To achieve this, non-free programs must be allowed to use the library. A more +frequent case is that a free library does the same job as widely used non-free +libraries. In this case, there is little to gain by limiting the free library +to free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs +enables a greater number of people to use a large body of free software. For +example, permission to use the GNU C Library in non-free programs enables +many more people to use the whole GNU operating system, as well as its variant, +the GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' +freedom, it does ensure that the user of a program that is linked with the +Library has the freedom and the wherewithal to run that program using a modified +version of the Library. + +The precise terms and conditions for copying, distribution and modification +follow. Pay close attention to the difference between a "work based on the +library" and a "work that uses the library". The former contains code derived +from the library, whereas the latter must be combined with the library in +order to run. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other program +which contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Lesser General +Public License (also called "this License"). Each licensee is addressed as +"you". + +A "library" means a collection of software functions and/or data prepared +so as to be conveniently linked with application programs (which use some +of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has +been distributed under these terms. A "work based on the Library" means either +the Library or any derivative work under copyright law: that is to say, a +work containing the Library or a portion of it, either verbatim or with modifications +and/or translated straightforwardly into another language. (Hereinafter, translation +is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications +to it. For a library, complete source code means all the source code for all +modules it contains, plus any associated interface definition files, plus +the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered +by this License; they are outside its scope. The act of running a program +using the Library is not restricted, and output from such a program is covered +only if its contents constitute a work based on the Library (independent of +the use of the Library in a tool for writing it). Whether that is true depends +on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and disclaimer +of warranty; keep intact all the notices that refer to this License and to +the absence of any warranty; and distribute a copy of this License along with +the Library. + +You may charge a fee for the physical act of transferring a copy, and you +may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, +thus forming a work based on the Library, and copy and distribute such modifications +or work under the terms of Section 1 above, provided that you also meet all +of these conditions: + + a) The modified work must itself be a software library. + +b) You must cause the files modified to carry prominent notices stating that +you changed the files and the date of any change. + +c) You must cause the whole of the work to be licensed at no charge to all +third parties under the terms of this License. + +d) If a facility in the modified Library refers to a function or a table of +data to be supplied by an application program that uses the facility, other +than as an argument passed when the facility is invoked, then you must make +a good faith effort to ensure that, in the event an application does not supply +such function or table, the facility still operates, and performs whatever +part of its purpose remains meaningful. + +(For example, a function in a library to compute square roots has a purpose +that is entirely well-defined independent of the application. Therefore, Subsection +2d requires that any application-supplied function or table used by this function +must be optional: if the application does not supply it, the square root function +must still compute square roots.) + +These requirements apply to the modified work as a whole. If identifiable +sections of that work are not derived from the Library, and can be reasonably +considered independent and separate works in themselves, then this License, +and its terms, do not apply to those sections when you distribute them as +separate works. But when you distribute the same sections as part of a whole +which is a work based on the Library, the distribution of the whole must be +on the terms of this License, whose permissions for other licensees extend +to the entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest your +rights to work written entirely by you; rather, the intent is to exercise +the right to control the distribution of derivative or collective works based +on the Library. + +In addition, mere aggregation of another work not based on the Library with +the Library (or with a work based on the Library) on a volume of a storage +or distribution medium does not bring the other work under the scope of this +License. + +3. You may opt to apply the terms of the ordinary GNU General Public License +instead of this License to a given copy of the Library. To do this, you must +alter all the notices that refer to this License, so that they refer to the +ordinary GNU General Public License, version 2, instead of to this License. +(If a newer version than version 2 of the ordinary GNU General Public License +has appeared, then you can specify that version instead if you wish.) Do not +make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, +so the ordinary GNU General Public License applies to all subsequent copies +and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library +into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of +it, under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you accompany it with the complete corresponding +machine-readable source code, which must be distributed under the terms of +Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated +place, then offering equivalent access to copy the source code from the same +place satisfies the requirement to distribute the source code, even though +third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but +is designed to work with the Library by being compiled or linked with it, +is called a "work that uses the Library". Such a work, in isolation, is not +a derivative work of the Library, and therefore falls outside the scope of +this License. + +However, linking a "work that uses the Library" with the Library creates an +executable that is a derivative of the Library (because it contains portions +of the Library), rather than a "work that uses the library". The executable +is therefore covered by this License. Section 6 states terms for distribution +of such executables. + +When a "work that uses the Library" uses material from a header file that +is part of the Library, the object code for the work may be a derivative work +of the Library even though the source code is not. Whether this is true is +especially significant if the work can be linked without the Library, or if +the work is itself a library. The threshold for this to be true is not precisely +defined by law. + +If such an object file uses only numerical parameters, data structure layouts +and accessors, and small macros and small inline functions (ten lines or less +in length), then the use of the object file is unrestricted, regardless of +whether it is legally a derivative work. (Executables containing this object +code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute +the object code for the work under the terms of Section 6. Any executables +containing that work also fall under Section 6, whether or not they are linked +directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work +that uses the Library" with the Library to produce a work containing portions +of the Library, and distribute that work under terms of your choice, provided +that the terms permit modification of the work for the customer's own use +and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library +is used in it and that the Library and its use are covered by this License. +You must supply a copy of this License. If the work during execution displays +copyright notices, you must include the copyright notice for the Library among +them, as well as a reference directing the user to the copy of this License. +Also, you must do one of these things: + +a) Accompany the work with the complete corresponding machine-readable source +code for the Library including whatever changes were used in the work (which +must be distributed under Sections 1 and 2 above); and, if the work is an +executable linked with the Library, with the complete machine-readable "work +that uses the Library", as object code and/or source code, so that the user +can modify the Library and then relink to produce a modified executable containing +the modified Library. (It is understood that the user who changes the contents +of definitions files in the Library will not necessarily be able to recompile +the application to use the modified definitions.) + +b) Use a suitable shared library mechanism for linking with the Library. A +suitable mechanism is one that (1) uses at run time a copy of the library +already present on the user's computer system, rather than copying library +functions into the executable, and (2) will operate properly with a modified +version of the library, if the user installs one, as long as the modified +version is interface-compatible with the version that the work was made with. + +c) Accompany the work with a written offer, valid for at least three years, +to give the same user the materials specified in Subsection 6a, above, for +a charge no more than the cost of performing this distribution. + +d) If distribution of the work is made by offering access to copy from a designated +place, offer equivalent access to copy the above specified materials from +the same place. + +e) Verify that the user has already received a copy of these materials or +that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must +include any data and utility programs needed for reproducing the executable +from it. However, as a special exception, the materials to be distributed +need not include anything that is normally distributed (in either source or +binary form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component itself +accompanies the executable. + +It may happen that this requirement contradicts the license restrictions of +other proprietary libraries that do not normally accompany the operating system. +Such a contradiction means you cannot use both them and the Library together +in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side +in a single library together with other library facilities not covered by +this License, and distribute such a combined library, provided that the separate +distribution of the work based on the Library and of the other library facilities +is otherwise permitted, and provided that you do these two things: + +a) Accompany the combined library with a copy of the same work based on the +Library, uncombined with any other library facilities. This must be distributed +under the terms of the Sections above. + +b) Give prominent notice with the combined library of the fact that part of +it is a work based on the Library, and explaining where to find the accompanying +uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library +except as expressly provided under this License. Any attempt otherwise to +copy, modify, sublicense, link with, or distribute the Library is void, and +will automatically terminate your rights under this License. However, parties +who have received copies, or rights, from you under this License will not +have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed +it. However, nothing else grants you permission to modify or distribute the +Library or its derivative works. These actions are prohibited by law if you +do not accept this License. Therefore, by modifying or distributing the Library +(or any work based on the Library), you indicate your acceptance of this License +to do so, and all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), +the recipient automatically receives a license from the original licensor +to copy, distribute, link with or modify the Library subject to these terms +and conditions. You may not impose any further restrictions on the recipients' +exercise of the rights granted herein. You are not responsible for enforcing +compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement +or for any other reason (not limited to patent issues), conditions are imposed +on you (whether by court order, agreement or otherwise) that contradict the +conditions of this License, they do not excuse you from the conditions of +this License. If you cannot distribute so as to satisfy simultaneously your +obligations under this License and any other pertinent obligations, then as +a consequence you may not distribute the Library at all. For example, if a +patent license would not permit royalty-free redistribution of the Library +by all those who receive copies directly or indirectly through you, then the +only way you could satisfy both it and this License would be to refrain entirely +from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents +or other property right claims or to contest validity of any such claims; +this section has the sole purpose of protecting the integrity of the free +software distribution system which is implemented by public license practices. +Many people have made generous contributions to the wide range of software +distributed through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing to +distribute software through any other system and a licensee cannot impose +that choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Library under this License may add an explicit geographical +distribution limitation excluding those countries, so that distribution is +permitted only in or among countries not thus excluded. In such case, this +License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of +the Lesser General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to address +new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies +a version number of this License which applies to it and "any later version", +you have the option of following the terms and conditions either of that version +or of any later version published by the Free Software Foundation. If the +Library does not specify a license version number, you may choose any version +ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs +whose distribution conditions are incompatible with these, write to the author +to ask for permission. For software which is copyrighted by the Free Software +Foundation, write to the Free Software Foundation; we sometimes make exceptions +for this. Our decision will be guided by the two goals of preserving the free +status of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR +THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE +STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY +"AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE +OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE +THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE +OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA +OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES +OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH +HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Libraries + +If you develop a new library, and you want it to be of the greatest possible +use to the public, we recommend making it free software that everyone can +redistribute and change. You can do so by permitting redistribution under +these terms (or, alternatively, under the terms of the ordinary General Public +License). + +To apply these terms, attach the following notices to the library. It is safest +to attach them to the start of each source file to most effectively convey +the exclusion of warranty; and each file should have at least the "copyright" +line and a pointer to where the full notice is found. + +< one line to give the library's name and an idea of what it does. > + +Copyright (C) < year > < name of author > + +This library is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free +Software Foundation; either version 2.1 of the License, or (at your option) +any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +details. + +You should have received a copy of the GNU Lesser General Public License along +with this library; if not, write to the Free Software Foundation, Inc., 51 +Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information +on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, +if any, to sign a "copyright disclaimer" for the library, if necessary. Here +is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in + +the library `Frob' (a library for tweaking knobs) written + +by James Random Hacker. + +< signature of Ty Coon > , 1 April 1990 + +Ty Coon, President of Vice + +That's all there is to it! diff --git a/LICENSES/LGPL-3.0-only.txt b/LICENSES/LGPL-3.0-only.txt new file mode 100644 index 000000000..bd405afbe --- /dev/null +++ b/LICENSES/LGPL-3.0-only.txt @@ -0,0 +1,163 @@ +GNU LESSER GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +This version of the GNU Lesser General Public License incorporates the terms +and conditions of version 3 of the GNU General Public License, supplemented +by the additional permissions listed below. + + 0. Additional Definitions. + + + +As used herein, "this License" refers to version 3 of the GNU Lesser General +Public License, and the "GNU GPL" refers to version 3 of the GNU General Public +License. + + + +"The Library" refers to a covered work governed by this License, other than +an Application or a Combined Work as defined below. + + + +An "Application" is any work that makes use of an interface provided by the +Library, but which is not otherwise based on the Library. Defining a subclass +of a class defined by the Library is deemed a mode of using an interface provided +by the Library. + + + +A "Combined Work" is a work produced by combining or linking an Application +with the Library. The particular version of the Library with which the Combined +Work was made is also called the "Linked Version". + + + +The "Minimal Corresponding Source" for a Combined Work means the Corresponding +Source for the Combined Work, excluding any source code for portions of the +Combined Work that, considered in isolation, are based on the Application, +and not on the Linked Version. + + + +The "Corresponding Application Code" for a Combined Work means the object +code and/or source code for the Application, including any data and utility +programs needed for reproducing the Combined Work from the Application, but +excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + +You may convey a covered work under sections 3 and 4 of this License without +being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + +If you modify a copy of the Library, and, in your modifications, a facility +refers to a function or data to be supplied by an Application that uses the +facility (other than as an argument passed when the facility is invoked), +then you may convey a copy of the modified version: + +a) under this License, provided that you make a good faith effort to ensure +that, in the event an Application does not supply the function or data, the +facility still operates, and performs whatever part of its purpose remains +meaningful, or + +b) under the GNU GPL, with none of the additional permissions of this License +applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + +The object code form of an Application may incorporate material from a header +file that is part of the Library. You may convey such object code under terms +of your choice, provided that, if the incorporated material is not limited +to numerical parameters, data structure layouts and accessors, or small macros, +inline functions and templates (ten or fewer lines in length), you do both +of the following: + +a) Give prominent notice with each copy of the object code that the Library +is used in it and that the Library and its use are covered by this License. + +b) Accompany the object code with a copy of the GNU GPL and this license document. + + 4. Combined Works. + +You may convey a Combined Work under terms of your choice that, taken together, +effectively do not restrict modification of the portions of the Library contained +in the Combined Work and reverse engineering for debugging such modifications, +if you also do each of the following: + +a) Give prominent notice with each copy of the Combined Work that the Library +is used in it and that the Library and its use are covered by this License. + +b) Accompany the Combined Work with a copy of the GNU GPL and this license +document. + +c) For a Combined Work that displays copyright notices during execution, include +the copyright notice for the Library among these notices, as well as a reference +directing the user to the copies of the GNU GPL and this license document. + + d) Do one of the following: + +0) Convey the Minimal Corresponding Source under the terms of this License, +and the Corresponding Application Code in a form suitable for, and under terms +that permit, the user to recombine or relink the Application with a modified +version of the Linked Version to produce a modified Combined Work, in the +manner specified by section 6 of the GNU GPL for conveying Corresponding Source. + +1) Use a suitable shared library mechanism for linking with the Library. A +suitable mechanism is one that (a) uses at run time a copy of the Library +already present on the user's computer system, and (b) will operate properly +with a modified version of the Library that is interface-compatible with the +Linked Version. + +e) Provide Installation Information, but only if you would otherwise be required +to provide such information under section 6 of the GNU GPL, and only to the +extent that such information is necessary to install and execute a modified +version of the Combined Work produced by recombining or relinking the Application +with a modified version of the Linked Version. (If you use option 4d0, the +Installation Information must accompany the Minimal Corresponding Source and +Corresponding Application Code. If you use option 4d1, you must provide the +Installation Information in the manner specified by section 6 of the GNU GPL +for conveying Corresponding Source.) + + 5. Combined Libraries. + +You may place library facilities that are a work based on the Library side +by side in a single library together with other library facilities that are +not Applications and are not covered by this License, and convey such a combined +library under terms of your choice, if you do both of the following: + +a) Accompany the combined library with a copy of the same work based on the +Library, uncombined with any other library facilities, conveyed under the +terms of this License. + +b) Give prominent notice with the combined library that part of it is a work +based on the Library, and explaining where to find the accompanying uncombined +form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + +The Free Software Foundation may publish revised and/or new versions of the +GNU Lesser General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to address +new problems or concerns. + +Each version is given a distinguishing version number. If the Library as you +received it specifies that a certain numbered version of the GNU Lesser General +Public License "or any later version" applies to it, you have the option of +following the terms and conditions either of that published version or of +any later version published by the Free Software Foundation. If the Library +as you received it does not specify a version number of the GNU Lesser General +Public License, you may choose any version of the GNU Lesser General Public +License ever published by the Free Software Foundation. + +If the Library as you received it specifies that a proxy can decide whether +future versions of the GNU Lesser General Public License shall apply, that +proxy's public statement of acceptance of any version is permanent authorization +for you to choose that version for the Library. diff --git a/LICENSES/LicenseRef-KDE-Accepted-LGPL.txt b/LICENSES/LicenseRef-KDE-Accepted-LGPL.txt new file mode 100644 index 000000000..232b3c5da --- /dev/null +++ b/LICENSES/LicenseRef-KDE-Accepted-LGPL.txt @@ -0,0 +1,12 @@ +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 3 of the license or (at your option) any later version +that is accepted by the membership of KDE e.V. (or its successor +approved by the membership of KDE e.V.), which shall act as a +proxy as defined in Section 6 of version 3 of the license. + +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. diff --git a/archlinux/PKGBUILD b/archlinux/PKGBUILD index 42e0dfcc9..af446f913 100644 --- a/archlinux/PKGBUILD +++ b/archlinux/PKGBUILD @@ -41,6 +41,7 @@ makedepends=('git' 'ninja' 'extra-cmake-modules' 'wayland-protocols' + 'libnm' ) conflicts=('dde-shell') provides=('dde-shell') diff --git a/debian/control b/debian/control index 3e6660478..33040c575 100644 --- a/debian/control +++ b/debian/control @@ -43,6 +43,7 @@ Build-Depends: libxres-dev, libxtst-dev, libdframeworkdbus-dev, + libnm-dev (>= 1.4.0~), Standards-Version: 3.9.8 Homepage: http://www.deepin.org diff --git a/debian/dde-shell.install b/debian/dde-shell.install index 3d19ddedb..17a122b62 100644 --- a/debian/dde-shell.install +++ b/debian/dde-shell.install @@ -10,6 +10,8 @@ usr/lib/*/dde-shell/org.deepin.ds.notification* usr/share/dde-shell/org.deepin.ds.notification*/ usr/lib/*/dde-shell/org.deepin.ds.dde-appearance* usr/share/dde-shell/org.deepin.ds.dde-appearance*/ +usr/lib/*/dde-shell/org.deepin.ds.dde-am* +usr/share/dde-shell/org.deepin.ds.dde-am*/ usr/libexec/dockplugin-loader usr/lib/*/qt5/plugins/wayland-shell-integration usr/lib/*/libdde-dockplugin-interface.so.* @@ -18,3 +20,4 @@ usr/lib/dde-dock/tmp/plugins usr/lib/dde-dock/tmp/plugins/quick-trays usr/share/dde-dock/tmp/translations usr/share/dde-shell/*/translations +usr/share/dock-network-plugin/tmp/translations diff --git a/panels/dock/tray/CMakeLists.txt b/panels/dock/tray/CMakeLists.txt index 660c789df..ceac788a5 100644 --- a/panels/dock/tray/CMakeLists.txt +++ b/panels/dock/tray/CMakeLists.txt @@ -74,28 +74,6 @@ endfunction(generation_dbus_interface) file(GLOB INTERFACES "interfaces/*.h") add_definitions(-DCVERSION="${VERSION}") -#因为单元测试需要直接测试源代码,而主程序代码中include的单元使用了相对路径 -#单元测试的CMakeLists和主程序的CMakeLists路径不同,编译单元测试时会提示找不到文件 -#因此设置搜索路径 -include_directories( - frame/accessible - frame/controller - frame/dbus - frame/dbus/sni - frame/display - frame/item - frame/item/components - frame/item/resources - frame/model - frame/util - frame/window - frame/window/components - frame/window/tray - frame/window/tray/widgets - frame/xcb - ../widgets - ../interfaces - ) aux_source_directory(frame/accessible ACCESSIBLE) aux_source_directory(frame/controller CONTROLLER) aux_source_directory(frame/dbus DBUS) @@ -129,9 +107,34 @@ file(GLOB SRC_PATH ${XCB} ) +add_subdirectory("networkmanager-qt") add_subdirectory("frame") add_subdirectory("plugins") add_subdirectory("libdbusmenu-qt") + +#因为单元测试需要直接测试源代码,而主程序代码中include的单元使用了相对路径 +#单元测试的CMakeLists和主程序的CMakeLists路径不同,编译单元测试时会提示找不到文件 +#因此设置搜索路径 +# include_directories( +# frame/accessible +# frame/controller +# frame/dbus +# frame/dbus/sni +# frame/display +# frame/item +# frame/item/components +# frame/item/resources +# frame/model +# frame/util +# frame/window +# frame/window/components +# frame/window/tray +# frame/window/tray/widgets +# frame/xcb +# ../widgets +# ../interfaces +# ) + ## qm files file(GLOB QM_FILES "translations/*.qm") install(FILES ${QM_FILES} diff --git a/panels/dock/tray/frame/CMakeLists.txt b/panels/dock/tray/frame/CMakeLists.txt index 8f18c24d9..dd676e37d 100644 --- a/panels/dock/tray/frame/CMakeLists.txt +++ b/panels/dock/tray/frame/CMakeLists.txt @@ -53,6 +53,7 @@ target_include_directories(${BIN_NAME} PUBLIC accessible controller dbus + dbus/sni display item item/components diff --git a/panels/dock/tray/networkmanager-qt/CMakeLists.txt b/panels/dock/tray/networkmanager-qt/CMakeLists.txt new file mode 100644 index 000000000..a76256e2c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/CMakeLists.txt @@ -0,0 +1,101 @@ +cmake_minimum_required(VERSION 3.16) + +set(KF_VERSION "5.103.0") # handled by release scripts +project(NetworkManagerQt VERSION ${KF_VERSION}) + +include(FeatureSummary) +find_package(ECM 5.103.0 NO_MODULE) +set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://commits.kde.org/extra-cmake-modules") +feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) + + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${ECM_MODULE_PATH}) + +find_package(PkgConfig) +pkg_search_module(NetworkManager REQUIRED IMPORTED_TARGET libnm>=1.4.0) +pkg_search_module(Gio REQUIRED IMPORTED_TARGET gio-2.0) + +include(KDEInstallDirs) +include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) +include(KDECMakeSettings) + +include(KDEGitCommitHooks) +include(ECMDeprecationSettings) + +set(REQUIRED_QT_VERSION 6.6.1) +set(QT_MAJOR_VERSION 6) +find_package(Qt${QT_MAJOR_VERSION} ${REQUIRED_QT_VERSION} REQUIRED Core DBus Network) + +remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_FROM_BYTEARRAY) + + +include(GenerateExportHeader) + +include(ECMSetupVersion) +include(ECMGenerateHeaders) +include(ECMAddQch) +include(ECMQtDeclareLoggingCategory) + +set(BUILD_TESTING OFF) +option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) +add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") + +ecm_setup_version(PROJECT VARIABLE_PREFIX NETWORKMANAGERQT + VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/networkmanagerqt_version.h" + PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5NetworkManagerQtConfigVersion.cmake" + SOVERSION 6) +ecm_set_disabled_deprecation_versions( + QT 6.6.1 +) + +# Enable unit testing +if (BUILD_TESTING) + add_subdirectory(src/fakenetwork) + add_subdirectory(autotests) +endif () + +add_subdirectory(src) +################## examples ################################ +option(BUILD_EXAMPLES "Build example applications" FALSE) +if (BUILD_EXAMPLES) + add_subdirectory(examples) +endif(BUILD_EXAMPLES) + +# create a Config.cmake and a ConfigVersion.cmake file and install them +set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5NetworkManagerQt") + +if (BUILD_QCH) + ecm_install_qch_export( + TARGETS KF5NetworkManagerQt_QCH + FILE KF5NetworkManagerQtQchTargets.cmake + DESTINATION "${CMAKECONFIG_INSTALL_DIR}" + COMPONENT Devel + ) + set(PACKAGE_INCLUDE_QCHTARGETS "include(\"\${CMAKE_CURRENT_LIST_DIR}/KF5NetworkManagerQtQchTargets.cmake\")") +endif() + +include(CMakePackageConfigHelpers) + +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/KF5NetworkManagerQtConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/KF5NetworkManagerQtConfig.cmake" + INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} +) + +# install(FILES +# "${CMAKE_CURRENT_BINARY_DIR}/KF5NetworkManagerQtConfig.cmake" +# "${CMAKE_CURRENT_BINARY_DIR}/KF5NetworkManagerQtConfigVersion.cmake" +# DESTINATION "${CMAKECONFIG_INSTALL_DIR}" +# COMPONENT Devel +# ) + +# install(EXPORT KF5NetworkManagerQtTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5NetworkManagerQtTargets.cmake NAMESPACE KF5:: ) + +# install(FILES +# ${CMAKE_CURRENT_BINARY_DIR}/networkmanagerqt_version.h +# DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/NetworkManagerQt COMPONENT Devel +# ) + +feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) + +kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT) diff --git a/panels/dock/tray/networkmanager-qt/KF5NetworkManagerQtConfig.cmake.in b/panels/dock/tray/networkmanager-qt/KF5NetworkManagerQtConfig.cmake.in new file mode 100644 index 000000000..15284bd75 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/KF5NetworkManagerQtConfig.cmake.in @@ -0,0 +1,12 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +find_dependency(Qt@QT_MAJOR_VERSION@Core @REQUIRED_QT_VERSION@) +find_dependency(Qt@QT_MAJOR_VERSION@DBus @REQUIRED_QT_VERSION@) + +find_package(PkgConfig) +pkg_search_module(NetworkManager REQUIRED IMPORTED_TARGET libnm>=1.4.0) +pkg_search_module(Gio REQUIRED IMPORTED_TARGET gio-2.0) + +include("${CMAKE_CURRENT_LIST_DIR}/KF5NetworkManagerQtTargets.cmake") +@PACKAGE_INCLUDE_QCHTARGETS@ diff --git a/panels/dock/tray/networkmanager-qt/README.md b/panels/dock/tray/networkmanager-qt/README.md new file mode 100644 index 000000000..b75076ded --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/README.md @@ -0,0 +1,11 @@ +# NetworkManagerQt + +Qt wrapper for NetworkManager DBus API. + +## Introduction + +NetworkManagerQt provides access to all NetworkManager features +exposed on DBus. It allows you to manage your connections and control +your network devices and also provides a library for parsing connection +settings which are used in DBus communication. + diff --git a/panels/dock/tray/networkmanager-qt/TODO b/panels/dock/tray/networkmanager-qt/TODO new file mode 100644 index 000000000..e9b167707 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/TODO @@ -0,0 +1,92 @@ +== NetworkManager 1.0/1.2/1.4/1.6/1.8 == + +* New interfaces: + - org.freedesktop.NetworkManager.DnsManager + - org.freedesktop.NetworkManager.Device.Vxlan + - org.freedesktop.NetworkManager.Device.MacSec + - org.freedesktop.NetworkManager.Device.Dummy + +* New properties/slots/signals: + - org.freedesktop.NetworkManager + ------------------------------- + - Methods: + - GetAllDevices() + - Reload() + - CheckpointCreate() + - CheckpointDestroy() + - CheckpointRollback() + - Properties: + - GlobalDnsConfiguration + + - org.freedesktop.NetworkManager.Device + ------------------------------------- + - Methods: + - Reapply() + - GetAppliedConnection() + - Properties: + - LldpNeighbors + - Real + + - org.freedesktop.NetworkManager.IP4Config + ---------------------------------------- + - Properties: + - DnsPriority + - WinServers + + - org.freedesktop.NetworkManager.IP6Config + ---------------------------------------- + - Properties: + - DnsPriority + +* New settings and settings properties: + - dcb setting + ----------------- + - completely + + - dummy setting + ----------------- + - completely + + - ip-tunnel setting + ----------------- + - completely + + - macsec setting + ----------------- + - completely + + - proxy setting + ----------------- + - completely + + - team-port setting + ----------------- + - completely + + - user setting + ----------------- + - completely + + - vxlan setting + ----------------- + - completely + + - ipv4 setting + ----------------- + - address-data + - dad-timeout + - dhcp-fqdn + - dns-options + - dns-priority + - route-data + + - ipv6 setting + ----------------- + - addr-gen-mode + - address-data + - dad-timeout + - dhcp-timeout + - dhcp-fqdn + - dns-options + - route-data + - token diff --git a/panels/dock/tray/networkmanager-qt/metainfo.yaml b/panels/dock/tray/networkmanager-qt/metainfo.yaml new file mode 100644 index 000000000..911b05705 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/metainfo.yaml @@ -0,0 +1,20 @@ +maintainer: + - grulich + - lvsouza + - lukas +description: Qt wrapper for NetworkManager API +tier: 1 +type: integration +platforms: + - name: Linux + note: Functional only with running NetworkManager +portingAid: false +deprecated: false +release: true +libraries: + - cmake: "KF5NetworkManagerQt" +cmakename: KF5NetworkManagerQt + +public_lib: true +group: Frameworks +subgroup: Tier 1 diff --git a/panels/dock/tray/networkmanager-qt/src/CMakeLists.txt b/panels/dock/tray/networkmanager-qt/src/CMakeLists.txt new file mode 100644 index 000000000..f2983b5b1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/CMakeLists.txt @@ -0,0 +1,299 @@ +# add_subdirectory(dbus) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/dbus + ${CMAKE_CURRENT_SOURCE_DIR}/settings +) + +set(NetworkManagerQt_PART_SRCS + device.cpp + accesspoint.cpp + activeconnection.cpp + adsldevice.cpp + bluetoothdevice.cpp + bonddevice.cpp + bridgedevice.cpp + connection.cpp + dhcp4config.cpp + dhcp6config.cpp + devicestatistics.cpp + dnsconfiguration.cpp + dnsdomain.cpp + infinibanddevice.cpp + ipaddress.cpp + iproute.cpp + ipconfig.cpp + manager.cpp + modemdevice.cpp + olpcmeshdevice.cpp + secretagent.cpp + settings.cpp + utils.cpp + vlandevice.cpp + vpnconnection.cpp + vpnplugin.cpp + wimaxdevice.cpp + wimaxnsp.cpp + wireddevice.cpp + wirelessdevice.cpp + wirelessnetwork.cpp + generictypes.cpp + genericdevice.cpp + gredevice.cpp + iptunneldevice.cpp + macvlandevice.cpp + teamdevice.cpp + tundevice.cpp + vethdevice.cpp + wimaxdevice.cpp + wimaxnsp.cpp + wireguarddevice.cpp +) + +set(NetworkManagerQt_SETTINGS_SRCS + settings/adslsetting.cpp + settings/bluetoothsetting.cpp + settings/bondsetting.cpp + settings/bridgesetting.cpp + settings/bridgeportsetting.cpp + settings/cdmasetting.cpp + settings/connectionsettings.cpp + settings/dcbsetting.cpp + settings/gsmsetting.cpp + settings/iptunnelsetting.cpp + settings/ipv4setting.cpp + settings/ipv6setting.cpp + settings/infinibandsetting.cpp + settings/macsecsetting.cpp + settings/matchsetting.cpp + settings/olpcmeshsetting.cpp + settings/ovsbridgesetting.cpp + settings/ovsinterfacesetting.cpp + settings/ovspatchsetting.cpp + settings/ovsportsetting.cpp + settings/pppsetting.cpp + settings/pppoesetting.cpp + settings/proxysetting.cpp + settings/setting.cpp + settings/serialsetting.cpp + settings/security8021xsetting.cpp + settings/teamportsetting.cpp + #settings/template.cpp + settings/vlansetting.cpp + settings/vpnsetting.cpp + settings/wimaxsetting.cpp + settings/wiredsetting.cpp + settings/wirelesssetting.cpp + settings/wirelesssecuritysetting.cpp + settings/teamsetting.cpp + settings/tcsetting.cpp + settings/genericsetting.cpp + settings/tunsetting.cpp + settings/usersetting.cpp + settings/vxlansetting.cpp + settings/wireguardsetting.cpp +) + +set(DBUS_INTERFACE_SRCS + dbus/accesspointinterface.cpp + dbus/activeconnectioninterface.cpp + dbus/adsldeviceinterface.cpp + dbus/agentmanagerinterface.cpp + dbus/bluetoothdeviceinterface.cpp + dbus/bonddeviceinterface.cpp + dbus/bridgedeviceinterface.cpp + dbus/connectioninterface.cpp + dbus/deviceinterface.cpp + dbus/devicestatisticsinterface.cpp + dbus/dhcp4configinterface.cpp + dbus/dhcp6configinterface.cpp + dbus/dnsmanagerinterface.cpp + dbus/genericdeviceinterface.cpp + dbus/gredeviceinterface.cpp + dbus/checkpointinterface.cpp + dbus/infinibanddeviceinterface.cpp + dbus/iptunneldeviceinterface.cpp + dbus/ip4configinterface.cpp + dbus/ip6configinterface.cpp + dbus/macsecdeviceinterface.cpp + dbus/macvlandeviceinterface.cpp + dbus/modemdeviceinterface.cpp + dbus/networkmanagerinterface.cpp + dbus/olpcmeshdeviceinterface.cpp + dbus/pppinterface.cpp + dbus/secretagentadaptor.cpp + dbus/settingsinterface.cpp + dbus/teamdeviceinterface.cpp + dbus/tundeviceinterface.cpp + dbus/vethdeviceinterface.cpp + dbus/vlandeviceinterface.cpp + dbus/vpnconnectioninterface.cpp + dbus/vpnplugininterface.cpp + dbus/vxlandeviceinterface.cpp + dbus/wimaxdeviceinterface.cpp + dbus/wimaxnspinterface.cpp + dbus/wireddeviceinterface.cpp + dbus/wirelessdeviceinterface.cpp + dbus/wireguarddeviceinterface.cpp +) + +ecm_qt_export_logging_category( + IDENTIFIER NMQT + CATEGORY_NAME kf.networkmanagerqt + OLD_CATEGORY_NAMES networkmanager-qt + DEFAULT_SEVERITY Warning + DESCRIPTION "NetworkManagerQt" + EXPORT NETWORMANAGERQT +) + +add_library(KF5NetworkManagerQt SHARED ${NetworkManagerQt_PART_SRCS} ${NetworkManagerQt_SETTINGS_SRCS} ${DBUS_INTERFACE_SRCS}) +generate_export_header(KF5NetworkManagerQt EXPORT_FILE_NAME ${NetworkManagerQt_BINARY_DIR}/networkmanagerqt/networkmanagerqt_export.h BASE_NAME NetworkManagerQt) +add_library(KF5::NetworkManagerQt ALIAS KF5NetworkManagerQt) + +target_include_directories(KF5NetworkManagerQt INTERFACE "$") +# for examples to build +target_include_directories(KF5NetworkManagerQt PUBLIC "$") + +target_link_libraries(KF5NetworkManagerQt PUBLIC Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Network Qt${QT_MAJOR_VERSION}::DBus PkgConfig::NetworkManager PkgConfig::Gio) + +set_target_properties(KF5NetworkManagerQt PROPERTIES VERSION ${NETWORKMANAGERQT_VERSION} + SOVERSION ${NETWORKMANAGERQT_SOVERSION} + EXPORT_NAME NetworkManagerQt +) + +########### static lib for tests ############### +add_library(KF5NetworkManagerQt_static STATIC ${NetworkManagerQt_PART_SRCS} ${NetworkManagerQt_SETTINGS_SRCS} ${DBUS_INTERFACE_SRCS}) +set_target_properties(KF5NetworkManagerQt_static PROPERTIES COMPILE_FLAGS -DNMQT_STATIC=1) +set_target_properties(KF5NetworkManagerQt_static PROPERTIES POSITION_INDEPENDENT_CODE ON) + +target_link_libraries(KF5NetworkManagerQt_static PUBLIC Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Network Qt${QT_MAJOR_VERSION}::DBus PkgConfig::NetworkManager PkgConfig::Gio) +target_include_directories(KF5NetworkManagerQt_static PUBLIC "$") + +ecm_generate_headers(NetworkManagerQt_CamelCase_HEADERS + HEADER_NAMES + AccessPoint + ActiveConnection + AdslDevice + BluetoothDevice + BondDevice + BridgeDevice + Connection + Device + DeviceStatistics + Dhcp4Config + Dhcp6Config + DnsConfiguration + DnsDomain + GenericDevice + GenericTypes + GreDevice + InfinibandDevice + IpAddress + IpConfig + IpRoute + IpTunnelDevice + MacVlanDevice + Manager + ModemDevice + OlpcMeshDevice + SecretAgent + Settings + TeamDevice + TunDevice + Utils + VethDevice + VlanDevice + VpnConnection + VpnPlugin + WimaxDevice + WimaxNsp + WiredDevice + WirelessDevice + WirelessNetwork + WireGuardDevice + + REQUIRED_HEADERS NetworkManagerQt_HEADERS + PREFIX NetworkManagerQt +) + +ecm_generate_headers(NetworkManagerQt_SETTINGS_CamelCase_HEADERS + HEADER_NAMES + AdslSetting + BluetoothSetting + BondSetting + BridgeSetting + BridgePortSetting + CdmaSetting + ConnectionSettings + GsmSetting + GenericSetting + InfinibandSetting + IpTunnelSetting + Ipv4Setting + Ipv6Setting + OlpcMeshSetting + PppoeSetting + PppSetting + Security8021xSetting + SerialSetting + Setting + TeamSetting + TunSetting + VlanSetting + VpnSetting + WimaxSetting + WiredSetting + WireguardSetting + WirelessSecuritySetting + WirelessSetting + + RELATIVE settings + REQUIRED_HEADERS NetworkManagerQt_SETTINGS_HEADERS + PREFIX NetworkManagerQt +) + +# install(TARGETS KF5NetworkManagerQt EXPORT KF5NetworkManagerQtTargets ${KF_INSTALL_TARGETS_DEFAULT_ARGS}) + +# install(FILES +# ${NetworkManagerQt_CamelCase_HEADERS} +# ${NetworkManagerQt_SETTINGS_CamelCase_HEADERS} +# DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/NetworkManagerQt/NetworkManagerQt COMPONENT Devel +# ) + +# install(FILES +# ${NetworkManagerQt_BINARY_DIR}/networkmanagerqt/networkmanagerqt_export.h +# ${NetworkManagerQt_HEADERS} +# ${NetworkManagerQt_SETTINGS_HEADERS} +# DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/NetworkManagerQt/networkmanagerqt COMPONENT Devel +# ) + +# ecm_qt_install_logging_categories( +# EXPORT NETWORMANAGERQT +# FILE networkmanagerqt.categories +# DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR} +# ) + +if(BUILD_QCH) + ecm_add_qch( + KF5NetworkManagerQt_QCH + NAME NetworkManagerQt + BASE_NAME KF5NetworkManagerQt + VERSION ${KF_VERSION} + ORG_DOMAIN org.kde + SOURCES # using only public headers, to cover only public API + ${NetworkManagerQt_HEADERS} + ${NetworkManagerQt_SETTINGS_HEADERS} + MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md" + LINK_QCHS + Qt5Core_QCH + Qt5Network_QCH + Qt5DBus_QCH + BLANK_MACROS + NETWORKMANAGERQT_EXPORT + NETWORKMANAGERQT_DEPRECATED + NETWORKMANAGERQT_DEPRECATED_EXPORT + TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} + QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} + COMPONENT Devel + ) +endif() diff --git a/panels/dock/tray/networkmanager-qt/src/accesspoint.cpp b/panels/dock/tray/networkmanager-qt/src/accesspoint.cpp new file mode 100644 index 000000000..c50799761 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/accesspoint.cpp @@ -0,0 +1,231 @@ +/* + SPDX-FileCopyrightText: 2008 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "accesspoint_p.h" +#include "manager_p.h" +#include "wirelessdevice.h" + +#include "nmdebug.h" + +NetworkManager::AccessPointPrivate::AccessPointPrivate(const QString &path, AccessPoint *q) +#ifdef NMQT_STATIC + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , capabilities(AccessPoint::None) + , wpaFlags() + , rsnFlags() + , frequency(0) + , maxBitRate(0) + , mode(AccessPoint::Unknown) + , signalStrength(0) + , lastSeen(-1) + , q_ptr(q) +{ + uni = path; +} + +NetworkManager::AccessPoint::Capabilities NetworkManager::AccessPointPrivate::convertCapabilities(int caps) +{ + NetworkManager::AccessPoint::Capabilities capFlags; + if (caps & NM_802_11_AP_FLAGS_PRIVACY) { + capFlags |= AccessPoint::Privacy; + } + if (caps & NM_802_11_AP_FLAGS_WPS) { + capFlags |= AccessPoint::Wps; + } + if (caps & NM_802_11_AP_FLAGS_WPS_PBC) { + capFlags |= AccessPoint::WpsPbc; + } + if (caps & NM_802_11_AP_FLAGS_WPS_PIN) { + capFlags |= AccessPoint::WpsPin; + } + + return capFlags; +} + +NetworkManager::AccessPoint::WpaFlags NetworkManager::AccessPointPrivate::convertWpaFlags(uint theirFlags) +{ + return (AccessPoint::WpaFlags)theirFlags; +} + +NetworkManager::AccessPoint::AccessPoint(const QString &path, QObject *parent) + : QObject(parent) + , d_ptr(new AccessPointPrivate(path, this)) +{ + Q_D(AccessPoint); + + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->uni, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + + // Get all AccessPoint's properties at once + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::AccessPoint::~AccessPoint() +{ + Q_D(AccessPoint); + delete d; +} + +QString NetworkManager::AccessPoint::uni() const +{ + Q_D(const AccessPoint); + return d->uni; +} + +QString NetworkManager::AccessPoint::hardwareAddress() const +{ + Q_D(const AccessPoint); + return d->hardwareAddress; +} + +NetworkManager::AccessPoint::Capabilities NetworkManager::AccessPoint::capabilities() const +{ + Q_D(const AccessPoint); + return d->capabilities; +} + +NetworkManager::AccessPoint::WpaFlags NetworkManager::AccessPoint::wpaFlags() const +{ + Q_D(const AccessPoint); + return d->wpaFlags; +} + +NetworkManager::AccessPoint::WpaFlags NetworkManager::AccessPoint::rsnFlags() const +{ + Q_D(const AccessPoint); + return d->rsnFlags; +} + +QString NetworkManager::AccessPoint::ssid() const +{ + Q_D(const AccessPoint); + return d->ssid; +} + +QByteArray NetworkManager::AccessPoint::rawSsid() const +{ + Q_D(const AccessPoint); + return d->rawSsid; +} + +uint NetworkManager::AccessPoint::frequency() const +{ + Q_D(const AccessPoint); + return d->frequency; +} + +uint NetworkManager::AccessPoint::maxBitRate() const +{ + Q_D(const AccessPoint); + return d->maxBitRate; +} + +NetworkManager::AccessPoint::OperationMode NetworkManager::AccessPoint::mode() const +{ + Q_D(const AccessPoint); + return d->mode; +} + +int NetworkManager::AccessPoint::signalStrength() const +{ + Q_D(const AccessPoint); + return d->signalStrength; +} + +int NetworkManager::AccessPoint::lastSeen() const +{ + Q_D(const AccessPoint); + return d->lastSeen; +} + +NetworkManager::AccessPoint::OperationMode NetworkManager::AccessPoint::convertOperationMode(uint mode) +{ + NetworkManager::AccessPoint::OperationMode ourMode = NetworkManager::AccessPoint::Unknown; + switch (mode) { + case NM_802_11_MODE_UNKNOWN: + ourMode = NetworkManager::AccessPoint::Unknown; + break; + case NM_802_11_MODE_ADHOC: + ourMode = NetworkManager::AccessPoint::Adhoc; + break; + case NM_802_11_MODE_INFRA: + ourMode = NetworkManager::AccessPoint::Infra; + break; + case NM_802_11_MODE_AP: + ourMode = NetworkManager::AccessPoint::ApMode; + break; + default: + qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled mode" << mode; + } + return ourMode; +} + +void NetworkManager::AccessPointPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.AccessPoint")) { + propertiesChanged(properties); + } +} + +void NetworkManager::AccessPointPrivate::propertiesChanged(const QVariantMap &properties) +{ + Q_Q(AccessPoint); + + // qCDebug(NMQT) << Q_FUNC_INFO << properties; + + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + const QString property = it.key(); + if (property == QLatin1String("Flags")) { + capabilities = convertCapabilities(it->toUInt()); + Q_EMIT q->capabilitiesChanged(capabilities); + } else if (property == QLatin1String("WpaFlags")) { + wpaFlags = convertWpaFlags(it->toUInt()); + Q_EMIT q->wpaFlagsChanged(wpaFlags); + } else if (property == QLatin1String("RsnFlags")) { + rsnFlags = convertWpaFlags(it->toUInt()); + Q_EMIT q->rsnFlagsChanged(rsnFlags); + } else if (property == QLatin1String("Ssid")) { + rawSsid = it->toByteArray(); + ssid = QString::fromUtf8(rawSsid); + Q_EMIT q->ssidChanged(ssid); + } else if (property == QLatin1String("Frequency")) { + frequency = it->toUInt(); + Q_EMIT q->frequencyChanged(frequency); + } else if (property == QLatin1String("HwAddress")) { + hardwareAddress = it->toString(); + } else if (property == QLatin1String("Mode")) { + mode = q->convertOperationMode(it->toUInt()); + } else if (property == QLatin1String("MaxBitrate")) { + maxBitRate = it->toUInt(); + Q_EMIT q->bitRateChanged(maxBitRate); + } else if (property == QLatin1String("Strength")) { + signalStrength = it->toInt(); + Q_EMIT q->signalStrengthChanged(signalStrength); + } else if (property == QLatin1String("LastSeen")) { + lastSeen = it->toInt(); + Q_EMIT q->lastSeenChanged(lastSeen); + } else { + qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } + ++it; + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/accesspoint.h b/panels/dock/tray/networkmanager-qt/src/accesspoint.h new file mode 100644 index 000000000..d61b458ba --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/accesspoint.h @@ -0,0 +1,202 @@ +/* + SPDX-FileCopyrightText: 2008 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_ACCESSPOINT_H +#define NETWORKMANAGERQT_ACCESSPOINT_H + +#include + +#include + +#include +#include +#include + +namespace NetworkManager +{ +class AccessPointPrivate; + +/** + * Represents an access point + */ +class NETWORKMANAGERQT_EXPORT AccessPoint : public QObject +{ + Q_OBJECT +public: + typedef QSharedPointer Ptr; + typedef QList List; + /** + * The access point's current operating mode + */ + enum OperationMode { + Unknown = 0, /**< not associated with a network */ + Adhoc, /**< part of an adhoc network */ + Infra, /**< a station in an infrastructure wireless network */ + ApMode, /**< access point in an infrastructure network */ + }; + /** + * General capabilities of an access point + */ + enum Capability { + None = 0x0, /**< Null capability - says nothing about the access point */ + Privacy = 0x1, /**< Access point supports privacy measures */ + Wps = 0x2, /**< Access point supports some WPS method */ + WpsPbc = 0x4, /**< Access point supports push-button WPS */ + WpsPin = 0x8, /**< Access point supports PIN-based WPS */ + }; + /** + * Flags describing the access point's capabilities according to WPA (Wifi Protected Access) + */ + enum WpaFlag { + PairWep40 = 0x1, + PairWep104 = 0x2, + PairTkip = 0x4, + PairCcmp = 0x8, + GroupWep40 = 0x10, + GroupWep104 = 0x20, + GroupTkip = 0x40, + GroupCcmp = 0x80, + KeyMgmtPsk = 0x100, + KeyMgmt8021x = 0x200, + KeyMgmtSAE = 0x400, + KeyMgmtEapSuiteB192 = 0x2000, + }; + Q_DECLARE_FLAGS(Capabilities, Capability) + Q_FLAG(Capabilities) + Q_DECLARE_FLAGS(WpaFlags, WpaFlag) + Q_FLAG(WpaFlags) + explicit AccessPoint(const QString &path, QObject *parent = nullptr); + ~AccessPoint() override; + + /** + * @return path of the access point + */ + QString uni() const; + /** + * @return capabilities of an access point + */ + Capabilities capabilities() const; + /** + * @return flags describing the access point's capabilities according to WPA (Wifi Protected Access). + * @see WpaFlag + */ + AccessPoint::WpaFlags wpaFlags() const; + /** + * @return Flags describing the access point's capabilities according to the RSN (Robust Secure Network) protocol. + * @see WpaFlag + */ + AccessPoint::WpaFlags rsnFlags() const; + /** + * @return The Service Set Identifier identifying the access point. + */ + QString ssid() const; + /** + * @return raw SSID, encoded as a byte array + */ + QByteArray rawSsid() const; + /** + * @return The radio channel frequency in use by the access point, in MHz. + */ + uint frequency() const; + /** + * @return The hardware address (BSSID) of the access point. + */ + QString hardwareAddress() const; + /** + * @return The maximum bitrate this access point is capable of, in kilobits/second (Kb/s). + */ + uint maxBitRate() const; + /** + * @return Describes the operating mode of the access point. + */ + OperationMode mode() const; + /** + * @return The current signal quality of the access point, in percent. + */ + int signalStrength() const; + /** + * @return The timestamp (in CLOCK_BOOTTIME seconds) for the last time the access point + * was found in scan results. A value of -1 means the access point has never been found in scan results. + * @since 5.14.0 + */ + int lastSeen() const; + + /** + * Helper method to convert wire representation of operation @p mode to enum + */ + static OperationMode convertOperationMode(uint mode); + +Q_SIGNALS: + /** + * This signal is emitted when the signal strength of this network has changed. + * + * @param strength the new signal strength value for this network + */ + void signalStrengthChanged(int strength); + + /** + * This signal is emitted when the bitrate of this network has changed. + * + * @param bitrate the new bitrate value for this network + */ + void bitRateChanged(int bitrate); + + /** + * This signal is emitted when the capabilities of this network have changed. + * + * @param caps the new capabilities + */ + void capabilitiesChanged(AccessPoint::Capabilities caps); + + /** + * This signal is emitted when the WPA flags in use by this access point change + * + * @param flags the new flags + */ + void wpaFlagsChanged(AccessPoint::WpaFlags flags); + + /** + * This signal is emitted when the RSN(WPA2) flags in use by this access point change + * + * @param flags the new flags + */ + void rsnFlagsChanged(AccessPoint::WpaFlags flags); + /** + * This signal is emitted when the ssid of this Access Point changes + * + * @param ssid the new SSID + */ + void ssidChanged(const QString &ssid); + + /** + * This signal is emitted when the frequency used by this Access Point changes + * + * @param frequency the new frequency + */ + void frequencyChanged(uint frequency); + + /** + * This signal is emitted when the timestamp for the last time the access point was found + * in scan results changes + * + * @param lastSeen the timestamp for the last time the access point was found in scan results. + * @since 5.14.0 + * @see lastSeen + */ + void lastSeenChanged(int lastSeen); + +private: + Q_DECLARE_PRIVATE(AccessPoint) + + AccessPointPrivate *const d_ptr; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(AccessPoint::WpaFlags) + +} +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/accesspoint_p.h b/panels/dock/tray/networkmanager-qt/src/accesspoint_p.h new file mode 100644 index 000000000..edd3ba27e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/accesspoint_p.h @@ -0,0 +1,50 @@ +/* + SPDX-FileCopyrightText: 2008 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_ACCESSPOINT_P_H +#define NETWORKMANAGERQT_ACCESSPOINT_P_H + +#include "accesspoint.h" +#include "dbus/accesspointinterface.h" + +namespace NetworkManager +{ +class AccessPointPrivate : public QObject +{ + Q_OBJECT +public: + AccessPointPrivate(const QString &path, AccessPoint *q); + + OrgFreedesktopNetworkManagerAccessPointInterface iface; + QString uni; + AccessPoint::Capabilities capabilities; + AccessPoint::WpaFlags wpaFlags; + AccessPoint::WpaFlags rsnFlags; + QString ssid; + QByteArray rawSsid; + uint frequency; + QString hardwareAddress; + uint maxBitRate; + AccessPoint::OperationMode mode; + int signalStrength; + + int lastSeen; + + NetworkManager::AccessPoint::Capabilities convertCapabilities(int caps); + NetworkManager::AccessPoint::WpaFlags convertWpaFlags(uint theirFlags); + + Q_DECLARE_PUBLIC(AccessPoint) + AccessPoint *q_ptr; +private Q_SLOTS: + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void propertiesChanged(const QVariantMap &properties); +}; + +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_ACCESSPOINT_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/activeconnection.cpp b/panels/dock/tray/networkmanager-qt/src/activeconnection.cpp new file mode 100644 index 000000000..76431c554 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/activeconnection.cpp @@ -0,0 +1,350 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "activeconnection.h" +#include "activeconnection_p.h" +#include "device.h" +#include "manager.h" +#include "nmdebug.h" +#include "settings.h" + +#include + +#include "manager_p.h" + +NetworkManager::ActiveConnectionPrivate::ActiveConnectionPrivate(const QString &dbusPath, ActiveConnection *q) +#ifdef NMQT_STATIC + : iface(NetworkManagerPrivate::DBUS_SERVICE, dbusPath, QDBusConnection::sessionBus()) +#else + : iface(NetworkManagerPrivate::DBUS_SERVICE, dbusPath, QDBusConnection::systemBus()) +#endif + , dhcp4Config(nullptr) + , dhcp6Config(nullptr) + , state(ActiveConnection::Unknown) + , q_ptr(q) +{ + path = dbusPath; +} + +NetworkManager::ActiveConnectionPrivate::~ActiveConnectionPrivate() +{ +} + +NetworkManager::ActiveConnection::State NetworkManager::ActiveConnectionPrivate::convertActiveConnectionState(uint state) +{ + return (NetworkManager::ActiveConnection::State)state; +} + +NetworkManager::ActiveConnection::Reason NetworkManager::ActiveConnectionPrivate::convertActiveConnectionReason(uint reason) +{ + return (NetworkManager::ActiveConnection::Reason)reason; +} + +NetworkManager::ActiveConnection::ActiveConnection(const QString &path, QObject *parent) + : QObject(parent) + , d_ptr(new ActiveConnectionPrivate(path, this)) +{ + Q_D(ActiveConnection); + +#ifndef NMQT_STATIC + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->path, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->path, + d->iface.staticInterfaceName(), + QLatin1String("StateChanged"), + d, + SLOT(stateChanged(uint, uint))); +#endif + +#ifdef NMQT_STATIC + connect(&d->iface, &OrgFreedesktopNetworkManagerConnectionActiveInterface::PropertiesChanged, d, &ActiveConnectionPrivate::propertiesChanged); + connect(&d->iface, &OrgFreedesktopNetworkManagerConnectionActiveInterface::StateChanged, d, &ActiveConnectionPrivate::stateChanged); +#endif + + // Get all ActiveConnection's at once + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::ActiveConnection::ActiveConnection(ActiveConnectionPrivate &dd, QObject *parent) + : QObject(parent) + , d_ptr(&dd) +{ + Q_D(ActiveConnection); + +#ifndef NMQT_STATIC + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->path, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->path, + d->iface.staticInterfaceName(), + QLatin1String("StateChanged"), + d, + SLOT(stateChanged(uint, uint))); +#endif + +#ifdef NMQT_STATIC + connect(&d->iface, &OrgFreedesktopNetworkManagerConnectionActiveInterface::PropertiesChanged, d, &ActiveConnectionPrivate::propertiesChanged); + connect(&d->iface, &OrgFreedesktopNetworkManagerConnectionActiveInterface::StateChanged, d, &ActiveConnectionPrivate::stateChanged); +#endif +} + +NetworkManager::ActiveConnection::~ActiveConnection() +{ + delete d_ptr; +} + +bool NetworkManager::ActiveConnection::isValid() const +{ + Q_D(const ActiveConnection); + return !d->connection.isNull(); +} + +NetworkManager::Connection::Ptr NetworkManager::ActiveConnection::connection() const +{ + Q_D(const ActiveConnection); + return d->connection; +} + +QString NetworkManager::ActiveConnection::path() const +{ + Q_D(const ActiveConnection); + return d->path; +} + +bool NetworkManager::ActiveConnection::default4() const +{ + Q_D(const ActiveConnection); + return d->default4; +} + +bool NetworkManager::ActiveConnection::default6() const +{ + Q_D(const ActiveConnection); + return d->default6; +} + +NetworkManager::Dhcp4Config::Ptr NetworkManager::ActiveConnection::dhcp4Config() const +{ + Q_D(const ActiveConnection); + if (!d->dhcp4Config && !d->dhcp4ConfigPath.isNull()) { + d->dhcp4Config = NetworkManager::Dhcp4Config::Ptr(new Dhcp4Config(d->dhcp4ConfigPath), &QObject::deleteLater); + } + return d->dhcp4Config; +} + +NetworkManager::Dhcp6Config::Ptr NetworkManager::ActiveConnection::dhcp6Config() const +{ + Q_D(const ActiveConnection); + if (!d->dhcp6Config && !d->dhcp6ConfigPath.isNull()) { + d->dhcp6Config = NetworkManager::Dhcp6Config::Ptr(new Dhcp6Config(d->dhcp6ConfigPath), &QObject::deleteLater); + } + return d->dhcp6Config; +} + +NetworkManager::IpConfig NetworkManager::ActiveConnection::ipV4Config() const +{ + Q_D(const ActiveConnection); + if (!d->ipV4Config.isValid() && !d->ipV4ConfigPath.isNull()) { + d->ipV4Config.setIPv4Path(d->ipV4ConfigPath); + } + return d->ipV4Config; +} + +NetworkManager::IpConfig NetworkManager::ActiveConnection::ipV6Config() const +{ + Q_D(const ActiveConnection); + if (!d->ipV6Config.isValid() && !d->ipV6ConfigPath.isNull()) { + d->ipV6Config.setIPv6Path(d->ipV6ConfigPath); + } + return d->ipV6Config; +} + +QString NetworkManager::ActiveConnection::id() const +{ + Q_D(const ActiveConnection); + return d->id; +} + +NetworkManager::ConnectionSettings::ConnectionType NetworkManager::ActiveConnection::type() const +{ + Q_D(const ActiveConnection); + return NetworkManager::ConnectionSettings::typeFromString(d->type); +} + +QString NetworkManager::ActiveConnection::master() const +{ + Q_D(const ActiveConnection); + return d->master; +} + +QString NetworkManager::ActiveConnection::specificObject() const +{ + Q_D(const ActiveConnection); + return d->specificObject; +} + +NetworkManager::ActiveConnection::State NetworkManager::ActiveConnection::state() const +{ + Q_D(const ActiveConnection); + return d->state; +} + +bool NetworkManager::ActiveConnection::vpn() const +{ + Q_D(const ActiveConnection); + return d->vpn; +} + +QString NetworkManager::ActiveConnection::uuid() const +{ + Q_D(const ActiveConnection); + return d->uuid; +} + +QStringList NetworkManager::ActiveConnection::devices() const +{ + Q_D(const ActiveConnection); + return d->devices; +} + +void NetworkManager::ActiveConnectionPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.Connection.Active")) { + propertiesChanged(properties); + } +} + +void NetworkManager::ActiveConnectionPrivate::propertiesChanged(const QVariantMap &properties) +{ + // qCDebug(NMQT) << Q_FUNC_INFO << properties; + + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + propertyChanged(it.key(), it.value()); + ++it; + } +} + +void NetworkManager::ActiveConnectionPrivate::stateChanged(uint state, uint reason) +{ + Q_Q(ActiveConnection); + + Q_EMIT q->stateChangedReason(convertActiveConnectionState(state), convertActiveConnectionReason(reason)); +} + +void NetworkManager::ActiveConnectionPrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(ActiveConnection); + + // qCDebug(NMQT) << property << " - " << value; + + if (property == QLatin1String("Connection")) { + connection = NetworkManager::findConnection(qdbus_cast(value).path()); + Q_EMIT q->connectionChanged(connection); + const QString tmpId = connection->settings()->id(); + const QString tmpType = connection->settings()->typeAsString(connection->settings()->connectionType()); + if (tmpId != id) { + id = tmpId; + Q_EMIT q->idChanged(id); + } + + if (tmpType != type) { + Q_EMIT q->typeChanged(NetworkManager::ConnectionSettings::typeFromString(type)); + } + } else if (property == QLatin1String("Default")) { + default4 = value.toBool(); + Q_EMIT q->default4Changed(default4); + } else if (property == QLatin1String("Default6")) { + default6 = value.toBool(); + Q_EMIT q->default6Changed(default6); + } else if (property == QLatin1String("Dhcp4Config")) { + QDBusObjectPath dhcp4ConfigPathTmp = (value).value(); + if (dhcp4ConfigPathTmp.path().isNull()) { + dhcp4Config.clear(); + dhcp4ConfigPath.clear(); + } else if (!dhcp4Config || dhcp4Config->path() != dhcp4ConfigPathTmp.path()) { + dhcp4Config.clear(); + dhcp4ConfigPath = dhcp4ConfigPathTmp.path(); + } + Q_EMIT q->dhcp4ConfigChanged(); + } else if (property == QLatin1String("Dhcp6Config")) { + QDBusObjectPath dhcp6ConfigPathTmp = (value).value(); + if (dhcp6ConfigPathTmp.path().isNull()) { + dhcp6Config.clear(); + dhcp6ConfigPath.clear(); + } else if (!dhcp6Config || dhcp6Config->path() != dhcp6ConfigPathTmp.path()) { + dhcp6Config.clear(); + dhcp6ConfigPath = dhcp6ConfigPathTmp.path(); + } + Q_EMIT q->dhcp6ConfigChanged(); + } else if (property == QLatin1String("Ip4Config")) { + QDBusObjectPath ip4ConfigObjectPathTmp = (value).value(); + if (ip4ConfigObjectPathTmp.path().isNull() || ip4ConfigObjectPathTmp.path() == QLatin1String("/")) { + ipV4ConfigPath.clear(); + } else { + ipV4ConfigPath = ip4ConfigObjectPathTmp.path(); + } + ipV4Config = IpConfig(); + Q_EMIT q->ipV4ConfigChanged(); + } else if (property == QLatin1String("Ip6Config")) { + QDBusObjectPath ip6ConfigObjectPathTmp = (value).value(); + if (ip6ConfigObjectPathTmp.path().isNull() || ip6ConfigObjectPathTmp.path() == QLatin1String("/")) { + ipV6ConfigPath.clear(); + } else { + ipV6ConfigPath = ip6ConfigObjectPathTmp.path(); + } + ipV6Config = IpConfig(); + Q_EMIT q->ipV6ConfigChanged(); + } else if (property == QLatin1String("Id")) { + id = value.toString(); + Q_EMIT q->idChanged(id); + } else if (property == QLatin1String("Type")) { + type = value.toString(); + Q_EMIT q->typeChanged(NetworkManager::ConnectionSettings::typeFromString(type)); + } else if (property == QLatin1String("Master")) { + master = qdbus_cast(value).path(); + Q_EMIT q->masterChanged(master); + } else if (property == QLatin1String("SpecificObject")) { + specificObject = qdbus_cast(value).path(); + Q_EMIT q->specificObjectChanged(specificObject); + } else if (property == QLatin1String("State")) { + state = NetworkManager::ActiveConnectionPrivate::convertActiveConnectionState(value.toUInt()); + Q_EMIT q->stateChanged(state); + } else if (property == QLatin1String("Vpn")) { + vpn = value.toBool(); + Q_EMIT q->vpnChanged(vpn); + } else if (property == QLatin1String("Uuid")) { + uuid = value.toString(); + Q_EMIT q->uuidChanged(uuid); + } else if (property == QLatin1String("Devices")) { + devices.clear(); + const QList opList = qdbus_cast>(value); + for (const QDBusObjectPath &path : opList) { + devices.append(path.path()); + } + Q_EMIT q->devicesChanged(); + } else { + qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/activeconnection.h b/panels/dock/tray/networkmanager-qt/src/activeconnection.h new file mode 100644 index 000000000..0d978d420 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/activeconnection.h @@ -0,0 +1,231 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_ACTIVECONNECTION_H +#define NETWORKMANAGERQT_ACTIVECONNECTION_H + +#include +#include +#include + +#include "connection.h" +#include "dhcp4config.h" +#include "dhcp6config.h" +#include "ipconfig.h" +#include + +namespace NetworkManager +{ +class ActiveConnectionPrivate; + +/** + * An active connection + */ +class NETWORKMANAGERQT_EXPORT ActiveConnection : public QObject +{ + Q_OBJECT + +public: + typedef QSharedPointer Ptr; + typedef QList List; + /** + * Enum describing possible active connection states + */ + enum State { + Unknown = 0, /**< The active connection is in an unknown state */ + Activating, /**< The connection is activating */ + Activated, /**< The connection is activated */ + Deactivating, /**< The connection is being torn down and cleaned up */ + Deactivated, /**< The connection is no longer active */ + }; + + enum Reason { + UknownReason = 0, /**< The reason for the active connection state change is unknown */ + None, /**< No reason was given for the active connection state change */ + UserDisconnected, /**< The active connection changed state because the user disconnected it */ + DeviceDisconnected, /**< The active connection changed state because the device it was using was disconnected */ + ServiceStopped, /**< The service providing the VPN connection was stopped */ + IpConfigInvalid, /**< The IP config of the active connection was invalid */ + ConnectTimeout, /**< The connection attempt to the VPN service timed out */ + ServiceStartTimeout, /**< A timeout occurred while starting the service providing the VPN connection */ + ServiceStartFailed, /**< Starting the service providing the VPN connection failed */ + NoSecrets, /**< Necessary secrets for the connection were not provided */ + LoginFailed, /**< Authentication to the server failed */ + ConnectionRemoved, /**< The connection was deleted from settings */ + DependencyFailed, /**< Master connection of this connection failed to activate */ + DeviceRealizeFailed, /**< Could not create the software device link */ + DeviceRemoved, /**< The device this connection depended on disappeared */ + }; + + /** + * Creates a new ActiveConnection object. + * + * @param path the DBus path of the device + */ + explicit ActiveConnection(const QString &path, QObject *parent = nullptr); + explicit ActiveConnection(ActiveConnectionPrivate &dd, QObject *parent = nullptr); + /** + * Destroys an ActiveConnection object. + */ + ~ActiveConnection() override; + + /** + * Returns true is this object holds a valid connection + */ + bool isValid() const; + /** + * Return path of the connection object + */ + QString path() const; + /** + * Returns a valid NetworkManager::Connection object + */ + Connection::Ptr connection() const; + /** + * Whether this connection has the default IPv4 route + */ + bool default4() const; + /** + * Whether this connection has the default IPv6 route + */ + bool default6() const; + /** + * The Ip4Config object describing the configuration of the + * connection. Only valid when the connection is in the + * NM_ACTIVE_CONNECTION_STATE_ACTIVATED state + */ + IpConfig ipV4Config() const; + /** + * The Ip6Config object describing the configuration of the + * connection. Only valid when the connection is in the + * NM_ACTIVE_CONNECTION_STATE_ACTIVATED state + */ + IpConfig ipV6Config() const; + /** + * The Dhcp4Config object describing the DHCP options + * returned by the DHCP server (assuming the connection used DHCP). Only + * valid when the connection is in the NM_ACTIVE_CONNECTION_STATE_ACTIVATED + * state + */ + Dhcp4Config::Ptr dhcp4Config() const; + /** + * The Dhcp6Config object describing the DHCP options + * returned by the DHCP server (assuming the connection used DHCP). Only + * valid when the connection is in the NM_ACTIVE_CONNECTION_STATE_ACTIVATED + * state + */ + Dhcp6Config::Ptr dhcp6Config() const; + /** + * The Id of the connection + */ + QString id() const; + /** + * The type of the connection + */ + NetworkManager::ConnectionSettings::ConnectionType type() const; + /** + * Returns the uni of master device if the connection is a slave. + */ + QString master() const; + /** + * The path of the specific object associated with the connection. + */ + QString specificObject() const; + /** + * The current state of the connection + */ + NetworkManager::ActiveConnection::State state() const; + /** + * Whether this is a VPN connection + */ + bool vpn() const; + /** + * The UUID of the connection. + */ + QString uuid() const; + /** + * List of devices UNIs which are part of this connection. + */ + QStringList devices() const; + +Q_SIGNALS: + /** + * This signal is emitted when the connection path has changed + */ + void connectionChanged(const NetworkManager::Connection::Ptr &connection); + /** + * The state of the default IPv4 route changed + */ + void default4Changed(bool isDefault); + /** + * The state of the default IPv6 route changed + */ + void default6Changed(bool isDefault); + /** + * Emitted when the DHCP configuration for IPv4 of this network has changed. + */ + void dhcp4ConfigChanged(); + /** + * Emitted when the DHCP configuration for IPv6 of this network has changed. + */ + void dhcp6ConfigChanged(); + /** + * Emitted when the IPv4 configuration of this network has changed. + */ + void ipV4ConfigChanged(); + /** + * Emitted when the IPv6 configuration of this network has changed. + */ + void ipV6ConfigChanged(); + /** + * The @p id changed + */ + void idChanged(const QString &id); + /** + * The @p type changed + */ + void typeChanged(NetworkManager::ConnectionSettings::ConnectionType type); + /** + * The master device changed. + */ + void masterChanged(const QString &uni); + /** + * The @p path to the specific object changed + */ + void specificObjectChanged(const QString &path); + /** + * The @p state changed + */ + void stateChanged(NetworkManager::ActiveConnection::State state); + /** + * The @p state changed because of reason @p reason + * (never emitted in runtime NM < 1.8.0) + */ + void stateChangedReason(NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); + /** + * The VPN property changed. + */ + void vpnChanged(bool isVpn); + /** + * The @p uuid changed. + */ + void uuidChanged(const QString &uuid); + /** + * The list of devices changed. + */ + void devicesChanged(); + +protected: + ActiveConnectionPrivate *const d_ptr; + +private: + Q_DECLARE_PRIVATE(ActiveConnection) +}; + +} // namespace NetworkManager +#endif // NETWORKMANAGERQT_ACTIVECONNECTION_H diff --git a/panels/dock/tray/networkmanager-qt/src/activeconnection_p.h b/panels/dock/tray/networkmanager-qt/src/activeconnection_p.h new file mode 100644 index 000000000..0c6edbe2d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/activeconnection_p.h @@ -0,0 +1,64 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_ACTIVECONNECTION_P_H +#define NETWORKMANAGERQT_ACTIVECONNECTION_P_H + +#include "activeconnection.h" +#include "activeconnectioninterface.h" + +namespace NetworkManager +{ +class ActiveConnectionPrivate : public QObject +{ + Q_OBJECT +public: + explicit ActiveConnectionPrivate(const QString &, ActiveConnection *q); + ~ActiveConnectionPrivate() override; + static NetworkManager::ActiveConnection::State convertActiveConnectionState(uint); + static NetworkManager::ActiveConnection::Reason convertActiveConnectionReason(uint); + NetworkManager::Connection::Ptr connection; + QString path; + bool default4; + bool default6; + QStringList devices; + OrgFreedesktopNetworkManagerConnectionActiveInterface iface; + mutable Dhcp4Config::Ptr dhcp4Config; + QString dhcp4ConfigPath; + mutable Dhcp6Config::Ptr dhcp6Config; + QString dhcp6ConfigPath; + mutable IpConfig ipV4Config; + QString ipV4ConfigPath; + mutable IpConfig ipV6Config; + QString ipV6ConfigPath; + QString id; + QString type; + QString specificObject; + ActiveConnection::State state; + bool vpn; + QString uuid; + QString master; + + Q_DECLARE_PUBLIC(ActiveConnection) + ActiveConnection *q_ptr; + +public: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + virtual void propertyChanged(const QString &property, const QVariant &value); + +public Q_SLOTS: + void propertiesChanged(const QVariantMap &properties); + void stateChanged(uint state, uint reason); + +private Q_SLOTS: + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); +}; + +} +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/adsldevice.cpp b/panels/dock/tray/networkmanager-qt/src/adsldevice.cpp new file mode 100644 index 000000000..1b6247f17 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/adsldevice.cpp @@ -0,0 +1,62 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "adsldevice_p.h" + +NetworkManager::AdslDevicePrivate::AdslDevicePrivate(const QString &path, AdslDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , carrier(false) +{ +} + +NetworkManager::AdslDevice::~AdslDevice() +{ +} + +NetworkManager::AdslDevice::AdslDevice(const QString &path, QObject *parent) + : Device(*new AdslDevicePrivate(path, this), parent) +{ + Q_D(AdslDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::AdslDevicePrivate::~AdslDevicePrivate() +{ +} + +NetworkManager::Device::Type NetworkManager::AdslDevice::type() const +{ + return NetworkManager::Device::Adsl; +} + +bool NetworkManager::AdslDevice::carrier() const +{ + Q_D(const AdslDevice); + + return d->carrier; +} + +void NetworkManager::AdslDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(AdslDevice); + + if (property == QLatin1String("Carrier")) { + carrier = value.toBool(); + Q_EMIT q->carrierChanged(carrier); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/adsldevice.h b/panels/dock/tray/networkmanager-qt/src/adsldevice.h new file mode 100644 index 000000000..176aa3b4f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/adsldevice.h @@ -0,0 +1,48 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_ADSL_DEVICE_H +#define NETWORKMANAGERQT_ADSL_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class AdslDevicePrivate; + +/** + * An adsl device interface + */ +class NETWORKMANAGERQT_EXPORT AdslDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(bool carrier READ carrier NOTIFY carrierChanged) +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit AdslDevice(const QString &path, QObject *parent = nullptr); + ~AdslDevice() override; + + Type type() const override; + /** + * Indicates whether the physical carrier is found + */ + bool carrier() const; + +Q_SIGNALS: + /** + * Emitted when the carrier of this device has changed + */ + void carrierChanged(bool plugged); + +private: + Q_DECLARE_PRIVATE(AdslDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/adsldevice_p.h b/panels/dock/tray/networkmanager-qt/src/adsldevice_p.h new file mode 100644 index 000000000..d5f85cde6 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/adsldevice_p.h @@ -0,0 +1,39 @@ +/* + SPDX-FileCopyrightText: 2012-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_ADSL_DEVICE_P_H +#define NETWORKMANAGERQT_ADSL_DEVICE_P_H + +#include "adsldevice.h" +#include "device_p.h" +#include "manager.h" +#include "manager_p.h" + +#include "adsldeviceinterface.h" + +namespace NetworkManager +{ +class AdslDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + AdslDevicePrivate(const QString &path, AdslDevice *q); + ~AdslDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceAdslInterface iface; + bool carrier; + + Q_DECLARE_PUBLIC(AdslDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/bluetoothdevice.cpp b/panels/dock/tray/networkmanager-qt/src/bluetoothdevice.cpp new file mode 100644 index 000000000..5c4ab26ed --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bluetoothdevice.cpp @@ -0,0 +1,77 @@ +/* + SPDX-FileCopyrightText: 2011 Lamarque Souza + SPDX-FileCopyrightText: 2011 Will Stephenson + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "bluetoothdevice.h" +#include "bluetoothdevice_p.h" +#include "manager_p.h" + +#include "nmdebug.h" + +NetworkManager::BluetoothDevicePrivate::BluetoothDevicePrivate(const QString &path, BluetoothDevice *q) + : ModemDevicePrivate(path, q) +#ifdef NMQT_STATIC + , btIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , btIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::BluetoothDevice::BluetoothDevice(const QString &path, QObject *parent) + : ModemDevice(*new BluetoothDevicePrivate(path, this), parent) +{ + Q_D(BluetoothDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->btIface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } + +} + +NetworkManager::BluetoothDevice::~BluetoothDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::BluetoothDevice::type() const +{ + return NetworkManager::Device::Bluetooth; +} + +void NetworkManager::BluetoothDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(BluetoothDevice); + + if (property == QLatin1String("Name")) { + name = value.toString(); + Q_EMIT q->nameChanged(name); + } else if (property == QLatin1String("HwAddress")) { + hardwareAddress = value.toString(); + } else if (property == QLatin1String("BtCapabilities")) { + btCapabilities = static_cast(value.toUInt()); + } else { + DevicePrivate::propertyChanged(property, value); + } +} + +NetworkManager::BluetoothDevice::Capabilities NetworkManager::BluetoothDevice::bluetoothCapabilities() const +{ + Q_D(const BluetoothDevice); + return d->btCapabilities; +} + +QString NetworkManager::BluetoothDevice::hardwareAddress() const +{ + Q_D(const BluetoothDevice); + return d->hardwareAddress; +} + +QString NetworkManager::BluetoothDevice::name() const +{ + Q_D(const BluetoothDevice); + return d->name; +} diff --git a/panels/dock/tray/networkmanager-qt/src/bluetoothdevice.h b/panels/dock/tray/networkmanager-qt/src/bluetoothdevice.h new file mode 100644 index 000000000..48019aad7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bluetoothdevice.h @@ -0,0 +1,85 @@ +/* + SPDX-FileCopyrightText: 2011 Lamarque Souza + SPDX-FileCopyrightText: 2011 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "modemdevice.h" + +#ifndef NETWORKMANAGERQT_BLUETOOTH_DEVICE_H +#define NETWORKMANAGERQT_BLUETOOTH_DEVICE_H + +#include + +namespace NetworkManager +{ +class BluetoothDevicePrivate; + +/** + * A bluetooth device interface + */ +class NETWORKMANAGERQT_EXPORT BluetoothDevice : public ModemDevice +{ + Q_OBJECT + + Q_PROPERTY(uint bluetoothCapabilities READ bluetoothCapabilities) + Q_PROPERTY(QString hardwareAddress READ hardwareAddress) + Q_PROPERTY(QString name READ name) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + /** + * Capabilities of the Bluetooth device + */ + enum Capability { + NoCapability = 0x0, /**< No special capability */ + Dun = 0x1, /**< Dial Up Networking profile */ + Pan = 0x2, /**< Personal Area Network profile */ + }; + Q_DECLARE_FLAGS(Capabilities, Capability) + Q_FLAG(Capabilities) + /** + * Creates a new BluetoothDevice object. + */ + explicit BluetoothDevice(const QString &path, QObject *parent = nullptr); + /** + * Destroys a BluetoothDevice object. + */ + ~BluetoothDevice() override; + + /** + * Retrieves the capabilities supported by this device. + * + * @return the capabilities of the device + * @see NetworkManager::BluetoothDevice::Capability + */ + Capabilities bluetoothCapabilities() const; + /** + * The hardware address assigned to the bluetooth interface + */ + QString hardwareAddress() const; + /** + * Name of the bluetooth interface + */ + QString name() const; + /** + * The NetworkInterface type. + * + * @return the NetworkManager::Device::Type. This always returns NetworkManager::Device::Bluetooth + */ + Type type() const override; + +Q_SIGNALS: + /** + * Emitted when the BT device @p name changes + */ + void nameChanged(const QString &name); + +private: + Q_DECLARE_PRIVATE(BluetoothDevice) +}; +} +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/bluetoothdevice_p.h b/panels/dock/tray/networkmanager-qt/src/bluetoothdevice_p.h new file mode 100644 index 000000000..ee1f254ec --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bluetoothdevice_p.h @@ -0,0 +1,35 @@ +/* + SPDX-FileCopyrightText: 2011 Lamarque Souza + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BLUETOOTH_DEVICE_P_H +#define NETWORKMANAGERQT_BLUETOOTH_DEVICE_P_H + +#include "dbus/bluetoothdeviceinterface.h" +#include "modemdevice_p.h" + +namespace NetworkManager +{ +class BluetoothDevicePrivate : public ModemDevicePrivate +{ + Q_OBJECT +public: + explicit BluetoothDevicePrivate(const QString &path, BluetoothDevice *q); + OrgFreedesktopNetworkManagerDeviceBluetoothInterface btIface; + BluetoothDevice::Capabilities btCapabilities; + QString hardwareAddress; + QString name; + + Q_DECLARE_PUBLIC(BluetoothDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} +#endif // NETWORKMANAGERQT__BLUETOOTH_DEVICE_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/bonddevice.cpp b/panels/dock/tray/networkmanager-qt/src/bonddevice.cpp new file mode 100644 index 000000000..5596c82a4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bonddevice.cpp @@ -0,0 +1,90 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "bonddevice_p.h" +#include "device_p.h" +#include "manager.h" +#include "manager_p.h" + +NetworkManager::BondDevicePrivate::BondDevicePrivate(const QString &path, BondDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , carrier(false) +{ +} + +NetworkManager::BondDevice::~BondDevice() +{ +} + +NetworkManager::BondDevice::BondDevice(const QString &path, QObject *parent) + : Device(*new BondDevicePrivate(path, this), parent) +{ + Q_D(BondDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } + +} + +NetworkManager::BondDevicePrivate::~BondDevicePrivate() +{ +} + +NetworkManager::Device::Type NetworkManager::BondDevice::type() const +{ + return NetworkManager::Device::Bond; +} + +bool NetworkManager::BondDevice::carrier() const +{ + Q_D(const BondDevice); + + return d->carrier; +} + +QString NetworkManager::BondDevice::hwAddress() const +{ + Q_D(const BondDevice); + + return d->hwAddress; +} + +QStringList NetworkManager::BondDevice::slaves() const +{ + Q_D(const BondDevice); + + return d->slaves; +} + +void NetworkManager::BondDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(BondDevice); + + if (property == QLatin1String("Carrier")) { + carrier = value.toBool(); + Q_EMIT q->carrierChanged(carrier); + } else if (property == QLatin1String("HwAddress")) { + hwAddress = value.toString(); + Q_EMIT q->hwAddressChanged(hwAddress); + } else if (property == QLatin1String("Slaves")) { + QStringList list; + const QList opList = qdbus_cast>(value); + for (const QDBusObjectPath &op : opList) { + list << op.path(); + } + slaves = list; + Q_EMIT q->slavesChanged(slaves); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/bonddevice.h b/panels/dock/tray/networkmanager-qt/src/bonddevice.h new file mode 100644 index 000000000..0c4477f98 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bonddevice.h @@ -0,0 +1,68 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BOND_DEVICE_H +#define NETWORKMANAGERQT_BOND_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class BondDevicePrivate; + +/** + * A bond device interface + */ +class NETWORKMANAGERQT_EXPORT BondDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(bool carrier READ carrier NOTIFY carrierChanged) + Q_PROPERTY(QString hwAddress READ hwAddress NOTIFY hwAddressChanged) + Q_PROPERTY(QStringList slaves READ slaves NOTIFY slavesChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit BondDevice(const QString &path, QObject *parent = nullptr); + ~BondDevice() override; + + Type type() const override; + + /** + * Indicates whether the physical carrier is found + */ + bool carrier() const; + /** + * Hardware address of the device + */ + QString hwAddress() const; + /** + * Array of object paths representing devices which are currently slaved to this device + */ + QStringList slaves() const; + +Q_SIGNALS: + /** + * Emitted when the carrier of this device has changed + */ + void carrierChanged(bool plugged); + /** + * Emitted when the hardware address of this device has changed + */ + void hwAddressChanged(const QString &address); + /** + * Emitted when the slaves of this device have changed + */ + void slavesChanged(const QStringList &slaves); + +private: + Q_DECLARE_PRIVATE(BondDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/bonddevice_p.h b/panels/dock/tray/networkmanager-qt/src/bonddevice_p.h new file mode 100644 index 000000000..f5f5adcc4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bonddevice_p.h @@ -0,0 +1,37 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BOND_DEVICE_P_H +#define NETWORKMANAGERQT_BOND_DEVICE_P_H + +#include "bonddevice.h" +#include "dbus/bonddeviceinterface.h" +#include "device_p.h" + +namespace NetworkManager +{ +class BondDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + BondDevicePrivate(const QString &path, BondDevice *q); + ~BondDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceBondInterface iface; + bool carrier; + QString hwAddress; + QStringList slaves; + + Q_DECLARE_PUBLIC(BondDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; +} +#endif // NETWORKMANAGERQT__BLUETOOTH_DEVICE_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/bridgedevice.cpp b/panels/dock/tray/networkmanager-qt/src/bridgedevice.cpp new file mode 100644 index 000000000..757ecd757 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bridgedevice.cpp @@ -0,0 +1,87 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "bridgedevice_p.h" +#include "manager_p.h" + +NetworkManager::BridgeDevicePrivate::BridgeDevicePrivate(const QString &path, BridgeDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , carrier(false) +{ +} + +NetworkManager::BridgeDevicePrivate::~BridgeDevicePrivate() +{ +} + +NetworkManager::BridgeDevice::BridgeDevice(const QString &path, QObject *parent) + : Device(*new BridgeDevicePrivate(path, this), parent) +{ + Q_D(BridgeDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::BridgeDevice::~BridgeDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::BridgeDevice::type() const +{ + return NetworkManager::Device::Bridge; +} + +bool NetworkManager::BridgeDevice::carrier() const +{ + Q_D(const BridgeDevice); + + return d->carrier; +} + +QString NetworkManager::BridgeDevice::hwAddress() const +{ + Q_D(const BridgeDevice); + + return d->hwAddress; +} + +QStringList NetworkManager::BridgeDevice::slaves() const +{ + Q_D(const BridgeDevice); + + return d->slaves; +} + +void NetworkManager::BridgeDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(BridgeDevice); + + if (property == QLatin1String("Carrier")) { + carrier = value.toBool(); + Q_EMIT q->carrierChanged(carrier); + } else if (property == QLatin1String("HwAddress")) { + hwAddress = value.toString(); + Q_EMIT q->hwAddressChanged(hwAddress); + } else if (property == QLatin1String("Slaves")) { + QStringList list; + const QList opList = qdbus_cast>(value); + for (const QDBusObjectPath &op : opList) { + list << op.path(); + } + slaves = list; + Q_EMIT q->slavesChanged(slaves); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/bridgedevice.h b/panels/dock/tray/networkmanager-qt/src/bridgedevice.h new file mode 100644 index 000000000..d60287398 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bridgedevice.h @@ -0,0 +1,68 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BRIDGE_DEVICE_H +#define NETWORKMANAGERQT_BRIDGE_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class BridgeDevicePrivate; + +/** + * A bridge device interface + */ +class NETWORKMANAGERQT_EXPORT BridgeDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(bool carrier READ carrier NOTIFY carrierChanged) + Q_PROPERTY(QString hwAddress READ hwAddress NOTIFY hwAddressChanged) + Q_PROPERTY(QStringList slaves READ slaves NOTIFY slavesChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit BridgeDevice(const QString &path, QObject *parent = nullptr); + ~BridgeDevice() override; + + Type type() const override; + + /** + * Indicates whether the physical carrier is found + */ + bool carrier() const; + /** + * Hardware address of the device + */ + QString hwAddress() const; + /** + * Array of object paths representing devices which are currently slaved to this device + */ + QStringList slaves() const; + +Q_SIGNALS: + /** + * Emitted when the carrier of this device has changed + */ + void carrierChanged(bool plugged); + /** + * Emitted when the hardware address of this device has changed + */ + void hwAddressChanged(const QString &address); + /** + * Emitted when the slaves of this device have changed + */ + void slavesChanged(const QStringList &slaves); + +private: + Q_DECLARE_PRIVATE(BridgeDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/bridgedevice_p.h b/panels/dock/tray/networkmanager-qt/src/bridgedevice_p.h new file mode 100644 index 000000000..d7537aad1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/bridgedevice_p.h @@ -0,0 +1,39 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BRIDGE_DEVICE_P_H +#define NETWORKMANAGERQT_BRIDGE_DEVICE_P_H + +#include "bridgedevice.h" +#include "device_p.h" +#include "manager.h" + +#include "bridgedeviceinterface.h" + +namespace NetworkManager +{ +class BridgeDevicePrivate : public DevicePrivate +{ +public: + BridgeDevicePrivate(const QString &path, BridgeDevice *q); + ~BridgeDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceBridgeInterface iface; + bool carrier; + QString hwAddress; + QStringList slaves; + + Q_DECLARE_PUBLIC(BridgeDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/connection.cpp b/panels/dock/tray/networkmanager-qt/src/connection.cpp new file mode 100644 index 000000000..488d3f532 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/connection.cpp @@ -0,0 +1,202 @@ +/* + SPDX-FileCopyrightText: 2008, 2009 Will Stephenson + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "connection_p.h" + +#undef signals +#include +#define signals Q_SIGNALS + +#include +#include + +#include "nmdebug.h" + +NetworkManager::ConnectionPrivate::ConnectionPrivate(const QString &path, Connection *q) +#ifdef NMQT_STATIC + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , q_ptr(q) +{ +} + +NetworkManager::Connection::Connection(const QString &path, QObject *parent) + : QObject(parent) + , d_ptr(new ConnectionPrivate(path, this)) +{ + Q_D(Connection); + + qDBusRegisterMetaType(); + QDBusReply reply = d->iface.GetSettings(); + if (reply.isValid()) { + d->updateSettings(reply.value()); + } else { + d->updateSettings(); + } + d->path = path; + // qCDebug(NMQT) << m_connection; + + connect(&d->iface, &OrgFreedesktopNetworkManagerSettingsConnectionInterface::Updated, d, &ConnectionPrivate::onConnectionUpdated); + connect(&d->iface, &OrgFreedesktopNetworkManagerSettingsConnectionInterface::Removed, d, &ConnectionPrivate::onConnectionRemoved); + + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->path, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + d->unsaved = d->iface.unsaved(); +} + +NetworkManager::Connection::~Connection() +{ + delete d_ptr; +} + +bool NetworkManager::Connection::isValid() const +{ + Q_D(const Connection); + return d->iface.isValid(); +} + +QString NetworkManager::Connection::uuid() const +{ + Q_D(const Connection); + return d->uuid; +} + +QString NetworkManager::Connection::name() const +{ + Q_D(const Connection); + return d->id; +} + +bool NetworkManager::Connection::isUnsaved() const +{ + Q_D(const Connection); + return d->unsaved; +} + +NetworkManager::ConnectionSettings::Ptr NetworkManager::Connection::settings() +{ + Q_D(Connection); + + if (d->connection.isNull()) { + d->connection = ConnectionSettings::Ptr(new ConnectionSettings(d->settings)); + } + return d->connection; +} + +QDBusPendingReply NetworkManager::Connection::secrets(const QString &setting) +{ + Q_D(Connection); + return d->iface.GetSecrets(setting); +} + +QDBusPendingReply<> NetworkManager::Connection::update(const NMVariantMapMap &settings) +{ + Q_D(Connection); + return d->iface.Update(settings); +} + +QDBusPendingReply<> NetworkManager::Connection::updateUnsaved(const NMVariantMapMap &settings) +{ + Q_D(Connection); + return d->iface.UpdateUnsaved(settings); +} + +QDBusPendingReply<> NetworkManager::Connection::save() +{ + Q_D(Connection); + return d->iface.Save(); +} + +QDBusPendingReply<> NetworkManager::Connection::clearSecrets() +{ + Q_D(Connection); + return d->iface.ClearSecrets(); +} + +QDBusPendingReply<> NetworkManager::Connection::remove() +{ + Q_D(Connection); + return d->iface.Delete(); +} + +QString NetworkManager::Connection::path() const +{ + Q_D(const Connection); + return d->path; +} + +void NetworkManager::ConnectionPrivate::onConnectionUpdated() +{ + Q_Q(Connection); + QDBusReply reply = iface.GetSettings(); + if (reply.isValid()) { + updateSettings(reply.value()); + } else { + updateSettings(); + } + Q_EMIT q->updated(); +} + +void NetworkManager::ConnectionPrivate::onConnectionRemoved() +{ + Q_Q(Connection); + QString tmpPath = path; + updateSettings(); + Q_EMIT q->removed(tmpPath); +} + +void NetworkManager::ConnectionPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.Settings.Connection")) { + onPropertiesChanged(properties); + } +} + +void NetworkManager::ConnectionPrivate::onPropertiesChanged(const QVariantMap &properties) +{ + Q_Q(Connection); + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + const QString property = it.key(); + if (property == QLatin1String("Unsaved")) { + unsaved = it->toBool(); + Q_EMIT q->unsavedChanged(unsaved); + } else { + qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } + ++it; + } +} + +void NetworkManager::ConnectionPrivate::updateSettings(const NMVariantMapMap &newSettings) +{ + settings = newSettings; + if (settings.contains(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME))) { + QVariantMap connectionSetting = settings.value(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME)); + if (connectionSetting.contains(QLatin1String(NM_SETTING_CONNECTION_UUID))) { + uuid = connectionSetting.value(QLatin1String(NM_SETTING_CONNECTION_UUID)).toString(); + } + if (connectionSetting.contains(QLatin1String(NM_SETTING_CONNECTION_ID))) { + id = connectionSetting.value(QLatin1String(NM_SETTING_CONNECTION_ID)).toString(); + } + } else if (newSettings.isEmpty()) { + uuid.clear(); + id.clear(); + } + connection.clear(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/connection.h b/panels/dock/tray/networkmanager-qt/src/connection.h new file mode 100644 index 000000000..0be5d2030 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/connection.h @@ -0,0 +1,150 @@ +/* + SPDX-FileCopyrightText: 2008, 2009 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SETTINGS_CONNECTION_H +#define NETWORKMANAGERQT_SETTINGS_CONNECTION_H + +#include "connectionsettings.h" +#include "generictypes.h" +#include + +#include +#include +#include + +class QDBusPendingCallWatcher; + +namespace NetworkManager +{ +class ConnectionPrivate; + +/** + * This class represents a single network connection configuration. + */ +class NETWORKMANAGERQT_EXPORT Connection : public QObject +{ + Q_OBJECT +public: + typedef QSharedPointer Ptr; + typedef QList List; + + /** + * Constructs a connection object for the given path + */ + explicit Connection(const QString &path, QObject *parent = nullptr); + ~Connection() override; + + /** + * Returns if this connection is valid + */ + bool isValid() const; + + /** + * Returns the unique identifier of this connection + */ + QString uuid() const; + + /** + * Returns the path (DBus) of this connection + */ + QString path() const; + + /** + * Returns the name of this connection + */ + QString name() const; + /** + * If set, indicates that the in-memory state of the + * connection does not match the on-disk state. This flag + * will be set when updateUnsaved() is called or when any + * connection details change, and cleared when the connection + * is saved to disk via save() or from internal operations. + * + * @since 0.9.9.0 + */ + bool isUnsaved() const; + /** + * Returns the settings of this connection + */ + ConnectionSettings::Ptr settings(); + + /** + * Retrieves this connections's secrets (passwords and / or encryption keys). + * + * @param setting the setting identifier. + */ + QDBusPendingReply secrets(const QString &setting); + + /** + * Update the connection with new @p settings and properties, replacing all previous settings and properties. + * Secrets may be part of the update request, and will be either stored in persistent storage or given to a Secret Agent for storage, + * depending on the request. + */ + QDBusPendingReply<> update(const NMVariantMapMap &settings); + /** + * Update the connection with new @p settings and properties (replacing + * all previous settings and properties) but do not immediately save + * the connection to disk. Secrets may be part of the update request + * and may sent to a Secret Agent for storage, depending on the + * flags associated with each secret. + * + * Use the save() method to save these changes to disk. Note + * that unsaved changes will be lost if the connection is + * reloaded from disk (either automatically on file change or + * due to an explicit reloadConnections() call). + * + * @since 0.9.9.0 + */ + QDBusPendingReply<> updateUnsaved(const NMVariantMapMap &settings); + + /** + * Saves a "dirty" connection (that had previously been + * updated with updateUnsaved()) to persistent storage. + * + * @since 0.9.9.0 + */ + QDBusPendingReply<> save(); + + /** + * Clear the secrets belonging to this network connection profile. + * @since 5.8.0 + */ + QDBusPendingReply<> clearSecrets(); + + /** + * Removes the connection from NetworkManager database, + * this operation does not ask for confirmation but + * a policykit rule might prevent it from being removed + * without the proper password. + */ + QDBusPendingReply<> remove(); + +Q_SIGNALS: + /** + * Emitted when the connection settings changes + */ + void updated(); + + /** + * Emitted when the connection was removed + * @param path connections's path. + */ + void removed(const QString &path); + /** + * Emitted when the connection unsaved state changes + */ + void unsavedChanged(bool unsaved); + +private: + Q_DECLARE_PRIVATE(Connection) + + ConnectionPrivate *const d_ptr; +}; + +} +#endif // CONNECTION_H diff --git a/panels/dock/tray/networkmanager-qt/src/connection_p.h b/panels/dock/tray/networkmanager-qt/src/connection_p.h new file mode 100644 index 000000000..f26016da8 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/connection_p.h @@ -0,0 +1,48 @@ +/* + SPDX-FileCopyrightText: 2008, 2009 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SETTINGS_CONNECTION_P_H +#define NETWORKMANAGERQT_SETTINGS_CONNECTION_P_H + +#include "connection.h" +#include "connectioninterface.h" +#include "device.h" +#include "generictypes.h" +#include "manager_p.h" + +class QDBusPendingCallWatcher; + +namespace NetworkManager +{ +class ConnectionPrivate : public QObject +{ + Q_OBJECT +public: + ConnectionPrivate(const QString &path, Connection *q); + + void updateSettings(const NMVariantMapMap &newSettings = NMVariantMapMap()); + bool unsaved; + QString uuid; + QString id; + NMVariantMapMap settings; + ConnectionSettings::Ptr connection; + QString path; + OrgFreedesktopNetworkManagerSettingsConnectionInterface iface; + + Q_DECLARE_PUBLIC(Connection) + Connection *q_ptr; +private Q_SLOTS: + void onConnectionUpdated(); + void onConnectionRemoved(); + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void onPropertiesChanged(const QVariantMap &properties); +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/CMakeLists.txt b/panels/dock/tray/networkmanager-qt/src/dbus/CMakeLists.txt new file mode 100644 index 000000000..1616f80ee --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/CMakeLists.txt @@ -0,0 +1,75 @@ +# Steps to generate the dbus interface files +# 1) Place the NetworkManager introspection dbus xml in introspection/ +# 2) Update the list of xml files below that we want to generate interfaces for +# 3) Enable dbus subdirectory in ../CMakeLists.txt +# Make, in order to generate the interface sources +# 3.1) Add annotations to the xml so qdbusxml2cpp knows what type or typedef to use +# Add typedefs as needed to generictypes.h +# 4) Add the list of generated files needed for the plugin to FILES_TO_BUILD +# 6) Copy the working generated interface sources into the source dir +# 5) Edit the sources as required to get them to build +# 5.1) Fix the inclusion guards as the compiler ignores anything after a '-' so the compiler thinks +# headers have already been included +# Run do-hand-edits to update the diff of the interfaces vs what is generated; this speeds up regenerating them since you just have to apply the diff to make them compile + +set(INTERFACE_INTROSPECTION_XML_FILES + introspection/nm-agent-manager.xml + introspection/org.freedesktop.NetworkManager.AccessPoint.xml + introspection/org.freedesktop.NetworkManager.AgentManager.xml + introspection/org.freedesktop.NetworkManager.Connection.Active.xml + introspection/org.freedesktop.NetworkManager.Device.Adsl.xml + introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml + introspection/org.freedesktop.NetworkManager.Device.Bond.xml + introspection/org.freedesktop.NetworkManager.Device.Bridge.xml + introspection/org.freedesktop.NetworkManager.Device.Generic.xml + introspection/org.freedesktop.NetworkManager.Device.Gre.xml + introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml + introspection/org.freedesktop.NetworkManager.Device.IPTunnel.xml + introspection/org.freedesktop.NetworkManager.Device.Macsec.xml + introspection/org.freedesktop.NetworkManager.Device.Macvlan.xml + introspection/org.freedesktop.NetworkManager.Device.Modem.xml + introspection/org.freedesktop.NetworkManager.Device.OlpcMesh.xml + introspection/org.freedesktop.NetworkManager.Device.Statistics.xml + introspection/org.freedesktop.NetworkManager.Device.Team.xml + introspection/org.freedesktop.NetworkManager.Device.Tun.xml + introspection/org.freedesktop.NetworkManager.Device.Veth.xml + introspection/org.freedesktop.NetworkManager.Device.Vlan.xml + introspection/org.freedesktop.NetworkManager.Device.Vxlan.xml + introspection/org.freedesktop.NetworkManager.Device.WiMax.xml + introspection/org.freedesktop.NetworkManager.Device.Wired.xml + introspection/org.freedesktop.NetworkManager.Device.Wireless.xml + introspection/org.freedesktop.NetworkManager.Device.xml + introspection/org.freedesktop.NetworkManager.DHCP4Config.xml + introspection/org.freedesktop.NetworkManager.DHCP6Config.xml + introspection/org.freedesktop.NetworkManager.DnsManager.xml + introspection/org.freedesktop.NetworkManager.Checkpoint.xml + introspection/org.freedesktop.NetworkManager.IP4Config.xml + introspection/org.freedesktop.NetworkManager.IP6Config.xml + introspection/org.freedesktop.NetworkManager.PPP.xml +# introspection/org.freedesktop.NetworkManager.Settings.Connection.xml + introspection/org.freedesktop.NetworkManager.Settings.xml + introspection/org.freedesktop.NetworkManager.VPN.Connection.xml + introspection/org.freedesktop.NetworkManager.VPN.Plugin.xml + introspection/org.freedesktop.NetworkManager.WiMax.Nsp.xml + introspection/org.freedesktop.NetworkManager.xml + ) + +set_property(SOURCE ${INTERFACE_INTROSPECTION_XML_FILES} PROPERTY INCLUDE generictypes.h) + +set(ADAPTER_INTROSPECTION_XML_FILES + ) + +set_source_files_properties(${INTERFACE_INTROSPECTION_XML_FILES} ${ADAPTER_INTROSPECTION_XML_FILES} PROPERTIES NO_NAMESPACE TRUE) + +set(FILES_TO_BUILD + ) + +qt_add_dbus_interfaces(FILES_TO_BUILD ${INTERFACE_INTROSPECTION_XML_FILES}) +qt_add_dbus_adaptor(FILES_TO_BUILD introspection/org.freedesktop.NetworkManager.SecretAgent.xml "secretagent.h" "NetworkManager::SecretAgent") +foreach(adaptor ${ADAPTER_INTROSPECTION_XML_FILES}) + qt_add_dbus_adaptor(FILES_TO_BUILD ${adaptor} "generictypes.h") +endforeach(adaptor ${ADAPTER_INTROSPECTION_XML_FILES}) + +add_library(networkmanagerdbus ${FILES_TO_BUILD}) + +target_link_libraries(networkmanagerdbus ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY}) diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/accesspointinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/accesspointinterface.cpp new file mode 100644 index 000000000..cb513fabc --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/accesspointinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "accesspointinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerAccessPointInterface + */ + +OrgFreedesktopNetworkManagerAccessPointInterface::OrgFreedesktopNetworkManagerAccessPointInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerAccessPointInterface::~OrgFreedesktopNetworkManagerAccessPointInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/accesspointinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/accesspointinterface.h new file mode 100644 index 000000000..416fda83e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/accesspointinterface.h @@ -0,0 +1,109 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef ACCESSPOINTINTERFACE_H +#define ACCESSPOINTINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.AccessPoint + */ +class OrgFreedesktopNetworkManagerAccessPointInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.AccessPoint"; + } +#else + { + return "org.freedesktop.NetworkManager.AccessPoint"; + } +#endif +public: + OrgFreedesktopNetworkManagerAccessPointInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerAccessPointInterface() override; + + Q_PROPERTY(uint Flags READ flags) + inline uint flags() const + { + return qvariant_cast(property("Flags")); + } + + Q_PROPERTY(uint Frequency READ frequency) + inline uint frequency() const + { + return qvariant_cast(property("Frequency")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(int LastSeen READ lastSeen) + inline int lastSeen() const + { + return qvariant_cast(property("LastSeen")); + } + + Q_PROPERTY(uint MaxBitrate READ maxBitrate) + inline uint maxBitrate() const + { + return qvariant_cast(property("MaxBitrate")); + } + + Q_PROPERTY(uint Mode READ mode) + inline uint mode() const + { + return qvariant_cast(property("Mode")); + } + + Q_PROPERTY(uint RsnFlags READ rsnFlags) + inline uint rsnFlags() const + { + return qvariant_cast(property("RsnFlags")); + } + + Q_PROPERTY(QByteArray Ssid READ ssid) + inline QByteArray ssid() const + { + return qvariant_cast(property("Ssid")); + } + + Q_PROPERTY(uchar Strength READ strength) + inline uchar strength() const + { + return qvariant_cast(property("Strength")); + } + + Q_PROPERTY(uint WpaFlags READ wpaFlags) + inline uint wpaFlags() const + { + return qvariant_cast(property("WpaFlags")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/activeconnectioninterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/activeconnectioninterface.cpp new file mode 100644 index 000000000..74cb343f6 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/activeconnectioninterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "activeconnectioninterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerConnectionActiveInterface + */ + +OrgFreedesktopNetworkManagerConnectionActiveInterface::OrgFreedesktopNetworkManagerConnectionActiveInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerConnectionActiveInterface::~OrgFreedesktopNetworkManagerConnectionActiveInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/activeconnectioninterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/activeconnectioninterface.h new file mode 100644 index 000000000..dd402ec77 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/activeconnectioninterface.h @@ -0,0 +1,144 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef ACTIVECONNECTIONINTERFACE_H +#define ACTIVECONNECTIONINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Connection.Active + */ +class OrgFreedesktopNetworkManagerConnectionActiveInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Connection.Active"; + } +#else + { + return "org.freedesktop.NetworkManager.Connection.Active"; + } +#endif + +public: + OrgFreedesktopNetworkManagerConnectionActiveInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerConnectionActiveInterface() override; + + Q_PROPERTY(QDBusObjectPath Connection READ connection) + inline QDBusObjectPath connection() const + { + return qvariant_cast(property("Connection")); + } + + Q_PROPERTY(bool Default READ default4) + inline bool default4() const + { + return qvariant_cast(property("Default")); + } + + Q_PROPERTY(bool Default6 READ default6) + inline bool default6() const + { + return qvariant_cast(property("Default6")); + } + + Q_PROPERTY(QList Devices READ devices) + inline QList devices() const + { + return qvariant_cast>(property("Devices")); + } + + Q_PROPERTY(QDBusObjectPath Dhcp4Config READ dhcp4Config) + inline QDBusObjectPath dhcp4Config() const + { + return qvariant_cast(property("Dhcp4Config")); + } + + Q_PROPERTY(QDBusObjectPath Dhcp6Config READ dhcp6Config) + inline QDBusObjectPath dhcp6Config() const + { + return qvariant_cast(property("Dhcp6Config")); + } + + Q_PROPERTY(QString Id READ id) + inline QString id() const + { + return qvariant_cast(property("Id")); + } + + Q_PROPERTY(QDBusObjectPath Ip4Config READ ip4Config) + inline QDBusObjectPath ip4Config() const + { + return qvariant_cast(property("Ip4Config")); + } + + Q_PROPERTY(QDBusObjectPath Ip6Config READ ip6Config) + inline QDBusObjectPath ip6Config() const + { + return qvariant_cast(property("Ip6Config")); + } + + Q_PROPERTY(QDBusObjectPath Master READ master) + inline QDBusObjectPath master() const + { + return qvariant_cast(property("Master")); + } + + Q_PROPERTY(QDBusObjectPath SpecificObject READ specificObject) + inline QDBusObjectPath specificObject() const + { + return qvariant_cast(property("SpecificObject")); + } + + Q_PROPERTY(uint State READ state) + inline uint state() const + { + return qvariant_cast(property("State")); + } + + Q_PROPERTY(QString Type READ type) + inline QString type() const + { + return qvariant_cast(property("Type")); + } + + Q_PROPERTY(QString Uuid READ uuid) + inline QString uuid() const + { + return qvariant_cast(property("Uuid")); + } + + Q_PROPERTY(bool Vpn READ vpn) + inline bool vpn() const + { + return qvariant_cast(property("Vpn")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); + void StateChanged(uint state, uint reason); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/adsldeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/adsldeviceinterface.cpp new file mode 100644 index 000000000..af1339f53 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/adsldeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "adsldeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceAdslInterface + */ + +OrgFreedesktopNetworkManagerDeviceAdslInterface::OrgFreedesktopNetworkManagerDeviceAdslInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceAdslInterface::~OrgFreedesktopNetworkManagerDeviceAdslInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/adsldeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/adsldeviceinterface.h new file mode 100644 index 000000000..cf0f50761 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/adsldeviceinterface.h @@ -0,0 +1,55 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef ADSLDEVICEINTERFACE_H +#define ADSLDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Adsl + */ +class OrgFreedesktopNetworkManagerDeviceAdslInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Adsl"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Adsl"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceAdslInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceAdslInterface() override; + + Q_PROPERTY(bool Carrier READ carrier) + inline bool carrier() const + { + return qvariant_cast(property("Carrier")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/agentmanagerinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/agentmanagerinterface.cpp new file mode 100644 index 000000000..b6f1d8426 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/agentmanagerinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "agentmanagerinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerAgentManagerInterface + */ + +OrgFreedesktopNetworkManagerAgentManagerInterface::OrgFreedesktopNetworkManagerAgentManagerInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerAgentManagerInterface::~OrgFreedesktopNetworkManagerAgentManagerInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/agentmanagerinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/agentmanagerinterface.h new file mode 100644 index 000000000..9ef7f67a3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/agentmanagerinterface.h @@ -0,0 +1,72 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef AGENTMANAGERINTERFACE_H +#define AGENTMANAGERINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.AgentManager + */ +class OrgFreedesktopNetworkManagerAgentManagerInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.AgentManager"; + } +#else + { + return "org.freedesktop.NetworkManager.AgentManager"; + } +#endif + +public: + OrgFreedesktopNetworkManagerAgentManagerInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerAgentManagerInterface() override; + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> Register(const QString &identifier) + { + QList argumentList; + argumentList << QVariant::fromValue(identifier); + return asyncCallWithArgumentList(QStringLiteral("Register"), argumentList); + } + + inline QDBusPendingReply<> RegisterWithCapabilities(const QString &identifier, uint capabilities) + { + QList argumentList; + argumentList << QVariant::fromValue(identifier) << QVariant::fromValue(capabilities); + return asyncCallWithArgumentList(QStringLiteral("RegisterWithCapabilities"), argumentList); + } + + inline QDBusPendingReply<> Unregister() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Unregister"), argumentList); + } + +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/bluetoothdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/bluetoothdeviceinterface.cpp new file mode 100644 index 000000000..23018e113 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/bluetoothdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "bluetoothdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceBluetoothInterface + */ + +OrgFreedesktopNetworkManagerDeviceBluetoothInterface::OrgFreedesktopNetworkManagerDeviceBluetoothInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceBluetoothInterface::~OrgFreedesktopNetworkManagerDeviceBluetoothInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/bluetoothdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/bluetoothdeviceinterface.h new file mode 100644 index 000000000..f71850276 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/bluetoothdeviceinterface.h @@ -0,0 +1,70 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef BLUETOOTHDEVICEINTERFACE_H +#define BLUETOOTHDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Bluetooth + */ +class OrgFreedesktopNetworkManagerDeviceBluetoothInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Bluetooth"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Bluetooth"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceBluetoothInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceBluetoothInterface() override; + + Q_PROPERTY(uint BtCapabilities READ btCapabilities) + inline uint btCapabilities() const + { + return qvariant_cast(property("BtCapabilities")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QString Name READ name) + inline QString name() const + { + return qvariant_cast(property("Name")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/bonddeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/bonddeviceinterface.cpp new file mode 100644 index 000000000..3b5c2c02a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/bonddeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "bonddeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceBondInterface + */ + +OrgFreedesktopNetworkManagerDeviceBondInterface::OrgFreedesktopNetworkManagerDeviceBondInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceBondInterface::~OrgFreedesktopNetworkManagerDeviceBondInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/bonddeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/bonddeviceinterface.h new file mode 100644 index 000000000..2a4016b1f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/bonddeviceinterface.h @@ -0,0 +1,68 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef BONDDEVICEINTERFACE_H +#define BONDDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Bond + */ +class OrgFreedesktopNetworkManagerDeviceBondInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Bond"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Bond"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceBondInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceBondInterface() override; + + Q_PROPERTY(bool Carrier READ carrier) + inline bool carrier() const + { + return qvariant_cast(property("Carrier")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QList Slaves READ slaves) + inline QList slaves() const + { + return qvariant_cast>(property("Slaves")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/bridgedeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/bridgedeviceinterface.cpp new file mode 100644 index 000000000..9c2b78de4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/bridgedeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "bridgedeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceBridgeInterface + */ + +OrgFreedesktopNetworkManagerDeviceBridgeInterface::OrgFreedesktopNetworkManagerDeviceBridgeInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceBridgeInterface::~OrgFreedesktopNetworkManagerDeviceBridgeInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/bridgedeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/bridgedeviceinterface.h new file mode 100644 index 000000000..9acd43973 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/bridgedeviceinterface.h @@ -0,0 +1,71 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef BRIDGEDEVICEINTERFACE_H +#define BRIDGEDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Bridge + */ +class OrgFreedesktopNetworkManagerDeviceBridgeInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Bridge"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Bridge"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceBridgeInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceBridgeInterface() override; + + Q_PROPERTY(bool Carrier READ carrier) + inline bool carrier() const + { + return qvariant_cast(property("Carrier")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QList Slaves READ slaves) + inline QList slaves() const + { + return qvariant_cast>(property("Slaves")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/checkpointinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/checkpointinterface.cpp new file mode 100644 index 000000000..ceabbd4c2 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/checkpointinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "checkpointinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerCheckpointInterface + */ + +OrgFreedesktopNetworkManagerCheckpointInterface::OrgFreedesktopNetworkManagerCheckpointInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerCheckpointInterface::~OrgFreedesktopNetworkManagerCheckpointInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/checkpointinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/checkpointinterface.h new file mode 100644 index 000000000..187d0f956 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/checkpointinterface.h @@ -0,0 +1,68 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef CHECKPOINTINTERFACE_H +#define CHECKPOINTINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Checkpoint + */ +class OrgFreedesktopNetworkManagerCheckpointInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Checkpoint"; + } +#else + { + return "org.freedesktop.NetworkManager.Checkpoint"; + } +#endif + +public: + OrgFreedesktopNetworkManagerCheckpointInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerCheckpointInterface() override; + + Q_PROPERTY(qlonglong Created READ created) + inline qlonglong created() const + { + return qvariant_cast(property("Created")); + } + + Q_PROPERTY(QList Devices READ devices) + inline QList devices() const + { + return qvariant_cast>(property("Devices")); + } + + Q_PROPERTY(uint RollbackTimeout READ rollbackTimeout) + inline uint rollbackTimeout() const + { + return qvariant_cast(property("RollbackTimeout")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/connectioninterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/connectioninterface.cpp new file mode 100644 index 000000000..3467d6505 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/connectioninterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "connectioninterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerSettingsConnectionInterface + */ + +OrgFreedesktopNetworkManagerSettingsConnectionInterface::OrgFreedesktopNetworkManagerSettingsConnectionInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerSettingsConnectionInterface::~OrgFreedesktopNetworkManagerSettingsConnectionInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/connectioninterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/connectioninterface.h new file mode 100644 index 000000000..ab20d58ae --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/connectioninterface.h @@ -0,0 +1,106 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef CONNECTIONINTERFACE_H +#define CONNECTIONINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Settings.Connection + */ +class OrgFreedesktopNetworkManagerSettingsConnectionInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Settings.Connection"; + } +#else + { + return "org.freedesktop.NetworkManager.Settings.Connection"; + } +#endif + +public: + OrgFreedesktopNetworkManagerSettingsConnectionInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerSettingsConnectionInterface() override; + + Q_PROPERTY(bool Unsaved READ unsaved) + inline bool unsaved() const + { + return qvariant_cast(property("Unsaved")); + } + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> ClearSecrets() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("ClearSecrets"), argumentList); + } + + inline QDBusPendingReply<> Delete() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Delete"), argumentList); + } + + inline QDBusPendingReply GetSecrets(const QString &setting_name) + { + QList argumentList; + argumentList << QVariant::fromValue(setting_name); + return asyncCallWithArgumentList(QStringLiteral("GetSecrets"), argumentList); + } + + inline QDBusPendingReply GetSettings() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetSettings"), argumentList); + } + + inline QDBusPendingReply<> Save() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Save"), argumentList); + } + + inline QDBusPendingReply<> Update(NMVariantMapMap properties) + { + QList argumentList; + argumentList << QVariant::fromValue(properties); + return asyncCallWithArgumentList(QStringLiteral("Update"), argumentList); + } + + inline QDBusPendingReply<> UpdateUnsaved(NMVariantMapMap properties) + { + QList argumentList; + argumentList << QVariant::fromValue(properties); + return asyncCallWithArgumentList(QStringLiteral("UpdateUnsaved"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); + void Removed(); + void Updated(); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/deviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/deviceinterface.cpp new file mode 100644 index 000000000..a4778e3ed --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/deviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "deviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceInterface + */ + +OrgFreedesktopNetworkManagerDeviceInterface::OrgFreedesktopNetworkManagerDeviceInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceInterface::~OrgFreedesktopNetworkManagerDeviceInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/deviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/deviceinterface.h new file mode 100644 index 000000000..e5fd468d2 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/deviceinterface.h @@ -0,0 +1,246 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef DEVICEINTERFACE_H +#define DEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device + */ +class OrgFreedesktopNetworkManagerDeviceInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device"; + } +#else + { + return "org.freedesktop.NetworkManager.Device"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceInterface() override; + + Q_PROPERTY(QDBusObjectPath ActiveConnection READ activeConnection) + inline QDBusObjectPath activeConnection() const + { + return qvariant_cast(property("ActiveConnection")); + } + + Q_PROPERTY(bool Autoconnect READ autoconnect WRITE setAutoconnect) + inline bool autoconnect() const + { + return qvariant_cast(property("Autoconnect")); + } + inline void setAutoconnect(bool value) + { + setProperty("Autoconnect", QVariant::fromValue(value)); + } + + Q_PROPERTY(QList AvailableConnections READ availableConnections) + inline QList availableConnections() const + { + return qvariant_cast>(property("AvailableConnections")); + } + + Q_PROPERTY(uint Capabilities READ capabilities) + inline uint capabilities() const + { + return qvariant_cast(property("Capabilities")); + } + + Q_PROPERTY(uint DeviceType READ deviceType) + inline uint deviceType() const + { + return qvariant_cast(property("DeviceType")); + } + + Q_PROPERTY(QDBusObjectPath Dhcp4Config READ dhcp4Config) + inline QDBusObjectPath dhcp4Config() const + { + return qvariant_cast(property("Dhcp4Config")); + } + + Q_PROPERTY(QDBusObjectPath Dhcp6Config READ dhcp6Config) + inline QDBusObjectPath dhcp6Config() const + { + return qvariant_cast(property("Dhcp6Config")); + } + + Q_PROPERTY(QString Driver READ driver) + inline QString driver() const + { + return qvariant_cast(property("Driver")); + } + + Q_PROPERTY(QString DriverVersion READ driverVersion) + inline QString driverVersion() const + { + return qvariant_cast(property("DriverVersion")); + } + + Q_PROPERTY(bool FirmwareMissing READ firmwareMissing) + inline bool firmwareMissing() const + { + return qvariant_cast(property("FirmwareMissing")); + } + + Q_PROPERTY(QString FirmwareVersion READ firmwareVersion) + inline QString firmwareVersion() const + { + return qvariant_cast(property("FirmwareVersion")); + } + + Q_PROPERTY(QString Interface READ interface) + inline QString interface() const + { + return qvariant_cast(property("Interface")); + } + + Q_PROPERTY(uint Ip4Address READ ip4Address) + inline uint ip4Address() const + { + return qvariant_cast(property("Ip4Address")); + } + + Q_PROPERTY(QDBusObjectPath Ip4Config READ ip4Config) + inline QDBusObjectPath ip4Config() const + { + return qvariant_cast(property("Ip4Config")); + } + + Q_PROPERTY(QDBusObjectPath Ip6Config READ ip6Config) + inline QDBusObjectPath ip6Config() const + { + return qvariant_cast(property("Ip6Config")); + } + + Q_PROPERTY(QString IpInterface READ ipInterface) + inline QString ipInterface() const + { + return qvariant_cast(property("IpInterface")); + } + + Q_PROPERTY(uint InterfaceFlags READ interfaceFlags) + inline uint interfaceFlags() const + { + return qvariant_cast(property("InterfaceFlags")); + } + + Q_PROPERTY(NMVariantMapList LldpNeighbors READ lldpNeighbors) + inline NMVariantMapList lldpNeighbors() const + { + return qvariant_cast(property("LldpNeighbors")); + } + + Q_PROPERTY(bool Managed READ managed WRITE setManaged) + inline bool managed() const + { + return qvariant_cast(property("Managed")); + } + inline void setManaged(bool value) + { + setProperty("Managed", QVariant::fromValue(value)); + } + + Q_PROPERTY(uint Metered READ metered) + inline uint metered() const + { + return qvariant_cast(property("Metered")); + } + + Q_PROPERTY(uint Mtu READ mtu) + inline uint mtu() const + { + return qvariant_cast(property("Mtu")); + } + + Q_PROPERTY(bool NmPluginMissing READ nmPluginMissing) + inline bool nmPluginMissing() const + { + return qvariant_cast(property("NmPluginMissing")); + } + + Q_PROPERTY(QString PhysicalPortId READ physicalPortId) + inline QString physicalPortId() const + { + return qvariant_cast(property("PhysicalPortId")); + } + + Q_PROPERTY(bool Real READ real) + inline bool real() const + { + return qvariant_cast(property("Real")); + } + + Q_PROPERTY(uint State READ state) + inline uint state() const + { + return qvariant_cast(property("State")); + } + + Q_PROPERTY(DeviceDBusStateReason StateReason READ stateReason) + inline DeviceDBusStateReason stateReason() const + { + return qvariant_cast(property("StateReason")); + } + + Q_PROPERTY(QString Udi READ udi) + inline QString udi() const + { + return qvariant_cast(property("Udi")); + } + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> Delete() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Delete"), argumentList); + } + + inline QDBusPendingReply<> Disconnect() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Disconnect"), argumentList); + } + + inline QDBusPendingReply GetAppliedConnection(uint flags) + { + QList argumentList; + argumentList << QVariant::fromValue(flags); + return asyncCallWithArgumentList(QStringLiteral("GetAppliedConnection"), argumentList); + } + + inline QDBusPendingReply<> Reapply(NMVariantMapMap connection, qulonglong version_id, uint flags) + { + QList argumentList; + argumentList << QVariant::fromValue(connection) << QVariant::fromValue(version_id) << QVariant::fromValue(flags); + return asyncCallWithArgumentList(QStringLiteral("Reapply"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void StateChanged(uint new_state, uint old_state, uint reason); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/devicestatisticsinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/devicestatisticsinterface.cpp new file mode 100644 index 000000000..641eee21f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/devicestatisticsinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "devicestatisticsinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceStatisticsInterface + */ + +OrgFreedesktopNetworkManagerDeviceStatisticsInterface::OrgFreedesktopNetworkManagerDeviceStatisticsInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceStatisticsInterface::~OrgFreedesktopNetworkManagerDeviceStatisticsInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/devicestatisticsinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/devicestatisticsinterface.h new file mode 100644 index 000000000..7b93e014b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/devicestatisticsinterface.h @@ -0,0 +1,74 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef DEVICESTATISTICSINTERFACE_H +#define DEVICESTATISTICSINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Statistics + */ +class OrgFreedesktopNetworkManagerDeviceStatisticsInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Statistics"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Statistics"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceStatisticsInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceStatisticsInterface() override; + + Q_PROPERTY(uint RefreshRateMs READ refreshRateMs WRITE setRefreshRateMs) + inline uint refreshRateMs() const + { + return qvariant_cast(property("RefreshRateMs")); + } + inline void setRefreshRateMs(uint value) + { + setProperty("RefreshRateMs", QVariant::fromValue(value)); + } + + Q_PROPERTY(qulonglong RxBytes READ rxBytes) + inline qulonglong rxBytes() const + { + return qvariant_cast(property("RxBytes")); + } + + Q_PROPERTY(qulonglong TxBytes READ txBytes) + inline qulonglong txBytes() const + { + return qvariant_cast(property("TxBytes")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/dhcp4configinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/dhcp4configinterface.cpp new file mode 100644 index 000000000..72799e374 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/dhcp4configinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "dhcp4configinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDHCP4ConfigInterface + */ + +OrgFreedesktopNetworkManagerDHCP4ConfigInterface::OrgFreedesktopNetworkManagerDHCP4ConfigInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDHCP4ConfigInterface::~OrgFreedesktopNetworkManagerDHCP4ConfigInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/dhcp4configinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/dhcp4configinterface.h new file mode 100644 index 000000000..fca6483e6 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/dhcp4configinterface.h @@ -0,0 +1,55 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef DHCP4CONFIGINTERFACE_H +#define DHCP4CONFIGINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.DHCP4Config + */ +class OrgFreedesktopNetworkManagerDHCP4ConfigInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.DHCP4Config"; + } +#else + { + return "org.freedesktop.NetworkManager.DHCP4Config"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDHCP4ConfigInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDHCP4ConfigInterface() override; + + Q_PROPERTY(QVariantMap Options READ options) + inline QVariantMap options() const + { + return qvariant_cast(property("Options")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/dhcp6configinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/dhcp6configinterface.cpp new file mode 100644 index 000000000..3cf9c9f0b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/dhcp6configinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "dhcp6configinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDHCP6ConfigInterface + */ + +OrgFreedesktopNetworkManagerDHCP6ConfigInterface::OrgFreedesktopNetworkManagerDHCP6ConfigInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDHCP6ConfigInterface::~OrgFreedesktopNetworkManagerDHCP6ConfigInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/dhcp6configinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/dhcp6configinterface.h new file mode 100644 index 000000000..37623d5ce --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/dhcp6configinterface.h @@ -0,0 +1,55 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef DHCP6CONFIGINTERFACE_H +#define DHCP6CONFIGINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.DHCP6Config + */ +class OrgFreedesktopNetworkManagerDHCP6ConfigInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.DHCP6Config"; + } +#else + { + return "org.freedesktop.NetworkManager.DHCP6Config"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDHCP6ConfigInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDHCP6ConfigInterface() override; + + Q_PROPERTY(QVariantMap Options READ options) + inline QVariantMap options() const + { + return qvariant_cast(property("Options")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/dnsmanagerinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/dnsmanagerinterface.cpp new file mode 100644 index 000000000..45f5ba4d4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/dnsmanagerinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "dnsmanagerinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDnsManagerInterface + */ + +OrgFreedesktopNetworkManagerDnsManagerInterface::OrgFreedesktopNetworkManagerDnsManagerInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDnsManagerInterface::~OrgFreedesktopNetworkManagerDnsManagerInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/dnsmanagerinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/dnsmanagerinterface.h new file mode 100644 index 000000000..21af40200 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/dnsmanagerinterface.h @@ -0,0 +1,65 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef DNSMANAGERINTERFACE_H +#define DNSMANAGERINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.DnsManager + */ +class OrgFreedesktopNetworkManagerDnsManagerInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.DnsManager"; + } +#else + { + return "org.freedesktop.NetworkManager.DnsManager"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDnsManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDnsManagerInterface() override; + + Q_PROPERTY(NMVariantMapList Configuration READ configuration) + inline NMVariantMapList configuration() const + { + return qvariant_cast(property("Configuration")); + } + + Q_PROPERTY(QString Mode READ mode) + inline QString mode() const + { + return qvariant_cast(property("Mode")); + } + + Q_PROPERTY(QString RcManager READ rcManager) + inline QString rcManager() const + { + return qvariant_cast(property("RcManager")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/genericdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/genericdeviceinterface.cpp new file mode 100644 index 000000000..ec6bf0680 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/genericdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "genericdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceGenericInterface + */ + +OrgFreedesktopNetworkManagerDeviceGenericInterface::OrgFreedesktopNetworkManagerDeviceGenericInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceGenericInterface::~OrgFreedesktopNetworkManagerDeviceGenericInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/genericdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/genericdeviceinterface.h new file mode 100644 index 000000000..c41169d67 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/genericdeviceinterface.h @@ -0,0 +1,64 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef GENERICDEVICEINTERFACE_H +#define GENERICDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Generic + */ +class OrgFreedesktopNetworkManagerDeviceGenericInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Generic"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Generic"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceGenericInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceGenericInterface() override; + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QString TypeDescription READ typeDescription) + inline QString typeDescription() const + { + return qvariant_cast(property("TypeDescription")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/gredeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/gredeviceinterface.cpp new file mode 100644 index 000000000..06dfd7f98 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/gredeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "gredeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceGreInterface + */ + +OrgFreedesktopNetworkManagerDeviceGreInterface::OrgFreedesktopNetworkManagerDeviceGreInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceGreInterface::~OrgFreedesktopNetworkManagerDeviceGreInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/gredeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/gredeviceinterface.h new file mode 100644 index 000000000..7c51016c8 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/gredeviceinterface.h @@ -0,0 +1,109 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef GREDEVICEINTERFACE_H +#define GREDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Gre + */ +class OrgFreedesktopNetworkManagerDeviceGreInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Gre"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Gre"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceGreInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceGreInterface() override; + + Q_PROPERTY(ushort InputFlags READ inputFlags) + inline ushort inputFlags() const + { + return qvariant_cast(property("InputFlags")); + } + + Q_PROPERTY(uint InputKey READ inputKey) + inline uint inputKey() const + { + return qvariant_cast(property("InputKey")); + } + + Q_PROPERTY(QString Local READ local) + inline QString local() const + { + return qvariant_cast(property("Local")); + } + + Q_PROPERTY(ushort OutputFlags READ outputFlags) + inline ushort outputFlags() const + { + return qvariant_cast(property("OutputFlags")); + } + + Q_PROPERTY(uint OutputKey READ outputKey) + inline uint outputKey() const + { + return qvariant_cast(property("OutputKey")); + } + + Q_PROPERTY(QDBusObjectPath Parent READ parent) + inline QDBusObjectPath parent() const + { + return qvariant_cast(property("Parent")); + } + + Q_PROPERTY(bool PathMtuDiscovery READ pathMtuDiscovery) + inline bool pathMtuDiscovery() const + { + return qvariant_cast(property("PathMtuDiscovery")); + } + + Q_PROPERTY(QString Remote READ remote) + inline QString remote() const + { + return qvariant_cast(property("Remote")); + } + + Q_PROPERTY(uchar Tos READ tos) + inline uchar tos() const + { + return qvariant_cast(property("Tos")); + } + + Q_PROPERTY(uchar Ttl READ ttl) + inline uchar ttl() const + { + return qvariant_cast(property("Ttl")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/infinibanddeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/infinibanddeviceinterface.cpp new file mode 100644 index 000000000..fcb27f398 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/infinibanddeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "infinibanddeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceInfinibandInterface + */ + +OrgFreedesktopNetworkManagerDeviceInfinibandInterface::OrgFreedesktopNetworkManagerDeviceInfinibandInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceInfinibandInterface::~OrgFreedesktopNetworkManagerDeviceInfinibandInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/infinibanddeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/infinibanddeviceinterface.h new file mode 100644 index 000000000..b1a8f2054 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/infinibanddeviceinterface.h @@ -0,0 +1,64 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef INFINIBANDDEVICEINTERFACE_H +#define INFINIBANDDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Infiniband + */ +class OrgFreedesktopNetworkManagerDeviceInfinibandInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Infiniband"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Infiniband"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceInfinibandInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceInfinibandInterface() override; + + Q_PROPERTY(bool Carrier READ carrier) + inline bool carrier() const + { + return qvariant_cast(property("Carrier")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/nm-agent-manager.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/nm-agent-manager.xml new file mode 100644 index 000000000..d10744286 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/nm-agent-manager.xml @@ -0,0 +1,56 @@ + + + + + + + + Called by secret Agents to register their ability to provide and save + network secrets. + + + + + + Identifies this agent; only one agent in each user session may use the + same identifier. Identifier formatting follows the same rules as + D-Bus bus names with the exception that the ':' character is not + allowed. The valid set of characters is "[A-Z][a-z][0-9]_-." and the + identifier is limited in length to 255 characters with a minimum + of 3 characters. An example valid identifier is 'org.gnome.nm-applet' + (without quotes). + + + + + + + Like Register() but indicates agent capabilities to NetworkManager. + + + + + + See the Register() method's identifier argument. + + + + + Indicates various agent capabilities to NetworkManager. + + + + + + + Called by secret Agents to notify NetworkManager that they will no + longer handle requests for network secrets. Agents are automatically + unregistered when they disconnect from D-Bus. + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.AccessPoint.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.AccessPoint.xml new file mode 100644 index 000000000..45d07f7eb --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.AccessPoint.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.AgentManager.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.AgentManager.xml new file mode 100644 index 000000000..86b4404a1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.AgentManager.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Checkpoint.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Checkpoint.xml new file mode 100644 index 000000000..33c21bc29 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Checkpoint.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Connection.Active.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Connection.Active.xml new file mode 100644 index 000000000..ee741e042 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Connection.Active.xml @@ -0,0 +1,173 @@ + + + + + + + + a + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DHCP4Config.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DHCP4Config.xml new file mode 100644 index 000000000..7692a8367 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DHCP4Config.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DHCP6Config.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DHCP6Config.xml new file mode 100644 index 000000000..32ae21b40 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DHCP6Config.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Adsl.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Adsl.xml new file mode 100644 index 000000000..839708a34 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Adsl.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml new file mode 100644 index 000000000..1a478c1a8 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bond.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bond.xml new file mode 100644 index 000000000..7ea664972 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bond.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bridge.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bridge.xml new file mode 100644 index 000000000..b52174b19 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Bridge.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Generic.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Generic.xml new file mode 100644 index 000000000..e50efc43d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Generic.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Gre.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Gre.xml new file mode 100644 index 000000000..352644737 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Gre.xml @@ -0,0 +1,82 @@ + + + + + + + + The object path of the parent device. + + + + + + The expected set of GRE flags for incoming packets. (The + values are specified by the GRE specification. On Linux, they + are defined in <linux/if_tunnel.h>. Eg, GRE_KEY for the + 'Key Present' bit.) + + + + + + The set of GRE flags to use for outgoing packets. (The + values are specified by the GRE specification. On Linux, they + are defined in <linux/if_tunnel.h>. Eg, GRE_KEY for the + 'Key Present' bit.) + + + + + + Expected input key (if the "Key Present" bit is set in the input flags). + + + + + + Output key (if the "Key Present" bit is set in the output flags). + + + + + + The local end of the tunnel. + + + + + + The remote end of the tunnel. + + + + + + The value to use in the IP TTL field for tunnel packets. + + + + + + The value to use in the IP ToS field for tunnel packets. + + + + + + Whether path MTU discovery is performed. + + + + + + + + A dictionary mapping property names to variant boxed values + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.IPTunnel.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.IPTunnel.xml new file mode 100644 index 000000000..1e8ec1a26 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.IPTunnel.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml new file mode 100644 index 000000000..a026eee0c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Macsec.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Macsec.xml new file mode 100644 index 000000000..ff94cf52e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Macsec.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Macvlan.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Macvlan.xml new file mode 100644 index 000000000..83f6c42d0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Macvlan.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Modem.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Modem.xml new file mode 100644 index 000000000..c1290f362 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Modem.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.OlpcMesh.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.OlpcMesh.xml new file mode 100644 index 000000000..43f4be04b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.OlpcMesh.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Statistics.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Statistics.xml new file mode 100644 index 000000000..bc4c922e4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Statistics.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Team.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Team.xml new file mode 100644 index 000000000..808df88b5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Team.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Tun.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Tun.xml new file mode 100644 index 000000000..64ed0e84c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Tun.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Veth.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Veth.xml new file mode 100644 index 000000000..91926f725 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Veth.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Vlan.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Vlan.xml new file mode 100644 index 000000000..7a563de94 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Vlan.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Vxlan.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Vxlan.xml new file mode 100644 index 000000000..6f62eb7a8 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Vxlan.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.WiMax.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.WiMax.xml new file mode 100644 index 000000000..f845c1d68 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.WiMax.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Wired.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Wired.xml new file mode 100644 index 000000000..ef21774d5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Wired.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml new file mode 100644 index 000000000..8ff906962 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.xml new file mode 100644 index 000000000..daa5f145c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Device.xml @@ -0,0 +1,325 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DnsManager.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DnsManager.xml new file mode 100644 index 000000000..a3d9782fa --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.DnsManager.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.IP4Config.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.IP4Config.xml new file mode 100644 index 000000000..4819b1863 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.IP4Config.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.IP6Config.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.IP6Config.xml new file mode 100644 index 000000000..c4d44272f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.IP6Config.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.PPP.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.PPP.xml new file mode 100644 index 000000000..3cc559362 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.PPP.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.SecretAgent.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.SecretAgent.xml new file mode 100644 index 000000000..6dc5497d2 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.SecretAgent.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Settings.Connection.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Settings.Connection.xml new file mode 100644 index 000000000..63388f22c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Settings.Connection.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Settings.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Settings.xml new file mode 100644 index 000000000..faea82530 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.Settings.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml new file mode 100644 index 000000000..5350e97dc --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.VPN.Plugin.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.VPN.Plugin.xml new file mode 100644 index 000000000..3f972cfa2 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.VPN.Plugin.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.WiMax.Nsp.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.WiMax.Nsp.xml new file mode 100644 index 000000000..416b8fd9b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.WiMax.Nsp.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.xml new file mode 100644 index 000000000..14e55c113 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/org.freedesktop.NetworkManager.xml @@ -0,0 +1,525 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/introspection/vpn-errors.xml b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/vpn-errors.xml new file mode 100644 index 000000000..7b92d0736 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/introspection/vpn-errors.xml @@ -0,0 +1,60 @@ + + + + General failure without further details. + + + + The plugin is already starting, and another connect request was received. + + + + + The plugin is already connected, and another connect request was received. + + + + + The plugin is already stopping, and another stop request was received. + + + + + The plugin is already stopped, and another disconnect request was received. + + + + + The request could not be processed because the VPN plugin is in the wrong + state for this type of request. + + + + + The request could not be processed because it contained malformed + arguments, or arguments of unexpected type. It usually means that one of + the VPN setting data items or secrets was not of the expected type (i.e. + int, string, bool, etc). + + + + + A binary providing the service failed to launch. + + + + + The request could not be processed because the connection was invalid. It + usually means that the connection's VPN setting was missing some required + data item or secret. + + + + + The request could not be processed because the plugin does not support + interactive operations, such as ConnectInteractive() or NewSecrets(). + + + + diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/ip4configinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/ip4configinterface.cpp new file mode 100644 index 000000000..f8cbe7c0d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/ip4configinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "ip4configinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerIP4ConfigInterface + */ + +OrgFreedesktopNetworkManagerIP4ConfigInterface::OrgFreedesktopNetworkManagerIP4ConfigInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerIP4ConfigInterface::~OrgFreedesktopNetworkManagerIP4ConfigInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/ip4configinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/ip4configinterface.h new file mode 100644 index 000000000..bc39e49e3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/ip4configinterface.h @@ -0,0 +1,116 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef IP4CONFIGINTERFACE_H +#define IP4CONFIGINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.IP4Config + */ +class OrgFreedesktopNetworkManagerIP4ConfigInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.IP4Config"; + } +#else + { + return "org.freedesktop.NetworkManager.IP4Config"; + } +#endif + +public: + OrgFreedesktopNetworkManagerIP4ConfigInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerIP4ConfigInterface() override; + + Q_PROPERTY(NMVariantMapList AddressData READ addressData) + inline NMVariantMapList addressData() const + { + return qvariant_cast(property("AddressData")); + } + + Q_PROPERTY(UIntListList Addresses READ addresses) + inline UIntListList addresses() const + { + return qvariant_cast(property("Addresses")); + } + + Q_PROPERTY(QStringList DnsOptions READ dnsOptions) + inline QStringList dnsOptions() const + { + return qvariant_cast(property("DnsOptions")); + } + + Q_PROPERTY(int DnsPriority READ dnsPriority) + inline int dnsPriority() const + { + return qvariant_cast(property("DnsPriority")); + } + + Q_PROPERTY(QStringList Domains READ domains) + inline QStringList domains() const + { + return qvariant_cast(property("Domains")); + } + + Q_PROPERTY(QString Gateway READ gateway) + inline QString gateway() const + { + return qvariant_cast(property("Gateway")); + } + + Q_PROPERTY(UIntList Nameservers READ nameservers) + inline UIntList nameservers() const + { + return qvariant_cast(property("Nameservers")); + } + + Q_PROPERTY(NMVariantMapList RouteData READ routeData) + inline NMVariantMapList routeData() const + { + return qvariant_cast(property("RouteData")); + } + + Q_PROPERTY(UIntListList Routes READ routes) + inline UIntListList routes() const + { + return qvariant_cast(property("Routes")); + } + + Q_PROPERTY(QStringList Searches READ searches) + inline QStringList searches() const + { + return qvariant_cast(property("Searches")); + } + + Q_PROPERTY(UIntList WinsServers READ winsServers) + inline UIntList winsServers() const + { + return qvariant_cast(property("WinsServers")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/ip6configinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/ip6configinterface.cpp new file mode 100644 index 000000000..45e4d3ddb --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/ip6configinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "ip6configinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerIP6ConfigInterface + */ + +OrgFreedesktopNetworkManagerIP6ConfigInterface::OrgFreedesktopNetworkManagerIP6ConfigInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerIP6ConfigInterface::~OrgFreedesktopNetworkManagerIP6ConfigInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/ip6configinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/ip6configinterface.h new file mode 100644 index 000000000..fecc1fb39 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/ip6configinterface.h @@ -0,0 +1,109 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef IP6CONFIGINTERFACE_H +#define IP6CONFIGINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.IP6Config + */ +class OrgFreedesktopNetworkManagerIP6ConfigInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.IP6Config"; + } +#else + { + return "org.freedesktop.NetworkManager.IP6Config"; + } +#endif +public: + OrgFreedesktopNetworkManagerIP6ConfigInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerIP6ConfigInterface() override; + + Q_PROPERTY(NMVariantMapList AddressData READ addressData) + inline NMVariantMapList addressData() const + { + return qvariant_cast(property("AddressData")); + } + + Q_PROPERTY(IpV6DBusAddressList Addresses READ addresses) + inline IpV6DBusAddressList addresses() const + { + return qvariant_cast(property("Addresses")); + } + + Q_PROPERTY(QStringList DnsOptions READ dnsOptions) + inline QStringList dnsOptions() const + { + return qvariant_cast(property("DnsOptions")); + } + + Q_PROPERTY(int DnsPriority READ dnsPriority) + inline int dnsPriority() const + { + return qvariant_cast(property("DnsPriority")); + } + + Q_PROPERTY(QStringList Domains READ domains) + inline QStringList domains() const + { + return qvariant_cast(property("Domains")); + } + + Q_PROPERTY(QString Gateway READ gateway) + inline QString gateway() const + { + return qvariant_cast(property("Gateway")); + } + + Q_PROPERTY(IpV6DBusNameservers Nameservers READ nameservers) + inline IpV6DBusNameservers nameservers() const + { + return qvariant_cast(property("Nameservers")); + } + + Q_PROPERTY(NMVariantMapList RouteData READ routeData) + inline NMVariantMapList routeData() const + { + return qvariant_cast(property("RouteData")); + } + + Q_PROPERTY(IpV6DBusRouteList Routes READ routes) + inline IpV6DBusRouteList routes() const + { + return qvariant_cast(property("Routes")); + } + + Q_PROPERTY(QStringList Searches READ searches) + inline QStringList searches() const + { + return qvariant_cast(property("Searches")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/iptunneldeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/iptunneldeviceinterface.cpp new file mode 100644 index 000000000..715860e21 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/iptunneldeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "iptunneldeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceIPTunnelInterface + */ + +OrgFreedesktopNetworkManagerDeviceIPTunnelInterface::OrgFreedesktopNetworkManagerDeviceIPTunnelInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceIPTunnelInterface::~OrgFreedesktopNetworkManagerDeviceIPTunnelInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/iptunneldeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/iptunneldeviceinterface.h new file mode 100644 index 000000000..f88074c9f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/iptunneldeviceinterface.h @@ -0,0 +1,117 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef IPTUNNELDEVICEINTERFACE_H +#define IPTUNNELDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.IPTunnel + */ +class OrgFreedesktopNetworkManagerDeviceIPTunnelInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.IPTunnel"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.IPTunnel"; + } +#endif +public: + OrgFreedesktopNetworkManagerDeviceIPTunnelInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceIPTunnelInterface() override; + + Q_PROPERTY(uchar EncapsulationLimit READ encapsulationLimit) + inline uchar encapsulationLimit() const + { + return qvariant_cast(property("EncapsulationLimit")); + } + + Q_PROPERTY(uint FlowLabel READ flowLabel) + inline uint flowLabel() const + { + return qvariant_cast(property("FlowLabel")); + } + + Q_PROPERTY(QString InputKey READ inputKey) + inline QString inputKey() const + { + return qvariant_cast(property("InputKey")); + } + + Q_PROPERTY(QString Local READ local) + inline QString local() const + { + return qvariant_cast(property("Local")); + } + + Q_PROPERTY(uint Mode READ mode) + inline uint mode() const + { + return qvariant_cast(property("Mode")); + } + + Q_PROPERTY(QString OutputKey READ outputKey) + inline QString outputKey() const + { + return qvariant_cast(property("OutputKey")); + } + + Q_PROPERTY(QDBusObjectPath Parent READ parent) + inline QDBusObjectPath parent() const + { + return qvariant_cast(property("Parent")); + } + + Q_PROPERTY(bool PathMtuDiscovery READ pathMtuDiscovery) + inline bool pathMtuDiscovery() const + { + return qvariant_cast(property("PathMtuDiscovery")); + } + + Q_PROPERTY(QString Remote READ remote) + inline QString remote() const + { + return qvariant_cast(property("Remote")); + } + + Q_PROPERTY(uchar Tos READ tos) + inline uchar tos() const + { + return qvariant_cast(property("Tos")); + } + + Q_PROPERTY(uchar Ttl READ ttl) + inline uchar ttl() const + { + return qvariant_cast(property("Ttl")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/macsecdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/macsecdeviceinterface.cpp new file mode 100644 index 000000000..b70a2a675 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/macsecdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "macsecdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceMacsecInterface + */ + +OrgFreedesktopNetworkManagerDeviceMacsecInterface::OrgFreedesktopNetworkManagerDeviceMacsecInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceMacsecInterface::~OrgFreedesktopNetworkManagerDeviceMacsecInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/macsecdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/macsecdeviceinterface.h new file mode 100644 index 000000000..840355aab --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/macsecdeviceinterface.h @@ -0,0 +1,130 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef MACSECDEVICEINTERFACE_H +#define MACSECDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Macsec + */ +class OrgFreedesktopNetworkManagerDeviceMacsecInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Macsec"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Macsec"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceMacsecInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceMacsecInterface() override; + + Q_PROPERTY(qulonglong CipherSuite READ cipherSuite) + inline qulonglong cipherSuite() const + { + return qvariant_cast(property("CipherSuite")); + } + + Q_PROPERTY(uchar EncodingSa READ encodingSa) + inline uchar encodingSa() const + { + return qvariant_cast(property("EncodingSa")); + } + + Q_PROPERTY(bool Encrypt READ encrypt) + inline bool encrypt() const + { + return qvariant_cast(property("Encrypt")); + } + + Q_PROPERTY(bool Es READ es) + inline bool es() const + { + return qvariant_cast(property("Es")); + } + + Q_PROPERTY(uchar IcvLength READ icvLength) + inline uchar icvLength() const + { + return qvariant_cast(property("IcvLength")); + } + + Q_PROPERTY(bool IncludeSci READ includeSci) + inline bool includeSci() const + { + return qvariant_cast(property("IncludeSci")); + } + + Q_PROPERTY(QDBusObjectPath Parent READ parent) + inline QDBusObjectPath parent() const + { + return qvariant_cast(property("Parent")); + } + + Q_PROPERTY(bool Protect READ protect) + inline bool protect() const + { + return qvariant_cast(property("Protect")); + } + + Q_PROPERTY(bool ReplayProtect READ replayProtect) + inline bool replayProtect() const + { + return qvariant_cast(property("ReplayProtect")); + } + + Q_PROPERTY(bool Scb READ scb) + inline bool scb() const + { + return qvariant_cast(property("Scb")); + } + + Q_PROPERTY(qulonglong Sci READ sci) + inline qulonglong sci() const + { + return qvariant_cast(property("Sci")); + } + + Q_PROPERTY(QString Validation READ validation) + inline QString validation() const + { + return qvariant_cast(property("Validation")); + } + + Q_PROPERTY(uint Window READ window) + inline uint window() const + { + return qvariant_cast(property("Window")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/macvlandeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/macvlandeviceinterface.cpp new file mode 100644 index 000000000..c8831fb97 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/macvlandeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "macvlandeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceMacvlanInterface + */ + +OrgFreedesktopNetworkManagerDeviceMacvlanInterface::OrgFreedesktopNetworkManagerDeviceMacvlanInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceMacvlanInterface::~OrgFreedesktopNetworkManagerDeviceMacvlanInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/macvlandeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/macvlandeviceinterface.h new file mode 100644 index 000000000..575f1c626 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/macvlandeviceinterface.h @@ -0,0 +1,76 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef MACVLANDEVICEINTERFACE_H +#define MACVLANDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Macvlan + */ +class OrgFreedesktopNetworkManagerDeviceMacvlanInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Macvlan"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Macvlan"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceMacvlanInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceMacvlanInterface() override; + + Q_PROPERTY(QString Mode READ mode) + inline QString mode() const + { + return qvariant_cast(property("Mode")); + } + + Q_PROPERTY(bool NoPromisc READ noPromisc) + inline bool noPromisc() const + { + return qvariant_cast(property("NoPromisc")); + } + + Q_PROPERTY(QDBusObjectPath Parent READ parent) + inline QDBusObjectPath parent() const + { + return qvariant_cast(property("Parent")); + } + + Q_PROPERTY(bool Tap READ tap) + inline bool tap() const + { + return qvariant_cast(property("Tap")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/modemdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/modemdeviceinterface.cpp new file mode 100644 index 000000000..7ff82e1ac --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/modemdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "modemdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceModemInterface + */ + +OrgFreedesktopNetworkManagerDeviceModemInterface::OrgFreedesktopNetworkManagerDeviceModemInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceModemInterface::~OrgFreedesktopNetworkManagerDeviceModemInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/modemdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/modemdeviceinterface.h new file mode 100644 index 000000000..29ec38241 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/modemdeviceinterface.h @@ -0,0 +1,61 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef MODEMDEVICEINTERFACE_H +#define MODEMDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Modem + */ +class OrgFreedesktopNetworkManagerDeviceModemInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Modem"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Modem"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceModemInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceModemInterface() override; + + Q_PROPERTY(uint CurrentCapabilities READ currentCapabilities) + inline uint currentCapabilities() const + { + return qvariant_cast(property("CurrentCapabilities")); + } + + Q_PROPERTY(uint ModemCapabilities READ modemCapabilities) + inline uint modemCapabilities() const + { + return qvariant_cast(property("ModemCapabilities")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/networkmanagerinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/networkmanagerinterface.cpp new file mode 100644 index 000000000..141afc8e4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/networkmanagerinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "networkmanagerinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerInterface + */ + +OrgFreedesktopNetworkManagerInterface::OrgFreedesktopNetworkManagerInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerInterface::~OrgFreedesktopNetworkManagerInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/networkmanagerinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/networkmanagerinterface.h new file mode 100644 index 000000000..a49367724 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/networkmanagerinterface.h @@ -0,0 +1,306 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef NETWORKMANAGERINTERFACE_H +#define NETWORKMANAGERINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager + */ +class OrgFreedesktopNetworkManagerInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork"; + } +#else + { + return "org.freedesktop.NetworkManager"; + } +#endif + +public: + OrgFreedesktopNetworkManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerInterface() override; + + Q_PROPERTY(QDBusObjectPath ActivatingConnection READ activatingConnection) + inline QDBusObjectPath activatingConnection() const + { + return qvariant_cast(property("ActivatingConnection")); + } + + Q_PROPERTY(QList ActiveConnections READ activeConnections) + inline QList activeConnections() const + { + return qvariant_cast>(property("ActiveConnections")); + } + + Q_PROPERTY(QList AllDevices READ allDevices) + inline QList allDevices() const + { + return qvariant_cast>(property("AllDevices")); + } + + Q_PROPERTY(UIntList Capabilities READ capabilities) + inline UIntList capabilities() const + { + return qvariant_cast(property("Capabilities")); + } + + Q_PROPERTY(uint Connectivity READ connectivity) + inline uint connectivity() const + { + return qvariant_cast(property("Connectivity")); + } + + Q_PROPERTY(QList Devices READ devices) + inline QList devices() const + { + return qvariant_cast>(property("Devices")); + } + + Q_PROPERTY(QVariantMap GlobalDnsConfiguration READ globalDnsConfiguration WRITE setGlobalDnsConfiguration) + inline QVariantMap globalDnsConfiguration() const + { + return qvariant_cast(property("GlobalDnsConfiguration")); + } + inline void setGlobalDnsConfiguration(QVariantMap value) + { + setProperty("GlobalDnsConfiguration", QVariant::fromValue(value)); + } + + Q_PROPERTY(uint Metered READ metered) + inline uint metered() const + { + return qvariant_cast(property("Metered")); + } + + Q_PROPERTY(bool NetworkingEnabled READ networkingEnabled) + inline bool networkingEnabled() const + { + return qvariant_cast(property("NetworkingEnabled")); + } + + Q_PROPERTY(QDBusObjectPath PrimaryConnection READ primaryConnection) + inline QDBusObjectPath primaryConnection() const + { + return qvariant_cast(property("PrimaryConnection")); + } + + Q_PROPERTY(QString PrimaryConnectionType READ primaryConnectionType) + inline QString primaryConnectionType() const + { + return qvariant_cast(property("PrimaryConnectionType")); + } + + Q_PROPERTY(bool Startup READ startup) + inline bool startup() const + { + return qvariant_cast(property("Startup")); + } + + Q_PROPERTY(uint State READ state) + inline uint state() const + { + return qvariant_cast(property("State")); + } + + Q_PROPERTY(QString Version READ version) + inline QString version() const + { + return qvariant_cast(property("Version")); + } + + Q_PROPERTY(bool WimaxEnabled READ wimaxEnabled WRITE setWimaxEnabled) + inline bool wimaxEnabled() const + { + return qvariant_cast(property("WimaxEnabled")); + } + inline void setWimaxEnabled(bool value) + { + setProperty("WimaxEnabled", QVariant::fromValue(value)); + } + + Q_PROPERTY(bool WimaxHardwareEnabled READ wimaxHardwareEnabled) + inline bool wimaxHardwareEnabled() const + { + return qvariant_cast(property("WimaxHardwareEnabled")); + } + + Q_PROPERTY(bool WirelessEnabled READ wirelessEnabled WRITE setWirelessEnabled) + inline bool wirelessEnabled() const + { + return qvariant_cast(property("WirelessEnabled")); + } + inline void setWirelessEnabled(bool value) + { + setProperty("WirelessEnabled", QVariant::fromValue(value)); + } + + Q_PROPERTY(bool WirelessHardwareEnabled READ wirelessHardwareEnabled) + inline bool wirelessHardwareEnabled() const + { + return qvariant_cast(property("WirelessHardwareEnabled")); + } + + Q_PROPERTY(bool WwanEnabled READ wwanEnabled WRITE setWwanEnabled) + inline bool wwanEnabled() const + { + return qvariant_cast(property("WwanEnabled")); + } + inline void setWwanEnabled(bool value) + { + setProperty("WwanEnabled", QVariant::fromValue(value)); + } + + Q_PROPERTY(bool WwanHardwareEnabled READ wwanHardwareEnabled) + inline bool wwanHardwareEnabled() const + { + return qvariant_cast(property("WwanHardwareEnabled")); + } + +public Q_SLOTS: // METHODS + inline QDBusPendingReply + ActivateConnection(const QDBusObjectPath &connection, const QDBusObjectPath &device, const QDBusObjectPath &specific_object) + { + QList argumentList; + argumentList << QVariant::fromValue(connection) << QVariant::fromValue(device) << QVariant::fromValue(specific_object); + return asyncCallWithArgumentList(QStringLiteral("ActivateConnection"), argumentList); + } + + inline QDBusPendingReply + AddAndActivateConnection(NMVariantMapMap connection, const QDBusObjectPath &device, const QDBusObjectPath &specific_object) + { + QList argumentList; + argumentList << QVariant::fromValue(connection) << QVariant::fromValue(device) << QVariant::fromValue(specific_object); + return asyncCallWithArgumentList(QStringLiteral("AddAndActivateConnection"), argumentList); + } + + inline QDBusPendingReply + AddAndActivateConnection2(NMVariantMapMap connection, const QDBusObjectPath &device, const QDBusObjectPath &specific_object, const QVariantMap &options) + { + QList argumentList; + argumentList << QVariant::fromValue(connection) << QVariant::fromValue(device) << QVariant::fromValue(specific_object) << QVariant::fromValue(options); + return asyncCallWithArgumentList(QStringLiteral("AddAndActivateConnection2"), argumentList); + } + + inline QDBusPendingReply CheckConnectivity() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("CheckConnectivity"), argumentList); + } + + inline QDBusPendingReply CheckpointCreate(const QList &devices, uint rollback_timeout, uint flags) + { + QList argumentList; + argumentList << QVariant::fromValue(devices) << QVariant::fromValue(rollback_timeout) << QVariant::fromValue(flags); + return asyncCallWithArgumentList(QStringLiteral("CheckpointCreate"), argumentList); + } + + inline QDBusPendingReply<> CheckpointDestroy(const QDBusObjectPath &checkpoint) + { + QList argumentList; + argumentList << QVariant::fromValue(checkpoint); + return asyncCallWithArgumentList(QStringLiteral("CheckpointDestroy"), argumentList); + } + + inline QDBusPendingReply<> DeactivateConnection(const QDBusObjectPath &active_connection) + { + QList argumentList; + argumentList << QVariant::fromValue(active_connection); + return asyncCallWithArgumentList(QStringLiteral("DeactivateConnection"), argumentList); + } + + inline QDBusPendingReply<> Enable(bool enable) + { + QList argumentList; + argumentList << QVariant::fromValue(enable); + return asyncCallWithArgumentList(QStringLiteral("Enable"), argumentList); + } + + inline QDBusPendingReply> GetAllDevices() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetAllDevices"), argumentList); + } + + inline QDBusPendingReply GetDeviceByIpIface(const QString &iface) + { + QList argumentList; + argumentList << QVariant::fromValue(iface); + return asyncCallWithArgumentList(QStringLiteral("GetDeviceByIpIface"), argumentList); + } + + inline QDBusPendingReply> GetDevices() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetDevices"), argumentList); + } + + inline QDBusPendingReply GetLogging() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetLogging"), argumentList); + } + + inline QDBusPendingReply GetPermissions() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetPermissions"), argumentList); + } + + inline QDBusPendingReply<> Reload(uint flags) + { + QList argumentList; + argumentList << QVariant::fromValue(flags); + return asyncCallWithArgumentList(QStringLiteral("Reload"), argumentList); + } + + inline QDBusPendingReply<> SetLogging(const QString &level, const QString &domains) + { + QList argumentList; + argumentList << QVariant::fromValue(level) << QVariant::fromValue(domains); + return asyncCallWithArgumentList(QStringLiteral("SetLogging"), argumentList); + } + + inline QDBusPendingReply<> Sleep(bool sleep) + { + QList argumentList; + argumentList << QVariant::fromValue(sleep); + return asyncCallWithArgumentList(QStringLiteral("Sleep"), argumentList); + } + + inline QDBusPendingReply state() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("state"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void CheckPermissions(); + void DeviceAdded(const QDBusObjectPath &device_path); + void DeviceRemoved(const QDBusObjectPath &device_path); + void PropertiesChanged(const QVariantMap &properties); + void StateChanged(uint state); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/olpcmeshdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/olpcmeshdeviceinterface.cpp new file mode 100644 index 000000000..f2e78b5e9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/olpcmeshdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "olpcmeshdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface + */ + +OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface::OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface::~OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/olpcmeshdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/olpcmeshdeviceinterface.h new file mode 100644 index 000000000..a01634974 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/olpcmeshdeviceinterface.h @@ -0,0 +1,70 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef OLPCMESHDEVICEINTERFACE_H +#define OLPCMESHDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.OlpcMesh + */ +class OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.OlpcMesh"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.OlpcMesh"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface() override; + + Q_PROPERTY(uint ActiveChannel READ activeChannel) + inline uint activeChannel() const + { + return qvariant_cast(property("ActiveChannel")); + } + + Q_PROPERTY(QDBusObjectPath Companion READ companion) + inline QDBusObjectPath companion() const + { + return qvariant_cast(property("Companion")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/pppinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/pppinterface.cpp new file mode 100644 index 000000000..fcc33eec3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/pppinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "pppinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerPPPInterface + */ + +OrgFreedesktopNetworkManagerPPPInterface::OrgFreedesktopNetworkManagerPPPInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerPPPInterface::~OrgFreedesktopNetworkManagerPPPInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/pppinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/pppinterface.h new file mode 100644 index 000000000..f5414d7b4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/pppinterface.h @@ -0,0 +1,76 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef PPPINTERFACE_H +#define PPPINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.PPP + */ +class OrgFreedesktopNetworkManagerPPPInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.PPP"; + } +#else + { + return "org.freedesktop.NetworkManager.PPP"; + } +#endif + +public: + OrgFreedesktopNetworkManagerPPPInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerPPPInterface() override; + +public Q_SLOTS: // METHODS + inline QDBusPendingReply NeedSecrets() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("NeedSecrets"), argumentList); + } + + inline QDBusPendingReply<> SetIp4Config(const QVariantMap &config) + { + QList argumentList; + argumentList << QVariant::fromValue(config); + return asyncCallWithArgumentList(QStringLiteral("SetIp4Config"), argumentList); + } + + inline QDBusPendingReply<> SetIp6Config(const QVariantMap &config) + { + QList argumentList; + argumentList << QVariant::fromValue(config); + return asyncCallWithArgumentList(QStringLiteral("SetIp6Config"), argumentList); + } + + inline QDBusPendingReply<> SetState(uint state) + { + QList argumentList; + argumentList << QVariant::fromValue(state); + return asyncCallWithArgumentList(QStringLiteral("SetState"), argumentList); + } + +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/secretagentadaptor.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/secretagentadaptor.cpp new file mode 100644 index 000000000..daa4c3661 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/secretagentadaptor.cpp @@ -0,0 +1,56 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#include "secretagentadaptor.h" +#include + +/* + * Implementation of adaptor class SecretAgentAdaptor + */ + +SecretAgentAdaptor::SecretAgentAdaptor(NetworkManager::SecretAgent *parent) + : QDBusAbstractAdaptor(parent) +{ + // constructor + setAutoRelaySignals(true); +} + +SecretAgentAdaptor::~SecretAgentAdaptor() +{ + // destructor +} + +void SecretAgentAdaptor::CancelGetSecrets(const QDBusObjectPath &connection_path, const QString &setting_name) +{ + // handle method call org.freedesktop.NetworkManager.SecretAgent.CancelGetSecrets + parent()->CancelGetSecrets(connection_path, setting_name); +} + +void SecretAgentAdaptor::DeleteSecrets(NMVariantMapMap connection, const QDBusObjectPath &connection_path) +{ + // handle method call org.freedesktop.NetworkManager.SecretAgent.DeleteSecrets + parent()->DeleteSecrets(connection, connection_path); +} + +NMVariantMapMap SecretAgentAdaptor::GetSecrets(NMVariantMapMap connection, + const QDBusObjectPath &connection_path, + const QString &setting_name, + const QStringList &hints, + uint flags) +{ + // handle method call org.freedesktop.NetworkManager.SecretAgent.GetSecrets + return parent()->GetSecrets(connection, connection_path, setting_name, hints, flags); +} + +void SecretAgentAdaptor::SaveSecrets(NMVariantMapMap connection, const QDBusObjectPath &connection_path) +{ + // handle method call org.freedesktop.NetworkManager.SecretAgent.SaveSecrets + parent()->SaveSecrets(connection, connection_path); +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/secretagentadaptor.h b/panels/dock/tray/networkmanager-qt/src/dbus/secretagentadaptor.h new file mode 100644 index 000000000..4231ba104 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/secretagentadaptor.h @@ -0,0 +1,92 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#ifndef SECRETAGENTADAPTOR_H +#define SECRETAGENTADAPTOR_H + +#include "secretagent.h" +#include +#include +#include +QT_BEGIN_NAMESPACE +class QByteArray; +template +class QList; +template +class QMap; +class QString; +class QVariant; +QT_END_NAMESPACE + +/* + * Adaptor class for interface org.freedesktop.NetworkManager.SecretAgent + */ +class SecretAgentAdaptor : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.freedesktop.NetworkManager.SecretAgent") + Q_CLASSINFO("D-Bus Introspection", + "" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "") +public: + SecretAgentAdaptor(NetworkManager::SecretAgent *parent); + ~SecretAgentAdaptor() override; + + inline NetworkManager::SecretAgent *parent() const + { + return static_cast(QObject::parent()); + } + +public: // PROPERTIES +public Q_SLOTS: // METHODS + void CancelGetSecrets(const QDBusObjectPath &connection_path, const QString &setting_name); + void DeleteSecrets(NMVariantMapMap connection, const QDBusObjectPath &connection_path); + NMVariantMapMap + GetSecrets(NMVariantMapMap connection, const QDBusObjectPath &connection_path, const QString &setting_name, const QStringList &hints, uint flags); + void SaveSecrets(NMVariantMapMap connection, const QDBusObjectPath &connection_path); +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/settingsinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/settingsinterface.cpp new file mode 100644 index 000000000..2f30371e9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/settingsinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "settingsinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerSettingsInterface + */ + +OrgFreedesktopNetworkManagerSettingsInterface::OrgFreedesktopNetworkManagerSettingsInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerSettingsInterface::~OrgFreedesktopNetworkManagerSettingsInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/settingsinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/settingsinterface.h new file mode 100644 index 000000000..44d96b89c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/settingsinterface.h @@ -0,0 +1,118 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef SETTINGSINTERFACE_H +#define SETTINGSINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Settings + */ +class OrgFreedesktopNetworkManagerSettingsInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Settings"; + } +#else + { + return "org.freedesktop.NetworkManager.Settings"; + } +#endif + +public: + OrgFreedesktopNetworkManagerSettingsInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerSettingsInterface() override; + + Q_PROPERTY(bool CanModify READ canModify) + inline bool canModify() const + { + return qvariant_cast(property("CanModify")); + } + + Q_PROPERTY(QList Connections READ connections) + inline QList connections() const + { + return qvariant_cast>(property("Connections")); + } + + Q_PROPERTY(QString Hostname READ hostname) + inline QString hostname() const + { + return qvariant_cast(property("Hostname")); + } + +public Q_SLOTS: // METHODS + inline QDBusPendingReply AddConnection(NMVariantMapMap connection) + { + QList argumentList; + argumentList << QVariant::fromValue(connection); + return asyncCallWithArgumentList(QStringLiteral("AddConnection"), argumentList); + } + + inline QDBusPendingReply AddConnectionUnsaved(NMVariantMapMap connection) + { + QList argumentList; + argumentList << QVariant::fromValue(connection); + return asyncCallWithArgumentList(QStringLiteral("AddConnectionUnsaved"), argumentList); + } + + inline QDBusPendingReply GetConnectionByUuid(const QString &uuid) + { + QList argumentList; + argumentList << QVariant::fromValue(uuid); + return asyncCallWithArgumentList(QStringLiteral("GetConnectionByUuid"), argumentList); + } + + inline QDBusPendingReply> ListConnections() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("ListConnections"), argumentList); + } + + inline QDBusPendingReply LoadConnections(const QStringList &filenames) + { + QList argumentList; + argumentList << QVariant::fromValue(filenames); + return asyncCallWithArgumentList(QStringLiteral("LoadConnections"), argumentList); + } + + inline QDBusPendingReply ReloadConnections() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("ReloadConnections"), argumentList); + } + + inline QDBusPendingReply<> SaveHostname(const QString &hostname) + { + QList argumentList; + argumentList << QVariant::fromValue(hostname); + return asyncCallWithArgumentList(QStringLiteral("SaveHostname"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void ConnectionRemoved(const QDBusObjectPath &connection); + void NewConnection(const QDBusObjectPath &connection); + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/teamdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/teamdeviceinterface.cpp new file mode 100644 index 000000000..853ae8b8f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/teamdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "teamdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceTeamInterface + */ + +OrgFreedesktopNetworkManagerDeviceTeamInterface::OrgFreedesktopNetworkManagerDeviceTeamInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceTeamInterface::~OrgFreedesktopNetworkManagerDeviceTeamInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/teamdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/teamdeviceinterface.h new file mode 100644 index 000000000..a0bbadd71 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/teamdeviceinterface.h @@ -0,0 +1,74 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef TEAMDEVICEINTERFACE_H +#define TEAMDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Team + */ +class OrgFreedesktopNetworkManagerDeviceTeamInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Team"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Team"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceTeamInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceTeamInterface() override; + + Q_PROPERTY(bool Carrier READ carrier) + inline bool carrier() const + { + return qvariant_cast(property("Carrier")); + } + + Q_PROPERTY(QString Config READ config) + inline QString config() const + { + return qvariant_cast(property("Config")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QList Slaves READ slaves) + inline QList slaves() const + { + return qvariant_cast>(property("Slaves")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/tundeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/tundeviceinterface.cpp new file mode 100644 index 000000000..54ddc77ad --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/tundeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "tundeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceTunInterface + */ + +OrgFreedesktopNetworkManagerDeviceTunInterface::OrgFreedesktopNetworkManagerDeviceTunInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceTunInterface::~OrgFreedesktopNetworkManagerDeviceTunInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/tundeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/tundeviceinterface.h new file mode 100644 index 000000000..ae38a6c63 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/tundeviceinterface.h @@ -0,0 +1,91 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef TUNDEVICEINTERFACE_H +#define TUNDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Tun + */ +class OrgFreedesktopNetworkManagerDeviceTunInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Tun"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Tun"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceTunInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceTunInterface() override; + + Q_PROPERTY(qlonglong Group READ group) + inline qlonglong group() const + { + return qvariant_cast(property("Group")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QString Mode READ mode) + inline QString mode() const + { + return qvariant_cast(property("Mode")); + } + + Q_PROPERTY(bool MultiQueue READ multiQueue) + inline bool multiQueue() const + { + return qvariant_cast(property("MultiQueue")); + } + + Q_PROPERTY(bool NoPi READ noPi) + inline bool noPi() const + { + return qvariant_cast(property("NoPi")); + } + + Q_PROPERTY(qlonglong Owner READ owner) + inline qlonglong owner() const + { + return qvariant_cast(property("Owner")); + } + + Q_PROPERTY(bool VnetHdr READ vnetHdr) + inline bool vnetHdr() const + { + return qvariant_cast(property("VnetHdr")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vethdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/vethdeviceinterface.cpp new file mode 100644 index 000000000..a0ec952fb --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vethdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "vethdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceVethInterface + */ + +OrgFreedesktopNetworkManagerDeviceVethInterface::OrgFreedesktopNetworkManagerDeviceVethInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceVethInterface::~OrgFreedesktopNetworkManagerDeviceVethInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vethdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/vethdeviceinterface.h new file mode 100644 index 000000000..fdf3f96f0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vethdeviceinterface.h @@ -0,0 +1,55 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef VETHINTERFACE_H +#define VETHINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Veth + */ +class OrgFreedesktopNetworkManagerDeviceVethInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Veth"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Veth"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceVethInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceVethInterface() override; + + Q_PROPERTY(QDBusObjectPath Peer READ peer) + inline QDBusObjectPath peer() const + { + return qvariant_cast(property("Peer")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vlandeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/vlandeviceinterface.cpp new file mode 100644 index 000000000..7cfebc118 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vlandeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "vlandeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceVlanInterface + */ + +OrgFreedesktopNetworkManagerDeviceVlanInterface::OrgFreedesktopNetworkManagerDeviceVlanInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceVlanInterface::~OrgFreedesktopNetworkManagerDeviceVlanInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vlandeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/vlandeviceinterface.h new file mode 100644 index 000000000..1a947ac8f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vlandeviceinterface.h @@ -0,0 +1,73 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef VLANDEVICEINTERFACE_H +#define VLANDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Vlan + */ +class OrgFreedesktopNetworkManagerDeviceVlanInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Vlan"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Vlan"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceVlanInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceVlanInterface() override; + + Q_PROPERTY(bool Carrier READ carrier) + inline bool carrier() const + { + return qvariant_cast(property("Carrier")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QDBusObjectPath Parent READ parent) + inline QDBusObjectPath parent() const + { + return qvariant_cast(property("Parent")); + } + + Q_PROPERTY(uint VlanId READ vlanId) + inline uint vlanId() const + { + return qvariant_cast(property("VlanId")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vpnconnectioninterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/vpnconnectioninterface.cpp new file mode 100644 index 000000000..8884472c4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vpnconnectioninterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "vpnconnectioninterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerVPNConnectionInterface + */ + +OrgFreedesktopNetworkManagerVPNConnectionInterface::OrgFreedesktopNetworkManagerVPNConnectionInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerVPNConnectionInterface::~OrgFreedesktopNetworkManagerVPNConnectionInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vpnconnectioninterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/vpnconnectioninterface.h new file mode 100644 index 000000000..07eb32fad --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vpnconnectioninterface.h @@ -0,0 +1,65 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef VPNCONNECTIONINTERFACE_H +#define VPNCONNECTIONINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.VPN.Connection + */ +class OrgFreedesktopNetworkManagerVPNConnectionInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Settings.VPN.Connection"; + } +#else + { + return "org.freedesktop.NetworkManager.VPN.Connection"; + } +#endif + +public: + OrgFreedesktopNetworkManagerVPNConnectionInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerVPNConnectionInterface() override; + + Q_PROPERTY(QString Banner READ banner) + inline QString banner() const + { + return qvariant_cast(property("Banner")); + } + + Q_PROPERTY(uint VpnState READ vpnState) + inline uint vpnState() const + { + return qvariant_cast(property("VpnState")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); + void VpnStateChanged(uint state, uint reason); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vpnplugininterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/vpnplugininterface.cpp new file mode 100644 index 000000000..adac5813d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vpnplugininterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "vpnplugininterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerVPNPluginInterface + */ + +OrgFreedesktopNetworkManagerVPNPluginInterface::OrgFreedesktopNetworkManagerVPNPluginInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerVPNPluginInterface::~OrgFreedesktopNetworkManagerVPNPluginInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vpnplugininterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/vpnplugininterface.h new file mode 100644 index 000000000..d8b0aed14 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vpnplugininterface.h @@ -0,0 +1,125 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef VPNPLUGININTERFACE_H +#define VPNPLUGININTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.VPN.Plugin + */ +class OrgFreedesktopNetworkManagerVPNPluginInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Settings.VPN.Plugin"; + } +#else + { + return "org.freedesktop.NetworkManager.VPN.Plugin"; + } +#endif + +public: + OrgFreedesktopNetworkManagerVPNPluginInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerVPNPluginInterface() override; + + Q_PROPERTY(uint State READ state) + inline uint state() const + { + return qvariant_cast(property("State")); + } + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> Connect(NMVariantMapMap connection) + { + QList argumentList; + argumentList << QVariant::fromValue(connection); + return asyncCallWithArgumentList(QStringLiteral("Connect"), argumentList); + } + + inline QDBusPendingReply<> ConnectInteractive(NMVariantMapMap connection, QVariant details) + { + QList argumentList; + argumentList << QVariant::fromValue(connection) << QVariant::fromValue(details); + return asyncCallWithArgumentList(QStringLiteral("ConnectInteractive"), argumentList); + } + + inline QDBusPendingReply<> Disconnect() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Disconnect"), argumentList); + } + + inline QDBusPendingReply NeedSecrets(NMVariantMapMap settings) + { + QList argumentList; + argumentList << QVariant::fromValue(settings); + return asyncCallWithArgumentList(QStringLiteral("NeedSecrets"), argumentList); + } + + inline QDBusPendingReply<> NewSecrets(NMVariantMapMap connection) + { + QList argumentList; + argumentList << QVariant::fromValue(connection); + return asyncCallWithArgumentList(QStringLiteral("NewSecrets"), argumentList); + } + + inline QDBusPendingReply<> SetConfig(QVariant config) + { + QList argumentList; + argumentList << QVariant::fromValue(config); + return asyncCallWithArgumentList(QStringLiteral("SetConfig"), argumentList); + } + + inline QDBusPendingReply<> SetFailure(const QString &reason) + { + QList argumentList; + argumentList << QVariant::fromValue(reason); + return asyncCallWithArgumentList(QStringLiteral("SetFailure"), argumentList); + } + + inline QDBusPendingReply<> SetIp4Config(QVariant config) + { + QList argumentList; + argumentList << QVariant::fromValue(config); + return asyncCallWithArgumentList(QStringLiteral("SetIp4Config"), argumentList); + } + + inline QDBusPendingReply<> SetIp6Config(QVariant config) + { + QList argumentList; + argumentList << QVariant::fromValue(config); + return asyncCallWithArgumentList(QStringLiteral("SetIp6Config"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void Config(QVariant config); + void Failure(uint reason); + void Ip4Config(QVariant ip4config); + void Ip6Config(QVariant ip6config); + void LoginBanner(const QString &banner); + void SecretsRequired(const QString &message, const QStringList &secrets); + void StateChanged(uint state); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vxlandeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/vxlandeviceinterface.cpp new file mode 100644 index 000000000..2ba1fca17 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vxlandeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "vxlandeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceVxlanInterface + */ + +OrgFreedesktopNetworkManagerDeviceVxlanInterface::OrgFreedesktopNetworkManagerDeviceVxlanInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceVxlanInterface::~OrgFreedesktopNetworkManagerDeviceVxlanInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/vxlandeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/vxlandeviceinterface.h new file mode 100644 index 000000000..1c7d56c59 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/vxlandeviceinterface.h @@ -0,0 +1,151 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef VXLANDEVICEINTERFACE_H +#define VXLANDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Vxlan + */ +class OrgFreedesktopNetworkManagerDeviceVxlanInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Vxlan"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Vxlan"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceVxlanInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceVxlanInterface() override; + + Q_PROPERTY(uint Ageing READ ageing) + inline uint ageing() const + { + return qvariant_cast(property("Ageing")); + } + + Q_PROPERTY(ushort DstPort READ dstPort) + inline ushort dstPort() const + { + return qvariant_cast(property("DstPort")); + } + + Q_PROPERTY(QString Group READ group) + inline QString group() const + { + return qvariant_cast(property("Group")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(uint Id READ id) + inline uint id() const + { + return qvariant_cast(property("Id")); + } + + Q_PROPERTY(bool L2miss READ l2miss) + inline bool l2miss() const + { + return qvariant_cast(property("L2miss")); + } + + Q_PROPERTY(bool L3miss READ l3miss) + inline bool l3miss() const + { + return qvariant_cast(property("L3miss")); + } + + Q_PROPERTY(bool Learning READ learning) + inline bool learning() const + { + return qvariant_cast(property("Learning")); + } + + Q_PROPERTY(uint Limit READ limit) + inline uint limit() const + { + return qvariant_cast(property("Limit")); + } + + Q_PROPERTY(QString Local READ local) + inline QString local() const + { + return qvariant_cast(property("Local")); + } + + Q_PROPERTY(QDBusObjectPath Parent READ parent) + inline QDBusObjectPath parent() const + { + return qvariant_cast(property("Parent")); + } + + Q_PROPERTY(bool Proxy READ proxy) + inline bool proxy() const + { + return qvariant_cast(property("Proxy")); + } + + Q_PROPERTY(bool Rsc READ rsc) + inline bool rsc() const + { + return qvariant_cast(property("Rsc")); + } + + Q_PROPERTY(ushort SrcPortMax READ srcPortMax) + inline ushort srcPortMax() const + { + return qvariant_cast(property("SrcPortMax")); + } + + Q_PROPERTY(ushort SrcPortMin READ srcPortMin) + inline ushort srcPortMin() const + { + return qvariant_cast(property("SrcPortMin")); + } + + Q_PROPERTY(uchar Tos READ tos) + inline uchar tos() const + { + return qvariant_cast(property("Tos")); + } + + Q_PROPERTY(uchar Ttl READ ttl) + inline uchar ttl() const + { + return qvariant_cast(property("Ttl")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wimaxdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/wimaxdeviceinterface.cpp new file mode 100644 index 000000000..fe710de7e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wimaxdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "wimaxdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceWiMaxInterface + */ + +OrgFreedesktopNetworkManagerDeviceWiMaxInterface::OrgFreedesktopNetworkManagerDeviceWiMaxInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceWiMaxInterface::~OrgFreedesktopNetworkManagerDeviceWiMaxInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wimaxdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/wimaxdeviceinterface.h new file mode 100644 index 000000000..d017b01c3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wimaxdeviceinterface.h @@ -0,0 +1,106 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef WIMAXDEVICEINTERFACE_H +#define WIMAXDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.WiMax + */ +class OrgFreedesktopNetworkManagerDeviceWiMaxInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.WiMax"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.WiMax"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceWiMaxInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceWiMaxInterface() override; + + Q_PROPERTY(QDBusObjectPath ActiveNsp READ activeNsp) + inline QDBusObjectPath activeNsp() const + { + return qvariant_cast(property("ActiveNsp")); + } + + Q_PROPERTY(QString Bsid READ bsid) + inline QString bsid() const + { + return qvariant_cast(property("Bsid")); + } + + Q_PROPERTY(uint CenterFrequency READ centerFrequency) + inline uint centerFrequency() const + { + return qvariant_cast(property("CenterFrequency")); + } + + Q_PROPERTY(int Cinr READ cinr) + inline int cinr() const + { + return qvariant_cast(property("Cinr")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QList Nsps READ nsps) + inline QList nsps() const + { + return qvariant_cast>(property("Nsps")); + } + + Q_PROPERTY(int Rssi READ rssi) + inline int rssi() const + { + return qvariant_cast(property("Rssi")); + } + + Q_PROPERTY(int TxPower READ txPower) + inline int txPower() const + { + return qvariant_cast(property("TxPower")); + } + +public Q_SLOTS: // METHODS + inline QDBusPendingReply> GetNspList() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetNspList"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void NspAdded(const QDBusObjectPath &nsp); + void NspRemoved(const QDBusObjectPath &nsp); + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wimaxnspinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/wimaxnspinterface.cpp new file mode 100644 index 000000000..278447cc9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wimaxnspinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "wimaxnspinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerWiMaxNspInterface + */ + +OrgFreedesktopNetworkManagerWiMaxNspInterface::OrgFreedesktopNetworkManagerWiMaxNspInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerWiMaxNspInterface::~OrgFreedesktopNetworkManagerWiMaxNspInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wimaxnspinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/wimaxnspinterface.h new file mode 100644 index 000000000..055415bca --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wimaxnspinterface.h @@ -0,0 +1,67 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef WIMAXNSPINTERFACE_H +#define WIMAXNSPINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.WiMax.Nsp + */ +class OrgFreedesktopNetworkManagerWiMaxNspInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Settings.WiMax.Nsp"; + } +#else + { + return "org.freedesktop.NetworkManager.WiMax.Nsp"; + } +#endif + +public: + OrgFreedesktopNetworkManagerWiMaxNspInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerWiMaxNspInterface() override; + + Q_PROPERTY(QString Name READ name) + inline QString name() const + { + return qvariant_cast(property("Name")); + } + + Q_PROPERTY(uint NetworkType READ networkType) + inline uint networkType() const + { + return qvariant_cast(property("NetworkType")); + } + + Q_PROPERTY(uint SignalQuality READ signalQuality) + inline uint signalQuality() const + { + return qvariant_cast(property("SignalQuality")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wireddeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/wireddeviceinterface.cpp new file mode 100644 index 000000000..4f714ca4a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wireddeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "wireddeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceWiredInterface + */ + +OrgFreedesktopNetworkManagerDeviceWiredInterface::OrgFreedesktopNetworkManagerDeviceWiredInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceWiredInterface::~OrgFreedesktopNetworkManagerDeviceWiredInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wireddeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/wireddeviceinterface.h new file mode 100644 index 000000000..eaa72d16b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wireddeviceinterface.h @@ -0,0 +1,80 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef WIREDDEVICEINTERFACE_H +#define WIREDDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Wired + */ +class OrgFreedesktopNetworkManagerDeviceWiredInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Wired"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Wired"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceWiredInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceWiredInterface() override; + + Q_PROPERTY(bool Carrier READ carrier) + inline bool carrier() const + { + return qvariant_cast(property("Carrier")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(QString PermHwAddress READ permHwAddress) + inline QString permHwAddress() const + { + return qvariant_cast(property("PermHwAddress")); + } + + Q_PROPERTY(QStringList S390Subchannels READ s390Subchannels) + inline QStringList s390Subchannels() const + { + return qvariant_cast(property("S390Subchannels")); + } + + Q_PROPERTY(uint Speed READ speed) + inline uint speed() const + { + return qvariant_cast(property("Speed")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wireguarddeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/wireguarddeviceinterface.cpp new file mode 100644 index 000000000..b3227a10e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wireguarddeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "wireguarddeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceWireGuardInterface + */ + +OrgFreedesktopNetworkManagerDeviceWireGuardInterface::OrgFreedesktopNetworkManagerDeviceWireGuardInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceWireGuardInterface::~OrgFreedesktopNetworkManagerDeviceWireGuardInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wireguarddeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/wireguarddeviceinterface.h new file mode 100644 index 000000000..5e15aacf5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wireguarddeviceinterface.h @@ -0,0 +1,69 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef WIREGUARDDEVICEINTERFACE_H +#define WIREGUARDDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.WireGuard + */ +class OrgFreedesktopNetworkManagerDeviceWireGuardInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.WireGuard"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.WireGuard"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceWireGuardInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceWireGuardInterface() override; + + Q_PROPERTY(QByteArray PublicKey READ publicKey) + inline QByteArray publicKey() const + { + return qvariant_cast(property("PublicKey")); + } + + Q_PROPERTY(uint ListenPort READ listenPort) + inline uint listenPort() const + { + return qvariant_cast(property("ListenPort")); + } + + Q_PROPERTY(uint FwMark READ fwMark) + inline uint fwMark() const + { + return qvariant_cast(property("FwMark")); + } + +public Q_SLOTS: // METHODS +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wirelessdeviceinterface.cpp b/panels/dock/tray/networkmanager-qt/src/dbus/wirelessdeviceinterface.cpp new file mode 100644 index 000000000..655518fcc --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wirelessdeviceinterface.cpp @@ -0,0 +1,28 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "wirelessdeviceinterface.h" + +/* + * Implementation of interface class OrgFreedesktopNetworkManagerDeviceWirelessInterface + */ + +OrgFreedesktopNetworkManagerDeviceWirelessInterface::OrgFreedesktopNetworkManagerDeviceWirelessInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopNetworkManagerDeviceWirelessInterface::~OrgFreedesktopNetworkManagerDeviceWirelessInterface() +{ +} diff --git a/panels/dock/tray/networkmanager-qt/src/dbus/wirelessdeviceinterface.h b/panels/dock/tray/networkmanager-qt/src/dbus/wirelessdeviceinterface.h new file mode 100644 index 000000000..ca6616ad7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dbus/wirelessdeviceinterface.h @@ -0,0 +1,116 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: + * + * qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef WIRELESSDEVICEINTERFACE_H +#define WIRELESSDEVICEINTERFACE_H + +#include "generictypes.h" + +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.NetworkManager.Device.Wireless + */ +class OrgFreedesktopNetworkManagerDeviceWirelessInterface : public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() +#ifdef NMQT_STATIC + { + return "org.kde.fakenetwork.Device.Wireless"; + } +#else + { + return "org.freedesktop.NetworkManager.Device.Wireless"; + } +#endif + +public: + OrgFreedesktopNetworkManagerDeviceWirelessInterface(const QString &service, + const QString &path, + const QDBusConnection &connection, + QObject *parent = nullptr); + + ~OrgFreedesktopNetworkManagerDeviceWirelessInterface() override; + + Q_PROPERTY(QList AccessPoints READ accessPoints) + inline QList accessPoints() const + { + return qvariant_cast>(property("AccessPoints")); + } + + Q_PROPERTY(QDBusObjectPath ActiveAccessPoint READ activeAccessPoint) + inline QDBusObjectPath activeAccessPoint() const + { + return qvariant_cast(property("ActiveAccessPoint")); + } + + Q_PROPERTY(uint Bitrate READ bitrate) + inline uint bitrate() const + { + return qvariant_cast(property("Bitrate")); + } + + Q_PROPERTY(QString HwAddress READ hwAddress) + inline QString hwAddress() const + { + return qvariant_cast(property("HwAddress")); + } + + Q_PROPERTY(uint Mode READ mode) + inline uint mode() const + { + return qvariant_cast(property("Mode")); + } + + Q_PROPERTY(QString PermHwAddress READ permHwAddress) + inline QString permHwAddress() const + { + return qvariant_cast(property("PermHwAddress")); + } + + Q_PROPERTY(uint WirelessCapabilities READ wirelessCapabilities) + inline uint wirelessCapabilities() const + { + return qvariant_cast(property("WirelessCapabilities")); + } + +public Q_SLOTS: // METHODS + inline QDBusPendingReply> GetAccessPoints() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetAccessPoints"), argumentList); + } + + inline QDBusPendingReply> GetAllAccessPoints() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("GetAllAccessPoints"), argumentList); + } + + inline QDBusPendingReply<> RequestScan(const QVariantMap &options) + { + QList argumentList; + argumentList << QVariant::fromValue(options); + return asyncCallWithArgumentList(QStringLiteral("RequestScan"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void AccessPointAdded(const QDBusObjectPath &access_point); + void AccessPointRemoved(const QDBusObjectPath &access_point); + void PropertiesChanged(const QVariantMap &properties); +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/device.cpp b/panels/dock/tray/networkmanager-qt/src/device.cpp new file mode 100644 index 000000000..be27876af --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/device.cpp @@ -0,0 +1,646 @@ +/* + SPDX-FileCopyrightText: 2008, 2010 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "connection.h" +#include "device_p.h" +#include "manager.h" +#include "manager_p.h" +#include "nmdebug.h" +#include "settings.h" + +#include + +#include + +// logging category for this framework, default: log stuff >= warning +Q_LOGGING_CATEGORY(NMQT, "kf.networkmanagerqt", QtWarningMsg) + +namespace NetworkManager +{ +class DeviceStateReasonPrivate +{ +public: + DeviceStateReasonPrivate(Device::State st, Device::StateChangeReason rsn) + : state(st) + , reason(rsn) + { + } + DeviceStateReasonPrivate() + : state(Device::UnknownState) + , reason(Device::UnknownReason) + { + } + Device::State state; + Device::StateChangeReason reason; +}; +} + +NetworkManager::DeviceStateReason::DeviceStateReason(Device::State state, Device::StateChangeReason reason) + : d_ptr(new DeviceStateReasonPrivate(state, reason)) +{ +} + +NetworkManager::DeviceStateReason::DeviceStateReason(const NetworkManager::DeviceStateReason &other) + : d_ptr(new DeviceStateReasonPrivate(*other.d_ptr)) +{ +} + +NetworkManager::DeviceStateReason::~DeviceStateReason() +{ + delete d_ptr; +} + +NetworkManager::Device::State NetworkManager::DeviceStateReason::state() const +{ + Q_D(const DeviceStateReason); + return d->state; +} + +NetworkManager::Device::StateChangeReason NetworkManager::DeviceStateReason::reason() const +{ + Q_D(const DeviceStateReason); + return d->reason; +} + +NetworkManager::DeviceStateReason &NetworkManager::DeviceStateReason::operator=(const NetworkManager::DeviceStateReason &other) +{ + if (&other != this) { + *d_ptr = *other.d_ptr; + } + return *this; +} + +NetworkManager::DevicePrivate::DevicePrivate(const QString &path, NetworkManager::Device *q) +#ifdef NMQT_STATIC + : deviceIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + : deviceIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , uni(path) + , designSpeed(0) + , deviceType(Device::UnknownType) + , dhcp4Config(nullptr) + , dhcp6Config(nullptr) + , mtu(0) + , q_ptr(q) +{ +} + +NetworkManager::DevicePrivate::~DevicePrivate() +{ +} + +void NetworkManager::DevicePrivate::init() +{ + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + uni, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + this, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + QObject::connect(&deviceIface, &OrgFreedesktopNetworkManagerDeviceInterface::StateChanged, this, &DevicePrivate::deviceStateChanged); + + + deviceStatistics = DeviceStatistics::Ptr(new NetworkManager::DeviceStatistics(uni), &QObject::deleteLater); + + // Get all Device's properties at once + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(deviceIface.staticInterfaceName(), uni); + if (!initialProperties.isEmpty()) { + propertiesChanged(initialProperties); + } + +} + +NetworkManager::Device::MeteredStatus NetworkManager::DevicePrivate::convertMeteredStatus(uint metered) +{ + NetworkManager::Device::MeteredStatus ourMeteredStatus = (NetworkManager::Device::MeteredStatus)metered; + return ourMeteredStatus; +} + +NetworkManager::Device::Capabilities NetworkManager::DevicePrivate::convertCapabilities(uint theirCaps) +{ + NetworkManager::Device::Capabilities ourCaps = (NetworkManager::Device::Capabilities)theirCaps; + return ourCaps; +} + +NetworkManager::Device::State NetworkManager::DevicePrivate::convertState(uint theirState) +{ + NetworkManager::Device::State ourState = static_cast(theirState); + return ourState; +} + +NetworkManager::Device::StateChangeReason NetworkManager::DevicePrivate::convertReason(uint theirReason) +{ + NetworkManager::Device::StateChangeReason ourReason = (NetworkManager::Device::StateChangeReason)theirReason; + return ourReason; +} + +NetworkManager::Device::Type NetworkManager::DevicePrivate::convertType(uint type) +{ + // These are identical to NM enums + if (type <= NM_DEVICE_TYPE_TEAM) { + return (NetworkManager::Device::Type)type; + } + + switch (type) { + case 16: + // NM_DEVICE_TYPE_TUN + return NetworkManager::Device::Tun; + case 17: + // NM_DEVICE_TYPE_IP_TUNNEL + return NetworkManager::Device::IpTunnel; + case 18: + // NM_DEVICE_TYPE_MACVLAN + return NetworkManager::Device::MacVlan; + case 19: + // NM_DEVICE_TYPE_VXLAN + return NetworkManager::Device::VxLan; + case 20: + // NM_DEVICE_TYPE_VETH + return NetworkManager::Device::Veth; + case 21: + // NM_DEVICE_TYPE_MACSEC + return NetworkManager::Device::MacSec; + case 22: + // NM_DEVICE_TYPE_DUMMY + return NetworkManager::Device::Dummy; + case 23: + // NM_DEVICE_TYPE_PPP + return NetworkManager::Device::Ppp; + case 24: + // NM_DEVICE_TYPE_OVS_INTERFACE + return NetworkManager::Device::OvsInterface; + case 25: + // NM_DEVICE_TYPE_OVS_PORT + return NetworkManager::Device::OvsPort; + case 26: + // NM_DEVICE_TYPE_OVS_BRIDGE + return NetworkManager::Device::OvsBridge; + case 27: + // NM_DEVICE_TYPE_WPAN + return NetworkManager::Device::Wpan; + case 28: + // NM_DEVICE_TYPE_6LOWPAN + return NetworkManager::Device::Lowpan; + case 29: + // NM_DEVICE_TYPE_NM_DEVICE_TYPE_WIREGUARD + return NetworkManager::Device::WireGuard; + case 30: + // NM_DEVICE_TYPE_WIFI_P2P + return NetworkManager::Device::WifiP2P; + } + + return NetworkManager::Device::UnknownType; +} + +NetworkManager::Device::Device(const QString &path, QObject *parent) + : QObject(parent) + , d_ptr(new DevicePrivate(path, this)) +{ + Q_D(Device); + + d->init(); +} + +NetworkManager::Device::Device(DevicePrivate &dd, QObject *parent) + : QObject(parent) + , d_ptr(&dd) +{ + Q_D(Device); + + d->init(); +} + +void NetworkManager::DevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(Device); + + // qCDebug(NMQT) << property << " - " << value; + if (property == QLatin1String("ActiveConnection")) { + // FIXME workaround, because NM doesn't Q_EMIT correct value + // d->activeConnection = value.value.path(); + activeConnection = deviceIface.activeConnection().path(); + Q_EMIT q->activeConnectionChanged(); + } else if (property == QLatin1String("Autoconnect")) { + autoconnect = value.toBool(); + Q_EMIT q->autoconnectChanged(); + } else if (property == QLatin1String("AvailableConnections")) { + QStringList newAvailableConnections; + const QList availableConnectionsTmp = qdbus_cast>(value); + for (const QDBusObjectPath &availableConnection : availableConnectionsTmp) { + newAvailableConnections << availableConnection.path(); + if (!availableConnections.contains(availableConnection.path())) { + availableConnections << availableConnection.path(); + Q_EMIT q->availableConnectionAppeared(availableConnection.path()); + } + } + auto it = availableConnections.begin(); + while (it != availableConnections.end()) { + const QString availableConnection = *it; + if (!newAvailableConnections.contains(availableConnection)) { + it = availableConnections.erase(it); + Q_EMIT q->availableConnectionDisappeared(availableConnection); + } else { + ++it; + } + } + Q_EMIT q->availableConnectionChanged(); + } else if (property == QLatin1String("Capabilities")) { + capabilities = NetworkManager::DevicePrivate::convertCapabilities(value.toUInt()); + Q_EMIT q->capabilitiesChanged(); + } else if (property == QLatin1String("DeviceType")) { + deviceType = convertType(value.toUInt()); + } else if (property == QLatin1String("Dhcp4Config")) { + QDBusObjectPath dhcp4ConfigPathTmp = value.value(); + if (dhcp4ConfigPathTmp.path().isNull()) { + dhcp4Config.clear(); + dhcp4ConfigPath.clear(); + } else if (!dhcp4Config || dhcp4Config->path() != dhcp4ConfigPathTmp.path()) { + dhcp4Config.clear(); + dhcp4ConfigPath = dhcp4ConfigPathTmp.path(); + } + Q_EMIT q->dhcp4ConfigChanged(); + } else if (property == QLatin1String("Dhcp6Config")) { + QDBusObjectPath dhcp6ConfigPathTmp = value.value(); + if (dhcp6ConfigPathTmp.path().isNull()) { + dhcp6Config.clear(); + dhcp6ConfigPath.clear(); + } else if (!dhcp6Config || dhcp6Config->path() != dhcp6ConfigPathTmp.path()) { + dhcp6Config.clear(); + dhcp6ConfigPath = dhcp6ConfigPathTmp.path(); + } + Q_EMIT q->dhcp6ConfigChanged(); + } else if (property == QLatin1String("Driver")) { + driver = value.toString(); + Q_EMIT q->driverChanged(); + } else if (property == QLatin1String("DriverVersion")) { + driverVersion = value.toString(); + Q_EMIT q->driverVersionChanged(); + } else if (property == QLatin1String("FirmwareMissing")) { + firmwareMissing = value.toBool(); + Q_EMIT q->firmwareMissingChanged(); + } else if (property == QLatin1String("FirmwareVersion")) { + firmwareVersion = value.toString(); + Q_EMIT q->firmwareVersionChanged(); + } else if (property == QLatin1String("Interface")) { + interfaceName = value.toString(); + Q_EMIT q->interfaceNameChanged(); + } else if (property == QLatin1String("InterfaceFlags")) { + interfaceFlags = value.toUInt(); + Q_EMIT q->interfaceFlagsChanged(); + } else if (property == QLatin1String("Ip4Address")) { + ipV4Address = QHostAddress(ntohl(value.toUInt())); + Q_EMIT q->ipV4AddressChanged(); + } else if (property == QLatin1String("Ip4Config")) { + QDBusObjectPath ip4ConfigObjectPathTmp = value.value(); + if (ip4ConfigObjectPathTmp.path().isNull() || ip4ConfigObjectPathTmp.path() == QLatin1String("/")) { + ipV4ConfigPath.clear(); + } else { + ipV4ConfigPath = ip4ConfigObjectPathTmp.path(); + } + ipV4Config = IpConfig(); + Q_EMIT q->ipV4ConfigChanged(); + } else if (property == QLatin1String("Ip6Config")) { + QDBusObjectPath ip6ConfigObjectPathTmp = value.value(); + if (ip6ConfigObjectPathTmp.path().isNull() || ip6ConfigObjectPathTmp.path() == QLatin1String("/")) { + ipV6ConfigPath.clear(); + } else { + ipV6ConfigPath = ip6ConfigObjectPathTmp.path(); + } + ipV6Config = IpConfig(); + Q_EMIT q->ipV6ConfigChanged(); + } else if (property == QLatin1String("IpInterface")) { + ipInterface = value.toString(); + Q_EMIT q->ipInterfaceChanged(); + } else if (property == QLatin1String("Managed")) { + managed = value.toBool(); + Q_EMIT q->managedChanged(); + } else if (property == QLatin1String("State")) { + connectionState = NetworkManager::DevicePrivate::convertState(value.toUInt()); + // FIXME NetworkManager 0.9.8 (maybe greater) doesn't + // update ActiveConnection when disconnected + // This is fixed in NM 73d128bbd17120225bb4986e3f05566f10fab581 + if (connectionState == NetworkManager::Device::Disconnected && activeConnection != QLatin1String("/")) { + activeConnection = QLatin1Char('/'); + Q_EMIT q->activeConnectionChanged(); + } + Q_EMIT q->connectionStateChanged(); + } else if (property == QLatin1String("StateReason")) { // just extracting the reason + reason = NetworkManager::DevicePrivate::convertReason(qdbus_cast(value).reason); + Q_EMIT q->stateReasonChanged(); + } else if (property == QLatin1String("Udi")) { + udi = value.toString(); + Q_EMIT q->udiChanged(); + } else if (property == QLatin1String("PhysicalPortId")) { + physicalPortId = value.toString(); + Q_EMIT q->physicalPortIdChanged(); + } else if (property == QLatin1String("Mtu")) { + mtu = value.toUInt(); + Q_EMIT q->mtuChanged(); + } else if (property == QLatin1String("NmPluginMissing")) { + nmPluginMissing = value.toBool(); + Q_EMIT q->nmPluginMissingChanged(nmPluginMissing); + } else if (property == QLatin1String("Metered")) { + metered = NetworkManager::DevicePrivate::convertMeteredStatus(value.toUInt()); + Q_EMIT q->meteredChanged(metered); + } else { + qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } +} + +NetworkManager::Device::~Device() +{ + Q_D(Device); + delete d; +} + +QString NetworkManager::Device::uni() const +{ + Q_D(const Device); + return d->uni; +} + +QString NetworkManager::Device::interfaceName() const +{ + Q_D(const Device); + return d->interfaceName; +} + +QString NetworkManager::Device::ipInterfaceName() const +{ + Q_D(const Device); + return d->ipInterface; +} + +QString NetworkManager::Device::driver() const +{ + Q_D(const Device); + return d->driver; +} + +QString NetworkManager::Device::driverVersion() const +{ + Q_D(const Device); + return d->driverVersion; +} + +QString NetworkManager::Device::firmwareVersion() const +{ + Q_D(const Device); + return d->firmwareVersion; +} + +NetworkManager::ActiveConnection::Ptr NetworkManager::Device::activeConnection() const +{ + Q_D(const Device); + return NetworkManager::findActiveConnection(d->activeConnection); +} + +NetworkManager::Connection::List NetworkManager::Device::availableConnections() +{ + Q_D(const Device); + + NetworkManager::Connection::List list; + for (const QString &availableConnection : std::as_const(d->availableConnections)) { + NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(availableConnection); + if (connection) { + list << connection; + } + } + + return list; +} + +bool NetworkManager::Device::firmwareMissing() const +{ + Q_D(const Device); + return d->firmwareMissing; +} + +bool NetworkManager::Device::autoconnect() const +{ + Q_D(const Device); + return d->autoconnect; +} + +void NetworkManager::Device::setAutoconnect(bool autoconnect) +{ + Q_D(Device); + d->deviceIface.setAutoconnect(autoconnect); +} + +QString NetworkManager::Device::udi() const +{ + Q_D(const Device); + return d->udi; +} + +QString NetworkManager::Device::physicalPortId() const +{ + Q_D(const Device); + return d->physicalPortId; +} + +QHostAddress NetworkManager::Device::ipV4Address() const +{ + Q_D(const Device); + return d->ipV4Address; +} + +NetworkManager::DeviceStateReason NetworkManager::Device::stateReason() const +{ + Q_D(const Device); + return DeviceStateReason(d->connectionState, d->reason); +} + +NetworkManager::IpConfig NetworkManager::Device::ipV4Config() const +{ + Q_D(const Device); + if (!d->ipV4Config.isValid() && !d->ipV4ConfigPath.isNull()) { + d->ipV4Config.setIPv4Path(d->ipV4ConfigPath); + } + return d->ipV4Config; +} + +NetworkManager::IpConfig NetworkManager::Device::ipV6Config() const +{ + Q_D(const Device); + if (!d->ipV6Config.isValid() && !d->ipV6ConfigPath.isNull()) { + d->ipV6Config.setIPv6Path(d->ipV6ConfigPath); + } + return d->ipV6Config; +} + +NetworkManager::Dhcp4Config::Ptr NetworkManager::Device::dhcp4Config() const +{ + Q_D(const Device); + if (!d->dhcp4Config && !d->dhcp4ConfigPath.isNull()) { + d->dhcp4Config = NetworkManager::Dhcp4Config::Ptr(new Dhcp4Config(d->dhcp4ConfigPath), &QObject::deleteLater); + } + return d->dhcp4Config; +} + +NetworkManager::Dhcp6Config::Ptr NetworkManager::Device::dhcp6Config() const +{ + Q_D(const Device); + if (!d->dhcp6Config && !d->dhcp6ConfigPath.isNull()) { + d->dhcp6Config = NetworkManager::Dhcp6Config::Ptr(new Dhcp6Config(d->dhcp6ConfigPath), &QObject::deleteLater); + } + return d->dhcp6Config; +} + +bool NetworkManager::Device::isActive() const +{ + Q_D(const Device); + /* clang-format off */ + return !(d->connectionState == NetworkManager::Device::Unavailable + || d->connectionState == NetworkManager::Device::Unmanaged + || d->connectionState == NetworkManager::Device::Disconnected + || d->connectionState == NetworkManager::Device::Failed); + /* clang-format on */ +} + +bool NetworkManager::Device::isValid() const +{ + Q_D(const Device); + return d->deviceIface.isValid(); +} + +bool NetworkManager::Device::managed() const +{ + Q_D(const Device); + return d->managed; +} + +uint NetworkManager::Device::interfaceFlags() const +{ + Q_D(const Device); + return d->interfaceFlags; +} + +uint NetworkManager::Device::mtu() const +{ + Q_D(const Device); + return d->mtu; +} + +bool NetworkManager::Device::nmPluginMissing() const +{ + Q_D(const Device); + return d->nmPluginMissing; +} + +NetworkManager::Device::MeteredStatus NetworkManager::Device::metered() const +{ + Q_D(const Device); + return d->metered; +} + +QDBusPendingReply<> NetworkManager::Device::reapplyConnection(const NMVariantMapMap &connection, qulonglong version_id, uint flags) +{ + Q_D(Device); + return d->deviceIface.Reapply(connection, version_id, flags); +} + +QDBusPendingReply<> NetworkManager::Device::disconnectInterface() +{ + Q_D(Device); + return d->deviceIface.Disconnect(); +} + +QDBusPendingReply<> NetworkManager::Device::deleteInterface() +{ + if (NetworkManager::checkVersion(1, 0, 0)) { + Q_D(Device); + return d->deviceIface.Delete(); + } else { + return QDBusPendingReply<>(); + } +} + +NetworkManager::Device::State NetworkManager::Device::state() const +{ + Q_D(const Device); + return d->connectionState; +} + +int NetworkManager::Device::designSpeed() const +{ + Q_D(const Device); + return d->designSpeed; +} + +NetworkManager::Device::Capabilities NetworkManager::Device::capabilities() const +{ + Q_D(const Device); + return d->capabilities; +} + +QVariant NetworkManager::Device::capabilitiesV() const +{ + Q_D(const Device); + return QVariant(d->capabilities); +} + +NetworkManager::DeviceStatistics::Ptr NetworkManager::Device::deviceStatistics() const +{ + Q_D(const Device); + return d->deviceStatistics; +} + +void NetworkManager::DevicePrivate::deviceStateChanged(uint newState, uint oldState, uint reason) +{ + Q_Q(Device); + connectionState = NetworkManager::DevicePrivate::convertState(newState); + reason = NetworkManager::DevicePrivate::convertReason(reason); + + Q_EMIT q->stateChanged(connectionState, NetworkManager::DevicePrivate::convertState(oldState), NetworkManager::DevicePrivate::convertReason(reason)); +} + +void NetworkManager::DevicePrivate::dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + if (interfaceName.contains(QLatin1String("org.freedesktop.NetworkManager.Device")) + && interfaceName != QLatin1String("org.freedesktop.NetworkManager.Device.Statistics")) { + propertiesChanged(properties); + } +} + +void NetworkManager::DevicePrivate::propertiesChanged(const QVariantMap &properties) +{ + // qCDebug(NMQT) << Q_FUNC_INFO << properties; + + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + propertyChanged(it.key(), it.value()); + ++it; + } + + // FIXME workaround, we need to get a path to updated IPv[46]Config, + // because NM doesn't Q_EMIT the updated value when the device is activated + // BUG: https://bugzilla.gnome.org/show_bug.cgi?id=725657 + if (properties.contains(QLatin1String("State")) && connectionState == NetworkManager::Device::Activated) { + propertyChanged(QLatin1String("Ip4Config"), QVariant::fromValue(deviceIface.ip4Config())); + propertyChanged(QLatin1String("Ip6Config"), QVariant::fromValue(deviceIface.ip6Config())); + } +} + +NetworkManager::Device::Type NetworkManager::Device::type() const +{ + Q_D(const Device); + return d->deviceType; +} diff --git a/panels/dock/tray/networkmanager-qt/src/device.h b/panels/dock/tray/networkmanager-qt/src/device.h new file mode 100644 index 000000000..661402870 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/device.h @@ -0,0 +1,632 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DEVICE_H +#define NETWORKMANAGERQT_DEVICE_H + +#include +#include + +#include "activeconnection.h" +#include "devicestatistics.h" +#include "dhcp4config.h" +#include "dhcp6config.h" +#include "generictypes.h" +#include "ipconfig.h" +#include + +namespace NetworkManager +{ +class DevicePrivate; +class DeviceStateReason; +class DeviceStateReasonPrivate; + +/** + * This class represents a common device interface + */ +class NETWORKMANAGERQT_EXPORT Device : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString uni READ uni) + Q_PROPERTY(QString interfaceName READ interfaceName) + Q_PROPERTY(QString ipInterfaceName READ ipInterfaceName) + Q_PROPERTY(QString driver READ driver) + Q_PROPERTY(QString driverVersion READ driverVersion) + Q_PROPERTY(QString firmwareVersion READ firmwareVersion) + Q_PROPERTY(QVariant genericCapabilities READ capabilitiesV) + Q_PROPERTY(QHostAddress ipV4Address READ ipV4Address) + Q_PROPERTY(uint InterfaceFlags READ interfaceFlags) + Q_PROPERTY(bool managed READ managed) + Q_PROPERTY(uint mtu READ mtu) + Q_PROPERTY(bool nmPluginMissing READ nmPluginMissing) + Q_PROPERTY(MeteredStatus metered READ metered) + Q_PROPERTY(QString udi READ udi) + Q_PROPERTY(bool firmwareMissing READ firmwareMissing) + Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect) + Q_PROPERTY(DeviceStateReason stateReason READ stateReason) + Q_PROPERTY(State state READ state) + Q_PROPERTY(NetworkManager::DeviceStatistics::Ptr deviceStatistics READ deviceStatistics) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + /** + * Device connection states describe the possible states of a + * network connection from the user's point of view. For + * simplicity, states from several different layers are present - + * this is a high level view + */ + enum State { + UnknownState = 0, /**< The device is in an unknown state */ + Unmanaged = 10, /**< The device is recognized but not managed by NetworkManager */ + Unavailable = 20, /**< The device cannot be used (carrier off, rfkill, etc) */ + Disconnected = 30, /**< The device is not connected */ + Preparing = 40, /**< The device is preparing to connect */ + ConfiguringHardware = 50, /**< The device is being configured */ + NeedAuth = 60, /**< The device is awaiting secrets necessary to continue connection */ + ConfiguringIp = 70, /**< The IP settings of the device are being requested and configured */ + CheckingIp = 80, /**< The device's IP connectivity ability is being determined */ + WaitingForSecondaries = 90, /**< The device is waiting for secondary connections to be activated */ + Activated = 100, /**< The device is active */ + Deactivating = 110, /**< The device's network connection is being torn down */ + Failed = 120, /**< The device is in a failure state following an attempt to activate it */ + }; + Q_ENUM(State) + + /** + * Enums describing the reason for a connection state change + * @note StateChangeReasons NewActivation, ParentChanged, ParentManagedChanged are available in runtime NM >= 1.0.4 + */ + enum StateChangeReason { + UnknownReason = 0, + NoReason = 1, + NowManagedReason = 2, + NowUnmanagedReason = 3, + ConfigFailedReason = 4, + ConfigUnavailableReason = 5, + ConfigExpiredReason = 6, + NoSecretsReason = 7, + AuthSupplicantDisconnectReason = 8, + AuthSupplicantConfigFailedReason = 9, + AuthSupplicantFailedReason = 10, + AuthSupplicantTimeoutReason = 11, + PppStartFailedReason = 12, + PppDisconnectReason = 13, + PppFailedReason = 14, + DhcpStartFailedReason = 15, + DhcpErrorReason = 16, + DhcpFailedReason = 17, + SharedStartFailedReason = 18, + SharedFailedReason = 19, + AutoIpStartFailedReason = 20, + AutoIpErrorReason = 21, + AutoIpFailedReason = 22, + ModemBusyReason = 23, + ModemNoDialToneReason = 24, + ModemNoCarrierReason = 25, + ModemDialTimeoutReason = 26, + ModemDialFailedReason = 27, + ModemInitFailedReason = 28, + GsmApnSelectFailedReason = 29, + GsmNotSearchingReason = 30, + GsmRegistrationDeniedReason = 31, + GsmRegistrationTimeoutReason = 32, + GsmRegistrationFailedReason = 33, + GsmPinCheckFailedReason = 34, + FirmwareMissingReason = 35, + DeviceRemovedReason = 36, + SleepingReason = 37, + ConnectionRemovedReason = 38, + UserRequestedReason = 39, + CarrierReason = 40, + ConnectionAssumedReason = 41, + SupplicantAvailableReason = 42, + ModemNotFoundReason = 43, + BluetoothFailedReason = 44, + GsmSimNotInserted = 45, + GsmSimPinRequired = 46, + GsmSimPukRequired = 47, + GsmSimWrong = 48, + InfiniBandMode = 49, + DependencyFailed = 50, + Br2684Failed = 51, + ModemManagerUnavailable = 52, + SsidNotFound = 53, + SecondaryConnectionFailed = 54, + DcbFcoeFailed = 55, + TeamdControlFailed = 56, + ModemFailed = 57, + ModemAvailable = 58, + SimPinIncorrect = 59, + NewActivation = 60, + ParentChanged = 61, + ParentManagedChanged = 62, + Reserved = 65536, + }; + Q_ENUM(StateChangeReason) + + enum MeteredStatus { + UnknownStatus = 0, /**< The device metered status is unknown. */ + Yes = 1, /**< The device is metered and the value was statically set. */ + No = 2, /**< The device is not metered and the value was statically set. */ + GuessYes = 3, /**< The device is metered and the value was guessed. */ + GuessNo = 4, /**< The device is not metered and the value was guessed. */ + }; + Q_ENUM(MeteredStatus) + + /** + * Possible device capabilities + */ + enum Capability { + IsManageable = 0x1, /**< denotes that the device can be controlled by this API */ + SupportsCarrierDetect = 0x2, /**< the device informs us when it is plugged in to the medium */ + }; + Q_ENUM(Capability) + Q_DECLARE_FLAGS(Capabilities, Capability) + Q_FLAG(Capabilities) + + /** + * Device type + */ + enum Type { + UnknownType = NM_DEVICE_TYPE_UNKNOWN, /**< Unknown device type */ + Ethernet = NM_DEVICE_TYPE_ETHERNET, /**< Ieee8023 wired ethernet */ + Wifi = NM_DEVICE_TYPE_WIFI, /**< the Ieee80211 family of wireless networks */ + Unused1 = NM_DEVICE_TYPE_UNUSED1, /**< Currently unused */ + Unused2 = NM_DEVICE_TYPE_UNUSED2, /**< Currently unused */ + Bluetooth = NM_DEVICE_TYPE_BT, /**< network bluetooth device (usually a cell phone) */ + OlpcMesh = NM_DEVICE_TYPE_OLPC_MESH, /**< OLPC Mesh networking device */ + Wimax = NM_DEVICE_TYPE_WIMAX, /**< WiMax WWAN technology */ + Modem = NM_DEVICE_TYPE_MODEM, /**< POTS, GSM, CDMA or LTE modems */ + InfiniBand = NM_DEVICE_TYPE_INFINIBAND, /**< Infiniband network device */ + Bond = NM_DEVICE_TYPE_BOND, /**< Bond virtual device */ + Vlan = NM_DEVICE_TYPE_VLAN, /**< Vlan virtual device */ + Adsl = NM_DEVICE_TYPE_ADSL, /**< ADSL modem device */ + Bridge = NM_DEVICE_TYPE_BRIDGE, /**< Bridge virtual device */ + Generic = NM_DEVICE_TYPE_GENERIC, /**< Generic device @since 1.0.0 */ + Team = NM_DEVICE_TYPE_TEAM, /**< Team master device @since 1.0.0 */ + Gre, /**< Gre virtual device @since 1.2.0, @deprecated use IpTunnel instead*/ + MacVlan, /**< MacVlan virtual device @since 1.2.0 */ + Tun, /**< Tun virtual device @since 1.2.0 */ + Veth, /**< Veth virtual device @since 1.2.0 */ + IpTunnel, /**< IP Tunneling Device @since 1.2.0 */ + VxLan, /**< Vxlan Device @since 1.2.0 */ + MacSec, /**< MacSec Device @since 1.6.0 */ + Dummy, /**< Dummy Device @since 1.8.0 */ + Ppp, /**< Ppp Device @since 1.10 */ + OvsInterface, /**< OvsInterface Device @since 1.10 */ + OvsPort, /**< OvsPort Device @since 1.10 */ + OvsBridge, /**< OvsBridge Device @since 1.10 */ + Wpan, /**< Wpan Device @since 1.14 */ + Lowpan, /**< Lowpan Device @since 1.14 */ + WireGuard, /**< WireGuard Device @since 1.14 */ + WifiP2P, /**< WifiP2P Device @since 1.16 */ + }; + Q_ENUM(Type) + Q_DECLARE_FLAGS(Types, Type) + Q_FLAG(Types) + + /** + * Creates a new device object. + * + * @param path UNI of the device + */ + explicit Device(const QString &path, QObject *parent = nullptr); + Device(DevicePrivate &dd, QObject *parent); + /** + * Destroys a device object. + */ + ~Device() override; + /** + * Retrieves the interface type. This is a virtual function that will return the + * proper type of all sub-classes. + * + * @returns the NetworkManager::Device::Type that corresponds to this device. + */ + virtual Type type() const; + /** + * Retrieves the Unique Network Identifier (UNI) of the device. + * This identifier is unique for each network and network interface in the system. + * + * @returns the Unique Network Identifier of the current device + */ + QString uni() const; + /** + * The current active connection for this device + * + * @returns A valid ActiveConnection object or NULL if no active connection was found + */ + NetworkManager::ActiveConnection::Ptr activeConnection() const; + /** + * Returns available connections for this device + * + * @returns List of availables connection + */ + Connection::List availableConnections(); + /** + * The system name for the network device + */ + QString interfaceName() const; + /** + * The name of the device's data interface when available. This property + * may not refer to the actual data interface until the device has + * successfully established a data connection, indicated by the device's + * state() becoming ACTIVATED. + */ + QString ipInterfaceName() const; + /** + * Handle for the system driver controlling this network interface + */ + QString driver() const; + /** + * The driver version. + */ + QString driverVersion() const; + /** + * The firmware version. + */ + QString firmwareVersion() const; + /** + * Reapplies connection settings on the interface. + */ + QDBusPendingReply<> reapplyConnection(const NMVariantMapMap &connection, qulonglong version_id, uint flags); + /** + * Disconnects a device and prevents the device from automatically + * activating further connections without user intervention. + */ + QDBusPendingReply<> disconnectInterface(); + /** + * Deletes a software device from NetworkManager and removes the interface from the system. + * The method returns an error when called for a hardware device. + * + * @since 5.8.0 + * + */ + QDBusPendingReply<> deleteInterface(); + /** + * returns the current IPv4 address without the prefix + * \sa ipV4Config() + * \sa ipV6Config() + * @deprecated + */ + QHostAddress ipV4Address() const; + /** + * Get the current IPv4 configuration of this device. + * Only valid when device is Activated. + */ + IpConfig ipV4Config() const; + /** + * Get the current IPv6 configuration of this device. + * Only valid when device is Activated. + */ + IpConfig ipV6Config() const; + + /** + * Get the DHCP options returned by the DHCP server + * or a null pointer if the device is not Activated or does not + * use DHCP configuration. + */ + Dhcp4Config::Ptr dhcp4Config() const; + + /** + * Get the DHCP options returned by the DHCP server + * or a null pointer if the device is not Activated or does not + * use DHCP configuration. + */ + Dhcp6Config::Ptr dhcp6Config() const; + + /** + * Retrieves the activation status of this network interface. + * + * @return true if this network interface is active, false otherwise + */ + bool isActive() const; + + /** + * Retrieves the device is valid. + * + * @return true if this device interface is valid, false otherwise + */ + bool isValid() const; + + /** + * Retrieves the current state of the device. + * This is a high level view of the device. It is user oriented, so + * actually it provides state coming from different layers. + * + * @return the current connection state + * @see Device::State + */ + State state() const; + /** + * Retrieves the maximum speed as reported by the device. + * Note that this is only a design related piece of information, and that + * the device might not reach this maximum. + * + * @return the device's maximum speed + */ + int designSpeed() const; + /** + * Retrieves the capabilities supported by this device. + * + * @return the capabilities of the device + */ + Capabilities capabilities() const; + QVariant capabilitiesV() const; + /** + * Is the device currently being managed by NetworkManager? + */ + bool managed() const; + /** + * The up or down flag for the device + */ + uint interfaceFlags() const; + /** + * Is the firmware needed by the device missing? + */ + bool firmwareMissing() const; + /** + * If the device is allowed to autoconnect. + */ + bool autoconnect() const; + /** + * The current state and reason for changing to that state. + */ + DeviceStateReason stateReason() const; + /** + * Retrieves the Unique Device Identifier (UDI) of the device. + * This identifier is unique for each device in the system. + */ + QString udi() const; + + /** + * @return If non-empty, an (opaque) indicator of the physical network + * port associated with the device. This can be used to recognize + * when two seemingly-separate hardware devices are actually just + * different virtual interfaces to the same physical port. + * + * @since 0.9.9.0 + */ + QString physicalPortId() const; + /** + * The device MTU (maximum transmission unit) + * @since 0.9.9.0 + * + */ + uint mtu() const; + + /** + * @return If TRUE, indicates the NetworkManager plugin for the device is likely + * missing or misconfigured. + * @since 5.14.0 + */ + bool nmPluginMissing() const; + + /** + * @return Whether the amount of traffic flowing through the device is + * subject to limitations, for example set by service providers. + * @since 5.14.0 + */ + MeteredStatus metered() const; + + /** + * If true, indicates the device is allowed to autoconnect. + * If false, manual intervention is required before the device + * will automatically connect to a known network, such as activating + * a connection using the device, or setting this property to @p true. + */ + void setAutoconnect(bool autoconnect); + + /** + * Returns Device Statistics interface + */ + DeviceStatistics::Ptr deviceStatistics() const; + + /** + * Retrieves a specialized interface to interact with the device corresponding + * to a given device interface. + * + * @returns a pointer to the device interface if it exists, @p 0 otherwise + */ + template + DevIface *as() + { + return qobject_cast(this); + } + + /** + * Retrieves a specialized interface to interact with the device corresponding + * to a given device interface. + * + * @returns a pointer to the device interface if it exists, 0 otherwise + */ + template + const DevIface *as() const + { + return qobject_cast(this); + } + +Q_SIGNALS: + /** + * This signal is emitted when the device's link status changed. + * + * @param newstate the new state of the connection + * @param oldstate the previous state of the connection + * @param reason the reason for the state change, if any. ReasonNone where the backend + * provides no reason. + * @see Device::State + * @see Device::StateChangeReason + */ + void stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason); + + /** + * Emitted when the autoconnect of this network has changed. + */ + void activeConnectionChanged(); + + /** + * Emitted when the autoconnect of this network has changed. + */ + void autoconnectChanged(); + + /** + * Emitted when the list of avaiable connections of this network has changed. + */ + void availableConnectionChanged(); + + /** + * Emitted when a new connection is available + */ + void availableConnectionAppeared(const QString &connection); + + /** + * Emitted when the connection is no longer available + */ + void availableConnectionDisappeared(const QString &connection); + + /** + * Emitted when the capabilities of this network has changed. + */ + void capabilitiesChanged(); + + /** + * Emitted when the DHCP configuration for IPv4 of this network has changed. + */ + void dhcp4ConfigChanged(); + + /** + * Emitted when the DHCP configuration for IPv6 of this network has changed. + */ + void dhcp6ConfigChanged(); + + /** + * Emitted when the driver of this network has changed. + */ + void driverChanged(); + + /** + * Emitted when the driver version of this network has changed. + */ + void driverVersionChanged(); + + /** + * Emitted when the firmware missing state of this network has changed. + */ + void firmwareMissingChanged(); + + /** + * Emitted when the firmware version of this network has changed. + */ + void firmwareVersionChanged(); + + /** + * Emitted when the interface name of this network has changed. + */ + void interfaceNameChanged(); + + /** + * Emitted when the IPv4 address of this network has changed. + */ + void ipV4AddressChanged(); + + /** + * Emitted when the IPv4 configuration of this network has changed. + */ + void ipV4ConfigChanged(); + + /** + * Emitted when the IPv6 configuration of this network has changed. + */ + void ipV6ConfigChanged(); + + /** + * Emitted when the ip interface name of this network has changed. + */ + void ipInterfaceChanged(); + + /** + * Emitted when the managed state of this network has changed. + */ + void managedChanged(); + /** + * Emitted when the up or down state of the device changed + */ + void interfaceFlagsChanged(); + /** + * Emitted when the physical port ID changes. + * @see physicalPortId() + * @since 0.9.9.0 + */ + void physicalPortIdChanged(); + + /** + * Emitted when the maximum transmission unit has changed + * @since 0.9.9.0 + */ + void mtuChanged(); + + /** + * Emitted when NmPluginMissing property has changed + * @since 5.14.0 + * @see nmPluginMissing + */ + void nmPluginMissingChanged(bool nmPluginMissing); + + /** + * Emitted when metered property has changed + * @since 5.14.0 + * @see metered + */ + void meteredChanged(MeteredStatus metered); + + /** + * Emitted when the connection state of this network has changed. + */ + void connectionStateChanged(); + + /** + * Emitted when the state reason of this network has changed. + */ + void stateReasonChanged(); + + /** + * Emitted when the Unique Device Identifier of this device has changed. + */ + void udiChanged(); + +protected: + DevicePrivate *const d_ptr; + +private: + Q_DECLARE_PRIVATE(Device) +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(Device::Capabilities) +Q_DECLARE_OPERATORS_FOR_FLAGS(Device::Types) + +class NETWORKMANAGERQT_EXPORT DeviceStateReason +{ +public: + DeviceStateReason(Device::State state, Device::StateChangeReason reason); + DeviceStateReason(const DeviceStateReason &); + ~DeviceStateReason(); + Device::State state() const; + Device::StateChangeReason reason() const; + DeviceStateReason &operator=(const DeviceStateReason &); + +private: + Q_DECLARE_PRIVATE(DeviceStateReason) + + DeviceStateReasonPrivate *const d_ptr; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/device_p.h b/panels/dock/tray/networkmanager-qt/src/device_p.h new file mode 100644 index 000000000..a1a0c4e98 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/device_p.h @@ -0,0 +1,83 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DEVICE_P_H +#define NETWORKMANAGERQT_DEVICE_P_H + +#include "dbus/deviceinterface.h" +#include "device.h" + +namespace NetworkManager +{ +class NetworkManagerPrivate; + +class DevicePrivate : public QObject +{ + Q_OBJECT +public: + explicit DevicePrivate(const QString &path, Device *q); + ~DevicePrivate() override; + + void init(); + + OrgFreedesktopNetworkManagerDeviceInterface deviceIface; + Device::Capabilities capabilities; + QString uni; + QString udi; + QString activeConnection; + int designSpeed; + Device::Type deviceType; + Device::State connectionState; + bool managed; + uint interfaceFlags; + mutable IpConfig ipV4Config; + QString ipV4ConfigPath; + mutable IpConfig ipV6Config; + QString ipV6ConfigPath; + QString driver; + QHostAddress ipV4Address; + QString interfaceName; + QString ipInterface; + bool firmwareMissing; + mutable Dhcp4Config::Ptr dhcp4Config; + QString dhcp4ConfigPath; + mutable Dhcp6Config::Ptr dhcp6Config; + QString dhcp6ConfigPath; + QString driverVersion; + QString firmwareVersion; + QStringList availableConnections; + bool autoconnect; + Device::StateChangeReason reason; + QString physicalPortId; + uint mtu; + bool nmPluginMissing; + Device::MeteredStatus metered; + DeviceStatistics::Ptr deviceStatistics; + + static NetworkManager::Device::MeteredStatus convertMeteredStatus(uint); + static NetworkManager::Device::Capabilities convertCapabilities(uint); + static NetworkManager::Device::State convertState(uint); + static NetworkManager::Device::StateChangeReason convertReason(uint); + static NetworkManager::Device::Type convertType(uint); + + Q_DECLARE_PUBLIC(Device) + Device *q_ptr; + +public: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + virtual void propertyChanged(const QString &property, const QVariant &value); + +public Q_SLOTS: + void deviceStateChanged(uint, uint, uint); + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void propertiesChanged(const QVariantMap &properties); +}; + +} // namespace NetworkManager +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/devicestatistics.cpp b/panels/dock/tray/networkmanager-qt/src/devicestatistics.cpp new file mode 100644 index 000000000..85df2055e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/devicestatistics.cpp @@ -0,0 +1,117 @@ +/* + SPDX-FileCopyrightText: 2017 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "devicestatistics_p.h" +#include "manager_p.h" +#include "nmdebug.h" + +NetworkManager::DeviceStatisticsPrivate::DeviceStatisticsPrivate(const QString &path, DeviceStatistics *q) +#ifdef NMQT_STATIC + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , refreshRateMs(0) + , rxBytes(0) + , txBytes(0) + , q_ptr(q) +{ + uni = path; +} + +NetworkManager::DeviceStatistics::DeviceStatistics(const QString &path, QObject *parent) + : QObject(parent) + , d_ptr(new DeviceStatisticsPrivate(path, this)) +{ + Q_D(DeviceStatistics); + + // Refresh rate by default is 0, + // as soon as the refresh rate is changed, we'll get the rest of properties initialised + + // Get all DeviceStatistics's properties at once + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->uni, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); +} + +NetworkManager::DeviceStatistics::~DeviceStatistics() +{ + Q_D(DeviceStatistics); + delete d; +} + +uint NetworkManager::DeviceStatistics::refreshRateMs() const +{ + Q_D(const DeviceStatistics); + return d->refreshRateMs; +} + +void NetworkManager::DeviceStatistics::setRefreshRateMs(uint refreshRate) +{ + Q_D(DeviceStatistics); + + // HACK calling d->iface.setRefreshRateMs does a blocking DBus call as internally it does + // setProperty which returns whether the call succeeded, so Qt waits for it. + // Since this can occasionally take a quite a while, this is replaced with a manual DBus call. + + QDBusMessage message = QDBusMessage::createMethodCall(NetworkManager::NetworkManagerPrivate::DBUS_SERVICE, + d->iface.path(), + NetworkManager::NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("Set")); + message << d->iface.staticInterfaceName() << QLatin1String("RefreshRateMs") << QVariant::fromValue(QDBusVariant(refreshRate)); + + d->iface.connection().call(message, QDBus::NoBlock); +} + +qulonglong NetworkManager::DeviceStatistics::rxBytes() const +{ + Q_D(const DeviceStatistics); + return d->rxBytes; +} + +qulonglong NetworkManager::DeviceStatistics::txBytes() const +{ + Q_D(const DeviceStatistics); + return d->txBytes; +} + +void NetworkManager::DeviceStatisticsPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.Device.Statistics")) { + propertiesChanged(properties); + } +} + +void NetworkManager::DeviceStatisticsPrivate::propertiesChanged(const QVariantMap &properties) +{ + Q_Q(DeviceStatistics); + + // qCDebug(NMQT) << Q_FUNC_INFO << properties; + + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + const QString property = it.key(); + if (property == QLatin1String("RefreshRateMs")) { + refreshRateMs = it->toUInt(); + Q_EMIT q->refreshRateMsChanged(refreshRateMs); + } else if (property == QLatin1String("RxBytes")) { + rxBytes = it->toULongLong(); + Q_EMIT q->rxBytesChanged(rxBytes); + } else if (property == QLatin1String("TxBytes")) { + txBytes = it->toULongLong(); + Q_EMIT q->txBytesChanged(txBytes); + } else { + qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } + ++it; + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/devicestatistics.h b/panels/dock/tray/networkmanager-qt/src/devicestatistics.h new file mode 100644 index 000000000..f55f4804a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/devicestatistics.h @@ -0,0 +1,74 @@ +/* + SPDX-FileCopyrightText: 2017 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DEVICE_STATISTICS_H +#define NETWORKMANAGERQT_DEVICE_STATISTICS_H + +#include + +#include + +#include +#include + +namespace NetworkManager +{ +class DeviceStatisticsPrivate; + +/** + * Represents device statistics interface + */ +class NETWORKMANAGERQT_EXPORT DeviceStatistics : public QObject +{ + Q_OBJECT + Q_PROPERTY(uint refreshRateMs READ refreshRateMs WRITE setRefreshRateMs NOTIFY refreshRateMsChanged) + Q_PROPERTY(qulonglong txBytes READ txBytes NOTIFY txBytesChanged) + Q_PROPERTY(qulonglong rxBytes READ rxBytes NOTIFY rxBytesChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + + explicit DeviceStatistics(const QString &path, QObject *parent = nullptr); + ~DeviceStatistics() override; + + /** + * Refresh rate of the rest of properties of this interface. The properties are guaranteed to be refreshed + * each RefreshRateMs milliseconds in case the underlying counter has changed too. If zero, there is no guaranteed + * refresh rate of the properties. + */ + uint refreshRateMs() const; + void setRefreshRateMs(uint refreshRate); + /** + * Number of received bytes + */ + qulonglong rxBytes() const; + /** + * Number of transmitted bytes + */ + qulonglong txBytes() const; + +Q_SIGNALS: + /** + * Emitted when the refresh rate has changed + */ + void refreshRateMsChanged(uint refreshRate); + /** + * Emitted when the received bytes has changed + */ + void rxBytesChanged(qulonglong rxBytes); + /** + * Emitted when the transmitted bytes has changed + */ + void txBytesChanged(qulonglong txBytes); + +private: + Q_DECLARE_PRIVATE(DeviceStatistics) + DeviceStatisticsPrivate *const d_ptr; +}; + +} +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/devicestatistics_p.h b/panels/dock/tray/networkmanager-qt/src/devicestatistics_p.h new file mode 100644 index 000000000..3ca63866b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/devicestatistics_p.h @@ -0,0 +1,36 @@ +/* + SPDX-FileCopyrightText: 2017 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DEVICE_STATISTICS_P_H +#define NETWORKMANAGERQT_DEVICE_STATISTICS_P_H + +#include "dbus/devicestatisticsinterface.h" +#include "devicestatistics.h" + +namespace NetworkManager +{ +class DeviceStatisticsPrivate : public QObject +{ + Q_OBJECT +public: + DeviceStatisticsPrivate(const QString &path, DeviceStatistics *q); + + OrgFreedesktopNetworkManagerDeviceStatisticsInterface iface; + QString uni; + uint refreshRateMs; + qulonglong rxBytes; + qulonglong txBytes; + + Q_DECLARE_PUBLIC(DeviceStatistics) + DeviceStatistics *q_ptr; +private Q_SLOTS: + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void propertiesChanged(const QVariantMap &properties); +}; + +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_DEVICE_STATISTICS_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/dhcp4config.cpp b/panels/dock/tray/networkmanager-qt/src/dhcp4config.cpp new file mode 100644 index 000000000..889732e69 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dhcp4config.cpp @@ -0,0 +1,95 @@ +/* + SPDX-FileCopyrightText: 2011 Lamarque V. Souza + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "dhcp4config.h" +#include "dhcp4config_p.h" +#include "manager_p.h" +#include "nmdebug.h" + +NetworkManager::Dhcp4ConfigPrivate::Dhcp4ConfigPrivate(const QString &path, Dhcp4Config *q) +#ifdef NMQT_STATIC + : dhcp4Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + : dhcp4Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , myPath(path) + , q_ptr(q) +{ +} + +NetworkManager::Dhcp4ConfigPrivate::~Dhcp4ConfigPrivate() +{ +} + +NetworkManager::Dhcp4Config::Dhcp4Config(const QString &path, QObject *owner) + : d_ptr(new Dhcp4ConfigPrivate(path, this)) +{ + Q_D(Dhcp4Config); + Q_UNUSED(owner); + + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->myPath, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + d->options = d->dhcp4Iface.options(); +} + +NetworkManager::Dhcp4Config::~Dhcp4Config() +{ + delete d_ptr; +} + +QString NetworkManager::Dhcp4Config::path() const +{ + Q_D(const Dhcp4Config); + return d->myPath; +} + +QVariantMap NetworkManager::Dhcp4Config::options() const +{ + Q_D(const Dhcp4Config); + return d->options; +} + +QString NetworkManager::Dhcp4Config::optionValue(const QString &key) const +{ + Q_D(const Dhcp4Config); + QString value; + if (d->options.contains(key)) { + value = d->options.value(key).toString(); + } + return value; +} + +void NetworkManager::Dhcp4ConfigPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.DHCP4Config")) { + dhcp4PropertiesChanged(properties); + } +} + +void NetworkManager::Dhcp4ConfigPrivate::dhcp4PropertiesChanged(const QVariantMap &properties) +{ + Q_Q(Dhcp4Config); + + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + const QString property = it.key(); + if (property == QLatin1String("Options")) { + options = it.value().toMap(); + Q_EMIT q->optionsChanged(options); + } else { + qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } + ++it; + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/dhcp4config.h b/panels/dock/tray/networkmanager-qt/src/dhcp4config.h new file mode 100644 index 000000000..4ed1b7573 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dhcp4config.h @@ -0,0 +1,50 @@ +/* + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DHCP4CONFIG_H +#define NETWORKMANAGERQT_DHCP4CONFIG_H + +#include "generictypes.h" + +#include + +#include + +namespace NetworkManager +{ +class Dhcp4ConfigPrivate; + +/** + * This class represents dhcp4 configuration + */ +class NETWORKMANAGERQT_EXPORT Dhcp4Config : public QObject +{ + Q_OBJECT +public: + typedef QSharedPointer Ptr; + typedef QList List; + + explicit Dhcp4Config(const QString &path, QObject *owner = nullptr); + ~Dhcp4Config() override; + + QString path() const; + + QVariantMap options() const; + + QString optionValue(const QString &key) const; + +Q_SIGNALS: + void optionsChanged(const QVariantMap &); + +private: + Q_DECLARE_PRIVATE(Dhcp4Config) + + Dhcp4ConfigPrivate *const d_ptr; +}; +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_DHCP4CONFIG_H diff --git a/panels/dock/tray/networkmanager-qt/src/dhcp4config_p.h b/panels/dock/tray/networkmanager-qt/src/dhcp4config_p.h new file mode 100644 index 000000000..63ef7c270 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dhcp4config_p.h @@ -0,0 +1,35 @@ +/* + SPDX-FileCopyrightText: 2011 Lamarque V. Souza + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DHCP4CONFIG_P_H +#define NETWORKMANAGERQT_DHCP4CONFIG_P_H + +#include "dbus/dhcp4configinterface.h" +#include "dhcp4config.h" + +namespace NetworkManager +{ +class Dhcp4ConfigPrivate : public QObject +{ + Q_OBJECT +public: + Dhcp4ConfigPrivate(const QString &path, Dhcp4Config *q); + ~Dhcp4ConfigPrivate() override; + OrgFreedesktopNetworkManagerDHCP4ConfigInterface dhcp4Iface; + QString myPath; + QVariantMap options; + + Q_DECLARE_PUBLIC(Dhcp4Config) + Dhcp4Config *q_ptr; +protected Q_SLOTS: + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void dhcp4PropertiesChanged(const QVariantMap &); +}; + +} // namespace NetworkManager + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dhcp6config.cpp b/panels/dock/tray/networkmanager-qt/src/dhcp6config.cpp new file mode 100644 index 000000000..2f3818c4f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dhcp6config.cpp @@ -0,0 +1,95 @@ +/* + SPDX-FileCopyrightText: 2011 Lamarque V. Souza + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "dhcp6config_p.h" +#include "manager_p.h" +#include "nmdebug.h" + +NetworkManager::Dhcp6ConfigPrivate::Dhcp6ConfigPrivate(const QString &path, Dhcp6Config *q) +#ifdef NMQT_STATIC + : dhcp6Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + : dhcp6Iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , path(path) + , q_ptr(q) +{ +} + +NetworkManager::Dhcp6ConfigPrivate::~Dhcp6ConfigPrivate() +{ +} + +NetworkManager::Dhcp6Config::Dhcp6Config(const QString &path, QObject *owner) + : d_ptr(new Dhcp6ConfigPrivate(path, this)) +{ + Q_D(Dhcp6Config); + Q_UNUSED(owner); + + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->path, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + + d->options = d->dhcp6Iface.options(); +} + +NetworkManager::Dhcp6Config::~Dhcp6Config() +{ + delete d_ptr; +} + +QString NetworkManager::Dhcp6Config::path() const +{ + Q_D(const Dhcp6Config); + return d->path; +} + +QVariantMap NetworkManager::Dhcp6Config::options() const +{ + Q_D(const Dhcp6Config); + return d->options; +} + +QString NetworkManager::Dhcp6Config::optionValue(const QString &key) const +{ + Q_D(const Dhcp6Config); + QString value; + if (d->options.contains(key)) { + value = d->options.value(key).toString(); + } + return value; +} + +void NetworkManager::Dhcp6ConfigPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.DHCP6Config")) { + dhcp6PropertiesChanged(properties); + } +} + +void NetworkManager::Dhcp6ConfigPrivate::dhcp6PropertiesChanged(const QVariantMap &properties) +{ + Q_Q(Dhcp6Config); + + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + const QString property = it.key(); + if (property == QLatin1String("Options")) { + options = it.value().toMap(); + Q_EMIT q->optionsChanged(options); + } else { + qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } + ++it; + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/dhcp6config.h b/panels/dock/tray/networkmanager-qt/src/dhcp6config.h new file mode 100644 index 000000000..52d246e8d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dhcp6config.h @@ -0,0 +1,50 @@ +/* + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DHCP6CONFIG_H +#define NETWORKMANAGERQT_DHCP6CONFIG_H + +#include "generictypes.h" + +#include + +#include + +namespace NetworkManager +{ +class Dhcp6ConfigPrivate; + +/** + * This class represents dhcp4 configuration + */ +class NETWORKMANAGERQT_EXPORT Dhcp6Config : public QObject +{ + Q_OBJECT +public: + typedef QSharedPointer Ptr; + typedef QList List; + + explicit Dhcp6Config(const QString &path, QObject *owner = nullptr); + ~Dhcp6Config() override; + + QString path() const; + + QVariantMap options() const; + + QString optionValue(const QString &key) const; + +Q_SIGNALS: + void optionsChanged(const QVariantMap &); + +private: + Q_DECLARE_PRIVATE(Dhcp6Config) + + Dhcp6ConfigPrivate *const d_ptr; +}; +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_DHCP6CONFIG_H diff --git a/panels/dock/tray/networkmanager-qt/src/dhcp6config_p.h b/panels/dock/tray/networkmanager-qt/src/dhcp6config_p.h new file mode 100644 index 000000000..db8bc5e77 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dhcp6config_p.h @@ -0,0 +1,35 @@ +/* + SPDX-FileCopyrightText: 2011 Lamarque V. Souza + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DHCP6CONFIG_P_H +#define NETWORKMANAGERQT_DHCP6CONFIG_P_H + +#include "dbus/dhcp6configinterface.h" +#include "dhcp6config.h" + +namespace NetworkManager +{ +class Dhcp6ConfigPrivate : public QObject +{ + Q_OBJECT +public: + Dhcp6ConfigPrivate(const QString &path, Dhcp6Config *q); + ~Dhcp6ConfigPrivate() override; + OrgFreedesktopNetworkManagerDHCP6ConfigInterface dhcp6Iface; + QString path; + QVariantMap options; + + Q_DECLARE_PUBLIC(Dhcp6Config) + Dhcp6Config *q_ptr; +protected Q_SLOTS: + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void dhcp6PropertiesChanged(const QVariantMap &); +}; + +} // namespace NetworkManager + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/dnsconfiguration.cpp b/panels/dock/tray/networkmanager-qt/src/dnsconfiguration.cpp new file mode 100644 index 000000000..465a7d2b9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dnsconfiguration.cpp @@ -0,0 +1,140 @@ +/* + SPDX-FileCopyrightText: 2018 Aleksander Morgado + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ipconfig.h" + +#include + +#include "dnsconfiguration.h" + +#include + +namespace NetworkManager +{ +class NetworkManager::DnsConfiguration::Private +{ +public: + Private(const QStringList &theSearches, const QStringList &theOptions, const QList theDomains) + : searches(theSearches) + , options(theOptions) + , domains(theDomains) + { + } + Private() + { + } + QStringList searches; + QStringList options; + QList domains; +}; + +} + +NetworkManager::DnsConfiguration::DnsConfiguration(const QStringList &searches, const QStringList &options, const QList domains) + : d(new Private(searches, options, domains)) +{ +} + +NetworkManager::DnsConfiguration::DnsConfiguration() + : d(new Private()) +{ +} + +NetworkManager::DnsConfiguration::DnsConfiguration(const DnsConfiguration &other) + : d(new Private) +{ + *this = other; +} + +NetworkManager::DnsConfiguration::~DnsConfiguration() +{ + delete d; +} + +QStringList NetworkManager::DnsConfiguration::searches() const +{ + return d->searches; +} + +void NetworkManager::DnsConfiguration::setSearches(const QStringList &searches) +{ + d->searches = searches; +} + +QStringList NetworkManager::DnsConfiguration::options() const +{ + return d->options; +} + +void NetworkManager::DnsConfiguration::setOptions(const QStringList &options) +{ + d->options = options; +} + +QList NetworkManager::DnsConfiguration::domains() const +{ + return d->domains; +} + +void NetworkManager::DnsConfiguration::setDomains(const QList &domains) +{ + d->domains = domains; +} + +QVariantMap NetworkManager::DnsConfiguration::toMap() const +{ + QVariantMap map; + + map["searches"] = d->searches; + map["options"] = d->options; + + QVariantMap domains; + for (const NetworkManager::DnsDomain &domain : std::as_const(d->domains)) { + QVariantMap contents; + QStringList serversList; + const QList servers = domain.servers(); + for (const QHostAddress &address : servers) { + serversList.append(address.toString()); + } + contents["servers"] = serversList; + contents["options"] = domain.options(); + domains[domain.name()] = contents; + } + map["domains"] = domains; + + return map; +} + +void NetworkManager::DnsConfiguration::fromMap(const QVariantMap &map) +{ + d->searches = map["searches"].toStringList(); + d->options = map["options"].toStringList(); + d->domains = QList(); + + QVariantMap domains = map["domains"].toMap(); + QVariantMap::const_iterator i = domains.constBegin(); + while (i != domains.constEnd()) { + const QVariantMap contents = i.value().toMap(); + QList addressList; + const QStringList serversList = contents["servers"].toStringList(); + for (const QString &server : serversList) { + addressList.append(QHostAddress(server)); + } + NetworkManager::DnsDomain domain(i.key(), addressList, contents["options"].toStringList()); + d->domains.append(domain); + ++i; + } +} + +NetworkManager::DnsConfiguration &NetworkManager::DnsConfiguration::operator=(const DnsConfiguration &other) +{ + if (this == &other) { + return *this; + } + + *d = *other.d; + return *this; +} diff --git a/panels/dock/tray/networkmanager-qt/src/dnsconfiguration.h b/panels/dock/tray/networkmanager-qt/src/dnsconfiguration.h new file mode 100644 index 000000000..8e9038588 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dnsconfiguration.h @@ -0,0 +1,101 @@ +/* + SPDX-FileCopyrightText: 2018 Aleksander Morgado + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DNSCONFIGURATION_H +#define NETWORKMANAGERQT_DNSCONFIGURATION_H + +#include "dnsdomain.h" +#include + +// To prevent signals in glib2 be defined by QT +#undef signals +#include +#include +#define signals Q_SIGNALS + +#include + +namespace NetworkManager +{ +/** + * This class represents IP configuration + */ +class NETWORKMANAGERQT_EXPORT DnsConfiguration +{ +public: + /** + * Constructs an initialized DnsConfiguration object + */ + DnsConfiguration(const QStringList &searches, const QStringList &options, const QList domains); + + /** + * Constructs an empty DnsConfiguration object + */ + DnsConfiguration(); + + /** + * Destroys this DnsConfiguration object. + */ + ~DnsConfiguration(); + + /** + * Constructs a DnsConfiguration object that is a copy of the object @p other. + */ + DnsConfiguration(const DnsConfiguration &other); + + /** + * Returns the list of search domains + */ + QStringList searches() const; + + /** + * Sets the list of search domains + */ + void setSearches(const QStringList &list); + + /** + * Returns the list of resolver options + */ + QStringList options() const; + + /** + * Sets the list of resolver options + */ + void setOptions(const QStringList &list); + + /** + * Returns the list of domains + */ + QList domains() const; + + /** + * Sets the list of domains + */ + void setDomains(const QList &domains); + + /** + * Marshall into a map + */ + QVariantMap toMap() const; + + /** + * De-marshall from a map + */ + void fromMap(const QVariantMap &map); + + /** + * Makes a copy of the DnsConfiguration object @p other. + */ + DnsConfiguration &operator=(const DnsConfiguration &other); + +private: + class Private; + Private *const d; +}; + +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_DNSCONFIGURATION_H diff --git a/panels/dock/tray/networkmanager-qt/src/dnsdomain.cpp b/panels/dock/tray/networkmanager-qt/src/dnsdomain.cpp new file mode 100644 index 000000000..7bb8ff572 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dnsdomain.cpp @@ -0,0 +1,93 @@ +/* + SPDX-FileCopyrightText: 2018 Aleksander Morgado + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ipconfig.h" + +#include + +#include "dnsdomain.h" + +namespace NetworkManager +{ +class NetworkManager::DnsDomain::Private +{ +public: + Private(const QString &theName, const QList &theServers, const QStringList &theOptions) + : name(theName) + , servers(theServers) + , options(theOptions) + { + } + Private() + { + } + QString name; + QList servers; + QStringList options; +}; + +} + +NetworkManager::DnsDomain::DnsDomain(const QString &name, const QList &servers, const QStringList &options) + : d(new Private(name, servers, options)) +{ +} + +NetworkManager::DnsDomain::DnsDomain() + : d(new Private()) +{ +} + +NetworkManager::DnsDomain::DnsDomain(const DnsDomain &other) + : d(new Private) +{ + *this = other; +} + +NetworkManager::DnsDomain::~DnsDomain() +{ + delete d; +} + +QString NetworkManager::DnsDomain::name() const +{ + return d->name; +} + +void NetworkManager::DnsDomain::setName(const QString &name) +{ + d->name = name; +} + +QList NetworkManager::DnsDomain::servers() const +{ + return d->servers; +} + +void NetworkManager::DnsDomain::setServers(const QList &servers) +{ + d->servers = servers; +} + +QStringList NetworkManager::DnsDomain::options() const +{ + return d->options; +} + +void NetworkManager::DnsDomain::setOptions(const QStringList &options) +{ + d->options = options; +} + +NetworkManager::DnsDomain &NetworkManager::DnsDomain::operator=(const DnsDomain &other) +{ + if (this == &other) { + return *this; + } + + *d = *other.d; + return *this; +} diff --git a/panels/dock/tray/networkmanager-qt/src/dnsdomain.h b/panels/dock/tray/networkmanager-qt/src/dnsdomain.h new file mode 100644 index 000000000..31c0e1717 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/dnsdomain.h @@ -0,0 +1,92 @@ +/* + SPDX-FileCopyrightText: 2018 Aleksander Morgado + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DNSDOMAIN_H +#define NETWORKMANAGERQT_DNSDOMAIN_H + +#include "ipaddress.h" +#include "iproute.h" +#include + +// To prevent signals in glib2 be defined by QT +#undef signals +#include +#include +#define signals Q_SIGNALS + +#include + +namespace NetworkManager +{ +/** + * This class represents the configuration for a DNS domain + */ +class NETWORKMANAGERQT_EXPORT DnsDomain +{ +public: + /** + * Constructs a DnsDomain object with a list of + */ + DnsDomain(const QString &name, const QList &servers, const QStringList &options); + + /** + * Constructs a DnsDomain object + */ + DnsDomain(); + + /** + * Destroys this DnsDomain object. + */ + ~DnsDomain(); + + /** + * Constructs a DnsDomain object that is a copy of the object @p other. + */ + DnsDomain(const DnsDomain &other); + + /** + * Returns the domain name + */ + QString name() const; + + /** + * Sets the domain name + */ + void setName(const QString &name); + + /** + * Returns the list of servers + */ + QList servers() const; + + /** + * Sets the list of servers + */ + void setServers(const QList &list); + + /** + * Returns the list of resolver options + */ + QStringList options() const; + + /** + * Sets the list of resolver options + */ + void setOptions(const QStringList &list); + + /** + * Makes a copy of the DnsDomain object @p other. + */ + DnsDomain &operator=(const DnsDomain &other); + +private: + class Private; + Private *const d; +}; + +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_DNSDOMAIN_H diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/CMakeLists.txt b/panels/dock/tray/networkmanager-qt/src/fakenetwork/CMakeLists.txt new file mode 100644 index 000000000..6a174b99a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/CMakeLists.txt @@ -0,0 +1,23 @@ +include_directories( + ${CMAKE_SOURCE_DIR}/src/settings +) + +set(fakeNetwork_SRCS + accesspoint.cpp + activeconnection.cpp + connection.cpp + device.cpp + fakenetwork.cpp + settings.cpp + wireddevice.cpp + wirelessdevice.cpp +) + +add_library(fakeNetwork STATIC ${fakeNetwork_SRCS}) + +target_link_libraries(fakeNetwork + KF5NetworkManagerQt_static + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Network + Qt${QT_MAJOR_VERSION}::DBus + PkgConfig::NetworkManager) diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/accesspoint.cpp b/panels/dock/tray/networkmanager-qt/src/fakenetwork/accesspoint.cpp new file mode 100644 index 000000000..51988fe25 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/accesspoint.cpp @@ -0,0 +1,123 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "accesspoint.h" + +AccessPoint::AccessPoint(QObject *parent) + : QObject(parent) + , m_flags(0) + , m_frequency(0) + , m_maxBitrate(0) + , m_mode(0) + , m_rsnFlags(0) + , m_strength(0) + , m_wpaFlags(0) +{ +} + +AccessPoint::~AccessPoint() +{ +} + +uint AccessPoint::flags() const +{ + return m_flags; +} + +uint AccessPoint::frequency() const +{ + return m_frequency; +} + +QString AccessPoint::hwAddress() const +{ + return m_hwAddress; +} + +uint AccessPoint::maxBitrate() const +{ + return m_maxBitrate; +} + +uint AccessPoint::mode() const +{ + return m_mode; +} + +uint AccessPoint::rsnFlags() const +{ + return m_rsnFlags; +} + +QByteArray AccessPoint::ssid() const +{ + return m_ssid; +} + +uchar AccessPoint::strength() const +{ + return m_strength; +} + +uint AccessPoint::wpaFlags() const +{ + return m_wpaFlags; +} + +QString AccessPoint::accessPointPath() const +{ + return m_apPath; +} + +void AccessPoint::setAccessPointPath(const QString &path) +{ + m_apPath = path; +} + +void AccessPoint::setFlags(uint flags) +{ + m_flags = flags; +} + +void AccessPoint::setFrequency(uint frequency) +{ + m_frequency = frequency; +} + +void AccessPoint::setHwAddress(const QString &hwAddress) +{ + m_hwAddress = hwAddress; +} + +void AccessPoint::setMaxBitrate(uint bitrate) +{ + m_maxBitrate = bitrate; +} + +void AccessPoint::setMode(uint mode) +{ + m_mode = mode; +} + +void AccessPoint::setRsnFlags(uint flags) +{ + m_rsnFlags = flags; +} + +void AccessPoint::setSsid(const QByteArray &ssid) +{ + m_ssid = ssid; +} + +void AccessPoint::setStrength(uchar strength) +{ + m_strength = strength; +} + +void AccessPoint::setWpaFlags(uint flags) +{ + m_wpaFlags = flags; +} diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/accesspoint.h b/panels/dock/tray/networkmanager-qt/src/fakenetwork/accesspoint.h new file mode 100644 index 000000000..9c76be620 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/accesspoint.h @@ -0,0 +1,73 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_FAKE_NETWORK_ACCESS_POINT_H +#define NETWORKMANAGERQT_FAKE_NETWORK_ACCESS_POINT_H + +#include + +#include + +#include "../generictypes.h" + +class AccessPoint : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.fakenetwork.AccessPoint") +public: + explicit AccessPoint(QObject *parent = nullptr); + ~AccessPoint() override; + + Q_PROPERTY(uint Flags READ flags) + Q_PROPERTY(uint Frequency READ frequency) + Q_PROPERTY(QString HwAddress READ hwAddress) + Q_PROPERTY(uint MaxBitrate READ maxBitrate) + Q_PROPERTY(uint Mode READ mode) + Q_PROPERTY(uint RsnFlags READ rsnFlags) + Q_PROPERTY(QByteArray Ssid READ ssid) + Q_PROPERTY(uchar Strength READ strength) + Q_PROPERTY(uint WpaFlags READ wpaFlags) + + uint flags() const; + uint frequency() const; + QString hwAddress() const; + uint maxBitrate() const; + uint mode() const; + uint rsnFlags() const; + QByteArray ssid() const; + uchar strength() const; + uint wpaFlags() const; + + /* Not part of DBus interface */ + QString accessPointPath() const; + void setAccessPointPath(const QString &path); + void setFlags(uint flags); + void setFrequency(uint frequency); + void setHwAddress(const QString &hwAddress); + void setMaxBitrate(uint bitrate); + void setMode(uint mode); + void setRsnFlags(uint flags); + void setSsid(const QByteArray &ssid); + void setStrength(uchar strength); + void setWpaFlags(uint flags); + +Q_SIGNALS: + Q_SCRIPTABLE void PropertiesChanged(const QVariantMap &properties); + +private: + QString m_apPath; + uint m_flags; + uint m_frequency; + QString m_hwAddress; + uint m_maxBitrate; + uint m_mode; + uint m_rsnFlags; + QByteArray m_ssid; + uchar m_strength; + uint m_wpaFlags; +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/activeconnection.cpp b/panels/dock/tray/networkmanager-qt/src/fakenetwork/activeconnection.cpp new file mode 100644 index 000000000..faa6b22d7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/activeconnection.cpp @@ -0,0 +1,202 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "activeconnection.h" +#include "connection.h" + +#include + +ActiveConnection::ActiveConnection(QObject *parent) + : QObject(parent) + , m_connection(QDBusObjectPath("/")) + , m_default4(false) + , m_default6(false) + , m_dhcp4Config(QDBusObjectPath("/")) + , m_dhcp6Config(QDBusObjectPath("/")) + , m_ip4Config(QDBusObjectPath("/")) + , m_ip6Config(QDBusObjectPath("/")) + , m_master(QDBusObjectPath("/")) + , m_specificObject(QDBusObjectPath("/")) + , m_state(0) + , m_vpn(false) +{ +} + +ActiveConnection::~ActiveConnection() +{ +} + +QDBusObjectPath ActiveConnection::connection() const +{ + return m_connection; +} + +bool ActiveConnection::default4() const +{ + return m_default4; +} + +bool ActiveConnection::default6() const +{ + return m_default6; +} + +QList ActiveConnection::devices() const +{ + return m_devices; +} + +QDBusObjectPath ActiveConnection::dhcp4Config() const +{ + return m_dhcp4Config; +} + +QDBusObjectPath ActiveConnection::dhcp6Config() const +{ + return m_dhcp6Config; +} + +QString ActiveConnection::id() const +{ + return m_id; +} + +QDBusObjectPath ActiveConnection::ip4Config() const +{ + return m_ip4Config; +} + +QDBusObjectPath ActiveConnection::ip6Config() const +{ + return m_ip6Config; +} + +QDBusObjectPath ActiveConnection::master() const +{ + return m_master; +} + +QDBusObjectPath ActiveConnection::specificObject() const +{ + return m_specificObject; +} + +uint ActiveConnection::state() const +{ + return m_state; +} + +QString ActiveConnection::type() const +{ + return m_type; +} + +bool ActiveConnection::vpn() const +{ + return m_vpn; +} + +QString ActiveConnection::uuid() const +{ + return m_uuid; +} + +void ActiveConnection::addDevice(const QDBusObjectPath &device) +{ + m_devices << device; +} + +void ActiveConnection::removeDevice(const QDBusObjectPath &device) +{ + m_devices.removeAll(device); +} + +QString ActiveConnection::activeConnectionPath() const +{ + return m_activeConnectionPath; +} + +void ActiveConnection::setActiveConnectionPath(const QString &path) +{ + m_activeConnectionPath = path; +} + +void ActiveConnection::setConnection(const QDBusObjectPath &connection) +{ + m_connection = connection; + + Connection *usedConnection = static_cast(QDBusConnection::sessionBus().objectRegisteredAt(connection.path())); + if (usedConnection) { + NMVariantMapMap settings = usedConnection->GetSettings(); + setId(settings.value(QLatin1String("connection")).value(QLatin1String("id")).toString()); + setUuid(settings.value(QLatin1String("connection")).value(QLatin1String("uuid")).toString()); + setType(settings.value(QLatin1String("connection")).value(QLatin1String("type")).toString()); + } +} + +void ActiveConnection::setDefault4(bool default4) +{ + m_default4 = default4; +} + +void ActiveConnection::setDefault6(bool default6) +{ + m_default6 = default6; +} + +void ActiveConnection::setDhcp4Config(const QDBusObjectPath &dhcp4Config) +{ + m_dhcp4Config = dhcp4Config; +} + +void ActiveConnection::setDhcp6Config(const QDBusObjectPath &dhcp6Config) +{ + m_dhcp6Config = dhcp6Config; +} + +void ActiveConnection::setId(const QString &id) +{ + m_id = id; +} + +void ActiveConnection::setIpv4Config(const QDBusObjectPath &ipv4Config) +{ + m_ip4Config = ipv4Config; +} + +void ActiveConnection::setIpv6Config(const QDBusObjectPath &ipv6Config) +{ + m_ip6Config = ipv6Config; +} + +void ActiveConnection::setMaster(const QDBusObjectPath &master) +{ + m_master = master; +} + +void ActiveConnection::setSpecificObject(const QDBusObjectPath &specificObject) +{ + m_specificObject = specificObject; +} + +void ActiveConnection::setState(uint state) +{ + m_state = state; +} + +void ActiveConnection::setType(const QString &type) +{ + m_type = type; + + if (type == QLatin1String("vpn")) { + m_vpn = true; + } +} + +void ActiveConnection::setUuid(const QString &uuid) +{ + m_uuid = uuid; +} diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/activeconnection.h b/panels/dock/tray/networkmanager-qt/src/fakenetwork/activeconnection.h new file mode 100644 index 000000000..7e7994e34 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/activeconnection.h @@ -0,0 +1,102 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_FAKE_NETWORK_SETTINGS_ACTIVE_CONNECTION_H +#define NETWORKMANAGERQT_FAKE_NETWORK_SETTINGS_ACTIVE_CONNECTION_H + +#include + +#include + +#include "../device.h" + +#include "device.h" + +class ActiveConnection : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.fakenetwork.Connection.Active") +public: + explicit ActiveConnection(QObject *parent = nullptr); + ~ActiveConnection() override; + + Q_PROPERTY(QDBusObjectPath Connection READ connection) + Q_PROPERTY(bool Default READ default4) + Q_PROPERTY(bool Default6 READ default6) + Q_PROPERTY(QList Devices READ devices) + Q_PROPERTY(QDBusObjectPath Dhcp4Config READ dhcp4Config) + Q_PROPERTY(QDBusObjectPath Dhcp6Config READ dhcp6Config) + Q_PROPERTY(QDBusObjectPath Ip4Config READ ip4Config) + Q_PROPERTY(QDBusObjectPath Ip6Config READ ip6Config) + Q_PROPERTY(QDBusObjectPath Master READ master) + Q_PROPERTY(QDBusObjectPath SpecificObject READ specificObject) + Q_PROPERTY(uint State READ state) + Q_PROPERTY(QString Id READ id) + Q_PROPERTY(QString Uuid READ uuid) + Q_PROPERTY(QString Type READ type) + Q_PROPERTY(bool Vpn READ vpn) + + QDBusObjectPath connection() const; + bool default4() const; + bool default6() const; + QList devices() const; + QDBusObjectPath dhcp4Config() const; + QDBusObjectPath dhcp6Config() const; + QDBusObjectPath ip4Config() const; + QDBusObjectPath ip6Config() const; + QDBusObjectPath master() const; + QDBusObjectPath specificObject() const; + uint state() const; + QString id() const; + QString uuid() const; + QString type() const; + bool vpn() const; + + /* Not part of DBus interface */ + void addDevice(const QDBusObjectPath &path); + void removeDevice(const QDBusObjectPath &device); + QString activeConnectionPath() const; + void setActiveConnectionPath(const QString &path); + void setConnection(const QDBusObjectPath &connection); + void setDefault4(bool default4); + void setDefault6(bool default6); + void setDhcp4Config(const QDBusObjectPath &dhcp4Config); + void setDhcp6Config(const QDBusObjectPath &dhcp6Config); + void setIpv4Config(const QDBusObjectPath &ipv4Config); + void setIpv6Config(const QDBusObjectPath &ipv6Config); + void setMaster(const QDBusObjectPath &master); + void setSpecificObject(const QDBusObjectPath &specificObject); + void setState(uint state); + void setId(const QString &id); + void setUuid(const QString &uuid); + void setType(const QString &type); + +Q_SIGNALS: + Q_SCRIPTABLE void PropertiesChanged(const QVariantMap &properties); + Q_SCRIPTABLE void StateChanged(uint state, uint reason); + +private: + QDBusObjectPath m_connection; + bool m_default4; + bool m_default6; + QList m_devices; + QDBusObjectPath m_dhcp4Config; + QDBusObjectPath m_dhcp6Config; + QDBusObjectPath m_ip4Config; + QDBusObjectPath m_ip6Config; + QDBusObjectPath m_master; + QDBusObjectPath m_specificObject; + uint m_state; + QString m_id; + QString m_uuid; + QString m_type; + bool m_vpn; + + /* Not part of DBus interface */ + QString m_activeConnectionPath; +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/connection.cpp b/panels/dock/tray/networkmanager-qt/src/fakenetwork/connection.cpp new file mode 100644 index 000000000..fa477ebda --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/connection.cpp @@ -0,0 +1,78 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "connection.h" + +#include + +Connection::Connection(QObject *parent, const NMVariantMapMap &settings) + : QObject(parent) + , m_unsaved(false) + , m_settings(settings) +{ + qDBusRegisterMetaType(); +} + +Connection::~Connection() +{ +} + +bool Connection::unsaved() const +{ + return m_unsaved; +} + +void Connection::Delete() +{ + // From some reason signal Removed is not send over DBus when using only Q_EMIT + QDBusMessage message = QDBusMessage::createSignal(m_connectionPath, QLatin1String("org.kde.fakenetwork.Settings.Connection"), QLatin1String("Removed")); + QDBusConnection::sessionBus().send(message); + // Q_EMIT Removed(); + + // Send it for FakeNetwork as well + Q_EMIT connectionRemoved(QDBusObjectPath(m_connectionPath)); +} + +NMVariantMapMap Connection::GetSecrets(const QString &setting_name) +{ + Q_UNUSED(setting_name) + // TODO + return NMVariantMapMap(); +} + +NMVariantMapMap Connection::GetSettings() +{ + // TODO: return settings without secrets + return m_settings; +} + +void Connection::Save() +{ + // TODO +} + +void Connection::Update(const NMVariantMapMap &properties) +{ + m_settings = properties; + + Q_EMIT Updated(); +} + +void Connection::UpdateUnsaved(const NMVariantMapMap &properties) +{ + Q_UNUSED(properties) + // TODO +} + +QString Connection::connectionPath() const +{ + return m_connectionPath; +} + +void Connection::setConnectionPath(const QString &path) +{ + m_connectionPath = path; +} diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/connection.h b/panels/dock/tray/networkmanager-qt/src/fakenetwork/connection.h new file mode 100644 index 000000000..9a0976f71 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/connection.h @@ -0,0 +1,54 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_FAKE_NETWORK_SETTINGS_CONNECTION_H +#define NETWORKMANAGERQT_FAKE_NETWORK_SETTINGS_CONNECTION_H + +#include + +#include + +#include "../generictypes.h" + +class Connection : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.fakenetwork.Settings.Connection") +public: + explicit Connection(QObject *parent = nullptr, const NMVariantMapMap &settings = NMVariantMapMap()); + ~Connection() override; + + Q_PROPERTY(bool Unsaved READ unsaved) + + bool unsaved() const; + + /* Not part of DBus interface */ + QString connectionPath() const; + void setConnectionPath(const QString &path); + +public Q_SLOTS: // METHODS + Q_SCRIPTABLE void Delete(); + Q_SCRIPTABLE NMVariantMapMap GetSecrets(const QString &setting_name); + Q_SCRIPTABLE NMVariantMapMap GetSettings(); + Q_SCRIPTABLE void Save(); + Q_SCRIPTABLE void Update(const NMVariantMapMap &properties); + Q_SCRIPTABLE void UpdateUnsaved(const NMVariantMapMap &properties); + +Q_SIGNALS: + void connectionRemoved(const QDBusObjectPath &path); + Q_SCRIPTABLE void Removed(); + Q_SCRIPTABLE void Updated(); + Q_SCRIPTABLE void PropertiesChanged(const QVariantMap &properties); + +private: + bool m_unsaved; + NMVariantMapMap m_settings; + + /* Not part of DBus interface */ + QString m_connectionPath; +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/device.cpp b/panels/dock/tray/networkmanager-qt/src/fakenetwork/device.cpp new file mode 100644 index 000000000..9081c7010 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/device.cpp @@ -0,0 +1,291 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "device.h" +#include "activeconnection.h" + +#include +#include + +Device::Device(QObject *parent) + : QObject(parent) + , m_activeConnection(QDBusObjectPath("/")) + , m_autoconnect(true) + , m_capabilities(0) + , m_deviceType(0) + , m_dhcp4Config(QDBusObjectPath("/")) + , m_dhcp6Config(QDBusObjectPath("/")) + , m_firmwareMissing(false) + , m_ip4Address(0) + , m_ip4Config(QDBusObjectPath("/")) + , m_ip6Config(QDBusObjectPath("/")) + , m_managed(true) + , m_mtu(0) + , m_state(30) +{ + qDBusRegisterMetaType(); +} + +Device::~Device() +{ +} + +QDBusObjectPath Device::activeConnection() const +{ + return m_activeConnection; +} + +bool Device::autoconnect() const +{ + return m_autoconnect; +} + +void Device::setAutoconnect(bool autoconnect) +{ + m_autoconnect = autoconnect; +} + +QList Device::availableConnections() const +{ + return m_availableConnections; +} + +uint Device::capabilities() const +{ + return m_capabilities; +} + +QString Device::deviceInterface() const +{ + if (m_deviceType == NetworkManager::Device::Ethernet) { + return QLatin1String("org.kde.fakenetwork.Device.Wired"); + } else if (m_deviceType == NetworkManager::Device::Wifi) { + return QLatin1String("org.kde.fakenetwork.Device.Wireless"); + } + + return QLatin1String("org.kde.fakenetwork.Device.Wired"); +} + +QString Device::devicePath() const +{ + return m_devicePath; +} + +void Device::setDevicePath(const QString &devicePath) +{ + m_devicePath = devicePath; +} + +uint Device::deviceType() const +{ + return m_deviceType; +} + +QDBusObjectPath Device::dhcp4Config() const +{ + return m_dhcp4Config; +} + +QDBusObjectPath Device::dhcp6Config() const +{ + return m_dhcp6Config; +} + +QString Device::driver() const +{ + return m_driver; +} + +QString Device::driverVersion() const +{ + return m_driverVersion; +} + +bool Device::firmwareMissing() const +{ + return m_firmwareMissing; +} + +QString Device::firmwareVersion() const +{ + return m_firmwareVersion; +} + +QString Device::interface() const +{ + return m_interface; +} + +int Device::ip4Address() const +{ + return m_ip4Address; +} + +QDBusObjectPath Device::ip4Config() const +{ + return m_ip4Config; +} + +QDBusObjectPath Device::ip6Config() const +{ + return m_ip6Config; +} + +QString Device::ipInterface() const +{ + return m_ipInterface; +} + +uint Device::interfaceFlags() const +{ + return m_interfaceFlags; +} + +bool Device::managed() const +{ + return m_managed; +} + +uint Device::mtu() const +{ + return m_mtu; +} + +uint Device::state() const +{ + return m_state; +} + +DeviceDBusStateReason Device::stateReason() const +{ + return m_stateReason; +} + +QString Device::udi() const +{ + return m_udi; +} + +void Device::addAvailableConnection(const QDBusObjectPath &availableConnection) +{ + m_availableConnections << availableConnection; +} + +void Device::removeAvailableConnection(const QDBusObjectPath &availableConnection) +{ + m_availableConnections.removeAll(availableConnection); +} + +void Device::setActiveConnection(const QString &activeConnection) +{ + m_activeConnection = QDBusObjectPath(activeConnection); +} + +void Device::setCapabilities(uint capabilities) +{ + m_capabilities = capabilities; +} + +void Device::setDeviceType(uint deviceType) +{ + m_deviceType = deviceType; +} + +void Device::setDhcp4Config(const QString &config) +{ + m_dhcp4Config = QDBusObjectPath(config); +} + +void Device::setDhcp6Config(const QString &config) +{ + m_dhcp6Config = QDBusObjectPath(config); +} + +void Device::setDriver(const QString &driver) +{ + m_driver = driver; +} + +void Device::setDriverVersion(const QString &driverVersion) +{ + m_driverVersion = driverVersion; +} + +void Device::setFirmwareMissing(bool firmwareMissing) +{ + m_firmwareMissing = firmwareMissing; +} + +void Device::setFirmwareVersion(const QString &firmwareVersion) +{ + m_firmwareVersion = firmwareVersion; +} + +void Device::setInterface(const QString &interface) +{ + m_interface = interface; +} + +void Device::setInterfaceFlags(uint interfaceFlags) +{ + m_interfaceFlags = interfaceFlags; +} + +void Device::setIp4Config(const QString &config) +{ + m_ip4Config = QDBusObjectPath(config); +} + +void Device::setIp6Config(const QString &config) +{ + m_ip6Config = QDBusObjectPath(config); +} + +void Device::setIpv4Address(int address) +{ + m_ip4Address = address; +} + +void Device::setIpInterface(const QString &interface) +{ + m_ipInterface = interface; +} + +void Device::setManaged(bool managed) +{ + m_managed = managed; +} + +void Device::setMtu(uint mtu) +{ + m_mtu = mtu; +} + +void Device::setState(uint state) +{ + uint previousState = m_state; + m_state = state; + m_stateReason.state = state; + + QDBusMessage message = QDBusMessage::createSignal(m_devicePath, QLatin1String("org.kde.fakenetwork.Device"), QLatin1String("StateChanged")); + message << previousState << state << m_stateReason.reason; + QDBusConnection::sessionBus().send(message); +} + +void Device::setStateReason(const DeviceDBusStateReason &reason) +{ + m_stateReason = reason; +} + +void Device::setUdi(const QString &udi) +{ + m_udi = udi; +} + +void Device::Disconnect() +{ + // TODO +} diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/device.h b/panels/dock/tray/networkmanager-qt/src/fakenetwork/device.h new file mode 100644 index 000000000..6f333b03b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/device.h @@ -0,0 +1,133 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_FAKE_NETWORK_DEVICE_H +#define NETWORKMANAGERQT_FAKE_NETWORK_DEVICE_H + +#include + +#include + +#include "../device.h" +#include "../generictypes.h" + +class Device : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.fakenetwork.Device") +public: + explicit Device(QObject *parent = nullptr); + ~Device() override; + + Q_PROPERTY(QDBusObjectPath ActiveConnection READ activeConnection) + Q_PROPERTY(bool Autoconnect READ autoconnect WRITE setAutoconnect) + Q_PROPERTY(QList AvailableConnections READ availableConnections) + Q_PROPERTY(uint Capabilities READ capabilities) + Q_PROPERTY(uint DeviceType READ deviceType) + Q_PROPERTY(QDBusObjectPath Dhcp4Config READ dhcp4Config) + Q_PROPERTY(QDBusObjectPath Dhcp6Config READ dhcp6Config) + Q_PROPERTY(QString Driver READ driver) + Q_PROPERTY(QString DriverVersion READ driverVersion) + Q_PROPERTY(bool FirmwareMissing READ firmwareMissing) + Q_PROPERTY(QString FirmwareVersion READ firmwareVersion) + Q_PROPERTY(QString Interface READ interface) + Q_PROPERTY(int Ip4Address READ ip4Address) + Q_PROPERTY(QDBusObjectPath Ip4Config READ ip4Config) + Q_PROPERTY(QDBusObjectPath Ip6Config READ ip6Config) + Q_PROPERTY(QString IpInterface READ ipInterface) + Q_PROPERTY(uint InterfaceFlags READ interfaceFlags) + Q_PROPERTY(bool Managed READ managed) + Q_PROPERTY(uint Mtu READ mtu) + Q_PROPERTY(uint State READ state) + Q_PROPERTY(DeviceDBusStateReason StateReason READ stateReason) + Q_PROPERTY(QString Udi READ udi) + + QDBusObjectPath activeConnection() const; + bool autoconnect() const; + void setAutoconnect(bool autoconnect); + QList availableConnections() const; + uint capabilities() const; + uint deviceType() const; + QDBusObjectPath dhcp4Config() const; + QDBusObjectPath dhcp6Config() const; + QString driver() const; + QString driverVersion() const; + bool firmwareMissing() const; + QString firmwareVersion() const; + QString interface() const; + int ip4Address() const; + QDBusObjectPath ip4Config() const; + QDBusObjectPath ip6Config() const; + QString ipInterface() const; + uint interfaceFlags() const; + bool managed() const; + uint mtu() const; + uint state() const; + DeviceDBusStateReason stateReason() const; + QString udi() const; + + /* Not part of DBus interface */ + void addAvailableConnection(const QDBusObjectPath &availableConnection); + void removeAvailableConnection(const QDBusObjectPath &availableConnection); + void setActiveConnection(const QString &activeConnection); + void setCapabilities(uint capabilities); + QString deviceInterface() const; + QString devicePath() const; + void setDevicePath(const QString &devicePath); + void setDeviceType(uint deviceType); + void setDhcp4Config(const QString &config); + void setDhcp6Config(const QString &config); + void setDriver(const QString &driver); + void setDriverVersion(const QString &driverVersion); + void setFirmwareMissing(bool firmwareMissing); + void setFirmwareVersion(const QString &firmwareVersion); + void setInterface(const QString &interface); + void setInterfaceFlags(uint interfaceFlags); + void setIpv4Address(int address); + void setIp4Config(const QString &config); + void setIp6Config(const QString &config); + void setIpInterface(const QString &interface); + void setManaged(bool managed); + void setMtu(uint mtu); + virtual void setState(uint state); + void setStateReason(const DeviceDBusStateReason &reason); + void setUdi(const QString &udi); + +public Q_SLOTS: + Q_SCRIPTABLE void Disconnect(); + +Q_SIGNALS: + void activeConnectionRemoved(const QDBusObjectPath &activeConnection); + Q_SCRIPTABLE void StateChanged(uint new_state, uint old_state, uint reason); + +private: + QDBusObjectPath m_activeConnection; + bool m_autoconnect; + QList m_availableConnections; + uint m_capabilities; + QString m_devicePath; + uint m_deviceType; + QDBusObjectPath m_dhcp4Config; + QDBusObjectPath m_dhcp6Config; + QString m_driver; + QString m_driverVersion; + bool m_firmwareMissing; + QString m_firmwareVersion; + QString m_interface; + uint m_interfaceFlags; + int m_ip4Address; + QDBusObjectPath m_ip4Config; + QDBusObjectPath m_ip6Config; + QString m_ipInterface; + bool m_managed; + uint m_mtu; + QString m_physicalPortId; + uint m_state; + DeviceDBusStateReason m_stateReason; + QString m_udi; +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/fakenetwork.cpp b/panels/dock/tray/networkmanager-qt/src/fakenetwork/fakenetwork.cpp new file mode 100644 index 000000000..7eeb3c421 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/fakenetwork.cpp @@ -0,0 +1,477 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "fakenetwork.h" +#include "connection.h" +#include "wireddevice.h" +#include "wirelessdevice.h" + +#include +#include +#include + +#include "../manager.h" +#include "connectionsettings.h" + +FakeNetwork::FakeNetwork(QObject *parent) + : QObject(parent) + , m_activatingConnection(QDBusObjectPath("/")) + , m_connectivity(NetworkManager::Connectivity::NoConnectivity) + , m_networkingEnabled(true) + , m_primaryConnection(QDBusObjectPath("/")) + , m_state(20) + , m_version(QLatin1String("0.9.10.0")) + , m_wimaxEnabled(true) + , m_wimaxHardwareEnabled(true) + , m_wirelessEnabled(true) + , m_wirelessHardwareEnabled(true) + , m_wwanEnabled(true) + , m_wwanHardwareEnabled(true) + , m_activeConnectionsCounter(0) + , m_deviceCounter(0) + , m_settings(new Settings(this)) +{ + qDBusRegisterMetaType(); + registerService(); + connect(m_settings, &Settings::connectionAdded, this, &FakeNetwork::onConnectionAdded); + connect(m_settings, &Settings::connectionRemoved, this, &FakeNetwork::onConnectionRemoved); +} + +FakeNetwork::~FakeNetwork() +{ + unregisterService(); + qDeleteAll(m_devices); + delete m_settings; +} + +QDBusObjectPath FakeNetwork::activatingConnection() const +{ + return m_activatingConnection; +} + +QList FakeNetwork::activeConnections() const +{ + return m_activeConnections.keys(); +} + +uint FakeNetwork::connectivity() const +{ + return m_connectivity; +} + +QList FakeNetwork::devices() const +{ + return m_devices.keys(); +} + +bool FakeNetwork::networkingEnabled() const +{ + return m_networkingEnabled; +} + +QDBusObjectPath FakeNetwork::primaryConnection() const +{ + return m_primaryConnection; +} + +uint FakeNetwork::state() const +{ + return m_state; +} + +QString FakeNetwork::version() const +{ + return m_version; +} + +bool FakeNetwork::wimaxEnabled() const +{ + return m_wimaxEnabled; +} + +void FakeNetwork::setWimaxEnabled(bool enabled) +{ + m_wimaxEnabled = enabled; + + QVariantMap map; + map.insert(QLatin1String("WimaxEnabled"), m_wimaxEnabled); + Q_EMIT PropertiesChanged(map); +} + +bool FakeNetwork::wimaxHardwareEnabled() const +{ + return m_wimaxHardwareEnabled; +} + +void FakeNetwork::setWimaxHardwareEnabled(bool enabled) +{ + m_wimaxHardwareEnabled = enabled; + + QVariantMap map; + map.insert(QLatin1String("WimaxHardwareEnabled"), m_wimaxHardwareEnabled); + Q_EMIT PropertiesChanged(map); +} + +bool FakeNetwork::wirelessEnabled() const +{ + return m_wirelessEnabled; +} + +void FakeNetwork::setWirelessEnabled(bool enabled) +{ + m_wirelessEnabled = enabled; + + QVariantMap map; + map.insert(QLatin1String("WirelessEnabled"), m_wirelessEnabled); + Q_EMIT PropertiesChanged(map); +} + +bool FakeNetwork::wirelessHardwareEnabled() const +{ + return m_wirelessHardwareEnabled; +} + +void FakeNetwork::setWirelessHardwareEnabled(bool enabled) +{ + m_wirelessHardwareEnabled = enabled; + + QVariantMap map; + map.insert(QLatin1String("WirelessHardwareEnabled"), m_wirelessHardwareEnabled); + Q_EMIT PropertiesChanged(map); +} + +bool FakeNetwork::wwanEnabled() const +{ + return m_wwanEnabled; +} + +void FakeNetwork::setWwanEnabled(bool enabled) +{ + m_wwanEnabled = enabled; + + QVariantMap map; + map.insert(QLatin1String("WwanEnabled"), m_wwanEnabled); + Q_EMIT PropertiesChanged(map); +} + +bool FakeNetwork::wwanHardwareEnabled() const +{ + return m_wwanHardwareEnabled; +} + +void FakeNetwork::addDevice(Device *device) +{ + QString newDevicePath = QString("/org/kde/fakenetwork/Devices/") + QString::number(m_deviceCounter++); + device->setDevicePath(newDevicePath); + m_devices.insert(QDBusObjectPath(newDevicePath), device); + QDBusConnection::sessionBus().registerObject(newDevicePath, device, QDBusConnection::ExportScriptableContents); + Q_EMIT DeviceAdded(QDBusObjectPath(newDevicePath)); +} + +void FakeNetwork::removeDevice(Device *device) +{ + m_devices.remove(QDBusObjectPath(device->devicePath())); + QDBusConnection::sessionBus().unregisterObject(device->devicePath()); + Q_EMIT DeviceRemoved(QDBusObjectPath(device->devicePath())); +} + +void FakeNetwork::registerService() +{ + QDBusConnection::sessionBus().registerService(QLatin1String("org.kde.fakenetwork")); + QDBusConnection::sessionBus().registerObject(QLatin1String("/org/kde/fakenetwork"), this, QDBusConnection::ExportScriptableContents); + QDBusConnection::sessionBus().registerObject(QLatin1String("/org/kde/fakenetwork/Settings"), m_settings, QDBusConnection::ExportScriptableContents); + + for (auto it = m_devices.cbegin(); it != m_devices.cend(); ++it) { + const QDBusObjectPath &devicePath = it.key(); + QDBusConnection::sessionBus().registerObject(devicePath.path(), it.value(), QDBusConnection::ExportScriptableContents); + Q_EMIT DeviceAdded(devicePath); + } +} + +void FakeNetwork::unregisterService() +{ + for (auto it = m_devices.cbegin(); it != m_devices.cend(); ++it) { + const QDBusObjectPath &devicePath = it.key(); + QDBusConnection::sessionBus().unregisterObject(devicePath.path()); + Q_EMIT DeviceRemoved(devicePath); + } + + QDBusConnection::sessionBus().unregisterObject(QLatin1String("/org/kde/fakenetwork/Settings")); + QDBusConnection::sessionBus().unregisterObject(QLatin1String("/org/kde/fakenetwork")); + QDBusConnection::sessionBus().unregisterService(QLatin1String("org.kde.fakenetwork")); +} + +QDBusObjectPath FakeNetwork::ActivateConnection(const QDBusObjectPath &connection, const QDBusObjectPath &device, const QDBusObjectPath &specific_object) +{ + QString newActiveConnectionPath = QString("/org/kde/fakenetwork/ActiveConnection/") + QString::number(m_activeConnectionsCounter++); + ActiveConnection *newActiveConnection = new ActiveConnection(this); + newActiveConnection->addDevice(device); + newActiveConnection->setActiveConnectionPath(newActiveConnectionPath); + newActiveConnection->setConnection(connection); + newActiveConnection->setSpecificObject(specific_object); + newActiveConnection->setState(NetworkManager::ActiveConnection::Activating); + + m_activeConnections.insert(QDBusObjectPath(newActiveConnectionPath), newActiveConnection); + QDBusConnection::sessionBus().registerObject(newActiveConnectionPath, newActiveConnection, QDBusConnection::ExportScriptableContents); + + m_activatingConnection = QDBusObjectPath(newActiveConnectionPath); + + QVariantMap map; + map.insert(QLatin1String("ActiveConnections"), QVariant::fromValue>(m_activeConnections.keys())); + map.insert(QLatin1String("ActivatingConnection"), QVariant::fromValue(QDBusObjectPath(newActiveConnectionPath))); + Q_EMIT PropertiesChanged(map); + + Device *usedDevice = static_cast(QDBusConnection::sessionBus().objectRegisteredAt(device.path())); + if (usedDevice) { + m_activatedDevice = usedDevice->devicePath(); + // Start simulation of activation + usedDevice->setActiveConnection(newActiveConnectionPath); + usedDevice->setState(NetworkManager::Device::Preparing); + QTimer::singleShot(100, this, SLOT(updateConnectingState())); + } + + return QDBusObjectPath(newActiveConnectionPath); +} + +void FakeNetwork::updateConnectingState() +{ + QVariantMap deviceMap; + Device *device = m_devices.value(QDBusObjectPath(m_activatedDevice)); + if (device->state() == NetworkManager::Device::Preparing) { + device->setState(NetworkManager::Device::ConfiguringHardware); + } else if (device->state() == NetworkManager::Device::ConfiguringHardware) { + device->setState(NetworkManager::Device::NeedAuth); + } else if (device->state() == NetworkManager::Device::NeedAuth) { + device->setState(NetworkManager::Device::ConfiguringIp); + } else if (device->state() == NetworkManager::Device::ConfiguringIp) { + device->setState(NetworkManager::Device::CheckingIp); + } else if (device->state() == NetworkManager::Device::CheckingIp) { + device->setState(NetworkManager::Device::Activated); + + ActiveConnection *activeConnection = + static_cast(QDBusConnection::sessionBus().objectRegisteredAt(device->activeConnection().path())); + if (activeConnection) { + QVariantMap activeConnectionMap; + activeConnectionMap.insert(QLatin1String("State"), NetworkManager::ActiveConnection::Activated); + + activeConnection->setState(NetworkManager::ActiveConnection::Activated); + QDBusMessage message = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), + QLatin1String("org.kde.fakenetwork.Connection.Active"), + QLatin1String("PropertiesChanged")); + message << activeConnectionMap; + QDBusConnection::sessionBus().send(message); + + QDBusMessage message2 = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), + QLatin1String("org.kde.fakenetwork.Connection.Active"), + QLatin1String("StateChanged")); + message2 << (uint)2 << (uint)1; // NM_ACTIVE_CONNECTION_STATE_ACTIVATED << NM_ACTIVE_CONNECTION_STATE_REASON_NONE + QDBusConnection::sessionBus().send(message2); + } + // TODO: set dhcp4Config, dhcp6Config, ip4Config, ip6Config + // IP Interface is usually same as interface + device->setIpInterface(device->interface()); + // Set some IP address + device->setIpv4Address(1763189258); + + deviceMap.insert(QLatin1String("IpInterface"), device->ipInterface()); + deviceMap.insert(QLatin1String("Ip4Address"), device->ip4Address()); + deviceMap.insert(QLatin1String("ActiveConnection"), m_activatingConnection.path()); + + // Update FakeNetwork state, connectivity, primary connection + m_connectivity = NetworkManager::Connectivity::Full; + m_primaryConnection = m_activatingConnection; + m_activatingConnection = QDBusObjectPath("/"); + m_state = 70; + QVariantMap networkMap; + networkMap.insert(QLatin1String("ActivatingConnection"), QVariant::fromValue(m_activatingConnection)); + networkMap.insert(QLatin1String("Connectivity"), NetworkManager::Connectivity::Full); + networkMap.insert(QLatin1String("PrimaryConnection"), QVariant::fromValue(m_primaryConnection)); + networkMap.insert(QLatin1String("State"), m_state); + + QDBusMessage message = + QDBusMessage::createSignal(QLatin1String("/org/kde/fakenetwork"), QLatin1String("org.kde.fakenetwork"), QLatin1String("PropertiesChanged")); + message << networkMap; + QDBusConnection::sessionBus().send(message); + + Q_EMIT StateChanged(m_state); + } + + deviceMap.insert(QLatin1String("State"), device->state()); + QDBusMessage message = QDBusMessage::createSignal(device->devicePath(), device->deviceInterface(), QLatin1String("PropertiesChanged")); + message << deviceMap; + QDBusConnection::sessionBus().send(message); + + if (device->state() != NetworkManager::Device::Activated) { + QTimer::singleShot(100, this, SLOT(updateConnectingState())); + } +} + +uint FakeNetwork::CheckConnectivity() const +{ + return m_connectivity; +} + +void FakeNetwork::DeactivateConnection(const QDBusObjectPath &active_connection) +{ + ActiveConnection *activeConnection = m_activeConnections.value(active_connection); + if (activeConnection) { + activeConnection->setState(NetworkManager::ActiveConnection::Deactivating); + + QVariantMap activeConnectionMap; + activeConnectionMap.insert(QLatin1String("State"), NetworkManager::ActiveConnection::Deactivating); + + activeConnection->setState(NetworkManager::ActiveConnection::Activated); + QDBusMessage message = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), + QLatin1String("org.kde.fakenetwork.Connection.Active"), + QLatin1String("PropertiesChanged")); + message << activeConnectionMap; + QDBusConnection::sessionBus().send(message); + + QDBusMessage message2 = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), + QLatin1String("org.kde.fakenetwork.Connection.Active"), + QLatin1String("StateChanged")); + message2 << (uint)4 << (uint)2; // NM_ACTIVE_CONNECTION_STATE_DEACTIVATED << NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED + QDBusConnection::sessionBus().send(message2); + + Device *device = m_devices.value(activeConnection->devices().first()); + if (device) { + m_deactivatedDevice = device->devicePath(); + device->setState(NetworkManager::Device::Deactivating); + QTimer::singleShot(100, this, SLOT(updateDeactivatingState())); + } + + // Update FakeNetwork state, connectivity, primary connection + m_connectivity = NetworkManager::Connectivity::NoConnectivity; + m_primaryConnection = QDBusObjectPath("/"); + m_state = 20; + QVariantMap networkMap; + networkMap.insert(QLatin1String("Connectivity"), m_connectivity); + networkMap.insert(QLatin1String("PrimaryConnection"), QVariant::fromValue(m_primaryConnection)); + networkMap.insert(QLatin1String("State"), m_state); + + message = QDBusMessage::createSignal(QLatin1String("/org/kde/fakenetwork"), QLatin1String("org.kde.fakenetwork"), QLatin1String("PropertiesChanged")); + message << networkMap; + QDBusConnection::sessionBus().send(message); + + Q_EMIT StateChanged(m_state); + } +} + +void FakeNetwork::updateDeactivatingState() +{ + QVariantMap deviceMap; + Device *device = m_devices.value(QDBusObjectPath(m_deactivatedDevice)); + ActiveConnection *activeConnection = static_cast(QDBusConnection::sessionBus().objectRegisteredAt(device->activeConnection().path())); + if (activeConnection) { + QVariantMap activeConnectionMap; + activeConnectionMap.insert(QLatin1String("State"), NetworkManager::ActiveConnection::Deactivated); + + activeConnection->setState(NetworkManager::ActiveConnection::Activated); + QDBusMessage message = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), + QLatin1String("org.kde.fakenetwork.Connection.Active"), + QLatin1String("PropertiesChanged")); + message << activeConnectionMap; + QDBusConnection::sessionBus().send(message); + + QDBusMessage message2 = QDBusMessage::createSignal(activeConnection->activeConnectionPath(), + QLatin1String("org.kde.fakenetwork.Connection.Active"), + QLatin1String("StateChanged")); + message2 << (uint)3 << (uint)2; // NM_ACTIVE_CONNECTION_STATE_DEACTIVATING << NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED + QDBusConnection::sessionBus().send(message2); + + removeActiveConnection(QDBusObjectPath(activeConnection->activeConnectionPath())); + } + + device->setActiveConnection(QLatin1String("/")); + device->setState(NetworkManager::Device::Disconnected); + // TODO: set dhcp4Config, dhcp6Config, ip4Config, ip6Config + // IP Interface is usually same as interface + device->setIpInterface(""); + // Set some IP address + device->setIpv4Address(0); + + deviceMap.insert(QLatin1String("ActiveConnection"), device->activeConnection().path()); + deviceMap.insert(QLatin1String("IpInterface"), device->ipInterface()); + deviceMap.insert(QLatin1String("Ip4Address"), device->ip4Address()); + deviceMap.insert(QLatin1String("State"), device->state()); + + QDBusMessage message = QDBusMessage::createSignal(device->devicePath(), device->deviceInterface(), QLatin1String("PropertiesChanged")); + message << deviceMap; + QDBusConnection::sessionBus().send(message); +} + +QDBusObjectPath FakeNetwork::GetDeviceByIpIface(const QString &iface) +{ + Q_UNUSED(iface) + // TODO + return QDBusObjectPath(); +} + +QList FakeNetwork::GetDevices() const +{ + return m_devices.keys(); +} + +void FakeNetwork::onConnectionAdded(const QDBusObjectPath &connection) +{ + Connection *newConnection = static_cast(QDBusConnection::sessionBus().objectRegisteredAt(connection.path())); + if (newConnection) { + NMVariantMapMap settings = newConnection->GetSettings(); + NetworkManager::ConnectionSettings::ConnectionType type = + NetworkManager::ConnectionSettings::typeFromString(settings.value(QLatin1String("connection")).value(QLatin1String("type")).toString()); + if (!m_devices.isEmpty()) { + Device *selectedDevice = nullptr; + for (Device *device : std::as_const(m_devices)) { + if (type == NetworkManager::ConnectionSettings::Wired && device->deviceType() == NetworkManager::Device::Ethernet) { + selectedDevice = device; + device->addAvailableConnection(connection); + break; + } else if (type == NetworkManager::ConnectionSettings::Wireless && device->deviceType() == NetworkManager::Device::Wifi) { + selectedDevice = device; + // TODO + break; + } + } + + if (selectedDevice) { + QVariantMap map; + map.insert(QLatin1String("AvailableConnections"), QVariant::fromValue>(selectedDevice->availableConnections())); + + QDBusMessage message = + QDBusMessage::createSignal(selectedDevice->devicePath(), selectedDevice->deviceInterface(), QLatin1String("PropertiesChanged")); + message << map; + QDBusConnection::sessionBus().send(message); + } + } + } +} + +void FakeNetwork::onConnectionRemoved(const QDBusObjectPath &connection) +{ + for (Device *device : std::as_const(m_devices)) { + if (device && device->availableConnections().contains(connection)) { + device->removeAvailableConnection(connection); + + QVariantMap map; + map.insert(QLatin1String("AvailableConnections"), QVariant::fromValue>(device->availableConnections())); + + QDBusMessage message = QDBusMessage::createSignal(device->devicePath(), device->deviceInterface(), QLatin1String("PropertiesChanged")); + message << map; + QDBusConnection::sessionBus().send(message); + } + } +} + +void FakeNetwork::removeActiveConnection(const QDBusObjectPath &activeConnection) +{ + delete m_activeConnections.value(activeConnection); + m_activeConnections.remove(activeConnection); + QDBusConnection::sessionBus().unregisterObject(activeConnection.path()); + + QVariantMap map; + map.insert(QLatin1String("ActiveConnections"), QVariant::fromValue>(m_activeConnections.keys())); + Q_EMIT PropertiesChanged(map); +} diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/fakenetwork.h b/panels/dock/tray/networkmanager-qt/src/fakenetwork/fakenetwork.h new file mode 100644 index 000000000..8c050400f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/fakenetwork.h @@ -0,0 +1,114 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_FAKE_NETWORK_H +#define NETWORKMANAGERQT_FAKE_NETWORK_H + +#include + +#include + +#include "../device.h" +#include "../generictypes.h" + +#include "activeconnection.h" +#include "device.h" +#include "settings.h" + +class FakeNetwork : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.fakenetwork") +public: + explicit FakeNetwork(QObject *parent = nullptr); + ~FakeNetwork() override; + + Q_PROPERTY(QDBusObjectPath ActivatingConnection READ activatingConnection) + Q_PROPERTY(QList ActiveConnections READ activeConnections) + Q_PROPERTY(uint Connectivity READ connectivity) + Q_PROPERTY(QList Devices READ devices) + Q_PROPERTY(bool NetworkingEnabled READ networkingEnabled) + Q_PROPERTY(QDBusObjectPath PrimaryConnection READ primaryConnection) + Q_PROPERTY(uint State READ state) + Q_PROPERTY(QString Version READ version) + Q_PROPERTY(bool WimaxEnabled READ wimaxEnabled WRITE setWimaxEnabled) + Q_PROPERTY(bool WimaxHardwareEnabled READ wimaxHardwareEnabled) + Q_PROPERTY(bool WirelessEnabled READ wirelessEnabled WRITE setWirelessEnabled) + Q_PROPERTY(bool WirelessHardwareEnabled READ wirelessHardwareEnabled) + Q_PROPERTY(bool WwanEnabled READ wwanEnabled WRITE setWwanEnabled) + Q_PROPERTY(bool WwanHardwareEnabled READ wwanHardwareEnabled) + + QDBusObjectPath activatingConnection() const; + QList activeConnections() const; + uint connectivity() const; + QList devices() const; + bool networkingEnabled() const; + QDBusObjectPath primaryConnection() const; + uint state() const; + QString version() const; + bool wimaxEnabled() const; + void setWimaxEnabled(bool enabled); + bool wimaxHardwareEnabled() const; + void setWimaxHardwareEnabled(bool enabled); + bool wirelessEnabled() const; + void setWirelessEnabled(bool enabled); + bool wirelessHardwareEnabled() const; + void setWirelessHardwareEnabled(bool enabled); + bool wwanEnabled() const; + void setWwanEnabled(bool enabled); + bool wwanHardwareEnabled() const; + + /* Not part of DBus interface */ + void addDevice(Device *device); + void removeDevice(Device *device); + void registerService(); + void unregisterService(); + +private Q_SLOTS: + void onConnectionAdded(const QDBusObjectPath &connection); + void onConnectionRemoved(const QDBusObjectPath &connection); + void removeActiveConnection(const QDBusObjectPath &activeConnection); + void updateConnectingState(); + void updateDeactivatingState(); + +public Q_SLOTS: + Q_SCRIPTABLE QDBusObjectPath ActivateConnection(const QDBusObjectPath &connection, const QDBusObjectPath &device, const QDBusObjectPath &specific_object); + Q_SCRIPTABLE uint CheckConnectivity() const; + Q_SCRIPTABLE void DeactivateConnection(const QDBusObjectPath &active_connection); + Q_SCRIPTABLE QDBusObjectPath GetDeviceByIpIface(const QString &iface); + Q_SCRIPTABLE QList GetDevices() const; + +Q_SIGNALS: + Q_SCRIPTABLE void DeviceAdded(const QDBusObjectPath &device_path); + Q_SCRIPTABLE void DeviceRemoved(const QDBusObjectPath &device_path); + Q_SCRIPTABLE void PropertiesChanged(const QVariantMap &properties); + Q_SCRIPTABLE void StateChanged(uint state); + +private: + QDBusObjectPath m_activatingConnection; + QMap m_activeConnections; + uint m_connectivity; + QMap m_devices; + bool m_networkingEnabled; + QDBusObjectPath m_primaryConnection; + uint m_state; + QString m_version; + bool m_wimaxEnabled; + bool m_wimaxHardwareEnabled; + bool m_wirelessEnabled; + bool m_wirelessHardwareEnabled; + bool m_wwanEnabled; + bool m_wwanHardwareEnabled; + + /* Not part of DBus interface */ + QString m_activatedDevice; + QString m_deactivatedDevice; + int m_activeConnectionsCounter; + int m_deviceCounter; + Settings *m_settings; +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/settings.cpp b/panels/dock/tray/networkmanager-qt/src/fakenetwork/settings.cpp new file mode 100644 index 000000000..08456d6da --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/settings.cpp @@ -0,0 +1,99 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "settings.h" + +#include + +Settings::Settings(QObject *parent) + : QObject(parent) + , m_canModify(true) + , m_hostname(QLatin1String("fake-hostname")) + , m_connectionCounter(0) +{ + qDBusRegisterMetaType(); +} + +Settings::~Settings() +{ + for (auto it = m_connections.cbegin(); it != m_connections.cend(); ++it) { + const QDBusObjectPath &connection = it.key(); + QDBusConnection::sessionBus().unregisterObject(connection.path()); + Q_EMIT ConnectionRemoved(connection); + } + + qDeleteAll(m_connections); +} + +bool Settings::canModify() const +{ + return m_canModify; +} + +QList Settings::connections() const +{ + return m_connections.keys(); +} + +QString Settings::hostname() const +{ + return m_hostname; +} + +QDBusObjectPath Settings::AddConnection(const NMVariantMapMap &connection) +{ + Connection *newConnection = new Connection(this, connection); + QString newConnectionPath = QString("/org/kde/fakenetwork/Settings/") + QString::number(m_connectionCounter++); + newConnection->setConnectionPath(newConnectionPath); + m_connections.insert(QDBusObjectPath(newConnectionPath), newConnection); + QDBusConnection::sessionBus().registerObject(newConnectionPath, newConnection, QDBusConnection::ExportScriptableContents); + + connect(newConnection, &Connection::connectionRemoved, this, &Settings::onConnectionRemoved); + + Q_EMIT NewConnection(QDBusObjectPath(newConnectionPath)); + // Send it for FakeNetwork separately to get AvailableConnections signal after NewConnection + Q_EMIT connectionAdded(QDBusObjectPath(newConnectionPath)); + + return QDBusObjectPath(newConnectionPath); +} + +QDBusObjectPath Settings::AddConnectionUnsaved(const NMVariantMapMap &connection) +{ + Q_UNUSED(connection) + // TODO + return QDBusObjectPath(); +} + +QDBusObjectPath Settings::GetConnectionByUuid(const QString &uuid) +{ + Q_UNUSED(uuid) + // TODO + return QDBusObjectPath(); +} + +QList Settings::ListConnections() +{ + return m_connections.keys(); +} + +void Settings::SaveHostname(const QString &hostname) +{ + m_hostname = hostname; +} + +void Settings::onConnectionRemoved(const QDBusObjectPath &connectionPath) +{ + Connection *connection = m_connections.value(connectionPath); + + if (connection) { + QDBusConnection::sessionBus().unregisterObject(connectionPath.path()); + Q_EMIT ConnectionRemoved(connectionPath); + // Send it for FakeNetwork separately to get AvailableConnections signal after ConnectionRemoved + Q_EMIT connectionRemoved(connectionPath); + m_connections.remove(QDBusObjectPath(connectionPath)); + delete connection; + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/settings.h b/panels/dock/tray/networkmanager-qt/src/fakenetwork/settings.h new file mode 100644 index 000000000..dc5d2c0a3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/settings.h @@ -0,0 +1,60 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_FAKE_NETWORK_SETTINGS_H +#define NETWORKMANAGERQT_FAKE_NETWORK_SETTINGS_H + +#include + +#include + +#include "../generictypes.h" + +#include "connection.h" + +class Settings : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.fakenetwork.Settings") +public: + explicit Settings(QObject *parent = nullptr); + ~Settings() override; + + Q_PROPERTY(bool CanModify READ canModify) + Q_PROPERTY(QList Connections READ connections) + Q_PROPERTY(QString Hostname READ hostname) + + bool canModify() const; + QList connections() const; + QString hostname() const; + +private Q_SLOTS: + void onConnectionRemoved(const QDBusObjectPath &connectionPath); + +public Q_SLOTS: // METHODS + Q_SCRIPTABLE QDBusObjectPath AddConnection(const NMVariantMapMap &connection); + Q_SCRIPTABLE QDBusObjectPath AddConnectionUnsaved(const NMVariantMapMap &connection); + Q_SCRIPTABLE QDBusObjectPath GetConnectionByUuid(const QString &uuid); + Q_SCRIPTABLE QList ListConnections(); + Q_SCRIPTABLE void SaveHostname(const QString &hostname); + +Q_SIGNALS: + void connectionAdded(const QDBusObjectPath &connection); + void connectionRemoved(const QDBusObjectPath &connection); + Q_SCRIPTABLE void ConnectionRemoved(const QDBusObjectPath &connection); + Q_SCRIPTABLE void NewConnection(const QDBusObjectPath &connection); + Q_SCRIPTABLE void PropertiesChanged(const QVariantMap &properties); + +private: + bool m_canModify; + QMap m_connections; + QString m_hostname; + + /* Not part of DBus interface */ + int m_connectionCounter; +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/wireddevice.cpp b/panels/dock/tray/networkmanager-qt/src/fakenetwork/wireddevice.cpp new file mode 100644 index 000000000..d54c9954f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/wireddevice.cpp @@ -0,0 +1,65 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wireddevice.h" + +WiredDevice::WiredDevice(QObject *parent) + : Device(parent) +{ +} + +WiredDevice::~WiredDevice() +{ + QVariantMap map; + map.insert(QLatin1String("AvailableConnections"), QVariant::fromValue>(QList())); + Q_EMIT PropertiesChanged(map); +} + +bool WiredDevice::carrier() const +{ + return m_carrier; +} + +QString WiredDevice::hwAddress() const +{ + return m_hwAddress; +} + +QString WiredDevice::permHwAddress() const +{ + return m_permHwAddress; +} + +uint WiredDevice::speed() const +{ + return m_speed; +} + +void WiredDevice::setCarrier(bool carrier) +{ + m_carrier = carrier; +} + +void WiredDevice::setHwAddress(const QString &hwAddress) +{ + m_hwAddress = hwAddress; +} + +void WiredDevice::setPermanentHwAddress(const QString &permanentHwAddress) +{ + m_permHwAddress = permanentHwAddress; +} + +void WiredDevice::setSpeed(uint speed) +{ + m_speed = speed; +} + +void WiredDevice::setState(uint state) +{ + Device::setState(state); + // set speed +} diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/wireddevice.h b/panels/dock/tray/networkmanager-qt/src/fakenetwork/wireddevice.h new file mode 100644 index 000000000..2f367704d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/wireddevice.h @@ -0,0 +1,54 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_FAKE_NETWORK_WIRED_DEVICE_H +#define NETWORKMANAGERQT_FAKE_NETWORK_WIRED_DEVICE_H + +#include + +#include + +#include "../device.h" +#include "../generictypes.h" + +#include "device.h" + +class WiredDevice : public Device +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.fakenetwork.Device.Wired") +public: + explicit WiredDevice(QObject *parent = nullptr); + ~WiredDevice() override; + + Q_PROPERTY(bool Carrier READ carrier) + Q_PROPERTY(QString HwAddress READ hwAddress) + Q_PROPERTY(QString PermHwAddress READ permHwAddress) + Q_PROPERTY(uint Speed READ speed) + + bool carrier() const; + QString hwAddress() const; + QString permHwAddress() const; + uint speed() const; + + /* Not part of DBus interface */ + void setCarrier(bool carrier); + void setHwAddress(const QString &hwAddress); + void setPermanentHwAddress(const QString &permanentHwAddress); + void setSpeed(uint speed); + void setState(uint state) override; + +Q_SIGNALS: + Q_SCRIPTABLE void PropertiesChanged(const QVariantMap &properties); + +private: + bool m_carrier; + QString m_hwAddress; + QString m_permHwAddress; + uint m_speed; +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/wirelessdevice.cpp b/panels/dock/tray/networkmanager-qt/src/fakenetwork/wirelessdevice.cpp new file mode 100644 index 000000000..11ace80b5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/wirelessdevice.cpp @@ -0,0 +1,138 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wirelessdevice.h" + +#include + +WirelessDevice::WirelessDevice(QObject *parent) + : Device(parent) + , m_activeAccessPoint(QDBusObjectPath("/")) + , m_bitrate(0) + , m_mode(2) + , m_wirelessCapabilities(0) + , m_accessPointCounter(0) +{ +} + +WirelessDevice::~WirelessDevice() +{ + for (auto it = m_accessPoints.cbegin(); it != m_accessPoints.cend(); ++it) { + const QDBusObjectPath &ap = it.key(); + QDBusConnection::sessionBus().unregisterObject(ap.path()); + Q_EMIT AccessPointRemoved(ap); + } + + qDeleteAll(m_accessPoints); + + QVariantMap map; + map.insert(QLatin1String("AvailableConnections"), QVariant::fromValue>(QList())); + Q_EMIT PropertiesChanged(map); +} + +QList WirelessDevice::accessPoints() const +{ + return m_accessPoints.keys(); +} + +QDBusObjectPath WirelessDevice::activeAccessPoint() const +{ + return m_activeAccessPoint; +} + +uint WirelessDevice::bitrate() const +{ + return m_bitrate; +} + +QString WirelessDevice::hwAddress() const +{ + return m_hwAddress; +} + +uint WirelessDevice::mode() const +{ + return m_mode; +} + +QString WirelessDevice::permHwAddress() const +{ + return m_permHwAddress; +} + +uint WirelessDevice::wirelessCapabilities() const +{ + return m_wirelessCapabilities; +} + +void WirelessDevice::addAccessPoint(AccessPoint *accessPoint) +{ + QString newApPath = QString("/org/kde/fakenetwork/AccessPoints/") + QString::number(m_accessPointCounter++); + accessPoint->setAccessPointPath(newApPath); + m_accessPoints.insert(QDBusObjectPath(newApPath), accessPoint); + QDBusConnection::sessionBus().registerObject(newApPath, accessPoint, QDBusConnection::ExportScriptableContents); + + Q_EMIT AccessPointAdded(QDBusObjectPath(newApPath)); +} + +void WirelessDevice::removeAccessPoint(AccessPoint *accessPoint) +{ + m_accessPoints.remove(QDBusObjectPath(accessPoint->accessPointPath())); + + Q_EMIT AccessPointRemoved(QDBusObjectPath(accessPoint->accessPointPath())); +} + +void WirelessDevice::setActiveAccessPoint(const QString &activeAccessPoint) +{ + m_activeAccessPoint = QDBusObjectPath(activeAccessPoint); +} + +void WirelessDevice::setBitrate(uint bitrate) +{ + m_bitrate = bitrate; +} + +void WirelessDevice::setHwAddress(const QString &hwAddress) +{ + m_hwAddress = hwAddress; +} + +void WirelessDevice::setMode(uint mode) +{ + m_mode = mode; +} + +void WirelessDevice::setPermHwAddress(const QString &permHwAddress) +{ + m_permHwAddress = permHwAddress; +} + +void WirelessDevice::setState(uint state) +{ + Device::setState(state); + + // TODO: set speed, etc. +} + +void WirelessDevice::setWirelessCapabilities(uint capabilities) +{ + m_wirelessCapabilities = capabilities; +} + +QList WirelessDevice::GetAccessPoints() +{ + return m_accessPoints.keys(); +} + +QList WirelessDevice::GetAllAccessPoints() +{ + return m_accessPoints.keys(); +} + +void WirelessDevice::RequestScan(const QVariantMap &options) +{ + Q_UNUSED(options); +} diff --git a/panels/dock/tray/networkmanager-qt/src/fakenetwork/wirelessdevice.h b/panels/dock/tray/networkmanager-qt/src/fakenetwork/wirelessdevice.h new file mode 100644 index 000000000..d42bd28f3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/fakenetwork/wirelessdevice.h @@ -0,0 +1,78 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_FAKE_NETWORK_WIRELESS_DEVICE_H +#define NETWORKMANAGERQT_FAKE_NETWORK_WIRELESS_DEVICE_H + +#include + +#include + +#include "../device.h" +#include "../generictypes.h" + +#include "accesspoint.h" +#include "device.h" + +class WirelessDevice : public Device +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.fakenetwork.Device.Wireless") +public: + explicit WirelessDevice(QObject *parent = nullptr); + ~WirelessDevice() override; + + Q_PROPERTY(QList AccessPoints READ accessPoints) + Q_PROPERTY(QDBusObjectPath ActiveAccessPoint READ activeAccessPoint) + Q_PROPERTY(uint Bitrate READ bitrate) + Q_PROPERTY(QString HwAddress READ hwAddress) + Q_PROPERTY(uint Mode READ mode) + Q_PROPERTY(QString PermHwAddress READ permHwAddress) + Q_PROPERTY(uint WirelessCapabilities READ wirelessCapabilities) + + QList accessPoints() const; + QDBusObjectPath activeAccessPoint() const; + uint bitrate() const; + QString hwAddress() const; + uint mode() const; + QString permHwAddress() const; + uint wirelessCapabilities() const; + + /* Not part of DBus interface */ + void addAccessPoint(AccessPoint *accessPoint); + void removeAccessPoint(AccessPoint *accessPoint); + void setActiveAccessPoint(const QString &activeAccessPoint); + void setBitrate(uint bitrate); + void setHwAddress(const QString &hwAddress); + void setMode(uint mode); + void setPermHwAddress(const QString &permHwAddress); + void setState(uint state) override; + void setWirelessCapabilities(uint capabilities); + +public Q_SLOTS: + Q_SCRIPTABLE QList GetAccessPoints(); + Q_SCRIPTABLE QList GetAllAccessPoints(); + Q_SCRIPTABLE void RequestScan(const QVariantMap &options); + +Q_SIGNALS: + Q_SCRIPTABLE void AccessPointAdded(const QDBusObjectPath &access_point); + Q_SCRIPTABLE void AccessPointRemoved(const QDBusObjectPath &access_point); + Q_SCRIPTABLE void PropertiesChanged(const QVariantMap &properties); + +private: + QMap m_accessPoints; + QDBusObjectPath m_activeAccessPoint; + uint m_bitrate; + QString m_hwAddress; + uint m_mode; + QString m_permHwAddress; + uint m_wirelessCapabilities; + + /* Not part of DBus interface */ + int m_accessPointCounter; +}; + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/genericdevice.cpp b/panels/dock/tray/networkmanager-qt/src/genericdevice.cpp new file mode 100644 index 000000000..a2c1933d6 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/genericdevice.cpp @@ -0,0 +1,70 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "genericdevice_p.h" +#include "manager.h" +#include "nmdebug.h" + +NetworkManager::GenericDevicePrivate::GenericDevicePrivate(const QString &path, GenericDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::GenericDevicePrivate::~GenericDevicePrivate() +{ +} + +NetworkManager::GenericDevice::GenericDevice(const QString &path, QObject *parent) + : Device(*new NetworkManager::GenericDevicePrivate(path, this), parent) +{ + Q_D(GenericDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::GenericDevice::~GenericDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::GenericDevice::type() const +{ + return NetworkManager::Device::Generic; +} + +QString NetworkManager::GenericDevice::hardwareAddress() const +{ + Q_D(const GenericDevice); + return d->hwAddress; +} + +QString NetworkManager::GenericDevice::typeDescription() const +{ + Q_D(const GenericDevice); + return d->typeDescription; +} + +void NetworkManager::GenericDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(GenericDevice); + + if (property == QLatin1String("HwAddress")) { + hwAddress = value.toString(); + Q_EMIT q->hardwareAddressChanged(hwAddress); + } else if (property == QLatin1String("TypeDescription")) { + typeDescription = value.toString(); + Q_EMIT q->permanentHardwareAddressChanged(typeDescription); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/genericdevice.h b/panels/dock/tray/networkmanager-qt/src/genericdevice.h new file mode 100644 index 000000000..ff81acfa1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/genericdevice.h @@ -0,0 +1,61 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_GENERICDEVICE_H +#define NETWORKMANAGERQT_GENERICDEVICE_H + +#include + +#include "device.h" + +namespace NetworkManager +{ +class GenericDevicePrivate; + +/** + * A generic device interface + */ +class NETWORKMANAGERQT_EXPORT GenericDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(QString hardwareAddress READ hardwareAddress) + Q_PROPERTY(QString typeDescription READ typeDescription) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit GenericDevice(const QString &path, QObject *parent = nullptr); + ~GenericDevice() override; + /** + * Return the type + */ + Type type() const override; + /** + * Active hardware address of the device + */ + QString hardwareAddress() const; + /** + * A (non-localized) description of the interface type, if known. + */ + QString typeDescription() const; + +Q_SIGNALS: + /** + * Emitted when the hardware address of this device has changed + */ + void hardwareAddressChanged(const QString &hwAddress); + /** + * Emitted when the type description this device has changed + */ + void permanentHardwareAddressChanged(const QString &permHwAddress); + +private: + Q_DECLARE_PRIVATE(GenericDevice) +}; + +} + +#endif // NETWORKMANAGERQT_GENERICDEVICE_H diff --git a/panels/dock/tray/networkmanager-qt/src/genericdevice_p.h b/panels/dock/tray/networkmanager-qt/src/genericdevice_p.h new file mode 100644 index 000000000..cd7371ed3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/genericdevice_p.h @@ -0,0 +1,39 @@ +/* + SPDX-FileCopyrightText: 2012-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_GENERIC_DEVICE_P_H +#define NETWORKMANAGERQT_GENERIC_DEVICE_P_H + +#include "device_p.h" +#include "genericdevice.h" +#include "genericdeviceinterface.h" +#include "manager_p.h" + +namespace NetworkManager +{ +class GenericDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + GenericDevicePrivate(const QString &path, GenericDevice *q); + ~GenericDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceGenericInterface iface; + QString hwAddress; + QString typeDescription; + + Q_DECLARE_PUBLIC(GenericDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/generictypes.cpp b/panels/dock/tray/networkmanager-qt/src/generictypes.cpp new file mode 100644 index 000000000..1ced18252 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/generictypes.cpp @@ -0,0 +1,89 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "generictypes.h" + +QDBusArgument &operator<<(QDBusArgument &argument, const IpV6DBusAddress &address) +{ + argument.beginStructure(); + argument << address.address << address.prefix << address.gateway; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, IpV6DBusAddress &address) +{ + argument.beginStructure(); + argument >> address.address >> address.prefix >> address.gateway; + argument.endStructure(); + return argument; +} + +QDBusArgument &operator<<(QDBusArgument &argument, const IpV6DBusRoute &route) +{ + argument.beginStructure(); + argument << route.destination << route.prefix << route.nexthop << route.metric; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, IpV6DBusRoute &route) +{ + argument.beginStructure(); + argument >> route.destination >> route.prefix >> route.nexthop >> route.metric; + argument.endStructure(); + return argument; +} + +QDBusArgument &operator<<(QDBusArgument &argument, const NMStringMap &mydict) +{ + argument.beginMap(QMetaType::QString, QMetaType::QString); + + QMapIterator i(mydict); + while (i.hasNext()) { + i.next(); + argument.beginMapEntry(); + argument << i.key() << i.value(); + argument.endMapEntry(); + } + argument.endMap(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, NMStringMap &mydict) +{ + argument.beginMap(); + mydict.clear(); + + while (!argument.atEnd()) { + QString key; + QString value; + argument.beginMapEntry(); + argument >> key >> value; + argument.endMapEntry(); + mydict.insert(key, value); + } + + argument.endMap(); + return argument; +} + +QDBusArgument &operator<<(QDBusArgument &argument, const DeviceDBusStateReason &reason) +{ + argument.beginStructure(); + argument << reason.state << reason.reason; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceDBusStateReason &reason) +{ + argument.beginStructure(); + argument >> reason.state >> reason.reason; + argument.endStructure(); + return argument; +} diff --git a/panels/dock/tray/networkmanager-qt/src/generictypes.h b/panels/dock/tray/networkmanager-qt/src/generictypes.h new file mode 100644 index 000000000..d97652e4f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/generictypes.h @@ -0,0 +1,76 @@ +/* + This file is part of the KDE project + SPDX-FileCopyrightText: 2008 Will Stephenson + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef GENERIC_TYPES_H +#define GENERIC_TYPES_H + +#include + +#include +#include + +typedef QList> UIntListList; +Q_DECLARE_METATYPE(UIntListList) + +typedef QList UIntList; +Q_DECLARE_METATYPE(UIntList) + +typedef QMap NMVariantMapMap; +Q_DECLARE_METATYPE(NMVariantMapMap) + +typedef QList NMVariantMapList; +Q_DECLARE_METATYPE(NMVariantMapList) + +typedef QMap NMStringMap; +typedef QMapIterator NMStringMapIterator; +Q_DECLARE_METATYPE(NMStringMap) + +NETWORKMANAGERQT_EXPORT QDBusArgument &operator<<(QDBusArgument &argument, const NMStringMap &mydict); +NETWORKMANAGERQT_EXPORT const QDBusArgument &operator>>(const QDBusArgument &argument, NMStringMap &mydict); + +typedef struct { + QByteArray address; + uint prefix; + QByteArray gateway; +} IpV6DBusAddress; + +Q_DECLARE_METATYPE(IpV6DBusAddress) +typedef QList IpV6DBusAddressList; +Q_DECLARE_METATYPE(IpV6DBusAddressList) + +NETWORKMANAGERQT_EXPORT QDBusArgument &operator<<(QDBusArgument &argument, const IpV6DBusAddress &address); +NETWORKMANAGERQT_EXPORT const QDBusArgument &operator>>(const QDBusArgument &argument, IpV6DBusAddress &address); + +typedef struct { + QByteArray destination; + uint prefix; + QByteArray nexthop; + uint metric; +} IpV6DBusRoute; + +Q_DECLARE_METATYPE(IpV6DBusRoute) +typedef QList IpV6DBusRouteList; +Q_DECLARE_METATYPE(IpV6DBusRouteList) + +NETWORKMANAGERQT_EXPORT QDBusArgument &operator<<(QDBusArgument &argument, const IpV6DBusRoute &route); +NETWORKMANAGERQT_EXPORT const QDBusArgument &operator>>(const QDBusArgument &argument, IpV6DBusRoute &route); + +// ipv6 nameservers +typedef QList IpV6DBusNameservers; +Q_DECLARE_METATYPE(IpV6DBusNameservers) + +typedef struct { + uint state; + uint reason; +} DeviceDBusStateReason; +Q_DECLARE_METATYPE(DeviceDBusStateReason) + +NETWORKMANAGERQT_EXPORT QDBusArgument &operator<<(QDBusArgument &argument, const DeviceDBusStateReason &reason); +NETWORKMANAGERQT_EXPORT const QDBusArgument &operator>>(const QDBusArgument &argument, DeviceDBusStateReason &reason); + +#endif // GENERIC_TYPES_H diff --git a/panels/dock/tray/networkmanager-qt/src/gredevice.cpp b/panels/dock/tray/networkmanager-qt/src/gredevice.cpp new file mode 100644 index 000000000..564c757e7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/gredevice.cpp @@ -0,0 +1,144 @@ +/* + SPDX-FileCopyrightText: 2013 Lukáš Tinkl + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "device_p.h" +#include "gredevice_p.h" +#include "manager.h" + +NetworkManager::GreDevicePrivate::GreDevicePrivate(const QString &path, GreDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::GreDevicePrivate::~GreDevicePrivate() +{ +} + +NetworkManager::GreDevice::GreDevice(const QString &path, QObject *parent) + : Device(*new GreDevicePrivate(path, this), parent) +{ + Q_D(GreDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } + +} + +NetworkManager::GreDevice::~GreDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::GreDevice::type() const +{ + return NetworkManager::Device::Gre; +} + +ushort NetworkManager::GreDevice::inputFlags() const +{ + Q_D(const GreDevice); + return d->inputFlags; +} + +ushort NetworkManager::GreDevice::outputFlags() const +{ + Q_D(const GreDevice); + return d->outputFlags; +} + +uint NetworkManager::GreDevice::inputKey() const +{ + Q_D(const GreDevice); + return d->inputKey; +} + +uint NetworkManager::GreDevice::outputKey() const +{ + Q_D(const GreDevice); + return d->outputKey; +} + +QString NetworkManager::GreDevice::localEnd() const +{ + Q_D(const GreDevice); + return d->localEnd; +} + +QString NetworkManager::GreDevice::remoteEnd() const +{ + Q_D(const GreDevice); + return d->remoteEnd; +} + +QString NetworkManager::GreDevice::parent() const +{ + Q_D(const GreDevice); + return d->parent; +} + +bool NetworkManager::GreDevice::pathMtuDiscovery() const +{ + Q_D(const GreDevice); + return d->pathMtuDiscovery; +} + +uchar NetworkManager::GreDevice::tos() const +{ + Q_D(const GreDevice); + return d->tos; +} + +uchar NetworkManager::GreDevice::ttl() const +{ + Q_D(const GreDevice); + return d->ttl; +} + +void NetworkManager::GreDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(GreDevice); + + if (property == QLatin1String("InputFlags")) { + inputFlags = static_cast(value.toUInt()); + Q_EMIT q->inputFlagsChanged(inputFlags); + } else if (property == QLatin1String("OutputFlags")) { + outputFlags = static_cast(value.toUInt()); + Q_EMIT q->outputFlagsChanged(outputFlags); + } else if (property == QLatin1String("InputKey")) { + inputKey = value.toUInt(); + Q_EMIT q->inputKeyChanged(inputKey); + } else if (property == QLatin1String("OutputKey")) { + outputKey = value.toUInt(); + Q_EMIT q->outputKeyChanged(outputKey); + } else if (property == QLatin1String("Local")) { + localEnd = value.toString(); + Q_EMIT q->localEndChanged(localEnd); + } else if (property == QLatin1String("Remote")) { + remoteEnd = value.toString(); + Q_EMIT q->remoteEndChanged(remoteEnd); + } else if (property == QLatin1String("Parent")) { + parent = value.toString(); + Q_EMIT q->parentChanged(parent); + } else if (property == QLatin1String("PathMtuDiscovery")) { + pathMtuDiscovery = value.toBool(); + Q_EMIT q->pathMtuDiscoveryChanged(pathMtuDiscovery); + } else if (property == QLatin1String("Tos")) { + tos = static_cast(value.toUInt()); + Q_EMIT q->tosChanged(tos); + } else if (property == QLatin1String("Ttl")) { + ttl = static_cast(value.toUInt()); + Q_EMIT q->ttlChanged(ttl); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/gredevice.h b/panels/dock/tray/networkmanager-qt/src/gredevice.h new file mode 100644 index 000000000..7b9aa2a40 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/gredevice.h @@ -0,0 +1,73 @@ +/* + SPDX-FileCopyrightText: 2013 Lukáš Tinkl + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_GRE_DEVICE_H +#define NETWORKMANAGERQT_GRE_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class GreDevicePrivate; + +/** + * A gre device interface + * @deprecated renamed to IpTunnelDevice + */ +class NETWORKMANAGERQT_EXPORT GreDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(ushort inputFlags READ inputFlags NOTIFY inputFlagsChanged) + Q_PROPERTY(ushort outputFlags READ outputFlags NOTIFY outputFlagsChanged) + Q_PROPERTY(uint inputKey READ inputKey NOTIFY inputKeyChanged) + Q_PROPERTY(uint outputKey READ outputKey NOTIFY outputKeyChanged) + Q_PROPERTY(QString localEnd READ localEnd NOTIFY localEndChanged) + Q_PROPERTY(QString remoteEnd READ remoteEnd NOTIFY remoteEndChanged) + Q_PROPERTY(QString parent READ parent NOTIFY parentChanged) + Q_PROPERTY(bool pathMtuDiscovery READ pathMtuDiscovery NOTIFY pathMtuDiscoveryChanged) + Q_PROPERTY(uchar tos READ tos NOTIFY tosChanged) + Q_PROPERTY(uchar ttl READ ttl NOTIFY ttlChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit GreDevice(const QString &path, QObject *parent = nullptr); + ~GreDevice() override; + + Type type() const override; + + ushort inputFlags() const; + ushort outputFlags() const; + uint inputKey() const; + uint outputKey() const; + QString localEnd() const; + QString remoteEnd() const; + QString parent() const; + bool pathMtuDiscovery() const; + uchar tos() const; + uchar ttl() const; + +Q_SIGNALS: + void inputFlagsChanged(ushort inputflags); + void outputFlagsChanged(ushort outputFlags); + void inputKeyChanged(uint inputKey); + void outputKeyChanged(uint outputKey); + void localEndChanged(const QString &localEnd); + void remoteEndChanged(const QString &remoteEnd); + void parentChanged(const QString &parent); + void pathMtuDiscoveryChanged(bool pathMtuDiscovery); + void tosChanged(uchar tos); + void ttlChanged(uchar ttl); + +private: + Q_DECLARE_PRIVATE(GreDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/gredevice_p.h b/panels/dock/tray/networkmanager-qt/src/gredevice_p.h new file mode 100644 index 000000000..26f4b4742 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/gredevice_p.h @@ -0,0 +1,49 @@ +/* + SPDX-FileCopyrightText: 2012-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_GRE_DEVICE_P_H +#define NETWORKMANAGERQT_GRE_DEVICE_P_H + +#include "device_p.h" +#include "gredevice.h" +#include "manager.h" +#include "manager_p.h" + +#include "gredeviceinterface.h" + +namespace NetworkManager +{ +class GreDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + GreDevicePrivate(const QString &path, GreDevice *q); + ~GreDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceGreInterface iface; + ushort inputFlags; + ushort outputFlags; + uint inputKey; + uint outputKey; + QString localEnd; + QString remoteEnd; + QString parent; + bool pathMtuDiscovery; + uchar tos; + uchar ttl; + + Q_DECLARE_PUBLIC(GreDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/infinibanddevice.cpp b/panels/dock/tray/networkmanager-qt/src/infinibanddevice.cpp new file mode 100644 index 000000000..75c3b6288 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/infinibanddevice.cpp @@ -0,0 +1,74 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "device_p.h" +#include "infinibanddevice_p.h" +#include "manager.h" + +NetworkManager::InfinibandDevicePrivate::InfinibandDevicePrivate(const QString &path, InfinibandDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , carrier(false) +{ +} + +NetworkManager::InfinibandDevice::~InfinibandDevice() +{ +} + +NetworkManager::InfinibandDevice::InfinibandDevice(const QString &path, QObject *parent) + : Device(*new InfinibandDevicePrivate(path, this), parent) +{ + Q_D(InfinibandDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::InfinibandDevicePrivate::~InfinibandDevicePrivate() +{ +} + +NetworkManager::Device::Type NetworkManager::InfinibandDevice::type() const +{ + return NetworkManager::Device::InfiniBand; +} + +bool NetworkManager::InfinibandDevice::carrier() const +{ + Q_D(const InfinibandDevice); + + return d->carrier; +} + +QString NetworkManager::InfinibandDevice::hwAddress() const +{ + Q_D(const InfinibandDevice); + + return d->hwAddress; +} + +void NetworkManager::InfinibandDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(InfinibandDevice); + + if (property == QLatin1String("Carrier")) { + carrier = value.toBool(); + Q_EMIT q->carrierChanged(carrier); + } else if (property == QLatin1String("HwAddress")) { + hwAddress = value.toString(); + Q_EMIT q->hwAddressChanged(hwAddress); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/infinibanddevice.h b/panels/dock/tray/networkmanager-qt/src/infinibanddevice.h new file mode 100644 index 000000000..da89e99eb --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/infinibanddevice.h @@ -0,0 +1,59 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_INFINIBAND_DEVICE_H +#define NETWORKMANAGERQT_INFINIBAND_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class InfinibandDevicePrivate; + +/** + * An infiniband device interface + */ +class NETWORKMANAGERQT_EXPORT InfinibandDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(bool carrier READ carrier NOTIFY carrierChanged) + Q_PROPERTY(QString hwAddress READ hwAddress NOTIFY hwAddressChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit InfinibandDevice(const QString &path, QObject *parent = nullptr); + ~InfinibandDevice() override; + + Type type() const override; + + /** + * Indicates whether the physical carrier is found + */ + bool carrier() const; + /** + * Hardware address of the device + */ + QString hwAddress() const; + +Q_SIGNALS: + /** + * Emitted when the carrier of this device has changed + */ + void carrierChanged(bool plugged); + /** + * Emitted when the hardware address of this device has changed + */ + void hwAddressChanged(const QString &address); + +private: + Q_DECLARE_PRIVATE(InfinibandDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/infinibanddevice_p.h b/panels/dock/tray/networkmanager-qt/src/infinibanddevice_p.h new file mode 100644 index 000000000..7d2fdb550 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/infinibanddevice_p.h @@ -0,0 +1,39 @@ +/* + SPDX-FileCopyrightText: 2012-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_INFINIBAND_DEVICE_P_H +#define NETWORKMANAGERQT_INFINIBAND_DEVICE_P_H + +#include "device_p.h" +#include "infinibanddevice.h" +#include "infinibanddeviceinterface.h" +#include "manager_p.h" + +namespace NetworkManager +{ +class InfinibandDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + InfinibandDevicePrivate(const QString &path, InfinibandDevice *q); + ~InfinibandDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceInfinibandInterface iface; + bool carrier; + QString hwAddress; + + Q_DECLARE_PUBLIC(InfinibandDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/ipaddress.cpp b/panels/dock/tray/networkmanager-qt/src/ipaddress.cpp new file mode 100644 index 000000000..5ec6cbe69 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/ipaddress.cpp @@ -0,0 +1,62 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ipaddress.h" + +namespace NetworkManager +{ +class IpAddress::Private +{ +public: + QHostAddress gateway; +}; + +} + +NetworkManager::IpAddress::IpAddress() + : d(new Private) +{ +} + +NetworkManager::IpAddress::~IpAddress() +{ + delete d; +} + +NetworkManager::IpAddress::IpAddress(const NetworkManager::IpAddress &other) + : QNetworkAddressEntry(other) + , d(new Private) +{ + *this = other; +} + +bool NetworkManager::IpAddress::isValid() const +{ + return !ip().isNull(); +} + +void NetworkManager::IpAddress::setGateway(const QHostAddress &gateway) +{ + d->gateway = gateway; +} + +QHostAddress NetworkManager::IpAddress::gateway() const +{ + return d->gateway; +} + +NetworkManager::IpAddress &NetworkManager::IpAddress::operator=(const NetworkManager::IpAddress &other) +{ + if (this == &other) { + return *this; + } + + QNetworkAddressEntry::operator=(other); + *d = *other.d; + + return *this; +} diff --git a/panels/dock/tray/networkmanager-qt/src/ipaddress.h b/panels/dock/tray/networkmanager-qt/src/ipaddress.h new file mode 100644 index 000000000..8936ca946 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/ipaddress.h @@ -0,0 +1,66 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPADDRESS_H +#define NETWORKMANAGERQT_IPADDRESS_H + +#include + +#include + +namespace NetworkManager +{ +/** + * This class represents IP address + */ +class NETWORKMANAGERQT_EXPORT IpAddress : public QNetworkAddressEntry +{ +public: + /** + * Constructs an empty IpAddress object. + */ + IpAddress(); + + /** + * Constructs an IpAddress object that is a copy of the object other. + */ + IpAddress(const IpAddress &other); + + /** + * Destroys this IpAddress object. + */ + ~IpAddress(); + + /** + * Return if the IP address is defined. + */ + bool isValid() const; + + /** + * Defines the default @p gateway of this object. + */ + void setGateway(const QHostAddress &gateway); + + /** + * Returns the default gateway of this object. + */ + QHostAddress gateway() const; + + /** + * Makes a copy of the IpAddress object @p other. + */ + IpAddress &operator=(const IpAddress &other); + +private: + class Private; + Private *const d; +}; +typedef QList IpAddresses; + +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_IPADDRESS_H diff --git a/panels/dock/tray/networkmanager-qt/src/ipconfig.cpp b/panels/dock/tray/networkmanager-qt/src/ipconfig.cpp new file mode 100644 index 000000000..799746854 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/ipconfig.cpp @@ -0,0 +1,303 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ipconfig.h" + +#include "manager.h" +#include "manager_p.h" + +#include + +#include "dbus/ip4configinterface.h" +#include "dbus/ip6configinterface.h" + +namespace NetworkManager +{ +class NetworkManager::IpConfig::Private +{ +public: + Private(const QList &theAddresses, const QList &theNameservers, const QStringList &theDomains, const QList &theRoutes) + : addresses(theAddresses) + , nameservers(theNameservers) + , domains(theDomains) + , routes(theRoutes) + { + } + Private() + { + } + IpAddresses addresses; + QString gateway; + QStringList searches; + QList nameservers; + QStringList domains; + IpRoutes routes; + QStringList dnsOptions; +}; + +} + +NetworkManager::IpConfig::IpConfig(const IpAddresses &addresses, const QList &nameservers, const QStringList &domains, const IpRoutes &routes) + : d(new Private(addresses, nameservers, domains, routes)) +{ +} + +NetworkManager::IpConfig::IpConfig() + : d(new Private()) +{ +} + +NetworkManager::IpConfig::IpConfig(const IpConfig &other) + : d(new Private) +{ + *this = other; +} + +void NetworkManager::IpConfig::setIPv4Path(const QString &path) +{ + OrgFreedesktopNetworkManagerIP4ConfigInterface iface(NetworkManagerPrivate::DBUS_SERVICE, + path, +#ifdef NMQT_STATIC + QDBusConnection::sessionBus()); +#else + QDBusConnection::systemBus()); +#endif + // TODO - watch propertiesChanged signal + + QList addressObjects; + QList routeObjects; + if (NetworkManager::checkVersion(1, 0, 0)) { + const NMVariantMapList addresses = iface.addressData(); + for (const QVariantMap &addressList : addresses) { + if (addressList.contains(QLatin1String("address")) // + && addressList.contains(QLatin1String("prefix"))) { + NetworkManager::IpAddress address; + address.setIp(QHostAddress(addressList.value(QLatin1String("address")).toString())); + address.setPrefixLength(addressList.value(QLatin1String("prefix")).toUInt()); + if (addressList.contains(QLatin1String("gateway"))) { + address.setGateway(QHostAddress(addressList.value(QLatin1String("gateway")).toString())); + } + addressObjects << address; + } + } + + const NMVariantMapList routes = iface.routeData(); + for (const QVariantMap &routeList : routes) { + if (routeList.contains(QLatin1String("address")) && routeList.contains(QLatin1String("prefix"))) { + NetworkManager::IpRoute route; + route.setIp(QHostAddress(routeList.value(QLatin1String("address")).toString())); + route.setPrefixLength(routeList.value(QLatin1String("prefix")).toUInt()); + if (routeList.contains(QLatin1String("next-hop"))) { + route.setNextHop(QHostAddress(routeList.value(QLatin1String("next-hop")).toString())); + } + + if (routeList.contains(QLatin1String("metric"))) { + route.setMetric(routeList.value(QLatin1String("metric")).toUInt()); + } + routeObjects << route; + } + } + } else { + // convert ipaddresses into object + const UIntListList addresses = iface.addresses(); + for (const UIntList &addressList : addresses) { + if (addressList.count() == 3) { + NetworkManager::IpAddress address; + address.setIp(QHostAddress(ntohl(addressList[0]))); + address.setPrefixLength(addressList[1]); + address.setGateway(QHostAddress(ntohl(addressList[2]))); + addressObjects << address; + } + } + // convert routes into objects + const UIntListList routes = iface.routes(); + for (const UIntList &routeList : routes) { + if (routeList.count() == 4) { + NetworkManager::IpRoute route; + route.setIp(QHostAddress(ntohl(routeList[0]))); + route.setPrefixLength(routeList[1]); + route.setNextHop(QHostAddress(ntohl(routeList[2]))); + route.setMetric(ntohl(routeList[3])); + routeObjects << route; + } + } + } + // nameservers' IP addresses are always in network byte order + QList nameservers; + const QList ifaceNameservers = iface.nameservers(); + for (uint nameserver : ifaceNameservers) { + nameservers << QHostAddress(ntohl(nameserver)); + } + + d->addresses = addressObjects; + d->routes = routeObjects; + d->nameservers = nameservers; + d->gateway = iface.gateway(); + d->searches = iface.searches(); + d->domains = iface.domains(); + if (NetworkManager::checkVersion(1, 2, 0)) { + d->dnsOptions = iface.dnsOptions(); + } +} + +void NetworkManager::IpConfig::setIPv6Path(const QString &path) +{ + // ask the daemon for the details + OrgFreedesktopNetworkManagerIP6ConfigInterface iface(NetworkManagerPrivate::DBUS_SERVICE, + path, +#ifdef NMQT_STATIC + QDBusConnection::sessionBus()); +#else + QDBusConnection::systemBus()); +#endif + // TODO - watch propertiesChanged signal + + QList addressObjects; + QList routeObjects; + if (NetworkManager::checkVersion(1, 0, 0)) { + const NMVariantMapList addresses = iface.addressData(); + for (const QVariantMap &addressList : addresses) { + if (addressList.contains(QLatin1String("address")) // + && addressList.contains(QLatin1String("prefix"))) { + NetworkManager::IpAddress address; + address.setIp(QHostAddress(addressList.value(QLatin1String("address")).toString())); + address.setPrefixLength(addressList.value(QLatin1String("prefix")).toUInt()); + if (addressList.contains(QLatin1String("gateway"))) { + address.setGateway(QHostAddress(addressList.value(QLatin1String("gateway")).toString())); + } + addressObjects << address; + } + } + + const NMVariantMapList routes = iface.routeData(); + for (const QVariantMap &routeList : routes) { + if (routeList.contains(QLatin1String("address")) && routeList.contains(QLatin1String("prefix"))) { + NetworkManager::IpRoute route; + route.setIp(QHostAddress(routeList.value(QLatin1String("address")).toString())); + route.setPrefixLength(routeList.value(QLatin1String("prefix")).toUInt()); + if (routeList.contains(QLatin1String("next-hop"))) { + route.setNextHop(QHostAddress(routeList.value(QLatin1String("next-hop")).toString())); + } + + if (routeList.contains(QLatin1String("metric"))) { + route.setMetric(routeList.value(QLatin1String("metric")).toUInt()); + } + routeObjects << route; + } + } + } else { + const IpV6DBusAddressList addresses = iface.addresses(); + for (const IpV6DBusAddress &address : addresses) { + Q_IPV6ADDR addr; + Q_IPV6ADDR gateway; + for (int i = 0; i < 16; i++) { + addr[i] = address.address[i]; + } + for (int i = 0; i < 16; i++) { + gateway[i] = address.gateway[i]; + } + NetworkManager::IpAddress addressEntry; + addressEntry.setIp(QHostAddress(addr)); + addressEntry.setPrefixLength(address.prefix); + addressEntry.setGateway(QHostAddress(gateway)); + addressObjects << addressEntry; + } + + const IpV6DBusRouteList routes = iface.routes(); + for (const IpV6DBusRoute &route : routes) { + Q_IPV6ADDR dest; + Q_IPV6ADDR nexthop; + for (int i = 0; i < 16; i++) { + dest[i] = route.destination[i]; + } + for (int i = 0; i < 16; i++) { + nexthop[i] = route.nexthop[i]; + } + NetworkManager::IpRoute routeEntry; + routeEntry.setIp(QHostAddress(dest)); + routeEntry.setPrefixLength(route.prefix); + routeEntry.setNextHop(QHostAddress(nexthop)); + routeEntry.setMetric(route.metric); + routeObjects << routeEntry; + } + } + + QList nameservers; + const QList ifaceNservers = iface.nameservers(); + for (const QByteArray &nameserver : ifaceNservers) { + Q_IPV6ADDR address; + for (int i = 0; i < 16; i++) { + address[i] = static_cast(nameserver[i]); + } + nameservers << QHostAddress(address); + } + + d->addresses = addressObjects; + d->routes = routeObjects; + d->nameservers = nameservers; + d->gateway = iface.gateway(); + d->searches = iface.searches(); + d->domains = iface.domains(); + if (NetworkManager::checkVersion(1, 2, 0)) { + d->dnsOptions = iface.dnsOptions(); + } +} + +NetworkManager::IpConfig::~IpConfig() +{ + delete d; +} + +NetworkManager::IpAddresses NetworkManager::IpConfig::addresses() const +{ + return d->addresses; +} + +QString NetworkManager::IpConfig::gateway() const +{ + return d->gateway; +} + +QList NetworkManager::IpConfig::nameservers() const +{ + return d->nameservers; +} + +QStringList NetworkManager::IpConfig::domains() const +{ + return d->domains; +} + +QList NetworkManager::IpConfig::routes() const +{ + return d->routes; +} + +QStringList NetworkManager::IpConfig::searches() const +{ + return d->searches; +} + +QStringList NetworkManager::IpConfig::dnsOptions() const +{ + return d->dnsOptions; +} + +NetworkManager::IpConfig &NetworkManager::IpConfig::operator=(const IpConfig &other) +{ + if (this == &other) { + return *this; + } + + *d = *other.d; + return *this; +} + +bool NetworkManager::IpConfig::isValid() const +{ + return !d->addresses.isEmpty(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/ipconfig.h b/panels/dock/tray/networkmanager-qt/src/ipconfig.h new file mode 100644 index 000000000..7fbe129a5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/ipconfig.h @@ -0,0 +1,120 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPCONFIG_H +#define NETWORKMANAGERQT_IPCONFIG_H + +#include "ipaddress.h" +#include "iproute.h" +#include + +// To prevent signals in glib2 be defined by QT +#undef signals +#include +#define signals Q_SIGNALS + +#include + +namespace NetworkManager +{ +/** + * This class represents IP configuration + */ +class NETWORKMANAGERQT_EXPORT IpConfig +{ +public: + /** + * Constructs an IP config object with a list of @p addresses, @p nameservers, @p domains and @p routes. + */ + IpConfig(const IpAddresses &addresses, const QList &nameservers, const QStringList &domains, const IpRoutes &routes); + + /** + * Constructs an empty IpConfig object. + */ + IpConfig(); + + /** + * Destroys this IpConfig object. + */ + ~IpConfig(); + + /** + * Constructs an IpConfig object that is a copy of the object @p other. + */ + IpConfig(const IpConfig &other); + + /** + * Configure this class using the information on the following @p path + */ + void setIPv4Path(const QString &path); + + /** + * Configure this class using the information on the following @p path + */ + void setIPv6Path(const QString &path); + + /** + * Returns a list of IP addresses and gateway related to this configuration. + * Use IpAddress::ip() to access the IP address and IpAddress::gateway() + * to access the gateway address. + */ + NetworkManager::IpAddresses addresses() const; + + /** + * Returns a list of domains related to this configuration. + */ + QStringList domains() const; + + /** + * Returns the gateway in use + * + * @since 0.9.9.0 + */ + QString gateway() const; + + /** + * Returns a list of nameservers related to this configuration. + */ + QList nameservers() const; + + /** + * Returns a list of static routes (not the default gateway) related to this configuration. + * Use @ref addresses() to retrieve the default gateway. + */ + IpRoutes routes() const; + + /** + * Returns a list of DNS searches. + * + * @since 0.9.9.0 + */ + QStringList searches() const; + + /** + * Returns a list of DNS options that modify the behaviour of the DNS resolver. + * @since 5.14.0 + */ + QStringList dnsOptions() const; + + /** + * Makes a copy of the IpConfig object @p other. + */ + IpConfig &operator=(const IpConfig &other); + + /** + * Returns false if the list of IP addresses is empty + */ + bool isValid() const; + +private: + class Private; + Private *const d; +}; + +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_IPCONFIG_H diff --git a/panels/dock/tray/networkmanager-qt/src/iproute.cpp b/panels/dock/tray/networkmanager-qt/src/iproute.cpp new file mode 100644 index 000000000..7d113a434 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/iproute.cpp @@ -0,0 +1,77 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ipconfig.h" + +namespace NetworkManager +{ +class NetworkManager::IpRoute::Private +{ +public: + Private() + : metric(0) + { + } + QHostAddress nextHop; + quint32 metric; +}; + +} + +NetworkManager::IpRoute::IpRoute() + : d(new Private) +{ +} + +NetworkManager::IpRoute::~IpRoute() +{ + delete d; +} + +NetworkManager::IpRoute::IpRoute(const NetworkManager::IpRoute &other) + : QNetworkAddressEntry(other) + , d(new Private) +{ + *this = other; +} + +void NetworkManager::IpRoute::setNextHop(const QHostAddress &nextHop) const +{ + d->nextHop = nextHop; +} + +QHostAddress NetworkManager::IpRoute::nextHop() const +{ + return d->nextHop; +} + +void NetworkManager::IpRoute::setMetric(quint32 metric) +{ + d->metric = metric; +} + +quint32 NetworkManager::IpRoute::metric() const +{ + return d->metric; +} + +NetworkManager::IpRoute &NetworkManager::IpRoute::operator=(const NetworkManager::IpRoute &other) +{ + if (this == &other) { + return *this; + } + + QNetworkAddressEntry::operator=(other); + *d = *other.d; + + return *this; +} + +bool NetworkManager::IpRoute::isValid() const +{ + return !ip().isNull(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/iproute.h b/panels/dock/tray/networkmanager-qt/src/iproute.h new file mode 100644 index 000000000..74002e025 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/iproute.h @@ -0,0 +1,78 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPROUTE_H +#define NETWORKMANAGERQT_IPROUTE_H + +#include "ipaddress.h" +#include + +#include + +namespace NetworkManager +{ +/** + * This class represents IP route + */ +class NETWORKMANAGERQT_EXPORT IpRoute : public QNetworkAddressEntry +{ +public: + /** + * Constructs an empty IpRoute object. + */ + IpRoute(); + + /** + * Constructs an IpRoute object that is a copy of the object @p other. + */ + IpRoute(const IpRoute &other); + + /** + * Destroys this IpRoute object. + */ + ~IpRoute(); + + /** + * Returns true if the route IP is defined. + */ + bool isValid() const; + + /** + * Defines the next hop of the given route. + */ + void setNextHop(const QHostAddress &nextHop) const; + + /** + * Returns the next hop of the given route. + */ + QHostAddress nextHop() const; + + /** + * Defines the @p metric of the given route, + * lower values have higher priority. + */ + void setMetric(quint32 metric); + + /** + * Returns the route metric number of the given route. + */ + quint32 metric() const; + + /** + * Makes a copy of the IpRoute object @p other. + */ + IpRoute &operator=(const IpRoute &other); + +private: + class Private; + Private *const d; +}; +typedef QList IpRoutes; + +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_IPROUTE_H diff --git a/panels/dock/tray/networkmanager-qt/src/iptunneldevice.cpp b/panels/dock/tray/networkmanager-qt/src/iptunneldevice.cpp new file mode 100644 index 000000000..5c081bbdb --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/iptunneldevice.cpp @@ -0,0 +1,152 @@ +/* + SPDX-FileCopyrightText: 2017 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "device_p.h" +#include "iptunneldevice_p.h" +#include "manager.h" + +NetworkManager::IpTunnelDevicePrivate::IpTunnelDevicePrivate(const QString &path, IpTunnelDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::IpTunnelDevicePrivate::~IpTunnelDevicePrivate() +{ +} + +NetworkManager::IpTunnelDevice::IpTunnelDevice(const QString &path, QObject *parent) + : Device(*new IpTunnelDevicePrivate(path, this), parent) +{ + Q_D(IpTunnelDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } + +} + +NetworkManager::IpTunnelDevice::~IpTunnelDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::IpTunnelDevice::type() const +{ + return NetworkManager::Device::IpTunnel; +} + +uchar NetworkManager::IpTunnelDevice::encapsulationLimit() const +{ + Q_D(const IpTunnelDevice); + return d->encapsulationLimit; +} + +uint NetworkManager::IpTunnelDevice::flowLabel() const +{ + Q_D(const IpTunnelDevice); + return d->flowLabel; +} + +QString NetworkManager::IpTunnelDevice::inputKey() const +{ + Q_D(const IpTunnelDevice); + return d->inputKey; +} + +QString NetworkManager::IpTunnelDevice::local() const +{ + Q_D(const IpTunnelDevice); + return d->local; +} + +uint NetworkManager::IpTunnelDevice::mode() const +{ + Q_D(const IpTunnelDevice); + return d->mode; +} + +QString NetworkManager::IpTunnelDevice::outputKey() const +{ + Q_D(const IpTunnelDevice); + return d->outputKey; +} + +NetworkManager::Device::Ptr NetworkManager::IpTunnelDevice::parent() const +{ + Q_D(const IpTunnelDevice); + return NetworkManager::findNetworkInterface(d->parent); +} + +bool NetworkManager::IpTunnelDevice::pathMtuDiscovery() const +{ + Q_D(const IpTunnelDevice); + return d->pathMtuDiscovery; +} + +QString NetworkManager::IpTunnelDevice::remote() const +{ + Q_D(const IpTunnelDevice); + return d->remote; +} + +uchar NetworkManager::IpTunnelDevice::tos() const +{ + Q_D(const IpTunnelDevice); + return d->tos; +} + +uchar NetworkManager::IpTunnelDevice::ttl() const +{ + Q_D(const IpTunnelDevice); + return d->ttl; +} + +void NetworkManager::IpTunnelDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(IpTunnelDevice); + + if (property == QLatin1String("EncapsulationLimit")) { + encapsulationLimit = static_cast(value.toUInt()); + Q_EMIT q->encapsulationLimitChanged(encapsulationLimit); + } else if (property == QLatin1String("FlowLabel")) { + flowLabel = value.toUInt(); + Q_EMIT q->flowLabelChanged(flowLabel); + } else if (property == QLatin1String("InputKey")) { + inputKey = value.toString(); + Q_EMIT q->inputKeyChanged(inputKey); + } else if (property == QLatin1String("Local")) { + local = value.toString(); + Q_EMIT q->localChanged(local); + } else if (property == QLatin1String("Mode")) { + mode = value.toUInt(); + Q_EMIT q->modeChanged(mode); + } else if (property == QLatin1String("OutputKey")) { + outputKey = value.toString(); + Q_EMIT q->outputKeyChanged(outputKey); + } else if (property == QLatin1String("Parent")) { + parent = value.toString(); + Q_EMIT q->parentChanged(parent); + } else if (property == QLatin1String("PathMtuDiscovery")) { + pathMtuDiscovery = value.toBool(); + Q_EMIT q->pathMtuDiscoveryChanged(pathMtuDiscovery); + } else if (property == QLatin1String("Remote")) { + remote = value.toString(); + Q_EMIT q->remoteChanged(remote); + } else if (property == QLatin1String("Tos")) { + tos = static_cast(value.toUInt()); + Q_EMIT q->tosChanged(tos); + } else if (property == QLatin1String("Ttl")) { + ttl = static_cast(value.toUInt()); + Q_EMIT q->ttlChanged(ttl); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/iptunneldevice.h b/panels/dock/tray/networkmanager-qt/src/iptunneldevice.h new file mode 100644 index 000000000..04236abb4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/iptunneldevice.h @@ -0,0 +1,141 @@ +/* + SPDX-FileCopyrightText: 2017 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPTUNNEL_DEVICE_H +#define NETWORKMANAGERQT_IPTUNNEL_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class IpTunnelDevicePrivate; + +/** + * A Ip Tunnel device interface + */ +class NETWORKMANAGERQT_EXPORT IpTunnelDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(uchar encapsulationLimit READ encapsulationLimit NOTIFY encapsulationLimitChanged) + Q_PROPERTY(uint flowLabel READ flowLabel NOTIFY flowLabelChanged) + Q_PROPERTY(QString inputKey READ inputKey NOTIFY inputKeyChanged) + Q_PROPERTY(QString local READ local NOTIFY localChanged) + Q_PROPERTY(uint mode READ mode NOTIFY modeChanged) + Q_PROPERTY(QString outputKey READ outputKey NOTIFY outputKeyChanged) + Q_PROPERTY(NetworkManager::Device::Ptr parent READ parent NOTIFY parentChanged) + Q_PROPERTY(bool pathMtuDiscovery READ pathMtuDiscovery NOTIFY pathMtuDiscoveryChanged) + Q_PROPERTY(QString remote READ remote NOTIFY remoteChanged) + Q_PROPERTY(uchar tos READ tos NOTIFY tosChanged) + Q_PROPERTY(uchar ttl READ ttl NOTIFY ttlChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit IpTunnelDevice(const QString &path, QObject *parent = nullptr); + ~IpTunnelDevice() override; + + Type type() const override; + + /** + * How many additional levels of encapsulation are permitted to be prepended to packets. + * This property applies only to IPv6 tunnels. + */ + uchar encapsulationLimit() const; + /** + * The flow label to assign to tunnel packets. This property applies only to IPv6 tunnels. + */ + uint flowLabel() const; + /** + * The key used for incoming packets. + */ + QString inputKey() const; + /** + * The local endpoint of the tunnel. + */ + QString local() const; + /** + * The tunneling mode. + */ + uint mode() const; + /** + * The key used for outgoing packets. + */ + QString outputKey() const; + /** + * The object path of the parent device. + */ + NetworkManager::Device::Ptr parent() const; + /** + * Whether path MTU discovery is enabled on this tunnel. + */ + bool pathMtuDiscovery() const; + /** + * The remote endpoint of the tunnel. + */ + QString remote() const; + /** + * The type of service (IPv4) or traffic class (IPv6) assigned to tunneled packets. + */ + uchar tos() const; + /** + * The TTL assigned to tunneled packets. 0 is a special value meaning that packets inherit the TTL value + */ + uchar ttl() const; + +Q_SIGNALS: + /** + * Emitted when the encapsulation limit has changed + */ + void encapsulationLimitChanged(uchar limit); + /** + * Emitted when the flow label has changed + */ + void flowLabelChanged(uint flowLabel); + /** + * Emitted when the key used for incoming packets has changed + */ + void inputKeyChanged(const QString &inputKey); + /** + * Emitted when the local endpoint of the tunnel has changed + */ + void localChanged(const QString &local); + /** + * Emitted when the tunneling mode has changed + */ + void modeChanged(uint mode); + /** + * Emitted when the key used for outgoing packets has changed + */ + void outputKeyChanged(const QString &outputKey); + /** + * Emitted when the parent of this device has changed + */ + void parentChanged(const QString &parent); + /** + * Emitted when the path MTU discovery enablemened has changed + */ + void pathMtuDiscoveryChanged(bool pathMtuDiscovery); + /** + * Emitted when the remote endpoint of the tunnel has changed + */ + void remoteChanged(const QString &remote); + /** + * Emitted when the type of service or traffic class assigned to tunneled packets has changed + */ + void tosChanged(uchar tos); + /** + * Emitted when the TTL assigned to tunneled packets has changed + */ + void ttlChanged(uchar ttl); + +private: + Q_DECLARE_PRIVATE(IpTunnelDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/iptunneldevice_p.h b/panels/dock/tray/networkmanager-qt/src/iptunneldevice_p.h new file mode 100644 index 000000000..1ec0caf25 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/iptunneldevice_p.h @@ -0,0 +1,50 @@ +/* + SPDX-FileCopyrightText: 2017 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPTUNNEL_DEVICE_P_H +#define NETWORKMANAGERQT_IPTUNNEL_DEVICE_P_H + +#include "device_p.h" +#include "iptunneldevice.h" +#include "manager.h" +#include "manager_p.h" + +#include "iptunneldeviceinterface.h" + +namespace NetworkManager +{ +class IpTunnelDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + IpTunnelDevicePrivate(const QString &path, IpTunnelDevice *q); + ~IpTunnelDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceIPTunnelInterface iface; + uchar encapsulationLimit; + uint flowLabel; + QString inputKey; + QString local; + uint mode; + QString outputKey; + QString parent; + bool pathMtuDiscovery; + QString remote; + uchar tos; + uchar ttl; + + Q_DECLARE_PUBLIC(IpTunnelDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/macros.h b/panels/dock/tray/networkmanager-qt/src/macros.h new file mode 100644 index 000000000..1361dbbd0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/macros.h @@ -0,0 +1,74 @@ +/* + SPDX-FileCopyrightText: 2011 Will Stephenson + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_MACROS_H +#define NETWORKMANAGERQT_MACROS_H + +#define NM_GLOBAL_STATIC_STRUCT_NAME(NAME) +typedef void (*NmCleanUpFunction)(); +class NmCleanUpGlobalStatic +{ +public: + NmCleanUpFunction func; + + inline ~NmCleanUpGlobalStatic() + { + func(); + } +}; + +#define NM_GLOBAL_STATIC(TYPE, NAME) NM_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ()) + +/* clang-format off */ +#define NM_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \ + static QBasicAtomicPointer _nm_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0); \ + static bool _nm_static_##NAME##_destroyed; \ + static struct NM_GLOBAL_STATIC_STRUCT_NAME(NAME) \ + { \ + inline bool isDestroyed() const \ + { \ + return _nm_static_##NAME##_destroyed; \ + } \ + inline bool exists() const \ + { \ + return _nm_static_##NAME != 0; \ + } \ + inline operator TYPE*() \ + { \ + return operator->(); \ + } \ + inline TYPE *operator->() \ + { \ + if (!_nm_static_##NAME) { \ + if (isDestroyed()) { \ + qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \ + "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \ + } \ + TYPE *x = new TYPE ARGS; \ + if (!_nm_static_##NAME.testAndSetOrdered(0, x) \ + && _nm_static_##NAME != x ) { \ + delete x; \ + } else { \ + static NmCleanUpGlobalStatic cleanUpObject = { destroy }; \ + } \ + } \ + return _nm_static_##NAME; \ + } \ + inline TYPE &operator*() \ + { \ + return *operator->(); \ + } \ + static void destroy() \ + { \ + _nm_static_##NAME##_destroyed = true; \ + TYPE *x = _nm_static_##NAME; \ + _nm_static_##NAME = 0; \ + delete x; \ + } \ + } NAME; +/* clang-format on */ + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/macvlandevice.cpp b/panels/dock/tray/networkmanager-qt/src/macvlandevice.cpp new file mode 100644 index 000000000..75380f3d2 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/macvlandevice.cpp @@ -0,0 +1,79 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "device_p.h" +#include "macvlandevice_p.h" +#include "manager.h" + +NetworkManager::MacVlanDevicePrivate::MacVlanDevicePrivate(const QString &path, MacVlanDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::MacVlanDevicePrivate::~MacVlanDevicePrivate() +{ +} + +NetworkManager::MacVlanDevice::MacVlanDevice(const QString &path, QObject *parent) + : Device(*new MacVlanDevicePrivate(path, this), parent) +{ + Q_D(MacVlanDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::MacVlanDevice::~MacVlanDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::MacVlanDevice::type() const +{ + return NetworkManager::Device::MacVlan; +} + +QString NetworkManager::MacVlanDevice::mode() const +{ + Q_D(const MacVlanDevice); + return d->mode; +} + +bool NetworkManager::MacVlanDevice::noPromisc() const +{ + Q_D(const MacVlanDevice); + return d->noPromisc; +} + +QString NetworkManager::MacVlanDevice::parent() const +{ + Q_D(const MacVlanDevice); + return d->parent; +} + +void NetworkManager::MacVlanDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(MacVlanDevice); + + if (property == QLatin1String("Mode")) { + mode = value.toString(); + Q_EMIT q->modeChanged(mode); + } else if (property == QLatin1String("NoPromisc")) { + noPromisc = value.toBool(); + Q_EMIT q->noPromiscChanged(noPromisc); + } else if (property == QLatin1String("Parent")) { + parent = value.toString(); + Q_EMIT q->parentChanged(parent); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/macvlandevice.h b/panels/dock/tray/networkmanager-qt/src/macvlandevice.h new file mode 100644 index 000000000..1dbd0a09d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/macvlandevice.h @@ -0,0 +1,50 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_MACVLAN_DEVICE_H +#define NETWORKMANAGERQT_MACVLAN_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class MacVlanDevicePrivate; + +/** + * A macvlan device interface + */ +class NETWORKMANAGERQT_EXPORT MacVlanDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(QString mode READ mode NOTIFY modeChanged) + Q_PROPERTY(bool noPromisc READ noPromisc NOTIFY noPromiscChanged) + Q_PROPERTY(QString parent READ parent NOTIFY parentChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit MacVlanDevice(const QString &path, QObject *parent = nullptr); + ~MacVlanDevice() override; + + Type type() const override; + + QString mode() const; + bool noPromisc() const; + QString parent() const; + +Q_SIGNALS: + void modeChanged(const QString &mode); + void noPromiscChanged(bool noPromisc); + void parentChanged(const QString &parent); + +private: + Q_DECLARE_PRIVATE(MacVlanDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/macvlandevice_p.h b/panels/dock/tray/networkmanager-qt/src/macvlandevice_p.h new file mode 100644 index 000000000..5f17a595f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/macvlandevice_p.h @@ -0,0 +1,40 @@ +/* + SPDX-FileCopyrightText: 2012-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_MACVLAN_DEVICE_P_H +#define NETWORKMANAGERQT_MACVLAN_DEVICE_P_H + +#include "device_p.h" +#include "macvlandevice.h" +#include "macvlandeviceinterface.h" +#include "manager_p.h" + +namespace NetworkManager +{ +class MacVlanDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + MacVlanDevicePrivate(const QString &path, MacVlanDevice *q); + ~MacVlanDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceMacvlanInterface iface; + QString mode; + bool noPromisc; + QString parent; + + Q_DECLARE_PUBLIC(MacVlanDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/manager.cpp b/panels/dock/tray/networkmanager-qt/src/manager.cpp new file mode 100644 index 000000000..a19254588 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/manager.cpp @@ -0,0 +1,1163 @@ +/* + SPDX-FileCopyrightText: 2008, 2010 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque Souza + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "manager.h" +#include "manager_p.h" + +#include "macros.h" + +#undef signals +#include +#define signals Q_SIGNALS + +#include "adsldevice.h" +#include "bluetoothdevice.h" +#include "bonddevice.h" +#include "bridgedevice.h" +#include "dbus/deviceinterface.h" +#include "device_p.h" +#include "genericdevice.h" +#include "gredevice.h" +#include "infinibanddevice.h" +#include "iptunneldevice.h" +#include "macvlandevice.h" +#include "modemdevice.h" +#include "olpcmeshdevice.h" +#include "settings.h" +#include "settings_p.h" +#include "tundevice.h" +#include "vethdevice.h" +#include "vlandevice.h" +#include "vpnconnection.h" +#include "wimaxdevice.h" +#include "wireddevice.h" +#include "wireguarddevice.h" +#include "wirelessdevice.h" + +#include "nmdebug.h" + +#define DBUS_OBJECT_MANAGER "org.freedesktop.DBus.ObjectManager" +#define DBUS_PROPERTIES "org.freedesktop.DBus.Properties" + +#ifdef NMQT_STATIC +const QString NetworkManager::NetworkManagerPrivate::DBUS_SERVICE(QString::fromLatin1("org.kde.fakenetwork")); +const QString NetworkManager::NetworkManagerPrivate::DBUS_DAEMON_PATH(QString::fromLatin1("/org/kde/fakenetwork")); +const QString NetworkManager::NetworkManagerPrivate::DBUS_DAEMON_INTERFACE(QString::fromLatin1("org.kde.fakenetwork")); +const QString NetworkManager::NetworkManagerPrivate::DBUS_SETTINGS_PATH(QString::fromLatin1("/org/kde/fakenetwork/Settings")); +#else +const QString NetworkManager::NetworkManagerPrivate::DBUS_SERVICE(QString::fromLatin1(NM_DBUS_SERVICE)); +const QString NetworkManager::NetworkManagerPrivate::DBUS_DAEMON_PATH(QString::fromLatin1(NM_DBUS_PATH)); +const QString NetworkManager::NetworkManagerPrivate::DBUS_DAEMON_INTERFACE(QString::fromLatin1(NM_DBUS_INTERFACE)); +const QString NetworkManager::NetworkManagerPrivate::DBUS_SETTINGS_PATH(QString::fromLatin1(NM_DBUS_PATH_SETTINGS)); +#endif +const QString NetworkManager::NetworkManagerPrivate::FDO_DBUS_PROPERTIES(QString::fromLatin1(DBUS_PROPERTIES)); +const QString NetworkManager::NetworkManagerPrivate::FDO_DBUS_OBJECT_MANAGER(QString::fromLatin1(DBUS_OBJECT_MANAGER)); + +Q_GLOBAL_STATIC(NetworkManager::NetworkManagerPrivate, globalNetworkManager) + +NetworkManager::NetworkManagerPrivate::NetworkManagerPrivate() +#ifdef NMQT_STATIC + : watcher(DBUS_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration, this) + , iface(NetworkManager::NetworkManagerPrivate::DBUS_SERVICE, NetworkManager::NetworkManagerPrivate::DBUS_DAEMON_PATH, QDBusConnection::sessionBus()) +#else + : watcher(DBUS_SERVICE, QDBusConnection::systemBus(), QDBusServiceWatcher::WatchForUnregistration, this) + , iface(NetworkManager::NetworkManagerPrivate::DBUS_SERVICE, NetworkManager::NetworkManagerPrivate::DBUS_DAEMON_PATH, QDBusConnection::systemBus()) +#endif + , nmState(NetworkManager::Unknown) + , m_connectivity(NetworkManager::UnknownConnectivity) + , m_isNetworkingEnabled(false) + , m_isWimaxEnabled(false) + , m_isWimaxHardwareEnabled(false) + , m_isWirelessEnabled(false) + , m_isWirelessHardwareEnabled(false) + , m_isWwanEnabled(false) + , m_isWwanHardwareEnabled(false) + , m_globalDnsConfiguration(NetworkManager::DnsConfiguration()) + , m_supportedInterfaceTypes(NetworkManager::Device::UnknownType) +{ + connect(&iface, &OrgFreedesktopNetworkManagerInterface::DeviceAdded, this, &NetworkManagerPrivate::onDeviceAdded); + connect(&iface, &OrgFreedesktopNetworkManagerInterface::DeviceRemoved, this, &NetworkManagerPrivate::onDeviceRemoved); + +#ifndef NMQT_STATIC + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + NetworkManagerPrivate::DBUS_DAEMON_PATH, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + this, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); +#else + connect(&iface, &OrgFreedesktopNetworkManagerInterface::PropertiesChanged, this, &NetworkManagerPrivate::propertiesChanged); +#endif + + iface.connection().connect(NetworkManagerPrivate::DBUS_SERVICE, + "/org/freedesktop", + NetworkManagerPrivate::FDO_DBUS_OBJECT_MANAGER, + QLatin1String("InterfacesAdded"), + this, + SLOT(dbusInterfacesAdded(QDBusObjectPath, QVariantMap))); + + connect(&watcher, &QDBusServiceWatcher::serviceUnregistered, this, &NetworkManagerPrivate::daemonUnregistered); + + init(); +} + +void NetworkManager::NetworkManagerPrivate::parseVersion(const QString &version) +{ + const QStringList sl = version.split('.'); + + if (sl.size() > 2) { + m_x = sl[0].toInt(); + m_y = sl[1].toInt(); + m_z = sl[2].toInt(); + } else { + m_x = -1; + m_y = -1; + m_z = -1; + } +} + +void NetworkManager::NetworkManagerPrivate::init() +{ + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + // qDBusRegisterMetaType(); + // qDBusRegisterMetaType(); + // qDBusRegisterMetaType(); + // qDBusRegisterMetaType(); + // qDBusRegisterMetaType(); + qDBusRegisterMetaType>(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + + m_version = iface.version(); + parseVersion(m_version); + /* clang-format off */ + m_supportedInterfaceTypes = static_cast( + NetworkManager::Device::Ethernet + | NetworkManager::Device::Wifi + | NetworkManager::Device::Modem + | (checkVersion(1, 2, 0) ? 0 : NetworkManager::Device::Wimax) + | NetworkManager::Device::Bluetooth + | NetworkManager::Device::OlpcMesh + | NetworkManager::Device::InfiniBand + | NetworkManager::Device::Bond + | NetworkManager::Device::Vlan + | NetworkManager::Device::Adsl + | NetworkManager::Device::Bridge + | NetworkManager::Device::Generic + | NetworkManager::Device::Team + | NetworkManager::Device::MacVlan + | NetworkManager::Device::Tun + | NetworkManager::Device::Veth + | NetworkManager::Device::IpTunnel + | NetworkManager::Device::WireGuard); + /* clang-format on */ + + // Get all Manager's properties async + QVariantMap initialProperties = retrieveInitialProperties(iface.staticInterfaceName(), DBUS_DAEMON_PATH); + if (!initialProperties.isEmpty()) { + propertiesChanged(initialProperties); + } + + QTimer::singleShot(0, [] { + qobject_cast(settingsNotifier())->init(); + }); + + if (iface.isValid()) { + const QList devices = iface.devices(); + qCDebug(NMQT) << "Device list"; + for (const QDBusObjectPath &op : devices) { + networkInterfaceMap.insert(op.path(), Device::Ptr()); + Q_EMIT deviceAdded(op.path()); + qCDebug(NMQT) << " " << op.path(); + } + } +} + +NetworkManager::NetworkManagerPrivate::~NetworkManagerPrivate() +{ +} + +QString NetworkManager::NetworkManagerPrivate::version() const +{ + return m_version; +} + +int NetworkManager::NetworkManagerPrivate::compareVersion(const QString &version) +{ + int x; + int y; + int z; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const auto sl = QStringView(version).split('.'); +#else + const auto sl = version.splitRef('.'); +#endif + if (sl.size() > 2) { + x = sl[0].toInt(); + y = sl[1].toInt(); + z = sl[2].toInt(); + } else { + x = -1; + y = -1; + z = -1; + } + + return compareVersion(x, y, z); +} + +int NetworkManager::NetworkManagerPrivate::compareVersion(const int x, const int y, const int z) const +{ + if (m_x > x) { + return 1; + } else if (m_x < x) { + return -1; + } else if (m_y > y) { + return 1; + } else if (m_y < y) { + return -1; + } else if (m_z > z) { + return 1; + } else if (m_z < z) { + return -1; + } + return 0; +} + +bool NetworkManager::NetworkManagerPrivate::checkVersion(const int x, const int y, const int z) const +{ + return 0 <= compareVersion(x, y, z); +} + +NetworkManager::Device::Types NetworkManager::NetworkManagerPrivate::supportedInterfaceTypes() const +{ + return m_supportedInterfaceTypes; +} + +QVariantMap NetworkManager::NetworkManagerPrivate::retrieveInitialProperties(const QString &interfaceName, const QString &path) +{ + QDBusMessage message = QDBusMessage::createMethodCall(DBUS_SERVICE, path, FDO_DBUS_PROPERTIES, QLatin1String("GetAll")); + message << interfaceName; +#ifdef NMQT_STATIC + QDBusMessage resultMessage = QDBusConnection::sessionBus().call(message); +#else + QDBusMessage resultMessage = QDBusConnection::systemBus().call(message); +#endif + if (resultMessage.type() == QDBusMessage::ReplyMessage) { + QVariantMap result; + QDBusArgument dbusArgument = resultMessage.arguments().at(0).value(); + while (!dbusArgument.atEnd()) { + dbusArgument >> result; + } + return result; + } + + return QVariantMap(); +} + +NetworkManager::Device::Ptr NetworkManager::NetworkManagerPrivate::findRegisteredNetworkInterface(const QString &uni) +{ + NetworkManager::Device::Ptr networkInterface; + auto it = networkInterfaceMap.constFind(uni); + if (it != networkInterfaceMap.constEnd()) { + if (*it) { + networkInterface = *it; + } else { + networkInterface = createNetworkInterface(uni); + networkInterfaceMap[uni] = networkInterface; + } + } + return networkInterface; +} + +NetworkManager::ActiveConnection::Ptr NetworkManager::NetworkManagerPrivate::findRegisteredActiveConnection(const QString &uni) +{ + NetworkManager::ActiveConnection::Ptr activeConnection; + if (!uni.isEmpty() && uni != QLatin1String("/")) { + const auto it = m_activeConnections.constFind(uni); + const bool contains = it != m_activeConnections.constEnd(); + if (contains && *it) { + activeConnection = *it; + } else { + activeConnection = NetworkManager::ActiveConnection::Ptr(new NetworkManager::VpnConnection(uni), &QObject::deleteLater); + if (activeConnection->connection()) { + m_activeConnections[uni] = activeConnection; + if (!contains) { + Q_EMIT activeConnectionAdded(uni); + } + } else { + activeConnection.clear(); + } + } + } + return activeConnection; +} + +NetworkManager::Device::Ptr NetworkManager::NetworkManagerPrivate::createNetworkInterface(const QString &uni) +{ + // qCDebug(NMQT); + auto message = QDBusMessage::createMethodCall(DBUS_SERVICE, uni, FDO_DBUS_PROPERTIES, QStringLiteral("Get")); + message.setArguments({QLatin1String(OrgFreedesktopNetworkManagerDeviceInterface::staticInterfaceName()), QStringLiteral("DeviceType")}); +#ifdef NMQT_STATIC + auto bus = QDBusConnection::sessionBus(); +#else + auto bus = QDBusConnection::systemBus(); +#endif + QDBusReply reply = bus.call(message); + Device::Type type = reply.isValid() ? NetworkManager::DevicePrivate::convertType(reply.value().toInt()) : Device::UnknownType; + switch (type) { + case Device::Ethernet: + return Device::Ptr(new NetworkManager::WiredDevice(uni), &QObject::deleteLater); + case Device::Wifi: + return Device::Ptr(new NetworkManager::WirelessDevice(uni), &QObject::deleteLater); + case Device::Modem: + return Device::Ptr(new NetworkManager::ModemDevice(uni), &QObject::deleteLater); + case Device::Bluetooth: + return Device::Ptr(new NetworkManager::BluetoothDevice(uni), &QObject::deleteLater); + case Device::Wimax: + return Device::Ptr(new NetworkManager::WimaxDevice(uni), &QObject::deleteLater); + case Device::OlpcMesh: + return Device::Ptr(new NetworkManager::OlpcMeshDevice(uni), &QObject::deleteLater); + case Device::InfiniBand: + return Device::Ptr(new NetworkManager::InfinibandDevice(uni), &QObject::deleteLater); + case Device::Bond: + return Device::Ptr(new NetworkManager::BondDevice(uni), &QObject::deleteLater); + case Device::Vlan: + return Device::Ptr(new NetworkManager::VlanDevice(uni), &QObject::deleteLater); + case Device::Adsl: + return Device::Ptr(new NetworkManager::AdslDevice(uni), &QObject::deleteLater); + case Device::Bridge: + return Device::Ptr(new NetworkManager::BridgeDevice(uni), &QObject::deleteLater); + // No need to check checkVersion, because we can't get Generic, Gre, MacVlan, Tun & Veth values in incompatible runtime + case Device::Generic: + return Device::Ptr(new NetworkManager::GenericDevice(uni), &QObject::deleteLater); + case Device::Gre: + return Device::Ptr(new NetworkManager::GreDevice(uni), &QObject::deleteLater); + case Device::MacVlan: + return Device::Ptr(new NetworkManager::MacVlanDevice(uni), &QObject::deleteLater); + case Device::Tun: + return Device::Ptr(new NetworkManager::TunDevice(uni), &QObject::deleteLater); + case Device::Veth: + return Device::Ptr(new NetworkManager::VethDevice(uni), &QObject::deleteLater); + case Device::IpTunnel: + return Device::Ptr(new NetworkManager::IpTunnelDevice(uni), &QObject::deleteLater); + case Device::WireGuard: + return Device::Ptr(new NetworkManager::WireGuardDevice(uni), &QObject::deleteLater); + default: + if (uni != QLatin1String("any")) { // VPN connections use "any" as uni for the network interface. + qCDebug(NMQT) << "Can't create device of type" << type << "for" << uni; + } + } + + return Device::Ptr(new Device(uni), &QObject::deleteLater); +} + +NetworkManager::Status NetworkManager::NetworkManagerPrivate::status() const +{ + return nmState; +} + +NetworkManager::Device::List NetworkManager::NetworkManagerPrivate::networkInterfaces() +{ + Device::List list; + + QMap::const_iterator i; + for (i = networkInterfaceMap.constBegin(); i != networkInterfaceMap.constEnd(); ++i) { + Device::Ptr networkInterface = findRegisteredNetworkInterface(i.key()); + if (!networkInterface.isNull()) { + list.append(networkInterface); + } else { + qCWarning(NMQT) << "warning: null network Interface for" << i.key(); + } + } + + return list; +} + +NetworkManager::Device::Ptr NetworkManager::NetworkManagerPrivate::findDeviceByIpIface(const QString &iface) +{ + QMap::const_iterator i; + for (i = networkInterfaceMap.constBegin(); i != networkInterfaceMap.constEnd(); ++i) { + Device::Ptr networkInterface = findRegisteredNetworkInterface(i.key()); + if (networkInterface && networkInterface->udi() == iface) { + return networkInterface; + } + } + + return Device::Ptr(); +} + +bool NetworkManager::NetworkManagerPrivate::isNetworkingEnabled() const +{ + return m_isNetworkingEnabled; +} + +bool NetworkManager::NetworkManagerPrivate::isWirelessEnabled() const +{ + return m_isWirelessEnabled; +} + +bool NetworkManager::NetworkManagerPrivate::isWirelessHardwareEnabled() const +{ + return m_isWirelessHardwareEnabled; +} + +bool NetworkManager::NetworkManagerPrivate::isWwanEnabled() const +{ + return m_isWwanEnabled; +} + +bool NetworkManager::NetworkManagerPrivate::isWwanHardwareEnabled() const +{ + return m_isWwanHardwareEnabled; +} + +bool NetworkManager::NetworkManagerPrivate::isWimaxEnabled() const +{ + return checkVersion(1, 2, 0) ? false : m_isWimaxEnabled; +} + +bool NetworkManager::NetworkManagerPrivate::isWimaxHardwareEnabled() const +{ + return checkVersion(1, 2, 0) ? false : m_isWimaxHardwareEnabled; +} + +QDBusPendingReply +NetworkManager::NetworkManagerPrivate::activateConnection(const QString &connectionUni, const QString &interfaceUni, const QString &connectionParameter) +{ + QString extra_connection_parameter = connectionParameter; + QString extra_interface_parameter = interfaceUni; + if (extra_connection_parameter.isEmpty()) { + extra_connection_parameter = QLatin1String("/"); + } + if (extra_interface_parameter.isEmpty()) { + extra_interface_parameter = QLatin1String("/"); + } + // TODO store error code + QDBusObjectPath connPath(connectionUni); + QDBusObjectPath interfacePath(interfaceUni); + // qCDebug(NMQT) << "Activating connection" << connPath.path() << "on interface" << interfacePath.path() << "with extra" << extra_connection_parameter; + return iface.ActivateConnection(connPath, QDBusObjectPath(extra_interface_parameter), QDBusObjectPath(extra_connection_parameter)); +} + +QDBusPendingReply NetworkManager::NetworkManagerPrivate::addAndActivateConnection(const NMVariantMapMap &connection, + const QString &interfaceUni, + const QString &connectionParameter) +{ + QString extra_connection_parameter = connectionParameter; + if (extra_connection_parameter.isEmpty()) { + extra_connection_parameter = QLatin1String("/"); + } + // TODO store error code + QDBusObjectPath interfacePath(interfaceUni); + return iface.AddAndActivateConnection(connection, interfacePath, QDBusObjectPath(extra_connection_parameter)); +} + +QDBusPendingReply +NetworkManager::NetworkManagerPrivate::addAndActivateConnection2(const NMVariantMapMap &connection, + const QString &interfaceUni, + const QString &connectionParameter, + const QVariantMap &options) +{ + QString extra_connection_parameter = connectionParameter; + if (extra_connection_parameter.isEmpty()) { + extra_connection_parameter = QLatin1String("/"); + } + // TODO store error code + QDBusObjectPath interfacePath(interfaceUni); + return iface.AddAndActivateConnection2(connection, interfacePath, QDBusObjectPath(extra_connection_parameter), options); +} + +QDBusPendingReply<> NetworkManager::NetworkManagerPrivate::deactivateConnection(const QString &activeConnectionPath) +{ + return iface.DeactivateConnection(QDBusObjectPath(activeConnectionPath)); +} + +void NetworkManager::NetworkManagerPrivate::setNetworkingEnabled(bool enabled) +{ + iface.Enable(enabled); +} + +void NetworkManager::NetworkManagerPrivate::setWirelessEnabled(bool enabled) +{ + iface.setWirelessEnabled(enabled); +} + +void NetworkManager::NetworkManagerPrivate::setWwanEnabled(bool enabled) +{ + iface.setWwanEnabled(enabled); +} + +void NetworkManager::NetworkManagerPrivate::setWimaxEnabled(bool enabled) +{ + if (!checkVersion(1, 2, 0)) { + iface.setWimaxEnabled(enabled); + } +} + +void NetworkManager::NetworkManagerPrivate::sleep(bool sleep) +{ + iface.Sleep(sleep); +} + +void NetworkManager::NetworkManagerPrivate::setLogging(NetworkManager::LogLevel level, NetworkManager::LogDomains domains) +{ + QString logLevel; + QStringList logDomains; + switch (level) { + case NetworkManager::Error: + logLevel = QLatin1String("ERR"); + break; + case NetworkManager::Warning: + logLevel = QLatin1String("WARN"); + break; + case NetworkManager::Info: + logLevel = QLatin1String("INFO"); + break; + case NetworkManager::Debug: + logLevel = QLatin1String("DEBUG"); + break; + case NetworkManager::Trace: + logLevel = QLatin1String("TRACE"); + break; + } + if (!domains.testFlag(NoChange)) { + if (domains.testFlag(NetworkManager::None)) { + logDomains << QLatin1String("NONE"); + } + if (domains.testFlag(NetworkManager::Hardware)) { + logDomains << QLatin1String("PLATFORM"); + } + if (domains.testFlag(NetworkManager::RFKill)) { + logDomains << QLatin1String("RFKILL"); + } + if (domains.testFlag(NetworkManager::Ethernet)) { + logDomains << QLatin1String("ETHER"); + } + if (domains.testFlag(NetworkManager::WiFi)) { + logDomains << QLatin1String("WIFI"); + } + if (domains.testFlag(NetworkManager::Bluetooth)) { + logDomains << QLatin1String("BT"); + } + if (domains.testFlag(NetworkManager::MobileBroadBand)) { + logDomains << QLatin1String("MB"); + } + if (domains.testFlag(NetworkManager::DHCP4)) { + logDomains << QLatin1String("DHCP4"); + } + if (domains.testFlag(NetworkManager::DHCP6)) { + logDomains << QLatin1String("DHCP6"); + } + if (domains.testFlag(NetworkManager::PPP)) { + logDomains << QLatin1String("PPP"); + } + if (domains.testFlag(NetworkManager::WiFiScan)) { + logDomains << QLatin1String("WIFI_SCAN"); + } + if (domains.testFlag(NetworkManager::IPv4)) { + logDomains << QLatin1String("IP4"); + } + if (domains.testFlag(NetworkManager::IPv6)) { + logDomains << QLatin1String("IP6"); + } + if (domains.testFlag(NetworkManager::AutoIPv4)) { + logDomains << QLatin1String("AUTOIP4"); + } + if (domains.testFlag(NetworkManager::DNS)) { + logDomains << QLatin1String("DNS"); + } + if (domains.testFlag(NetworkManager::VPN)) { + logDomains << QLatin1String("VPN"); + } + if (domains.testFlag(NetworkManager::Sharing)) { + logDomains << QLatin1String("SHARING"); + } + if (domains.testFlag(NetworkManager::Supplicant)) { + logDomains << QLatin1String("SUPPLICANT"); + } + if (domains.testFlag(NetworkManager::UserSet)) { + logDomains << QLatin1String("USER_SET"); + } + if (domains.testFlag(NetworkManager::SysSet)) { + logDomains << QLatin1String("SYS_SET"); + } + if (domains.testFlag(NetworkManager::Suspend)) { + logDomains << QLatin1String("SUSPEND"); + } + if (domains.testFlag(NetworkManager::Core)) { + logDomains << QLatin1String("CORE"); + } + if (domains.testFlag(NetworkManager::Devices)) { + logDomains << QLatin1String("DEVICE"); + } + if (domains.testFlag(NetworkManager::OLPC)) { + logDomains << QLatin1String("OLPC"); + } + if (domains.testFlag(NetworkManager::Wimax)) { + logDomains << QLatin1String("WIMAX"); + } + if (domains.testFlag(NetworkManager::Infiniband)) { + logDomains << QLatin1String("INFINIBAND"); + } + if (domains.testFlag(NetworkManager::Firewall)) { + logDomains << QLatin1String("FIREWALL"); + } + if (domains.testFlag(NetworkManager::Adsl)) { + logDomains << QLatin1String("ADSL"); + } + if (domains.testFlag(NetworkManager::Bond)) { + logDomains << QLatin1String("BOND"); + } + if (domains.testFlag(NetworkManager::Vlan)) { + logDomains << QLatin1String("VLAN"); + } + if (domains.testFlag(NetworkManager::Agents)) { + logDomains << QLatin1String("AGENTS"); + } + if (domains.testFlag(NetworkManager::Settings)) { + logDomains << QLatin1String("SETTINGS"); + } + if (domains.testFlag(NetworkManager::DbusProps)) { + logDomains << QLatin1String("DBUS_PROPS"); + } + if (domains.testFlag(NetworkManager::Team)) { + logDomains << QLatin1String("TEAM"); + } + if (domains.testFlag(NetworkManager::ConCheck)) { + logDomains << QLatin1String("CONCHECK"); + } + if (domains.testFlag(NetworkManager::Dcb)) { + logDomains << QLatin1String("DCB"); + } + if (domains.testFlag(NetworkManager::Dispatch)) { + logDomains << QLatin1String("DISPATCH"); + } + } + iface.SetLogging(logLevel, logDomains.join(QLatin1Char(','))); +} + +NMStringMap NetworkManager::NetworkManagerPrivate::permissions() +{ + return iface.GetPermissions(); +} + +NetworkManager::Connectivity NetworkManager::NetworkManagerPrivate::connectivity() const +{ + return m_connectivity; +} + +QDBusPendingReply NetworkManager::NetworkManagerPrivate::checkConnectivity() +{ + return iface.CheckConnectivity(); +} + +NetworkManager::ActiveConnection::Ptr NetworkManager::NetworkManagerPrivate::primaryConnection() +{ + return findRegisteredActiveConnection(m_primaryConnection); +} + +NetworkManager::ActiveConnection::Ptr NetworkManager::NetworkManagerPrivate::activatingConnection() +{ + return findRegisteredActiveConnection(m_activatingConnection); +} + +NetworkManager::ConnectionSettings::ConnectionType NetworkManager::NetworkManagerPrivate::primaryConnectionType() +{ + return checkVersion(1, 0, 0) ? m_primaryConnectionType : NetworkManager::ConnectionSettings::Unknown; +} + +bool NetworkManager::NetworkManagerPrivate::isStartingUp() const +{ + return iface.startup(); +} + +NetworkManager::Device::MeteredStatus NetworkManager::NetworkManagerPrivate::metered() const +{ + return checkVersion(1, 0, 6) ? m_metered : NetworkManager::Device::UnknownStatus; +} + +NetworkManager::DnsConfiguration NetworkManager::NetworkManagerPrivate::globalDnsConfiguration() const +{ + return m_globalDnsConfiguration; +} + +void NetworkManager::NetworkManagerPrivate::setGlobalDnsConfiguration(const NetworkManager::DnsConfiguration &configuration) +{ + m_globalDnsConfiguration = configuration; + iface.setGlobalDnsConfiguration(m_globalDnsConfiguration.toMap()); +} + +void NetworkManager::NetworkManagerPrivate::onDeviceAdded(const QDBusObjectPath &objpath) +{ + // qCDebug(NMQT); + if (!networkInterfaceMap.contains(objpath.path())) { + networkInterfaceMap.insert(objpath.path(), Device::Ptr()); + Q_EMIT deviceAdded(objpath.path()); + } +} + +void NetworkManager::NetworkManagerPrivate::onDeviceRemoved(const QDBusObjectPath &objpath) +{ + // qCDebug(NMQT); + networkInterfaceMap.remove(objpath.path()); + Q_EMIT deviceRemoved(objpath.path()); +} + +void NetworkManager::NetworkManagerPrivate::connectivityChanged(uint connectivity) +{ + NetworkManager::Connectivity newConnectivity = convertConnectivity(connectivity); + if (m_connectivity != newConnectivity) { + m_connectivity = newConnectivity; + Q_EMIT Notifier::connectivityChanged(newConnectivity); + } +} + +void NetworkManager::NetworkManagerPrivate::stateChanged(uint state) +{ + NetworkManager::Status newStatus = convertNMState(state); + if (nmState != newStatus) { + nmState = newStatus; + Q_EMIT Notifier::statusChanged(newStatus); + } +} + +void NetworkManager::NetworkManagerPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager")) { + propertiesChanged(properties); + } +} + +void NetworkManager::NetworkManagerPrivate::propertiesChanged(const QVariantMap &changedProperties) +{ + // qCDebug(NMQT) << Q_FUNC_INFO << changedProperties; + + QVariantMap::const_iterator it = changedProperties.constBegin(); + while (it != changedProperties.constEnd()) { + const QString property = it.key(); + if (property == QLatin1String("ActiveConnections")) { + const QList activePaths = qdbus_cast>(*it); + if (activePaths.isEmpty()) { + QMap::const_iterator it = m_activeConnections.constBegin(); + while (it != m_activeConnections.constEnd()) { + Q_EMIT activeConnectionRemoved(it.key()); + ++it; + } + m_activeConnections.clear(); + } else { + QStringList knownConnections = m_activeConnections.keys(); + for (const QDBusObjectPath &ac : activePaths) { + if (!m_activeConnections.contains(ac.path())) { + m_activeConnections.insert(ac.path(), NetworkManager::ActiveConnection::Ptr()); + Q_EMIT activeConnectionAdded(ac.path()); + } else { + knownConnections.removeOne(ac.path()); + } + // qCDebug(NMQT) << " " << ac.path(); + } + for (const QString &path : std::as_const(knownConnections)) { + m_activeConnections.remove(path); + Q_EMIT activeConnectionRemoved(path); + } + } + Q_EMIT activeConnectionsChanged(); + } else if (property == QLatin1String("NetworkingEnabled")) { + m_isNetworkingEnabled = it->toBool(); + qCDebug(NMQT) << property << m_isNetworkingEnabled; + Q_EMIT networkingEnabledChanged(m_isNetworkingEnabled); + } else if (property == QLatin1String("WirelessHardwareEnabled")) { + m_isWirelessHardwareEnabled = it->toBool(); + qCDebug(NMQT) << property << m_isWirelessHardwareEnabled; + Q_EMIT wirelessHardwareEnabledChanged(m_isWirelessHardwareEnabled); + } else if (property == QLatin1String("WirelessEnabled")) { + m_isWirelessEnabled = it->toBool(); + qCDebug(NMQT) << property << m_isWirelessEnabled; + Q_EMIT wirelessEnabledChanged(m_isWirelessEnabled); + } else if (property == QLatin1String("WwanHardwareEnabled")) { + m_isWwanHardwareEnabled = it->toBool(); + qCDebug(NMQT) << property << m_isWwanHardwareEnabled; + Q_EMIT wwanHardwareEnabledChanged(m_isWwanHardwareEnabled); + } else if (property == QLatin1String("WwanEnabled")) { + m_isWwanEnabled = it->toBool(); + qCDebug(NMQT) << property << m_isWwanEnabled; + Q_EMIT wwanEnabledChanged(m_isWwanEnabled); + } else if (property == QLatin1String("WimaxHardwareEnabled")) { + m_isWimaxHardwareEnabled = it->toBool(); + qCDebug(NMQT) << property << m_isWimaxHardwareEnabled; + Q_EMIT wimaxHardwareEnabledChanged(m_isWimaxHardwareEnabled); + } else if (property == QLatin1String("WimaxEnabled")) { + m_isWimaxEnabled = it->toBool(); + qCDebug(NMQT) << property << m_isWimaxEnabled; + Q_EMIT wimaxEnabledChanged(m_isWimaxEnabled); + } else if (property == QLatin1String("Version")) { + m_version = it->toString(); + parseVersion(m_version); + } else if (property == QLatin1String("State")) { + stateChanged(it->toUInt()); + } else if (property == QLatin1String("Connectivity")) { + connectivityChanged(it->toUInt()); + } else if (property == QLatin1String("PrimaryConnection")) { + m_primaryConnection = it->value().path(); + Q_EMIT primaryConnectionChanged(m_primaryConnection); + } else if (property == QLatin1String("ActivatingConnection")) { + m_activatingConnection = it->value().path(); + Q_EMIT activatingConnectionChanged(m_activatingConnection); + } else if (property == QLatin1String("PrimaryConnectionType")) { + m_primaryConnectionType = NetworkManager::ConnectionSettings::typeFromString(it->toString()); + Q_EMIT primaryConnectionTypeChanged(m_primaryConnectionType); + } else if (property == QLatin1String("Startup")) { + Q_EMIT isStartingUpChanged(); + } else if (property == QLatin1String("Metered")) { + m_metered = (NetworkManager::Device::MeteredStatus)it->toUInt(); + Q_EMIT meteredChanged(m_metered); + } else if (property == QLatin1String("GlobalDnsConfiguration")) { + m_globalDnsConfiguration.fromMap(qdbus_cast(*it)); + Q_EMIT globalDnsConfigurationChanged(m_globalDnsConfiguration); + } else { + qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } + ++it; + } +} + +NetworkManager::Connectivity NetworkManager::NetworkManagerPrivate::convertConnectivity(uint connectivity) +{ + NetworkManager::Connectivity convertedConnectivity = NetworkManager::UnknownConnectivity; + switch (connectivity) { + case NM_CONNECTIVITY_UNKNOWN: + convertedConnectivity = NetworkManager::UnknownConnectivity; + break; + case NM_CONNECTIVITY_NONE: + convertedConnectivity = NetworkManager::NoConnectivity; + break; + case NM_CONNECTIVITY_PORTAL: + convertedConnectivity = NetworkManager::Portal; + break; + case NM_CONNECTIVITY_LIMITED: + convertedConnectivity = NetworkManager::Limited; + break; + case NM_CONNECTIVITY_FULL: + convertedConnectivity = NetworkManager::Full; + break; + } + return convertedConnectivity; +} + +NetworkManager::Status NetworkManager::NetworkManagerPrivate::convertNMState(uint state) +{ + NetworkManager::Status status = NetworkManager::Unknown; + switch (state) { + case NM_STATE_UNKNOWN: + status = NetworkManager::Unknown; + break; + case NM_STATE_ASLEEP: + status = NetworkManager::Asleep; + break; + case NM_STATE_DISCONNECTED: + status = NetworkManager::Disconnected; + break; + case NM_STATE_DISCONNECTING: + status = NetworkManager::Disconnecting; + break; + case NM_STATE_CONNECTING: + status = NetworkManager::Connecting; + break; + case NM_STATE_CONNECTED_LOCAL: + status = NetworkManager::ConnectedLinkLocal; + break; + case NM_STATE_CONNECTED_SITE: + status = NetworkManager::ConnectedSiteOnly; + break; + case NM_STATE_CONNECTED_GLOBAL: + status = NetworkManager::Connected; + break; + } + return status; +} + +void NetworkManager::NetworkManagerPrivate::dbusInterfacesAdded(const QDBusObjectPath &path, const QVariantMap &addedInterfaces) +{ + Q_UNUSED(path); + + if (!addedInterfaces.contains(NetworkManagerPrivate::DBUS_DAEMON_INTERFACE)) { + return; + } + + init(); + Q_EMIT serviceAppeared(); +} + +void NetworkManager::NetworkManagerPrivate::daemonUnregistered() +{ + stateChanged(NM_STATE_UNKNOWN); + QMap::const_iterator i = networkInterfaceMap.constBegin(); + while (i != networkInterfaceMap.constEnd()) { + Q_EMIT deviceRemoved(i.key()); + ++i; + } + networkInterfaceMap.clear(); + + QMap::const_iterator it = m_activeConnections.constBegin(); + while (it != m_activeConnections.constEnd()) { + Q_EMIT activeConnectionRemoved(it.key()); + ++it; + } + m_activeConnections.clear(); + + qobject_cast(settingsNotifier())->daemonUnregistered(); + + Q_EMIT activeConnectionsChanged(); + Q_EMIT serviceDisappeared(); +} + +NetworkManager::ActiveConnection::List NetworkManager::NetworkManagerPrivate::activeConnections() +{ + NetworkManager::ActiveConnection::List list; + + // Take a copy because findRegisteredActiveConnection() may change m_activeConnections. + const QStringList keyList = m_activeConnections.keys(); + for (const QString &key : keyList) { + NetworkManager::ActiveConnection::Ptr activeConnection = findRegisteredActiveConnection(key); + + if (activeConnection) { + list << activeConnection; + } + } + return list; +} + +QStringList NetworkManager::NetworkManagerPrivate::activeConnectionsPaths() const +{ + return m_activeConnections.keys(); +} + +QDBusPendingReply NetworkManager::NetworkManagerPrivate::getLogging() +{ + return iface.GetLogging(); +} + +QString NetworkManager::version() +{ + return globalNetworkManager->version(); +} + +int NetworkManager::compareVersion(const QString &version) +{ + return globalNetworkManager->compareVersion(version); +} + +int NetworkManager::compareVersion(const int x, const int y, const int z) +{ + return globalNetworkManager->compareVersion(x, y, z); +} + +bool NetworkManager::checkVersion(const int x, const int y, const int z) +{ + return globalNetworkManager->checkVersion(x, y, z); +} + +NetworkManager::Status NetworkManager::status() +{ + return globalNetworkManager->status(); +} + +NetworkManager::ActiveConnection::List NetworkManager::activeConnections() +{ + return globalNetworkManager->activeConnections(); +} + +QStringList NetworkManager::activeConnectionsPaths() +{ + return globalNetworkManager->activeConnectionsPaths(); +} + +NetworkManager::ActiveConnection::Ptr NetworkManager::findActiveConnection(const QString &uni) +{ + return globalNetworkManager->findRegisteredActiveConnection(uni); +} + +NetworkManager::Device::List NetworkManager::networkInterfaces() +{ + return globalNetworkManager->networkInterfaces(); +} + +bool NetworkManager::isNetworkingEnabled() +{ + return globalNetworkManager->isNetworkingEnabled(); +} + +bool NetworkManager::isWirelessEnabled() +{ + return globalNetworkManager->isWirelessEnabled(); +} + +bool NetworkManager::isWirelessHardwareEnabled() +{ + return globalNetworkManager->isWirelessHardwareEnabled(); +} + +NetworkManager::Device::Ptr NetworkManager::findNetworkInterface(const QString &uni) +{ + return globalNetworkManager->findRegisteredNetworkInterface(uni); +} + +NetworkManager::Device::Ptr NetworkManager::findDeviceByIpFace(const QString &iface) +{ + return globalNetworkManager->findDeviceByIpIface(iface); +} + +QDBusPendingReply +NetworkManager::addAndActivateConnection(const NMVariantMapMap &connection, const QString &interfaceUni, const QString &connectionParameter) +{ + return globalNetworkManager->addAndActivateConnection(connection, interfaceUni, connectionParameter); +} + +QDBusPendingReply NetworkManager::addAndActivateConnection2(const NMVariantMapMap &connection, + const QString &interfaceUni, + const QString &connectionParameter, + const QVariantMap &options) +{ + if (checkVersion(1, 16, 0)) { + return globalNetworkManager->addAndActivateConnection2(connection, interfaceUni, connectionParameter, options); + } else { + return globalNetworkManager->addAndActivateConnection(connection, interfaceUni, connectionParameter); + } +} + +QDBusPendingReply +NetworkManager::activateConnection(const QString &connectionUni, const QString &interfaceUni, const QString &connectionParameter) +{ + return globalNetworkManager->activateConnection(connectionUni, interfaceUni, connectionParameter); +} + +QDBusPendingReply<> NetworkManager::deactivateConnection(const QString &activeConnectionPath) +{ + return globalNetworkManager->deactivateConnection(activeConnectionPath); +} + +QDBusPendingReply NetworkManager::getLogging() +{ + return globalNetworkManager->getLogging(); +} + +void NetworkManager::setNetworkingEnabled(bool enabled) +{ + globalNetworkManager->setNetworkingEnabled(enabled); +} + +void NetworkManager::setWirelessEnabled(bool enabled) +{ + globalNetworkManager->setWirelessEnabled(enabled); +} + +bool NetworkManager::isWwanEnabled() +{ + return globalNetworkManager->isWwanEnabled(); +} + +bool NetworkManager::isWwanHardwareEnabled() +{ + return globalNetworkManager->isWwanHardwareEnabled(); +} + +void NetworkManager::setWwanEnabled(bool enabled) +{ + globalNetworkManager->setWwanEnabled(enabled); +} + +bool NetworkManager::isWimaxEnabled() +{ + return globalNetworkManager->isWimaxEnabled(); +} + +bool NetworkManager::isWimaxHardwareEnabled() +{ + return globalNetworkManager->isWimaxHardwareEnabled(); +} + +void NetworkManager::setWimaxEnabled(bool enabled) +{ + globalNetworkManager->setWimaxEnabled(enabled); +} + +void NetworkManager::sleep(bool sleep) +{ + globalNetworkManager->sleep(sleep); +} + +void NetworkManager::setLogging(NetworkManager::LogLevel level, NetworkManager::LogDomains domains) +{ + globalNetworkManager->setLogging(level, domains); +} + +NMStringMap NetworkManager::permissions() +{ + return globalNetworkManager->permissions(); +} + +NetworkManager::Device::Types NetworkManager::supportedInterfaceTypes() +{ + return globalNetworkManager->supportedInterfaceTypes(); +} + +NetworkManager::Connectivity NetworkManager::connectivity() +{ + return globalNetworkManager->connectivity(); +} + +QDBusPendingReply NetworkManager::checkConnectivity() +{ + return globalNetworkManager->checkConnectivity(); +} + +NetworkManager::ActiveConnection::Ptr NetworkManager::primaryConnection() +{ + return globalNetworkManager->primaryConnection(); +} + +NetworkManager::ActiveConnection::Ptr NetworkManager::activatingConnection() +{ + return globalNetworkManager->activatingConnection(); +} + +NetworkManager::ConnectionSettings::ConnectionType NetworkManager::primaryConnectionType() +{ + return globalNetworkManager->primaryConnectionType(); +} + +bool NetworkManager::isStartingUp() +{ + return globalNetworkManager->isStartingUp(); +} + +NetworkManager::Device::MeteredStatus NetworkManager::metered() +{ + return globalNetworkManager->metered(); +} + +NetworkManager::DnsConfiguration NetworkManager::globalDnsConfiguration() +{ + return globalNetworkManager->globalDnsConfiguration(); +} + +void NetworkManager::setGlobalDnsConfiguration(const NetworkManager::DnsConfiguration &configuration) +{ + globalNetworkManager->setGlobalDnsConfiguration(configuration); +} + +NetworkManager::Notifier *NetworkManager::notifier() +{ + return globalNetworkManager; +} diff --git a/panels/dock/tray/networkmanager-qt/src/manager.h b/panels/dock/tray/networkmanager-qt/src/manager.h new file mode 100644 index 000000000..ec9d2ec52 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/manager.h @@ -0,0 +1,492 @@ +/* + SPDX-FileCopyrightText: 2008, 2010, 2011 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_NETWORKMANAGER_H +#define NETWORKMANAGERQT_NETWORKMANAGER_H + +#include + +#include "activeconnection.h" +#include "device.h" +#include "dnsconfiguration.h" + +/** + * This class allows querying the underlying system to discover the available + * network interfaces and reachable networks. It has also the + * responsibility to notify when a network interface appears or disappears. + * + * It is the unique entry point for network management. Applications should use + * it to find network interfaces, or to be notified about network related changes. + * + * Note that it is implemented as a singleton + */ +namespace NetworkManager +{ +Q_NAMESPACE_EXPORT(NETWORKMANAGERQT_EXPORT) + +enum Status { + Unknown, /**< the networking system is not active or unable to report its status - proceed with caution */ + Asleep, /**< networking is inactive and all devices are disabled */ + Disconnected, /**< the system is not connected to any network */ + Disconnecting, /**< the system is breaking the connection */ + Connecting, /**< the system is not connected to any network */ + ConnectedLinkLocal, /**< a network device is connected, but there is only link-local connectivity */ + ConnectedSiteOnly, /**< a network device is connected, but there is only site-local connectivity */ + Connected, /**< the system is currently connected to a network */ +}; +Q_ENUM_NS(Status) + +enum LogLevel { + Error, + Warning, + Info, + Debug, + Trace, /**< = Debug in runtime NM < 0.9.10*/ +}; + +enum LogDomain { + NoChange, + None, + Hardware, + RFKill, + Ethernet, + WiFi, + Bluetooth, + MobileBroadBand, + DHCP4, + DHCP6, + PPP, + WiFiScan, + IPv4, + IPv6, + AutoIPv4, + DNS, + VPN, + Sharing, + Supplicant, + UserSet, + SysSet, + Suspend, + Core, + Devices, + OLPC, + Wimax /*TODO: mark it deprecated somehow?*/, + Infiniband, + Firewall, + Adsl, + Bond, + Vlan, + Agents, + Settings, + Bridge, + DbusProps, + Team, + ConCheck, + Dcb, + Dispatch, +}; +Q_DECLARE_FLAGS(LogDomains, LogDomain) +Q_FLAGS(LogDomain) + +/** + * Describes the network connectivity state. + * @since 0.9.9.0 + */ +enum Connectivity { + UnknownConnectivity = 0, /**< Network connectivity is unknown. */ + NoConnectivity = 1, /**< The host is not connected to any network. */ + Portal = 2, /**< The host is behind a captive portal and cannot reach the full Internet. */ + Limited = 3, /**< The host is connected to a network, but does not appear to be able to reach the full Internet. */ + Full = 4, /**< The host is connected to a network, and appears to be able to reach the full Internet. */ +}; +Q_ENUM_NS(Connectivity) + +class NETWORKMANAGERQT_EXPORT Notifier : public QObject +{ + Q_OBJECT +Q_SIGNALS: + /** + * This signal is emitted when the system's connection state changes + */ + void statusChanged(NetworkManager::Status status); + /** + * This signal is emitted when a new network interface is available. + * + * @param uni the network interface identifier + */ + void deviceAdded(const QString &uni); + /** + * This signal is emitted when a network interface is not available anymore. + * + * @param uni the network interface identifier + */ + void deviceRemoved(const QString &uni); + /** + * This signal is emitted when the status of the wireless changed + */ + void wirelessEnabledChanged(bool); + /** + * This signal is emitted when the status of the wireless changed + */ + void wwanEnabledChanged(bool); + /** + * This signal is emitted when the status of the wimax changed + * + * @deprecated Wimax support was removed from NetworkManager 1.2 + * (never emitted in runtime NM >= 1.2.0). + */ + void wimaxEnabledChanged(bool); + /** + * This signal is emitted when the status of the wireless changed + */ + void wirelessHardwareEnabledChanged(bool); + /** + * This signal is emitted when the status of the wireless changed + */ + void wwanHardwareEnabledChanged(bool); + /** + * This signal is emitted when the status of the wimax hardware changed + * + * @deprecated Wimax support was removed from NetworkManager 1.2 + * (never emitted in runtime NM >= 1.2.0). + */ + void wimaxHardwareEnabledChanged(bool); + /** + * This signal is emitted when the status of overall networking changed + */ + void networkingEnabledChanged(bool); + /** + * This signal is emitted when a new connection was made active + * + * @param path the path of the new connection + */ + void activeConnectionAdded(const QString &path); + /** + * This signal is emitted when an active connection is no longer active + * + * @param path the path of the removed connection + */ + void activeConnectionRemoved(const QString &path); + /** + * This signal is emitted when the set of active connections changes + */ + void activeConnectionsChanged(); + /** + * This signal is emitted when the NetworkManager DBus service goes away + */ + void serviceDisappeared(); + /** + * This signal is emitted when the NetworkManager DBus service appears + */ + void serviceAppeared(); + /** + * Emitted when the global connectivity changes. + * @since 0.9.9.0 + */ + void connectivityChanged(NetworkManager::Connectivity connectivity); + /** + * Emitted when the primary connection changes. + * @param uni path of the new primary connection + * @since 0.9.9.0 + */ + void primaryConnectionChanged(const QString &uni); + /** + * Emitted when the activating connection changes. + * @param uni path of the new activating connection + * @since 0.9.9.0 + */ + void activatingConnectionChanged(const QString &uni); + /** + * Emitted when the primary connection type changes. + * @param connection type of the new primary connection + * @since 5.8.0 + */ + void primaryConnectionTypeChanged(NetworkManager::ConnectionSettings::ConnectionType type); + + /** + * Emitted when NM has started/finished its startup sequence + * @since 0.9.9.0 + */ + void isStartingUpChanged(); + + /** + * Emitted when metered property has changed + * @since 5.14.0 + * @see metered + */ + void meteredChanged(NetworkManager::Device::MeteredStatus metered); + + /** + * Emitted when the global DNS configuration has changed + * @since 5.45.0 + * @see globalDnsConfiguration + */ + void globalDnsConfigurationChanged(const NetworkManager::DnsConfiguration &configuration); +}; + +/** + * Get the NetworkManager version + */ +NETWORKMANAGERQT_EXPORT QString version(); +/** + * Compares NetworkManager's version to the parameter version. + * returns 1, -1 or 0 if NetworkManager's version is greater, less or equal to parameter. + */ +NETWORKMANAGERQT_EXPORT int compareVersion(const QString &version); +/** + * Compares NetworkManager version to x.y.z. + * returns 1, -1 or 0 if NetworkManager's version is greater, less or equal to x.y.z. + */ +NETWORKMANAGERQT_EXPORT int compareVersion(const int x, const int y, const int z); +/** + * Checks if NetworkManager version is at least x.y.z + * @return true if NetworkManager's version is greater or equal, false otherwise + **/ +NETWORKMANAGERQT_EXPORT bool checkVersion(const int x, const int y, const int z); +/** + * Get the manager connection state + */ +NETWORKMANAGERQT_EXPORT NetworkManager::Status status(); +/** + * Retrieves the list of all the network interfaces in the system. + * It includes both hardware and virtual devices. + * + * @return the list of network interfaces available in this system + */ +NETWORKMANAGERQT_EXPORT Device::List networkInterfaces(); +/** + * Find a new NetworkInterface object given its UNI. This pointer is owned by the Solid + * infrastructure. + * + * @param uni the identifier of the network interface to find + * @return a valid NetworkInterface object if there's a device having the given UNI, an invalid one otherwise + */ +NETWORKMANAGERQT_EXPORT Device::Ptr findNetworkInterface(const QString &uni); +/** + * Return the network device referenced by its IP interface name. + * This is not system independent so programs that will use this method will not be portable. + */ +NETWORKMANAGERQT_EXPORT Device::Ptr findDeviceByIpFace(const QString &iface); +/** + * Retrieves the status of networking (as a whole) in the system. + * This is distinct from whether the system's networking is online or offline. + * To check that, see @ref status(). + * + * @return true if this networking is enabled, false otherwise + */ +NETWORKMANAGERQT_EXPORT bool isNetworkingEnabled(); +/** + * Retrieves the activation status of wireless networking in the system. + * + * @return true if this wireless networking is enabled, false otherwise + */ +NETWORKMANAGERQT_EXPORT bool isWirelessEnabled(); +/** + * Retrieves the status of wireless hardware in the system. This is typically + * controlled by a physical switch so there is no way to set this in software. + * + * @return true if this wireless networking is enabled, false otherwise + */ +NETWORKMANAGERQT_EXPORT bool isWirelessHardwareEnabled(); +/** + * Retrieves the status of wireless broadband (Wireless WAN) in the system. + * + * @return true if this type of wireless networking is enabled, false otherwise + */ +NETWORKMANAGERQT_EXPORT bool isWwanEnabled(); +/** + * Retrieves the status of wireless broadband (Wireless WAN) hardware in the system. This is typically + * controlled by a physical switch so there is no way to set this in software. + * + * @return true if this broddband hardware is enabled, false otherwise + */ +NETWORKMANAGERQT_EXPORT bool isWwanHardwareEnabled(); + +/** + * Retrieves the activation status of wimax networking in the system. + * + * @return true if this wimax networking is enabled, false otherwise + * + * @deprecated Wimax support was removed from NetworkManager 1.2 + * (always returns false in runtime NM >= 1.2.0). + */ +NETWORKMANAGERQT_EXPORT bool isWimaxEnabled(); +/** + * Retrieves the status of wimax hardware in the system. This is typically + * controlled by a physical switch so there is no way to set this in software. + * + * @return true if wimax HW networking is enabled, false otherwise + * + * @deprecated Wimax support was removed from NetworkManager 1.2 + * (always returns false in runtime NM >= 1.2.0). + */ +NETWORKMANAGERQT_EXPORT bool isWimaxHardwareEnabled(); + +/** + * Activate a connection using the supplied device. + * + * @param connectionUni unique identifier for the connection to be activated + * @param interfaceUni unique identifier of the network interface to be activated + * @param connectionParameter can be used to specify extra parameters not specific to the NetworkInterface or the connection, eg which AP to use when several + * present with same ESSID in range (because ESSID does not guarantee that the AP is part of the network you want to join!) + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply +activateConnection(const QString &connectionUni, const QString &interfaceUni, const QString &connectionParameter); +/** + * Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the given device and + * specific object), then activate the new connection. Cannot be used for VPN connections at this time. + * + * @param connection connection definition to be added and activated + * @param interfaceUni unique identifier of the network interface to be activated + * @param connectionParameter can be used to specify extra parameters not specific to the NetworkInterface or the connection, eg which AP to use when several + * present with same ESSID in range (because ESSID does not guarantee that the AP is part of the network you want to join!) + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply +addAndActivateConnection(const NMVariantMapMap &connection, const QString &interfaceUni, const QString &connectionParameter); +/** + * Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the given device and + * specific object), then activate the new connection. Cannot be used for VPN connections at this time. + * + * @param connection connection definition to be added and activated + * @param interfaceUni unique identifier of the network interface to be activated + * @param connectionParameter can be used to specify extra parameters not specific to the NetworkInterface or the connection, eg which AP to use when several + * present with same ESSID in range (because ESSID does not guarantee that the AP is part of the network you want to join!) + * @param options further options for the method call. + * + * This method extends AddAndActivateConnection to allow passing further + * parameters. At this time the following options are supported: + * + * * persist: A string value of either "disk" (default), "memory" or "volatile". If "memory" is passed, the connection will not be saved to disk. If + * "volatile" is passed, the connection will not be saved to disk and will be destroyed when disconnected. + * * bind-activation: Bind the activation lifetime. Set to "dbus-name" to automatically disconnect when the requesting process disappears from the bus. + * The default of "none" means the connection is kept activated normally. + * + * NOTE: will call AddAndActivateConnection(connection, interfaceUni, connectionParameter) instead when NetworkManager is older than 1.16, which means that the + * options property is ignored + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply +addAndActivateConnection2(const NMVariantMapMap &connection, const QString &interfaceUni, const QString &connectionParameter, const QVariantMap &options); +/** + * Deactivate this network interface, if active + * + * @param activeConnection identifier of the connection to deactivate + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply<> deactivateConnection(const QString &activeConnection); +/** + * Access the list of any active connections + * + * @return a list of valid ActiveConnection objects + */ +NETWORKMANAGERQT_EXPORT ActiveConnection::List activeConnections(); +/** + * Access the list of any active connections paths + * + * @return a list of valid ActiveConnection paths + */ +NETWORKMANAGERQT_EXPORT QStringList activeConnectionsPaths(); +/** + * Get current logging verbosity level and operations domains + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply getLogging(); + +/** + * @return the network connectivity state + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT Connectivity connectivity(); + +/** + * Re-check the network connectivity state. + * @see connectivity() + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply checkConnectivity(); + +/** + * @return the "primary" active connection being used + * to access the network. In particular, if there is no VPN + * active, or the VPN does not have the default route, then this + * indicates the connection that has the default route. If there + * is a VPN active with the default route, then this indicates + * the connection that contains the route to the VPN endpoint. + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT ActiveConnection::Ptr primaryConnection(); + +/** + * @return an active connection that is currently + * being activated and which is expected to become the new + * primaryConnection() when it finishes activating. + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT ActiveConnection::Ptr activatingConnection(); + +/** + * @return The connection type of the "primary" active connection being + * used to access the network. This is the same as the Type + * property on the object indicated by PrimaryConnection. + * @since 5.8.0 + */ +NETWORKMANAGERQT_EXPORT NetworkManager::ConnectionSettings::ConnectionType primaryConnectionType(); + +/** + * Indicates whether NM is still starting up; this becomes @p false + * when NM has finished attempting to activate every connection + * that it might be able to activate at startup. + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT bool isStartingUp(); + +/** + * @return Indicates whether the connectivity is metered. + * @since 5.14.0 + */ +NETWORKMANAGERQT_EXPORT NetworkManager::Device::MeteredStatus metered(); + +/** + * @return Gets the global DNS configuration. + * @since 5.45.0 + */ +NETWORKMANAGERQT_EXPORT NetworkManager::DnsConfiguration globalDnsConfiguration(); + +/** + * @return Sets the global DNS configuration. + * @since 5.45.0 + */ +NETWORKMANAGERQT_EXPORT void setGlobalDnsConfiguration(const NetworkManager::DnsConfiguration &configuration); + +/** + * Find an ActiveConnection object for an active connection id + * + * @param uni the id of the ActiveConnection + * @return a valid ActiveConnection object + */ +NETWORKMANAGERQT_EXPORT ActiveConnection::Ptr findActiveConnection(const QString &uni); +/** + * Retrieves the interface types supported by this network manager. + * + * @return the interface types supported by the network manager + */ +NETWORKMANAGERQT_EXPORT Device::Types supportedInterfaceTypes(); +NETWORKMANAGERQT_EXPORT void setNetworkingEnabled(bool enabled); +// implemented in Notifier +NETWORKMANAGERQT_EXPORT void setWirelessEnabled(bool enabled); +NETWORKMANAGERQT_EXPORT void setWwanEnabled(bool enabled); +/** + * @deprecated Wimax support was removed from NetworkManager 1.2 + * (it is a noop in runtime NM >= 1.2.0). + */ +NETWORKMANAGERQT_EXPORT void setWimaxEnabled(bool enabled); +NETWORKMANAGERQT_EXPORT void sleep(bool sleep); +NETWORKMANAGERQT_EXPORT void setLogging(LogLevel, LogDomains); +NETWORKMANAGERQT_EXPORT NMStringMap permissions(); +NETWORKMANAGERQT_EXPORT Notifier *notifier(); + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/manager_p.h b/panels/dock/tray/networkmanager-qt/src/manager_p.h new file mode 100644 index 000000000..2b859ffe2 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/manager_p.h @@ -0,0 +1,132 @@ +/* + SPDX-FileCopyrightText: 2008, 2010 Will Stephenson + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_NETWORKMANAGER_P_H +#define NETWORKMANAGERQT_NETWORKMANAGER_P_H + +#include +#include + +#include "activeconnection.h" +#include "dbus/networkmanagerinterface.h" +#include "device.h" + +#include "manager.h" + +namespace NetworkManager +{ +class Device; +class ActiveConnection; + +class NetworkManagerPrivate : public NetworkManager::Notifier +{ + Q_OBJECT +public: + static const QString DBUS_SERVICE; + static const QString DBUS_DAEMON_INTERFACE; + static const QString DBUS_DAEMON_PATH; + static const QString DBUS_SETTINGS_PATH; + static const QString FDO_DBUS_PROPERTIES; + static const QString FDO_DBUS_OBJECT_MANAGER; + + // Functions useful also for other classes + static QVariantMap retrieveInitialProperties(const QString &interfaceName, const QString &path); + + NetworkManagerPrivate(); + ~NetworkManagerPrivate() override; + QDBusServiceWatcher watcher; + OrgFreedesktopNetworkManagerInterface iface; + NetworkManager::Status nmState; + Connectivity m_connectivity; + bool m_isNetworkingEnabled; + bool m_isWimaxEnabled; + // TODO: mark it deprecated somehow? + bool m_isWimaxHardwareEnabled; + bool m_isWirelessEnabled; + bool m_isWirelessHardwareEnabled; + bool m_isWwanEnabled; + bool m_isWwanHardwareEnabled; + QString m_activatingConnection; + QString m_primaryConnection; + NetworkManager::ConnectionSettings::ConnectionType m_primaryConnectionType; + NetworkManager::Device::MeteredStatus m_metered; + NetworkManager::DnsConfiguration m_globalDnsConfiguration; + QString m_version; + // to store NetworkManager's version. + int m_x; + int m_y; + int m_z; + void parseVersion(const QString &version); + int compareVersion(const QString &version); + int compareVersion(const int x, const int y, const int z) const; + bool checkVersion(const int x, const int y, const int z) const; + NetworkManager::Device::Types m_supportedInterfaceTypes; + NetworkManager::Device::Types supportedInterfaceTypes() const; + + QMap m_activeConnections; + ActiveConnection::Ptr findRegisteredActiveConnection(const QString &); + // manage device children + Device::Ptr findRegisteredNetworkInterface(const QString &uni); + Device::Ptr createNetworkInterface(const QString &uni); + QMap networkInterfaceMap; + // for frontend to call + QString version() const; + NetworkManager::Status status() const; + Device::List networkInterfaces(); + Device::Ptr findNetworkInterface(const QString &uni); + Device::Ptr findDeviceByIpIface(const QString &iface); + bool isNetworkingEnabled() const; + bool isWirelessEnabled() const; + bool isWirelessHardwareEnabled() const; + bool isWwanEnabled() const; + bool isWwanHardwareEnabled() const; + bool isWimaxEnabled() const; + // TODO: mark it deprecated somehow? + bool isWimaxHardwareEnabled() const; + QDBusPendingReply activateConnection(const QString &connectionUni, const QString &interfaceUni, const QString &connectionParameter); + QDBusPendingReply + addAndActivateConnection(const NMVariantMapMap &connection, const QString &interfaceUni, const QString &connectionParameter); + QDBusPendingReply + addAndActivateConnection2(const NMVariantMapMap &connection, const QString &interfaceUni, const QString &connectionParameter, const QVariantMap &options); + QDBusPendingReply<> deactivateConnection(const QString &activeConnection); + ActiveConnection::List activeConnections(); + QStringList activeConnectionsPaths() const; + QDBusPendingReply getLogging(); + void setNetworkingEnabled(bool enabled); + void setWirelessEnabled(bool enabled); + void setWwanEnabled(bool enabled); + // TODO: mark it deprecated somehow? + void setWimaxEnabled(bool enabled); + void sleep(bool sleep); + void setLogging(NetworkManager::LogLevel, NetworkManager::LogDomains); + NMStringMap permissions(); + Connectivity connectivity() const; + QDBusPendingReply checkConnectivity(); + ActiveConnection::Ptr primaryConnection(); + ActiveConnection::Ptr activatingConnection(); + NetworkManager::ConnectionSettings::ConnectionType primaryConnectionType(); + bool isStartingUp() const; + NetworkManager::Device::MeteredStatus metered() const; + NetworkManager::DnsConfiguration globalDnsConfiguration() const; + void setGlobalDnsConfiguration(const NetworkManager::DnsConfiguration &configuration); +protected Q_SLOTS: + void init(); + void onDeviceAdded(const QDBusObjectPath &state); + void onDeviceRemoved(const QDBusObjectPath &state); + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void propertiesChanged(const QVariantMap &changedProperties); + void dbusInterfacesAdded(const QDBusObjectPath &path, const QVariantMap &addedInterfaces); + void daemonUnregistered(); + +private: + void connectivityChanged(uint connectivity); + void stateChanged(uint state); + static NetworkManager::Connectivity convertConnectivity(uint connectivity); + static NetworkManager::Status convertNMState(uint state); +}; +} +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/modemdevice.cpp b/panels/dock/tray/networkmanager-qt/src/modemdevice.cpp new file mode 100644 index 000000000..ab59d8ece --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/modemdevice.cpp @@ -0,0 +1,88 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque Souza + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "modemdevice.h" +#include "modemdevice_p.h" + +#include "manager_p.h" + +NetworkManager::ModemDevice::Capabilities convertModemCapabilities(uint theirCaps) +{ + NetworkManager::ModemDevice::Capabilities ourCaps = (NetworkManager::ModemDevice::Capabilities)theirCaps; + return ourCaps; +} + +NetworkManager::ModemDevicePrivate::ModemDevicePrivate(const QString &path, ModemDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , modemIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , modemIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::ModemDevice::ModemDevice(const QString &path, QObject *parent) + : Device(*new ModemDevicePrivate(path, this), parent) +{ + Q_D(ModemDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->modemIface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::ModemDevice::ModemDevice(NetworkManager::ModemDevicePrivate &dd, QObject *parent) + : Device(dd, parent) +{ + Q_D(ModemDevice); + + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->uni, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); +} + +NetworkManager::ModemDevice::~ModemDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::ModemDevice::type() const +{ + return NetworkManager::Device::Modem; +} + +NetworkManager::ModemDevice::Capabilities NetworkManager::ModemDevice::currentCapabilities() const +{ + Q_D(const ModemDevice); + return d->currentCapabilities; +} + +NetworkManager::ModemDevice::Capabilities NetworkManager::ModemDevice::modemCapabilities() const +{ + Q_D(const ModemDevice); + return d->modemCapabilities; +} + +void NetworkManager::ModemDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(ModemDevice); + + if (property == QLatin1String("CurrentCapabilities")) { + currentCapabilities = convertModemCapabilities(value.toUInt()); + Q_EMIT q->currentCapabilitiesChanged(currentCapabilities); + } else if (property == QLatin1String("ModemCapabilities")) { + modemCapabilities = convertModemCapabilities(value.toUInt()); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/modemdevice.h b/panels/dock/tray/networkmanager-qt/src/modemdevice.h new file mode 100644 index 000000000..9e5b61c7e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/modemdevice.h @@ -0,0 +1,70 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_MODEMDEVICE_H +#define NETWORKMANAGERQT_MODEMDEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class ModemDevicePrivate; + +/** + * Represents a generic modem device, generally defined by the modemCapabilities() it exposes and at + * the current point in time by the currentCapabilities(). + */ +class NETWORKMANAGERQT_EXPORT ModemDevice : public Device +{ + Q_OBJECT +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum Capability { + NoCapability = 0x0, + Pots = 0x1, + CdmaEvdo = 0x2, + GsmUmts = 0x4, + Lte = 0x8, + }; + Q_DECLARE_FLAGS(Capabilities, Capability) + explicit ModemDevice(const QString &path, QObject *parent = nullptr); + explicit ModemDevice(ModemDevicePrivate &dd, QObject *parent = nullptr); + ~ModemDevice() override; + /** + * Return the type + */ + Type type() const override; + /** + * The generic family of access technologies the modem supports. Not all capabilities are + * available at the same time however; some modems require a firmware reload or other + * reinitialization to switch between eg CDMA/EVDO and GSM/UMTS. + */ + Capabilities modemCapabilities() const; + /** + * The generic family of access technologies the modem currently supports without a firmware + * reload or reinitialization. + */ + Capabilities currentCapabilities() const; + +Q_SIGNALS: + /** + * This signal is emitted when the capabilities of the device change + */ + void currentCapabilitiesChanged(Capabilities); + +private: + Q_DECLARE_PRIVATE(ModemDevice) +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(ModemDevice::Capabilities) + +} // namespace NetworkManager + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/modemdevice_p.h b/panels/dock/tray/networkmanager-qt/src/modemdevice_p.h new file mode 100644 index 000000000..63971ce53 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/modemdevice_p.h @@ -0,0 +1,38 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ +#ifndef NETWORKMANAGERQT_MODEMDEVICE_P_H +#define NETWORKMANAGERQT_MODEMDEVICE_P_H + +#include "dbus/modemdeviceinterface.h" +#include "device_p.h" + +namespace NetworkManager +{ +class ModemDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + explicit ModemDevicePrivate(const QString &path, ModemDevice *q); + + void initModemProperties(); + + OrgFreedesktopNetworkManagerDeviceModemInterface modemIface; + NetworkManager::ModemDevice::Capabilities modemCapabilities; + NetworkManager::ModemDevice::Capabilities currentCapabilities; + + Q_DECLARE_PUBLIC(ModemDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} // namespace NetworkManager + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/nmdebug.h b/panels/dock/tray/networkmanager-qt/src/nmdebug.h new file mode 100644 index 000000000..1151980a4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/nmdebug.h @@ -0,0 +1,14 @@ +/* + SPDX-FileCopyrightText: 2011-2013 Lamarque Souza + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_NMDEBUG_H +#define NETWORKMANAGERQT_NMDEBUG_H + +#include + +Q_DECLARE_LOGGING_CATEGORY(NMQT) + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice.cpp b/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice.cpp new file mode 100644 index 000000000..2eb3289cf --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice.cpp @@ -0,0 +1,78 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "olpcmeshdevice.h" +#include "manager_p.h" +#include "olpcmeshdevice_p.h" + +#include "wimaxnsp.h" + +NetworkManager::OlpcMeshDevicePrivate::OlpcMeshDevicePrivate(const QString &path, OlpcMeshDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::OlpcMeshDevice::OlpcMeshDevice(const QString &path, QObject *parent) + : Device(*new OlpcMeshDevicePrivate(path, this), parent) +{ + Q_D(OlpcMeshDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::OlpcMeshDevice::~OlpcMeshDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::OlpcMeshDevice::type() const +{ + return NetworkManager::Device::OlpcMesh; +} + +QString NetworkManager::OlpcMeshDevice::hardwareAddress() const +{ + Q_D(const OlpcMeshDevice); + return d->hardwareAddress; +} + +uint NetworkManager::OlpcMeshDevice::activeChannel() const +{ + Q_D(const OlpcMeshDevice); + return d->activeChannel; +} + +NetworkManager::Device::Ptr NetworkManager::OlpcMeshDevice::companionDevice() const +{ + Q_D(const OlpcMeshDevice); + return NetworkManager::findNetworkInterface(d->companion); +} + +void NetworkManager::OlpcMeshDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(OlpcMeshDevice); + + if (property == QLatin1String("ActiveChannel")) { + activeChannel = value.toUInt(); + Q_EMIT q->activeChannelChanged(activeChannel); + } else if (property == QLatin1String("HwAddress")) { + hardwareAddress = value.toString(); + Q_EMIT q->hardwareAddressChanged(hardwareAddress); + } else if (property == QLatin1String("Companion")) { + companion = qdbus_cast(value).path(); + Q_EMIT q->companionChanged(NetworkManager::findNetworkInterface(companion)); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice.h b/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice.h new file mode 100644 index 000000000..f47b8d686 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice.h @@ -0,0 +1,77 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2011-2013 Lamarque Souza + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OLPCMESHDEVICE_H +#define NETWORKMANAGERQT_OLPCMESHDEVICE_H + +#include "device.h" + +#include + +#include + +namespace NetworkManager +{ +class OlpcMeshDevicePrivate; + +/** + * A OLPC mesh interface + */ +class NETWORKMANAGERQT_EXPORT OlpcMeshDevice : public Device +{ + Q_OBJECT + +public: + typedef QSharedPointer Ptr; + typedef QList List; + /** + * Creates a new OlpcMeshDevice object. + * + * @param path the DBus path of the device + */ + explicit OlpcMeshDevice(const QString &path, QObject *parent = nullptr); + /** + * Destroys a OlpcMeshDevice object. + */ + ~OlpcMeshDevice() override; + /** + * Return the type + */ + Type type() const override; + /** + * Currently active channel. + */ + uint activeChannel() const; + /** + * The hardware address currently used by the network interface + */ + QString hardwareAddress() const; + /** + * The current companion device. + */ + Device::Ptr companionDevice() const; + +Q_SIGNALS: + /** + * The active channel changed. + */ + void activeChannelChanged(uint); + /** + * The companion changed. + */ + void companionChanged(const Device::Ptr &device); + /** + * The device changed its hardware address + */ + void hardwareAddressChanged(const QString &); + +private: + Q_DECLARE_PRIVATE(OlpcMeshDevice) +}; + +} // namespace NetworkManager +#endif // NETWORKMANAGERQT_OLPCMESHDEVICE_H diff --git a/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice_p.h b/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice_p.h new file mode 100644 index 000000000..fce1f6b55 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/olpcmeshdevice_p.h @@ -0,0 +1,36 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OLPCMESHDEVICE_P_H +#define NETWORKMANAGERQT_OLPCMESHDEVICE_P_H + +#include "dbus/olpcmeshdeviceinterface.h" +#include "device_p.h" + +namespace NetworkManager +{ +class OlpcMeshDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + explicit OlpcMeshDevicePrivate(const QString &path, OlpcMeshDevice *q); + OrgFreedesktopNetworkManagerDeviceOlpcMeshInterface iface; + uint activeChannel; + QString companion; + QString hardwareAddress; + + Q_DECLARE_PUBLIC(OlpcMeshDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/secretagent.cpp b/panels/dock/tray/networkmanager-qt/src/secretagent.cpp new file mode 100644 index 000000000..30daf1249 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/secretagent.cpp @@ -0,0 +1,139 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "secretagent.h" +#include "manager_p.h" +#include "nmdebug.h" +#include "secretagent_p.h" + +#undef signals +#include +#include + +#define signals Q_SIGNALS + +#include + +#include "agentmanagerinterface.h" +#include "secretagentadaptor.h" + +NetworkManager::SecretAgentPrivate::SecretAgentPrivate(const QString &id, + const NetworkManager::SecretAgent::Capabilities capabilities, + NetworkManager::SecretAgent *parent) + : q_ptr(parent) + , agent(parent) +#ifdef NMQT_STATIC + , agentManager(NetworkManagerPrivate::DBUS_SERVICE, QLatin1String(NM_DBUS_PATH_AGENT_MANAGER), QDBusConnection::sessionBus(), parent) +#else + , agentManager(NetworkManagerPrivate::DBUS_SERVICE, QLatin1String(NM_DBUS_PATH_AGENT_MANAGER), QDBusConnection::systemBus(), parent) +#endif + , agentId(id) + , capabilities(capabilities) +{ + Q_Q(SecretAgent); + + qRegisterMetaType("NMVariantMapMap"); + qDBusRegisterMetaType(); + + agentManager.connection().connect(NetworkManagerPrivate::DBUS_SERVICE, + "/org/freedesktop", + NetworkManagerPrivate::FDO_DBUS_OBJECT_MANAGER, + QLatin1String("InterfacesAdded"), + q, + SLOT(dbusInterfacesAdded(QDBusObjectPath, QVariantMap))); + + agentManager.connection().registerObject(QLatin1String(NM_DBUS_PATH_SECRET_AGENT), &agent, QDBusConnection::ExportAllSlots); + + registerAgent(capabilities); +} + +NetworkManager::SecretAgentPrivate::~SecretAgentPrivate() +{ + agentManager.Unregister(); +} + +void NetworkManager::SecretAgentPrivate::dbusInterfacesAdded(const QDBusObjectPath &path, const QVariantMap &interfaces) +{ + Q_UNUSED(path); + if (!interfaces.contains(QString::fromLatin1(agentManager.staticInterfaceName()))) { + return; + } + + registerAgent(capabilities); +} + +void NetworkManager::SecretAgentPrivate::registerAgent() +{ + agentManager.RegisterWithCapabilities(agentId, NetworkManager::SecretAgent::Capability::NoCapability); +} + +void NetworkManager::SecretAgentPrivate::registerAgent(NetworkManager::SecretAgent::Capabilities capabilities) +{ + agentManager.RegisterWithCapabilities(agentId, capabilities); +} + +NetworkManager::SecretAgent::SecretAgent(const QString &id, QObject *parent) + : QObject(parent) + , QDBusContext() + , d_ptr(new NetworkManager::SecretAgentPrivate(id, NetworkManager::SecretAgent::Capability::NoCapability, this)) +{ +} + +NetworkManager::SecretAgent::SecretAgent(const QString &id, NetworkManager::SecretAgent::Capabilities capabilities, QObject *parent) + : QObject(parent) + , QDBusContext() + , d_ptr(new NetworkManager::SecretAgentPrivate(id, capabilities, this)) +{ +} + +NetworkManager::SecretAgent::~SecretAgent() +{ + Q_D(SecretAgent); + delete d; +} + +void NetworkManager::SecretAgent::sendError(NetworkManager::SecretAgent::Error error, const QString &explanation, const QDBusMessage &callMessage) const +{ + Q_D(const SecretAgent); + + QString errorString; + switch (error) { + case NotAuthorized: + errorString = QStringLiteral(NM_DBUS_INTERFACE_SECRET_AGENT) % QStringLiteral(".NotAuthorized"); + break; + case InvalidConnection: + errorString = QStringLiteral(NM_DBUS_INTERFACE_SECRET_AGENT) % QStringLiteral(".InvalidConnection"); + break; + case UserCanceled: + errorString = QStringLiteral(NM_DBUS_INTERFACE_SECRET_AGENT) % QStringLiteral(".UserCanceled"); + break; + case AgentCanceled: + errorString = QStringLiteral(NM_DBUS_INTERFACE_SECRET_AGENT) % QStringLiteral(".AgentCanceled"); + break; + case InternalError: + errorString = QStringLiteral(NM_DBUS_INTERFACE_SECRET_AGENT) % QStringLiteral(".InternalError"); + break; + case NoSecrets: + errorString = QStringLiteral(NM_DBUS_INTERFACE_SECRET_AGENT) % QStringLiteral(".NoSecrets"); + break; + default: + errorString = QStringLiteral(NM_DBUS_INTERFACE_SECRET_AGENT) % QStringLiteral(".Unknown"); + break; + } + + QDBusMessage reply; + if (callMessage.type() == QDBusMessage::InvalidMessage) { + reply = message().createErrorReply(errorString, explanation); + } else { + reply = callMessage.createErrorReply(errorString, explanation); + } + + if (!d->agentManager.connection().send(reply)) { + qCDebug(NMQT) << "Failed to put error message on DBus queue" << errorString << explanation; + } +} + +#include "moc_secretagent.cpp" diff --git a/panels/dock/tray/networkmanager-qt/src/secretagent.h b/panels/dock/tray/networkmanager-qt/src/secretagent.h new file mode 100644 index 000000000..8b0105a35 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/secretagent.h @@ -0,0 +1,150 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2011-2013 Lamarque Souza + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SECRETAGENT_H +#define NETWORKMANAGERQT_SECRETAGENT_H + +#include +#include +#include +#include + +#include "generictypes.h" +#include + +namespace NetworkManager +{ +class SecretAgentPrivate; + +/** + * Implementation of a private D-Bus interface used by secret agents that store and provide secrets to NetworkManager. + * If an agent provides secrets to NetworkManager as part of connection creation, and the some of those secrets are "agent owned" + * the agent should store those secrets itself and should not expect its SaveSecrets() method to be called. + * SaveSecrets() will be called eg if some program other than the agent itself (like a connection editor) changes the secrets out of band. + */ +class NETWORKMANAGERQT_EXPORT SecretAgent : public QObject, protected QDBusContext +{ + Q_OBJECT +public: + enum Error { + NotAuthorized, + InvalidConnection, + UserCanceled, + AgentCanceled, + InternalError, + NoSecrets, + }; + + /** + * Flags modifying the behavior of GetSecrets request. + */ + enum GetSecretsFlag { + None = 0, /**< No special behavior; by default no user interaction is allowed and requests for secrets are fulfilled from persistent storage, or if no + secrets are available an error is returned. */ + AllowInteraction = 0x01, /**< Allows the request to interact with the user, possibly prompting via UI for secrets if any are required, or if none are + found in persistent storage. */ + RequestNew = 0x02, /**< Explicitly prompt for new secrets from the user. This flag signals that NetworkManager thinks any existing secrets are invalid + or wrong. This flag implies that interaction is allowed. */ + UserRequested = 0x04, /**< Set if the request was initiated by user-requested action via the D-Bus interface, as opposed to automatically initiated by + NetworkManager in response to (for example) scan results or carrier changes. */ + }; + Q_DECLARE_FLAGS(GetSecretsFlags, GetSecretsFlag) + + /** + * Capabilities to pass to secret agents + */ + enum Capability { + NoCapability = 0, /**< No capability */ + VpnHints = 0x01, /**< Pass hints to secret agent */ + }; + Q_DECLARE_FLAGS(Capabilities, Capability) + + /** + * Registers a SecretAgent with the \p id on NetworkManager + * Optionally add a capabilities argument + */ + explicit SecretAgent(const QString &id, QObject *parent = nullptr); + explicit SecretAgent(const QString &id, NetworkManager::SecretAgent::Capabilities capabilities, QObject *parent = nullptr); + ~SecretAgent() override; + + /** + * Send to NetworkManager the \p error the subclass has + * found, the \p explanation is useful for debugging purposes, + * and the \p callMessage is ONLY needed if \ref setDelayedReply() + * was set to @p true when the method was called. + */ + void sendError(Error error, const QString &explanation, const QDBusMessage &callMessage = QDBusMessage()) const; + +public Q_SLOTS: + /** + * Called when the subclass should retrieve and return secrets. + * If the request is canceled, called function should call + * \ref sendError(), in this case the return value is ignored. + * + * @param connection Nested settings maps containing the connection for which secrets are being requested. + * This may contain system-owned secrets if the agent has successfully authenticated to modify system network settings + * and the GetSecrets request flags allow user interaction. + * @param connection_path Object path of the connection for which secrets are being requested. + * @param setting_name Setting name for which secrets are being requested. + * @param hints Array of strings of key names in the requested setting for which NetworkManager thinks a secrets may be required, + * and/or well-known identifiers and data that may be useful to the client in processing the secrets request. Note that it's not + * always possible to determine which secret is required, so in some cases no hints may be given. The Agent should return any + * secrets it has, or that it thinks are required, regardless of what hints NetworkManager sends in this request. + * @param flags Flags which modify the behavior of the secrets request (see @ref GetSecretsFlag) + */ + virtual NMVariantMapMap GetSecrets(const NMVariantMapMap &connection, + const QDBusObjectPath &connection_path, + const QString &setting_name, + const QStringList &hints, + uint flags) = 0; + + /** + * Called when the subclass should cancel an outstanding request to + * get secrets for a given connection. + * Cancelling the request MUST \ref sendError() with the original + * DBus message using \ref AgentCanceled param as the error type. + * + * @param connection_path Object path of the connection for which, if secrets for the given 'setting_name' are being requested, the request should be + * canceled. + * @param setting_name Setting name for which secrets for this connection were originally being requested. + */ + virtual void CancelGetSecrets(const QDBusObjectPath &connection_path, const QString &setting_name) = 0; + + /** + * Called when the subclass should save the secrets contained in the + * connection to backing storage. + * + * @param connection Nested settings maps containing the connection for which secrets are being saved. + * This may contain system-owned secrets if the agent has successfully authenticated to modify system network settings + * and the GetSecrets request flags allow user interaction. + * @param connection_path Object path of the connection for which the agent should save secrets to backing storage. + */ + virtual void SaveSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) = 0; + + /** + * Called when the subclass should delete the secrets contained in the + * connection from backing storage. + * + * @param connection Nested settings maps containing the connection properties (sans secrets), + * for which the agent should delete the secrets from backing storage. + * @param connection_path Object path of the connection for which the agent should delete secrets from backing storage. + */ + virtual void DeleteSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) = 0; + +private: + Q_DECLARE_PRIVATE(SecretAgent) + Q_PRIVATE_SLOT(d_func(), void registerAgent()) + Q_PRIVATE_SLOT(d_func(), void registerAgent(const NetworkManager::SecretAgent::Capabilities capabilities)) + Q_PRIVATE_SLOT(d_func(), void dbusInterfacesAdded(const QDBusObjectPath &path, const QVariantMap &interfaces)) + + SecretAgentPrivate *const d_ptr; +}; +} +Q_DECLARE_OPERATORS_FOR_FLAGS(NetworkManager::SecretAgent::GetSecretsFlags) +Q_DECLARE_OPERATORS_FOR_FLAGS(NetworkManager::SecretAgent::Capabilities) + +#endif // NETWORKMANAGERQT_SECRETAGENT_H diff --git a/panels/dock/tray/networkmanager-qt/src/secretagent_p.h b/panels/dock/tray/networkmanager-qt/src/secretagent_p.h new file mode 100644 index 000000000..442677462 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/secretagent_p.h @@ -0,0 +1,37 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SECRETAGENT_P_H +#define NETWORKMANAGERQT_SECRETAGENT_P_H + +#include "agentmanagerinterface.h" +#include "secretagentadaptor.h" + +namespace NetworkManager +{ +class SecretAgent; +class SecretAgentPrivate +{ + Q_DECLARE_PUBLIC(SecretAgent) +public: + explicit SecretAgentPrivate(const QString &, SecretAgent *parent = nullptr); + explicit SecretAgentPrivate(const QString &, const NetworkManager::SecretAgent::Capabilities, SecretAgent *parent = nullptr); + virtual ~SecretAgentPrivate(); +private Q_SLOTS: + void dbusInterfacesAdded(const QDBusObjectPath &path, const QVariantMap &interfaces); + void registerAgent(); + void registerAgent(const NetworkManager::SecretAgent::Capabilities capabilities); + +private: + SecretAgent *q_ptr; + SecretAgentAdaptor agent; + OrgFreedesktopNetworkManagerAgentManagerInterface agentManager; + QString agentId; + NetworkManager::SecretAgent::Capabilities capabilities; +}; +} + +#endif // NETWORKMANAGERQT_SECRETAGENT_P_H \ No newline at end of file diff --git a/panels/dock/tray/networkmanager-qt/src/settings.cpp b/panels/dock/tray/networkmanager-qt/src/settings.cpp new file mode 100644 index 000000000..038e65705 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings.cpp @@ -0,0 +1,267 @@ +/* + SPDX-FileCopyrightText: 2011-2013 Lamarque Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "settings.h" +#include "macros.h" +#include "manager_p.h" +#include "settings_p.h" + +#include + +#include + +#include "nmdebug.h" + +// NM_GLOBAL_STATIC(NetworkManager::SettingsPrivate, globalSettings) +Q_GLOBAL_STATIC(NetworkManager::SettingsPrivate, globalSettings) + +NetworkManager::SettingsPrivate::SettingsPrivate() +#ifdef NMQT_STATIC + : iface(NetworkManagerPrivate::DBUS_SERVICE, NetworkManagerPrivate::DBUS_SETTINGS_PATH, QDBusConnection::sessionBus()) +#else + : iface(NetworkManagerPrivate::DBUS_SERVICE, NetworkManagerPrivate::DBUS_SETTINGS_PATH, QDBusConnection::systemBus()) +#endif + , m_canModify(true) +{ + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + NetworkManagerPrivate::DBUS_SETTINGS_PATH, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + this, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + connect(&iface, &OrgFreedesktopNetworkManagerSettingsInterface::NewConnection, this, &SettingsPrivate::onConnectionAdded); + connect(&iface, + &OrgFreedesktopNetworkManagerSettingsInterface::ConnectionRemoved, + this, + static_cast(&SettingsPrivate::onConnectionRemoved)); + init(); + // This class is a friend of NetworkManagerPrivate thus initted there too + // because of the init chain we must follow, + // But if this class is used first we need to make sure the + // NetworkManagerPrivate also get created so we have its signals for + // when the daemon dies, we just can not call it directly here or + // we will have a constructor infinite loop + QTimer::singleShot(0, this, SLOT(initNotifier())); +} + +void NetworkManager::SettingsPrivate::init() +{ + const QList connectionList = iface.connections(); + qCDebug(NMQT) << "Connections list"; + for (const QDBusObjectPath &connection : connectionList) { + if (!connections.contains(connection.path())) { + connections.insert(connection.path(), Connection::Ptr()); + Q_EMIT connectionAdded(connection.path()); + qCDebug(NMQT) << " " << connection.path(); + } + } + + // Get all Setting's properties at once + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(iface.staticInterfaceName(), NetworkManagerPrivate::DBUS_SETTINGS_PATH); + if (!initialProperties.isEmpty()) { + propertiesChanged(initialProperties); + } +} + +NetworkManager::Connection::List NetworkManager::SettingsPrivate::listConnections() +{ + NetworkManager::Connection::List list; + QMap::const_iterator i = connections.constBegin(); + while (i != connections.constEnd()) { + NetworkManager::Connection::Ptr connection = findRegisteredConnection(i.key()); + if (connection) { + list << connection; + } + ++i; + } + return list; +} + +NetworkManager::Connection::Ptr NetworkManager::SettingsPrivate::findConnectionByUuid(const QString &uuid) +{ + QMap::const_iterator i = connections.constBegin(); + while (i != connections.constEnd()) { + NetworkManager::Connection::Ptr connection = findRegisteredConnection(i.key()); + if (connection && connection->uuid() == uuid) { + return connection; + } + ++i; + } + + return NetworkManager::Connection::Ptr(); +} + +QString NetworkManager::SettingsPrivate::hostname() const +{ + return m_hostname; +} + +bool NetworkManager::SettingsPrivate::canModify() const +{ + return m_canModify; +} + +QDBusPendingReply NetworkManager::SettingsPrivate::addConnection(const NMVariantMapMap &connection) +{ + return iface.AddConnection(connection); +} + +QDBusPendingReply NetworkManager::SettingsPrivate::addConnectionUnsaved(const NMVariantMapMap &connection) +{ + return iface.AddConnectionUnsaved(connection); +} + +QDBusPendingReply NetworkManager::SettingsPrivate::loadConnections(const QStringList &filenames) +{ + return iface.LoadConnections(filenames); +} + +QDBusPendingReply NetworkManager::SettingsPrivate::reloadConnections() +{ + return iface.ReloadConnections(); +} + +void NetworkManager::SettingsPrivate::initNotifier() +{ + notifier(); +} + +void NetworkManager::SettingsPrivate::saveHostname(const QString &hostname) +{ + iface.SaveHostname(hostname); +} + +void NetworkManager::SettingsPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.Settings")) { + propertiesChanged(properties); + } +} + +void NetworkManager::SettingsPrivate::propertiesChanged(const QVariantMap &properties) +{ + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + const QString property = it.key(); + if (property == QLatin1String("CanModify")) { + m_canModify = it->toBool(); + Q_EMIT canModifyChanged(m_canModify); + } else if (property == QLatin1String("Hostname")) { + m_hostname = it->toString(); + Q_EMIT hostnameChanged(m_hostname); + } else if (property == QLatin1String("Connections")) { + // will never get here in runtime NM < 0.9.10 + // TODO some action?? + } else { + qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } + ++it; + } +} + +void NetworkManager::SettingsPrivate::onConnectionAdded(const QDBusObjectPath &path) +{ + const QString id = path.path(); + if (connections.contains(id)) { + return; + } + connections.insert(id, Connection::Ptr()); + Q_EMIT connectionAdded(id); +} + +NetworkManager::Connection::Ptr NetworkManager::SettingsPrivate::findRegisteredConnection(const QString &path) +{ + Connection::Ptr ret; + if (!path.isEmpty()) { + bool contains = connections.contains(path); + if (contains && connections.value(path)) { + ret = connections.value(path); + } else { + ret = Connection::Ptr(new Connection(path), &QObject::deleteLater); + connections[path] = ret; + connect(ret.data(), SIGNAL(removed(QString)), this, SLOT(onConnectionRemoved(QString))); + if (!contains) { + Q_EMIT connectionAdded(path); + } + } + } + return ret; +} + +void NetworkManager::SettingsPrivate::onConnectionRemoved(const QDBusObjectPath &path) +{ + onConnectionRemoved(path.path()); +} + +void NetworkManager::SettingsPrivate::onConnectionRemoved(const QString &path) +{ + connections.remove(path); + Q_EMIT connectionRemoved(path); +} + +void NetworkManager::SettingsPrivate::daemonUnregistered() +{ + connections.clear(); +} + +NetworkManager::Connection::List NetworkManager::listConnections() +{ + return globalSettings->listConnections(); +} + +NetworkManager::Connection::Ptr NetworkManager::findConnectionByUuid(const QString &uuid) +{ + return globalSettings->findConnectionByUuid(uuid); +} + +NetworkManager::Connection::Ptr NetworkManager::findConnection(const QString &path) +{ + return globalSettings->findRegisteredConnection(path); +} + +QDBusPendingReply NetworkManager::addConnection(const NMVariantMapMap &connection) +{ + return globalSettings->addConnection(connection); +} + +QDBusPendingReply NetworkManager::addConnectionUnsaved(const NMVariantMapMap &connection) +{ + return globalSettings->addConnectionUnsaved(connection); +} + +QDBusPendingReply NetworkManager::loadConnections(const QStringList &filenames) +{ + return globalSettings->loadConnections(filenames); +} + +QDBusPendingReply NetworkManager::reloadConnections() +{ + return globalSettings->reloadConnections(); +} + +void NetworkManager::saveHostname(const QString &hostname) +{ + globalSettings->saveHostname(hostname); +} + +bool NetworkManager::canModify() +{ + return globalSettings->canModify(); +} + +QString NetworkManager::hostname() +{ + return globalSettings->hostname(); +} + +NetworkManager::SettingsNotifier *NetworkManager::settingsNotifier() +{ + return globalSettings; +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings.h b/panels/dock/tray/networkmanager-qt/src/settings.h new file mode 100644 index 000000000..e55cd14d9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings.h @@ -0,0 +1,165 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SETTINGS_H +#define NETWORKMANAGERQT_SETTINGS_H + +#include + +#include "connection.h" +#include "generictypes.h" +#include "manager.h" +#include + +#include + +namespace NetworkManager +{ +/** + * This class manages provides access to connections and notify about new ones + */ +class NETWORKMANAGERQT_EXPORT SettingsNotifier : public QObject +{ + Q_OBJECT +Q_SIGNALS: + /** + * Emitted when the settings are modifiable by user + * @param canModify @p true if the user can modify the settings + */ + void canModifyChanged(bool canModify); + /** + * Emitted when the hostname has changed + * @param hostname new hostname + */ + void hostnameChanged(const QString &hostname); + /** + * Emitted when a new connection is added + * + * \note This signal is not emitted when the Network Manager + * daemon starts, if you are interested in keeping an + * updated listing of connections you must also watch for + * NetworkManager::Notifier::serviceAppeared() and + * NetworkManager::Notifier::serviceDisappeared() signals + */ + void connectionAdded(const QString &path); + /** + * Emitted when a new connection is removed + * + * \note This signal is not emitted when the Network Manager + * daemon starts, if you are interested in keeping an + * updated listing of connections you must also watch for + * NetworkManager::Notifier::serviceAppeared() and + * NetworkManager::Notifier::serviceDisappeared() signals + */ + void connectionRemoved(const QString &path); +}; +/** + * Retrieves the list of connections. + */ +NETWORKMANAGERQT_EXPORT NetworkManager::Connection::List listConnections(); + +/** + * Retrieves the connection for the given path, returns null if not found + */ +NETWORKMANAGERQT_EXPORT NetworkManager::Connection::Ptr findConnection(const QString &path); + +/** + * Add new connection and save it to disk. This operation does not start + * the network connection unless (1) device is idle and able to connect to + * the network described by the new connection, and (2) the connection + * is allowed to be started automatically. + * Once the connection has been added, you will get a notification through + * SettingsNotifier::connectionAddComplete() + * + * @returns Uuid of the new connection that was just added. + * + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply addConnection(const NMVariantMapMap &settings); + +/** + * Add new connection but do not save it to disk immediately. This + * operation does not start the network connection unless (1) device is + * idle and able to connect to the network described by the new connection, + * and (2) the connection is allowed to be started automatically. + * + * Use the 'Save' method on the connection to save these changes + * to disk. Note that unsaved changes will be lost if the + * connection is reloaded from disk (either automatically on file + * change or due to an explicit ReloadConnections call). + * + * Once the connection has been added, you will get a notification through + * SettingsNotifier::connectionAddComplete() + * + * @returns Uuid of the new connection that was just added. + * + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply addConnectionUnsaved(const NMVariantMapMap &settings); + +/** + * Retrieves the connection for the given @p uuid, returns null if not found + */ +NETWORKMANAGERQT_EXPORT NetworkManager::Connection::Ptr findConnectionByUuid(const QString &uuid); + +/** + * Loads or reloads the indicated connections from disk. You + * should call this after making changes directly to an on-disk + * connection file to make sure that NetworkManager sees the + * changes. (If "monitor-connection-files" in NetworkManager.conf + * is "true", then this will have no real effect, but is + * harmless.) As with AddConnection(), this operation does not + * necessarily start the network connection. + * + * @returns Success or failure of the operation as a whole. True if + * NetworkManager at least tried to load the indicated + * connections, even if it did not succeed. False if an error + * occurred before trying to load the connections (eg, + * permission denied). + * + * @returns Paths of connection files that could not be loaded. + * + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply loadConnections(const QStringList &filenames); + +/** + * Tells NetworkManager to reload all connection files from disk, + * including noticing any added or deleted connection files. By + * default, connections are re-read automatically any time they + * change, so you only need to use this command if you have set + * "monitor-connection-files=false" in NetworkManager.conf. + * + * @returns Success or failure. + * + * @since 0.9.9.0 + */ +NETWORKMANAGERQT_EXPORT QDBusPendingReply reloadConnections(); + +/** + * Configure the following hostname + */ +NETWORKMANAGERQT_EXPORT void saveHostname(const QString &hostname); + +/** + * Returns @p true if the user can modify the settings + */ +NETWORKMANAGERQT_EXPORT bool canModify(); + +/** + * Returns hostname of the machine + */ +NETWORKMANAGERQT_EXPORT QString hostname(); + +/** + * Notifier object for connecting signals + */ +NETWORKMANAGERQT_EXPORT SettingsNotifier *settingsNotifier(); +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/settings/adslsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/adslsetting.cpp new file mode 100644 index 000000000..92fe18e2e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/adslsetting.cpp @@ -0,0 +1,275 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "adslsetting.h" +#include "adslsetting_p.h" +#include + +#include + +NetworkManager::AdslSettingPrivate::AdslSettingPrivate() + : name(NM_SETTING_ADSL_SETTING_NAME) + , passwordFlags(Setting::None) + , protocol(AdslSetting::UnknownProtocol) + , encapsulation(AdslSetting::UnknownEncapsulation) + , vpi(0) + , vci(0) +{ +} + +NetworkManager::AdslSetting::AdslSetting() + : Setting(Setting::Adsl) + , d_ptr(new AdslSettingPrivate()) +{ +} + +NetworkManager::AdslSetting::AdslSetting(const AdslSetting::Ptr &other) + : Setting(other) + , d_ptr(new AdslSettingPrivate()) +{ + setUsername(other->username()); + setPassword(other->password()); + setProtocol(other->protocol()); + setPasswordFlags(other->passwordFlags()); + setProtocol(other->protocol()); + setEncapsulation(other->encapsulation()); + setVpi(other->vpi()); + setVci(other->vci()); +} + +NetworkManager::AdslSetting::~AdslSetting() +{ + delete d_ptr; +} + +QString NetworkManager::AdslSetting::name() const +{ + Q_D(const AdslSetting); + + return d->name; +} + +void NetworkManager::AdslSetting::setUsername(const QString &username) +{ + Q_D(AdslSetting); + + d->username = username; +} + +QString NetworkManager::AdslSetting::username() const +{ + Q_D(const AdslSetting); + + return d->username; +} + +void NetworkManager::AdslSetting::setPassword(const QString &password) +{ + Q_D(AdslSetting); + + d->password = password; +} + +QString NetworkManager::AdslSetting::password() const +{ + Q_D(const AdslSetting); + + return d->password; +} + +void NetworkManager::AdslSetting::setPasswordFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(AdslSetting); + + d->passwordFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::AdslSetting::passwordFlags() const +{ + Q_D(const AdslSetting); + + return d->passwordFlags; +} + +void NetworkManager::AdslSetting::setProtocol(NetworkManager::AdslSetting::Protocol protocol) +{ + Q_D(AdslSetting); + + d->protocol = protocol; +} + +NetworkManager::AdslSetting::Protocol NetworkManager::AdslSetting::protocol() const +{ + Q_D(const AdslSetting); + + return d->protocol; +} + +void NetworkManager::AdslSetting::setEncapsulation(NetworkManager::AdslSetting::Encapsulation encapsulation) +{ + Q_D(AdslSetting); + + d->encapsulation = encapsulation; +} + +NetworkManager::AdslSetting::Encapsulation NetworkManager::AdslSetting::encapsulation() const +{ + Q_D(const AdslSetting); + + return d->encapsulation; +} + +void NetworkManager::AdslSetting::setVpi(quint32 vpi) +{ + Q_D(AdslSetting); + + d->vpi = vpi; +} + +quint32 NetworkManager::AdslSetting::vpi() const +{ + Q_D(const AdslSetting); + + return d->vpi; +} + +void NetworkManager::AdslSetting::setVci(quint32 vci) +{ + Q_D(AdslSetting); + + d->vci = vci; +} + +quint32 NetworkManager::AdslSetting::vci() const +{ + Q_D(const AdslSetting); + + return d->vci; +} + +QStringList NetworkManager::AdslSetting::needSecrets(bool requestNew) const +{ + QStringList secrets; + + if ((password().isEmpty() || requestNew) && !passwordFlags().testFlag(NotRequired)) { + secrets << QLatin1String(NM_SETTING_ADSL_PASSWORD); + } + + return secrets; +} + +void NetworkManager::AdslSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_ADSL_USERNAME))) { + setUsername(setting.value(QLatin1String(NM_SETTING_ADSL_USERNAME)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_ADSL_PASSWORD))) { + setPassword(setting.value(QLatin1String(NM_SETTING_ADSL_PASSWORD)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_ADSL_PASSWORD_FLAGS))) { + setPasswordFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_ADSL_PASSWORD_FLAGS)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_ADSL_PROTOCOL))) { + const QString protocol = setting.value(QLatin1String(NM_SETTING_ADSL_PROTOCOL)).toString(); + + if (protocol == QLatin1String(NM_SETTING_ADSL_PROTOCOL_PPPOA)) { + setProtocol(Pppoa); + } else if (protocol == QLatin1String(NM_SETTING_ADSL_PROTOCOL_PPPOE)) { + setProtocol(Pppoe); + } else if (protocol == QLatin1String(NM_SETTING_ADSL_PROTOCOL_IPOATM)) { + setProtocol(Ipoatm); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_ADSL_ENCAPSULATION))) { + const QString encapsulation = setting.value(QLatin1String(NM_SETTING_ADSL_ENCAPSULATION)).toString(); + + if (encapsulation == QLatin1String(NM_SETTING_ADSL_ENCAPSULATION_VCMUX)) { + setEncapsulation(Vcmux); + } else if (encapsulation == QLatin1String(NM_SETTING_ADSL_ENCAPSULATION_LLC)) { + setEncapsulation(Llc); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_ADSL_VPI))) { + setVpi(setting.value(QLatin1String(NM_SETTING_ADSL_VPI)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_ADSL_VCI))) { + setVci(setting.value(QLatin1String(NM_SETTING_ADSL_VCI)).toUInt()); + } +} + +QVariantMap NetworkManager::AdslSetting::toMap() const +{ + QVariantMap setting; + + if (!username().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_ADSL_USERNAME), username()); + } + + if (!password().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_ADSL_PASSWORD), password()); + } + + if (passwordFlags() != None) { + setting.insert(QLatin1String(NM_SETTING_ADSL_PASSWORD_FLAGS), (int)passwordFlags()); + } + + switch (protocol()) { + case Pppoa: + setting.insert(QLatin1String(NM_SETTING_ADSL_PROTOCOL), QLatin1String(NM_SETTING_ADSL_PROTOCOL_PPPOA)); + break; + case Pppoe: + setting.insert(QLatin1String(NM_SETTING_ADSL_PROTOCOL), QLatin1String(NM_SETTING_ADSL_PROTOCOL_PPPOE)); + break; + case Ipoatm: + setting.insert(QLatin1String(NM_SETTING_ADSL_PROTOCOL), QLatin1String(NM_SETTING_ADSL_PROTOCOL_IPOATM)); + break; + case UnknownProtocol: + break; + } + + switch (encapsulation()) { + case Vcmux: + setting.insert(QLatin1String(NM_SETTING_ADSL_ENCAPSULATION), QLatin1String(NM_SETTING_ADSL_ENCAPSULATION_VCMUX)); + break; + case Llc: + setting.insert(QLatin1String(NM_SETTING_ADSL_ENCAPSULATION), QLatin1String(NM_SETTING_ADSL_ENCAPSULATION_LLC)); + break; + case UnknownEncapsulation: + break; + } + + if (vpi()) { + setting.insert(QLatin1String(NM_SETTING_ADSL_VPI), vpi()); + } + + if (vci()) { + setting.insert(QLatin1String(NM_SETTING_ADSL_VCI), vci()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::AdslSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_ADSL_USERNAME << ": " << setting.username() << '\n'; + dbg.nospace() << NM_SETTING_ADSL_PASSWORD << ": " << setting.password() << '\n'; + dbg.nospace() << NM_SETTING_ADSL_PASSWORD_FLAGS << ": " << setting.passwordFlags() << '\n'; + dbg.nospace() << NM_SETTING_ADSL_PROTOCOL << ": " << setting.protocol() << '\n'; + dbg.nospace() << NM_SETTING_ADSL_ENCAPSULATION << ": " << setting.encapsulation() << '\n'; + dbg.nospace() << NM_SETTING_ADSL_VPI << ": " << setting.vpi() << '\n'; + dbg.nospace() << NM_SETTING_ADSL_VCI << ": " << setting.vci() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/adslsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/adslsetting.h new file mode 100644 index 000000000..dd4d64bc9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/adslsetting.h @@ -0,0 +1,83 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_ADSL_SETTING_H +#define NETWORKMANAGERQT_ADSL_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class AdslSettingPrivate; + +/** + * Represents adsl setting + */ +class NETWORKMANAGERQT_EXPORT AdslSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum Protocol { + UnknownProtocol = 0, + Pppoa, + Pppoe, + Ipoatm, + }; + enum Encapsulation { + UnknownEncapsulation = 0, + Vcmux, + Llc, + }; + + AdslSetting(); + explicit AdslSetting(const Ptr &other); + ~AdslSetting() override; + + QString name() const override; + + void setUsername(const QString &username); + QString username() const; + + void setPassword(const QString &password); + QString password() const; + + void setPasswordFlags(SecretFlags flags); + SecretFlags passwordFlags() const; + + void setProtocol(Protocol protocol); + Protocol protocol() const; + + void setEncapsulation(Encapsulation encapsulation); + Encapsulation encapsulation() const; + + void setVpi(quint32 vpi); + quint32 vpi() const; + + void setVci(quint32 vci); + quint32 vci() const; + + QStringList needSecrets(bool requestNew = false) const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + AdslSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(AdslSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const AdslSetting &setting); + +} + +#endif // NETWORKMANAGERQT_ADSL_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/adslsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/adslsetting_p.h new file mode 100644 index 000000000..a18945228 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/adslsetting_p.h @@ -0,0 +1,31 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_ADSL_SETTING_P_H +#define NETWORKMANAGERQT_ADSL_SETTING_P_H + +#include + +namespace NetworkManager +{ +class AdslSettingPrivate +{ +public: + AdslSettingPrivate(); + + QString name; + QString username; + QString password; + NetworkManager::Setting::SecretFlags passwordFlags; + NetworkManager::AdslSetting::Protocol protocol; + NetworkManager::AdslSetting::Encapsulation encapsulation; + quint32 vpi; + quint32 vci; +}; + +} + +#endif // NETWORKMANAGERQT_ADSL_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting.cpp new file mode 100644 index 000000000..ae44884c1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting.cpp @@ -0,0 +1,120 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "bluetoothsetting.h" +#include "bluetoothsetting_p.h" + +#include + +NetworkManager::BluetoothSettingPrivate::BluetoothSettingPrivate() + : name(NM_SETTING_BLUETOOTH_SETTING_NAME) + , profileType(BluetoothSetting::Unknown) +{ +} + +NetworkManager::BluetoothSetting::BluetoothSetting() + : Setting(Setting::Bluetooth) + , d_ptr(new BluetoothSettingPrivate()) +{ +} + +NetworkManager::BluetoothSetting::BluetoothSetting(const Ptr &other) + : Setting(other) + , d_ptr(new BluetoothSettingPrivate()) +{ + setBluetoothAddress(other->bluetoothAddress()); + setProfileType(other->profileType()); +} + +NetworkManager::BluetoothSetting::~BluetoothSetting() +{ + delete d_ptr; +} + +QString NetworkManager::BluetoothSetting::name() const +{ + Q_D(const BluetoothSetting); + + return d->name; +} + +void NetworkManager::BluetoothSetting::setBluetoothAddress(const QByteArray &address) +{ + Q_D(BluetoothSetting); + + d->bdaddr = address; +} + +QByteArray NetworkManager::BluetoothSetting::bluetoothAddress() const +{ + Q_D(const BluetoothSetting); + + return d->bdaddr; +} + +void NetworkManager::BluetoothSetting::setProfileType(NetworkManager::BluetoothSetting::ProfileType type) +{ + Q_D(BluetoothSetting); + + d->profileType = type; +} + +NetworkManager::BluetoothSetting::ProfileType NetworkManager::BluetoothSetting::profileType() const +{ + Q_D(const BluetoothSetting); + + return d->profileType; +} + +void NetworkManager::BluetoothSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR))) { + setBluetoothAddress(setting.value(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BLUETOOTH_TYPE))) { + const QString type = setting.value(QLatin1String(NM_SETTING_BLUETOOTH_TYPE)).toString(); + + if (type == QLatin1String(NM_SETTING_BLUETOOTH_TYPE_DUN)) { + setProfileType(Dun); + } else if (type == QLatin1String(NM_SETTING_BLUETOOTH_TYPE_PANU)) { + setProfileType(Panu); + } + } +} + +QVariantMap NetworkManager::BluetoothSetting::toMap() const +{ + QVariantMap setting; + + if (!bluetoothAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR), bluetoothAddress()); + } + + switch (profileType()) { + case Dun: + setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_TYPE), QLatin1String(NM_SETTING_BLUETOOTH_TYPE_DUN)); + break; + case Panu: + setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_TYPE), QLatin1String(NM_SETTING_BLUETOOTH_TYPE_PANU)); + break; + case Unknown: + break; + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BluetoothSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_BLUETOOTH_BDADDR << ": " << setting.bluetoothAddress() << '\n'; + dbg.nospace() << NM_SETTING_BLUETOOTH_TYPE << ": " << setting.profileType() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting.h new file mode 100644 index 000000000..e9e3be7e0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting.h @@ -0,0 +1,60 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BLUETOOTH_SETTING_H +#define NETWORKMANAGERQT_BLUETOOTH_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class BluetoothSettingPrivate; + +/** + * Represents bluetooth setting + */ +class NETWORKMANAGERQT_EXPORT BluetoothSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum ProfileType { + Unknown = 0, + Dun, + Panu, + }; + + BluetoothSetting(); + explicit BluetoothSetting(const Ptr &other); + ~BluetoothSetting() override; + + QString name() const override; + + void setBluetoothAddress(const QByteArray &address); + QByteArray bluetoothAddress() const; + + void setProfileType(ProfileType type); + ProfileType profileType() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + BluetoothSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(BluetoothSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const BluetoothSetting &setting); + +} + +#endif // NETWORKMANAGERQT_SETTINGS_BLUETOOTH_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting_p.h new file mode 100644 index 000000000..6abc1517f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bluetoothsetting_p.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BLUETOOTH_SETTING_P_H +#define NETWORKMANAGERQT_BLUETOOTH_SETTING_P_H + +#include + +namespace NetworkManager +{ +class BluetoothSettingPrivate +{ +public: + BluetoothSettingPrivate(); + + QString name; + QByteArray bdaddr; + NetworkManager::BluetoothSetting::ProfileType profileType; +}; + +} + +#endif // NETWORKMANAGERQT_BLUETOOTH_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bondsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/bondsetting.cpp new file mode 100644 index 000000000..9ec6bdd0d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bondsetting.cpp @@ -0,0 +1,113 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "bondsetting.h" +#include "bondsetting_p.h" + +#define NM_SETTING_BOND_INTERFACE_NAME "interface-name" + +#include + +NetworkManager::BondSettingPrivate::BondSettingPrivate() + : name(NM_SETTING_BOND_SETTING_NAME) +{ +} + +NetworkManager::BondSetting::BondSetting() + : Setting(Setting::Bond) + , d_ptr(new BondSettingPrivate()) +{ +} + +NetworkManager::BondSetting::BondSetting(const Ptr &other) + : Setting(other) + , d_ptr(new BondSettingPrivate()) +{ + setInterfaceName(other->interfaceName()); + setOptions(other->options()); +} + +NetworkManager::BondSetting::~BondSetting() +{ + delete d_ptr; +} + +QString NetworkManager::BondSetting::name() const +{ + Q_D(const BondSetting); + + return d->name; +} + +void NetworkManager::BondSetting::setInterfaceName(const QString &name) +{ + Q_D(BondSetting); + + d->interfaceName = name; +} + +QString NetworkManager::BondSetting::interfaceName() const +{ + Q_D(const BondSetting); + + return d->interfaceName; +} + +void NetworkManager::BondSetting::addOption(const QString &option, const QString &value) +{ + Q_D(BondSetting); + + d->options.insert(option, value); +} + +void NetworkManager::BondSetting::setOptions(const NMStringMap &options) +{ + Q_D(BondSetting); + + d->options = options; +} + +NMStringMap NetworkManager::BondSetting::options() const +{ + Q_D(const BondSetting); + + return d->options; +} + +void NetworkManager::BondSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_BOND_INTERFACE_NAME))) { + setInterfaceName(setting.value(QLatin1String(NM_SETTING_BOND_INTERFACE_NAME)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BOND_OPTIONS))) { + setOptions(qdbus_cast(setting.value(QLatin1String(NM_SETTING_BOND_OPTIONS)))); + } +} + +QVariantMap NetworkManager::BondSetting::toMap() const +{ + QVariantMap setting; + if (!interfaceName().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_BOND_INTERFACE_NAME), interfaceName()); + } + if (!options().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_BOND_OPTIONS), QVariant::fromValue(options())); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BondSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_BOND_INTERFACE_NAME << ": " << setting.interfaceName() << '\n'; + dbg.nospace() << NM_SETTING_BOND_OPTIONS << ": " << setting.options() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bondsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/bondsetting.h new file mode 100644 index 000000000..5bb73cc7c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bondsetting.h @@ -0,0 +1,56 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BOND_SETTING_H +#define NETWORKMANAGERQT_BOND_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class BondSettingPrivate; + +/** + * Represents bond setting + */ +class NETWORKMANAGERQT_EXPORT BondSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + BondSetting(); + explicit BondSetting(const Ptr &other); + ~BondSetting() override; + + QString name() const override; + + /// @deprecated in favor of connection.interface-name in NM 1.0.0 + void setInterfaceName(const QString &name); + QString interfaceName() const; + + void addOption(const QString &option, const QString &value); + void setOptions(const NMStringMap &options); + NMStringMap options() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + BondSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(BondSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const BondSetting &setting); + +} + +#endif // NETWORKMANAGERQT_BOND_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bondsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/bondsetting_p.h new file mode 100644 index 000000000..281ebf068 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bondsetting_p.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BOND_SETTING_P_H +#define NETWORKMANAGERQT_BOND_SETTING_P_H + +#include + +namespace NetworkManager +{ +class BondSettingPrivate +{ +public: + BondSettingPrivate(); + + QString name; + QString interfaceName; + NMStringMap options; +}; + +} + +#endif // NETWORKMANAGERQT_BOND_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting.cpp new file mode 100644 index 000000000..37cd37ed5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting.cpp @@ -0,0 +1,133 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "bridgeportsetting.h" +#include "bridgeportsetting_p.h" + +#include + +NetworkManager::BridgePortSettingPrivate::BridgePortSettingPrivate() + : name(NM_SETTING_BRIDGE_PORT_SETTING_NAME) + , priority(32) + , pathCost(100) + , hairpinMode(false) +{ +} + +NetworkManager::BridgePortSetting::BridgePortSetting() + : Setting(Setting::BridgePort) + , d_ptr(new BridgePortSettingPrivate()) +{ +} + +NetworkManager::BridgePortSetting::BridgePortSetting(const NetworkManager::BridgePortSetting::Ptr &other) + : Setting(other) + , d_ptr(new BridgePortSettingPrivate()) +{ + setPriority(other->priority()); + setPathCost(other->pathCost()); + setHairpinMode(other->hairpinMode()); +} + +NetworkManager::BridgePortSetting::~BridgePortSetting() +{ + delete d_ptr; +} + +QString NetworkManager::BridgePortSetting::name() const +{ + Q_D(const BridgePortSetting); + + return d->name; +} + +void NetworkManager::BridgePortSetting::setPriority(quint32 priority) +{ + Q_D(BridgePortSetting); + + d->priority = priority; +} + +quint32 NetworkManager::BridgePortSetting::priority() const +{ + Q_D(const BridgePortSetting); + + return d->priority; +} + +void NetworkManager::BridgePortSetting::setPathCost(quint32 cost) +{ + Q_D(BridgePortSetting); + + d->pathCost = cost; +} + +quint32 NetworkManager::BridgePortSetting::pathCost() const +{ + Q_D(const BridgePortSetting); + + return d->pathCost; +} + +void NetworkManager::BridgePortSetting::setHairpinMode(bool enable) +{ + Q_D(BridgePortSetting); + + d->hairpinMode = enable; +} + +bool NetworkManager::BridgePortSetting::hairpinMode() const +{ + Q_D(const BridgePortSetting); + + return d->hairpinMode; +} + +void NetworkManager::BridgePortSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_PORT_PRIORITY))) { + setPriority(setting.value(QLatin1String(NM_SETTING_BRIDGE_PORT_PRIORITY)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_PORT_PATH_COST))) { + setPathCost(setting.value(QLatin1String(NM_SETTING_BRIDGE_PORT_PATH_COST)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE))) { + setHairpinMode(setting.value(QLatin1String(NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE)).toBool()); + } +} + +QVariantMap NetworkManager::BridgePortSetting::toMap() const +{ + QVariantMap setting; + + if (priority() != 32) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_PORT_PRIORITY), priority()); + } + + if (pathCost() != 100) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_PORT_PATH_COST), pathCost()); + } + + if (hairpinMode()) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_PORT_PATH_COST), hairpinMode()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BridgePortSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_BRIDGE_PORT_PRIORITY << ": " << setting.priority() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_PORT_PATH_COST << ": " << setting.pathCost() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_PORT_PATH_COST << ": " << setting.hairpinMode() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting.h new file mode 100644 index 000000000..d3301f786 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting.h @@ -0,0 +1,57 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BRIDGEPORT_SETTING_H +#define NETWORKMANAGERQT_BRIDGEPORT_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class BridgePortSettingPrivate; + +/** + * Represents bridge port setting + */ +class NETWORKMANAGERQT_EXPORT BridgePortSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + BridgePortSetting(); + explicit BridgePortSetting(const Ptr &other); + ~BridgePortSetting() override; + + QString name() const override; + + void setPriority(quint32 priority); + quint32 priority() const; + + void setPathCost(quint32 cost); + quint32 pathCost() const; + + void setHairpinMode(bool enable); + bool hairpinMode() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + BridgePortSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(BridgePortSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const BridgePortSetting &setting); + +} + +#endif // NETWORKMANAGERQT_BRIDGEPORT_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting_p.h new file mode 100644 index 000000000..0cfd80de1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bridgeportsetting_p.h @@ -0,0 +1,27 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BRIDGEPORT_SETTING_P_H +#define NETWORKMANAGERQT_BRIDGEPORT_SETTING_P_H + +#include + +namespace NetworkManager +{ +class BridgePortSettingPrivate +{ +public: + BridgePortSettingPrivate(); + + QString name; + quint32 priority; + quint32 pathCost; + bool hairpinMode; +}; + +} + +#endif // NETWORKMANAGERQT_BRIDGEPORT_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting.cpp new file mode 100644 index 000000000..dcfa4a590 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting.cpp @@ -0,0 +1,281 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "bridgesetting.h" +#include "bridgesetting_p.h" + +#define NM_SETTING_BRIDGE_INTERFACE_NAME "interface-name" + +#include + +NetworkManager::BridgeSettingPrivate::BridgeSettingPrivate() + : name(NM_SETTING_BRIDGE_SETTING_NAME) + , multicastSnooping(true) + , stp(true) + , priority(128) + , forwardDelay(15) + , helloTime(2) + , maxAge(20) + , agingTime(300) +{ +} + +NetworkManager::BridgeSetting::BridgeSetting() + : Setting(Setting::Bridge) + , d_ptr(new BridgeSettingPrivate()) +{ +} + +NetworkManager::BridgeSetting::BridgeSetting(const Ptr &other) + : Setting(other) + , d_ptr(new BridgeSettingPrivate()) +{ + setInterfaceName(other->interfaceName()); + setStp(other->stp()); + setPriority(other->priority()); + setForwardDelay(other->forwardDelay()); + setHelloTime(other->helloTime()); + setMaxAge(other->maxAge()); + setAgingTime(other->agingTime()); + setMulticastSnooping(other->multicastSnooping()); + setMacAddress(other->macAddress()); +} + +NetworkManager::BridgeSetting::~BridgeSetting() +{ + delete d_ptr; +} + +QString NetworkManager::BridgeSetting::name() const +{ + Q_D(const BridgeSetting); + + return d->name; +} + +void NetworkManager::BridgeSetting::setInterfaceName(const QString &name) +{ + Q_D(BridgeSetting); + + d->interfaceName = name; +} + +QString NetworkManager::BridgeSetting::interfaceName() const +{ + Q_D(const BridgeSetting); + + return d->interfaceName; +} + +void NetworkManager::BridgeSetting::setStp(bool enabled) +{ + Q_D(BridgeSetting); + + d->stp = enabled; +} + +bool NetworkManager::BridgeSetting::stp() const +{ + Q_D(const BridgeSetting); + + return d->stp; +} + +void NetworkManager::BridgeSetting::setPriority(quint32 priority) +{ + Q_D(BridgeSetting); + + d->priority = priority; +} + +quint32 NetworkManager::BridgeSetting::priority() const +{ + Q_D(const BridgeSetting); + + return d->priority; +} + +void NetworkManager::BridgeSetting::setForwardDelay(quint32 delay) +{ + Q_D(BridgeSetting); + + d->forwardDelay = delay; +} + +quint32 NetworkManager::BridgeSetting::forwardDelay() const +{ + Q_D(const BridgeSetting); + + return d->forwardDelay; +} + +void NetworkManager::BridgeSetting::setHelloTime(quint32 time) +{ + Q_D(BridgeSetting); + + d->helloTime = time; +} + +quint32 NetworkManager::BridgeSetting::helloTime() const +{ + Q_D(const BridgeSetting); + + return d->helloTime; +} + +void NetworkManager::BridgeSetting::setMaxAge(quint32 age) +{ + Q_D(BridgeSetting); + + d->maxAge = age; +} + +quint32 NetworkManager::BridgeSetting::maxAge() const +{ + Q_D(const BridgeSetting); + + return d->maxAge; +} + +void NetworkManager::BridgeSetting::setAgingTime(quint32 time) +{ + Q_D(BridgeSetting); + + d->agingTime = time; +} + +quint32 NetworkManager::BridgeSetting::agingTime() const +{ + Q_D(const BridgeSetting); + + return d->agingTime; +} + +void NetworkManager::BridgeSetting::setMulticastSnooping(bool snooping) +{ + Q_D(BridgeSetting); + + d->multicastSnooping = snooping; +} + +bool NetworkManager::BridgeSetting::multicastSnooping() const +{ + Q_D(const BridgeSetting); + + return d->multicastSnooping; +} + +void NetworkManager::BridgeSetting::setMacAddress(const QByteArray &address) +{ + Q_D(BridgeSetting); + + d->macAddress = address; +} + +QByteArray NetworkManager::BridgeSetting::macAddress() const +{ + Q_D(const BridgeSetting); + + return d->macAddress; +} + +void NetworkManager::BridgeSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_INTERFACE_NAME))) { + setInterfaceName(setting.value(QLatin1String(NM_SETTING_BRIDGE_INTERFACE_NAME)).toString()); + } + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_STP))) { + setStp(setting.value(QLatin1String(NM_SETTING_BRIDGE_STP)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_PRIORITY))) { + setPriority(setting.value(QLatin1String(NM_SETTING_BRIDGE_PRIORITY)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_FORWARD_DELAY))) { + setForwardDelay(setting.value(QLatin1String(NM_SETTING_BRIDGE_FORWARD_DELAY)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_HELLO_TIME))) { + setHelloTime(setting.value(QLatin1String(NM_SETTING_BRIDGE_HELLO_TIME)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_MAX_AGE))) { + setMaxAge(setting.value(QLatin1String(NM_SETTING_BRIDGE_MAX_AGE)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_AGEING_TIME))) { + setAgingTime(setting.value(QLatin1String(NM_SETTING_BRIDGE_AGEING_TIME)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_MULTICAST_SNOOPING))) { + setMulticastSnooping(setting.value(QLatin1String(NM_SETTING_BRIDGE_MULTICAST_SNOOPING)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_BRIDGE_MAC_ADDRESS))) { + setMacAddress(setting.value(QLatin1String(NM_SETTING_BRIDGE_MAC_ADDRESS)).toByteArray()); + } +} + +QVariantMap NetworkManager::BridgeSetting::toMap() const +{ + QVariantMap setting; + + if (!interfaceName().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_INTERFACE_NAME), interfaceName()); + } + if (!stp()) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_STP), stp()); + } + + if (priority() != 128) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_PRIORITY), priority()); + } + + if (forwardDelay() != 15) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_FORWARD_DELAY), forwardDelay()); + } + + if (helloTime() != 2) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_HELLO_TIME), helloTime()); + } + + if (maxAge() != 20) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_MAX_AGE), maxAge()); + } + + if (agingTime() != 300) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_AGEING_TIME), agingTime()); + } + + if (!multicastSnooping()) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_MULTICAST_SNOOPING), multicastSnooping()); + } + + if (!macAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_BRIDGE_MAC_ADDRESS), macAddress()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BridgeSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_BRIDGE_INTERFACE_NAME << ": " << setting.interfaceName() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_STP << ": " << setting.stp() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_PRIORITY << ": " << setting.priority() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_FORWARD_DELAY << ": " << setting.forwardDelay() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_HELLO_TIME << ": " << setting.helloTime() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_MAX_AGE << ": " << setting.maxAge() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_AGEING_TIME << ": " << setting.agingTime() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_MULTICAST_SNOOPING << ": " << setting.multicastSnooping() << '\n'; + dbg.nospace() << NM_SETTING_BRIDGE_MAC_ADDRESS << ": " << setting.macAddress() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting.h b/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting.h new file mode 100644 index 000000000..0cf0ee916 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting.h @@ -0,0 +1,76 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BRIDGE_SETTING_H +#define NETWORKMANAGERQT_BRIDGE_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class BridgeSettingPrivate; + +/** + * Represents bridge setting + */ +class NETWORKMANAGERQT_EXPORT BridgeSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + BridgeSetting(); + explicit BridgeSetting(const Ptr &other); + ~BridgeSetting() override; + + QString name() const override; + + // Deprecated in favor of connection.interface-name in NM 1.0.0 + void setInterfaceName(const QString &name); + QString interfaceName() const; + + void setStp(bool enabled); + bool stp() const; + + void setPriority(quint32 priority); + quint32 priority() const; + + void setForwardDelay(quint32 delay); + quint32 forwardDelay() const; + + void setHelloTime(quint32 time); + quint32 helloTime() const; + + void setMaxAge(quint32 age); + quint32 maxAge() const; + + void setAgingTime(quint32 time); + quint32 agingTime() const; + + void setMulticastSnooping(bool snooping); + bool multicastSnooping() const; + + void setMacAddress(const QByteArray &address); + QByteArray macAddress() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + BridgeSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(BridgeSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const BridgeSetting &setting); + +} + +#endif // NETWORKMANAGERQT_BRIDGE_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting_p.h new file mode 100644 index 000000000..64c65c281 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/bridgesetting_p.h @@ -0,0 +1,33 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_BRIDGE_SETTING_P_H +#define NETWORKMANAGERQT_BRIDGE_SETTING_P_H + +#include + +namespace NetworkManager +{ +class BridgeSettingPrivate +{ +public: + BridgeSettingPrivate(); + + QString name; + QString interfaceName; + bool multicastSnooping; + bool stp; + quint32 priority; + quint32 forwardDelay; + quint32 helloTime; + quint32 maxAge; + quint32 agingTime; + QByteArray macAddress; +}; + +} + +#endif // NETWORKMANAGERQT_BRIDGE_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting.cpp new file mode 100644 index 000000000..cac7c24d0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting.cpp @@ -0,0 +1,187 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "cdmasetting.h" +#include "cdmasetting_p.h" + +#include + +NetworkManager::CdmaSettingPrivate::CdmaSettingPrivate() + : name(NM_SETTING_CDMA_SETTING_NAME) + , passwordFlags(Setting::None) +{ +} + +NetworkManager::CdmaSetting::CdmaSetting() + : Setting(Setting::Cdma) + , d_ptr(new CdmaSettingPrivate()) +{ +} + +NetworkManager::CdmaSetting::CdmaSetting(const Ptr &other) + : Setting(other) + , d_ptr(new CdmaSettingPrivate()) +{ + setUsername(other->username()); + setNumber(other->number()); + setPassword(other->password()); + setPasswordFlags(other->passwordFlags()); +} + +NetworkManager::CdmaSetting::~CdmaSetting() +{ + delete d_ptr; +} + +QString NetworkManager::CdmaSetting::name() const +{ + Q_D(const CdmaSetting); + + return d->name; +} + +void NetworkManager::CdmaSetting::setNumber(const QString &number) +{ + Q_D(CdmaSetting); + + d->number = number; +} + +QString NetworkManager::CdmaSetting::number() const +{ + Q_D(const CdmaSetting); + + return d->number; +} + +void NetworkManager::CdmaSetting::setUsername(const QString &username) +{ + Q_D(CdmaSetting); + + d->username = username; +} + +QString NetworkManager::CdmaSetting::username() const +{ + Q_D(const CdmaSetting); + + return d->username; +} + +void NetworkManager::CdmaSetting::setPassword(const QString &password) +{ + Q_D(CdmaSetting); + + d->password = password; +} + +QString NetworkManager::CdmaSetting::password() const +{ + Q_D(const CdmaSetting); + + return d->password; +} + +void NetworkManager::CdmaSetting::setPasswordFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(CdmaSetting); + + d->passwordFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::CdmaSetting::passwordFlags() const +{ + Q_D(const CdmaSetting); + + return d->passwordFlags; +} + +QStringList NetworkManager::CdmaSetting::needSecrets(bool requestNew) const +{ + QStringList secrets; + if (!username().isEmpty()) { + if ((password().isEmpty() || requestNew) && !passwordFlags().testFlag(NotRequired)) { + secrets << QLatin1String(NM_SETTING_CDMA_PASSWORD); + } + } + + return secrets; +} + +void NetworkManager::CdmaSetting::secretsFromMap(const QVariantMap &secrets) +{ + if (secrets.contains(QLatin1String(NM_SETTING_CDMA_PASSWORD))) { + setPassword(secrets.value(QLatin1String(NM_SETTING_CDMA_PASSWORD)).toString()); + } +} + +QVariantMap NetworkManager::CdmaSetting::secretsToMap() const +{ + QVariantMap secrets; + + if (!password().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_CDMA_PASSWORD), password()); + } + + return secrets; +} + +void NetworkManager::CdmaSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_CDMA_NUMBER))) { + setNumber(setting.value(QLatin1String(NM_SETTING_CDMA_NUMBER)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_CDMA_USERNAME))) { + setUsername(setting.value(QLatin1String(NM_SETTING_CDMA_USERNAME)).toString()); + } + + // SECRETS + if (setting.contains(QLatin1String(NM_SETTING_CDMA_PASSWORD))) { + setPassword(setting.value(QLatin1String(NM_SETTING_CDMA_PASSWORD)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_CDMA_PASSWORD_FLAGS))) { + setPasswordFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_CDMA_PASSWORD_FLAGS)).toInt()); + } +} + +QVariantMap NetworkManager::CdmaSetting::toMap() const +{ + QVariantMap setting; + + if (!number().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_CDMA_NUMBER), number()); + } + + if (!username().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_CDMA_USERNAME), username()); + } + + // SECRETS + if (!password().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_CDMA_PASSWORD), password()); + } + + if (passwordFlags() != None) { + setting.insert(QLatin1String(NM_SETTING_CDMA_PASSWORD_FLAGS), (int)passwordFlags()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::CdmaSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_CDMA_NUMBER << ": " << setting.number() << '\n'; + dbg.nospace() << NM_SETTING_CDMA_USERNAME << ": " << setting.username() << '\n'; + dbg.nospace() << NM_SETTING_CDMA_PASSWORD << ": " << setting.password() << '\n'; + dbg.nospace() << NM_SETTING_CDMA_PASSWORD_FLAGS << ": " << setting.passwordFlags() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting.h b/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting.h new file mode 100644 index 000000000..c014edf5d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting.h @@ -0,0 +1,66 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_CDMA_SETTINGS_H +#define NETWORKMANAGERQT_CDMA_SETTINGS_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class CdmaSettingPrivate; + +/** + * Represents cdma setting + */ +class NETWORKMANAGERQT_EXPORT CdmaSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + CdmaSetting(); + explicit CdmaSetting(const Ptr &other); + ~CdmaSetting() override; + + QString name() const override; + + void setNumber(const QString &number); + QString number() const; + + void setUsername(const QString &username); + QString username() const; + + void setPassword(const QString &password); + QString password() const; + + void setPasswordFlags(SecretFlags flags); + SecretFlags passwordFlags() const; + + QStringList needSecrets(bool requestNew = false) const override; + + void secretsFromMap(const QVariantMap &secrets) override; + + QVariantMap secretsToMap() const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + CdmaSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(CdmaSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const CdmaSetting &setting); + +} + +#endif // NETWORKMANAGERQT_CDMA_SETTINGS_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting_p.h new file mode 100644 index 000000000..3d3a928a8 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/cdmasetting_p.h @@ -0,0 +1,28 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_CDMA_SETTING_P_H +#define NETWORKMANAGERQT_CDMA_SETTING_P_H + +#include + +namespace NetworkManager +{ +class CdmaSettingPrivate +{ +public: + CdmaSettingPrivate(); + + QString name; + QString number; + QString username; + QString password; + NetworkManager::Setting::SecretFlags passwordFlags; +}; + +} + +#endif // NETWORKMANAGERQT_CDMA_SETTINGS_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings.cpp b/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings.cpp new file mode 100644 index 000000000..c8a62d0a3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings.cpp @@ -0,0 +1,1137 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "connectionsettings.h" +#include "connectionsettings_p.h" + +#include "adslsetting.h" +#include "bluetoothsetting.h" +#include "bondsetting.h" +#include "bridgeportsetting.h" +#include "bridgesetting.h" +#include "cdmasetting.h" +#include "gsmsetting.h" +#include "infinibandsetting.h" +#include "iptunnelsetting.h" +#include "ipv4setting.h" +#include "ipv6setting.h" +#include "olpcmeshsetting.h" +#include "pppoesetting.h" +#include "pppsetting.h" +#include "security8021xsetting.h" +#include "serialsetting.h" +#include "tunsetting.h" +#include "vlansetting.h" +#include "vpnsetting.h" +#include "wimaxsetting.h" +#include "wiredsetting.h" +#include "wireguardsetting.h" +#include "wirelesssecuritysetting.h" +#include "wirelesssetting.h" + +#undef signals + +#if !NM_CHECK_VERSION(1, 6, 0) +#define NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES "autoconnect-retries" +#endif + +#if !NM_CHECK_VERSION(1, 12, 0) +#define NM_SETTING_CONNECTION_MDNS "mdns" +#endif + +#if !NM_CHECK_VERSION(1, 16, 0) +#define NM_SETTING_WIREGUARD_SETTING_NAME "wireguard" +#endif + +#include "genericsetting.h" +#include "teamsetting.h" + +#include + +namespace NetworkManager +{ +extern int checkVersion(const int x, const int y, const int z); +} + +NetworkManager::ConnectionSettingsPrivate::ConnectionSettingsPrivate(ConnectionSettings *q) + : name(NM_SETTING_CONNECTION_SETTING_NAME) + , uuid(QUuid().toString()) + , type(ConnectionSettings::Wired) + , autoconnect(true) + , readOnly(false) + , gatewayPingTimeout(0) + , autoconnectPriority(0) + , autoconnectRetries(-1) + , autoconnectSlaves(ConnectionSettings::SlavesDefault) + , lldp(ConnectionSettings::LldpDefault) + , metered(ConnectionSettings::MeteredUnknown) + , mdns(ConnectionSettings::MdnsDefault) + , q_ptr(q) +{ +} + +void NetworkManager::ConnectionSettingsPrivate::addSetting(const NetworkManager::Setting::Ptr &setting) +{ + settings.push_back(setting); +} + +void NetworkManager::ConnectionSettingsPrivate::clearSettings() +{ + settings.clear(); +} + +void NetworkManager::ConnectionSettingsPrivate::initSettings(NMBluetoothCapabilities bt_cap) +{ + clearSettings(); + + switch (type) { + case ConnectionSettings::Adsl: + addSetting(Setting::Ptr(new AdslSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::Bond: + addSetting(Setting::Ptr(new BondSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::Bluetooth: + addSetting(Setting::Ptr(new BluetoothSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + // addSetting(Setting::Ptr(new Ipv6Setting())); + if (bt_cap == NM_BT_CAPABILITY_DUN) { + addSetting(Setting::Ptr(new GsmSetting())); + addSetting(Setting::Ptr(new PppSetting())); + addSetting(Setting::Ptr(new SerialSetting())); + } + break; + case ConnectionSettings::Bridge: + addSetting(Setting::Ptr(new BridgeSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::Cdma: + addSetting(Setting::Ptr(new CdmaSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + if (NetworkManager::checkVersion(1, 0, 0)) { + addSetting(Setting::Ptr(new Ipv6Setting())); + } + addSetting(Setting::Ptr(new PppSetting())); + break; + case ConnectionSettings::Gsm: + addSetting(Setting::Ptr(new GsmSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + if (NetworkManager::checkVersion(1, 0, 0)) { + addSetting(Setting::Ptr(new Ipv6Setting())); + } + addSetting(Setting::Ptr(new PppSetting())); + break; + case ConnectionSettings::Infiniband: + addSetting(Setting::Ptr(new InfinibandSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::OLPCMesh: + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + addSetting(Setting::Ptr(new OlpcMeshSetting())); + break; + case ConnectionSettings::Pppoe: + addSetting(Setting::Ptr(new Ipv4Setting())); + // addSetting(new Ipv6Setting())); + addSetting(Setting::Ptr(new PppSetting())); + addSetting(Setting::Ptr(new PppoeSetting())); + addSetting(Setting::Ptr(new WiredSetting())); + break; + case ConnectionSettings::Vlan: + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + addSetting(Setting::Ptr(new VlanSetting())); + break; + case ConnectionSettings::Vpn: + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + addSetting(Setting::Ptr(new VpnSetting())); + break; + case ConnectionSettings::Wimax: + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + addSetting(Setting::Ptr(new WimaxSetting())); + break; + case ConnectionSettings::Wired: + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + addSetting(Setting::Ptr(new Security8021xSetting())); + addSetting(Setting::Ptr(new WiredSetting())); + break; + case ConnectionSettings::Wireless: + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + addSetting(Setting::Ptr(new Security8021xSetting())); + addSetting(Setting::Ptr(new WirelessSetting())); + addSetting(Setting::Ptr(new WirelessSecuritySetting())); + break; + case ConnectionSettings::Team: + addSetting(Setting::Ptr(new TeamSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::Generic: + addSetting(Setting::Ptr(new GenericSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::Tun: + addSetting(Setting::Ptr(new TunSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::IpTunnel: + addSetting(Setting::Ptr(new IpTunnelSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::WireGuard: + addSetting(Setting::Ptr(new WireGuardSetting())); + addSetting(Setting::Ptr(new Ipv4Setting())); + addSetting(Setting::Ptr(new Ipv6Setting())); + break; + case ConnectionSettings::Unknown: + default: + break; + } +} + +void NetworkManager::ConnectionSettingsPrivate::initSettings(const NetworkManager::ConnectionSettings::Ptr &connectionSettings) +{ + Q_Q(ConnectionSettings); + + clearSettings(); + + switch (type) { + case ConnectionSettings::Adsl: + addSetting(connectionSettings->setting(Setting::Adsl)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::Bond: + addSetting(connectionSettings->setting(Setting::Bond)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::Bluetooth: + addSetting(connectionSettings->setting(Setting::Bluetooth)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + if (NetworkManager::checkVersion(1, 0, 0)) { + addSetting(connectionSettings->setting(Setting::Ipv6)); + } + if (q->setting(Setting::Gsm) && q->setting(Setting::Ppp) && q->setting(Setting::Serial)) { + addSetting(connectionSettings->setting(Setting::Gsm)); + addSetting(connectionSettings->setting(Setting::Ppp)); + addSetting(connectionSettings->setting(Setting::Serial)); + } + break; + case ConnectionSettings::Bridge: + addSetting(connectionSettings->setting(Setting::Bridge)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::Cdma: + addSetting(connectionSettings->setting(Setting::Cdma)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + if (NetworkManager::checkVersion(1, 0, 0)) { + addSetting(connectionSettings->setting(Setting::Ipv6)); + } + addSetting(connectionSettings->setting(Setting::Ppp)); + break; + case ConnectionSettings::Gsm: + addSetting(connectionSettings->setting(Setting::Gsm)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + if (NetworkManager::checkVersion(1, 0, 0)) { + addSetting(connectionSettings->setting(Setting::Ipv6)); + } + addSetting(connectionSettings->setting(Setting::Ppp)); + break; + case ConnectionSettings::Infiniband: + addSetting(connectionSettings->setting(Setting::Infiniband)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::OLPCMesh: + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + addSetting(connectionSettings->setting(Setting::OlpcMesh)); + break; + case ConnectionSettings::Pppoe: + addSetting(connectionSettings->setting(Setting::Ipv4)); + // addSetting(Ipv6Setting(connectionSettings->setting(Setting::Ipv6)); + addSetting(connectionSettings->setting(Setting::Ppp)); + addSetting(connectionSettings->setting(Setting::Pppoe)); + addSetting(connectionSettings->setting(Setting::Wired)); + break; + case ConnectionSettings::Vlan: + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + addSetting(connectionSettings->setting(Setting::Vlan)); + break; + case ConnectionSettings::Vpn: + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + addSetting(connectionSettings->setting(Setting::Vpn)); + break; + case ConnectionSettings::Wimax: + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + addSetting(connectionSettings->setting(Setting::Wimax)); + break; + case ConnectionSettings::Wired: + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + addSetting(connectionSettings->setting(Setting::Security8021x)); + addSetting(connectionSettings->setting(Setting::Wired)); + break; + case ConnectionSettings::Wireless: + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + addSetting(connectionSettings->setting(Setting::Security8021x)); + addSetting(connectionSettings->setting(Setting::Wireless)); + addSetting(connectionSettings->setting(Setting::WirelessSecurity)); + break; + case ConnectionSettings::Team: + addSetting(connectionSettings->setting(Setting::Team)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::Generic: + addSetting(connectionSettings->setting(Setting::Generic)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::Tun: + addSetting(connectionSettings->setting(Setting::Tun)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::IpTunnel: + addSetting(connectionSettings->setting(Setting::IpTunnel)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::WireGuard: + addSetting(connectionSettings->setting(Setting::WireGuard)); + addSetting(connectionSettings->setting(Setting::Ipv4)); + addSetting(connectionSettings->setting(Setting::Ipv6)); + break; + case ConnectionSettings::Unknown: + default: + break; + } +} + +NetworkManager::ConnectionSettings::ConnectionType NetworkManager::ConnectionSettings::typeFromString(const QString &typeString) +{ + ConnectionSettings::ConnectionType type = Wired; + + if (typeString == QLatin1String(NM_SETTING_ADSL_SETTING_NAME)) { + type = Adsl; + } else if (typeString == QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME)) { + type = Bluetooth; + } else if (typeString == QLatin1String(NM_SETTING_BOND_SETTING_NAME)) { + type = Bond; + } else if (typeString == QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME)) { + type = Bridge; + } else if (typeString == QLatin1String(NM_SETTING_CDMA_SETTING_NAME)) { + type = Cdma; + } else if (typeString == QLatin1String(NM_SETTING_GSM_SETTING_NAME)) { + type = Gsm; + } else if (typeString == QLatin1String(NM_SETTING_INFINIBAND_SETTING_NAME)) { + type = Infiniband; + } else if (typeString == QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME)) { + type = OLPCMesh; + } else if (typeString == QLatin1String(NM_SETTING_PPPOE_SETTING_NAME)) { + type = Pppoe; + } else if (typeString == QLatin1String(NM_SETTING_VLAN_SETTING_NAME)) { + type = Vlan; + } else if (typeString == QLatin1String(NM_SETTING_VPN_SETTING_NAME)) { + type = Vpn; + } else if (typeString == QLatin1String(NM_SETTING_WIMAX_SETTING_NAME)) { + type = Wimax; + } else if (typeString == QLatin1String(NM_SETTING_WIRED_SETTING_NAME)) { + type = Wired; + } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME)) { + type = Wireless; + } else if (typeString == QLatin1String(NM_SETTING_TEAM_SETTING_NAME)) { + type = Team; + } else if (typeString == QLatin1String(NM_SETTING_GENERIC_SETTING_NAME)) { + type = Generic; + } else if (typeString == QLatin1String(NM_SETTING_TUN_SETTING_NAME)) { + type = Tun; + } else if (typeString == QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME)) { + type = IpTunnel; + } else if (typeString == QLatin1String(NM_SETTING_WIREGUARD_SETTING_NAME)) { + type = WireGuard; + } + + return type; +} + +QString NetworkManager::ConnectionSettings::typeAsString(NetworkManager::ConnectionSettings::ConnectionType type) +{ + QString typeString; + + switch (type) { + case Adsl: + typeString = QLatin1String(NM_SETTING_ADSL_SETTING_NAME); + break; + case Bond: + typeString = QLatin1String(NM_SETTING_BOND_SETTING_NAME); + break; + case Bluetooth: + typeString = QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME); + break; + case Bridge: + typeString = QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME); + break; + case Cdma: + typeString = QLatin1String(NM_SETTING_CDMA_SETTING_NAME); + break; + case Gsm: + typeString = QLatin1String(NM_SETTING_GSM_SETTING_NAME); + break; + case Infiniband: + typeString = QLatin1String(NM_SETTING_INFINIBAND_SETTING_NAME); + break; + case OLPCMesh: + typeString = QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME); + break; + case Pppoe: + typeString = QLatin1String(NM_SETTING_PPPOE_SETTING_NAME); + break; + case Vlan: + typeString = QLatin1String(NM_SETTING_VLAN_SETTING_NAME); + break; + case Vpn: + typeString = QLatin1String(NM_SETTING_VPN_SETTING_NAME); + break; + case Wimax: + typeString = QLatin1String(NM_SETTING_WIMAX_SETTING_NAME); + break; + case Wired: + typeString = QLatin1String(NM_SETTING_WIRED_SETTING_NAME); + break; + case Wireless: + typeString = QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME); + break; + case Team: + typeString = QLatin1String(NM_SETTING_TEAM_SETTING_NAME); + break; + case Generic: + typeString = QLatin1String(NM_SETTING_GENERIC_SETTING_NAME); + break; + case Tun: + typeString = QLatin1String(NM_SETTING_TUN_SETTING_NAME); + break; + case IpTunnel: + typeString = QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME); + break; + case WireGuard: + typeString = QLatin1String(NM_SETTING_WIREGUARD_SETTING_NAME); + break; + default: + break; + }; + + return typeString; +} + +QString NetworkManager::ConnectionSettings::createNewUuid() +{ + return QUuid::createUuid().toString().mid(1, QUuid::createUuid().toString().length() - 2); +} + +NetworkManager::ConnectionSettings::ConnectionSettings() + : d_ptr(new ConnectionSettingsPrivate(this)) +{ +} + +NetworkManager::ConnectionSettings::ConnectionSettings(NetworkManager::ConnectionSettings::ConnectionType type, NMBluetoothCapabilities bt_cap) + : d_ptr(new ConnectionSettingsPrivate(this)) +{ + setConnectionType(type, bt_cap); +} + +NetworkManager::ConnectionSettings::ConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &other) + : d_ptr(new ConnectionSettingsPrivate(this)) +{ + Q_D(ConnectionSettings); + + setId(other->id()); + setUuid(other->uuid()); + setInterfaceName(other->interfaceName()); + setConnectionType(other->connectionType()); + setPermissions(other->permissions()); + setAutoconnect(other->autoconnect()); + setAutoconnectPriority(other->autoconnectPriority()); + setTimestamp(other->timestamp()); + setReadOnly(other->readOnly()); + setZone(other->zone()); + setMaster(other->master()); + setSlaveType(other->slaveType()); + setGatewayPingTimeout(other->gatewayPingTimeout()); + setAutoconnectRetries(other->autoconnectRetries()); + setAutoconnectSlaves(other->autoconnectSlaves()); + setLldp(other->lldp()); + setMetered(other->metered()); + setMdns(other->mdns()); + setStableId(other->stableId()); + + d->initSettings(other); +} + +NetworkManager::ConnectionSettings::ConnectionSettings(const NMVariantMapMap &map) + : d_ptr(new ConnectionSettingsPrivate(this)) +{ + fromMap(map); +} + +NetworkManager::ConnectionSettings::~ConnectionSettings() +{ + d_ptr->clearSettings(); + + delete d_ptr; +} + +void NetworkManager::ConnectionSettings::fromMap(const NMVariantMapMap &map) +{ + QVariantMap connectionSettings = map.value(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME)); + + setId(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_ID)).toString()); + setUuid(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_UUID)).toString()); + setConnectionType(typeFromString(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_TYPE)).toString())); + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_INTERFACE_NAME))) { + setInterfaceName(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_INTERFACE_NAME)).toString()); + } + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS))) { + const QStringList permissions = connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS)).toStringList(); + for (const QString &permission : permissions) { + const QStringList split = permission.split(QLatin1Char(':'), Qt::KeepEmptyParts); + addToPermissions(split.at(1), split.at(2)); + } + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT))) { + setAutoconnect(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT)).toBool()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY))) { + setAutoconnectPriority(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY)).toInt()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_TIMESTAMP))) { + const int timestamp = connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_TIMESTAMP)).toInt(); + setTimestamp(QDateTime::fromSecsSinceEpoch(timestamp)); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_READ_ONLY))) { + setReadOnly(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_READ_ONLY)).toBool()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_ZONE))) { + setZone(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_ZONE)).toString()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_MASTER))) { + setMaster(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_MASTER)).toString()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_SLAVE_TYPE))) { + setSlaveType(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_SLAVE_TYPE)).toString()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_SECONDARIES))) { + setSecondaries(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_SECONDARIES)).toStringList()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT))) { + setGatewayPingTimeout(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT)).toUInt()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES))) { + setAutoconnectRetries(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES)).toInt()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES))) { + setAutoconnectSlaves( + (NetworkManager::ConnectionSettings::AutoconnectSlaves)connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES)).toInt()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_LLDP))) { + setLldp((NetworkManager::ConnectionSettings::Lldp)connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_LLDP)).toInt()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_METERED))) { + setMetered((NetworkManager::ConnectionSettings::Metered)connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_METERED)).toInt()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_MDNS))) { + setMdns((NetworkManager::ConnectionSettings::Mdns)connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_MDNS)).toInt()); + } + + if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_STABLE_ID))) { + setStableId(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_STABLE_ID)).toString()); + } + + const auto settingsList = settings(); + for (const Setting::Ptr &setting : settingsList) { + if (map.contains(setting->name())) { + setting->fromMap(map.value(setting->name())); + setting->setInitialized(true); + } else { + setting->setInitialized(false); + } + } +} + +NMVariantMapMap NetworkManager::ConnectionSettings::toMap() const +{ + NMVariantMapMap result; + QVariantMap connectionSetting; + + if (!id().isEmpty()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_ID), id()); + } + + if (!uuid().isEmpty()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_UUID), uuid()); + } + + if (connectionType()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_TYPE), typeAsString(connectionType())); + } + + if (!interfaceName().isEmpty()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_INTERFACE_NAME), interfaceName()); + } + + if (!permissions().isEmpty()) { + QStringList perm; + QHash perms = permissions(); + QHash::const_iterator it = perms.constBegin(); + while (it != perms.constEnd()) { + const QString tmp = "user:" + it.key() + ':' + it.value(); + perm << tmp; + ++it; + } + + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS), perm); + } + + if (!autoconnect()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT), autoconnect()); + } + + if (autoconnectPriority()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), autoconnectPriority()); + } + + if (timestamp().isValid()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_TIMESTAMP), timestamp().toSecsSinceEpoch()); + } + + if (readOnly()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_READ_ONLY), readOnly()); + } + + if (!zone().isEmpty()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_ZONE), zone()); + } + + if (!master().isEmpty()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_MASTER), master()); + } + + if (!slaveType().isEmpty()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_SLAVE_TYPE), slaveType()); + } + + if (!secondaries().isEmpty()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_SECONDARIES), secondaries()); + } + + if (gatewayPingTimeout()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), gatewayPingTimeout()); + } + + if (autoconnectRetries() >= 0) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES), autoconnectRetries()); + } + + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), autoconnectSlaves()); + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_LLDP), lldp()); + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_METERED), metered()); + + if (mdns() != MdnsDefault) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_MDNS), mdns()); + } + + if (!stableId().isEmpty()) { + connectionSetting.insert(QLatin1String(NM_SETTING_CONNECTION_STABLE_ID), stableId()); + } + + result.insert(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME), connectionSetting); + + const auto settingsList = settings(); + for (const Setting::Ptr &setting : settingsList) { + QVariantMap map = setting->toMap(); + if (!setting->isNull()) { + result.insert(setting->name(), map); + } + } + return result; +} + +QString NetworkManager::ConnectionSettings::name() const +{ + Q_D(const ConnectionSettings); + + return d->name; +} + +void NetworkManager::ConnectionSettings::setId(const QString &id) +{ + Q_D(ConnectionSettings); + + d->id = id; +} + +QString NetworkManager::ConnectionSettings::id() const +{ + Q_D(const ConnectionSettings); + + return d->id; +} + +void NetworkManager::ConnectionSettings::setUuid(const QString &uuid) +{ + Q_D(ConnectionSettings); + + d->uuid = uuid; +} + +QString NetworkManager::ConnectionSettings::uuid() const +{ + Q_D(const ConnectionSettings); + + return d->uuid; +} + +void NetworkManager::ConnectionSettings::setInterfaceName(const QString &interfaceName) +{ + Q_D(ConnectionSettings); + + d->interfaceName = interfaceName; +} + +QString NetworkManager::ConnectionSettings::interfaceName() const +{ + Q_D(const ConnectionSettings); + + return d->interfaceName; +} + +void NetworkManager::ConnectionSettings::setConnectionType(NetworkManager::ConnectionSettings::ConnectionType type, NMBluetoothCapabilities bt_cap) +{ + Q_D(ConnectionSettings); + + d->type = type; + d->initSettings(bt_cap); +} + +NetworkManager::ConnectionSettings::ConnectionType NetworkManager::ConnectionSettings::connectionType() const +{ + Q_D(const ConnectionSettings); + + return d->type; +} + +void NetworkManager::ConnectionSettings::addToPermissions(const QString &user, const QString &type) +{ + Q_D(ConnectionSettings); + + d->permissions.insert(user, type); +} + +void NetworkManager::ConnectionSettings::setPermissions(const QHash &perm) +{ + Q_D(ConnectionSettings); + + d->permissions = perm; +} + +QHash NetworkManager::ConnectionSettings::permissions() const +{ + Q_D(const ConnectionSettings); + + return d->permissions; +} + +void NetworkManager::ConnectionSettings::setAutoconnect(bool autoconnect) +{ + Q_D(ConnectionSettings); + + d->autoconnect = autoconnect; +} + +bool NetworkManager::ConnectionSettings::autoconnect() const +{ + Q_D(const ConnectionSettings); + + return d->autoconnect; +} + +void NetworkManager::ConnectionSettings::setAutoconnectPriority(int priority) +{ + Q_D(ConnectionSettings); + + d->autoconnectPriority = priority; +} + +int NetworkManager::ConnectionSettings::autoconnectPriority() const +{ + Q_D(const ConnectionSettings); + + return d->autoconnectPriority; +} + +void NetworkManager::ConnectionSettings::setTimestamp(const QDateTime ×tamp) +{ + Q_D(ConnectionSettings); + + d->timestamp = timestamp; +} + +QDateTime NetworkManager::ConnectionSettings::timestamp() const +{ + Q_D(const ConnectionSettings); + + return d->timestamp; +} + +void NetworkManager::ConnectionSettings::setReadOnly(bool readonly) +{ + Q_D(ConnectionSettings); + + d->readOnly = readonly; +} + +bool NetworkManager::ConnectionSettings::readOnly() const +{ + Q_D(const ConnectionSettings); + + return d->readOnly; +} + +void NetworkManager::ConnectionSettings::setZone(const QString &zone) +{ + Q_D(ConnectionSettings); + + d->zone = zone; +} + +QString NetworkManager::ConnectionSettings::zone() const +{ + Q_D(const ConnectionSettings); + + return d->zone; +} + +bool NetworkManager::ConnectionSettings::isSlave() const +{ + Q_D(const ConnectionSettings); + + return !d->master.isEmpty() && !d->slaveType.isEmpty(); +} + +void NetworkManager::ConnectionSettings::setMaster(const QString &master) +{ + Q_D(ConnectionSettings); + + d->master = master; +} + +QString NetworkManager::ConnectionSettings::master() const +{ + Q_D(const ConnectionSettings); + + return d->master; +} + +void NetworkManager::ConnectionSettings::setSlaveType(const QString &type) +{ + Q_D(ConnectionSettings); + + d->slaveType = type; +} + +QString NetworkManager::ConnectionSettings::slaveType() const +{ + Q_D(const ConnectionSettings); + + return d->slaveType; +} + +void NetworkManager::ConnectionSettings::setSecondaries(const QStringList &secondaries) +{ + Q_D(ConnectionSettings); + + d->secondaries = secondaries; +} + +QStringList NetworkManager::ConnectionSettings::secondaries() const +{ + Q_D(const ConnectionSettings); + + return d->secondaries; +} + +void NetworkManager::ConnectionSettings::setGatewayPingTimeout(quint32 timeout) +{ + Q_D(ConnectionSettings); + + d->gatewayPingTimeout = timeout; +} + +quint32 NetworkManager::ConnectionSettings::gatewayPingTimeout() const +{ + Q_D(const ConnectionSettings); + + return d->gatewayPingTimeout; +} + +int NetworkManager::ConnectionSettings::autoconnectRetries() const +{ + Q_D(const ConnectionSettings); + + return d->autoconnectRetries; +} + +void NetworkManager::ConnectionSettings::setAutoconnectRetries(int retries) +{ + Q_D(ConnectionSettings); + + d->autoconnectRetries = retries; +} + +NetworkManager::ConnectionSettings::AutoconnectSlaves NetworkManager::ConnectionSettings::autoconnectSlaves() const +{ + Q_D(const ConnectionSettings); + + return d->autoconnectSlaves; +} + +void NetworkManager::ConnectionSettings::setAutoconnectSlaves(NetworkManager::ConnectionSettings::AutoconnectSlaves autoconnectSlaves) +{ + Q_D(ConnectionSettings); + + d->autoconnectSlaves = autoconnectSlaves; +} + +NetworkManager::ConnectionSettings::Lldp NetworkManager::ConnectionSettings::lldp() const +{ + Q_D(const ConnectionSettings); + + return d->lldp; +} + +void NetworkManager::ConnectionSettings::setLldp(NetworkManager::ConnectionSettings::Lldp lldp) +{ + Q_D(ConnectionSettings); + + d->lldp = lldp; +} + +NetworkManager::ConnectionSettings::Metered NetworkManager::ConnectionSettings::metered() const +{ + Q_D(const ConnectionSettings); + + return d->metered; +} + +void NetworkManager::ConnectionSettings::setMetered(NetworkManager::ConnectionSettings::Metered metered) +{ + Q_D(ConnectionSettings); + + d->metered = metered; +} + +NetworkManager::ConnectionSettings::Mdns NetworkManager::ConnectionSettings::mdns() const +{ + Q_D(const ConnectionSettings); + + return d->mdns; +} + +void NetworkManager::ConnectionSettings::setMdns(NetworkManager::ConnectionSettings::Mdns mdns) +{ + Q_D(ConnectionSettings); + + d->mdns = mdns; +} + +QString NetworkManager::ConnectionSettings::stableId() const +{ + Q_D(const ConnectionSettings); + + return d->stableId; +} + +void NetworkManager::ConnectionSettings::setStableId(const QString &stableId) +{ + Q_D(ConnectionSettings); + + d->stableId = stableId; +} + +NetworkManager::Setting::Ptr NetworkManager::ConnectionSettings::setting(Setting::SettingType type) const +{ + const auto settingsList = settings(); + for (const Setting::Ptr &setting : settingsList) { + if (setting->type() == type) { + return setting; + } + } + + return Setting::Ptr(); +} + +NetworkManager::Setting::Ptr NetworkManager::ConnectionSettings::setting(const QString &type) const +{ + return setting(Setting::typeFromString(type)); +} + +NetworkManager::Setting::List NetworkManager::ConnectionSettings::settings() const +{ + Q_D(const ConnectionSettings); + + return d->settings; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::ConnectionSettings &setting) +{ + dbg.nospace() << "CONNECTION SETTINGS\n"; + dbg.nospace() << "===================\n"; + + dbg.nospace() << NM_SETTING_CONNECTION_ID << ": " << setting.id() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_UUID << ": " << setting.uuid() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_INTERFACE_NAME << ": " << setting.interfaceName() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_TYPE << ": " << setting.typeAsString(setting.connectionType()) << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_PERMISSIONS << ": " << setting.permissions() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_AUTOCONNECT << ": " << setting.autoconnect() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY << ": " << setting.autoconnectPriority() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_TIMESTAMP << ": " << setting.timestamp().toSecsSinceEpoch() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_READ_ONLY << ": " << setting.readOnly() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_ZONE << ": " << setting.zone() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_MASTER << ": " << setting.master() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_SLAVE_TYPE << ": " << setting.slaveType() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_SECONDARIES << ": " << setting.secondaries() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT << ": " << setting.gatewayPingTimeout() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES << ": " << setting.autoconnectRetries() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES << ": " << setting.autoconnectSlaves() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_LLDP << ": " << setting.lldp() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_METERED << ": " << setting.metered() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_MDNS << ": " << setting.mdns() << '\n'; + dbg.nospace() << NM_SETTING_CONNECTION_STABLE_ID << ": " << setting.stableId() << '\n'; + dbg.nospace() << "===================\n"; + const auto settingsList = setting.settings(); + for (const Setting::Ptr &settingPtr : settingsList) { + dbg.nospace() << settingPtr->typeAsString(settingPtr->type()).toUpper() << " SETTINGS\n"; + dbg.nospace() << "---------------------------\n"; + switch (settingPtr->type()) { + case Setting::Adsl: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Bond: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Bluetooth: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Bridge: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::BridgePort: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Cdma: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Gsm: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Infiniband: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Ipv4: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Ipv6: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::OlpcMesh: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Ppp: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Pppoe: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Security8021x: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Serial: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Vlan: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Vpn: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Wimax: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Wired: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Wireless: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::WirelessSecurity: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Team: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::Tun: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::IpTunnel: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + case Setting::WireGuard: + dbg.nospace() << *(settingPtr.staticCast().data()); + break; + default: + dbg.nospace() << *settingPtr.data(); + } + + dbg.nospace() << '\n'; + } + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings.h b/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings.h new file mode 100644 index 000000000..a367a8557 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings.h @@ -0,0 +1,182 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_CONNECTION_SETTINGS_H +#define NETWORKMANAGERQT_CONNECTION_SETTINGS_H + +#include "setting.h" +#include + +#undef signals +#include +#define signals Q_SIGNALS + +#include +#include +#include + +namespace NetworkManager +{ +class ConnectionSettingsPrivate; + +/** + * Represents collection of all connection settings + */ +class NETWORKMANAGERQT_EXPORT ConnectionSettings +{ + Q_ENUMS(ConnectionType) +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum ConnectionType { + Unknown = 0, + Adsl, + Bluetooth, + Bond, + Bridge, + Cdma, + Gsm, + Infiniband, + OLPCMesh, + Pppoe, + Vlan, + Vpn, + Wimax, + Wired, + Wireless, + Team, + Generic, + Tun, + IpTunnel, + WireGuard, + }; + + enum AutoconnectSlaves { + SlavesDefault = -1, + DoNotConnectSlaves = 0, + ConnectAllSlaves = 1, + }; + + enum Lldp { + LldpDefault = -1, + LldpDisable = 0, + LldpEnableRx = 1, + }; + + // FIXME same enum as in device.h, unfortunately it's not possible to use that one + // maybe in future move all enums into one header so they can be used across all classes + enum Metered { + MeteredUnknown = 0, + MeteredYes = 1, + MeteredNo = 2, + MeteredGuessYes = 3, + MeteredGuessNo = 4, + }; + + enum Mdns { + MdnsDefault = -1, + MdnsNo = 0, + MdnsResolve = 1, + MdnsResolveAndRespond = 2 + }; + + static ConnectionType typeFromString(const QString &typeString); + static QString typeAsString(const ConnectionType type); + static QString createNewUuid(); + + ConnectionSettings(); + explicit ConnectionSettings(ConnectionType type, NMBluetoothCapabilities bt_cap = NM_BT_CAPABILITY_DUN); + explicit ConnectionSettings(const ConnectionSettings::Ptr &other); + explicit ConnectionSettings(const NMVariantMapMap &map); + virtual ~ConnectionSettings(); + + QString name() const; + + void fromMap(const NMVariantMapMap &map); + + NMVariantMapMap toMap() const; + + void setId(const QString &id); + QString id() const; + + void setUuid(const QString &uuid); + QString uuid() const; + + void setInterfaceName(const QString &interfaceName); + QString interfaceName() const; + + void setConnectionType(ConnectionType type, NMBluetoothCapabilities bt_cap = NM_BT_CAPABILITY_DUN); + ConnectionType connectionType() const; + + void addToPermissions(const QString &user, const QString &type); + void setPermissions(const QHash &perm); + QHash permissions() const; + + void setAutoconnect(bool autoconnect); + bool autoconnect() const; + + void setAutoconnectPriority(int priority); + int autoconnectPriority() const; + + void setTimestamp(const QDateTime ×tamp); + QDateTime timestamp() const; + + void setReadOnly(bool readonly); + bool readOnly() const; + + void setZone(const QString &zone); + QString zone() const; + + bool isSlave() const; + + void setMaster(const QString &master); + QString master() const; + + void setSlaveType(const QString &type); + QString slaveType() const; + + void setSecondaries(const QStringList &secondaries); + QStringList secondaries() const; + + void setGatewayPingTimeout(quint32 timeout); + quint32 gatewayPingTimeout() const; + + void setAutoconnectRetries(int retries); + int autoconnectRetries() const; + + void setAutoconnectSlaves(AutoconnectSlaves autoconnectSlaves); + AutoconnectSlaves autoconnectSlaves() const; + + void setLldp(Lldp lldp); + Lldp lldp() const; + + void setMetered(Metered metered); + Metered metered() const; + + void setMdns(Mdns mdns); + Mdns mdns() const; + + void setStableId(const QString &stableId); + QString stableId() const; + + Setting::Ptr setting(Setting::SettingType type) const; + Setting::Ptr setting(const QString &type) const; + + Setting::List settings() const; + +protected: + ConnectionSettingsPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(ConnectionSettings) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const ConnectionSettings &setting); + +} + +#endif // NETWORKMANAGERQT_CONNECTION_SETTINGS_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings_p.h b/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings_p.h new file mode 100644 index 000000000..d8fca0278 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/connectionsettings_p.h @@ -0,0 +1,58 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_CONNECTION_SETTINGS_P_H +#define NETWORKMANAGERQT_CONNECTION_SETTINGS_P_H + +#include "setting.h" + +#include +#include +#include + +namespace NetworkManager +{ +class ConnectionSettingsPrivate +{ +public: + Q_DECLARE_PUBLIC(ConnectionSettings) + + explicit ConnectionSettingsPrivate(ConnectionSettings *q); + + void addSetting(const NetworkManager::Setting::Ptr &setting); + void clearSettings(); + void initSettings(NMBluetoothCapabilities bt_cap); + void initSettings(const NetworkManager::ConnectionSettings::Ptr &connectionSettings); + + QString name; + QString id; + QString uuid; + QString interfaceName; + NetworkManager::ConnectionSettings::ConnectionType type; + QHash permissions; + bool autoconnect; + QDateTime timestamp; + bool readOnly; + QString zone; + QString master; + QString slaveType; + QStringList secondaries; + quint32 gatewayPingTimeout; + int autoconnectPriority; + int autoconnectRetries; + NetworkManager::ConnectionSettings::AutoconnectSlaves autoconnectSlaves; + NetworkManager::ConnectionSettings::Lldp lldp; + NetworkManager::ConnectionSettings::Metered metered; + NetworkManager::ConnectionSettings::Mdns mdns; + QString stableId; + Setting::List settings; + + ConnectionSettings *q_ptr; +}; + +} + +#endif // NETWORKMANAGERQT_CONNECTION_SETTINGS_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting.cpp new file mode 100644 index 000000000..c29aa459f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting.cpp @@ -0,0 +1,547 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "dcbsetting.h" +#include "dcbsetting_p.h" + +#include + +NetworkManager::DcbSettingPrivate::DcbSettingPrivate() + : name(NM_SETTING_DCB_SETTING_NAME) + , appFcoeMode(NM_SETTING_DCB_FCOE_MODE_FABRIC) + , appFcoePriority(-1) + , appFipPriority(-1) + , appIscsiPriority(-1) + , priorityFlowControl({0, 0, 0, 0, 0, 0, 0, 0}) + , priorityBandwidth({0, 0, 0, 0, 0, 0, 0, 0}) + , priorityGroupBandwidth({0, 0, 0, 0, 0, 0, 0, 0}) + , priorityGroupId({0, 0, 0, 0, 0, 0, 0, 0}) + , priorityStrictBandwidth({0, 0, 0, 0, 0, 0, 0, 0}) + , priorityTrafficClass({0, 0, 0, 0, 0, 0, 0, 0}) +{ +} + +NetworkManager::DcbSetting::DcbSetting() + : Setting(Setting::Dcb) + , d_ptr(new DcbSettingPrivate()) +{ +} + +NetworkManager::DcbSetting::DcbSetting(const Ptr &other) + : Setting(other) + , d_ptr(new DcbSettingPrivate()) +{ + setAppFcoeMode(other->appFcoeMode()); + setAppFcoePriority(other->appFcoePriority()); + setAppFipPriority(other->appFipPriority()); + setAppIscsiPriority(other->appIscsiPriority()); + setAppFcoeFlags(other->appFcoeFlags()); + setAppFipFlags(other->appFipFlags()); + setAppIscsiFlags(other->appIscsiFlags()); + setPriorityGroupFlags(other->priorityGroupFlags()); + setPriorityFlowControlFlags(other->priorityFlowControlFlags()); + setPriorityFlowControl(other->priorityFlowControl()); + setPriorityBandwidth(other->priorityBandwidth()); + setPriorityGroupBandwidth(other->priorityGroupBandwidth()); + setPriorityGroupId(other->priorityGroupId()); + setPriorityStrictBandwidth(other->priorityStrictBandwidth()); + setPriorityTrafficClass(other->priorityTrafficClass()); +} + +NetworkManager::DcbSetting::~DcbSetting() +{ + delete d_ptr; +} + +QString NetworkManager::DcbSetting::name() const +{ + Q_D(const DcbSetting); + + return d->name; +} + +void NetworkManager::DcbSetting::setAppFcoeMode(const QString &mode) +{ + Q_D(DcbSetting); + + d->appFcoeMode = mode; +} + +QString NetworkManager::DcbSetting::appFcoeMode() const +{ + Q_D(const DcbSetting); + + return d->appFcoeMode; +} + +void NetworkManager::DcbSetting::setAppFcoePriority(qint32 priority) +{ + Q_D(DcbSetting); + + d->appFcoePriority = priority; +} + +qint32 NetworkManager::DcbSetting::appFcoePriority() const +{ + Q_D(const DcbSetting); + + return d->appFcoePriority; +} + +void NetworkManager::DcbSetting::setAppFipPriority(qint32 priority) +{ + Q_D(DcbSetting); + + d->appFipPriority = priority; +} + +qint32 NetworkManager::DcbSetting::appFipPriority() const +{ + Q_D(const DcbSetting); + + return d->appFipPriority; +} + +void NetworkManager::DcbSetting::setAppIscsiPriority(qint32 priority) +{ + Q_D(DcbSetting); + + d->appIscsiPriority = priority; +} + +qint32 NetworkManager::DcbSetting::appIscsiPriority() const +{ + Q_D(const DcbSetting); + + return d->appIscsiPriority; +} + +void NetworkManager::DcbSetting::setAppFcoeFlags(NetworkManager::DcbSetting::DcbFlags flags) +{ + Q_D(DcbSetting); + + d->appFcoeFlags = flags; +} + +NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::appFcoeFlags() const +{ + Q_D(const DcbSetting); + + return d->appFcoeFlags; +} + +void NetworkManager::DcbSetting::setAppFipFlags(NetworkManager::DcbSetting::DcbFlags flags) +{ + Q_D(DcbSetting); + + d->appFipFlags = flags; +} + +NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::appFipFlags() const +{ + Q_D(const DcbSetting); + + return d->appFipFlags; +} + +void NetworkManager::DcbSetting::setAppIscsiFlags(NetworkManager::DcbSetting::DcbFlags flags) +{ + Q_D(DcbSetting); + + d->appIscsiFlags = flags; +} + +NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::appIscsiFlags() const +{ + Q_D(const DcbSetting); + + return d->appIscsiFlags; +} + +void NetworkManager::DcbSetting::setPriorityGroupFlags(NetworkManager::DcbSetting::DcbFlags flags) +{ + Q_D(DcbSetting); + + d->priorityGroupFlags = flags; +} + +NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::priorityGroupFlags() const +{ + Q_D(const DcbSetting); + + return d->priorityGroupFlags; +} + +void NetworkManager::DcbSetting::setPriorityFlowControlFlags(NetworkManager::DcbSetting::DcbFlags flags) +{ + Q_D(DcbSetting); + + d->priorityFlowControlFlags = flags; +} + +NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::priorityFlowControlFlags() const +{ + Q_D(const DcbSetting); + + return d->priorityFlowControlFlags; +} + +void NetworkManager::DcbSetting::setPriorityFlowControl(quint32 userPriority, bool enabled) +{ + Q_D(DcbSetting); + + if (userPriority < 8) { + d->priorityFlowControl[userPriority] = enabled; + } +} + +bool NetworkManager::DcbSetting::priorityFlowControl(quint32 userPriority) const +{ + Q_D(const DcbSetting); + + if (userPriority < 8) { + return d->priorityFlowControl.value(userPriority); + } + return false; +} + +void NetworkManager::DcbSetting::setPriorityFlowControl(const UIntList &list) +{ + Q_D(DcbSetting); + + d->priorityFlowControl = list; +} + +UIntList NetworkManager::DcbSetting::priorityFlowControl() const +{ + Q_D(const DcbSetting); + + return d->priorityFlowControl; +} + +void NetworkManager::DcbSetting::setPriorityBandwidth(quint32 userPriority, quint32 bandwidthPercent) +{ + Q_D(DcbSetting); + + if (userPriority < 8) { + d->priorityBandwidth[userPriority] = bandwidthPercent; + } +} + +quint32 NetworkManager::DcbSetting::priorityBandwidth(quint32 userPriority) const +{ + Q_D(const DcbSetting); + + if (userPriority < 8) { + return d->priorityBandwidth.value(userPriority); + } + return 0; +} + +void NetworkManager::DcbSetting::setPriorityBandwidth(const UIntList &list) +{ + Q_D(DcbSetting); + + d->priorityBandwidth = list; +} + +UIntList NetworkManager::DcbSetting::priorityBandwidth() const +{ + Q_D(const DcbSetting); + + return d->priorityBandwidth; +} + +void NetworkManager::DcbSetting::setPriorityGroupBandwidth(quint32 groupId, quint32 bandwidthPercent) +{ + Q_D(DcbSetting); + + if (groupId < 8) { + d->priorityGroupBandwidth[groupId] = bandwidthPercent; + } +} + +quint32 NetworkManager::DcbSetting::priorityGroupBandwidth(quint32 groupId) const +{ + Q_D(const DcbSetting); + + if (groupId < 8) { + return d->priorityGroupBandwidth.value(groupId); + } + return 0; +} + +void NetworkManager::DcbSetting::setPriorityGroupBandwidth(const UIntList &list) +{ + Q_D(DcbSetting); + + d->priorityGroupBandwidth = list; +} + +UIntList NetworkManager::DcbSetting::priorityGroupBandwidth() const +{ + Q_D(const DcbSetting); + + return d->priorityGroupBandwidth; +} + +void NetworkManager::DcbSetting::setPriorityGroupId(quint32 userPriority, quint32 groupId) +{ + Q_D(DcbSetting); + + if (userPriority < 8) { + d->priorityGroupId[userPriority] = groupId; + } +} + +quint32 NetworkManager::DcbSetting::priorityGroupId(quint32 userPriority) const +{ + Q_D(const DcbSetting); + + if (userPriority < 8) { + return d->priorityGroupId.value(userPriority); + } + return 0; +} + +void NetworkManager::DcbSetting::setPriorityGroupId(const UIntList &list) +{ + Q_D(DcbSetting); + + d->priorityGroupId = list; +} + +UIntList NetworkManager::DcbSetting::priorityGroupId() const +{ + Q_D(const DcbSetting); + + return d->priorityGroupId; +} + +void NetworkManager::DcbSetting::setPriorityStrictBandwidth(quint32 userPriority, bool strict) +{ + Q_D(DcbSetting); + + if (userPriority < 8) { + d->priorityStrictBandwidth[userPriority] = strict; + } +} + +bool NetworkManager::DcbSetting::priorityStrictBandwidth(quint32 userPriority) const +{ + Q_D(const DcbSetting); + + if (userPriority < 8) { + return d->priorityStrictBandwidth.value(userPriority); + } + return false; +} + +void NetworkManager::DcbSetting::setPriorityStrictBandwidth(const UIntList &list) +{ + Q_D(DcbSetting); + + d->priorityStrictBandwidth = list; +} + +UIntList NetworkManager::DcbSetting::priorityStrictBandwidth() const +{ + Q_D(const DcbSetting); + + return d->priorityStrictBandwidth; +} + +void NetworkManager::DcbSetting::setPriorityTrafficClass(quint32 userPriority, quint32 trafficClass) +{ + Q_D(DcbSetting); + + if (userPriority < 8) { + d->priorityTrafficClass[userPriority] = trafficClass; + } +} + +quint32 NetworkManager::DcbSetting::priorityTrafficClass(quint32 userPriority) const +{ + Q_D(const DcbSetting); + + if (userPriority < 8) { + return d->priorityTrafficClass.value(userPriority); + } + return 0; +} + +void NetworkManager::DcbSetting::setPriorityTrafficClass(const UIntList &list) +{ + Q_D(DcbSetting); + + d->priorityTrafficClass = list; +} + +UIntList NetworkManager::DcbSetting::priorityTrafficClass() const +{ + Q_D(const DcbSetting); + + return d->priorityTrafficClass; +} + +void NetworkManager::DcbSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_DCB_APP_FCOE_MODE))) { + setAppFcoeMode(setting.value(QLatin1String(NM_SETTING_DCB_APP_FCOE_MODE)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_APP_FCOE_PRIORITY))) { + setAppFcoePriority(setting.value(QLatin1String(NM_SETTING_DCB_APP_FCOE_PRIORITY)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_APP_FIP_PRIORITY))) { + setAppFipPriority(setting.value(QLatin1String(NM_SETTING_DCB_APP_FIP_PRIORITY)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_APP_ISCSI_PRIORITY))) { + setAppIscsiPriority(setting.value(QLatin1String(NM_SETTING_DCB_APP_ISCSI_PRIORITY)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_APP_FCOE_FLAGS))) { + setAppFcoeFlags(static_cast(setting.value(QLatin1String(NM_SETTING_DCB_APP_FCOE_FLAGS)).toUInt())); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_APP_FIP_FLAGS))) { + setAppFipFlags(static_cast(setting.value(QLatin1String(NM_SETTING_DCB_APP_FIP_FLAGS)).toUInt())); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_APP_ISCSI_FLAGS))) { + setAppIscsiFlags(static_cast(setting.value(QLatin1String(NM_SETTING_DCB_APP_ISCSI_FLAGS)).toUInt())); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_FLAGS))) { + setPriorityGroupFlags(static_cast(setting.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_FLAGS)).toUInt())); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS))) { + setPriorityFlowControlFlags(static_cast(setting.value(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS)).toUInt())); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL))) { + setPriorityFlowControl(qdbus_cast(setting.value(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH))) { + setPriorityBandwidth(qdbus_cast(setting.value(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH))) { + setPriorityGroupBandwidth(qdbus_cast(setting.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID))) { + setPriorityGroupId(qdbus_cast(setting.value(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH))) { + setPriorityStrictBandwidth(qdbus_cast(setting.value(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS))) { + setPriorityTrafficClass(qdbus_cast(setting.value(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS)))); + } +} + +QVariantMap NetworkManager::DcbSetting::toMap() const +{ + QVariantMap setting; + + if (!appFcoeMode().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_MODE), appFcoeMode()); + } + + if (appFcoePriority() >= 0) { + setting.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_PRIORITY), appFcoePriority()); + } + + if (appFipPriority() >= 0) { + setting.insert(QLatin1String(NM_SETTING_DCB_APP_FIP_PRIORITY), appFipPriority()); + } + + if (appIscsiPriority() >= 0) { + setting.insert(QLatin1String(NM_SETTING_DCB_APP_ISCSI_PRIORITY), appIscsiPriority()); + } + + setting.insert(QLatin1String(NM_SETTING_DCB_APP_FCOE_FLAGS), (int)appFcoeFlags()); + setting.insert(QLatin1String(NM_SETTING_DCB_APP_FIP_FLAGS), (int)appFipFlags()); + setting.insert(QLatin1String(NM_SETTING_DCB_APP_ISCSI_FLAGS), (int)appIscsiFlags()); + setting.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_FLAGS), (int)priorityGroupFlags()); + setting.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS), (int)priorityFlowControlFlags()); + + setting.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL), QVariant::fromValue(priorityFlowControl())); + setting.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH), QVariant::fromValue(priorityBandwidth())); + setting.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH), QVariant::fromValue(priorityGroupBandwidth())); + setting.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID), QVariant::fromValue(priorityGroupId())); + setting.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH), QVariant::fromValue(priorityStrictBandwidth())); + setting.insert(QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS), QVariant::fromValue(priorityTrafficClass())); + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::DcbSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_DCB_APP_FCOE_MODE << ": " << setting.appFcoeMode() << '\n'; + dbg.nospace() << NM_SETTING_DCB_APP_FCOE_PRIORITY << ": " << setting.appFcoePriority() << '\n'; + dbg.nospace() << NM_SETTING_DCB_APP_FIP_PRIORITY << ": " << setting.appFipPriority() << '\n'; + dbg.nospace() << NM_SETTING_DCB_APP_ISCSI_PRIORITY << ": " << setting.appIscsiPriority() << '\n'; + dbg.nospace() << NM_SETTING_DCB_APP_FCOE_FLAGS << ": " << setting.appFcoeFlags() << '\n'; + dbg.nospace() << NM_SETTING_DCB_APP_FIP_FLAGS << ": " << setting.appFipFlags() << '\n'; + dbg.nospace() << NM_SETTING_DCB_APP_ISCSI_FLAGS << ": " << setting.appIscsiFlags() << '\n'; + dbg.nospace() << NM_SETTING_DCB_PRIORITY_GROUP_FLAGS << ": " << setting.priorityGroupFlags() << '\n'; + dbg.nospace() << NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS << ": " << setting.priorityFlowControlFlags() << '\n'; + + dbg.nospace() << NM_SETTING_DCB_PRIORITY_FLOW_CONTROL << ": "; + const auto flowControlList = setting.priorityFlowControl(); + for (const quint32 enabled : flowControlList) { + dbg.nospace() << enabled << ' '; + } + dbg.nospace() << '\n'; + + dbg.nospace() << NM_SETTING_DCB_PRIORITY_BANDWIDTH << ": "; + const auto bwList = setting.priorityBandwidth(); + for (const quint32 bandwidthPercent : bwList) { + dbg.nospace() << bandwidthPercent << ' '; + } + dbg.nospace() << '\n'; + + dbg.nospace() << NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH << ": "; + const auto gbwList = setting.priorityGroupBandwidth(); + for (const quint32 bandwidthPercent : gbwList) { + dbg.nospace() << bandwidthPercent << ' '; + } + dbg.nospace() << '\n'; + + dbg.nospace() << NM_SETTING_DCB_PRIORITY_GROUP_ID << ": "; + const auto groupIds = setting.priorityGroupId(); + for (const quint32 groupId : groupIds) { + dbg.nospace() << groupId << ' '; + } + dbg.nospace() << '\n'; + + dbg.nospace() << NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH << ": "; + const auto strictList = setting.priorityStrictBandwidth(); + for (const quint32 strict : strictList) { + dbg.nospace() << strict << ' '; + } + dbg.nospace() << '\n'; + + dbg.nospace() << NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS << ": "; + const auto trafficList = setting.priorityTrafficClass(); + for (const quint32 trafficClass : trafficList) { + dbg.nospace() << trafficClass << ' '; + } + dbg.nospace() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting.h new file mode 100644 index 000000000..39b4018f5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting.h @@ -0,0 +1,115 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DCBSETTING_H +#define NETWORKMANAGERQT_DCBSETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class DcbSettingPrivate; + +/** + * Represents Dcb setting + */ +class NETWORKMANAGERQT_EXPORT DcbSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + enum DcbFlagType { + None = 0, + Enable = 0x01, + Advertise = 0x02, + Willing = 0x04, + }; + Q_DECLARE_FLAGS(DcbFlags, DcbFlagType) + + DcbSetting(); + explicit DcbSetting(const Ptr &other); + ~DcbSetting() override; + + QString name() const override; + + void setAppFcoeMode(const QString &mode); + QString appFcoeMode() const; + + void setAppFcoePriority(qint32 priority); + qint32 appFcoePriority() const; + + void setAppFipPriority(qint32 priority); + qint32 appFipPriority() const; + + void setAppIscsiPriority(qint32 priority); + qint32 appIscsiPriority() const; + + void setAppFcoeFlags(DcbFlags flags); + DcbFlags appFcoeFlags() const; + + void setAppFipFlags(DcbFlags flags); + DcbFlags appFipFlags() const; + + void setAppIscsiFlags(DcbFlags flags); + DcbFlags appIscsiFlags() const; + + void setPriorityGroupFlags(DcbFlags flags); + DcbFlags priorityGroupFlags() const; + + void setPriorityFlowControlFlags(DcbFlags flags); + DcbFlags priorityFlowControlFlags() const; + + void setPriorityFlowControl(quint32 userPriority, bool enabled); + bool priorityFlowControl(quint32 userPriority) const; + void setPriorityFlowControl(const UIntList &list); + UIntList priorityFlowControl() const; + + void setPriorityBandwidth(quint32 userPriority, quint32 bandwidthPercent); + quint32 priorityBandwidth(quint32 userPriority) const; + void setPriorityBandwidth(const UIntList &list); + UIntList priorityBandwidth() const; + + void setPriorityGroupBandwidth(quint32 groupId, quint32 bandwidthPercent); + quint32 priorityGroupBandwidth(quint32 groupId) const; + void setPriorityGroupBandwidth(const UIntList &list); + UIntList priorityGroupBandwidth() const; + + void setPriorityGroupId(quint32 userPriority, quint32 groupId); + quint32 priorityGroupId(quint32 userPriority) const; + void setPriorityGroupId(const UIntList &list); + UIntList priorityGroupId() const; + + void setPriorityStrictBandwidth(quint32 userPriority, bool strict); + bool priorityStrictBandwidth(quint32 userPriority) const; + void setPriorityStrictBandwidth(const UIntList &list); + UIntList priorityStrictBandwidth() const; + + void setPriorityTrafficClass(quint32 userPriority, quint32 trafficClass); + quint32 priorityTrafficClass(quint32 userPriority) const; + void setPriorityTrafficClass(const UIntList &list); + UIntList priorityTrafficClass() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + DcbSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(DcbSetting) +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(DcbSetting::DcbFlags) + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const DcbSetting &setting); + +} + +#endif // NETWORKMANAGERQT_DCBSETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting_p.h new file mode 100644 index 000000000..348d3413f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/dcbsetting_p.h @@ -0,0 +1,40 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_DCBSETTING_P_H +#define NETWORKMANAGERQT_DCBSETTING_P_H + +#include + +namespace NetworkManager +{ +class DcbSettingPrivate +{ +public: + DcbSettingPrivate(); + + QString name; + + QString appFcoeMode; + qint32 appFcoePriority; + qint32 appFipPriority; + qint32 appIscsiPriority; + NetworkManager::DcbSetting::DcbFlags appFcoeFlags; + NetworkManager::DcbSetting::DcbFlags appFipFlags; + NetworkManager::DcbSetting::DcbFlags appIscsiFlags; + NetworkManager::DcbSetting::DcbFlags priorityGroupFlags; + NetworkManager::DcbSetting::DcbFlags priorityFlowControlFlags; + UIntList priorityFlowControl; + UIntList priorityBandwidth; + UIntList priorityGroupBandwidth; + UIntList priorityGroupId; + UIntList priorityStrictBandwidth; + UIntList priorityTrafficClass; +}; + +} + +#endif // NETWORKMANAGERQT_DCBSETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/genericsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/genericsetting.cpp new file mode 100644 index 000000000..f1b38a8af --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/genericsetting.cpp @@ -0,0 +1,59 @@ +/* + SPDX-FileCopyrightText: 2015 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "genericsetting.h" +#include "genericsetting_p.h" + +#include "nmdebug.h" + +NetworkManager::GenericSettingPrivate::GenericSettingPrivate() + : name(NM_SETTING_GENERIC_SETTING_NAME) +{ +} + +NetworkManager::GenericSetting::GenericSetting() + : Setting(Setting::Generic) + , d_ptr(new GenericSettingPrivate()) +{ +} + +NetworkManager::GenericSetting::GenericSetting(const Ptr &other) + : Setting(other) + , d_ptr(new GenericSettingPrivate()) +{ +} + +NetworkManager::GenericSetting::~GenericSetting() +{ + delete d_ptr; +} + +QString NetworkManager::GenericSetting::name() const +{ + Q_D(const GenericSetting); + + return d->name; +} + +void NetworkManager::GenericSetting::fromMap(const QVariantMap &setting) +{ + Q_UNUSED(setting); +} + +QVariantMap NetworkManager::GenericSetting::toMap() const +{ + QVariantMap setting; + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::GenericSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/genericsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/genericsetting.h new file mode 100644 index 000000000..b7fa3ecac --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/genericsetting.h @@ -0,0 +1,48 @@ +/* + SPDX-FileCopyrightText: 2015 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_GENERIC_SETTING_H +#define NETWORKMANAGERQT_GENERIC_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class GenericSettingPrivate; + +/** + * Represents generic setting + */ +class NETWORKMANAGERQT_EXPORT GenericSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + GenericSetting(); + explicit GenericSetting(const Ptr &other); + ~GenericSetting() override; + + QString name() const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + GenericSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(GenericSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const GenericSetting &setting); + +} + +#endif // NETWORKMANAGERQT_GENERIC_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/genericsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/genericsetting_p.h new file mode 100644 index 000000000..8992802e0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/genericsetting_p.h @@ -0,0 +1,24 @@ +/* + SPDX-FileCopyrightText: 2015 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_GENERIC_SETTING_P_H +#define NETWORKMANAGERQT_GENERIC_SETTING_P_H + +#include + +namespace NetworkManager +{ +class GenericSettingPrivate +{ +public: + GenericSettingPrivate(); + + QString name; +}; + +} + +#endif // NETWORKMANAGERQT_GENERIC_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting.cpp new file mode 100644 index 000000000..f38afeabf --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting.cpp @@ -0,0 +1,441 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "gsmsetting.h" +#include "gsmsetting_p.h" + +#define NM_SETTING_GSM_NETWORK_TYPE "network-type" +#define NM_SETTING_GSM_ALLOWED_BANDS "allowed-bands" + +#include + +NetworkManager::GsmSettingPrivate::GsmSettingPrivate() + : name(NM_SETTING_GSM_SETTING_NAME) + , passwordFlags(NetworkManager::GsmSetting::None) + , networkType(NetworkManager::GsmSetting::Any) + , pinFlags(NetworkManager::GsmSetting::None) + , allowedBand(1) + , homeOnly(false) +{ +} + +NetworkManager::GsmSetting::GsmSetting() + : Setting(Setting::Gsm) + , d_ptr(new GsmSettingPrivate()) +{ +} + +NetworkManager::GsmSetting::GsmSetting(const Ptr &other) + : Setting(other) + , d_ptr(new GsmSettingPrivate()) +{ + setNumber(other->number()); + setUsername(other->username()); + setPassword(other->password()); + setPasswordFlags(other->passwordFlags()); + setApn(other->apn()); + setNetworkId(other->networkId()); + setNetworkType(other->networkType()); + setPin(other->pin()); + setPinFlags(other->pinFlags()); + setAllowedBand(other->allowedBand()); + setHomeOnly(other->homeOnly()); + setDeviceId(other->deviceId()); + setSimId(other->simId()); + setSimOperatorId(other->simOperatorId()); +} + +NetworkManager::GsmSetting::~GsmSetting() +{ + delete d_ptr; +} + +QString NetworkManager::GsmSetting::name() const +{ + Q_D(const GsmSetting); + + return d->name; +} + +void NetworkManager::GsmSetting::setNumber(const QString &number) +{ + Q_D(GsmSetting); + + d->number = number; +} + +QString NetworkManager::GsmSetting::number() const +{ + Q_D(const GsmSetting); + + return d->number; +} + +void NetworkManager::GsmSetting::setUsername(const QString &username) +{ + Q_D(GsmSetting); + + d->username = username; +} + +QString NetworkManager::GsmSetting::username() const +{ + Q_D(const GsmSetting); + + return d->username; +} + +void NetworkManager::GsmSetting::setPassword(const QString &password) +{ + Q_D(GsmSetting); + + d->password = password; +} + +QString NetworkManager::GsmSetting::password() const +{ + Q_D(const GsmSetting); + + return d->password; +} + +void NetworkManager::GsmSetting::setPasswordFlags(GsmSetting::SecretFlags flags) +{ + Q_D(GsmSetting); + + d->passwordFlags = flags; +} + +NetworkManager::GsmSetting::SecretFlags NetworkManager::GsmSetting::passwordFlags() const +{ + Q_D(const GsmSetting); + + return d->passwordFlags; +} + +void NetworkManager::GsmSetting::setApn(const QString &apn) +{ + Q_D(GsmSetting); + + d->apn = apn; +} + +QString NetworkManager::GsmSetting::apn() const +{ + Q_D(const GsmSetting); + + return d->apn; +} + +void NetworkManager::GsmSetting::setNetworkId(const QString &id) +{ + Q_D(GsmSetting); + + d->networkId = id; +} + +QString NetworkManager::GsmSetting::networkId() const +{ + Q_D(const GsmSetting); + + return d->networkId; +} + +void NetworkManager::GsmSetting::setNetworkType(NetworkType type) +{ + Q_D(GsmSetting); + + d->networkType = type; +} + +NetworkManager::GsmSetting::NetworkType NetworkManager::GsmSetting::networkType() const +{ + Q_D(const GsmSetting); + + return d->networkType; +} + +void NetworkManager::GsmSetting::setPin(const QString &pin) +{ + Q_D(GsmSetting); + + d->pin = pin; +} + +QString NetworkManager::GsmSetting::pin() const +{ + Q_D(const GsmSetting); + + return d->pin; +} + +void NetworkManager::GsmSetting::setPinFlags(GsmSetting::SecretFlags flags) +{ + Q_D(GsmSetting); + + d->pinFlags = flags; +} + +NetworkManager::GsmSetting::SecretFlags NetworkManager::GsmSetting::pinFlags() const +{ + Q_D(const GsmSetting); + + return d->pinFlags; +} + +void NetworkManager::GsmSetting::setAllowedBand(quint32 band) +{ + Q_D(GsmSetting); + + d->allowedBand = band; +} + +quint32 NetworkManager::GsmSetting::allowedBand() const +{ + Q_D(const GsmSetting); + + return d->allowedBand; +} + +void NetworkManager::GsmSetting::setHomeOnly(bool homeOnly) +{ + Q_D(GsmSetting); + + d->homeOnly = homeOnly; +} + +bool NetworkManager::GsmSetting::homeOnly() const +{ + Q_D(const GsmSetting); + + return d->homeOnly; +} + +void NetworkManager::GsmSetting::setDeviceId(const QString &id) +{ + Q_D(GsmSetting); + + d->deviceId = id; +} + +QString NetworkManager::GsmSetting::deviceId() const +{ + Q_D(const GsmSetting); + + return d->deviceId; +} + +void NetworkManager::GsmSetting::setSimId(const QString &id) +{ + Q_D(GsmSetting); + + d->simId = id; +} + +QString NetworkManager::GsmSetting::simId() const +{ + Q_D(const GsmSetting); + + return d->simId; +} + +void NetworkManager::GsmSetting::setSimOperatorId(const QString &id) +{ + Q_D(GsmSetting); + + d->simOperatorId = id; +} + +QString NetworkManager::GsmSetting::simOperatorId() const +{ + Q_D(const GsmSetting); + + return d->simOperatorId; +} + +void NetworkManager::GsmSetting::secretsFromMap(const QVariantMap &secrets) +{ + if (secrets.contains(QLatin1String(NM_SETTING_GSM_PASSWORD))) { + setPassword(secrets.value(QLatin1String(NM_SETTING_GSM_PASSWORD)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_GSM_PIN))) { + setPin(secrets.value(QLatin1String(NM_SETTING_GSM_PIN)).toString()); + } +} + +QVariantMap NetworkManager::GsmSetting::secretsToMap() const +{ + QVariantMap secrets; + + if (!password().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_GSM_PASSWORD), password()); + } + + if (!pin().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_GSM_PIN), pin()); + } + + return secrets; +} + +QStringList NetworkManager::GsmSetting::needSecrets(bool requestNew) const +{ + QStringList list; + + if ((password().isEmpty() || requestNew) && !passwordFlags().testFlag(NotRequired)) { + list << QLatin1String(NM_SETTING_GSM_PASSWORD); + } + + if ((pin().isEmpty() || requestNew) && !pinFlags().testFlag(NotRequired)) { + list << QLatin1String(NM_SETTING_GSM_PIN); + } + + return list; +} + +void NetworkManager::GsmSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_GSM_NUMBER))) { + setNumber(setting.value(QLatin1String(NM_SETTING_GSM_NUMBER)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_USERNAME))) { + setUsername(setting.value(QLatin1String(NM_SETTING_GSM_USERNAME)).toString()); + } + + // Secrets + if (setting.contains(QLatin1String(NM_SETTING_GSM_PASSWORD))) { + setPassword(setting.value(QLatin1String(NM_SETTING_GSM_PASSWORD)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_PASSWORD_FLAGS))) { + setPasswordFlags((SecretFlags)setting.value(QLatin1String(NM_SETTING_GSM_PASSWORD_FLAGS)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_APN))) { + setApn(setting.value(QLatin1String(NM_SETTING_GSM_APN)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_NETWORK_ID))) { + setNetworkId(setting.value(QLatin1String(NM_SETTING_GSM_NETWORK_ID)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE))) { + setNetworkType((NetworkType)setting.value(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE)).toInt()); + } + + // Secrets + if (setting.contains(QLatin1String(NM_SETTING_GSM_PIN))) { + setPin(setting.value(QLatin1String(NM_SETTING_GSM_PIN)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_PIN_FLAGS))) { + setPinFlags((SecretFlags)setting.value(QLatin1String(NM_SETTING_GSM_PIN_FLAGS)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_ALLOWED_BANDS))) { + setAllowedBand(setting.value(QLatin1String(NM_SETTING_GSM_ALLOWED_BANDS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_HOME_ONLY))) { + setHomeOnly(setting.value(QLatin1String(NM_SETTING_GSM_HOME_ONLY)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_DEVICE_ID))) { + setDeviceId(setting.value(QLatin1String(NM_SETTING_GSM_DEVICE_ID)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_SIM_ID))) { + setSimId(setting.value(QLatin1String(NM_SETTING_GSM_SIM_ID)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_GSM_SIM_OPERATOR_ID))) { + setSimOperatorId(setting.value(QLatin1String(NM_SETTING_GSM_SIM_OPERATOR_ID)).toString()); + } +} + +QVariantMap NetworkManager::GsmSetting::toMap() const +{ + QVariantMap setting; + + if (!number().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_NUMBER), number()); + } + + if (!username().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_USERNAME), username()); + } + + // Secrets + if (!password().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_PASSWORD), password()); + } + + setting.insert(QLatin1String(NM_SETTING_GSM_PASSWORD_FLAGS), (int)passwordFlags()); + + if (!apn().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_APN), apn()); + } + + if (!networkId().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_NETWORK_ID), networkId()); + } + + if (networkType() != -1) { + setting.insert(QLatin1String(NM_SETTING_GSM_NETWORK_TYPE), networkType()); + } + // Secrets + if (!pin().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_PIN), pin()); + } + + setting.insert(QLatin1String(NM_SETTING_GSM_PIN_FLAGS), (int)pinFlags()); + + if (allowedBand() != 1) { + setting.insert(QLatin1String(NM_SETTING_GSM_ALLOWED_BANDS), allowedBand()); + } + if (homeOnly()) { + setting.insert(QLatin1String(NM_SETTING_GSM_HOME_ONLY), homeOnly()); + } + + if (!deviceId().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_DEVICE_ID), deviceId()); + } + + if (!simId().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_SIM_ID), simId()); + } + + if (!simOperatorId().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_GSM_SIM_OPERATOR_ID), simOperatorId()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::GsmSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_GSM_NUMBER << ": " << setting.number() << '\n'; + dbg.nospace() << NM_SETTING_GSM_USERNAME << ": " << setting.username() << '\n'; + dbg.nospace() << NM_SETTING_GSM_PASSWORD << ": " << setting.password() << '\n'; + dbg.nospace() << NM_SETTING_GSM_PASSWORD_FLAGS << ": " << setting.passwordFlags() << '\n'; + dbg.nospace() << NM_SETTING_GSM_APN << ": " << setting.apn() << '\n'; + dbg.nospace() << NM_SETTING_GSM_NETWORK_ID << ": " << setting.networkId() << '\n'; + dbg.nospace() << NM_SETTING_GSM_NETWORK_TYPE << ": " << setting.networkType() << '\n'; + dbg.nospace() << NM_SETTING_GSM_ALLOWED_BANDS << ": " << setting.allowedBand() << '\n'; + dbg.nospace() << NM_SETTING_GSM_PIN << ": " << setting.pin() << '\n'; + dbg.nospace() << NM_SETTING_GSM_PIN_FLAGS << ": " << setting.pinFlags() << '\n'; + dbg.nospace() << NM_SETTING_GSM_HOME_ONLY << ": " << setting.homeOnly() << '\n'; + dbg.nospace() << NM_SETTING_GSM_DEVICE_ID << ": " << setting.deviceId() << '\n'; + dbg.nospace() << NM_SETTING_GSM_SIM_ID << ": " << setting.simId() << '\n'; + dbg.nospace() << NM_SETTING_GSM_SIM_OPERATOR_ID << ": " << setting.simOperatorId() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting.h new file mode 100644 index 000000000..ff357745c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting.h @@ -0,0 +1,108 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_GSM_SETTING_H +#define NETWORKMANAGERQT_GSM_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class GsmSettingPrivate; + +/** + * Represents gsm setting + */ +class NETWORKMANAGERQT_EXPORT GsmSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum NetworkType { + Any = -1, + Only3G, + GprsEdgeOnly, + Prefer3G, + Prefer2G, + Prefer4GLte, + Only4GLte, + }; + + GsmSetting(); + explicit GsmSetting(const Ptr &other); + ~GsmSetting() override; + + QString name() const override; + + void setNumber(const QString &number); + QString number() const; + + void setUsername(const QString &username); + QString username() const; + + void setPassword(const QString &password); + QString password() const; + + void setPasswordFlags(SecretFlags flags); + SecretFlags passwordFlags() const; + + void setApn(const QString &apn); + QString apn() const; + + void setNetworkId(const QString &id); + QString networkId() const; + + /// @deprecated since NM 1.0.0 + void setNetworkType(NetworkType type); + NetworkType networkType() const; + + void setPin(const QString &pin); + QString pin() const; + + void setPinFlags(SecretFlags flags); + SecretFlags pinFlags() const; + + /// @deprecated since NM 1.0.0 + void setAllowedBand(quint32 band); + quint32 allowedBand() const; + + void setHomeOnly(bool homeOnly); + bool homeOnly() const; + + void setDeviceId(const QString &id); + QString deviceId() const; + + void setSimId(const QString &id); + QString simId() const; + + void setSimOperatorId(const QString &id); + QString simOperatorId() const; + + void secretsFromMap(const QVariantMap &secrets) override; + + QVariantMap secretsToMap() const override; + + QStringList needSecrets(bool requestNew = false) const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + GsmSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(GsmSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const GsmSetting &setting); + +} + +#endif // NETWORKMANAGERQT_GSM_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting_p.h new file mode 100644 index 000000000..74cc737d0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/gsmsetting_p.h @@ -0,0 +1,38 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_GSM_SETTING_P_H +#define NETWORKMANAGERQT_GSM_SETTING_P_H + +#include + +namespace NetworkManager +{ +class GsmSettingPrivate +{ +public: + GsmSettingPrivate(); + + QString name; + QString number; + QString username; + QString password; + NetworkManager::Setting::SecretFlags passwordFlags; + QString apn; + QString networkId; + NetworkManager::GsmSetting::NetworkType networkType; + QString pin; + NetworkManager::Setting::SecretFlags pinFlags; + quint32 allowedBand; + bool homeOnly; + QString deviceId; + QString simId; + QString simOperatorId; +}; + +} + +#endif // NETWORKMANAGERQT_GSM_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting.cpp new file mode 100644 index 000000000..cc6fe44d0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting.cpp @@ -0,0 +1,191 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "infinibandsetting.h" +#include "infinibandsetting_p.h" + +#include + +NetworkManager::InfinibandSettingPrivate::InfinibandSettingPrivate() + : name(NM_SETTING_INFINIBAND_SETTING_NAME) + , mtu(0) + , transportMode(InfinibandSetting::Unknown) + , pKey(-1) +{ +} + +NetworkManager::InfinibandSetting::InfinibandSetting() + : Setting(Setting::Infiniband) + , d_ptr(new InfinibandSettingPrivate()) +{ +} + +NetworkManager::InfinibandSetting::InfinibandSetting(const NetworkManager::InfinibandSetting::Ptr &other) + : Setting(other) + , d_ptr(new InfinibandSettingPrivate()) +{ + setMacAddress(other->macAddress()); + setMtu(other->mtu()); + setTransportMode(other->transportMode()); + setPKey(other->pKey()); + setParent(other->parent()); +} + +NetworkManager::InfinibandSetting::~InfinibandSetting() +{ + delete d_ptr; +} + +QString NetworkManager::InfinibandSetting::name() const +{ + Q_D(const InfinibandSetting); + + return d->name; +} + +void NetworkManager::InfinibandSetting::setMacAddress(const QByteArray &address) +{ + Q_D(InfinibandSetting); + + d->macAddress = address; +} + +QByteArray NetworkManager::InfinibandSetting::macAddress() const +{ + Q_D(const InfinibandSetting); + + return d->macAddress; +} + +void NetworkManager::InfinibandSetting::setMtu(quint32 mtu) +{ + Q_D(InfinibandSetting); + + d->mtu = mtu; +} + +quint32 NetworkManager::InfinibandSetting::mtu() const +{ + Q_D(const InfinibandSetting); + + return d->mtu; +} + +void NetworkManager::InfinibandSetting::setTransportMode(NetworkManager::InfinibandSetting::TransportMode mode) +{ + Q_D(InfinibandSetting); + + d->transportMode = mode; +} + +NetworkManager::InfinibandSetting::TransportMode NetworkManager::InfinibandSetting::transportMode() const +{ + Q_D(const InfinibandSetting); + + return d->transportMode; +} + +void NetworkManager::InfinibandSetting::setPKey(qint32 key) +{ + Q_D(InfinibandSetting); + + d->pKey = key; +} + +qint32 NetworkManager::InfinibandSetting::pKey() const +{ + Q_D(const InfinibandSetting); + + return d->pKey; +} + +void NetworkManager::InfinibandSetting::setParent(const QString &parent) +{ + Q_D(InfinibandSetting); + + d->parent = parent; +} + +QString NetworkManager::InfinibandSetting::parent() const +{ + Q_D(const InfinibandSetting); + + return d->parent; +} + +void NetworkManager::InfinibandSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS))) { + setMacAddress(setting.value(QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_MTU))) { + setMtu(setting.value(QLatin1String(NM_SETTING_INFINIBAND_MTU)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE))) { + QString mode = setting.value(QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE)).toString(); + + if (mode == "datagram") { + setTransportMode(Datagram); + } else if (mode == "connected") { + setTransportMode(Connected); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_P_KEY))) { + setPKey(setting.value(QLatin1String(NM_SETTING_INFINIBAND_P_KEY)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_INFINIBAND_PARENT))) { + setParent(setting.value(QLatin1String(NM_SETTING_INFINIBAND_PARENT)).toString()); + } +} + +QVariantMap NetworkManager::InfinibandSetting::toMap() const +{ + QVariantMap setting; + + if (!macAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_INFINIBAND_MAC_ADDRESS), macAddress()); + } + + if (mtu()) { + setting.insert(QLatin1String(NM_SETTING_INFINIBAND_MTU), mtu()); + } + + if (transportMode() != Unknown) { + if (transportMode() == Datagram) { + setting.insert(QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE), "datagram"); + } else if (transportMode() == Connected) { + setting.insert(QLatin1String(NM_SETTING_INFINIBAND_TRANSPORT_MODE), "connected"); + } + } + + if (pKey() != -1) { + setting.insert(QLatin1String(NM_SETTING_INFINIBAND_P_KEY), pKey()); + } + + if (!parent().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_INFINIBAND_PARENT), parent()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::InfinibandSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_INFINIBAND_MAC_ADDRESS << ": " << setting.macAddress() << '\n'; + dbg.nospace() << NM_SETTING_INFINIBAND_MTU << ": " << setting.mtu() << '\n'; + dbg.nospace() << NM_SETTING_INFINIBAND_TRANSPORT_MODE << ": " << setting.transportMode() << '\n'; + dbg.nospace() << NM_SETTING_INFINIBAND_P_KEY << ": " << setting.pKey() << '\n'; + dbg.nospace() << NM_SETTING_INFINIBAND_PARENT << ": " << setting.parent() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting.h new file mode 100644 index 000000000..59adfe79f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting.h @@ -0,0 +1,69 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_INFINIBAND_SETTING_H +#define NETWORKMANAGERQT_INFINIBAND_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class InfinibandSettingPrivate; + +/** + * Represents infiniband setting + */ +class NETWORKMANAGERQT_EXPORT InfinibandSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum TransportMode { + Unknown = 0, + Datagram, + Connected, + }; + + InfinibandSetting(); + explicit InfinibandSetting(const Ptr &other); + ~InfinibandSetting() override; + + QString name() const override; + + void setMacAddress(const QByteArray &address); + QByteArray macAddress() const; + + void setMtu(quint32 mtu); + quint32 mtu() const; + + void setTransportMode(TransportMode mode); + TransportMode transportMode() const; + + void setPKey(qint32 key); + qint32 pKey() const; + + void setParent(const QString &parent); + QString parent() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + InfinibandSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(InfinibandSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const InfinibandSetting &setting); + +} + +#endif // NETWORKMANAGERQT_INFINIBAND_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting_p.h new file mode 100644 index 000000000..39804e312 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/infinibandsetting_p.h @@ -0,0 +1,29 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_INFINIBAND_SETTING_P_H +#define NETWORKMANAGERQT_INFINIBAND_SETTING_P_H + +#include + +namespace NetworkManager +{ +class InfinibandSettingPrivate +{ +public: + InfinibandSettingPrivate(); + + QString name; + QByteArray macAddress; + quint32 mtu; + NetworkManager::InfinibandSetting::TransportMode transportMode; + qint32 pKey; + QString parent; +}; + +} + +#endif // NETWORKMANAGERQT_INFINIBAND_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting.cpp new file mode 100644 index 000000000..9738f343a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting.cpp @@ -0,0 +1,380 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "iptunnelsetting.h" +#include "iptunnelsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 12, 0) +#define NM_SETTING_IP_TUNNEL_FLAGS "flags" +#endif + +NetworkManager::IpTunnelSettingPrivate::IpTunnelSettingPrivate() + : name(NM_SETTING_IP_TUNNEL_SETTING_NAME) + , mode(IpTunnelSetting::Unknown) + , pathMtuDiscovery(true) + , encapsulationLimit(0) + , flags(IpTunnelSetting::None) + , flowLabel(0) + , mtu(0) + , tos(0) + , ttl(0) +{ +} + +NetworkManager::IpTunnelSetting::IpTunnelSetting() + : Setting(Setting::IpTunnel) + , d_ptr(new IpTunnelSettingPrivate()) +{ +} + +NetworkManager::IpTunnelSetting::IpTunnelSetting(const Ptr &other) + : Setting(other) + , d_ptr(new IpTunnelSettingPrivate()) +{ + setMode(other->mode()); + setPathMtuDiscovery(other->pathMtuDiscovery()); + setEncapsulationLimit(other->encapsulationLimit()); + setFlags(other->flags()); + setFlowLabel(other->flowLabel()); + setMtu(other->mtu()); + setTos(other->tos()); + setTtl(other->ttl()); + setInputKey(other->inputKey()); + setLocal(other->local()); + setOutputKey(other->outputKey()); + setParent(other->parent()); + setRemote(other->remote()); +} + +NetworkManager::IpTunnelSetting::~IpTunnelSetting() +{ + delete d_ptr; +} + +QString NetworkManager::IpTunnelSetting::name() const +{ + Q_D(const IpTunnelSetting); + + return d->name; +} + +void NetworkManager::IpTunnelSetting::setMode(NetworkManager::IpTunnelSetting::Mode mode) +{ + Q_D(IpTunnelSetting); + + d->mode = mode; +} + +NetworkManager::IpTunnelSetting::Mode NetworkManager::IpTunnelSetting::mode() const +{ + Q_D(const IpTunnelSetting); + + return d->mode; +} + +void NetworkManager::IpTunnelSetting::setPathMtuDiscovery(bool discovery) +{ + Q_D(IpTunnelSetting); + + d->pathMtuDiscovery = discovery; +} + +bool NetworkManager::IpTunnelSetting::pathMtuDiscovery() const +{ + Q_D(const IpTunnelSetting); + + return d->pathMtuDiscovery; +} + +void NetworkManager::IpTunnelSetting::setEncapsulationLimit(quint32 limit) +{ + Q_D(IpTunnelSetting); + + d->encapsulationLimit = limit; +} + +quint32 NetworkManager::IpTunnelSetting::encapsulationLimit() const +{ + Q_D(const IpTunnelSetting); + + return d->encapsulationLimit; +} + +void NetworkManager::IpTunnelSetting::setFlags(NetworkManager::IpTunnelSetting::Flags flags) +{ + Q_D(IpTunnelSetting); + + d->flags = flags; +} + +NetworkManager::IpTunnelSetting::Flags NetworkManager::IpTunnelSetting::flags() const +{ + Q_D(const IpTunnelSetting); + + return d->flags; +} + +void NetworkManager::IpTunnelSetting::setFlowLabel(quint32 label) +{ + Q_D(IpTunnelSetting); + + d->flowLabel = label; +} + +quint32 NetworkManager::IpTunnelSetting::flowLabel() const +{ + Q_D(const IpTunnelSetting); + + return d->flowLabel; +} + +void NetworkManager::IpTunnelSetting::setMtu(quint32 mtu) +{ + Q_D(IpTunnelSetting); + + d->mtu = mtu; +} + +quint32 NetworkManager::IpTunnelSetting::mtu() const +{ + Q_D(const IpTunnelSetting); + + return d->mtu; +} + +void NetworkManager::IpTunnelSetting::setTos(quint32 tos) +{ + Q_D(IpTunnelSetting); + + d->tos = tos; +} + +quint32 NetworkManager::IpTunnelSetting::tos() const +{ + Q_D(const IpTunnelSetting); + + return d->tos; +} + +void NetworkManager::IpTunnelSetting::setTtl(quint32 ttl) +{ + Q_D(IpTunnelSetting); + + d->ttl = ttl; +} + +quint32 NetworkManager::IpTunnelSetting::ttl() const +{ + Q_D(const IpTunnelSetting); + + return d->ttl; +} + +void NetworkManager::IpTunnelSetting::setInputKey(const QString &key) +{ + Q_D(IpTunnelSetting); + + d->inputKey = key; +} + +QString NetworkManager::IpTunnelSetting::inputKey() const +{ + Q_D(const IpTunnelSetting); + + return d->inputKey; +} + +void NetworkManager::IpTunnelSetting::setLocal(const QString &local) +{ + Q_D(IpTunnelSetting); + + d->local = local; +} + +QString NetworkManager::IpTunnelSetting::local() const +{ + Q_D(const IpTunnelSetting); + + return d->local; +} + +void NetworkManager::IpTunnelSetting::setParent(const QString &parent) +{ + Q_D(IpTunnelSetting); + + d->parent = parent; +} + +QString NetworkManager::IpTunnelSetting::parent() const +{ + Q_D(const IpTunnelSetting); + + return d->parent; +} + +void NetworkManager::IpTunnelSetting::setOutputKey(const QString &key) +{ + Q_D(IpTunnelSetting); + + d->outputKey = key; +} + +QString NetworkManager::IpTunnelSetting::outputKey() const +{ + Q_D(const IpTunnelSetting); + + return d->outputKey; +} + +void NetworkManager::IpTunnelSetting::setRemote(const QString &remote) +{ + Q_D(IpTunnelSetting); + + d->remote = remote; +} + +QString NetworkManager::IpTunnelSetting::remote() const +{ + Q_D(const IpTunnelSetting); + + return d->remote; +} + +void NetworkManager::IpTunnelSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_MODE))) { + setMode((Mode)setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_MODE)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY))) { + setPathMtuDiscovery(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT))) { + setEncapsulationLimit(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS))) { + setFlags((Flag)setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL))) { + setFlowLabel(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_MTU))) { + setMtu(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_MTU)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_TOS))) { + setTos(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_TOS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_TTL))) { + setTtl(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_TTL)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY))) { + setInputKey(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL))) { + setLocal(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT))) { + setParent(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY))) { + setOutputKey(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE))) { + setRemote(setting.value(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE)).toString()); + } +} + +QVariantMap NetworkManager::IpTunnelSetting::toMap() const +{ + QVariantMap setting; + + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY), pathMtuDiscovery()); + + if (mode() != Unknown) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_MODE), (int)mode()); + } + + if (encapsulationLimit() > 0) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT), encapsulationLimit()); + } + + if (flags() > None) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_FLAGS), (int)flags()); + } + + if (flowLabel() > 0) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_FLOW_LABEL), flowLabel()); + } + + if (mtu() > 0) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_MTU), mtu()); + } + + if (tos() > 0) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_TOS), tos()); + } + + if (ttl() > 0) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_TTL), ttl()); + } + + if (!inputKey().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_INPUT_KEY), inputKey()); + } + + if (!local().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_LOCAL), local()); + } + + if (!parent().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_PARENT), parent()); + } + + if (!outputKey().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_OUTPUT_KEY), outputKey()); + } + + if (!remote().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_IP_TUNNEL_REMOTE), remote()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::IpTunnelSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_IP_TUNNEL_MODE << ": " << setting.mode() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY << ": " << setting.pathMtuDiscovery() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_ENCAPSULATION_LIMIT << ": " << setting.encapsulationLimit() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_FLAGS << ": " << setting.flags() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_FLOW_LABEL << ": " << setting.flowLabel() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_MTU << ": " << setting.mtu() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_TOS << ": " << setting.tos() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_TTL << ": " << setting.ttl() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_INPUT_KEY << ": " << setting.inputKey() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_LOCAL << ": " << setting.local() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_PARENT << ": " << setting.parent() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_OUTPUT_KEY << ": " << setting.outputKey() << '\n'; + dbg.nospace() << NM_SETTING_IP_TUNNEL_REMOTE << ": " << setting.remote() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting.h new file mode 100644 index 000000000..5a4adfb7d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting.h @@ -0,0 +1,110 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPTUNNEL_SETTING_H +#define NETWORKMANAGERQT_IPTUNNEL_SETTING_H + +#include "setting.h" +#include + +namespace NetworkManager +{ +class IpTunnelSettingPrivate; + +/** + * Represents IpTunnel setting + */ +class NETWORKMANAGERQT_EXPORT IpTunnelSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum Mode { + Unknown = NM_IP_TUNNEL_MODE_UNKNOWN, + Ipip = NM_IP_TUNNEL_MODE_IPIP, + Gre = NM_IP_TUNNEL_MODE_GRE, + Sit = NM_IP_TUNNEL_MODE_SIT, + Isatap = NM_IP_TUNNEL_MODE_ISATAP, + Vti = NM_IP_TUNNEL_MODE_VTI, + Ip6ip6 = NM_IP_TUNNEL_MODE_IP6IP6, + Ipip6 = NM_IP_TUNNEL_MODE_IPIP6, + Ip6gre = NM_IP_TUNNEL_MODE_IP6GRE, + Vti6 = NM_IP_TUNNEL_MODE_VTI, + }; + + enum Flag { + None = 0x0, + Ip6IgnEncapLimit = 0x1, + Ip6UseOrigTclass = 0x2, + Ip6UseOrigFlowlabel = 0x4, + Ip6Mip6Dev = 0x8, + Ip6RcvDscpCopy = 0x10, + Ip6UseOrigFwmark = 0x20, + }; + Q_DECLARE_FLAGS(Flags, Flag) + + IpTunnelSetting(); + explicit IpTunnelSetting(const Ptr &other); + ~IpTunnelSetting() override; + + QString name() const override; + + void setMode(Mode mode); + Mode mode() const; + + void setPathMtuDiscovery(bool discovery); + bool pathMtuDiscovery() const; + + void setEncapsulationLimit(quint32 limit); + quint32 encapsulationLimit() const; + + void setFlags(Flags flags); + Flags flags() const; + + void setFlowLabel(quint32 label); + quint32 flowLabel() const; + + void setMtu(quint32 mtu); + quint32 mtu() const; + + void setTos(quint32 tos); + quint32 tos() const; + + void setTtl(quint32 ttl); + quint32 ttl() const; + + void setInputKey(const QString &key); + QString inputKey() const; + + void setLocal(const QString &local); + QString local() const; + + void setParent(const QString &parent); + QString parent() const; + + void setOutputKey(const QString &key); + QString outputKey() const; + + void setRemote(const QString &remote); + QString remote() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + IpTunnelSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(IpTunnelSetting) +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(IpTunnelSetting::Flags) + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const IpTunnelSetting &setting); + +} + +#endif // NETWORKMANAGERQT_IP_TUNNEL_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting_p.h new file mode 100644 index 000000000..0ce28c8e5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/iptunnelsetting_p.h @@ -0,0 +1,38 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IP_TUNNEL_SETTING_P_H +#define NETWORKMANAGERQT_IP_TUNNEL_SETTING_P_H + +#include + +namespace NetworkManager +{ +class IpTunnelSettingPrivate +{ +public: + IpTunnelSettingPrivate(); + + QString name; + + NetworkManager::IpTunnelSetting::Mode mode; + bool pathMtuDiscovery; + quint32 encapsulationLimit; + NetworkManager::IpTunnelSetting::Flags flags; + quint32 flowLabel; + quint32 mtu; + quint32 tos; + quint32 ttl; + QString inputKey; + QString local; + QString outputKey; + QString parent; + QString remote; +}; + +} + +#endif // NETWORKMANAGERQT_IP_TUNNEL_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting.cpp new file mode 100644 index 000000000..caa05f345 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting.cpp @@ -0,0 +1,687 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ipv4setting.h" +#include "ipv4setting_p.h" + +#include "generictypes.h" + +#include + +#include + +NetworkManager::Ipv4SettingPrivate::Ipv4SettingPrivate() + : name(NMQT_SETTING_IP4_CONFIG_SETTING_NAME) + , method(NetworkManager::Ipv4Setting::Automatic) + , routeMetric(-1) + , ignoreAutoRoutes(false) + , ignoreAutoDns(false) + , dhcpSendHostname(true) + , neverDefault(false) + , mayFail(true) + , dadTimeout(-1) + , dnsPriority(0) +{ +} + +NetworkManager::Ipv4Setting::Ipv4Setting() + : Setting(Setting::Ipv4) + , d_ptr(new Ipv4SettingPrivate()) +{ +} + +NetworkManager::Ipv4Setting::Ipv4Setting(const Ptr &other) + : Setting(other) + , d_ptr(new Ipv4SettingPrivate()) +{ + setMethod(other->method()); + setDns(other->dns()); + setDnsSearch(other->dnsSearch()); + setAddresses(other->addresses()); + setRoutes(other->routes()); + setRouteMetric(other->routeMetric()); + setIgnoreAutoRoutes(other->ignoreAutoRoutes()); + setIgnoreAutoDns(other->ignoreAutoDns()); + setDhcpClientId(other->dhcpClientId()); + setDhcpSendHostname(other->dhcpSendHostname()); + setDhcpHostname(other->dhcpHostname()); + setNeverDefault(other->neverDefault()); + setMayFail(other->mayFail()); + setDadTimeout(other->dadTimeout()); + setDhcpFqdn(other->dhcpFqdn()); + setDnsOptions(other->dnsOptions()); + setDnsPriority(other->dnsPriority()); + setAddressData(other->addressData()); + setRouteData(other->routeData()); +} + +NetworkManager::Ipv4Setting::~Ipv4Setting() +{ + delete d_ptr; +} + +QString NetworkManager::Ipv4Setting::name() const +{ + Q_D(const Ipv4Setting); + + return d->name; +} + +void NetworkManager::Ipv4Setting::setMethod(NetworkManager::Ipv4Setting::ConfigMethod type) +{ + Q_D(Ipv4Setting); + + d->method = type; +} + +NetworkManager::Ipv4Setting::ConfigMethod NetworkManager::Ipv4Setting::method() const +{ + Q_D(const Ipv4Setting); + + return d->method; +} + +void NetworkManager::Ipv4Setting::setDns(const QList &dns) +{ + Q_D(Ipv4Setting); + + d->dns = dns; +} + +QList NetworkManager::Ipv4Setting::dns() const +{ + Q_D(const Ipv4Setting); + + return d->dns; +} + +void NetworkManager::Ipv4Setting::setDnsSearch(const QStringList &domains) +{ + Q_D(Ipv4Setting); + + d->dnsSearch = domains; +} + +QStringList NetworkManager::Ipv4Setting::dnsSearch() const +{ + Q_D(const Ipv4Setting); + + return d->dnsSearch; +} + +void NetworkManager::Ipv4Setting::setAddresses(const QList &ipv4addresses) +{ + Q_D(Ipv4Setting); + + d->addresses = ipv4addresses; +} + +QList NetworkManager::Ipv4Setting::addresses() const +{ + Q_D(const Ipv4Setting); + + return d->addresses; +} + +void NetworkManager::Ipv4Setting::setRoutes(const QList &ipv4routes) +{ + Q_D(Ipv4Setting); + + d->routes = ipv4routes; +} + +QList NetworkManager::Ipv4Setting::routes() const +{ + Q_D(const Ipv4Setting); + + return d->routes; +} + +void NetworkManager::Ipv4Setting::setRouteMetric(int metric) +{ + Q_D(Ipv4Setting); + + d->routeMetric = metric; +} + +int NetworkManager::Ipv4Setting::routeMetric() const +{ + Q_D(const Ipv4Setting); + + return d->routeMetric; +} + +void NetworkManager::Ipv4Setting::setIgnoreAutoRoutes(bool ignore) +{ + Q_D(Ipv4Setting); + + d->ignoreAutoRoutes = ignore; +} + +bool NetworkManager::Ipv4Setting::ignoreAutoRoutes() const +{ + Q_D(const Ipv4Setting); + + return d->ignoreAutoRoutes; +} + +void NetworkManager::Ipv4Setting::setIgnoreAutoDns(bool ignore) +{ + Q_D(Ipv4Setting); + + d->ignoreAutoDns = ignore; +} + +bool NetworkManager::Ipv4Setting::ignoreAutoDns() const +{ + Q_D(const Ipv4Setting); + + return d->ignoreAutoDns; +} + +void NetworkManager::Ipv4Setting::setDhcpClientId(const QString &id) +{ + Q_D(Ipv4Setting); + + d->dhcpClientId = id; +} + +QString NetworkManager::Ipv4Setting::dhcpClientId() const +{ + Q_D(const Ipv4Setting); + + return d->dhcpClientId; +} + +void NetworkManager::Ipv4Setting::setDhcpSendHostname(bool send) +{ + Q_D(Ipv4Setting); + + d->dhcpSendHostname = send; +} + +bool NetworkManager::Ipv4Setting::dhcpSendHostname() const +{ + Q_D(const Ipv4Setting); + + return d->dhcpSendHostname; +} + +void NetworkManager::Ipv4Setting::setDhcpHostname(const QString &hostname) +{ + Q_D(Ipv4Setting); + + d->dhcpHostname = hostname; +} + +QString NetworkManager::Ipv4Setting::dhcpHostname() const +{ + Q_D(const Ipv4Setting); + + return d->dhcpHostname; +} + +void NetworkManager::Ipv4Setting::setNeverDefault(bool neverDefault) +{ + Q_D(Ipv4Setting); + + d->neverDefault = neverDefault; +} + +bool NetworkManager::Ipv4Setting::neverDefault() const +{ + Q_D(const Ipv4Setting); + + return d->neverDefault; +} + +void NetworkManager::Ipv4Setting::setMayFail(bool mayFail) +{ + Q_D(Ipv4Setting); + + d->mayFail = mayFail; +} + +bool NetworkManager::Ipv4Setting::mayFail() const +{ + Q_D(const Ipv4Setting); + + return d->mayFail; +} + +void NetworkManager::Ipv4Setting::setDadTimeout(qint32 timeout) +{ + Q_D(Ipv4Setting); + + d->dadTimeout = timeout; +} + +qint32 NetworkManager::Ipv4Setting::dadTimeout() const +{ + Q_D(const Ipv4Setting); + + return d->dadTimeout; +} + +void NetworkManager::Ipv4Setting::setDhcpFqdn(const QString &fqdn) +{ + Q_D(Ipv4Setting); + + d->dhcpFqdn = fqdn; +} + +QString NetworkManager::Ipv4Setting::dhcpFqdn() const +{ + Q_D(const Ipv4Setting); + + return d->dhcpFqdn; +} + +void NetworkManager::Ipv4Setting::setDnsOptions(const QStringList &options) +{ + Q_D(Ipv4Setting); + + d->dnsOptions = options; +} + +QStringList NetworkManager::Ipv4Setting::dnsOptions() const +{ + Q_D(const Ipv4Setting); + + return d->dnsOptions; +} + +void NetworkManager::Ipv4Setting::setDnsPriority(qint32 priority) +{ + Q_D(Ipv4Setting); + + d->dnsPriority = priority; +} + +qint32 NetworkManager::Ipv4Setting::dnsPriority() const +{ + Q_D(const Ipv4Setting); + + return d->dnsPriority; +} + +void NetworkManager::Ipv4Setting::setGateway(const QString &gateway) +{ + Q_D(Ipv4Setting); + + d->gateway = gateway; +} + +QString NetworkManager::Ipv4Setting::gateway() const +{ + Q_D(const Ipv4Setting); + + return d->gateway; +} + +void NetworkManager::Ipv4Setting::setAddressData(const NMVariantMapList &addressData) +{ + Q_D(Ipv4Setting); + + d->addressData = addressData; +} + +NMVariantMapList NetworkManager::Ipv4Setting::addressData() const +{ + Q_D(const Ipv4Setting); + + return d->addressData; +} + +void NetworkManager::Ipv4Setting::setRouteData(const NMVariantMapList &routeData) +{ + Q_D(Ipv4Setting); + + d->routeData = routeData; +} + +NMVariantMapList NetworkManager::Ipv4Setting::routeData() const +{ + Q_D(const Ipv4Setting); + + return d->routeData; +} + +void NetworkManager::Ipv4Setting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD))) { + const QString methodType = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD)).toString(); + + if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_AUTO)) { + setMethod(Automatic); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) { + setMethod(LinkLocal); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_MANUAL)) { + setMethod(Manual); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_SHARED)) { + setMethod(Shared); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_DISABLED)) { + setMethod(Disabled); + } else { + setMethod(Automatic); + } + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS))) { + QList dbusDns; + QList temp; + if (setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).canConvert()) { + QDBusArgument dnsArg = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).value(); + temp = qdbus_cast>(dnsArg); + } else { + temp = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS)).value>(); + } + + for (const uint utmp : std::as_const(temp)) { + QHostAddress tmpHost(ntohl(utmp)); + dbusDns << tmpHost; + } + + setDns(dbusDns); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH))) { + setDnsSearch(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH)).toStringList()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES))) { + QList addresses; + QList> temp; + if (setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).canConvert()) { + QDBusArgument addressArg = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).value(); + temp = qdbus_cast>>(addressArg); + } else { + temp = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES)).value>>(); + } + + for (const QList &uintList : std::as_const(temp)) { + if (uintList.count() != 3) { + continue; + } + + NetworkManager::IpAddress address; + address.setIp(QHostAddress(ntohl(uintList.at(0)))); + address.setPrefixLength(uintList.at(1)); + address.setGateway(QHostAddress(ntohl(uintList.at(2)))); + if (!address.isValid()) { + continue; + } + + addresses << address; + } + + setAddresses(addresses); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES))) { + QList routes; + QList> temp; + if (setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).canConvert()) { + QDBusArgument routeArg = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).value(); + temp = qdbus_cast>>(routeArg); + } else { + temp = setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES)).value>>(); + } + + for (const QList &uintList : std::as_const(temp)) { + if (uintList.count() != 4) { + continue; + } + + NetworkManager::IpRoute route; + route.setIp(QHostAddress(ntohl(uintList.at(0)))); + route.setPrefixLength(uintList.at(1)); + route.setNextHop(QHostAddress(ntohl(uintList.at(2)))); + route.setMetric((quint32)uintList.at(3)); + if (!route.isValid()) { + continue; + } + routes << route; + } + + if (!routes.isEmpty()) { + setRoutes(routes); + } + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC))) { + setRouteMetric(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC)).toInt()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES))) { + setIgnoreAutoRoutes(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS))) { + setIgnoreAutoDns(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID))) { + setDhcpClientId(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID)).toString()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME))) { + setDhcpSendHostname(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME))) { + setDhcpHostname(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME)).toString()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT))) { + setNeverDefault(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL))) { + setMayFail(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT))) { + setDadTimeout(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT)).toUInt()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN))) { + setDhcpFqdn(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN)).toString()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS))) { + setDnsOptions(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS)).toStringList()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY))) { + setDnsPriority(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY)).toInt()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY))) { + setGateway(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY)).toString()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA))) { + setRouteData(qdbus_cast(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA)))); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA))) { + setAddressData(qdbus_cast(setting.value(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA)))); + } +} + +QVariantMap NetworkManager::Ipv4Setting::toMap() const +{ + QVariantMap setting; + + if (method() == Automatic) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_AUTO)); + } else if (method() == LinkLocal) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)); + } else if (method() == Manual) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_MANUAL)); + } else if (method() == Shared) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_SHARED)); + } else if (method() == Disabled) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP4_CONFIG_METHOD_DISABLED)); + } + + if (!dns().isEmpty()) { + QList dbusDns; + const QList dnsList = dns(); + for (const QHostAddress &dns : dnsList) { + dbusDns << htonl(dns.toIPv4Address()); + } + + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS), QVariant::fromValue(dbusDns)); + } + + if (!dnsSearch().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_SEARCH), dnsSearch()); + } + + if (!addresses().isEmpty()) { + QList> dbusAddresses; + const auto addressesList = addresses(); + for (const NetworkManager::IpAddress &addr : addressesList) { + QList dbusAddress; + dbusAddress << htonl(addr.ip().toIPv4Address()) << addr.prefixLength() << htonl(addr.gateway().toIPv4Address()); + dbusAddresses << dbusAddress; + } + + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESSES), QVariant::fromValue(dbusAddresses)); + } + + if (!routes().isEmpty()) { + QList> dbusRoutes; + const auto routesList = routes(); + for (const NetworkManager::IpRoute &route : routesList) { + QList dbusRoute; + dbusRoute << htonl(route.ip().toIPv4Address()) << route.prefixLength() << htonl(route.nextHop().toIPv4Address()) << route.metric(); + dbusRoutes << dbusRoute; + } + + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTES), QVariant::fromValue(dbusRoutes)); + } + + if (routeMetric() >= 0) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC), routeMetric()); + } + + if (ignoreAutoRoutes()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES), ignoreAutoRoutes()); + } + + if (ignoreAutoDns()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS), ignoreAutoDns()); + } + + if (!dhcpClientId().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID), dhcpClientId()); + } + + if (!dhcpSendHostname()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME), dhcpSendHostname()); + } + + if (!dhcpHostname().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME), dhcpHostname()); + } + + if (neverDefault()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT), neverDefault()); + } + + if (!mayFail()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_MAY_FAIL), mayFail()); + } + + if (dadTimeout() >= 0) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT), dadTimeout()); + } + + if (!dhcpFqdn().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DHCP_FQDN), dhcpFqdn()); + } + + if (!dnsOptions().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS), dnsOptions()); + } + + if (dnsPriority() != 0) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY), dnsPriority()); + } + + if (!gateway().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_GATEWAY), gateway()); + } + + if (!addressData().empty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA), QVariant::fromValue(addressData())); + } + + if (!routeData().empty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP4_CONFIG_ROUTE_DATA), QVariant::fromValue(routeData())); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::Ipv4Setting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_METHOD << ": " << setting.method() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DNS << ":\n"; + const QList dnsList = setting.dns(); + for (const QHostAddress &address : dnsList) { + dbg.nospace() << address.toString() << '\n'; + } + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DNS_SEARCH << ": " << setting.dnsSearch() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ADDRESSES << '\n'; + const auto addressesList = setting.addresses(); + for (const NetworkManager::IpAddress &address : addressesList) { + dbg.nospace() << address.ip() << ": " << address.gateway() << ": " << address.netmask() << '\n'; + } + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ROUTES << '\n'; + const auto routesList = setting.routes(); + for (const NetworkManager::IpRoute &route : routesList) { + dbg.nospace() << route.ip() << ": " << route.netmask() << ": " << route.nextHop() << ": " << route.metric() << '\n'; + } + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC << ":" << setting.routeMetric() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES << ": " << setting.ignoreAutoRoutes() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS << ": " << setting.ignoreAutoDns() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID << ": " << setting.dhcpClientId() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME << ": " << setting.dhcpSendHostname() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME << ": " << setting.dhcpHostname() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT << ": " << setting.neverDefault() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_MAY_FAIL << ": " << setting.mayFail() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT << ": " << setting.dadTimeout() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DHCP_FQDN << ": " << setting.dhcpFqdn() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS << ": " << setting.dnsOptions() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY << ": " << setting.dnsPriority() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_GATEWAY << ": " << setting.gateway() << '\n'; + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA << ": " << '\n'; + const NMVariantMapList addDataList = setting.addressData(); + for (const QVariantMap &addressData : addDataList) { + QVariantMap::const_iterator i = addressData.constBegin(); + while (i != addressData.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + dbg.nospace() << NMQT_SETTING_IP4_CONFIG_ROUTE_DATA << ": " << '\n'; + const NMVariantMapList routeDataList = setting.routeData(); + for (const QVariantMap &routeData : routeDataList) { + QVariantMap::const_iterator i = routeData.constBegin(); + while (i != routeData.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting.h b/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting.h new file mode 100644 index 000000000..725be89df --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting.h @@ -0,0 +1,146 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPV4_SETTING_H +#define NETWORKMANAGERQT_IPV4_SETTING_H + +#include "ipconfig.h" +#include "setting.h" +#include + +#include +#include + +#define NMQT_SETTING_IP4_CONFIG_SETTING_NAME NM_SETTING_IP4_CONFIG_SETTING_NAME +#define NMQT_SETTING_IP4_CONFIG_METHOD NM_SETTING_IP_CONFIG_METHOD +#define NMQT_SETTING_IP4_CONFIG_DNS NM_SETTING_IP_CONFIG_DNS +#define NMQT_SETTING_IP4_CONFIG_DNS_SEARCH NM_SETTING_IP_CONFIG_DNS_SEARCH +#define NMQT_SETTING_IP4_CONFIG_ADDRESSES NM_SETTING_IP_CONFIG_ADDRESSES +#define NMQT_SETTING_IP4_CONFIG_GATEWAY NM_SETTING_IP_CONFIG_GATEWAY +#define NMQT_SETTING_IP4_CONFIG_ROUTES NM_SETTING_IP_CONFIG_ROUTES +#define NMQT_SETTING_IP4_CONFIG_ROUTE_METRIC NM_SETTING_IP_CONFIG_ROUTE_METRIC +#define NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES +#define NMQT_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS +#define NMQT_SETTING_IP4_CONFIG_DHCP_HOSTNAME NM_SETTING_IP_CONFIG_DHCP_HOSTNAME +#define NMQT_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME +#define NMQT_SETTING_IP4_CONFIG_NEVER_DEFAULT NM_SETTING_IP_CONFIG_NEVER_DEFAULT +#define NMQT_SETTING_IP4_CONFIG_MAY_FAIL NM_SETTING_IP_CONFIG_MAY_FAIL +#define NMQT_SETTING_IP4_CONFIG_DHCP_CLIENT_ID NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID +#define NMQT_SETTING_IP4_CONFIG_METHOD_AUTO NM_SETTING_IP4_CONFIG_METHOD_AUTO +#define NMQT_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL +#define NMQT_SETTING_IP4_CONFIG_METHOD_MANUAL NM_SETTING_IP4_CONFIG_METHOD_MANUAL +#define NMQT_SETTING_IP4_CONFIG_METHOD_SHARED NM_SETTING_IP4_CONFIG_METHOD_SHARED +#define NMQT_SETTING_IP4_CONFIG_METHOD_DISABLED NM_SETTING_IP4_CONFIG_METHOD_DISABLED +#define NMQT_SETTING_IP4_CONFIG_DAD_TIMEOUT NM_SETTING_IP_CONFIG_DAD_TIMEOUT +#define NMQT_SETTING_IP4_CONFIG_DHCP_FQDN NM_SETTING_IP4_CONFIG_DHCP_FQDN +#define NMQT_SETTING_IP4_CONFIG_DNS_OPTIONS NM_SETTING_IP_CONFIG_DNS_OPTIONS +#define NMQT_SETTING_IP4_CONFIG_DNS_PRIORITY NM_SETTING_IP_CONFIG_DNS_PRIORITY +#define NMQT_SETTING_IP4_CONFIG_GATEWAY NM_SETTING_IP_CONFIG_GATEWAY +#define NMQT_SETTING_IP4_CONFIG_ROUTE_DATA "route-data" +#define NMQT_SETTING_IP4_CONFIG_ADDRESS_DATA "address-data" + +namespace NetworkManager +{ +class Ipv4SettingPrivate; + +/** + * Represents ipv4 setting + */ +class NETWORKMANAGERQT_EXPORT Ipv4Setting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum ConfigMethod { + Automatic, + LinkLocal, + Manual, + Shared, + Disabled, + }; + + Ipv4Setting(); + explicit Ipv4Setting(const Ptr &other); + ~Ipv4Setting() override; + + QString name() const override; + + void setMethod(ConfigMethod method); + ConfigMethod method() const; + + void setDns(const QList &dns); + QList dns() const; + + void setDnsSearch(const QStringList &domains); + QStringList dnsSearch() const; + + void setAddresses(const QList &ipv4addresses); + QList addresses() const; + + void setRoutes(const QList &ipv4routes); + QList routes() const; + + void setRouteMetric(int metric); + int routeMetric() const; + + void setIgnoreAutoRoutes(bool ignore); + bool ignoreAutoRoutes() const; + + void setIgnoreAutoDns(bool ignore); + bool ignoreAutoDns() const; + + void setDhcpClientId(const QString &id); + QString dhcpClientId() const; + + void setDhcpSendHostname(bool send); + bool dhcpSendHostname() const; + + void setDhcpHostname(const QString &hostname); + QString dhcpHostname() const; + + void setNeverDefault(bool neverDefault); + bool neverDefault() const; + + void setMayFail(bool mayFail); + bool mayFail() const; + + void setDadTimeout(qint32 timeout); + qint32 dadTimeout() const; + + void setDhcpFqdn(const QString &fqdn); + QString dhcpFqdn() const; + + void setDnsOptions(const QStringList &options); + QStringList dnsOptions() const; + + void setDnsPriority(qint32 priority); + qint32 dnsPriority() const; + + void setGateway(const QString &gateway); + QString gateway() const; + + void setAddressData(const NMVariantMapList &addressData); + NMVariantMapList addressData() const; + + void setRouteData(const NMVariantMapList &routeData); + NMVariantMapList routeData() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + Ipv4SettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(Ipv4Setting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const Ipv4Setting &setting); + +} + +#endif // NETWORKMANAGERQT_IPV4_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting_p.h new file mode 100644 index 000000000..6966221c6 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ipv4setting_p.h @@ -0,0 +1,47 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPV4_SETTING_P_H +#define NETWORKMANAGERQT_IPV4_SETTING_P_H + +#include "../ipconfig.h" + +#include +#include +#include + +namespace NetworkManager +{ +class Ipv4SettingPrivate +{ +public: + Ipv4SettingPrivate(); + + QString name; + NetworkManager::Ipv4Setting::ConfigMethod method; + QList dns; + QStringList dnsSearch; + QList addresses; + QList routes; + int routeMetric; + bool ignoreAutoRoutes; + bool ignoreAutoDns; + QString dhcpClientId; + bool dhcpSendHostname; + QString dhcpHostname; + bool neverDefault; + bool mayFail; + qint32 dadTimeout; + QString dhcpFqdn; + QStringList dnsOptions; + qint32 dnsPriority; + QString gateway; + NMVariantMapList addressData; + NMVariantMapList routeData; +}; + +} +#endif // NETWORKMANAGERQT_IPV4_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting.cpp new file mode 100644 index 000000000..74cd340da --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting.cpp @@ -0,0 +1,716 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ipv6setting.h" +#include "ipv6setting_p.h" + +#include "../ipconfig.h" +#include "generictypes.h" +#include "utils.h" + +#include + +NetworkManager::Ipv6SettingPrivate::Ipv6SettingPrivate() + : name(NMQT_SETTING_IP6_CONFIG_SETTING_NAME) + , method(NetworkManager::Ipv6Setting::Automatic) + , routeMetric(-1) + , ignoreAutoRoutes(false) + , ignoreAutoDns(false) + , neverDefault(false) + , mayFail(true) + , privacy(NetworkManager::Ipv6Setting::Unknown) + , dadTimeout(-1) + , addressGenMode(NetworkManager::Ipv6Setting::StablePrivacy) + , dhcpTimeout(0) + , routeTable(0) +{ +} + +NetworkManager::Ipv6Setting::Ipv6Setting() + : Setting(Setting::Ipv6) + , d_ptr(new Ipv6SettingPrivate()) +{ +} + +NetworkManager::Ipv6Setting::Ipv6Setting(const Ptr &other) + : Setting(other) + , d_ptr(new Ipv6SettingPrivate()) +{ + setMethod(other->method()); + setDns(other->dns()); + setDnsSearch(other->dnsSearch()); + setAddresses(other->addresses()); + setRoutes(other->routes()); + setRouteMetric(other->routeMetric()); + setIgnoreAutoRoutes(other->ignoreAutoRoutes()); + setIgnoreAutoDns(other->ignoreAutoDns()); + setNeverDefault(other->neverDefault()); + setMayFail(other->mayFail()); + setDadTimeout(other->dadTimeout()); + setAddressGenMode(other->addressGenMode()); + setDhcpTimeout(other->dhcpTimeout()); + setDhcpHostname(other->dhcpHostname()); + setDhcpDuid(other->dhcpDuid()); + setToken(other->token()); + setDnsOptions(other->dnsOptions()); + setAddressData(other->addressData()); + setRouteData(other->routeData()); + setRouteTable(other->routeTable()); +} + +NetworkManager::Ipv6Setting::~Ipv6Setting() +{ + delete d_ptr; +} + +QString NetworkManager::Ipv6Setting::name() const +{ + Q_D(const Ipv6Setting); + + return d->name; +} + +void NetworkManager::Ipv6Setting::setMethod(NetworkManager::Ipv6Setting::ConfigMethod type) +{ + Q_D(Ipv6Setting); + + d->method = type; +} + +NetworkManager::Ipv6Setting::ConfigMethod NetworkManager::Ipv6Setting::method() const +{ + Q_D(const Ipv6Setting); + + return d->method; +} + +void NetworkManager::Ipv6Setting::setDns(const QList &dns) +{ + Q_D(Ipv6Setting); + + d->dns = dns; +} + +QList NetworkManager::Ipv6Setting::dns() const +{ + Q_D(const Ipv6Setting); + + return d->dns; +} + +void NetworkManager::Ipv6Setting::setDnsSearch(const QStringList &domains) +{ + Q_D(Ipv6Setting); + + d->dnsSearch = domains; +} + +QStringList NetworkManager::Ipv6Setting::dnsSearch() const +{ + Q_D(const Ipv6Setting); + + return d->dnsSearch; +} + +void NetworkManager::Ipv6Setting::setAddresses(const QList ipv6addresses) +{ + Q_D(Ipv6Setting); + + d->addresses = ipv6addresses; +} + +QList NetworkManager::Ipv6Setting::addresses() const +{ + Q_D(const Ipv6Setting); + + return d->addresses; +} + +void NetworkManager::Ipv6Setting::setRoutes(const QList ipv6routes) +{ + Q_D(Ipv6Setting); + + d->routes = ipv6routes; +} + +QList NetworkManager::Ipv6Setting::routes() const +{ + Q_D(const Ipv6Setting); + + return d->routes; +} + +void NetworkManager::Ipv6Setting::setRouteMetric(int metric) +{ + Q_D(Ipv6Setting); + + d->routeMetric = metric; +} + +int NetworkManager::Ipv6Setting::routeMetric() const +{ + Q_D(const Ipv6Setting); + + return d->routeMetric; +} + +void NetworkManager::Ipv6Setting::setIgnoreAutoRoutes(bool ignore) +{ + Q_D(Ipv6Setting); + + d->ignoreAutoRoutes = ignore; +} + +bool NetworkManager::Ipv6Setting::ignoreAutoRoutes() const +{ + Q_D(const Ipv6Setting); + + return d->ignoreAutoRoutes; +} + +void NetworkManager::Ipv6Setting::setIgnoreAutoDns(bool ignore) +{ + Q_D(Ipv6Setting); + + d->ignoreAutoDns = ignore; +} + +bool NetworkManager::Ipv6Setting::ignoreAutoDns() const +{ + Q_D(const Ipv6Setting); + + return d->ignoreAutoDns; +} + +void NetworkManager::Ipv6Setting::setNeverDefault(bool neverDefault) +{ + Q_D(Ipv6Setting); + + d->neverDefault = neverDefault; +} + +bool NetworkManager::Ipv6Setting::neverDefault() const +{ + Q_D(const Ipv6Setting); + + return d->neverDefault; +} + +void NetworkManager::Ipv6Setting::setMayFail(bool mayFail) +{ + Q_D(Ipv6Setting); + + d->mayFail = mayFail; +} + +bool NetworkManager::Ipv6Setting::mayFail() const +{ + Q_D(const Ipv6Setting); + + return d->mayFail; +} + +void NetworkManager::Ipv6Setting::setPrivacy(IPv6Privacy privacy) +{ + Q_D(Ipv6Setting); + + d->privacy = privacy; +} + +NetworkManager::Ipv6Setting::IPv6Privacy NetworkManager::Ipv6Setting::privacy() const +{ + Q_D(const Ipv6Setting); + + return d->privacy; +} + +void NetworkManager::Ipv6Setting::setDadTimeout(qint32 timeout) +{ + Q_D(Ipv6Setting); + + d->dadTimeout = timeout; +} + +qint32 NetworkManager::Ipv6Setting::dadTimeout() const +{ + Q_D(const Ipv6Setting); + + return d->dadTimeout; +} + +void NetworkManager::Ipv6Setting::setDhcpTimeout(qint32 timeout) +{ + Q_D(Ipv6Setting); + + d->dhcpTimeout = timeout; +} + +qint32 NetworkManager::Ipv6Setting::dhcpTimeout() const +{ + Q_D(const Ipv6Setting); + + return d->dhcpTimeout; +} + +void NetworkManager::Ipv6Setting::setDhcpHostname(const QString &hostname) +{ + Q_D(Ipv6Setting); + + d->dhcpHostname = hostname; +} + +QString NetworkManager::Ipv6Setting::dhcpHostname() const +{ + Q_D(const Ipv6Setting); + + return d->dhcpHostname; +} + +void NetworkManager::Ipv6Setting::setDhcpDuid(const QString &duid) +{ + Q_D(Ipv6Setting); + + d->dhcpDuid = duid; +} + +QString NetworkManager::Ipv6Setting::dhcpDuid() const +{ + Q_D(const Ipv6Setting); + + return d->dhcpDuid; +} + +void NetworkManager::Ipv6Setting::setDnsOptions(const QStringList &options) +{ + Q_D(Ipv6Setting); + + d->dnsOptions = options; +} + +QStringList NetworkManager::Ipv6Setting::dnsOptions() const +{ + Q_D(const Ipv6Setting); + + return d->dnsOptions; +} + +void NetworkManager::Ipv6Setting::setAddressData(const NMVariantMapList &addressData) +{ + Q_D(Ipv6Setting); + + d->addressData = addressData; +} + +NMVariantMapList NetworkManager::Ipv6Setting::addressData() const +{ + Q_D(const Ipv6Setting); + + return d->addressData; +} + +void NetworkManager::Ipv6Setting::setAddressGenMode(IPv6AddressGenMode mode) +{ + Q_D(Ipv6Setting); + + d->addressGenMode = mode; +} + +NetworkManager::Ipv6Setting::IPv6AddressGenMode NetworkManager::Ipv6Setting::addressGenMode() const +{ + Q_D(const Ipv6Setting); + + return d->addressGenMode; +} + +void NetworkManager::Ipv6Setting::setRouteData(const NMVariantMapList &routeData) +{ + Q_D(Ipv6Setting); + + d->routeData = routeData; +} + +NMVariantMapList NetworkManager::Ipv6Setting::routeData() const +{ + Q_D(const Ipv6Setting); + + return d->routeData; +} + +void NetworkManager::Ipv6Setting::setToken(const QString &token) +{ + Q_D(Ipv6Setting); + + d->token = token; +} + +QString NetworkManager::Ipv6Setting::token() const +{ + Q_D(const Ipv6Setting); + + return d->token; +} + +void NetworkManager::Ipv6Setting::setRouteTable(quint32 routeTable) +{ + Q_D(Ipv6Setting); + + d->routeTable = routeTable; +} + +quint32 NetworkManager::Ipv6Setting::routeTable() const +{ + Q_D(const Ipv6Setting); + + return d->routeTable; +} + +void NetworkManager::Ipv6Setting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD))) { + const QString methodType = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD)).toString(); + + if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_AUTO)) { + setMethod(Automatic); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DHCP)) { + setMethod(Dhcp); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) { + setMethod(LinkLocal); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_MANUAL)) { + setMethod(Manual); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_IGNORE)) { + setMethod(Ignored); + } else if (methodType.toLower() == QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DISABLED)) { + setMethod(ConfigDisabled); + } else { + setMethod(Automatic); + } + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS))) { + QList dbusDns; + QList temp; + if (setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).canConvert()) { + QDBusArgument dnsArg = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).value(); + temp = qdbus_cast>(dnsArg); + } else { + temp = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).value>(); + } + + for (const QByteArray &utmp : std::as_const(temp)) { + dbusDns << ipv6AddressAsHostAddress(utmp); + } + + setDns(dbusDns); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH))) { + setDnsSearch(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH)).toStringList()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES))) { + QList temp; + if (setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS)).canConvert()) { + QDBusArgument addressArg = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES)).value(); + temp = qdbus_cast>(addressArg); + } else { + temp = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES)).value>(); + } + QList addresses; + + for (const IpV6DBusAddress &addressMap : std::as_const(temp)) { + if (addressMap.address.isEmpty() || !addressMap.prefix || addressMap.gateway.isEmpty()) { + continue; + } + + NetworkManager::IpAddress address; + address.setIp(ipv6AddressAsHostAddress(addressMap.address)); + address.setPrefixLength(addressMap.prefix); + address.setGateway(ipv6AddressAsHostAddress(addressMap.gateway)); + if (!address.isValid()) { + continue; + } + + addresses << address; + } + + setAddresses(addresses); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES))) { + QList temp; + if (setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).canConvert()) { + QDBusArgument routeArg = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).value(); + temp = qdbus_cast>(routeArg); + } else { + temp = setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES)).value>(); + } + QList routes; + + for (const IpV6DBusRoute &routeMap : std::as_const(temp)) { + if (routeMap.destination.isEmpty() || !routeMap.prefix || routeMap.nexthop.isEmpty() || !routeMap.metric) { + continue; + } + + NetworkManager::IpRoute route; + route.setIp(ipv6AddressAsHostAddress(routeMap.destination)); + route.setPrefixLength(routeMap.prefix); + route.setNextHop(ipv6AddressAsHostAddress(routeMap.nexthop)); + route.setMetric(routeMap.metric); + if (!route.isValid()) { + continue; + } + + routes << route; + } + setRoutes(routes); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC))) { + setRouteMetric(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC)).toInt()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES))) { + setIgnoreAutoRoutes(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS))) { + setIgnoreAutoDns(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT))) { + setNeverDefault(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL))) { + setMayFail(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL)).toBool()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY))) { + setPrivacy((IPv6Privacy)setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY)).toUInt()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT))) { + setDadTimeout(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT)).toUInt()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT))) { + setDhcpTimeout(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT)).toUInt()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE))) { + setAddressGenMode(static_cast(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE)).toUInt())); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME))) { + setDhcpHostname(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME)).toString()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID))) { + setDhcpDuid(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID)).toString()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN))) { + setToken(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN)).toString()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS))) { + setDnsOptions(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS)).toStringList()); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA))) { + setRouteData(qdbus_cast(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA)))); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA))) { + setAddressData(qdbus_cast(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA)))); + } + + if (setting.contains(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE))) { + setRouteTable(setting.value(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE)).toUInt()); + } +} + +QVariantMap NetworkManager::Ipv6Setting::toMap() const +{ + QVariantMap setting; + + if (method() == Automatic) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_AUTO)); + } else if (method() == Dhcp) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DHCP)); + } else if (method() == LinkLocal) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)); + } else if (method() == Manual) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_MANUAL)); + } else if (method() == Ignored) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_IGNORE)); + } else if (method() == ConfigDisabled) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD), QLatin1String(NMQT_SETTING_IP6_CONFIG_METHOD_DISABLED)); + } + + if (!dns().isEmpty()) { + QList dbusDns; + const QList dnsList = dns(); + for (const QHostAddress &dns : dnsList) { + dbusDns << ipv6AddressFromHostAddress(dns); + } + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS), QVariant::fromValue(dbusDns)); + } + + if (!dnsSearch().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_SEARCH), dnsSearch()); + } + + if (!addresses().isEmpty()) { + QList dbusAddresses; + const QList addressesList = addresses(); + for (const NetworkManager::IpAddress &addr : addressesList) { + IpV6DBusAddress dbusAddress; + dbusAddress.address = ipv6AddressFromHostAddress(addr.ip()); + dbusAddress.prefix = addr.prefixLength(); + dbusAddress.gateway = ipv6AddressFromHostAddress(addr.gateway()); + dbusAddresses << dbusAddress; + } + + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESSES), QVariant::fromValue(dbusAddresses)); + } + + if (!routes().isEmpty()) { + QList dbusRoutes; + const QList routesList = routes(); + for (const NetworkManager::IpRoute &route : routesList) { + IpV6DBusRoute dbusRoute; + dbusRoute.destination = ipv6AddressFromHostAddress(route.ip()); + dbusRoute.prefix = route.prefixLength(); + dbusRoute.nexthop = ipv6AddressFromHostAddress(route.nextHop()); + dbusRoute.metric = route.metric(); + dbusRoutes << dbusRoute; + } + + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTES), QVariant::fromValue(dbusRoutes)); + } + + if (routeMetric() >= 0) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC), routeMetric()); + } + + if (ignoreAutoRoutes()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES), ignoreAutoRoutes()); + } + + if (ignoreAutoDns()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS), ignoreAutoDns()); + } + + if (neverDefault()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT), neverDefault()); + } + + if (!mayFail()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_MAY_FAIL), mayFail()); + } + + if (privacy() != Unknown) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY), privacy()); + } + + if (dadTimeout() >= 0) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT), dadTimeout()); + } + + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE), addressGenMode()); + + if (dhcpTimeout() > 0) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT), dhcpTimeout()); + } + + if (!dhcpHostname().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME), dhcpHostname()); + } + + if (!dhcpDuid().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DHCP_DUID), dhcpDuid()); + } + + if (!token().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_TOKEN), token()); + } + + if (!dnsOptions().isEmpty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS), dnsOptions()); + } + + if (!addressData().empty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA), QVariant::fromValue(addressData())); + } + + if (!routeData().empty()) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_DATA), QVariant::fromValue(routeData())); + } + + if (routeTable() > 0) { + setting.insert(QLatin1String(NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE), routeTable()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::Ipv6Setting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_METHOD << ": " << setting.method() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DNS << '\n'; + const QList hostAdresses = setting.dns(); + for (const QHostAddress &address : hostAdresses) { + dbg.nospace() << address.toString() << '\n'; + } + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DNS_SEARCH << ": " << setting.dnsSearch() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ADDRESSES << '\n'; + const QList ipList = setting.addresses(); + for (const NetworkManager::IpAddress &address : ipList) { + dbg.nospace() << address.ip().toString() << ": " << address.gateway().toString() << ": " << address.netmask() << '\n'; + } + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ROUTES << '\n'; + const QList routesList = setting.routes(); + for (const NetworkManager::IpRoute &route : routesList) { + dbg.nospace() << route.ip().toString() << ": " << route.metric() << ": " << route.nextHop().toString() << ": " << route.metric() << '\n'; + } + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC << ":" << setting.routeMetric() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES << ": " << setting.ignoreAutoRoutes() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS << ": " << setting.ignoreAutoDns() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT << ": " << setting.neverDefault() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_MAY_FAIL << ": " << setting.mayFail() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY << ": " << setting.privacy() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT << ": " << setting.dadTimeout() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE << ": " << setting.addressGenMode() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT << ": " << setting.dhcpTimeout() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME << ": " << setting.dhcpHostname() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DHCP_DUID << ": " << setting.dhcpDuid() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_TOKEN << ": " << setting.token() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS << ": " << setting.dnsOptions() << '\n'; + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA << ": " << '\n'; + const auto dataList = setting.addressData(); + for (const QVariantMap &addressData : dataList) { + QVariantMap::const_iterator i = addressData.constBegin(); + while (i != addressData.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ROUTE_DATA << ": " << '\n'; + const auto routeDataList = setting.routeData(); + for (const QVariantMap &routeData : routeDataList) { + QVariantMap::const_iterator i = routeData.constBegin(); + while (i != routeData.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + dbg.nospace() << NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE << ": " << setting.routeTable() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting.h b/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting.h new file mode 100644 index 000000000..04311ec5a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting.h @@ -0,0 +1,178 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPV6_SETTING_H +#define NETWORKMANAGERQT_IPV6_SETTING_H + +#include "ipconfig.h" +#include "setting.h" +#include + +#include +#include + +#define NMQT_SETTING_IP6_CONFIG_SETTING_NAME NM_SETTING_IP6_CONFIG_SETTING_NAME +#define NMQT_SETTING_IP6_CONFIG_METHOD NM_SETTING_IP_CONFIG_METHOD +#define NMQT_SETTING_IP6_CONFIG_DNS NM_SETTING_IP_CONFIG_DNS +#define NMQT_SETTING_IP6_CONFIG_DNS_SEARCH NM_SETTING_IP_CONFIG_DNS_SEARCH +#define NMQT_SETTING_IP6_CONFIG_ADDRESSES NM_SETTING_IP_CONFIG_ADDRESSES +#define NMQT_SETTING_IP6_CONFIG_GATEWAY NM_SETTING_IP_CONFIG_GATEWAY +#define NMQT_SETTING_IP6_CONFIG_ROUTES NM_SETTING_IP_CONFIG_ROUTES +#define NMQT_SETTING_IP6_CONFIG_ROUTE_METRIC NM_SETTING_IP_CONFIG_ROUTE_METRIC +#define NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES +#define NMQT_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS +#define NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME NM_SETTING_IP_CONFIG_DHCP_HOSTNAME +#define NMQT_SETTING_IP6_CONFIG_DHCP_SEND_HOSTNAME NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME +#define NMQT_SETTING_IP6_CONFIG_NEVER_DEFAULT NM_SETTING_IP_CONFIG_NEVER_DEFAULT +#define NMQT_SETTING_IP6_CONFIG_MAY_FAIL NM_SETTING_IP_CONFIG_MAY_FAIL +#define NMQT_SETTING_IP6_CONFIG_DHCP_CLIENT_ID NM_SETTING_IP6_CONFIG_DHCP_CLIENT_ID +#define NMQT_SETTING_IP6_CONFIG_IP6_PRIVACY NM_SETTING_IP6_CONFIG_IP6_PRIVACY +#define NMQT_SETTING_IP6_CONFIG_METHOD_IGNORE NM_SETTING_IP6_CONFIG_METHOD_IGNORE +#define NMQT_SETTING_IP6_CONFIG_METHOD_AUTO NM_SETTING_IP6_CONFIG_METHOD_AUTO +#define NMQT_SETTING_IP6_CONFIG_METHOD_DHCP NM_SETTING_IP6_CONFIG_METHOD_DHCP +#define NMQT_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL +#define NMQT_SETTING_IP6_CONFIG_METHOD_MANUAL NM_SETTING_IP6_CONFIG_METHOD_MANUAL +#define NMQT_SETTING_IP6_CONFIG_METHOD_SHARED NM_SETTING_IP6_CONFIG_METHOD_SHARED +#if NM_CHECK_VERSION(1, 20, 0) +#define NMQT_SETTING_IP6_CONFIG_METHOD_DISABLED NM_SETTING_IP6_CONFIG_METHOD_DISABLED +#else +#define NMQT_SETTING_IP6_CONFIG_METHOD_DISABLED "disabled" +#endif +#define NMQT_SETTING_IP6_CONFIG_DAD_TIMEOUT NM_SETTING_IP_CONFIG_DAD_TIMEOUT +#define NMQT_SETTING_IP6_CONFIG_DHCP_TIMEOUT NM_SETTING_IP_CONFIG_DHCP_TIMEOUT +#define NMQT_SETTING_IP6_CONFIG_DHCP_HOSTNAME NM_SETTING_IP_CONFIG_DHCP_HOSTNAME +#define NMQT_SETTING_IP6_CONFIG_ADDRESS_GEN_MODE NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE +#if NM_CHECK_VERSION(1, 12, 0) +#define NMQT_SETTING_IP6_CONFIG_DHCP_DUID NM_SETTING_IP6_CONFIG_DHCP_DUID +#else +#define NMQT_SETTING_IP6_CONFIG_DHCP_DUID "dhcp-duid" +#endif +#define NMQT_SETTING_IP6_CONFIG_TOKEN NM_SETTING_IP6_CONFIG_TOKEN +#define NMQT_SETTING_IP6_CONFIG_DNS_OPTIONS NM_SETTING_IP_CONFIG_DNS_OPTIONS +#define NMQT_SETTING_IP6_CONFIG_ROUTE_DATA "route-data" +#define NMQT_SETTING_IP6_CONFIG_ADDRESS_DATA "address-data" +#if NM_CHECK_VERSION(1, 10, 0) +#define NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE NM_SETTING_IP_CONFIG_ROUTE_TABLE +#else +#define NMQT_SETTING_IP6_CONFIG_ROUTE_TABLE "route-table" +#endif + +namespace NetworkManager +{ +class Ipv6SettingPrivate; + +/** + * Represents ipv6 setting + */ +class NETWORKMANAGERQT_EXPORT Ipv6Setting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum ConfigMethod { + Automatic, + Dhcp, + LinkLocal, + Manual, + Ignored, + ConfigDisabled // FIXME KF6: fix enum naming (possibly move to enum class) + }; + enum IPv6Privacy { + Unknown = -1, + Disabled, + PreferPublic, + PreferTemporary, + }; + enum IPv6AddressGenMode { + Eui64, + StablePrivacy, + }; + + Ipv6Setting(); + explicit Ipv6Setting(const Ptr &other); + ~Ipv6Setting() override; + + QString name() const override; + + void setMethod(ConfigMethod method); + ConfigMethod method() const; + + void setDns(const QList &dns); + QList dns() const; + + void setDnsSearch(const QStringList &domains); + QStringList dnsSearch() const; + + void setAddresses(const QList ipv6addresses); + QList addresses() const; + + void setRoutes(const QList ipv6routes); + QList routes() const; + + void setRouteMetric(int metric); + int routeMetric() const; + + void setIgnoreAutoRoutes(bool ignore); + bool ignoreAutoRoutes() const; + + void setIgnoreAutoDns(bool ignore); + bool ignoreAutoDns() const; + + void setNeverDefault(bool neverDefault); + bool neverDefault() const; + + void setMayFail(bool mayFail); + bool mayFail() const; + + void setPrivacy(IPv6Privacy privacy); + IPv6Privacy privacy() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + + void setDadTimeout(qint32 timeout); + qint32 dadTimeout() const; + + void setAddressGenMode(IPv6AddressGenMode mode); + IPv6AddressGenMode addressGenMode() const; + + void setDhcpTimeout(qint32 timeout); + qint32 dhcpTimeout() const; + + void setDhcpHostname(const QString &hostname); + QString dhcpHostname() const; + + void setDhcpDuid(const QString &duid); + QString dhcpDuid() const; + + void setToken(const QString &token); + QString token() const; + + void setDnsOptions(const QStringList &options); + QStringList dnsOptions() const; + + void setAddressData(const NMVariantMapList &addressData); + NMVariantMapList addressData() const; + + void setRouteData(const NMVariantMapList &routeData); + NMVariantMapList routeData() const; + + void setRouteTable(quint32 routeTable); + quint32 routeTable() const; + +protected: + Ipv6SettingPrivate *const d_ptr; + +private: + Q_DECLARE_PRIVATE(Ipv6Setting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const Ipv6Setting &setting); + +} + +#endif // NETWORKMANAGERQT_IPV6_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting_p.h new file mode 100644 index 000000000..2d27d3b58 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ipv6setting_p.h @@ -0,0 +1,47 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_IPV6_SETTING_P_H +#define NETWORKMANAGERQT_IPV6_SETTING_P_H + +#include "../ipconfig.h" + +#include +#include + +namespace NetworkManager +{ +class Ipv6SettingPrivate +{ +public: + Ipv6SettingPrivate(); + + QString name; + NetworkManager::Ipv6Setting::ConfigMethod method; + QList dns; + QStringList dnsSearch; + QList addresses; + QList routes; + int routeMetric; + bool ignoreAutoRoutes; + bool ignoreAutoDns; + bool neverDefault; + bool mayFail; + NetworkManager::Ipv6Setting::IPv6Privacy privacy; + qint32 dadTimeout; + NetworkManager::Ipv6Setting::IPv6AddressGenMode addressGenMode; + qint32 dhcpTimeout; + QString dhcpHostname; + QString dhcpDuid; + QString token; + QStringList dnsOptions; + NMVariantMapList addressData; + NMVariantMapList routeData; + qint32 routeTable; +}; + +} +#endif // NETWORKMANAGERQT_IPV6_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting.cpp new file mode 100644 index 000000000..a7887e206 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting.cpp @@ -0,0 +1,323 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "macsecsetting.h" +#include "macsecsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 6, 0) +#define NM_SETTING_MACSEC_SETTING_NAME "macsec" + +#define NM_SETTING_MACSEC_PARENT "parent" +#define NM_SETTING_MACSEC_MODE "mode" +#define NM_SETTING_MACSEC_ENCRYPT "encrypt" +#define NM_SETTING_MACSEC_MKA_CAK "mka-cak" +#define NM_SETTING_MACSEC_MKA_CAK_FLAGS "mka-cak-flags" +#define NM_SETTING_MACSEC_MKA_CKN "mka-ckn" +#define NM_SETTING_MACSEC_PORT "port" +#define NM_SETTING_MACSEC_VALIDATION "validation" +#endif + +#if !NM_CHECK_VERSION(1, 12, 0) +#define NM_SETTING_MACSEC_SEND_SCI "send-sci" +#endif + +NetworkManager::MacsecSettingPrivate::MacsecSettingPrivate() + : name(NM_SETTING_MACSEC_SETTING_NAME) + , encrypt(true) + , mode(NetworkManager::MacsecSetting::Psk) + , port(1) + , sendSci(true) + , validation(NetworkManager::MacsecSetting::Strict) +{ +} + +NetworkManager::MacsecSetting::MacsecSetting() + : Setting(Setting::Macsec) + , d_ptr(new MacsecSettingPrivate()) +{ +} + +NetworkManager::MacsecSetting::MacsecSetting(const Ptr &other) + : Setting(other) + , d_ptr(new MacsecSettingPrivate()) +{ + setEncrypt(other->encrypt()); + setMkaCak(other->mkaCak()); + setMkaCkn(other->mkaCkn()); + setMode(other->mode()); + setParent(other->parent()); + setPort(other->port()); + setSendSci(other->sendSci()); + setValidation(other->validation()); + setMkaCakFlags(other->mkaCakFlags()); +} + +NetworkManager::MacsecSetting::~MacsecSetting() +{ + delete d_ptr; +} + +QString NetworkManager::MacsecSetting::name() const +{ + Q_D(const MacsecSetting); + + return d->name; +} + +void NetworkManager::MacsecSetting::setEncrypt(bool encrypt) +{ + Q_D(MacsecSetting); + + d->encrypt = encrypt; +} + +bool NetworkManager::MacsecSetting::encrypt() const +{ + Q_D(const MacsecSetting); + + return d->encrypt; +} + +void NetworkManager::MacsecSetting::setMkaCak(const QString &mkaCak) +{ + Q_D(MacsecSetting); + + d->mkaCak = mkaCak; +} + +QString NetworkManager::MacsecSetting::mkaCak() const +{ + Q_D(const MacsecSetting); + + return d->mkaCak; +} + +void NetworkManager::MacsecSetting::setMkaCkn(const QString &mkaCkn) +{ + Q_D(MacsecSetting); + + d->mkaCkn = mkaCkn; +} + +QString NetworkManager::MacsecSetting::mkaCkn() const +{ + Q_D(const MacsecSetting); + + return d->mkaCkn; +} + +void NetworkManager::MacsecSetting::setMode(Mode mode) +{ + Q_D(MacsecSetting); + + d->mode = mode; +} + +NetworkManager::MacsecSetting::Mode NetworkManager::MacsecSetting::mode() const +{ + Q_D(const MacsecSetting); + + return d->mode; +} + +void NetworkManager::MacsecSetting::setParent(const QString &parent) +{ + Q_D(MacsecSetting); + + d->parent = parent; +} + +QString NetworkManager::MacsecSetting::parent() const +{ + Q_D(const MacsecSetting); + + return d->parent; +} + +void NetworkManager::MacsecSetting::setPort(qint32 port) +{ + Q_D(MacsecSetting); + + d->port = port; +} + +qint32 NetworkManager::MacsecSetting::port() const +{ + Q_D(const MacsecSetting); + + return d->port; +} + +void NetworkManager::MacsecSetting::setSendSci(bool sendSci) +{ + Q_D(MacsecSetting); + + d->sendSci = sendSci; +} + +bool NetworkManager::MacsecSetting::sendSci() const +{ + Q_D(const MacsecSetting); + + return d->sendSci; +} + +void NetworkManager::MacsecSetting::setValidation(Validation validation) +{ + Q_D(MacsecSetting); + + d->validation = validation; +} + +NetworkManager::MacsecSetting::Validation NetworkManager::MacsecSetting::validation() const +{ + Q_D(const MacsecSetting); + + return d->validation; +} + +void NetworkManager::MacsecSetting::setMkaCakFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(MacsecSetting); + + d->mkaCakFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::MacsecSetting::mkaCakFlags() const +{ + Q_D(const MacsecSetting); + + return d->mkaCakFlags; +} + +QStringList NetworkManager::MacsecSetting::needSecrets(bool requestNew) const +{ + QStringList secrets; + + if ((mkaCak().isEmpty() || requestNew) && !mkaCakFlags().testFlag(Setting::NotRequired)) { + secrets << QLatin1String(NM_SETTING_MACSEC_MKA_CAK); + } + + return secrets; +} + +void NetworkManager::MacsecSetting::secretsFromMap(const QVariantMap &secrets) +{ + if (secrets.contains(QLatin1String(NM_SETTING_MACSEC_MKA_CAK))) { + setMkaCak(secrets.value(QLatin1String(NM_SETTING_MACSEC_MKA_CAK)).toString()); + } +} + +QVariantMap NetworkManager::MacsecSetting::secretsToMap() const +{ + QVariantMap secrets; + + if (!mkaCak().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_MACSEC_MKA_CAK), mkaCak()); + } + + return secrets; +} + +void NetworkManager::MacsecSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_ENCRYPT))) { + setEncrypt(setting.value(QLatin1String(NM_SETTING_MACSEC_ENCRYPT)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_MKA_CAK))) { + setMkaCak(setting.value(QLatin1String(NM_SETTING_MACSEC_MKA_CAK)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_MKA_CKN))) { + setMkaCkn(setting.value(QLatin1String(NM_SETTING_MACSEC_MKA_CKN)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_MODE))) { + setMode((Mode)setting.value(QLatin1String(NM_SETTING_MACSEC_MODE)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_PARENT))) { + setParent(setting.value(QLatin1String(NM_SETTING_MACSEC_PARENT)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_PORT))) { + setPort(setting.value(QLatin1String(NM_SETTING_MACSEC_PORT)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_SEND_SCI))) { + setSendSci(setting.value(QLatin1String(NM_SETTING_MACSEC_SEND_SCI)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_VALIDATION))) { + setValidation((Validation)setting.value(QLatin1String(NM_SETTING_MACSEC_VALIDATION)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_MACSEC_MKA_CAK_FLAGS))) { + setMkaCakFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_MACSEC_MKA_CAK_FLAGS)).toUInt()); + } +} + +QVariantMap NetworkManager::MacsecSetting::toMap() const +{ + QVariantMap setting; + + if (!encrypt()) { + setting.insert(QLatin1String(NM_SETTING_MACSEC_ENCRYPT), encrypt()); + } + + if (!mkaCak().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_MACSEC_MKA_CAK), mkaCak()); + } + + if (!mkaCkn().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_MACSEC_MKA_CKN), mkaCkn()); + } + + if (mode() > NetworkManager::MacsecSetting::Psk) { + setting.insert(QLatin1String(NM_SETTING_MACSEC_MODE), (int)mode()); + } + + if (!parent().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_MACSEC_PARENT), parent()); + } + + if (port() > 1) { + setting.insert(QLatin1String(NM_SETTING_MACSEC_PORT), port()); + } + + if (!sendSci()) { + setting.insert(QLatin1String(NM_SETTING_MACSEC_SEND_SCI), sendSci()); + } + + if (validation() != NetworkManager::MacsecSetting::Strict) { + setting.insert(QLatin1String(NM_SETTING_MACSEC_VALIDATION), (int)validation()); + } + + setting.insert(QLatin1String(NM_SETTING_MACSEC_MKA_CAK_FLAGS), (int)mkaCakFlags()); + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::MacsecSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_MACSEC_ENCRYPT << ": " << setting.encrypt() << '\n'; + dbg.nospace() << NM_SETTING_MACSEC_MKA_CAK << ": " << setting.mkaCak() << '\n'; + dbg.nospace() << NM_SETTING_MACSEC_MKA_CKN << ": " << setting.mkaCkn() << '\n'; + dbg.nospace() << NM_SETTING_MACSEC_MODE << ": " << setting.mode() << '\n'; + dbg.nospace() << NM_SETTING_MACSEC_PARENT << ": " << setting.parent() << '\n'; + dbg.nospace() << NM_SETTING_MACSEC_PORT << ": " << setting.port() << '\n'; + dbg.nospace() << NM_SETTING_MACSEC_SEND_SCI << ": " << setting.sendSci() << '\n'; + dbg.nospace() << NM_SETTING_MACSEC_VALIDATION << ": " << setting.validation() << '\n'; + dbg.nospace() << NM_SETTING_MACSEC_MKA_CAK_FLAGS << ": " << setting.mkaCakFlags() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting.h new file mode 100644 index 000000000..1115d02e0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting.h @@ -0,0 +1,91 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_MACSECSETTING_H +#define NETWORKMANAGERQT_MACSECSETTING_H + +#include "setting.h" +#include + +namespace NetworkManager +{ +class MacsecSettingPrivate; + +/** + * Represents Macsec setting + */ +class NETWORKMANAGERQT_EXPORT MacsecSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + enum Mode { + Psk, + Eap, + }; + + enum Validation { + Disable, + Check, + Strict, + }; + + MacsecSetting(); + explicit MacsecSetting(const Ptr &other); + ~MacsecSetting() override; + + QString name() const override; + + void setEncrypt(bool encrypt); + bool encrypt() const; + + void setMkaCak(const QString &mkaCak); + QString mkaCak() const; + + void setMkaCkn(const QString &mkaCkn); + QString mkaCkn() const; + + void setMode(Mode mode); + Mode mode() const; + + void setParent(const QString &parent); + QString parent() const; + + void setPort(qint32 port); + qint32 port() const; + + void setSendSci(bool sendSci); + bool sendSci() const; + + void setValidation(Validation validation); + Validation validation() const; + + void setMkaCakFlags(Setting::SecretFlags flags); + Setting::SecretFlags mkaCakFlags() const; + + QStringList needSecrets(bool requestNew = false) const override; + + void secretsFromMap(const QVariantMap &secrets) override; + + QVariantMap secretsToMap() const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + MacsecSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(MacsecSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const MacsecSetting &setting); + +} + +#endif // NETWORKMANAGERQT_MACSECSETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting_p.h new file mode 100644 index 000000000..99d382690 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/macsecsetting_p.h @@ -0,0 +1,34 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_MACSECSETTING_P_H +#define NETWORKMANAGERQT_MACSECSETTING_P_H + +#include + +namespace NetworkManager +{ +class MacsecSettingPrivate +{ +public: + MacsecSettingPrivate(); + + QString name; + + bool encrypt; + QString mkaCak; + QString mkaCkn; + NetworkManager::MacsecSetting::Mode mode; + QString parent; + qint32 port; + bool sendSci; + NetworkManager::MacsecSetting::Validation validation; + NetworkManager::Setting::SecretFlags mkaCakFlags; +}; + +} + +#endif // NETWORKMANAGERQT_MACSECSETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/matchsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/matchsetting.cpp new file mode 100644 index 000000000..632de999f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/matchsetting.cpp @@ -0,0 +1,87 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "matchsetting.h" +#include "matchsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 14, 0) +#define NM_SETTING_MATCH_SETTING_NAME "match" +#define NM_SETTING_MATCH_INTERFACE_NAME "interface-name" +#endif + +NetworkManager::MatchSettingPrivate::MatchSettingPrivate() + : name(NM_SETTING_MATCH_SETTING_NAME) +{ +} + +NetworkManager::MatchSetting::MatchSetting() + : Setting(Setting::Match) + , d_ptr(new MatchSettingPrivate()) +{ +} + +NetworkManager::MatchSetting::MatchSetting(const Ptr &other) + : Setting(other) + , d_ptr(new MatchSettingPrivate()) +{ + setInterfaceName(other->interfaceName()); +} + +NetworkManager::MatchSetting::~MatchSetting() +{ + delete d_ptr; +} + +QString NetworkManager::MatchSetting::name() const +{ + Q_D(const MatchSetting); + + return d->name; +} + +void NetworkManager::MatchSetting::setInterfaceName(const QStringList &name) +{ + Q_D(MatchSetting); + + d->interfaceName = name; +} + +QStringList NetworkManager::MatchSetting::interfaceName() const +{ + Q_D(const MatchSetting); + + return d->interfaceName; +} + +void NetworkManager::MatchSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME))) { + setInterfaceName(setting.value(QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME)).toStringList()); + } +} + +QVariantMap NetworkManager::MatchSetting::toMap() const +{ + QVariantMap setting; + + if (!interfaceName().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME), interfaceName()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::MatchSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_MATCH_INTERFACE_NAME << ": " << setting.interfaceName() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/matchsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/matchsetting.h new file mode 100644 index 000000000..7d07ed33b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/matchsetting.h @@ -0,0 +1,50 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_MATCH_SETTING_H +#define NETWORKMANAGERQT_MATCH_SETTING_H + +#include "setting.h" +#include + +namespace NetworkManager +{ +class MatchSettingPrivate; + +/** + * Represents Match setting + */ +class NETWORKMANAGERQT_EXPORT MatchSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + MatchSetting(); + explicit MatchSetting(const Ptr &other); + ~MatchSetting() override; + + QString name() const override; + + void setInterfaceName(const QStringList &name); + QStringList interfaceName() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + MatchSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(MatchSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const MatchSetting &setting); + +} + +#endif // NETWORKMANAGERQT_MATCH_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/matchsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/matchsetting_p.h new file mode 100644 index 000000000..5d133470a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/matchsetting_p.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_MATCH_SETTING_P_H +#define NETWORKMANAGERQT_MATCH_SETTING_P_H + +#include + +namespace NetworkManager +{ +class MatchSettingPrivate +{ +public: + MatchSettingPrivate(); + + QString name; + + QStringList interfaceName; +}; + +} + +#endif // NETWORKMANAGERQT_MATCH_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting.cpp new file mode 100644 index 000000000..5adf8c8a1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting.cpp @@ -0,0 +1,131 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "olpcmeshsetting.h" +#include "olpcmeshsetting_p.h" + +#include + +NetworkManager::OlpcMeshSettingPrivate::OlpcMeshSettingPrivate() + : name(NM_SETTING_OLPC_MESH_SETTING_NAME) + , channel(0) +{ +} + +NetworkManager::OlpcMeshSetting::OlpcMeshSetting() + : Setting(Setting::Bond) + , d_ptr(new OlpcMeshSettingPrivate()) +{ +} + +NetworkManager::OlpcMeshSetting::OlpcMeshSetting(const Ptr &other) + : Setting(other) + , d_ptr(new OlpcMeshSettingPrivate()) +{ + setSsid(other->ssid()); + setChannel(other->channel()); + setDhcpAnycastAddress(other->dhcpAnycastAddress()); +} + +NetworkManager::OlpcMeshSetting::~OlpcMeshSetting() +{ + delete d_ptr; +} + +QString NetworkManager::OlpcMeshSetting::name() const +{ + Q_D(const OlpcMeshSetting); + + return d->name; +} + +void NetworkManager::OlpcMeshSetting::setSsid(const QByteArray &ssid) +{ + Q_D(OlpcMeshSetting); + + d->ssid = ssid; +} + +QByteArray NetworkManager::OlpcMeshSetting::ssid() const +{ + Q_D(const OlpcMeshSetting); + + return d->ssid; +} + +void NetworkManager::OlpcMeshSetting::setChannel(quint32 channel) +{ + Q_D(OlpcMeshSetting); + + d->channel = channel; +} + +quint32 NetworkManager::OlpcMeshSetting::channel() const +{ + Q_D(const OlpcMeshSetting); + + return d->channel; +} + +void NetworkManager::OlpcMeshSetting::setDhcpAnycastAddress(const QByteArray &address) +{ + Q_D(OlpcMeshSetting); + + d->dhcpAnycastAddress = address; +} + +QByteArray NetworkManager::OlpcMeshSetting::dhcpAnycastAddress() const +{ + Q_D(const OlpcMeshSetting); + + return d->dhcpAnycastAddress; +} + +void NetworkManager::OlpcMeshSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_OLPC_MESH_SSID))) { + setSsid(setting.value(QLatin1String(NM_SETTING_OLPC_MESH_SSID)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OLPC_MESH_CHANNEL))) { + setChannel(setting.value(QLatin1String(NM_SETTING_OLPC_MESH_CHANNEL)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS))) { + setDhcpAnycastAddress(setting.value(QLatin1String(NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS)).toByteArray()); + } +} + +QVariantMap NetworkManager::OlpcMeshSetting::toMap() const +{ + QVariantMap setting; + + if (!ssid().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_OLPC_MESH_SSID), ssid()); + } + + if (channel()) { + setting.insert(QLatin1String(NM_SETTING_OLPC_MESH_CHANNEL), channel()); + } + + if (!dhcpAnycastAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS), dhcpAnycastAddress()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OlpcMeshSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_OLPC_MESH_SSID << ": " << setting.ssid() << '\n'; + dbg.nospace() << NM_SETTING_OLPC_MESH_CHANNEL << ": " << setting.channel() << '\n'; + dbg.nospace() << NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS << ": " << setting.dhcpAnycastAddress() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting.h new file mode 100644 index 000000000..d85521168 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting.h @@ -0,0 +1,57 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OLPCMESH_SETTING_H +#define NETWORKMANAGERQT_OLPCMESH_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class OlpcMeshSettingPrivate; + +/** + * Represents olpc mesh setting + */ +class NETWORKMANAGERQT_EXPORT OlpcMeshSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + OlpcMeshSetting(); + explicit OlpcMeshSetting(const Ptr &other); + ~OlpcMeshSetting() override; + + QString name() const override; + + void setSsid(const QByteArray &ssid); + QByteArray ssid() const; + + void setChannel(quint32 channel); + quint32 channel() const; + + void setDhcpAnycastAddress(const QByteArray &address); + QByteArray dhcpAnycastAddress() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + OlpcMeshSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(OlpcMeshSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const OlpcMeshSetting &setting); + +} + +#endif // NETWORKMANAGERQT_OLPCMESH_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting_p.h new file mode 100644 index 000000000..02261a66b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/olpcmeshsetting_p.h @@ -0,0 +1,27 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OLPCMESH_SETTING_P_H +#define NETWORKMANAGERQT_OLPCMESH_SETTING_P_H + +#include + +namespace NetworkManager +{ +class OlpcMeshSettingPrivate +{ +public: + OlpcMeshSettingPrivate(); + + QString name; + QByteArray ssid; + quint32 channel; + QByteArray dhcpAnycastAddress; +}; + +} + +#endif // NETWORKMANAGERQT_OLPCMESH_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting.cpp new file mode 100644 index 000000000..6962eb857 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting.cpp @@ -0,0 +1,157 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ovsbridgesetting.h" +#include "ovsbridgesetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_OVS_BRIDGE_SETTING_NAME "ovs-bridge" +#define NM_SETTING_OVS_BRIDGE_FAIL_MODE "fail-mode" +#define NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE "mcast-snooping-enable" +#define NM_SETTING_OVS_BRIDGE_RSTP_ENABLE "rstp-enable" +#define NM_SETTING_OVS_BRIDGE_STP_ENABLE "stp-enable" +#endif + +NetworkManager::OvsBridgeSettingPrivate::OvsBridgeSettingPrivate() + : name(NM_SETTING_OVS_BRIDGE_SETTING_NAME) + , mcastSnoopingEnable(false) + , rstpEnable(false) + , stpEnable(false) +{ +} + +NetworkManager::OvsBridgeSetting::OvsBridgeSetting() + : Setting(Setting::OvsBridge) + , d_ptr(new OvsBridgeSettingPrivate()) +{ +} + +NetworkManager::OvsBridgeSetting::OvsBridgeSetting(const Ptr &other) + : Setting(other) + , d_ptr(new OvsBridgeSettingPrivate()) +{ + setFailMode(other->failMode()); + setMcastSnoopingEnable(other->mcastSnoopingEnable()); + setRstpEnable(other->rstpEnable()); + setStpEnable(other->stpEnable()); +} + +NetworkManager::OvsBridgeSetting::~OvsBridgeSetting() +{ + delete d_ptr; +} + +QString NetworkManager::OvsBridgeSetting::name() const +{ + Q_D(const OvsBridgeSetting); + + return d->name; +} + +void NetworkManager::OvsBridgeSetting::setMcastSnoopingEnable(bool mcastSnoopingEnable) +{ + Q_D(OvsBridgeSetting); + + d->mcastSnoopingEnable = mcastSnoopingEnable; +} + +bool NetworkManager::OvsBridgeSetting::mcastSnoopingEnable() const +{ + Q_D(const OvsBridgeSetting); + + return d->mcastSnoopingEnable; +} + +void NetworkManager::OvsBridgeSetting::setRstpEnable(bool rstpEnable) +{ + Q_D(OvsBridgeSetting); + + d->rstpEnable = rstpEnable; +} + +bool NetworkManager::OvsBridgeSetting::rstpEnable() const +{ + Q_D(const OvsBridgeSetting); + + return d->rstpEnable; +} + +void NetworkManager::OvsBridgeSetting::setStpEnable(bool stpEnable) +{ + Q_D(OvsBridgeSetting); + + d->stpEnable = stpEnable; +} + +bool NetworkManager::OvsBridgeSetting::stpEnable() const +{ + Q_D(const OvsBridgeSetting); + + return d->stpEnable; +} + +void NetworkManager::OvsBridgeSetting::setFailMode(const QString &mode) +{ + Q_D(OvsBridgeSetting); + + d->failMode = mode; +} + +QString NetworkManager::OvsBridgeSetting::failMode() const +{ + Q_D(const OvsBridgeSetting); + + return d->failMode; +} + +void NetworkManager::OvsBridgeSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE))) { + setMcastSnoopingEnable(setting.value(QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE))) { + setRstpEnable(setting.value(QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE))) { + setStpEnable(setting.value(QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE))) { + setFailMode(setting.value(QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE)).toString()); + } +} + +QVariantMap NetworkManager::OvsBridgeSetting::toMap() const +{ + QVariantMap setting; + + setting.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE), mcastSnoopingEnable()); + setting.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE), rstpEnable()); + setting.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE), stpEnable()); + + if (!failMode().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE), failMode()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OvsBridgeSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE << ": " << setting.mcastSnoopingEnable() << '\n'; + dbg.nospace() << NM_SETTING_OVS_BRIDGE_RSTP_ENABLE << ": " << setting.rstpEnable() << '\n'; + dbg.nospace() << NM_SETTING_OVS_BRIDGE_STP_ENABLE << ": " << setting.stpEnable() << '\n'; + dbg.nospace() << NM_SETTING_OVS_BRIDGE_FAIL_MODE << ": " << setting.failMode() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting.h b/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting.h new file mode 100644 index 000000000..15cf47d72 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting.h @@ -0,0 +1,61 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OVS_BRIDGE_SETTING_H +#define NETWORKMANAGERQT_OVS_BRIDGE_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class OvsBridgeSettingPrivate; + +/** + * Represents ovs-bridge setting + */ +class NETWORKMANAGERQT_EXPORT OvsBridgeSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + OvsBridgeSetting(); + explicit OvsBridgeSetting(const Ptr &other); + ~OvsBridgeSetting() override; + + QString name() const override; + + void setMcastSnoopingEnable(bool mcastSnoopingEnable); + bool mcastSnoopingEnable() const; + + void setRstpEnable(bool rstpEnable); + bool rstpEnable() const; + + void setStpEnable(bool stpEnable); + bool stpEnable() const; + + void setFailMode(const QString &mode); + QString failMode() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + OvsBridgeSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(OvsBridgeSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const OvsBridgeSetting &setting); + +} + +#endif // NETWORKMANAGERQT_OVS_BRIDGE_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting_p.h new file mode 100644 index 000000000..0b8f4a5be --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsbridgesetting_p.h @@ -0,0 +1,29 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OVS_BRIDGE_SETTING_P_H +#define NETWORKMANAGERQT_OVS_BRIDGE_SETTING_P_H + +#include + +namespace NetworkManager +{ +class OvsBridgeSettingPrivate +{ +public: + OvsBridgeSettingPrivate(); + + QString name; + + bool mcastSnoopingEnable; + bool rstpEnable; + bool stpEnable; + QString failMode; +}; + +} + +#endif // NETWORKMANAGERQT_OVS_BRIDGE_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting.cpp new file mode 100644 index 000000000..752718c8b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting.cpp @@ -0,0 +1,87 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ovsinterfacesetting.h" +#include "ovsinterfacesetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_OVS_INTERFACE_SETTING_NAME "ovs-interface" +#define NM_SETTING_OVS_INTERFACE_TYPE "type" +#endif + +NetworkManager::OvsInterfaceSettingPrivate::OvsInterfaceSettingPrivate() + : name(NM_SETTING_OVS_INTERFACE_SETTING_NAME) +{ +} + +NetworkManager::OvsInterfaceSetting::OvsInterfaceSetting() + : Setting(Setting::OvsInterface) + , d_ptr(new OvsInterfaceSettingPrivate()) +{ +} + +NetworkManager::OvsInterfaceSetting::OvsInterfaceSetting(const Ptr &other) + : Setting(other) + , d_ptr(new OvsInterfaceSettingPrivate()) +{ + setInterfaceType(other->interfaceType()); +} + +NetworkManager::OvsInterfaceSetting::~OvsInterfaceSetting() +{ + delete d_ptr; +} + +QString NetworkManager::OvsInterfaceSetting::name() const +{ + Q_D(const OvsInterfaceSetting); + + return d->name; +} + +void NetworkManager::OvsInterfaceSetting::setInterfaceType(const QString &type) +{ + Q_D(OvsInterfaceSetting); + + d->type = type; +} + +QString NetworkManager::OvsInterfaceSetting::interfaceType() const +{ + Q_D(const OvsInterfaceSetting); + + return d->type; +} + +void NetworkManager::OvsInterfaceSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_OVS_INTERFACE_TYPE))) { + setInterfaceType(setting.value(QLatin1String(NM_SETTING_OVS_INTERFACE_TYPE)).toString()); + } +} + +QVariantMap NetworkManager::OvsInterfaceSetting::toMap() const +{ + QVariantMap setting; + + if (!interfaceType().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_OVS_INTERFACE_TYPE), interfaceType()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OvsInterfaceSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_OVS_INTERFACE_TYPE << ": " << setting.type() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting.h b/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting.h new file mode 100644 index 000000000..c07db8c67 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting.h @@ -0,0 +1,52 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OVS_INTERFACE_SETTING_H +#define NETWORKMANAGERQT_OVS_INTERFACE_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class OvsInterfaceSettingPrivate; + +/** + * Represents ovs-interface setting + */ +class NETWORKMANAGERQT_EXPORT OvsInterfaceSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + OvsInterfaceSetting(); + explicit OvsInterfaceSetting(const Ptr &other); + ~OvsInterfaceSetting() override; + + QString name() const override; + + void setInterfaceType(const QString &type); + QString interfaceType() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + OvsInterfaceSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(OvsInterfaceSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const OvsInterfaceSetting &setting); + +} + +#endif // NETWORKMANAGERQT_OVS_INTERFACE_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting_p.h new file mode 100644 index 000000000..b90fab6f4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsinterfacesetting_p.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OVS_INTERFACE_SETTING_P_H +#define NETWORKMANAGERQT_OVS_INTERFACE_SETTING_P_H + +#include + +namespace NetworkManager +{ +class OvsInterfaceSettingPrivate +{ +public: + OvsInterfaceSettingPrivate(); + + QString name; + + QString type; +}; + +} + +#endif // NETWORKMANAGERQT_OVS_INTERFACE_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting.cpp new file mode 100644 index 000000000..b09508a22 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting.cpp @@ -0,0 +1,87 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ovspatchsetting.h" +#include "ovspatchsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_OVS_PATCH_SETTING_NAME "ovs-patch" +#define NM_SETTING_OVS_PATCH_PEER "peer" +#endif + +NetworkManager::OvsPatchSettingPrivate::OvsPatchSettingPrivate() + : name(NM_SETTING_OVS_PATCH_SETTING_NAME) +{ +} + +NetworkManager::OvsPatchSetting::OvsPatchSetting() + : Setting(Setting::OvsPatch) + , d_ptr(new OvsPatchSettingPrivate()) +{ +} + +NetworkManager::OvsPatchSetting::OvsPatchSetting(const Ptr &other) + : Setting(other) + , d_ptr(new OvsPatchSettingPrivate()) +{ + setPeer(other->peer()); +} + +NetworkManager::OvsPatchSetting::~OvsPatchSetting() +{ + delete d_ptr; +} + +QString NetworkManager::OvsPatchSetting::name() const +{ + Q_D(const OvsPatchSetting); + + return d->name; +} + +void NetworkManager::OvsPatchSetting::setPeer(const QString &peer) +{ + Q_D(OvsPatchSetting); + + d->peer = peer; +} + +QString NetworkManager::OvsPatchSetting::peer() const +{ + Q_D(const OvsPatchSetting); + + return d->peer; +} + +void NetworkManager::OvsPatchSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_OVS_PATCH_PEER))) { + setPeer(setting.value(QLatin1String(NM_SETTING_OVS_PATCH_PEER)).toString()); + } +} + +QVariantMap NetworkManager::OvsPatchSetting::toMap() const +{ + QVariantMap setting; + + if (!peer().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_OVS_PATCH_PEER), peer()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OvsPatchSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_OVS_PATCH_PEER << ": " << setting.peer() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting.h new file mode 100644 index 000000000..3f1b655e5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting.h @@ -0,0 +1,52 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OVS_PATCH_SETTING_H +#define NETWORKMANAGERQT_OVS_PATCH_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class OvsPatchSettingPrivate; + +/** + * Represents OvsPatch setting + */ +class NETWORKMANAGERQT_EXPORT OvsPatchSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + OvsPatchSetting(); + explicit OvsPatchSetting(const Ptr &other); + ~OvsPatchSetting() override; + + QString name() const override; + + void setPeer(const QString &peer); + QString peer() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + OvsPatchSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(OvsPatchSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const OvsPatchSetting &setting); + +} + +#endif // NETWORKMANAGERQT_OVS_PATCH_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting_p.h new file mode 100644 index 000000000..f7948905e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovspatchsetting_p.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OVS_PATCH_SETTING_P_H +#define NETWORKMANAGERQT_OVS_PATCH_SETTING_P_H + +#include + +namespace NetworkManager +{ +class OvsPatchSettingPrivate +{ +public: + OvsPatchSettingPrivate(); + + QString name; + + QString peer; +}; + +} + +#endif // NETWORKMANAGERQT_OVS_PATCH_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting.cpp new file mode 100644 index 000000000..17ea01d57 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting.cpp @@ -0,0 +1,215 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "ovsportsetting.h" +#include "ovsportsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_OVS_PORT_SETTING_NAME "ovs-port" +#define NM_SETTING_OVS_PORT_VLAN_MODE "vlan-mode" +#define NM_SETTING_OVS_PORT_TAG "tag" +#define NM_SETTING_OVS_PORT_LACP "lacp" +#define NM_SETTING_OVS_PORT_BOND_MODE "bond-mode" +#define NM_SETTING_OVS_PORT_BOND_UPDELAY "bond-updelay" +#define NM_SETTING_OVS_PORT_BOND_DOWNDELAY "bond-downdelay" +#endif + +NetworkManager::OvsPortSettingPrivate::OvsPortSettingPrivate() + : name(NM_SETTING_OVS_PORT_SETTING_NAME) + , bondDowndelay(0) + , bondUpdelay(0) + , tag(0) +{ +} + +NetworkManager::OvsPortSetting::OvsPortSetting() + : Setting(Setting::OvsPort) + , d_ptr(new OvsPortSettingPrivate()) +{ +} + +NetworkManager::OvsPortSetting::OvsPortSetting(const Ptr &other) + : Setting(other) + , d_ptr(new OvsPortSettingPrivate()) +{ + setBondDowndelay(other->bondDowndelay()); + setBondUpdelay(other->bondUpdelay()); + setTag(other->tag()); + setBondMode(other->bondMode()); + setLacp(other->lacp()); + setVlanMode(other->vlanMode()); +} + +NetworkManager::OvsPortSetting::~OvsPortSetting() +{ + delete d_ptr; +} + +QString NetworkManager::OvsPortSetting::name() const +{ + Q_D(const OvsPortSetting); + + return d->name; +} + +void NetworkManager::OvsPortSetting::setBondDowndelay(quint32 delay) +{ + Q_D(OvsPortSetting); + + d->bondDowndelay = delay; +} + +quint32 NetworkManager::OvsPortSetting::bondDowndelay() const +{ + Q_D(const OvsPortSetting); + + return d->bondDowndelay; +} + +void NetworkManager::OvsPortSetting::setBondUpdelay(quint32 delay) +{ + Q_D(OvsPortSetting); + + d->bondUpdelay = delay; +} + +quint32 NetworkManager::OvsPortSetting::bondUpdelay() const +{ + Q_D(const OvsPortSetting); + + return d->bondUpdelay; +} + +void NetworkManager::OvsPortSetting::setTag(quint32 tag) +{ + Q_D(OvsPortSetting); + + d->tag = tag; +} + +quint32 NetworkManager::OvsPortSetting::tag() const +{ + Q_D(const OvsPortSetting); + + return d->tag; +} + +void NetworkManager::OvsPortSetting::setBondMode(const QString &mode) +{ + Q_D(OvsPortSetting); + + d->bondMode = mode; +} + +QString NetworkManager::OvsPortSetting::bondMode() const +{ + Q_D(const OvsPortSetting); + + return d->bondMode; +} + +void NetworkManager::OvsPortSetting::setLacp(const QString &lacp) +{ + Q_D(OvsPortSetting); + + d->lacp = lacp; +} + +QString NetworkManager::OvsPortSetting::lacp() const +{ + Q_D(const OvsPortSetting); + + return d->lacp; +} + +void NetworkManager::OvsPortSetting::setVlanMode(const QString &mode) +{ + Q_D(OvsPortSetting); + + d->vlanMode = mode; +} + +QString NetworkManager::OvsPortSetting::vlanMode() const +{ + Q_D(const OvsPortSetting); + + return d->vlanMode; +} + +void NetworkManager::OvsPortSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY))) { + setBondUpdelay(setting.value(QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY))) { + setBondDowndelay(setting.value(QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_TAG))) { + setTag(setting.value(QLatin1String(NM_SETTING_OVS_PORT_TAG)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE))) { + setBondMode(setting.value(QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_LACP))) { + setLacp(setting.value(QLatin1String(NM_SETTING_OVS_PORT_LACP)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE))) { + setVlanMode(setting.value(QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE)).toString()); + } +} + +QVariantMap NetworkManager::OvsPortSetting::toMap() const +{ + QVariantMap setting; + + if (bondUpdelay() > 0) { + setting.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY), bondUpdelay()); + } + + if (bondDowndelay() > 0) { + setting.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY), bondDowndelay()); + } + + if (tag() > 0) { + setting.insert(QLatin1String(NM_SETTING_OVS_PORT_TAG), tag()); + } + + if (!bondMode().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE), bondMode()); + } + + if (!lacp().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_OVS_PORT_LACP), lacp()); + } + + if (!vlanMode().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE), vlanMode()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OvsPortSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_OVS_PORT_BOND_UPDELAY << ": " << setting.bondUpdelay() << '\n'; + dbg.nospace() << NM_SETTING_OVS_PORT_BOND_DOWNDELAY << ": " << setting.bondDowndelay() << '\n'; + dbg.nospace() << NM_SETTING_OVS_PORT_TAG << ": " << setting.tag() << '\n'; + dbg.nospace() << NM_SETTING_OVS_PORT_BOND_MODE << ": " << setting.bondMode() << '\n'; + dbg.nospace() << NM_SETTING_OVS_PORT_LACP << ": " << setting.lacp() << '\n'; + dbg.nospace() << NM_SETTING_OVS_PORT_VLAN_MODE << ": " << setting.vlanMode() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting.h new file mode 100644 index 000000000..9474d1b37 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting.h @@ -0,0 +1,65 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQTOVS_PORT_SETTING_H +#define NETWORKMANAGERQTOVS_PORT_SETTING_H + +#include "setting.h" +#include + +namespace NetworkManager +{ +class OvsPortSettingPrivate; + +/** + * Represents OvsPort setting + */ +class NETWORKMANAGERQT_EXPORT OvsPortSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + OvsPortSetting(); + explicit OvsPortSetting(const Ptr &other); + ~OvsPortSetting() override; + + QString name() const override; + + void setBondDowndelay(quint32 delay); + quint32 bondDowndelay() const; + + void setBondUpdelay(quint32 delay); + quint32 bondUpdelay() const; + + void setTag(quint32 tag); + quint32 tag() const; + + void setBondMode(const QString &mode); + QString bondMode() const; + + void setLacp(const QString &lacp); + QString lacp() const; + + void setVlanMode(const QString &mode); + QString vlanMode() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + OvsPortSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(OvsPortSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const OvsPortSetting &setting); + +} + +#endif // NETWORKMANAGERQT_OVS_PORT_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting_p.h new file mode 100644 index 000000000..8e565a54d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/ovsportsetting_p.h @@ -0,0 +1,31 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_OVS_PORT_SETTING_P_H +#define NETWORKMANAGERQT_OVS_PORT_SETTING_P_H + +#include + +namespace NetworkManager +{ +class OvsPortSettingPrivate +{ +public: + OvsPortSettingPrivate(); + + QString name; + + quint32 bondDowndelay; + quint32 bondUpdelay; + quint32 tag; + QString bondMode; + QString lacp; + QString vlanMode; +}; + +} + +#endif // NETWORKMANAGERQT_OVS_PORT_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting.cpp new file mode 100644 index 000000000..a47bd73f4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting.cpp @@ -0,0 +1,203 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "pppoesetting.h" +#include "pppoesetting_p.h" + +#include + +NetworkManager::PppoeSettingPrivate::PppoeSettingPrivate() + : name(NM_SETTING_PPPOE_SETTING_NAME) + , passwordFlags(Setting::None) +{ +} + +NetworkManager::PppoeSetting::PppoeSetting() + : Setting(Setting::Pppoe) + , d_ptr(new PppoeSettingPrivate()) +{ +} + +NetworkManager::PppoeSetting::PppoeSetting(const Ptr &other) + : Setting(other) + , d_ptr(new PppoeSettingPrivate()) +{ + setService(other->service()); + setUsername(other->username()); + setPassword(other->password()); + setPasswordFlags(other->passwordFlags()); +} + +NetworkManager::PppoeSetting::~PppoeSetting() +{ + delete d_ptr; +} + +QString NetworkManager::PppoeSetting::name() const +{ + Q_D(const PppoeSetting); + + return d->name; +} + +void NetworkManager::PppoeSetting::setService(const QString &service) +{ + Q_D(PppoeSetting); + + d->service = service; +} + +QString NetworkManager::PppoeSetting::service() const +{ + Q_D(const PppoeSetting); + + return d->service; +} + +void NetworkManager::PppoeSetting::setParent(const QString &parent) +{ + Q_D(PppoeSetting); + + d->parent = parent; +} + +QString NetworkManager::PppoeSetting::parent() const +{ + Q_D(const PppoeSetting); + + return d->parent; +} + +void NetworkManager::PppoeSetting::setUsername(const QString &username) +{ + Q_D(PppoeSetting); + + d->username = username; +} + +QString NetworkManager::PppoeSetting::username() const +{ + Q_D(const PppoeSetting); + + return d->username; +} + +void NetworkManager::PppoeSetting::setPassword(const QString &password) +{ + Q_D(PppoeSetting); + + d->password = password; +} + +QString NetworkManager::PppoeSetting::password() const +{ + Q_D(const PppoeSetting); + + return d->password; +} + +void NetworkManager::PppoeSetting::setPasswordFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(PppoeSetting); + + d->passwordFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::PppoeSetting::passwordFlags() const +{ + Q_D(const PppoeSetting); + + return d->passwordFlags; +} + +QStringList NetworkManager::PppoeSetting::needSecrets(bool requestNew) const +{ + QStringList secrets; + + if ((password().isEmpty() || requestNew) && !passwordFlags().testFlag(Setting::NotRequired)) { + secrets << QLatin1String(NM_SETTING_PPPOE_PASSWORD); + } + + return secrets; +} + +void NetworkManager::PppoeSetting::secretsFromMap(const QVariantMap &secrets) +{ + if (secrets.contains(QLatin1String(NM_SETTING_PPPOE_PASSWORD))) { + setPassword(secrets.value(QLatin1String(NM_SETTING_PPPOE_PASSWORD)).toString()); + } +} + +QVariantMap NetworkManager::PppoeSetting::secretsToMap() const +{ + QVariantMap secrets; + + if (!password().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_PPPOE_PASSWORD), password()); + } + + return secrets; +} + +void NetworkManager::PppoeSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_PPPOE_SERVICE))) { + setService(setting.value(QLatin1String(NM_SETTING_PPPOE_SERVICE)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPPOE_USERNAME))) { + setUsername(setting.value(QLatin1String(NM_SETTING_PPPOE_USERNAME)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPPOE_PASSWORD))) { + setPassword(setting.value(QLatin1String(NM_SETTING_PPPOE_PASSWORD)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPPOE_PASSWORD_FLAGS))) { + setPasswordFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_PPPOE_PASSWORD_FLAGS)).toUInt()); + } +} + +QVariantMap NetworkManager::PppoeSetting::toMap() const +{ + QVariantMap setting; + + if (!service().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_PPPOE_SERVICE), service()); + } + + if (!parent().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_PPPOE_PARENT), parent()); + } + + if (!username().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_PPPOE_USERNAME), username()); + } + + if (!password().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_PPPOE_PASSWORD), password()); + } + + if (passwordFlags()) { + setting.insert(QLatin1String(NM_SETTING_PPPOE_PASSWORD_FLAGS), (int)passwordFlags()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::PppoeSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_PPPOE_SERVICE << ": " << setting.service() << '\n'; + dbg.nospace() << NM_SETTING_PPPOE_PARENT << ": " << setting.parent() << '\n'; + dbg.nospace() << NM_SETTING_PPPOE_USERNAME << ": " << setting.username() << '\n'; + dbg.nospace() << NM_SETTING_PPPOE_PASSWORD << ": " << setting.password() << '\n'; + dbg.nospace() << NM_SETTING_PPPOE_PASSWORD_FLAGS << ": " << setting.passwordFlags() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting.h b/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting.h new file mode 100644 index 000000000..cca222e89 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting.h @@ -0,0 +1,69 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_PPPOE_SETTING_H +#define NETWORKMANAGERQT_PPPOE_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class PppoeSettingPrivate; + +/** + * Represents pppoe setting + */ +class NETWORKMANAGERQT_EXPORT PppoeSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + PppoeSetting(); + explicit PppoeSetting(const Ptr &other); + ~PppoeSetting() override; + + QString name() const override; + + void setService(const QString &service); + QString service() const; + + void setParent(const QString &parent); + QString parent() const; + + void setUsername(const QString &username); + QString username() const; + + void setPassword(const QString &password); + QString password() const; + + void setPasswordFlags(Setting::SecretFlags flags); + Setting::SecretFlags passwordFlags() const; + + QStringList needSecrets(bool requestNew = false) const override; + + void secretsFromMap(const QVariantMap &secrets) override; + + QVariantMap secretsToMap() const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + PppoeSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(PppoeSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const PppoeSetting &setting); + +} + +#endif // NETWORKMANAGERQT_PPPOE_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting_p.h new file mode 100644 index 000000000..390007d8f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/pppoesetting_p.h @@ -0,0 +1,29 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_PPPOE_SETTING_P_H +#define NETWORKMANAGERQT_PPPOE_SETTING_P_H + +#include + +namespace NetworkManager +{ +class PppoeSettingPrivate +{ +public: + PppoeSettingPrivate(); + + QString name; + QString service; + QString username; + QString password; + QString parent; + NetworkManager::Setting::SecretFlags passwordFlags; +}; + +} + +#endif // NETWORKMANAGERQT_PPPOE_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/pppsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/pppsetting.cpp new file mode 100644 index 000000000..1def838f7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/pppsetting.cpp @@ -0,0 +1,508 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "pppsetting.h" +#include "pppsetting_p.h" + +#include + +NetworkManager::PppSettingPrivate::PppSettingPrivate() + : name(NM_SETTING_PPP_SETTING_NAME) + , noauth(true) + , refuseEap(false) + , refusePap(false) + , refuseChap(false) + , refuseMschap(false) + , refuseMschapv2(false) + , nobsdcomp(false) + , nodeflate(false) + , noVjComp(false) + , requireMppe(false) + , requireMppe128(false) + , mppeStateful(false) + , crtscts(false) + , baud(0) + , mru(0) + , mtu(0) + , lcpEchoFailure(0) + , lcpEchoInterval(0) +{ +} + +NetworkManager::PppSetting::PppSetting() + : Setting(Setting::Ppp) + , d_ptr(new PppSettingPrivate()) +{ +} + +NetworkManager::PppSetting::PppSetting(const Ptr &other) + : Setting(other) + , d_ptr(new PppSettingPrivate()) +{ + setNoAuth(other->noAuth()); + setRefuseEap(other->refuseEap()); + setRefusePap(other->refusePap()); + setRefuseChap(other->refuseChap()); + setRefuseMschap(other->refuseMschap()); + setRefuseMschapv2(other->refuseMschapv2()); + setNoBsdComp(other->noBsdComp()); + setNoDeflate(other->noDeflate()); + setNoVjComp(other->noVjComp()); + setRequireMppe(other->requireMppe()); + setRequireMppe128(other->requireMppe128()); + setMppeStateful(other->mppeStateful()); + setCRtsCts(other->cRtsCts()); + setBaud(other->baud()); + setMru(other->mru()); + setMtu(other->mtu()); + setLcpEchoFailure(other->lcpEchoFailure()); + setLcpEchoInterval(other->lcpEchoInterval()); +} + +NetworkManager::PppSetting::~PppSetting() +{ + delete d_ptr; +} + +QString NetworkManager::PppSetting::name() const +{ + Q_D(const PppSetting); + + return d->name; +} + +void NetworkManager::PppSetting::setNoAuth(bool require) +{ + Q_D(PppSetting); + + d->noauth = require; +} + +bool NetworkManager::PppSetting::noAuth() const +{ + Q_D(const PppSetting); + + return d->noauth; +} + +void NetworkManager::PppSetting::setRefuseEap(bool refuse) +{ + Q_D(PppSetting); + + d->refuseEap = refuse; +} + +bool NetworkManager::PppSetting::refuseEap() const +{ + Q_D(const PppSetting); + + return d->refuseEap; +} + +void NetworkManager::PppSetting::setRefusePap(bool refuse) +{ + Q_D(PppSetting); + + d->refusePap = refuse; +} + +bool NetworkManager::PppSetting::refusePap() const +{ + Q_D(const PppSetting); + + return d->refusePap; +} + +void NetworkManager::PppSetting::setRefuseChap(bool refuse) +{ + Q_D(PppSetting); + + d->refuseChap = refuse; +} + +bool NetworkManager::PppSetting::refuseChap() const +{ + Q_D(const PppSetting); + + return d->refuseChap; +} + +void NetworkManager::PppSetting::setRefuseMschap(bool refuse) +{ + Q_D(PppSetting); + + d->refuseMschap = refuse; +} + +bool NetworkManager::PppSetting::refuseMschap() const +{ + Q_D(const PppSetting); + + return d->refuseMschap; +} + +void NetworkManager::PppSetting::setRefuseMschapv2(bool refuse) +{ + Q_D(PppSetting); + + d->refuseMschapv2 = refuse; +} + +bool NetworkManager::PppSetting::refuseMschapv2() const +{ + Q_D(const PppSetting); + + return d->refuseMschapv2; +} + +void NetworkManager::PppSetting::setNoBsdComp(bool require) +{ + Q_D(PppSetting); + + d->nobsdcomp = require; +} + +bool NetworkManager::PppSetting::noBsdComp() const +{ + Q_D(const PppSetting); + + return d->nobsdcomp; +} + +void NetworkManager::PppSetting::setNoDeflate(bool require) +{ + Q_D(PppSetting); + + d->nodeflate = require; +} + +bool NetworkManager::PppSetting::noDeflate() const +{ + Q_D(const PppSetting); + + return d->nodeflate; +} + +void NetworkManager::PppSetting::setNoVjComp(bool require) +{ + Q_D(PppSetting); + + d->noVjComp = require; +} + +bool NetworkManager::PppSetting::noVjComp() const +{ + Q_D(const PppSetting); + + return d->noVjComp; +} + +void NetworkManager::PppSetting::setRequireMppe(bool require) +{ + Q_D(PppSetting); + + d->requireMppe = require; +} + +bool NetworkManager::PppSetting::requireMppe() const +{ + Q_D(const PppSetting); + + return d->requireMppe; +} + +void NetworkManager::PppSetting::setRequireMppe128(bool require) +{ + Q_D(PppSetting); + + d->requireMppe128 = require; +} + +bool NetworkManager::PppSetting::requireMppe128() const +{ + Q_D(const PppSetting); + + return d->requireMppe128; +} + +void NetworkManager::PppSetting::setMppeStateful(bool used) +{ + Q_D(PppSetting); + + d->mppeStateful = used; +} + +bool NetworkManager::PppSetting::mppeStateful() const +{ + Q_D(const PppSetting); + + return d->mppeStateful; +} + +void NetworkManager::PppSetting::setCRtsCts(bool control) +{ + Q_D(PppSetting); + + d->crtscts = control; +} + +bool NetworkManager::PppSetting::cRtsCts() const +{ + Q_D(const PppSetting); + + return d->crtscts; +} + +void NetworkManager::PppSetting::setBaud(quint32 baud) +{ + Q_D(PppSetting); + + d->baud = baud; +} + +quint32 NetworkManager::PppSetting::baud() const +{ + Q_D(const PppSetting); + + return d->baud; +} + +void NetworkManager::PppSetting::setMru(quint32 mru) +{ + Q_D(PppSetting); + + d->mru = mru; +} + +quint32 NetworkManager::PppSetting::mru() const +{ + Q_D(const PppSetting); + + return d->mru; +} + +void NetworkManager::PppSetting::setMtu(quint32 mtu) +{ + Q_D(PppSetting); + + d->mtu = mtu; +} + +quint32 NetworkManager::PppSetting::mtu() const +{ + Q_D(const PppSetting); + + return d->mtu; +} + +void NetworkManager::PppSetting::setLcpEchoFailure(quint32 number) +{ + Q_D(PppSetting); + + d->lcpEchoFailure = number; +} + +quint32 NetworkManager::PppSetting::lcpEchoFailure() const +{ + Q_D(const PppSetting); + + return d->lcpEchoFailure; +} + +void NetworkManager::PppSetting::setLcpEchoInterval(quint32 interval) +{ + Q_D(PppSetting); + + d->lcpEchoInterval = interval; +} + +quint32 NetworkManager::PppSetting::lcpEchoInterval() const +{ + Q_D(const PppSetting); + + return d->lcpEchoInterval; +} + +void NetworkManager::PppSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_PPP_NOAUTH))) { + setNoAuth(setting.value(QLatin1String(NM_SETTING_PPP_NOAUTH)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_EAP))) { + setRefuseEap(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_EAP)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_PAP))) { + setRefusePap(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_PAP)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_CHAP))) { + setRefuseChap(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_CHAP)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP))) { + setRefuseMschap(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2))) { + setRefuseMschapv2(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_NOBSDCOMP))) { + setNoBsdComp(setting.value(QLatin1String(NM_SETTING_PPP_NOBSDCOMP)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_NODEFLATE))) { + setNoDeflate(setting.value(QLatin1String(NM_SETTING_PPP_NODEFLATE)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_NO_VJ_COMP))) { + setNoVjComp(setting.value(QLatin1String(NM_SETTING_PPP_NO_VJ_COMP)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE))) { + setRequireMppe(setting.value(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128))) { + setRequireMppe128(setting.value(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL))) { + setMppeStateful(setting.value(QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_CRTSCTS))) { + setCRtsCts(setting.value(QLatin1String(NM_SETTING_PPP_CRTSCTS)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_BAUD))) { + setBaud(setting.value(QLatin1String(NM_SETTING_PPP_BAUD)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_MRU))) { + setMru(setting.value(QLatin1String(NM_SETTING_PPP_MRU)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_MTU))) { + setMtu(setting.value(QLatin1String(NM_SETTING_PPP_MTU)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE))) { + setLcpEchoFailure(setting.value(QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL))) { + setLcpEchoInterval(setting.value(QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL)).toUInt()); + } +} + +QVariantMap NetworkManager::PppSetting::toMap() const +{ + QVariantMap setting; + + if (!noAuth()) { + setting.insert(QLatin1String(NM_SETTING_PPP_NOAUTH), noAuth()); + } + + if (refuseEap()) { + setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_EAP), refuseEap()); + } + + if (refusePap()) { + setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_PAP), refusePap()); + } + + if (refuseChap()) { + setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_CHAP), refuseChap()); + } + + if (refuseMschap()) { + setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP), refuseMschap()); + } + + if (refuseMschapv2()) { + setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2), refuseMschapv2()); + } + + if (noBsdComp()) { + setting.insert(QLatin1String(NM_SETTING_PPP_NOBSDCOMP), noBsdComp()); + } + + if (noDeflate()) { + setting.insert(QLatin1String(NM_SETTING_PPP_NODEFLATE), noDeflate()); + } + + if (noVjComp()) { + setting.insert(QLatin1String(NM_SETTING_PPP_NO_VJ_COMP), noVjComp()); + } + + if (requireMppe()) { + setting.insert(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE), requireMppe()); + } + + if (requireMppe128()) { + setting.insert(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128), requireMppe128()); + } + + if (mppeStateful()) { + setting.insert(QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL), mppeStateful()); + } + + if (cRtsCts()) { + setting.insert(QLatin1String(NM_SETTING_PPP_CRTSCTS), cRtsCts()); + } + + if (baud()) { + setting.insert(QLatin1String(NM_SETTING_PPP_BAUD), baud()); + } + + if (mru()) { + setting.insert(QLatin1String(NM_SETTING_PPP_MRU), mru()); + } + + if (mtu()) { + setting.insert(QLatin1String(NM_SETTING_PPP_MTU), mtu()); + } + + if (lcpEchoFailure()) { + setting.insert(QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE), lcpEchoFailure()); + } + + if (lcpEchoInterval()) { + setting.insert(QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL), lcpEchoInterval()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::PppSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_PPP_NOAUTH << ": " << setting.noAuth() << '\n'; + dbg.nospace() << NM_SETTING_PPP_REFUSE_EAP << ": " << setting.refuseEap() << '\n'; + dbg.nospace() << NM_SETTING_PPP_REFUSE_PAP << ": " << setting.refusePap() << '\n'; + dbg.nospace() << NM_SETTING_PPP_REFUSE_CHAP << ": " << setting.refuseChap() << '\n'; + dbg.nospace() << NM_SETTING_PPP_REFUSE_MSCHAP << ": " << setting.refuseMschap() << '\n'; + dbg.nospace() << NM_SETTING_PPP_REFUSE_MSCHAPV2 << ": " << setting.refuseMschapv2() << '\n'; + dbg.nospace() << NM_SETTING_PPP_NOBSDCOMP << ": " << setting.noBsdComp() << '\n'; + dbg.nospace() << NM_SETTING_PPP_NODEFLATE << ": " << setting.noDeflate() << '\n'; + dbg.nospace() << NM_SETTING_PPP_NO_VJ_COMP << ": " << setting.noVjComp() << '\n'; + dbg.nospace() << NM_SETTING_PPP_REQUIRE_MPPE << ": " << setting.requireMppe() << '\n'; + dbg.nospace() << NM_SETTING_PPP_REQUIRE_MPPE_128 << ": " << setting.requireMppe128() << '\n'; + dbg.nospace() << NM_SETTING_PPP_MPPE_STATEFUL << ": " << setting.mppeStateful() << '\n'; + dbg.nospace() << NM_SETTING_PPP_CRTSCTS << ": " << setting.cRtsCts() << '\n'; + dbg.nospace() << NM_SETTING_PPP_BAUD << ": " << setting.baud() << '\n'; + dbg.nospace() << NM_SETTING_PPP_MRU << ": " << setting.mru() << '\n'; + dbg.nospace() << NM_SETTING_PPP_MTU << ": " << setting.mtu() << '\n'; + dbg.nospace() << NM_SETTING_PPP_LCP_ECHO_FAILURE << ": " << setting.lcpEchoFailure() << '\n'; + dbg.nospace() << NM_SETTING_PPP_LCP_ECHO_INTERVAL << ": " << setting.lcpEchoInterval() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/pppsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/pppsetting.h new file mode 100644 index 000000000..cd90d85fc --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/pppsetting.h @@ -0,0 +1,102 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_PPP_SETTING_H +#define NETWORKMANAGERQT_PPP_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class PppSettingPrivate; + +/** + * Represents ppp setting + */ +class NETWORKMANAGERQT_EXPORT PppSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + PppSetting(); + explicit PppSetting(const Ptr &other); + ~PppSetting() override; + + QString name() const override; + + void setNoAuth(bool require); + bool noAuth() const; + + void setRefuseEap(bool refuse); + bool refuseEap() const; + + void setRefusePap(bool refuse); + bool refusePap() const; + + void setRefuseChap(bool refuse); + bool refuseChap() const; + + void setRefuseMschap(bool refuse); + bool refuseMschap() const; + + void setRefuseMschapv2(bool refuse); + bool refuseMschapv2() const; + + void setNoBsdComp(bool require); + bool noBsdComp() const; + + void setNoDeflate(bool require); + bool noDeflate() const; + + void setNoVjComp(bool require); + bool noVjComp() const; + + void setRequireMppe(bool require); + bool requireMppe() const; + + void setRequireMppe128(bool require); + bool requireMppe128() const; + + void setMppeStateful(bool used); + bool mppeStateful() const; + + void setCRtsCts(bool control); + bool cRtsCts() const; + + void setBaud(quint32 baud); + quint32 baud() const; + + void setMru(quint32 mru); + quint32 mru() const; + + void setMtu(quint32 mtu); + quint32 mtu() const; + + void setLcpEchoFailure(quint32 number); + quint32 lcpEchoFailure() const; + + void setLcpEchoInterval(quint32 interval); + quint32 lcpEchoInterval() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + PppSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(PppSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const PppSetting &setting); + +} + +#endif // NETWORKMANAGERQT_PPP_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/pppsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/pppsetting_p.h new file mode 100644 index 000000000..0d5d7d622 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/pppsetting_p.h @@ -0,0 +1,42 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_PPP_SETTING_P_H +#define NETWORKMANAGERQT_PPP_SETTING_P_H + +#include + +namespace NetworkManager +{ +class PppSettingPrivate +{ +public: + PppSettingPrivate(); + + QString name; + bool noauth; + bool refuseEap; + bool refusePap; + bool refuseChap; + bool refuseMschap; + bool refuseMschapv2; + bool nobsdcomp; + bool nodeflate; + bool noVjComp; + bool requireMppe; + bool requireMppe128; + bool mppeStateful; + bool crtscts; + quint32 baud; + quint32 mru; + quint32 mtu; + quint32 lcpEchoFailure; + quint32 lcpEchoInterval; +}; + +} + +#endif // NETWORKMANAGERQT_PPP_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/proxysetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/proxysetting.cpp new file mode 100644 index 000000000..3f20ce514 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/proxysetting.cpp @@ -0,0 +1,162 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "proxysetting.h" +#include "proxysetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 6, 0) +#define NM_SETTING_PROXY_SETTING_NAME "proxy" +#define NM_SETTING_PROXY_BROWSER_ONLY "browser-only" +#define NM_SETTING_PROXY_METHOD "method" +#define NM_SETTING_PROXY_PAC_SCRIPT "pac-script" +#define NM_SETTING_PROXY_PAC_URL "pac-url" +#endif + +NetworkManager::ProxySettingPrivate::ProxySettingPrivate() + : name(NM_SETTING_PROXY_SETTING_NAME) + , browserOnly(false) + , method(ProxySetting::None) +{ +} + +NetworkManager::ProxySetting::ProxySetting() + : Setting(Setting::Proxy) + , d_ptr(new ProxySettingPrivate()) +{ +} + +NetworkManager::ProxySetting::ProxySetting(const Ptr &other) + : Setting(other) + , d_ptr(new ProxySettingPrivate()) +{ + setBrowserOnly(other->browserOnly()); + setMethod(other->method()); + setPacScript(other->pacScript()); + setPacUrl(other->pacUrl()); +} + +NetworkManager::ProxySetting::~ProxySetting() +{ + delete d_ptr; +} + +QString NetworkManager::ProxySetting::name() const +{ + Q_D(const ProxySetting); + + return d->name; +} + +void NetworkManager::ProxySetting::setBrowserOnly(bool browserOnly) +{ + Q_D(ProxySetting); + + d->browserOnly = browserOnly; +} + +bool NetworkManager::ProxySetting::browserOnly() const +{ + Q_D(const ProxySetting); + + return d->browserOnly; +} + +void NetworkManager::ProxySetting::setMethod(NetworkManager::ProxySetting::Mode method) +{ + Q_D(ProxySetting); + + d->method = method; +} + +NetworkManager::ProxySetting::Mode NetworkManager::ProxySetting::method() const +{ + Q_D(const ProxySetting); + + return d->method; +} + +void NetworkManager::ProxySetting::setPacScript(const QString &script) +{ + Q_D(ProxySetting); + + d->pacScript = script; +} + +QString NetworkManager::ProxySetting::pacScript() const +{ + Q_D(const ProxySetting); + + return d->pacScript; +} + +void NetworkManager::ProxySetting::setPacUrl(const QString &url) +{ + Q_D(ProxySetting); + + d->pacUrl = url; +} + +QString NetworkManager::ProxySetting::pacUrl() const +{ + Q_D(const ProxySetting); + + return d->pacUrl; +} + +void NetworkManager::ProxySetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY))) { + setBrowserOnly(setting.value(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PROXY_METHOD))) { + setMethod((Mode)setting.value(QLatin1String(NM_SETTING_PROXY_METHOD)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT))) { + setPacScript(setting.value(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_PROXY_PAC_URL))) { + setPacUrl(setting.value(QLatin1String(NM_SETTING_PROXY_PAC_URL)).toString()); + } +} + +QVariantMap NetworkManager::ProxySetting::toMap() const +{ + QVariantMap setting; + + setting.insert(QLatin1String(NM_SETTING_PROXY_BROWSER_ONLY), browserOnly()); + + if (method() > 0) { + setting.insert(QLatin1String(NM_SETTING_PROXY_METHOD), (int)method()); + } + + if (!pacScript().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_PROXY_PAC_SCRIPT), pacScript()); + } + + if (!pacUrl().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_PROXY_PAC_URL), pacUrl()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::ProxySetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_PROXY_BROWSER_ONLY << ": " << setting.browserOnly() << '\n'; + dbg.nospace() << NM_SETTING_PROXY_METHOD << ": " << setting.method() << '\n'; + dbg.nospace() << NM_SETTING_PROXY_PAC_SCRIPT << ": " << setting.pacScript() << '\n'; + dbg.nospace() << NM_SETTING_PROXY_PAC_URL << ": " << setting.pacUrl() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/proxysetting.h b/panels/dock/tray/networkmanager-qt/src/settings/proxysetting.h new file mode 100644 index 000000000..b05308e45 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/proxysetting.h @@ -0,0 +1,65 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_PROXY_SETTING_H +#define NETWORKMANAGERQT_PROXY_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class ProxySettingPrivate; + +/** + * Represents proxy setting + */ +class NETWORKMANAGERQT_EXPORT ProxySetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum Mode { + None = 0, + Auto = 1, + }; + + ProxySetting(); + explicit ProxySetting(const Ptr &other); + ~ProxySetting() override; + + QString name() const override; + + void setBrowserOnly(bool browserOnly); + bool browserOnly() const; + + void setMethod(Mode method); + Mode method() const; + + void setPacScript(const QString &script); + QString pacScript() const; + + void setPacUrl(const QString &url); + QString pacUrl() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + ProxySettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(ProxySetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const ProxySetting &setting); + +} + +#endif // NETWORKMANAGERQT_PROXY_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/proxysetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/proxysetting_p.h new file mode 100644 index 000000000..d60abccca --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/proxysetting_p.h @@ -0,0 +1,29 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_PROXY_SETTING_P_H +#define NETWORKMANAGERQT_PROXY_SETTING_P_H + +#include + +namespace NetworkManager +{ +class ProxySettingPrivate +{ +public: + ProxySettingPrivate(); + + QString name; + + bool browserOnly; + NetworkManager::ProxySetting::Mode method; + QString pacScript; + QString pacUrl; +}; + +} + +#endif // NETWORKMANAGERQT_PROXY_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting.cpp new file mode 100644 index 000000000..d9173af8c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting.cpp @@ -0,0 +1,1127 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "security8021xsetting.h" +#include "security8021xsetting_p.h" + +#include + +NetworkManager::Security8021xSettingPrivate::Security8021xSettingPrivate() + : name(NM_SETTING_802_1X_SETTING_NAME) + , phase1PeapVer(Security8021xSetting::PeapVersionUnknown) + , phase1PeapLabel(Security8021xSetting::PeapLabelUnknown) + , phase1FastProvisioning(Security8021xSetting::FastProvisioningUnknown) + , phase2AuthMethod(Security8021xSetting::AuthMethodUnknown) + , phase2AuthEapMethod(Security8021xSetting::AuthEapMethodUnknown) + , passwordFlags(NetworkManager::Setting::None) + , passwordRawFlags(NetworkManager::Setting::None) + , privateKeyPasswordFlags(NetworkManager::Setting::None) + , phase2PrivateKeyPasswordFlags(NetworkManager::Setting::None) + , pinFlags(NetworkManager::Setting::None) + , systemCaCerts(false) +{ +} + +NetworkManager::Security8021xSetting::Security8021xSetting() + : Setting(Setting::Security8021x) + , d_ptr(new Security8021xSettingPrivate()) +{ +} + +NetworkManager::Security8021xSetting::Security8021xSetting(const Ptr &other) + : Setting(other) + , d_ptr(new Security8021xSettingPrivate()) +{ + setEapMethods(other->eapMethods()); + setIdentity(other->identity()); + setDomainSuffixMatch(other->domainSuffixMatch()); + setAnonymousIdentity(other->anonymousIdentity()); + setPacFile(other->pacFile()); + setCaCertificate(other->caCertificate()); + setCaPath(other->caPath()); + setSubjectMatch(other->subjectMatch()); + setAltSubjectMatches(other->altSubjectMatches()); + setClientCertificate(other->clientCertificate()); + setPhase1PeapVersion(other->phase1PeapVersion()); + setPhase1PeapLabel(other->phase1PeapLabel()); + setPhase1FastProvisioning(other->phase1FastProvisioning()); + setPhase2AuthMethod(other->phase2AuthMethod()); + setPhase2AuthEapMethod(other->phase2AuthEapMethod()); + setPhase2CaCertificate(other->phase2CaCertificate()); + setPhase2CaPath(other->phase2CaPath()); + setPhase2SubjectMatch(other->phase2SubjectMatch()); + setPhase2AltSubjectMatches(other->phase2AltSubjectMatches()); + setPassword(other->password()); + setPasswordFlags(other->passwordFlags()); + setPasswordRaw(other->passwordRaw()); + setPasswordRawFlags(other->passwordRawFlags()); + setPrivateKey(other->privateKey()); + setPrivateKeyPassword(other->privateKeyPassword()); + setPrivateKeyPasswordFlags(other->privateKeyPasswordFlags()); + setPhase2PrivateKey(other->phase2PrivateKey()); + setPhase2PrivateKeyPassword(other->phase2PrivateKeyPassword()); + setPhase2PrivateKeyPasswordFlags(other->phase2PrivateKeyPasswordFlags()); + setSystemCaCertificates(other->systemCaCertificates()); +} + +NetworkManager::Security8021xSetting::~Security8021xSetting() +{ + delete d_ptr; +} + +QString NetworkManager::Security8021xSetting::name() const +{ + Q_D(const Security8021xSetting); + + return d->name; +} + +void NetworkManager::Security8021xSetting::setEapMethods(const QList &methods) +{ + Q_D(Security8021xSetting); + + d->eap = methods; +} + +QList NetworkManager::Security8021xSetting::eapMethods() const +{ + Q_D(const Security8021xSetting); + + return d->eap; +} + +void NetworkManager::Security8021xSetting::setIdentity(const QString &identity) +{ + Q_D(Security8021xSetting); + + d->identity = identity; +} + +QString NetworkManager::Security8021xSetting::identity() const +{ + Q_D(const Security8021xSetting); + + return d->identity; +} + +void NetworkManager::Security8021xSetting::setAnonymousIdentity(const QString &identity) +{ + Q_D(Security8021xSetting); + + d->anonymousIdentity = identity; +} + +QString NetworkManager::Security8021xSetting::anonymousIdentity() const +{ + Q_D(const Security8021xSetting); + + return d->anonymousIdentity; +} + +void NetworkManager::Security8021xSetting::setDomainSuffixMatch(const QString &domain) +{ + Q_D(Security8021xSetting); + + d->domainSuffixMatch = domain; +} + +QString NetworkManager::Security8021xSetting::domainSuffixMatch() const +{ + Q_D(const Security8021xSetting); + + return d->domainSuffixMatch; +} + +void NetworkManager::Security8021xSetting::setPacFile(const QString &filePath) +{ + Q_D(Security8021xSetting); + + d->pacFile = filePath; +} + +QString NetworkManager::Security8021xSetting::pacFile() const +{ + Q_D(const Security8021xSetting); + + return d->pacFile; +} + +void NetworkManager::Security8021xSetting::setCaCertificate(const QByteArray &certificate) +{ + Q_D(Security8021xSetting); + + d->caCert = certificate; +} + +QByteArray NetworkManager::Security8021xSetting::caCertificate() const +{ + Q_D(const Security8021xSetting); + + return d->caCert; +} + +void NetworkManager::Security8021xSetting::setCaPath(const QString &path) +{ + Q_D(Security8021xSetting); + + d->caPath = path; +} + +QString NetworkManager::Security8021xSetting::caPath() const +{ + Q_D(const Security8021xSetting); + + return d->caPath; +} + +void NetworkManager::Security8021xSetting::setSubjectMatch(const QString &substring) +{ + Q_D(Security8021xSetting); + + d->subjectMatch = substring; +} + +QString NetworkManager::Security8021xSetting::subjectMatch() const +{ + Q_D(const Security8021xSetting); + + return d->subjectMatch; +} + +void NetworkManager::Security8021xSetting::setAltSubjectMatches(const QStringList &strings) +{ + Q_D(Security8021xSetting); + + d->altSubjectMatches = strings; +} + +QStringList NetworkManager::Security8021xSetting::altSubjectMatches() const +{ + Q_D(const Security8021xSetting); + + return d->altSubjectMatches; +} + +void NetworkManager::Security8021xSetting::setClientCertificate(const QByteArray &certificate) +{ + Q_D(Security8021xSetting); + + d->clientCert = certificate; +} + +QByteArray NetworkManager::Security8021xSetting::clientCertificate() const +{ + Q_D(const Security8021xSetting); + + return d->clientCert; +} + +void NetworkManager::Security8021xSetting::setPhase1PeapVersion(NetworkManager::Security8021xSetting::PeapVersion version) +{ + Q_D(Security8021xSetting); + + d->phase1PeapVer = version; +} + +NetworkManager::Security8021xSetting::PeapVersion NetworkManager::Security8021xSetting::phase1PeapVersion() const +{ + Q_D(const Security8021xSetting); + + return d->phase1PeapVer; +} + +void NetworkManager::Security8021xSetting::setPhase1PeapLabel(NetworkManager::Security8021xSetting::PeapLabel label) +{ + Q_D(Security8021xSetting); + + d->phase1PeapLabel = label; +} + +NetworkManager::Security8021xSetting::PeapLabel NetworkManager::Security8021xSetting::phase1PeapLabel() const +{ + Q_D(const Security8021xSetting); + + return d->phase1PeapLabel; +} + +void NetworkManager::Security8021xSetting::setPhase1FastProvisioning(NetworkManager::Security8021xSetting::FastProvisioning provisioning) +{ + Q_D(Security8021xSetting); + + d->phase1FastProvisioning = provisioning; +} + +NetworkManager::Security8021xSetting::FastProvisioning NetworkManager::Security8021xSetting::phase1FastProvisioning() const +{ + Q_D(const Security8021xSetting); + + return d->phase1FastProvisioning; +} + +void NetworkManager::Security8021xSetting::setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethod method) +{ + Q_D(Security8021xSetting); + + d->phase2AuthMethod = method; +} + +NetworkManager::Security8021xSetting::AuthMethod NetworkManager::Security8021xSetting::phase2AuthMethod() const +{ + Q_D(const Security8021xSetting); + + return d->phase2AuthMethod; +} + +void NetworkManager::Security8021xSetting::setPhase2AuthEapMethod(NetworkManager::Security8021xSetting::AuthEapMethod method) +{ + Q_D(Security8021xSetting); + + d->phase2AuthEapMethod = method; +} + +NetworkManager::Security8021xSetting::AuthEapMethod NetworkManager::Security8021xSetting::phase2AuthEapMethod() const +{ + Q_D(const Security8021xSetting); + + return d->phase2AuthEapMethod; +} + +void NetworkManager::Security8021xSetting::setPhase2CaCertificate(const QByteArray &certificate) +{ + Q_D(Security8021xSetting); + + d->phase2CaCert = certificate; +} + +QByteArray NetworkManager::Security8021xSetting::phase2CaCertificate() const +{ + Q_D(const Security8021xSetting); + + return d->phase2CaCert; +} + +void NetworkManager::Security8021xSetting::setPhase2CaPath(const QString &path) +{ + Q_D(Security8021xSetting); + + d->phase2CaPath = path; +} + +QString NetworkManager::Security8021xSetting::phase2CaPath() const +{ + Q_D(const Security8021xSetting); + + return d->phase2CaPath; +} + +void NetworkManager::Security8021xSetting::setPhase2SubjectMatch(const QString &substring) +{ + Q_D(Security8021xSetting); + + d->phase2SubjectMatch = substring; +} + +QString NetworkManager::Security8021xSetting::phase2SubjectMatch() const +{ + Q_D(const Security8021xSetting); + + return d->phase2SubjectMatch; +} + +void NetworkManager::Security8021xSetting::setPhase2AltSubjectMatches(const QStringList &strings) +{ + Q_D(Security8021xSetting); + + d->phase2AltSubjectMatches = strings; +} + +QStringList NetworkManager::Security8021xSetting::phase2AltSubjectMatches() const +{ + Q_D(const Security8021xSetting); + + return d->phase2AltSubjectMatches; +} + +void NetworkManager::Security8021xSetting::setPhase2ClientCertificate(const QByteArray &certificate) +{ + Q_D(Security8021xSetting); + + d->phase2ClientCert = certificate; +} + +QByteArray NetworkManager::Security8021xSetting::phase2ClientCertificate() const +{ + Q_D(const Security8021xSetting); + + return d->phase2ClientCert; +} + +void NetworkManager::Security8021xSetting::setPassword(const QString &password) +{ + Q_D(Security8021xSetting); + + d->password = password; +} + +QString NetworkManager::Security8021xSetting::password() const +{ + Q_D(const Security8021xSetting); + + return d->password; +} + +void NetworkManager::Security8021xSetting::setPasswordFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(Security8021xSetting); + + d->passwordFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::Security8021xSetting::passwordFlags() const +{ + Q_D(const Security8021xSetting); + + return d->passwordFlags; +} + +void NetworkManager::Security8021xSetting::setPasswordRaw(const QByteArray &password) +{ + Q_D(Security8021xSetting); + + d->passwordRaw = password; +} + +QByteArray NetworkManager::Security8021xSetting::passwordRaw() const +{ + Q_D(const Security8021xSetting); + + return d->passwordRaw; +} + +void NetworkManager::Security8021xSetting::setPasswordRawFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(Security8021xSetting); + + d->passwordRawFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::Security8021xSetting::passwordRawFlags() const +{ + Q_D(const Security8021xSetting); + + return d->passwordRawFlags; +} + +void NetworkManager::Security8021xSetting::setPrivateKey(const QByteArray &key) +{ + Q_D(Security8021xSetting); + + d->privateKey = key; +} + +QByteArray NetworkManager::Security8021xSetting::privateKey() const +{ + Q_D(const Security8021xSetting); + + return d->privateKey; +} + +void NetworkManager::Security8021xSetting::setPrivateKeyPassword(const QString &password) +{ + Q_D(Security8021xSetting); + + d->privateKeyPassword = password; +} + +QString NetworkManager::Security8021xSetting::privateKeyPassword() const +{ + Q_D(const Security8021xSetting); + + return d->privateKeyPassword; +} + +void NetworkManager::Security8021xSetting::setPrivateKeyPasswordFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(Security8021xSetting); + + d->privateKeyPasswordFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::Security8021xSetting::privateKeyPasswordFlags() const +{ + Q_D(const Security8021xSetting); + + return d->privateKeyPasswordFlags; +} + +void NetworkManager::Security8021xSetting::setPhase2PrivateKey(const QByteArray &key) +{ + Q_D(Security8021xSetting); + + d->phase2PrivateKey = key; +} + +QByteArray NetworkManager::Security8021xSetting::phase2PrivateKey() const +{ + Q_D(const Security8021xSetting); + + return d->phase2PrivateKey; +} + +void NetworkManager::Security8021xSetting::setPhase2PrivateKeyPassword(const QString &password) +{ + Q_D(Security8021xSetting); + + d->phase2PrivateKeyPassword = password; +} + +QString NetworkManager::Security8021xSetting::phase2PrivateKeyPassword() const +{ + Q_D(const Security8021xSetting); + + return d->phase2PrivateKeyPassword; +} + +void NetworkManager::Security8021xSetting::setPhase2PrivateKeyPasswordFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(Security8021xSetting); + + d->phase2PrivateKeyPasswordFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::Security8021xSetting::phase2PrivateKeyPasswordFlags() const +{ + Q_D(const Security8021xSetting); + + return d->phase2PrivateKeyPasswordFlags; +} + +void NetworkManager::Security8021xSetting::setSystemCaCertificates(bool use) +{ + Q_D(Security8021xSetting); + + d->systemCaCerts = use; +} + +void NetworkManager::Security8021xSetting::setPin(const QString &pin) +{ + Q_D(Security8021xSetting); + + d->pin = pin; +} + +QString NetworkManager::Security8021xSetting::pin() const +{ + Q_D(const Security8021xSetting); + + return d->pin; +} + +void NetworkManager::Security8021xSetting::setPinFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(Security8021xSetting); + + d->pinFlags = flags; +} + +NetworkManager::Setting::SecretFlags NetworkManager::Security8021xSetting::pinFlags() const +{ + Q_D(const Security8021xSetting); + + return d->pinFlags; +} + +bool NetworkManager::Security8021xSetting::systemCaCertificates() const +{ + Q_D(const Security8021xSetting); + + return d->systemCaCerts; +} + +QStringList NetworkManager::Security8021xSetting::needSecrets(bool requestNew) const +{ + QStringList secrets; + + /* clang-format off */ + if (eapMethods().contains(EapMethodTls) + && (privateKeyPassword().isEmpty() || requestNew) + && !privateKeyPasswordFlags().testFlag(NotRequired)) { + secrets << QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD); + } else if ((eapMethods().contains(EapMethodTtls) + || eapMethods().contains(EapMethodPeap) + || eapMethods().contains(EapMethodLeap) + || eapMethods().contains(EapMethodFast) + || eapMethods().contains(EapMethodPwd)) + && (password().isEmpty() || requestNew) + && !passwordFlags().testFlag(NotRequired)) { + secrets << QLatin1String(NM_SETTING_802_1X_PASSWORD); + secrets << QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW); + } else if (eapMethods().contains(EapMethodSim) + && (pin().isEmpty() || requestNew) + && !pinFlags().testFlag(NotRequired)) { /* clang-format on */ + secrets << QLatin1String(NM_SETTING_802_1X_PIN); + } + + /* clang-format off */ + if ((phase2AuthMethod() == AuthMethodTls || phase2AuthEapMethod() == AuthEapMethodTls) + && (phase2PrivateKeyPassword().isEmpty() || requestNew) + && !phase2PrivateKeyPasswordFlags().testFlag(NotRequired)) { /* clang-format on */ + secrets << QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD); + } + + return secrets; +} + +void NetworkManager::Security8021xSetting::secretsFromMap(const QVariantMap &secrets) +{ + if (secrets.contains(QLatin1String(NM_SETTING_802_1X_PASSWORD))) { + setPassword(secrets.value(QLatin1String(NM_SETTING_802_1X_PASSWORD)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW))) { + setPasswordRaw(secrets.value(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW)).toByteArray()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD))) { + setPrivateKeyPassword(secrets.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD))) { + setPhase2PrivateKeyPassword(secrets.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_802_1X_PIN))) { + setPin(secrets.value(QLatin1String(NM_SETTING_802_1X_PIN)).toString()); + } +} + +QVariantMap NetworkManager::Security8021xSetting::secretsToMap() const +{ + QVariantMap secrets; + + if (!password().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD), password()); + } + + if (!passwordRaw().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW), passwordRaw()); + } + + if (!privateKeyPassword().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD), privateKeyPassword()); + } + + if (!phase2PrivateKeyPassword().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD), phase2PrivateKeyPassword()); + } + + if (!pin().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_802_1X_PIN), pin()); + } + + return secrets; +} + +void NetworkManager::Security8021xSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_802_1X_EAP))) { + const QStringList methods = setting.value(QLatin1String(NM_SETTING_802_1X_EAP)).toStringList(); + QList eapMethods; + for (const QString &method : methods) { + if (method == "leap") { + eapMethods << EapMethodLeap; + } else if (method == "md5") { + eapMethods << EapMethodMd5; + } else if (method == "tls") { + eapMethods << EapMethodTls; + } else if (method == "peap") { + eapMethods << EapMethodPeap; + } else if (method == "ttls") { + eapMethods << EapMethodTtls; + } else if (method == "sim") { + eapMethods << EapMethodSim; + } else if (method == "fast") { + eapMethods << EapMethodFast; + } else if (method == "pwd") { + eapMethods << EapMethodPwd; + } + } + + setEapMethods(eapMethods); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_IDENTITY))) { + setIdentity(setting.value(QLatin1String(NM_SETTING_802_1X_IDENTITY)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY))) { + setAnonymousIdentity(setting.value(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH))) { + setDomainSuffixMatch(setting.value(QLatin1String(NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PAC_FILE))) { + setPacFile(setting.value(QLatin1String(NM_SETTING_802_1X_PAC_FILE)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_CA_CERT))) { + setCaCertificate(setting.value(QLatin1String(NM_SETTING_802_1X_CA_CERT)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_CA_PATH))) { + setCaPath(setting.value(QLatin1String(NM_SETTING_802_1X_CA_PATH)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_SUBJECT_MATCH))) { + setSubjectMatch(setting.value(QLatin1String(NM_SETTING_802_1X_SUBJECT_MATCH)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_ALTSUBJECT_MATCHES))) { + setAltSubjectMatches(setting.value(QLatin1String(NM_SETTING_802_1X_ALTSUBJECT_MATCHES)).toStringList()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT))) { + setClientCertificate(setting.value(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER))) { + const QString version = setting.value(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER)).toString(); + + if (version == "0") { + setPhase1PeapVersion(PeapVersionZero); + } else if (version == "1") { + setPhase1PeapVersion(PeapVersionOne); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL))) { + const QString label = setting.value(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL)).toString(); + + if (label == "1") { + setPhase1PeapLabel(PeapLabelForce); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING))) { + const QString provisioning = setting.value(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING)).toString(); + + if (provisioning == "0") { + setPhase1FastProvisioning(FastProvisioningDisabled); + } else if (provisioning == "1") { + setPhase1FastProvisioning(FastProvisioningAllowUnauthenticated); + } else if (provisioning == "2") { + setPhase1FastProvisioning(FastProvisioningAllowAuthenticated); + } else if (provisioning == "3") { + setPhase1FastProvisioning(FastProvisioningAllowBoth); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH))) { + const QString authMethod = setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH)).toString(); + + if (authMethod == "pap") { + setPhase2AuthMethod(AuthMethodPap); + } else if (authMethod == "chap") { + setPhase2AuthMethod(AuthMethodChap); + } else if (authMethod == "mschap") { + setPhase2AuthMethod(AuthMethodMschap); + } else if (authMethod == "mschapv2") { + setPhase2AuthMethod(AuthMethodMschapv2); + } else if (authMethod == "gtc") { + setPhase2AuthMethod(AuthMethodGtc); + } else if (authMethod == "otp") { + setPhase2AuthMethod(AuthMethodOtp); + } else if (authMethod == "md5") { + setPhase2AuthMethod(AuthMethodMd5); + } else if (authMethod == "tls") { + setPhase2AuthMethod(AuthMethodTls); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP))) { + const QString authEapMethod = setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP)).toString(); + + if (authEapMethod == "md5") { + setPhase2AuthEapMethod(AuthEapMethodMd5); + } else if (authEapMethod == "mschapv2") { + setPhase2AuthEapMethod(AuthEapMethodMschapv2); + } else if (authEapMethod == "otp") { + setPhase2AuthEapMethod(AuthEapMethodOtp); + } else if (authEapMethod == "gtc") { + setPhase2AuthEapMethod(AuthEapMethodGtc); + } else if (authEapMethod == "tls") { + setPhase2AuthEapMethod(AuthEapMethodTls); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT))) { + setPhase2CaCertificate(setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH))) { + setPhase2CaPath(setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH))) { + setPhase2SubjectMatch(setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES))) { + setPhase2AltSubjectMatches(setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES)).toStringList()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT))) { + setPhase2ClientCertificate(setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PASSWORD))) { + setPassword(setting.value(QLatin1String(NM_SETTING_802_1X_PASSWORD)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PASSWORD_FLAGS))) { + setPasswordFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_802_1X_PASSWORD_FLAGS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW))) { + setPasswordRaw(setting.value(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW_FLAGS))) { + setPasswordRawFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW_FLAGS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY))) { + setPrivateKey(setting.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD))) { + setPrivateKeyPassword(setting.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS))) { + setPrivateKeyPasswordFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY))) { + setPhase2PrivateKey(setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD))) { + setPhase2PrivateKeyPassword(setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS))) { + setPhase2PrivateKeyPasswordFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PIN))) { + setPin(setting.value(QLatin1String(NM_SETTING_802_1X_PIN)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_PIN_FLAGS))) { + setPinFlags((Setting::SecretFlags)setting.value(QLatin1String(NM_SETTING_802_1X_PIN_FLAGS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS))) { + setSystemCaCertificates(setting.value(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS)).toBool()); + } +} + +QVariantMap NetworkManager::Security8021xSetting::toMap() const +{ + QVariantMap setting; + + if (!eapMethods().isEmpty()) { + QStringList methods; + + const auto methodList = eapMethods(); + for (const EapMethod &method : methodList) { + if (method == EapMethodLeap) { + methods << "leap"; + } else if (method == EapMethodMd5) { + methods << "md5"; + } else if (method == EapMethodTls) { + methods << "tls"; + } else if (method == EapMethodPeap) { + methods << "peap"; + } else if (method == EapMethodTtls) { + methods << "ttls"; + } else if (method == EapMethodSim) { + methods << "sim"; + } else if (method == EapMethodFast) { + methods << "fast"; + } else if (method == EapMethodPwd) { + methods << "pwd"; + } + } + + setting.insert(QLatin1String(NM_SETTING_802_1X_EAP), methods); + } + + if (!identity().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_IDENTITY), identity()); + } + + if (!anonymousIdentity().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY), anonymousIdentity()); + } + + if (!domainSuffixMatch().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH), domainSuffixMatch()); + } + + if (!pacFile().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PAC_FILE), pacFile()); + } + + if (!caCertificate().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_CA_CERT), caCertificate()); + } + + if (!caPath().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_CA_PATH), caPath()); + } + + if (!subjectMatch().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_SUBJECT_MATCH), subjectMatch()); + } + + if (!altSubjectMatches().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_ALTSUBJECT_MATCHES), altSubjectMatches()); + } + + if (!clientCertificate().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT), clientCertificate()); + } + + QString version; + switch (phase1PeapVersion()) { + case PeapVersionZero: + version = '0'; + break; + case PeapVersionOne: + version = '1'; + break; + case PeapVersionUnknown: + break; + } + + if (!version.isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER), version); + } + + QString peapLabel; + switch (phase1PeapLabel()) { + case PeapLabelForce: + peapLabel = '1'; + break; + case PeapLabelUnknown: + break; + } + + if (!peapLabel.isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL), peapLabel); + } + + QString provisioning; + switch (phase1FastProvisioning()) { + case FastProvisioningDisabled: + provisioning = '0'; + break; + case FastProvisioningAllowUnauthenticated: + provisioning = '1'; + break; + case FastProvisioningAllowAuthenticated: + provisioning = '2'; + break; + case FastProvisioningAllowBoth: + provisioning = '3'; + break; + case FastProvisioningUnknown: + break; + } + + if (!provisioning.isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING), provisioning); + } + + QString authMethod; + switch (phase2AuthMethod()) { + case AuthMethodPap: + authMethod = "pap"; + break; + case AuthMethodChap: + authMethod = "chap"; + break; + case AuthMethodMschap: + authMethod = "mschap"; + break; + case AuthMethodMschapv2: + authMethod = "mschapv2"; + break; + case AuthMethodGtc: + authMethod = "gtc"; + break; + case AuthMethodOtp: + authMethod = "otp"; + break; + case AuthMethodMd5: + authMethod = "md5"; + break; + case AuthMethodTls: + authMethod = "tls"; + break; + case AuthMethodUnknown: + break; + } + + if (!authMethod.isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), authMethod); + } + + QString authEapMethod; + switch (phase2AuthEapMethod()) { + case AuthEapMethodMd5: + authEapMethod = "md5"; + break; + case AuthEapMethodMschapv2: + authEapMethod = "mschapv2"; + break; + case AuthEapMethodOtp: + authEapMethod = "otp"; + break; + case AuthEapMethodGtc: + authEapMethod = "gtc"; + break; + case AuthEapMethodTls: + authEapMethod = "tls"; + break; + case AuthEapMethodUnknown: + break; + } + + if (!authEapMethod.isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), authEapMethod); + } + + if (!phase2CaCertificate().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT), phase2CaCertificate()); + } + + if (!phase2CaPath().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH), phase2CaPath()); + } + + if (!phase2SubjectMatch().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH), phase2SubjectMatch()); + } + + if (!phase2AltSubjectMatches().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES), phase2AltSubjectMatches()); + } + + if (!phase2ClientCertificate().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT), phase2ClientCertificate()); + } + + if (!password().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD), password()); + } + + if (passwordFlags() != None) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD_FLAGS), (int)passwordFlags()); + } + + if (!passwordRaw().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW), passwordRaw()); + } + + if (passwordRawFlags() != None) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW_FLAGS), (int)passwordRawFlags()); + } + + if (!privateKey().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY), privateKey()); + } + + if (!privateKeyPassword().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD), privateKeyPassword()); + } + + if (privateKeyPasswordFlags() != None) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS), (int)privateKeyPasswordFlags()); + } + + if (!phase2PrivateKey().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY), phase2PrivateKey()); + } + + if (!phase2PrivateKeyPassword().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD), phase2PrivateKeyPassword()); + } + + if (phase2PrivateKeyPasswordFlags() != None) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS), (int)phase2PrivateKeyPasswordFlags()); + } + + if (!pin().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PIN), pin()); + } + + if (pinFlags() != None) { + setting.insert(QLatin1String(NM_SETTING_802_1X_PIN_FLAGS), (int)pinFlags()); + } + + if (systemCaCertificates()) { + setting.insert(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS), systemCaCertificates()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::Security8021xSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_802_1X_EAP << ": " << setting.eapMethods() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_IDENTITY << ": " << setting.identity() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_ANONYMOUS_IDENTITY << ": " << setting.anonymousIdentity() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PAC_FILE << ": " << setting.pacFile() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_CA_CERT << ": " << setting.caCertificate() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_CA_PATH << ": " << setting.caPath() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH << ": " << setting.domainSuffixMatch() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_SUBJECT_MATCH << ": " << setting.subjectMatch() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_ALTSUBJECT_MATCHES << ": " << setting.altSubjectMatches() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_CLIENT_CERT << ": " << setting.clientCertificate() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE1_PEAPVER << ": " << setting.phase1PeapVersion() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE1_PEAPLABEL << ": " << setting.phase1PeapLabel() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING << ": " << setting.phase1FastProvisioning() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_AUTH << ": " << setting.phase2AuthMethod() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_AUTHEAP << ": " << setting.phase2AuthEapMethod() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_CA_CERT << ": " << setting.phase2CaCertificate() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_CA_PATH << ": " << setting.phase2CaPath() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH << ": " << setting.phase2SubjectMatch() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES << ": " << setting.phase2AltSubjectMatches() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_CLIENT_CERT << ": " << setting.phase2ClientCertificate() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PASSWORD << ": " << setting.password() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PASSWORD_FLAGS << ": " << setting.passwordFlags() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PASSWORD_RAW << ": " << setting.passwordRaw() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PASSWORD_RAW_FLAGS << ": " << setting.passwordRawFlags() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PRIVATE_KEY << ": " << setting.privateKey() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD << ": " << setting.privateKeyPassword() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS << ": " << setting.privateKeyPasswordFlags() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_PRIVATE_KEY << ": " << setting.phase2PrivateKey() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD << ": " << setting.phase2PrivateKeyPassword() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS << ": " << setting.phase2PrivateKeyPasswordFlags() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PIN << ": " << setting.pin() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_PIN_FLAGS << ": " << setting.pinFlags() << '\n'; + dbg.nospace() << NM_SETTING_802_1X_SYSTEM_CA_CERTS << ": " << setting.systemCaCertificates() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting.h new file mode 100644 index 000000000..cde5b3c6f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting.h @@ -0,0 +1,232 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SECURITY8021X_SETTING_H +#define NETWORKMANAGERQT_SECURITY8021X_SETTING_H + +#include "setting.h" +#include + +namespace NetworkManager +{ +class Security8021xSettingPrivate; + +/** + * Represents 802.1x wireless security setting + */ +class NETWORKMANAGERQT_EXPORT Security8021xSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum EapMethod { + EapMethodUnknown = 0, + EapMethodLeap, + EapMethodMd5, + EapMethodTls, + EapMethodPeap, + EapMethodTtls, + EapMethodSim, + EapMethodFast, + EapMethodPwd, + }; + enum PeapVersion { + PeapVersionUnknown = -1, + PeapVersionZero, + PeapVersionOne, + }; + enum PeapLabel { + PeapLabelUnknown = 0, + PeapLabelForce, + }; + enum FastProvisioning { + FastProvisioningUnknown = -1, + FastProvisioningDisabled, + FastProvisioningAllowUnauthenticated, + FastProvisioningAllowAuthenticated, + FastProvisioningAllowBoth, + }; + enum AuthMethod { + AuthMethodUnknown = 0, + AuthMethodPap, + AuthMethodChap, + AuthMethodMschap, + AuthMethodMschapv2, + AuthMethodGtc, + AuthMethodOtp, + AuthMethodMd5, + AuthMethodTls, + }; + enum AuthEapMethod { + AuthEapMethodUnknown = 0, + AuthEapMethodMd5, + AuthEapMethodMschapv2, + AuthEapMethodOtp, + AuthEapMethodGtc, + AuthEapMethodTls, + }; + + Security8021xSetting(); + explicit Security8021xSetting(const Ptr &other); + ~Security8021xSetting() override; + + QString name() const override; + + void setEapMethods(const QList &methods); + QList eapMethods() const; + + void setIdentity(const QString &identity); + QString identity() const; + + void setAnonymousIdentity(const QString &identity); + QString anonymousIdentity() const; + + void setDomainSuffixMatch(const QString &domainSuffixMatch); + QString domainSuffixMatch() const; + + /** + * Set UTF-8 encoded file path containing PAC for EAP-FAST. + * + * \param filePath file path to be set. + */ + void setPacFile(const QString &filePath); + QString pacFile() const; + + /** + * Set certificate authority (ca)'s certificate for this setting. + * + * \param certificate certificate's file path encoded into a byte array. + * + * \warning certificate have to be null terminated or NetworkManager will refuse it. + */ + void setCaCertificate(const QByteArray &certificate); + QByteArray caCertificate() const; + + void setCaPath(const QString &path); + QString caPath() const; + + void setSubjectMatch(const QString &substring); + QString subjectMatch() const; + + void setAltSubjectMatches(const QStringList &strings); + QStringList altSubjectMatches() const; + + /** + * Set client certificate for this setting. + * + * \param certificate certificate's file path encoded into a byte array. + * + * \warning certificate have to be null terminated or NetworkManager will refuse it. + */ + void setClientCertificate(const QByteArray &certificate); + QByteArray clientCertificate() const; + + void setPhase1PeapVersion(PeapVersion version); + PeapVersion phase1PeapVersion() const; + + void setPhase1PeapLabel(PeapLabel label); + PeapLabel phase1PeapLabel() const; + + void setPhase1FastProvisioning(FastProvisioning provisioning); + FastProvisioning phase1FastProvisioning() const; + + void setPhase2AuthMethod(AuthMethod method); + AuthMethod phase2AuthMethod() const; + + void setPhase2AuthEapMethod(AuthEapMethod method); + AuthEapMethod phase2AuthEapMethod() const; + + /** + * Contains the CA certificate if used by the EAP method specified in the + * phase2AuthMethod() or phase2AuthEapMethod() properties. + * + * \param certificate certificate's file path encoded into a byte array. + * + * \warning certificate have to be null terminated or NetworkManager will refuse it. + */ + void setPhase2CaCertificate(const QByteArray &certificate); + QByteArray phase2CaCertificate() const; + + void setPhase2CaPath(const QString &path); + QString phase2CaPath() const; + + void setPhase2SubjectMatch(const QString &substring); + QString phase2SubjectMatch() const; + + void setPhase2AltSubjectMatches(const QStringList &strings); + QStringList phase2AltSubjectMatches() const; + + void setPhase2ClientCertificate(const QByteArray &certificate); + QByteArray phase2ClientCertificate() const; + + void setPassword(const QString &password); + QString password() const; + + void setPasswordFlags(Setting::SecretFlags flags); + Setting::SecretFlags passwordFlags() const; + + void setPasswordRaw(const QByteArray &password); + QByteArray passwordRaw() const; + + void setPasswordRawFlags(Setting::SecretFlags flags); + Setting::SecretFlags passwordRawFlags() const; + + /** + * Set private key for this setting. + * + * \param key the key to be set. + * + * \warning key have to be null terminated or NetworkManager will refuse it. + */ + void setPrivateKey(const QByteArray &key); + QByteArray privateKey() const; + + void setPrivateKeyPassword(const QString &password); + QString privateKeyPassword() const; + + void setPrivateKeyPasswordFlags(Setting::SecretFlags flags); + Setting::SecretFlags privateKeyPasswordFlags() const; + + void setPhase2PrivateKey(const QByteArray &key); + QByteArray phase2PrivateKey() const; + + void setPhase2PrivateKeyPassword(const QString &password); + QString phase2PrivateKeyPassword() const; + + void setPhase2PrivateKeyPasswordFlags(Setting::SecretFlags flags); + Setting::SecretFlags phase2PrivateKeyPasswordFlags() const; + + void setPin(const QString &pin); + QString pin() const; + + void setPinFlags(Setting::SecretFlags flags); + Setting::SecretFlags pinFlags() const; + + void setSystemCaCertificates(bool use); + bool systemCaCertificates() const; + + QStringList needSecrets(bool requestNew = false) const override; + + void secretsFromMap(const QVariantMap &secrets) override; + + QVariantMap secretsToMap() const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + Security8021xSettingPrivate *const d_ptr; + +private: + Q_DECLARE_PRIVATE(Security8021xSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const Security8021xSetting &setting); + +} + +#endif // NETWORKMANAGERQT_SECURITY802X_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting_p.h new file mode 100644 index 000000000..b2a201715 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/security8021xsetting_p.h @@ -0,0 +1,57 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SECURITY8021X_SETTING_P_H +#define NETWORKMANAGERQT_SECURITY8021X_SETTING_P_H + +#include + +namespace NetworkManager +{ +class Security8021xSettingPrivate +{ +public: + Security8021xSettingPrivate(); + + QString name; + QList eap; + QString identity; + QString anonymousIdentity; + QString domainSuffixMatch; + QString pacFile; + QByteArray caCert; + QString caPath; + QString subjectMatch; + QStringList altSubjectMatches; + QByteArray clientCert; + Security8021xSetting::PeapVersion phase1PeapVer; + Security8021xSetting::PeapLabel phase1PeapLabel; + Security8021xSetting::FastProvisioning phase1FastProvisioning; + Security8021xSetting::AuthMethod phase2AuthMethod; + Security8021xSetting::AuthEapMethod phase2AuthEapMethod; + QByteArray phase2CaCert; + QString phase2CaPath; + QString phase2SubjectMatch; + QStringList phase2AltSubjectMatches; + QByteArray phase2ClientCert; + QString password; + Setting::SecretFlags passwordFlags; + QByteArray passwordRaw; + Setting::SecretFlags passwordRawFlags; + QByteArray privateKey; + QString privateKeyPassword; + Setting::SecretFlags privateKeyPasswordFlags; + QByteArray phase2PrivateKey; + QString phase2PrivateKeyPassword; + Setting::SecretFlags phase2PrivateKeyPasswordFlags; + QString pin; + Setting::SecretFlags pinFlags; + bool systemCaCerts; +}; + +} + +#endif // NETWORKMANAGERQT_SECURITY802X_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/serialsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/serialsetting.cpp new file mode 100644 index 000000000..21b1031af --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/serialsetting.cpp @@ -0,0 +1,195 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "serialsetting.h" +#include "serialsetting_p.h" + +#include + +NetworkManager::SerialSettingPrivate::SerialSettingPrivate() + : name(NM_SETTING_SERIAL_SETTING_NAME) + , baud(57600) + , bits(8) + , parity(SerialSetting::NoParity) + , stopbits(1) + , sendDelay(0) +{ +} + +NetworkManager::SerialSetting::SerialSetting() + : Setting(Setting::Serial) + , d_ptr(new SerialSettingPrivate()) +{ +} + +NetworkManager::SerialSetting::SerialSetting(const Ptr &other) + : Setting(other) + , d_ptr(new SerialSettingPrivate()) +{ + setBaud(other->baud()); + setBits(other->bits()); + setParity(other->parity()); + setStopbits(other->stopbits()); + setSendDelay(other->sendDelay()); +} + +NetworkManager::SerialSetting::~SerialSetting() +{ + delete d_ptr; +} + +QString NetworkManager::SerialSetting::name() const +{ + Q_D(const SerialSetting); + + return d->name; +} + +void NetworkManager::SerialSetting::setBaud(quint32 speed) +{ + Q_D(SerialSetting); + + d->baud = speed; +} + +quint32 NetworkManager::SerialSetting::baud() const +{ + Q_D(const SerialSetting); + + return d->baud; +} + +void NetworkManager::SerialSetting::setBits(quint32 byteWidgh) +{ + Q_D(SerialSetting); + + d->bits = byteWidgh; +} + +quint32 NetworkManager::SerialSetting::bits() const +{ + Q_D(const SerialSetting); + + return d->bits; +} + +void NetworkManager::SerialSetting::setParity(NetworkManager::SerialSetting::Parity paritysetting) +{ + Q_D(SerialSetting); + + d->parity = paritysetting; +} + +NetworkManager::SerialSetting::Parity NetworkManager::SerialSetting::parity() const +{ + Q_D(const SerialSetting); + + return d->parity; +} + +void NetworkManager::SerialSetting::setStopbits(quint32 number) +{ + Q_D(SerialSetting); + + d->stopbits = number; +} + +quint32 NetworkManager::SerialSetting::stopbits() const +{ + Q_D(const SerialSetting); + + return d->stopbits; +} + +void NetworkManager::SerialSetting::setSendDelay(quint64 delay) +{ + Q_D(SerialSetting); + + d->sendDelay = delay; +} + +quint64 NetworkManager::SerialSetting::sendDelay() const +{ + Q_D(const SerialSetting); + + return d->sendDelay; +} + +void NetworkManager::SerialSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BAUD))) { + setBaud(setting.value(QLatin1String(NM_SETTING_SERIAL_BAUD)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BITS))) { + setBits(setting.value(QLatin1String(NM_SETTING_SERIAL_BITS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_SERIAL_PARITY))) { + QChar character = setting.value(QLatin1String(NM_SETTING_SERIAL_PARITY)).toChar(); + + if (character == 'n') { + setParity(NoParity); + } else if (character == 'E') { + setParity(EvenParity); + } else if (character == 'o') { + setParity(OddParity); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_SERIAL_STOPBITS))) { + setStopbits(setting.value(QLatin1String(NM_SETTING_SERIAL_STOPBITS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY))) { + setSendDelay((Setting::SecretFlagType)setting.value(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY)).toULongLong()); + } +} + +QVariantMap NetworkManager::SerialSetting::toMap() const +{ + QVariantMap setting; + + if (baud() != 57600) { + setting.insert(QLatin1String(NM_SETTING_SERIAL_BAUD), baud()); + } + + if (bits() != 8) { + setting.insert(QLatin1String(NM_SETTING_SERIAL_BITS), bits()); + } + + if (parity() != NoParity) { + if (parity() == EvenParity) { + setting.insert(QLatin1String(NM_SETTING_SERIAL_PARITY), QChar('E')); + } else if (parity() == OddParity) { + setting.insert(QLatin1String(NM_SETTING_SERIAL_PARITY), QChar('o')); + } + } + + if (stopbits() != 1) { + setting.insert(QLatin1String(NM_SETTING_SERIAL_STOPBITS), stopbits()); + } + + if (sendDelay()) { + setting.insert(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY), sendDelay()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::SerialSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_SERIAL_BAUD << ": " << setting.baud() << '\n'; + dbg.nospace() << NM_SETTING_SERIAL_BITS << ": " << setting.bits() << '\n'; + dbg.nospace() << NM_SETTING_SERIAL_PARITY << ": " << setting.parity() << '\n'; + dbg.nospace() << NM_SETTING_SERIAL_STOPBITS << ": " << setting.stopbits() << '\n'; + dbg.nospace() << NM_SETTING_SERIAL_SEND_DELAY << ": " << setting.sendDelay() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/serialsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/serialsetting.h new file mode 100644 index 000000000..54699e473 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/serialsetting.h @@ -0,0 +1,69 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SERIAL_SETTING_H +#define NETWORKMANAGERQT_SERIAL_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class SerialSettingPrivate; + +/** + * Represents serial setting + */ +class NETWORKMANAGERQT_EXPORT SerialSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum Parity { + NoParity, + EvenParity, + OddParity, + }; + + SerialSetting(); + explicit SerialSetting(const Ptr &other); + ~SerialSetting() override; + + QString name() const override; + + void setBaud(quint32 speed); + quint32 baud() const; + + void setBits(quint32 byteWidth); + quint32 bits() const; + + void setParity(Parity paritysetting); + Parity parity() const; + + void setStopbits(quint32 number); + quint32 stopbits() const; + + void setSendDelay(quint64 delay); + quint64 sendDelay() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + SerialSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(SerialSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const SerialSetting &setting); + +} + +#endif // NETWORKMANAGERQT_SERIAL_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/serialsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/serialsetting_p.h new file mode 100644 index 000000000..efa1fdd4a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/serialsetting_p.h @@ -0,0 +1,29 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SERIAL_SETTING_P_H +#define NETWORKMANAGERQT_SERIAL_SETTING_P_H + +#include + +namespace NetworkManager +{ +class SerialSettingPrivate +{ +public: + SerialSettingPrivate(); + + QString name; + quint32 baud; + quint32 bits; + NetworkManager::SerialSetting::Parity parity; + quint32 stopbits; + quint64 sendDelay; +}; + +} + +#endif // NETWORKMANAGERQT_SERIAL_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/setting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/setting.cpp new file mode 100644 index 000000000..9c1ebd754 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/setting.cpp @@ -0,0 +1,357 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "setting.h" + +#undef signals +#include +#define signals Q_SIGNALS + +#include + +#if !NM_CHECK_VERSION(1, 16, 0) +#define NM_SETTING_WIREGUARD_SETTING_NAME "wireguard" +#endif + +#if !NM_CHECK_VERSION(1, 14, 0) +#define NM_SETTING_MATCH_SETTING_NAME "match" +#endif + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_OVS_BRIDGE_SETTING_NAME "ovs-bridge" +#define NM_SETTING_OVS_INTERFACE_SETTING_NAME "ovs-interface" +#define NM_SETTING_OVS_PATCH_SETTING_NAME "ovs-patch" +#define NM_SETTING_OVS_PORT_SETTING_NAME "ovs-port" +#define NM_SETTING_TC_CONFIG_SETTING_NAME "tc" +#define NM_SETTING_TEAM_PORT_SETTING_NAME "team-port" +#endif + +#if !NM_CHECK_VERSION(1, 8, 0) +#define NM_SETTING_USER_SETTING_NAME "user" +#endif + +#if !NM_CHECK_VERSION(1, 6, 0) +#define NM_SETTING_MACSEC_SETTING_NAME "macsec" +#define NM_SETTING_PROXY_SETTING_NAME "proxy" +#endif + +namespace NetworkManager +{ +class SettingPrivate +{ +public: + SettingPrivate(); + + Setting::SettingType type; + bool initialized; +}; + +QDebug operator<<(QDebug dbg, const Setting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + return dbg.maybeSpace(); +} + +} + +NetworkManager::SettingPrivate::SettingPrivate() + : type(Setting::Wired) + , initialized(false) +{ +} + +QString NetworkManager::Setting::typeAsString(NetworkManager::Setting::SettingType type) +{ + QString typeString; + + switch (type) { + case Cdma: + typeString = QLatin1String(NM_SETTING_CDMA_SETTING_NAME); + break; + case Gsm: + typeString = QLatin1String(NM_SETTING_GSM_SETTING_NAME); + break; + case Bluetooth: + typeString = QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME); + break; + case Ipv4: + typeString = QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME); + break; + case Ipv6: + typeString = QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME); + break; + case Ppp: + typeString = QLatin1String(NM_SETTING_PPP_SETTING_NAME); + break; + case Pppoe: + typeString = QLatin1String(NM_SETTING_PPPOE_SETTING_NAME); + break; + case Security8021x: + typeString = QLatin1String(NM_SETTING_802_1X_SETTING_NAME); + break; + case Serial: + typeString = QLatin1String(NM_SETTING_SERIAL_SETTING_NAME); + break; + case Vpn: + typeString = QLatin1String(NM_SETTING_VPN_SETTING_NAME); + break; + case Wired: + typeString = QLatin1String(NM_SETTING_WIRED_SETTING_NAME); + break; + case Wireless: + typeString = QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME); + break; + case WirelessSecurity: + typeString = QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); + break; + case OlpcMesh: + typeString = QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME); + break; + case Vlan: + typeString = QLatin1String(NM_SETTING_VLAN_SETTING_NAME); + break; + case Wimax: + typeString = QLatin1String(NM_SETTING_WIMAX_SETTING_NAME); + break; + case Bond: + typeString = QLatin1String(NM_SETTING_BOND_SETTING_NAME); + break; + case Bridge: + typeString = QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME); + break; + case Team: + typeString = QLatin1String(NM_SETTING_TEAM_SETTING_NAME); + break; + case Vxlan: + typeString = QLatin1String(NM_SETTING_VXLAN_SETTING_NAME); + break; + case IpTunnel: + typeString = QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME); + break; + case Proxy: + typeString = QLatin1String(NM_SETTING_PROXY_SETTING_NAME); + break; + case User: + typeString = QLatin1String(NM_SETTING_USER_SETTING_NAME); + break; + case OvsInterface: + typeString = QLatin1String(NM_SETTING_OVS_INTERFACE_SETTING_NAME); + break; + case OvsBridge: + typeString = QLatin1String(NM_SETTING_OVS_BRIDGE_SETTING_NAME); + break; + case OvsPatch: + typeString = QLatin1String(NM_SETTING_OVS_PATCH_SETTING_NAME); + break; + case OvsPort: + typeString = QLatin1String(NM_SETTING_OVS_PORT_SETTING_NAME); + break; + case Match: + typeString = QLatin1String(NM_SETTING_MATCH_SETTING_NAME); + break; + case Tc: + typeString = QLatin1String(NM_SETTING_TC_CONFIG_SETTING_NAME); + break; + case TeamPort: + typeString = QLatin1String(NM_SETTING_TEAM_PORT_SETTING_NAME); + break; + case Macsec: + typeString = QLatin1String(NM_SETTING_MACSEC_SETTING_NAME); + break; + case Dcb: + typeString = QLatin1String(NM_SETTING_DCB_SETTING_NAME); + break; + case NetworkManager::Setting::WireGuard: + typeString = QLatin1String(NM_SETTING_WIREGUARD_SETTING_NAME); + break; + case NetworkManager::Setting::Generic: + typeString = QLatin1String(NM_SETTING_GENERIC_SETTING_NAME); + break; + default: + break; + } + + return typeString; +} + +NetworkManager::Setting::SettingType NetworkManager::Setting::typeFromString(const QString &typeString) +{ + SettingType type = Wired; + + if (typeString == QLatin1String(NM_SETTING_CDMA_SETTING_NAME)) { + type = Cdma; + } else if (typeString == QLatin1String(NM_SETTING_GSM_SETTING_NAME)) { + type = Gsm; + } else if (typeString == QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME)) { + type = Bluetooth; + } else if (typeString == QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME)) { + type = Ipv4; + } else if (typeString == QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME)) { + type = Ipv6; + } else if (typeString == QLatin1String(NM_SETTING_PPP_SETTING_NAME)) { + type = Ppp; + } else if (typeString == QLatin1String(NM_SETTING_PPPOE_SETTING_NAME)) { + type = Pppoe; + } else if (typeString == QLatin1String(NM_SETTING_SERIAL_SETTING_NAME)) { + type = Serial; + } else if (typeString == QLatin1String(NM_SETTING_802_1X_SETTING_NAME)) { + type = Security8021x; + } else if (typeString == QLatin1String(NM_SETTING_VPN_SETTING_NAME)) { + type = Vpn; + } else if (typeString == QLatin1String(NM_SETTING_WIRED_SETTING_NAME)) { + type = Wired; + } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME)) { + type = Wireless; + } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) { + type = WirelessSecurity; + } else if (typeString == QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME)) { + type = OlpcMesh; + } else if (typeString == QLatin1String(NM_SETTING_VLAN_SETTING_NAME)) { + type = Vlan; + } else if (typeString == QLatin1String(NM_SETTING_WIMAX_SETTING_NAME)) { + type = Wimax; + } else if (typeString == QLatin1String(NM_SETTING_BOND_SETTING_NAME)) { + type = Bond; + } else if (typeString == QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME)) { + type = Bridge; + } else if (typeString == QLatin1String(NM_SETTING_TEAM_SETTING_NAME)) { + type = Team; + } else if (typeString == QLatin1String(NM_SETTING_VXLAN_SETTING_NAME)) { + type = Vxlan; + } else if (typeString == QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME)) { + type = IpTunnel; + } else if (typeString == QLatin1String(NM_SETTING_GENERIC_SETTING_NAME)) { + type = Generic; + } else if (typeString == QLatin1String(NM_SETTING_USER_SETTING_NAME)) { + type = User; + } else if (typeString == QLatin1String(NM_SETTING_PROXY_SETTING_NAME)) { + type = Proxy; + } else if (typeString == QLatin1String(NM_SETTING_OVS_INTERFACE_SETTING_NAME)) { + type = OvsInterface; + } else if (typeString == QLatin1String(NM_SETTING_OVS_BRIDGE_SETTING_NAME)) { + type = OvsBridge; + } else if (typeString == QLatin1String(NM_SETTING_OVS_PATCH_SETTING_NAME)) { + type = OvsPatch; + } else if (typeString == QLatin1String(NM_SETTING_OVS_PORT_SETTING_NAME)) { + type = OvsPort; + } else if (typeString == QLatin1String(NM_SETTING_MATCH_SETTING_NAME)) { + type = Match; + } else if (typeString == QLatin1String(NM_SETTING_TC_CONFIG_SETTING_NAME)) { + type = Tc; + } else if (typeString == QLatin1String(NM_SETTING_TEAM_PORT_SETTING_NAME)) { + type = TeamPort; + } else if (typeString == QLatin1String(NM_SETTING_MACSEC_SETTING_NAME)) { + type = Macsec; + } else if (typeString == QLatin1String(NM_SETTING_DCB_SETTING_NAME)) { + type = Dcb; + } else if (typeString == QLatin1String(NM_SETTING_WIREGUARD_SETTING_NAME)) { + type = WireGuard; + } + + return type; +} + +NetworkManager::Setting::Setting(SettingType type) + : d_ptr(new SettingPrivate()) +{ + setType(type); +} + +NetworkManager::Setting::Setting(const NetworkManager::Setting::Ptr &setting) + : d_ptr(new SettingPrivate()) +{ + setInitialized(!setting->isNull()); + setType(setting->type()); +} + +NetworkManager::Setting::~Setting() +{ + delete d_ptr; +} + +void NetworkManager::Setting::fromMap(const QVariantMap &map) +{ + Q_UNUSED(map); +} + +QVariantMap NetworkManager::Setting::toMap() const +{ + return QVariantMap(); +} + +QStringList NetworkManager::Setting::needSecrets(bool requestNew) const +{ + Q_UNUSED(requestNew); + return QStringList(); +} + +QString NetworkManager::Setting::name() const +{ + return QString(); +} + +void NetworkManager::Setting::secretsFromMap(const QVariantMap &map) +{ + Q_UNUSED(map); +} + +void NetworkManager::Setting::secretsFromStringMap(const NMStringMap &map) +{ + QVariantMap secretsMap; + NMStringMap::ConstIterator i = map.constBegin(); + while (i != map.constEnd()) { + secretsMap.insert(i.key(), i.value()); + ++i; + } + secretsFromMap(secretsMap); +} + +QVariantMap NetworkManager::Setting::secretsToMap() const +{ + return QVariantMap(); +} + +NMStringMap NetworkManager::Setting::secretsToStringMap() const +{ + NMStringMap ret; + QVariantMap secretsMap = secretsToMap(); + QVariantMap::ConstIterator i = secretsMap.constBegin(); + while (i != secretsMap.constEnd()) { + ret.insert(i.key(), i.value().toString()); + ++i; + } + + return ret; +} + +void NetworkManager::Setting::setInitialized(bool initialized) +{ + Q_D(Setting); + + d->initialized = initialized; +} + +bool NetworkManager::Setting::isNull() const +{ + Q_D(const Setting); + + return !d->initialized; +} + +void NetworkManager::Setting::setType(NetworkManager::Setting::SettingType type) +{ + Q_D(Setting); + + d->type = type; +} + +NetworkManager::Setting::SettingType NetworkManager::Setting::type() const +{ + Q_D(const Setting); + + return d->type; +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/setting.h b/panels/dock/tray/networkmanager-qt/src/settings/setting.h new file mode 100644 index 000000000..2a4c8c745 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/setting.h @@ -0,0 +1,150 @@ +/* + SPDX-FileCopyrightText: 2012-2019 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SETTING_H +#define NETWORKMANAGERQT_SETTING_H + +#include + +#include "generictypes.h" + +#undef signals +#include +#define signals Q_SIGNALS + +#include +#include +#include + +namespace NetworkManager +{ +class SettingPrivate; + +/** + * Base class for all kinds of setting + */ +class NETWORKMANAGERQT_EXPORT Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum SettingType { + Adsl, + Cdma, + Gsm, + Infiniband, + Ipv4, + Ipv6, + Ppp, + Pppoe, + Security8021x, + Serial, + Vpn, + Wired, + Wireless, + WirelessSecurity, + Bluetooth, + OlpcMesh, + Vlan, + Wimax, + Bond, + Bridge, + BridgePort, + Team, + Generic, + Tun, + Vxlan, + IpTunnel, + Proxy, + User, + OvsBridge, + OvsInterface, + OvsPatch, + OvsPort, + Match, + Tc, + TeamPort, + Macsec, + Dcb, + WireGuard, + }; + + enum SecretFlagType { + None = 0, + AgentOwned = 0x01, + NotSaved = 0x02, + NotRequired = 0x04, + }; + Q_DECLARE_FLAGS(SecretFlags, SecretFlagType) + + enum MacAddressRandomization { + MacAddressRandomizationDefault = 0, + MacAddressRandomizationNever, + MacAddressRandomizationAlways, + }; + + static QString typeAsString(SettingType type); + static SettingType typeFromString(const QString &type); + + explicit Setting(SettingType type); + explicit Setting(const Ptr &setting); + virtual ~Setting(); + + /** + * @brief Must be reimplemented, default implementation does nothing + */ + virtual void fromMap(const QVariantMap &map); + + /** + * @brief Must be reimplemented, default implementationd does nothing + */ + virtual QVariantMap toMap() const; + + virtual void secretsFromMap(const QVariantMap &map); + + /** + * @brief secretsFromStringMap is a convenience function + * to set the secrets from a map of strings. + * @param map to extract secrets from + */ + virtual void secretsFromStringMap(const NMStringMap &map); + + virtual QVariantMap secretsToMap() const; + + /** + * @brief secretsToStringMap is a convenience function + * to get the secrets to map of strings. + * @return string map with current secrets + */ + virtual NMStringMap secretsToStringMap() const; + + virtual QStringList needSecrets(bool requestNew = false) const; + + /** + * @brief Must be reimplemented, default implementationd does nothing + */ + virtual QString name() const; + + void setInitialized(bool initialized); + + bool isNull() const; + + void setType(SettingType type); + SettingType type() const; + +protected: + SettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(Setting) +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(Setting::SecretFlags) + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const Setting &setting); + +} + +#endif // NETWORKMANAGERQT_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/tcsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/tcsetting.cpp new file mode 100644 index 000000000..762693920 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/tcsetting.cpp @@ -0,0 +1,127 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "tcsetting.h" +#include "tcsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_TC_CONFIG_SETTING_NAME "tc" + +#define NM_SETTING_TC_CONFIG_QDISCS "qdiscs" +#define NM_SETTING_TC_CONFIG_TFILTERS "tfilters" +#endif + +NetworkManager::TcSettingPrivate::TcSettingPrivate() + : name(NM_SETTING_TC_CONFIG_SETTING_NAME) +{ +} + +NetworkManager::TcSetting::TcSetting() + : Setting(Setting::Tc) + , d_ptr(new TcSettingPrivate()) +{ +} + +NetworkManager::TcSetting::TcSetting(const Ptr &other) + : Setting(other) + , d_ptr(new TcSettingPrivate()) +{ + setQdiscs(other->qdiscs()); + setTfilters(other->tfilters()); +} + +NetworkManager::TcSetting::~TcSetting() +{ + delete d_ptr; +} + +QString NetworkManager::TcSetting::name() const +{ + Q_D(const TcSetting); + + return d->name; +} + +void NetworkManager::TcSetting::setQdiscs(const NMVariantMapList &qdiscs) +{ + Q_D(TcSetting); + + d->qdiscs = qdiscs; +} + +NMVariantMapList NetworkManager::TcSetting::qdiscs() const +{ + Q_D(const TcSetting); + + return d->qdiscs; +} + +void NetworkManager::TcSetting::setTfilters(const NMVariantMapList &tfilters) +{ + Q_D(TcSetting); + + d->tfilters = tfilters; +} + +NMVariantMapList NetworkManager::TcSetting::tfilters() const +{ + Q_D(const TcSetting); + + return d->tfilters; +} + +void NetworkManager::TcSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS))) { + setQdiscs(qdbus_cast(setting.value(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS))) { + setTfilters(qdbus_cast(setting.value(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS)))); + } +} + +QVariantMap NetworkManager::TcSetting::toMap() const +{ + QVariantMap setting; + + if (!qdiscs().empty()) { + setting.insert(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS), QVariant::fromValue(qdiscs())); + } + + if (!tfilters().empty()) { + setting.insert(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS), QVariant::fromValue(tfilters())); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TcSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_TC_CONFIG_QDISCS << ": " << '\n'; + const NMVariantMapList qdiscList = setting.qdiscs(); + for (const QVariantMap &qdisc : qdiscList) { + QVariantMap::const_iterator i = qdisc.constBegin(); + while (i != qdisc.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + dbg.nospace() << NM_SETTING_TC_CONFIG_TFILTERS << ": " << '\n'; + const NMVariantMapList tfiltersList = setting.tfilters(); + for (const QVariantMap &tfilter : tfiltersList) { + QVariantMap::const_iterator i = tfilter.constBegin(); + while (i != tfilter.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/tcsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/tcsetting.h new file mode 100644 index 000000000..d28420f8d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/tcsetting.h @@ -0,0 +1,53 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TC_SETTING_H +#define NETWORKMANAGERQT_TC_SETTING_H + +#include "setting.h" +#include + +namespace NetworkManager +{ +class TcSettingPrivate; + +/** + * Represents Tc setting + */ +class NETWORKMANAGERQT_EXPORT TcSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + TcSetting(); + explicit TcSetting(const Ptr &other); + ~TcSetting() override; + + QString name() const override; + + void setQdiscs(const NMVariantMapList &qdiscs); + NMVariantMapList qdiscs() const; + + void setTfilters(const NMVariantMapList &tfilters); + NMVariantMapList tfilters() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + TcSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(TcSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const TcSetting &setting); + +} + +#endif // NETWORKMANAGERQT_TC_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/tcsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/tcsetting_p.h new file mode 100644 index 000000000..c20d91edf --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/tcsetting_p.h @@ -0,0 +1,31 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TC_SETTING_P_H +#define NETWORKMANAGERQT_TC_SETTING_P_H + +#include + +#include + +typedef QList NMVariantMapList; + +namespace NetworkManager +{ +class TcSettingPrivate +{ +public: + TcSettingPrivate(); + + QString name; + + NMVariantMapList qdiscs; + NMVariantMapList tfilters; +}; + +} + +#endif // NETWORKMANAGERQT_TC_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting.cpp new file mode 100644 index 000000000..61a30053f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting.cpp @@ -0,0 +1,251 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "teamportsetting.h" +#include "teamportsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_TEAM_PORT_SETTING_NAME "team-port" + +#define NM_SETTING_TEAM_PORT_CONFIG "config" +#define NM_SETTING_TEAM_PORT_QUEUE_ID "queue-id" +#define NM_SETTING_TEAM_PORT_PRIO "prio" +#define NM_SETTING_TEAM_PORT_STICKY "sticky" +#define NM_SETTING_TEAM_PORT_LACP_PRIO "lacp-prio" +#define NM_SETTING_TEAM_PORT_LACP_KEY "lacp-key" +#define NM_SETTING_TEAM_PORT_LINK_WATCHERS "link-watchers" +#endif + +NetworkManager::TeamPortSettingPrivate::TeamPortSettingPrivate() + : name(NM_SETTING_TEAM_PORT_SETTING_NAME) + , lacpKey(0) + , lacpPrio(255) + , prio(0) + , queueId(-1) + , sticky(false) +{ +} + +NetworkManager::TeamPortSetting::TeamPortSetting() + : Setting(Setting::TeamPort) + , d_ptr(new TeamPortSettingPrivate()) +{ +} + +NetworkManager::TeamPortSetting::TeamPortSetting(const Ptr &other) + : Setting(other) + , d_ptr(new TeamPortSettingPrivate()) +{ + config(other->config()); + lacpKey(other->lacpKey()); + lacpPrio(other->lacpPrio()); + prio(other->prio()); + queueId(other->queueId()); + sticky(other->sticky()); + setLinkWatchers(other->linkWatchers()); +} + +NetworkManager::TeamPortSetting::~TeamPortSetting() +{ + delete d_ptr; +} + +QString NetworkManager::TeamPortSetting::name() const +{ + Q_D(const TeamPortSetting); + + return d->name; +} + +void NetworkManager::TeamPortSetting::config(const QString &config) +{ + Q_D(TeamPortSetting); + + d->config = config; +} + +QString NetworkManager::TeamPortSetting::config() const +{ + Q_D(const TeamPortSetting); + + return d->config; +} + +void NetworkManager::TeamPortSetting::lacpKey(qint32 key) +{ + Q_D(TeamPortSetting); + + d->lacpKey = key; +} + +qint32 NetworkManager::TeamPortSetting::lacpKey() const +{ + Q_D(const TeamPortSetting); + + return d->lacpKey; +} + +void NetworkManager::TeamPortSetting::lacpPrio(qint32 priority) +{ + Q_D(TeamPortSetting); + + d->lacpPrio = priority; +} + +qint32 NetworkManager::TeamPortSetting::lacpPrio() const +{ + Q_D(const TeamPortSetting); + + return d->lacpPrio; +} + +void NetworkManager::TeamPortSetting::prio(qint32 prio) +{ + Q_D(TeamPortSetting); + + d->prio = prio; +} + +qint32 NetworkManager::TeamPortSetting::prio() const +{ + Q_D(const TeamPortSetting); + + return d->prio; +} + +void NetworkManager::TeamPortSetting::queueId(qint32 id) +{ + Q_D(TeamPortSetting); + + d->queueId = id; +} + +qint32 NetworkManager::TeamPortSetting::queueId() const +{ + Q_D(const TeamPortSetting); + + return d->queueId; +} + +void NetworkManager::TeamPortSetting::sticky(bool sticky) +{ + Q_D(TeamPortSetting); + + d->sticky = sticky; +} + +bool NetworkManager::TeamPortSetting::sticky() const +{ + Q_D(const TeamPortSetting); + + return d->sticky; +} + +void NetworkManager::TeamPortSetting::setLinkWatchers(const NMVariantMapList &linkWatchers) +{ + Q_D(TeamPortSetting); + + d->linkWatchers = linkWatchers; +} + +NMVariantMapList NetworkManager::TeamPortSetting::linkWatchers() const +{ + Q_D(const TeamPortSetting); + + return d->linkWatchers; +} + +void NetworkManager::TeamPortSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG))) { + config(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY))) { + lacpKey(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO))) { + lacpPrio(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_PRIO))) { + prio(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_PRIO)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID))) { + queueId(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_STICKY))) { + sticky(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_STICKY)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS))) { + setLinkWatchers(qdbus_cast(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS)))); + } +} + +QVariantMap NetworkManager::TeamPortSetting::toMap() const +{ + QVariantMap setting; + + if (!config().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG), config()); + } + + if (lacpKey() != 0) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY), lacpKey()); + } + + if (lacpPrio() != 255) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO), lacpPrio()); + } + + if (prio() != 0) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_PRIO), prio()); + } + + if (queueId() != -1) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID), queueId()); + } + + if (sticky()) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_STICKY), sticky()); + } + + if (!linkWatchers().empty()) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS), QVariant::fromValue(linkWatchers())); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TeamPortSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_TEAM_PORT_CONFIG << ": " << setting.config() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_LACP_KEY << ": " << setting.lacpKey() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_LACP_PRIO << ": " << setting.lacpPrio() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_PRIO << ": " << setting.prio() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_QUEUE_ID << ": " << setting.queueId() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_STICKY << ": " << setting.sticky() << '\n'; + + dbg.nospace() << NM_SETTING_TEAM_PORT_LINK_WATCHERS << ": " << '\n'; + const NMVariantMapList variantMapList = setting.linkWatchers(); + for (const QVariantMap &linkWatcher : variantMapList) { + QVariantMap::const_iterator i = linkWatcher.constBegin(); + while (i != linkWatcher.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting.h new file mode 100644 index 000000000..ec6482df1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting.h @@ -0,0 +1,70 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TEAM_PORT_SETTING_H +#define NETWORKMANAGERQT_TEAM_PORT_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class TeamPortSettingPrivate; + +/** + * Represents TeamPort setting + */ +class NETWORKMANAGERQT_EXPORT TeamPortSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + TeamPortSetting(); + explicit TeamPortSetting(const Ptr &other); + ~TeamPortSetting() override; + + QString name() const override; + + void config(const QString &config); + QString config() const; + + void lacpKey(qint32 key); + qint32 lacpKey() const; + + void lacpPrio(qint32 priority); + qint32 lacpPrio() const; + + void prio(qint32 prio); + qint32 prio() const; + + void queueId(qint32 id); + qint32 queueId() const; + + void sticky(bool sticky); + bool sticky() const; + + void setLinkWatchers(const NMVariantMapList &linkWatchers); + NMVariantMapList linkWatchers() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + TeamPortSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(TeamPortSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const TeamPortSetting &setting); + +} + +#endif // NETWORKMANAGERQT_TEAM_PORT_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting_p.h new file mode 100644 index 000000000..ed57a7003 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/teamportsetting_p.h @@ -0,0 +1,34 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TEAM_PORT_SETTING_P_H +#define NETWORKMANAGERQT_TEAM_PORT_SETTING_P_H + +#include + +typedef QList NMVariantMapList; + +namespace NetworkManager +{ +class TeamPortSettingPrivate +{ +public: + TeamPortSettingPrivate(); + + QString name; + + QString config; + qint32 lacpKey; + qint32 lacpPrio; + qint32 prio; + qint32 queueId; + bool sticky; + NMVariantMapList linkWatchers; +}; + +} + +#endif // NETWORKMANAGERQT_TEAM_PORT_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/teamsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/teamsetting.cpp new file mode 100644 index 000000000..db1a2119d --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/teamsetting.cpp @@ -0,0 +1,106 @@ +/* + SPDX-FileCopyrightText: 2014 Lukáš Tinkl + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "teamsetting.h" +#include "manager.h" +#include "teamsetting_p.h" + +#define NM_SETTING_TEAM_INTERFACE_NAME "interface-name" + +#include + +NetworkManager::TeamSettingPrivate::TeamSettingPrivate() + : name(NM_SETTING_TEAM_SETTING_NAME) +{ +} + +NetworkManager::TeamSetting::TeamSetting() + : Setting(Setting::Team) + , d_ptr(new TeamSettingPrivate()) +{ +} + +NetworkManager::TeamSetting::TeamSetting(const Ptr &other) + : Setting(other) + , d_ptr(new TeamSettingPrivate()) +{ + setInterfaceName(other->interfaceName()); + setConfig(other->config()); +} + +NetworkManager::TeamSetting::~TeamSetting() +{ + delete d_ptr; +} + +QString NetworkManager::TeamSetting::name() const +{ + Q_D(const TeamSetting); + + return d->name; +} + +void NetworkManager::TeamSetting::setInterfaceName(const QString &name) +{ + Q_D(TeamSetting); + + d->interfaceName = name; +} + +QString NetworkManager::TeamSetting::interfaceName() const +{ + Q_D(const TeamSetting); + + return d->interfaceName; +} + +QString NetworkManager::TeamSetting::config() const +{ + Q_D(const TeamSetting); + return d->config; +} + +void NetworkManager::TeamSetting::setConfig(const QString &config) +{ + Q_D(TeamSetting); + d->config = config; +} + +void NetworkManager::TeamSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_TEAM_INTERFACE_NAME))) { + setInterfaceName(setting.value(QLatin1String(NM_SETTING_TEAM_INTERFACE_NAME)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_CONFIG))) { + setConfig(setting.value(QLatin1String(NM_SETTING_TEAM_CONFIG)).toString()); + } +} + +QVariantMap NetworkManager::TeamSetting::toMap() const +{ + QVariantMap setting; + + if (!interfaceName().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_TEAM_INTERFACE_NAME), interfaceName()); + } + if (!config().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_TEAM_CONFIG), config()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TeamSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_TEAM_INTERFACE_NAME << ": " << setting.interfaceName() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_CONFIG << ": " << setting.config() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/teamsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/teamsetting.h new file mode 100644 index 000000000..ba4f422d1 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/teamsetting.h @@ -0,0 +1,55 @@ +/* + SPDX-FileCopyrightText: 2014 Lukáš Tinkl + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TEAM_SETTING_H +#define NETWORKMANAGERQT_TEAM_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class TeamSettingPrivate; + +/** + * Represents team setting + */ +class NETWORKMANAGERQT_EXPORT TeamSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + TeamSetting(); + explicit TeamSetting(const Ptr &other); + ~TeamSetting() override; + + QString name() const override; + + /// @deprecated in favor of connection.interface-name in NM 1.0.0 + void setInterfaceName(const QString &name); + QString interfaceName() const; + + QString config() const; + void setConfig(const QString &config); + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + TeamSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(TeamSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const TeamSetting &setting); + +} + +#endif // NETWORKMANAGERQT_TEAM_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/teamsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/teamsetting_p.h new file mode 100644 index 000000000..65e6b7a63 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/teamsetting_p.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2014 Lukáš Tinkl + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TEAM_SETTING_P_H +#define NETWORKMANAGERQT_TEAM_SETTING_P_H + +#include + +namespace NetworkManager +{ +class TeamSettingPrivate +{ +public: + TeamSettingPrivate(); + + QString name; + QString interfaceName; + QString config; +}; + +} + +#endif // NETWORKMANAGERQT_TEAM_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/template.cpp b/panels/dock/tray/networkmanager-qt/src/settings/template.cpp new file mode 100644 index 000000000..6f7dfd49f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/template.cpp @@ -0,0 +1,79 @@ +/* + SPDX-FileCopyrightText: 2012-2015 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "template.h" +#include "template_p.h" + +// TODO: Uncomment and replace the template with the setting that you want to implement +//#include + +NetworkManager::TemplateSettingPrivate::TemplateSettingPrivate() +// : name(NM_SETTING_TEMPLATE_SETTING_NAME) +{ +} + +NetworkManager::TemplateSetting::TemplateSetting() + : /* TODO: Uncomment and replace the template with the setting that you want to implement + * This setting must also be added into the enum in base class + */ + // Setting(Setting::Template), + d_ptr(new TemplateSettingPrivate()) +{ +} + +NetworkManager::TemplateSetting::TemplateSetting(const Ptr &other) + : Setting(other) + , d_ptr(new TemplateSettingPrivate()) +{ + /* + * setFoo(setting->foo()); + * + */ +} + +NetworkManager::TemplateSetting::~TemplateSetting() +{ + delete d_ptr; +} + +QString NetworkManager::TemplateSetting::name() const +{ + Q_D(const TemplateSetting); + + return d->name; +} + +void NetworkManager::TemplateSetting::fromMap(const QVariantMap &setting) +{ + /* + * if (setting.contains(QLatin1String(NM_SETTING_TEMPLATE_FOO))) { + * setFoo(setting.value(QLatin1String(NM_SETTING_TEMPLATE_FOO))); + * } + * + */ +} + +QVariantMap NetworkManager::TemplateSetting::toMap() const +{ + QVariantMap setting; + + /* + * if (!foo.isEmpty()) { + * setting.insert(QLatin1String(NM_SETTING_TEMPLATE_FOO), foo()); + * } + * + */ + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TemplateSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/template.h b/panels/dock/tray/networkmanager-qt/src/settings/template.h new file mode 100644 index 000000000..f379ce235 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/template.h @@ -0,0 +1,48 @@ +/* + SPDX-FileCopyrightText: 2012-2015 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TEMPLATE_SETTING_H +#define NETWORKMANAGERQT_TEMPLATE_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class TemplateSettingPrivate; + +/** + * Represents generic setting + */ +class NETWORKMANAGERQT_EXPORT TemplateSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + TemplateSetting(); + explicit TemplateSetting(const Ptr &other); + ~TemplateSetting() override; + + QString name() const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + TemplateSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(TemplateSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const TemplateSetting &setting); + +} + +#endif // NETWORKMANAGERQT_TEMPLATE_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/template_p.h b/panels/dock/tray/networkmanager-qt/src/settings/template_p.h new file mode 100644 index 000000000..d18487a48 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/template_p.h @@ -0,0 +1,24 @@ +/* + SPDX-FileCopyrightText: 2012-2015 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TEMPLATE_SETTING_P_H +#define NETWORKMANAGERQT_TEMPLATE_SETTING_P_H + +#include + +namespace NetworkManager +{ +class TemplateSettingPrivate +{ +public: + TemplateSettingPrivate(); + + QString name; +}; + +} + +#endif // NETWORKMANAGERQT_TEMPLATE_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/tunsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/tunsetting.cpp new file mode 100644 index 000000000..8f7b86811 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/tunsetting.cpp @@ -0,0 +1,196 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "tunsetting.h" +#include "tunsetting_p.h" + +#include + +NetworkManager::TunSettingPrivate::TunSettingPrivate() + : name(NM_SETTING_TUN_SETTING_NAME) + , mode(TunSetting::Tun) + , multiQueue(false) + , pi(false) + , vnetHdr(false) +{ +} + +NetworkManager::TunSetting::TunSetting() + : Setting(Setting::Tun) + , d_ptr(new TunSettingPrivate()) +{ +} + +NetworkManager::TunSetting::TunSetting(const Ptr &other) + : Setting(other) + , d_ptr(new TunSettingPrivate()) +{ + setGroup(other->group()); + setMode(other->mode()); + setMultiQueue(other->multiQueue()); + setOwner(other->owner()); + setPi(other->pi()); + setVnetHdr(other->vnetHdr()); +} + +NetworkManager::TunSetting::~TunSetting() +{ + delete d_ptr; +} + +QString NetworkManager::TunSetting::name() const +{ + Q_D(const TunSetting); + + return d->name; +} + +void NetworkManager::TunSetting::setGroup(const QString &group) +{ + Q_D(TunSetting); + + d->group = group; +} + +QString NetworkManager::TunSetting::group() const +{ + Q_D(const TunSetting); + + return d->group; +} + +void NetworkManager::TunSetting::setMode(NetworkManager::TunSetting::Mode mode) +{ + Q_D(TunSetting); + + d->mode = mode; +} + +NetworkManager::TunSetting::Mode NetworkManager::TunSetting::mode() const +{ + Q_D(const TunSetting); + + return d->mode; +} + +void NetworkManager::TunSetting::setMultiQueue(bool multiQueue) +{ + Q_D(TunSetting); + + d->multiQueue = multiQueue; +} + +bool NetworkManager::TunSetting::multiQueue() const +{ + Q_D(const TunSetting); + + return d->multiQueue; +} + +void NetworkManager::TunSetting::setOwner(const QString &owner) +{ + Q_D(TunSetting); + + d->owner = owner; +} + +QString NetworkManager::TunSetting::owner() const +{ + Q_D(const TunSetting); + + return d->owner; +} + +void NetworkManager::TunSetting::setPi(bool pi) +{ + Q_D(TunSetting); + + d->pi = pi; +} + +bool NetworkManager::TunSetting::pi() const +{ + Q_D(const TunSetting); + + return d->pi; +} + +void NetworkManager::TunSetting::setVnetHdr(bool vnetHdr) +{ + Q_D(TunSetting); + + d->vnetHdr = vnetHdr; +} + +bool NetworkManager::TunSetting::vnetHdr() const +{ + Q_D(const TunSetting); + + return d->vnetHdr; +} + +void NetworkManager::TunSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_TUN_GROUP))) { + setGroup(setting.value(QLatin1String(NM_SETTING_TUN_GROUP)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TUN_MODE))) { + setMode((Mode)setting.value(QLatin1String(NM_SETTING_TUN_MODE)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TUN_MULTI_QUEUE))) { + setMultiQueue(setting.value(QLatin1String(NM_SETTING_TUN_MULTI_QUEUE)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TUN_OWNER))) { + setOwner(setting.value(QLatin1String(NM_SETTING_TUN_OWNER)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TUN_PI))) { + setPi(setting.value(QLatin1String(NM_SETTING_TUN_PI)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TUN_VNET_HDR))) { + setVnetHdr(setting.value(QLatin1String(NM_SETTING_TUN_VNET_HDR)).toBool()); + } +} + +QVariantMap NetworkManager::TunSetting::toMap() const +{ + QVariantMap setting; + + if (!group().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_TUN_GROUP), group()); + } + + setting.insert(QLatin1String(NM_SETTING_TUN_MODE), (int)mode()); + setting.insert(QLatin1String(NM_SETTING_TUN_MULTI_QUEUE), multiQueue()); + + if (!owner().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_TUN_OWNER), owner()); + } + + setting.insert(QLatin1String(NM_SETTING_TUN_PI), pi()); + setting.insert(QLatin1String(NM_SETTING_TUN_VNET_HDR), vnetHdr()); + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TunSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_TUN_GROUP << ": " << setting.group() << '\n'; + dbg.nospace() << NM_SETTING_TUN_MODE << ": " << setting.mode() << '\n'; + dbg.nospace() << NM_SETTING_TUN_MULTI_QUEUE << ": " << setting.multiQueue() << '\n'; + dbg.nospace() << NM_SETTING_TUN_OWNER << ": " << setting.owner() << '\n'; + dbg.nospace() << NM_SETTING_TUN_PI << ": " << setting.pi() << '\n'; + dbg.nospace() << NM_SETTING_TUN_VNET_HDR << ": " << setting.vnetHdr() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/tunsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/tunsetting.h new file mode 100644 index 000000000..968bee486 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/tunsetting.h @@ -0,0 +1,71 @@ +/* + SPDX-FileCopyrightText: 2016 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TUN_SETTING_H +#define NETWORKMANAGERQT_TUN_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class TunSettingPrivate; + +/** + * Represents generic setting + */ +class NETWORKMANAGERQT_EXPORT TunSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum Mode { + Tun, + Tap, + }; + + TunSetting(); + explicit TunSetting(const Ptr &other); + ~TunSetting() override; + + QString name() const override; + + void setGroup(const QString &group); + QString group() const; + + void setMode(Mode mode); + Mode mode() const; + + void setMultiQueue(bool multiQueue); + bool multiQueue() const; + + void setOwner(const QString &owner); + QString owner() const; + + void setPi(bool pi); + bool pi() const; + + void setVnetHdr(bool vnetHdr); + bool vnetHdr() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + TunSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(TunSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const TunSetting &setting); + +} + +#endif // NETWORKMANAGERQT_TUN_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/tunsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/tunsetting_p.h new file mode 100644 index 000000000..83be35ca0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/tunsetting_p.h @@ -0,0 +1,30 @@ +/* + SPDX-FileCopyrightText: 2016 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TUN_SETTING_P_H +#define NETWORKMANAGERQT_TUN_SETTING_P_H + +#include + +namespace NetworkManager +{ +class TunSettingPrivate +{ +public: + TunSettingPrivate(); + + QString name; + QString group; + NetworkManager::TunSetting::Mode mode; + bool multiQueue; + QString owner; + bool pi; + bool vnetHdr; +}; + +} + +#endif // NETWORKMANAGERQT_TUN_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/usersetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/usersetting.cpp new file mode 100644 index 000000000..8cca91be8 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/usersetting.cpp @@ -0,0 +1,94 @@ +/* + SPDX-FileCopyrightText: Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "usersetting.h" +#include "usersetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 8, 0) +#define NM_SETTING_USER_SETTING_NAME "user" +#define NM_SETTING_USER_DATA "data" +#endif + +NetworkManager::UserSettingPrivate::UserSettingPrivate() + : name(NM_SETTING_USER_SETTING_NAME) +{ +} + +NetworkManager::UserSetting::UserSetting() + : Setting(Setting::User) + , d_ptr(new UserSettingPrivate()) +{ +} + +NetworkManager::UserSetting::UserSetting(const Ptr &other) + : Setting(other) + , d_ptr(new UserSettingPrivate()) +{ + setData(other->data()); +} + +NetworkManager::UserSetting::~UserSetting() +{ + delete d_ptr; +} + +QString NetworkManager::UserSetting::name() const +{ + Q_D(const UserSetting); + + return d->name; +} + +void NetworkManager::UserSetting::addData(const QString &data, const QString &value) +{ + Q_D(UserSetting); + + d->data.insert(data, value); +} + +void NetworkManager::UserSetting::setData(const NMStringMap &data) +{ + Q_D(UserSetting); + + d->data = data; +} + +NMStringMap NetworkManager::UserSetting::data() const +{ + Q_D(const UserSetting); + + return d->data; +} + +void NetworkManager::UserSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_USER_DATA))) { + setData(qdbus_cast(setting.value(QLatin1String(NM_SETTING_USER_DATA)))); + } +} + +QVariantMap NetworkManager::UserSetting::toMap() const +{ + QVariantMap setting; + + if (!data().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_USER_DATA), QVariant::fromValue(data())); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::UserSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_USER_DATA << ": " << setting.data() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/usersetting.h b/panels/dock/tray/networkmanager-qt/src/settings/usersetting.h new file mode 100644 index 000000000..10f40a238 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/usersetting.h @@ -0,0 +1,53 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_USER_SETTING_H +#define NETWORKMANAGERQT_USER_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class UserSettingPrivate; + +/** + * Represents user setting + */ +class NETWORKMANAGERQT_EXPORT UserSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + UserSetting(); + explicit UserSetting(const Ptr &other); + ~UserSetting() override; + + QString name() const override; + + void addData(const QString &data, const QString &value); + void setData(const NMStringMap &data); + NMStringMap data() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + UserSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(UserSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const UserSetting &setting); + +} + +#endif // NETWORKMANAGERQT_USER_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/usersetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/usersetting_p.h new file mode 100644 index 000000000..b5f119cee --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/usersetting_p.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2018 Pranav Gade + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_USER_SETTING_P_H +#define NETWORKMANAGERQT_USER_SETTING_P_H + +#include + +namespace NetworkManager +{ +class UserSettingPrivate +{ +public: + UserSettingPrivate(); + + QString name; + + NMStringMap data; +}; + +} + +#endif // NETWORKMANAGERQT_USER_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vlansetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/vlansetting.cpp new file mode 100644 index 000000000..2dab2b918 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vlansetting.cpp @@ -0,0 +1,207 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "vlansetting.h" +#include "vlansetting_p.h" + +// define the deprecated&dropped values +#define NM_SETTING_VLAN_INTERFACE_NAME "interface-name" + +#include + +NetworkManager::VlanSettingPrivate::VlanSettingPrivate() + : name(NM_SETTING_VLAN_SETTING_NAME) + , id(0) + , flags(VlanSetting::None) +{ +} + +NetworkManager::VlanSetting::VlanSetting() + : Setting(Setting::Vlan) + , d_ptr(new VlanSettingPrivate()) +{ +} + +NetworkManager::VlanSetting::VlanSetting(const Ptr &other) + : Setting(other) + , d_ptr(new VlanSettingPrivate()) +{ + setInterfaceName(other->interfaceName()); + setParent(other->parent()); + setId(other->id()); + setFlags(other->flags()); + setIngressPriorityMap(other->ingressPriorityMap()); + setEgressPriorityMap(other->egressPriorityMap()); +} + +NetworkManager::VlanSetting::~VlanSetting() +{ + delete d_ptr; +} + +QString NetworkManager::VlanSetting::name() const +{ + Q_D(const VlanSetting); + + return d->name; +} + +void NetworkManager::VlanSetting::setInterfaceName(const QString &name) +{ + Q_D(VlanSetting); + + d->interfaceName = name; +} + +QString NetworkManager::VlanSetting::interfaceName() const +{ + Q_D(const VlanSetting); + + return d->interfaceName; +} + +void NetworkManager::VlanSetting::setParent(const QString &parent) +{ + Q_D(VlanSetting); + + d->parent = parent; +} + +QString NetworkManager::VlanSetting::parent() const +{ + Q_D(const VlanSetting); + + return d->parent; +} + +void NetworkManager::VlanSetting::setId(quint32 id) +{ + Q_D(VlanSetting); + + d->id = id; +} + +quint32 NetworkManager::VlanSetting::id() const +{ + Q_D(const VlanSetting); + + return d->id; +} + +void NetworkManager::VlanSetting::setFlags(NetworkManager::VlanSetting::Flags flags) +{ + Q_D(VlanSetting); + + d->flags = flags; +} + +NetworkManager::VlanSetting::Flags NetworkManager::VlanSetting::flags() const +{ + Q_D(const VlanSetting); + + return d->flags; +} + +void NetworkManager::VlanSetting::setIngressPriorityMap(const QStringList &map) +{ + Q_D(VlanSetting); + + d->ingressPriorityMap = map; +} + +QStringList NetworkManager::VlanSetting::ingressPriorityMap() const +{ + Q_D(const VlanSetting); + + return d->ingressPriorityMap; +} + +void NetworkManager::VlanSetting::setEgressPriorityMap(const QStringList &map) +{ + Q_D(VlanSetting); + + d->egressPriorityMap = map; +} + +QStringList NetworkManager::VlanSetting::egressPriorityMap() const +{ + Q_D(const VlanSetting); + + return d->egressPriorityMap; +} + +void NetworkManager::VlanSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_VLAN_INTERFACE_NAME))) { + setInterfaceName(setting.value(QLatin1String(NM_SETTING_VLAN_INTERFACE_NAME)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VLAN_PARENT))) { + setParent(setting.value(QLatin1String(NM_SETTING_VLAN_PARENT)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VLAN_ID))) { + setId(setting.value(QLatin1String(NM_SETTING_VLAN_ID)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VLAN_FLAGS))) { + setFlags((Flag)setting.value(QLatin1String(NM_SETTING_VLAN_FLAGS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VLAN_INGRESS_PRIORITY_MAP))) { + setIngressPriorityMap(setting.value(QLatin1String(NM_SETTING_VLAN_INGRESS_PRIORITY_MAP)).toStringList()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VLAN_EGRESS_PRIORITY_MAP))) { + setEgressPriorityMap(setting.value(QLatin1String(NM_SETTING_VLAN_EGRESS_PRIORITY_MAP)).toStringList()); + } +} + +QVariantMap NetworkManager::VlanSetting::toMap() const +{ + QVariantMap setting; + + if (!interfaceName().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VLAN_INTERFACE_NAME), interfaceName()); + } + + if (!parent().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VLAN_PARENT), parent()); + } + + if (id()) { + setting.insert(QLatin1String(NM_SETTING_VLAN_ID), id()); + } + + if (flags() != None) { + setting.insert(QLatin1String(NM_SETTING_VLAN_FLAGS), (int)flags()); + } + + if (!ingressPriorityMap().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VLAN_INGRESS_PRIORITY_MAP), ingressPriorityMap()); + } + + if (!egressPriorityMap().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VLAN_EGRESS_PRIORITY_MAP), egressPriorityMap()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::VlanSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_VLAN_INTERFACE_NAME << ": " << setting.interfaceName() << '\n'; + dbg.nospace() << NM_SETTING_VLAN_PARENT << ": " << setting.parent() << '\n'; + dbg.nospace() << NM_SETTING_VLAN_ID << ": " << setting.id() << '\n'; + dbg.nospace() << NM_SETTING_VLAN_FLAGS << ": " << setting.flags() << '\n'; + dbg.nospace() << NM_SETTING_VLAN_INGRESS_PRIORITY_MAP << ": " << setting.ingressPriorityMap() << '\n'; + dbg.nospace() << NM_SETTING_VLAN_EGRESS_PRIORITY_MAP << ": " << setting.egressPriorityMap() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vlansetting.h b/panels/dock/tray/networkmanager-qt/src/settings/vlansetting.h new file mode 100644 index 000000000..c733ec8d9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vlansetting.h @@ -0,0 +1,76 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VLAN_SETTING_H +#define NETWORKMANAGERQT_VLAN_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class VlanSettingPrivate; + +/** + * Represents vlan setting + */ +class NETWORKMANAGERQT_EXPORT VlanSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum Flag { + None = 0, + ReorderHeaders = 0x1, + Gvrp = 0x2, + LooseBinding = 0x4, + }; + Q_DECLARE_FLAGS(Flags, Flag) + + VlanSetting(); + explicit VlanSetting(const Ptr &other); + ~VlanSetting() override; + + QString name() const override; + + /// @deprecated in favor of connection.interface-name in NM 1.0.0 + void setInterfaceName(const QString &name); + QString interfaceName() const; + + void setParent(const QString &parent); + QString parent() const; + + void setId(quint32 id); + quint32 id() const; + + void setFlags(Flags flags); + Flags flags() const; + + void setIngressPriorityMap(const QStringList &map); + QStringList ingressPriorityMap() const; + + void setEgressPriorityMap(const QStringList &map); + QStringList egressPriorityMap() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + VlanSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(VlanSetting) +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(VlanSetting::Flags) + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const VlanSetting &setting); + +} + +#endif // NETWORKMANAGERQT_VLAN_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vlansetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/vlansetting_p.h new file mode 100644 index 000000000..e159cc93e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vlansetting_p.h @@ -0,0 +1,30 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VLAN_SETTING_P_H +#define NETWORKMANAGERQT_VLAN_SETTING_P_H + +#include + +namespace NetworkManager +{ +class VlanSettingPrivate +{ +public: + VlanSettingPrivate(); + + QString name; + QString interfaceName; + QString parent; + quint32 id; + NetworkManager::VlanSetting::Flags flags; + QStringList ingressPriorityMap; + QStringList egressPriorityMap; +}; + +} + +#endif // NETWORKMANAGERQT_VLAN_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting.cpp new file mode 100644 index 000000000..b0f24da71 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting.cpp @@ -0,0 +1,246 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "vpnsetting.h" +#include "nmdebug.h" +#include "vpnsetting_p.h" + +NetworkManager::VpnSettingPrivate::VpnSettingPrivate() + : name(NM_SETTING_VPN_SETTING_NAME) + , persistent(false) + , timeout(0) +{ +} + +NetworkManager::VpnSetting::VpnSetting() + : Setting(Setting::Vpn) + , d_ptr(new VpnSettingPrivate()) +{ +} + +NetworkManager::VpnSetting::VpnSetting(const Ptr &other) + : Setting(other) + , d_ptr(new VpnSettingPrivate()) +{ + setServiceType(other->serviceType()); + setUsername(other->username()); + setData(other->data()); + setSecrets(other->secrets()); + setPersistent(other->persistent()); + setTimeout(other->timeout()); +} + +NetworkManager::VpnSetting::~VpnSetting() +{ + delete d_ptr; +} + +QString NetworkManager::VpnSetting::name() const +{ + Q_D(const VpnSetting); + + return d->name; +} + +bool NetworkManager::VpnSetting::persistent() const +{ + Q_D(const VpnSetting); + + return d->persistent; +} + +void NetworkManager::VpnSetting::setPersistent(bool persistent) +{ + Q_D(VpnSetting); + + d->persistent = persistent; +} + +uint NetworkManager::VpnSetting::timeout() const +{ + Q_D(const VpnSetting); + + return d->timeout; +} + +void NetworkManager::VpnSetting::setTimeout(uint timeout) +{ + Q_D(VpnSetting); + + d->timeout = timeout; +} + +void NetworkManager::VpnSetting::setServiceType(const QString &type) +{ + Q_D(VpnSetting); + + d->serviceType = type; +} + +QString NetworkManager::VpnSetting::serviceType() const +{ + Q_D(const VpnSetting); + + return d->serviceType; +} + +void NetworkManager::VpnSetting::setUsername(const QString &username) +{ + Q_D(VpnSetting); + + d->username = username; +} + +QString NetworkManager::VpnSetting::username() const +{ + Q_D(const VpnSetting); + + return d->username; +} + +void NetworkManager::VpnSetting::setData(const NMStringMap &data) +{ + Q_D(VpnSetting); + + d->data = data; +} + +NMStringMap NetworkManager::VpnSetting::data() const +{ + Q_D(const VpnSetting); + + return d->data; +} + +void NetworkManager::VpnSetting::setSecrets(const NMStringMap &secrets) +{ + Q_D(VpnSetting); + + d->secrets = secrets; +} + +NMStringMap NetworkManager::VpnSetting::secrets() const +{ + Q_D(const VpnSetting); + + return d->secrets; +} + +void NetworkManager::VpnSetting::secretsFromMap(const QVariantMap &secrets) +{ + if (secrets.contains(QLatin1String(NM_SETTING_VPN_SECRETS))) { + setSecrets(qdbus_cast(secrets.value(QLatin1String(NM_SETTING_VPN_SECRETS)))); + } +} + +QVariantMap NetworkManager::VpnSetting::secretsToMap() const +{ + QVariantMap secretsMap; + if (!secrets().isEmpty()) { + secretsMap.insert(QLatin1String(NM_SETTING_VPN_SECRETS), QVariant::fromValue(secrets())); + } + + // qCDebug(NMQT) << secretsMap; + return secretsMap; +} + +void NetworkManager::VpnSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_VPN_SERVICE_TYPE))) { + setServiceType(setting.value(QLatin1String(NM_SETTING_VPN_SERVICE_TYPE)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VPN_USER_NAME))) { + setUsername(setting.value(QLatin1String(NM_SETTING_VPN_USER_NAME)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VPN_DATA))) { + setData(qdbus_cast(setting.value(QLatin1String(NM_SETTING_VPN_DATA)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_VPN_SECRETS))) { + setSecrets(qdbus_cast(setting.value(QLatin1String(NM_SETTING_VPN_SECRETS)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_VPN_PERSISTENT))) { + setPersistent(setting.value(QLatin1String(NM_SETTING_VPN_PERSISTENT)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VPN_TIMEOUT))) { + setTimeout(setting.value(QLatin1String(NM_SETTING_VPN_TIMEOUT)).toUInt()); + } +} + +QVariantMap NetworkManager::VpnSetting::toMap() const +{ + QVariantMap setting; + + if (!serviceType().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VPN_SERVICE_TYPE), serviceType()); + } + + if (!username().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VPN_USER_NAME), username()); + } + + if (!data().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VPN_DATA), QVariant::fromValue(data())); + } + + if (!secrets().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VPN_SECRETS), QVariant::fromValue(secrets())); + } + + setting.insert(QLatin1String(NM_SETTING_VPN_PERSISTENT), persistent()); + setting.insert(QLatin1String(NM_SETTING_VPN_TIMEOUT), timeout()); + + return setting; +} + +void NetworkManager::VpnSetting::secretsFromStringMap(const NMStringMap &map) +{ + Q_D(VpnSetting); + + if (map.contains(QLatin1String("VpnSecrets"))) { + const QStringList list = map.value(QLatin1String("VpnSecrets")).split("%SEP%"); + if (list.count() % 2 == 0) { + for (int i = 0; i < list.count(); i += 2) { + if (d->secrets.contains(list[i])) { + d->secrets.remove(list[i]); + } + d->secrets.insert(list[i], list[i + 1]); + } + } + } +} + +NMStringMap NetworkManager::VpnSetting::secretsToStringMap() const +{ + NMStringMap ret; + QStringList list; + QMap::ConstIterator i = secrets().constBegin(); + while (i != secrets().constEnd()) { + list << i.key() << i.value(); + ++i; + } + + ret.insert(QLatin1String("VpnSecrets"), list.join("%SEP%")); + return ret; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::VpnSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_VPN_SERVICE_TYPE << ": " << setting.serviceType() << '\n'; + dbg.nospace() << NM_SETTING_VPN_USER_NAME << ": " << setting.username() << '\n'; + dbg.nospace() << NM_SETTING_VPN_DATA << ": " << setting.data() << '\n'; + dbg.nospace() << NM_SETTING_VPN_PERSISTENT << ": " << setting.persistent() << '\n'; + dbg.nospace() << NM_SETTING_VPN_TIMEOUT << ": " << setting.timeout() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting.h new file mode 100644 index 000000000..5dda6f15c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting.h @@ -0,0 +1,72 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VPN_SETTING_H +#define NETWORKMANAGERQT_VPN_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class VpnSettingPrivate; + +/** + * Represents vpn setting + */ +class NETWORKMANAGERQT_EXPORT VpnSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + VpnSetting(); + explicit VpnSetting(const Ptr &other); + ~VpnSetting() override; + + QString name() const override; + + bool persistent() const; + void setPersistent(bool persistent); + + void setServiceType(const QString &type); + QString serviceType() const; + + uint timeout() const; + void setTimeout(uint timeout); + + void setUsername(const QString &username); + QString username() const; + + void setData(const NMStringMap &data); + NMStringMap data() const; + + void setSecrets(const NMStringMap &secrets); + NMStringMap secrets() const; + + void secretsFromMap(const QVariantMap &secrets) override; + QVariantMap secretsToMap() const override; + + void secretsFromStringMap(const NMStringMap &map) override; + NMStringMap secretsToStringMap() const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + VpnSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(VpnSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const VpnSetting &setting); + +} + +#endif // NETWORKMANAGERQT_VPN_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting_p.h new file mode 100644 index 000000000..65fdd3dcc --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vpnsetting_p.h @@ -0,0 +1,32 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VPN_SETTING_P_H +#define NETWORKMANAGERQT_VPN_SETTING_P_H + +#include "generictypes.h" + +#include + +namespace NetworkManager +{ +class VpnSettingPrivate +{ +public: + VpnSettingPrivate(); + + QString name; + QString serviceType; + QString username; + NMStringMap data; + NMStringMap secrets; + bool persistent; + uint timeout; +}; + +} + +#endif // NETWORKMANAGERQT_VPN_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting.cpp new file mode 100644 index 000000000..c6142c36c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting.cpp @@ -0,0 +1,454 @@ +/* + SPDX-FileCopyrightText: 2018 Billy Laws + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "vxlansetting.h" +#include "vxlansetting_p.h" + +#include + +NetworkManager::VxlanSettingPrivate::VxlanSettingPrivate() + : name(NM_SETTING_VXLAN_SETTING_NAME) + , ageing(32) + , destinationPort(8472) + , id(0) + , l2Miss(false) + , l3Miss(false) + , learning(true) + , limit(0) + , proxy(false) + , rsc(false) + , sourcePortMax(0) + , sourcePortMin(0) + , tos(0) + , ttl(0) +{ +} + +NetworkManager::VxlanSetting::VxlanSetting() + : Setting(Setting::Vxlan) + , d_ptr(new VxlanSettingPrivate()) +{ +} + +NetworkManager::VxlanSetting::VxlanSetting(const NetworkManager::VxlanSetting::Ptr &other) + : Setting(other) + , d_ptr(new VxlanSettingPrivate()) +{ + setAgeing(other->ageing()); + setDestinationPort(other->destinationPort()); + setId(other->id()); + setL2Miss(other->l2Miss()); + setL3Miss(other->l3Miss()); + setLearning(other->learning()); + setLimit(other->limit()); + setLocal(other->local()); + setParent(other->parent()); + setProxy(other->proxy()); + setRemote(other->remote()); + setRsc(other->rsc()); + setSourcePortMax(other->sourcePortMax()); + setSourcePortMin(other->sourcePortMin()); + setTos(other->tos()); + setTtl(other->ttl()); +} + +NetworkManager::VxlanSetting::~VxlanSetting() +{ + delete d_ptr; +} + +QString NetworkManager::VxlanSetting::name() const +{ + Q_D(const VxlanSetting); + + return d->name; +} + +void NetworkManager::VxlanSetting::setAgeing(quint32 ageing) +{ + Q_D(VxlanSetting); + + d->ageing = ageing; +} + +quint32 NetworkManager::VxlanSetting::ageing() const +{ + Q_D(const VxlanSetting); + + return d->ageing; +} + +void NetworkManager::VxlanSetting::setDestinationPort(quint32 port) +{ + Q_D(VxlanSetting); + + d->destinationPort = port; +} + +quint32 NetworkManager::VxlanSetting::destinationPort() const +{ + Q_D(const VxlanSetting); + + return d->destinationPort; +} + +void NetworkManager::VxlanSetting::setId(quint32 id) +{ + Q_D(VxlanSetting); + + d->id = id; +} + +quint32 NetworkManager::VxlanSetting::id() const +{ + Q_D(const VxlanSetting); + + return d->id; +} + +void NetworkManager::VxlanSetting::setL2Miss(bool enable) +{ + Q_D(VxlanSetting); + + d->l2Miss = enable; +} + +bool NetworkManager::VxlanSetting::l2Miss() const +{ + Q_D(const VxlanSetting); + + return d->l2Miss; +} + +void NetworkManager::VxlanSetting::setL3Miss(bool enable) +{ + Q_D(VxlanSetting); + + d->l3Miss = enable; +} + +bool NetworkManager::VxlanSetting::l3Miss() const +{ + Q_D(const VxlanSetting); + + return d->l3Miss; +} + +void NetworkManager::VxlanSetting::setLearning(bool enable) +{ + Q_D(VxlanSetting); + + d->learning = enable; +} + +bool NetworkManager::VxlanSetting::learning() const +{ + Q_D(const VxlanSetting); + + return d->learning; +} + +void NetworkManager::VxlanSetting::setLimit(quint32 limit) +{ + Q_D(VxlanSetting); + + d->limit = limit; +} + +quint32 NetworkManager::VxlanSetting::limit() const +{ + Q_D(const VxlanSetting); + + return d->limit; +} + +void NetworkManager::VxlanSetting::setLocal(QString local) +{ + Q_D(VxlanSetting); + + d->local = local; +} + +QString NetworkManager::VxlanSetting::local() const +{ + Q_D(const VxlanSetting); + + return d->local; +} + +void NetworkManager::VxlanSetting::setParent(QString parent) +{ + Q_D(VxlanSetting); + + d->parent = parent; +} + +QString NetworkManager::VxlanSetting::parent() const +{ + Q_D(const VxlanSetting); + + return d->parent; +} + +void NetworkManager::VxlanSetting::setProxy(bool enable) +{ + Q_D(VxlanSetting); + + d->proxy = enable; +} + +bool NetworkManager::VxlanSetting::proxy() const +{ + Q_D(const VxlanSetting); + + return d->proxy; +} + +void NetworkManager::VxlanSetting::setRemote(QString remote) +{ + Q_D(VxlanSetting); + + d->remote = remote; +} + +QString NetworkManager::VxlanSetting::remote() const +{ + Q_D(const VxlanSetting); + + return d->remote; +} + +void NetworkManager::VxlanSetting::setRsc(bool enable) +{ + Q_D(VxlanSetting); + + d->rsc = enable; +} + +bool NetworkManager::VxlanSetting::rsc() const +{ + Q_D(const VxlanSetting); + + return d->rsc; +} + +void NetworkManager::VxlanSetting::setSourcePortMax(quint32 maxPort) +{ + Q_D(VxlanSetting); + + d->sourcePortMax = maxPort; +} + +quint32 NetworkManager::VxlanSetting::sourcePortMax() const +{ + Q_D(const VxlanSetting); + + return d->sourcePortMax; +} + +void NetworkManager::VxlanSetting::setSourcePortMin(quint32 minPort) +{ + Q_D(VxlanSetting); + + d->sourcePortMin = minPort; +} + +quint32 NetworkManager::VxlanSetting::sourcePortMin() const +{ + Q_D(const VxlanSetting); + + return d->sourcePortMin; +} + +void NetworkManager::VxlanSetting::setTos(quint32 tos) +{ + Q_D(VxlanSetting); + + d->tos = tos; +} + +quint32 NetworkManager::VxlanSetting::tos() const +{ + Q_D(const VxlanSetting); + + return d->tos; +} + +void NetworkManager::VxlanSetting::setTtl(quint32 ttl) +{ + Q_D(VxlanSetting); + + d->ttl = ttl; +} + +quint32 NetworkManager::VxlanSetting::ttl() const +{ + Q_D(const VxlanSetting); + + return d->ttl; +} +void NetworkManager::VxlanSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_AGEING))) { + setAgeing(setting.value(QLatin1String(NM_SETTING_VXLAN_AGEING)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT))) { + setDestinationPort(setting.value(QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_ID))) { + setId(setting.value(QLatin1String(NM_SETTING_VXLAN_ID)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_L2_MISS))) { + setL2Miss(setting.value(QLatin1String(NM_SETTING_VXLAN_L2_MISS)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_L3_MISS))) { + setL3Miss(setting.value(QLatin1String(NM_SETTING_VXLAN_L3_MISS)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_LEARNING))) { + setLearning(setting.value(QLatin1String(NM_SETTING_VXLAN_LEARNING)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_LIMIT))) { + setLimit(setting.value(QLatin1String(NM_SETTING_VXLAN_LIMIT)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_LOCAL))) { + setLocal(setting.value(QLatin1String(NM_SETTING_VXLAN_LOCAL)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_PARENT))) { + setParent(setting.value(QLatin1String(NM_SETTING_VXLAN_PARENT)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_PROXY))) { + setProxy(setting.value(QLatin1String(NM_SETTING_VXLAN_PROXY)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_REMOTE))) { + setRemote(setting.value(QLatin1String(NM_SETTING_VXLAN_REMOTE)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_RSC))) { + setRsc(setting.value(QLatin1String(NM_SETTING_VXLAN_RSC)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX))) { + setSourcePortMax(setting.value(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN))) { + setSourcePortMin(setting.value(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_TOS))) { + setTos(setting.value(QLatin1String(NM_SETTING_VXLAN_TOS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_TTL))) { + setTtl(setting.value(QLatin1String(NM_SETTING_VXLAN_TTL)).toUInt()); + } +} + +QVariantMap NetworkManager::VxlanSetting::toMap() const +{ + QVariantMap setting; + + if (ageing() != 32) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_AGEING), ageing()); + } + + if (destinationPort() != 8472) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT), destinationPort()); + } + + if (id()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_ID), id()); + } + + if (l2Miss()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_L2_MISS), l2Miss()); + } + + if (l3Miss()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_L3_MISS), l3Miss()); + } + + if (!learning()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_LEARNING), learning()); + } + + if (limit()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_LIMIT), limit()); + } + + if (!local().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_LOCAL), local()); + } + + if (!parent().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_PARENT), parent()); + } + + if (proxy()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_PROXY), proxy()); + } + + if (!remote().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_REMOTE), remote()); + } + + if (rsc()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_RSC), rsc()); + } + + if (sourcePortMax()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX), sourcePortMax()); + } + + if (sourcePortMin()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN), sourcePortMin()); + } + + if (tos()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_TOS), tos()); + } + + if (ttl()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_TTL), ttl()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::VxlanSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_VXLAN_AGEING << ": " << setting.ageing() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_DESTINATION_PORT << ": " << setting.destinationPort() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_ID << ": " << setting.id() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_L2_MISS << ": " << setting.l2Miss() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_L3_MISS << ": " << setting.l3Miss() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_LEARNING << ": " << setting.learning() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_LIMIT << ": " << setting.limit() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_LOCAL << ": " << setting.local() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_PARENT << ": " << setting.parent() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_PROXY << ": " << setting.proxy() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_REMOTE << ": " << setting.remote() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_RSC << ": " << setting.rsc() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_SOURCE_PORT_MAX << ": " << setting.sourcePortMax() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_SOURCE_PORT_MIN << ": " << setting.sourcePortMin() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_TOS << ": " << setting.tos() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_TTL << ": " << setting.ttl() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting.h b/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting.h new file mode 100644 index 000000000..e4805b151 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting.h @@ -0,0 +1,96 @@ +/* + SPDX-FileCopyrightText: 2018 Billy Laws + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VXLAN_SETTING_H +#define NETWORKMANAGERQT_VXLAN_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class VxlanSettingPrivate; + +/** + * Represents vxlan setting + */ +class NETWORKMANAGERQT_EXPORT VxlanSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + VxlanSetting(); + explicit VxlanSetting(const Ptr &other); + ~VxlanSetting() override; + + QString name() const override; + + void setAgeing(quint32 ageing); + quint32 ageing() const; + + void setDestinationPort(quint32 port); + quint32 destinationPort() const; + + void setId(quint32 id); + quint32 id() const; + + void setL2Miss(bool enable); + bool l2Miss() const; + + void setL3Miss(bool enable); + bool l3Miss() const; + + void setLearning(bool enable); + bool learning() const; + + void setLimit(quint32 limit); + quint32 limit() const; + + void setLocal(QString local); + QString local() const; + + void setParent(QString parent); + QString parent() const; + + void setProxy(bool enable); + bool proxy() const; + + void setRemote(QString remote); + QString remote() const; + + void setRsc(bool enable); + bool rsc() const; + + void setSourcePortMax(quint32 maxPort); + quint32 sourcePortMax() const; + + void setSourcePortMin(quint32 minPort); + quint32 sourcePortMin() const; + + void setTos(quint32 tos); + quint32 tos() const; + + void setTtl(quint32 ttl); + quint32 ttl() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + VxlanSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(VxlanSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const VxlanSetting &setting); + +} + +#endif // NETWORKMANAGERQT_VXLAN_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting_p.h new file mode 100644 index 000000000..5be33baad --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/vxlansetting_p.h @@ -0,0 +1,40 @@ +/* + SPDX-FileCopyrightText: 2018 Billy Laws + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VXLAN_SETTING_P_H +#define NETWORKMANAGERQT_VXLAN_SETTING_P_H + +#include + +namespace NetworkManager +{ +class VxlanSettingPrivate +{ +public: + VxlanSettingPrivate(); + + QString name; + quint32 ageing; + quint32 destinationPort; + quint32 id; + bool l2Miss; + bool l3Miss; + bool learning; + quint32 limit; + QString local; + QString parent; + bool proxy; + QString remote; + bool rsc; + quint32 sourcePortMax; + quint32 sourcePortMin; + quint32 tos; + quint32 ttl; +}; + +} + +#endif // NETWORKMANAGERQT_VXLAN_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting.cpp new file mode 100644 index 000000000..b14962e4f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting.cpp @@ -0,0 +1,107 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wimaxsetting.h" +#include "wimaxsetting_p.h" + +#include + +NetworkManager::WimaxSettingPrivate::WimaxSettingPrivate() + : name(NM_SETTING_WIMAX_SETTING_NAME) +{ +} + +NetworkManager::WimaxSetting::WimaxSetting() + : Setting(Setting::Wimax) + , d_ptr(new WimaxSettingPrivate()) +{ +} + +NetworkManager::WimaxSetting::WimaxSetting(const Ptr &other) + : Setting(other) + , d_ptr(new WimaxSettingPrivate()) +{ + setNetworkName(other->networkName()); + setMacAddress(other->macAddress()); +} + +NetworkManager::WimaxSetting::~WimaxSetting() +{ + delete d_ptr; +} + +QString NetworkManager::WimaxSetting::name() const +{ + Q_D(const WimaxSetting); + + return d->name; +} + +void NetworkManager::WimaxSetting::setNetworkName(const QString &name) +{ + Q_D(WimaxSetting); + + d->networkName = name; +} + +QString NetworkManager::WimaxSetting::networkName() const +{ + Q_D(const WimaxSetting); + + return d->networkName; +} + +void NetworkManager::WimaxSetting::setMacAddress(const QByteArray &address) +{ + Q_D(WimaxSetting); + + d->macAddress = address; +} + +QByteArray NetworkManager::WimaxSetting::macAddress() const +{ + Q_D(const WimaxSetting); + + return d->macAddress; +} + +void NetworkManager::WimaxSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_WIMAX_NETWORK_NAME))) { + setNetworkName(setting.value(QLatin1String(NM_SETTING_WIMAX_NETWORK_NAME)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIMAX_MAC_ADDRESS))) { + setMacAddress(setting.value(QLatin1String(NM_SETTING_WIMAX_MAC_ADDRESS)).toByteArray()); + } +} + +QVariantMap NetworkManager::WimaxSetting::toMap() const +{ + QVariantMap setting; + + if (!networkName().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIMAX_NETWORK_NAME), networkName()); + } + + if (!macAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIMAX_MAC_ADDRESS), macAddress()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::WimaxSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_WIMAX_NETWORK_NAME << ": " << setting.networkName() << '\n'; + dbg.nospace() << NM_SETTING_WIMAX_MAC_ADDRESS << ": " << setting.macAddress() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting.h new file mode 100644 index 000000000..bd3ca2d73 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting.h @@ -0,0 +1,55 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIMAX_SETTING_H +#define NETWORKMANAGERQT_WIMAX_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class WimaxSettingPrivate; + +/** + * Represents wimax setting + */ +class NETWORKMANAGERQT_EXPORT WimaxSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + WimaxSetting(); + explicit WimaxSetting(const Ptr &other); + ~WimaxSetting() override; + + QString name() const override; + + void setNetworkName(const QString &name); + QString networkName() const; + + void setMacAddress(const QByteArray &address); + QByteArray macAddress() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + WimaxSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(WimaxSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const WimaxSetting &setting); + +} + +#endif // NETWORKMANAGERQT_WIMAX_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting_p.h new file mode 100644 index 000000000..37c212c7b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wimaxsetting_p.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIMAX_SETTING_P_H +#define NETWORKMANAGERQT_WIMAX_SETTING_P_H + +#include + +namespace NetworkManager +{ +class WimaxSettingPrivate +{ +public: + WimaxSettingPrivate(); + + QString name; + QString networkName; + QByteArray macAddress; +}; + +} + +#endif // NETWORKMANAGERQT_WIMAX_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting.cpp new file mode 100644 index 000000000..a2eee9d5c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting.cpp @@ -0,0 +1,488 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wiredsetting.h" +#include "manager.h" +#include "wiredsetting_p.h" + +#include + +#define NM_SETTING_WIRED_ASSIGNED_MAC_ADDRESS "assigned-mac-address" + +NetworkManager::WiredSettingPrivate::WiredSettingPrivate() + : name(NM_SETTING_WIRED_SETTING_NAME) + , port(NetworkManager::WiredSetting::UnknownPort) + , speed(0) + , duplex(NetworkManager::WiredSetting::UnknownDuplexType) + , mtu(0) + , s390NetType(NetworkManager::WiredSetting::Undefined) + , wakeOnLan(NetworkManager::WiredSetting::WakeOnLanDefault) +{ + if (NetworkManager::checkVersion(1, 6, 0)) { + autoNegotiate = false; + } else { + autoNegotiate = true; + } +} + +NetworkManager::WiredSetting::WiredSetting() + : Setting(Setting::Wired) + , d_ptr(new WiredSettingPrivate()) +{ +} + +NetworkManager::WiredSetting::WiredSetting(const WiredSetting::Ptr &other) + : Setting(other) + , d_ptr(new WiredSettingPrivate()) +{ + setPort(other->port()); + setSpeed(other->speed()); + setDuplexType(other->duplexType()); + setAutoNegotiate(other->autoNegotiate()); + setGenerateMacAddressMask(other->generateMacAddressMask()); + setMacAddress(other->macAddress()); + setClonedMacAddress(other->clonedMacAddress()); + setMacAddressBlacklist(other->macAddressBlacklist()); + setMtu(other->mtu()); + setS390Subchannels(other->s390Subchannels()); + setS390NetType(other->s390NetType()); + setS390Options(other->s390Options()); + setWakeOnLan(other->wakeOnLan()); + setWakeOnLanPassword(other->wakeOnLanPassword()); + setAssignedMacAddress(other->assignedMacAddress()); +} + +NetworkManager::WiredSetting::~WiredSetting() +{ + delete d_ptr; +} + +QString NetworkManager::WiredSetting::name() const +{ + Q_D(const WiredSetting); + + return d->name; +} + +void NetworkManager::WiredSetting::setPort(NetworkManager::WiredSetting::PortType port) +{ + Q_D(WiredSetting); + + d->port = port; +} + +NetworkManager::WiredSetting::PortType NetworkManager::WiredSetting::port() const +{ + Q_D(const WiredSetting); + + return d->port; +} + +void NetworkManager::WiredSetting::setSpeed(quint32 speed) +{ + Q_D(WiredSetting); + + d->speed = speed; +} + +quint32 NetworkManager::WiredSetting::speed() const +{ + Q_D(const WiredSetting); + + return d->speed; +} + +void NetworkManager::WiredSetting::setDuplexType(NetworkManager::WiredSetting::DuplexType type) +{ + Q_D(WiredSetting); + + d->duplex = type; +} + +NetworkManager::WiredSetting::DuplexType NetworkManager::WiredSetting::duplexType() const +{ + Q_D(const WiredSetting); + + return d->duplex; +} + +void NetworkManager::WiredSetting::setAutoNegotiate(bool autoNegotiate) +{ + Q_D(WiredSetting); + + d->autoNegotiate = autoNegotiate; +} + +bool NetworkManager::WiredSetting::autoNegotiate() const +{ + Q_D(const WiredSetting); + + return d->autoNegotiate; +} + +QString NetworkManager::WiredSetting::generateMacAddressMask() const +{ + Q_D(const WiredSetting); + + return d->generateMacAddressMask; +} + +void NetworkManager::WiredSetting::setGenerateMacAddressMask(const QString &mask) +{ + Q_D(WiredSetting); + + d->generateMacAddressMask = mask; +} + +void NetworkManager::WiredSetting::setMacAddress(const QByteArray &address) +{ + Q_D(WiredSetting); + + d->macAddress = address; +} + +QByteArray NetworkManager::WiredSetting::macAddress() const +{ + Q_D(const WiredSetting); + + return d->macAddress; +} + +void NetworkManager::WiredSetting::setClonedMacAddress(const QByteArray &address) +{ + Q_D(WiredSetting); + + d->clonedMacAddress = address; +} + +QByteArray NetworkManager::WiredSetting::clonedMacAddress() const +{ + Q_D(const WiredSetting); + + return d->clonedMacAddress; +} + +void NetworkManager::WiredSetting::setMacAddressBlacklist(const QStringList &list) +{ + Q_D(WiredSetting); + + d->macAddressBlacklist = list; +} + +QStringList NetworkManager::WiredSetting::macAddressBlacklist() const +{ + Q_D(const WiredSetting); + + return d->macAddressBlacklist; +} + +void NetworkManager::WiredSetting::setMtu(quint32 mtu) +{ + Q_D(WiredSetting); + + d->mtu = mtu; +} + +quint32 NetworkManager::WiredSetting::mtu() const +{ + Q_D(const WiredSetting); + + return d->mtu; +} + +void NetworkManager::WiredSetting::setS390Subchannels(const QStringList &channels) +{ + Q_D(WiredSetting); + + d->s390Subchannels = channels; +} + +QStringList NetworkManager::WiredSetting::s390Subchannels() const +{ + Q_D(const WiredSetting); + + return d->s390Subchannels; +} + +void NetworkManager::WiredSetting::setS390NetType(NetworkManager::WiredSetting::S390Nettype type) +{ + Q_D(WiredSetting); + + d->s390NetType = type; +} + +NetworkManager::WiredSetting::S390Nettype NetworkManager::WiredSetting::s390NetType() const +{ + Q_D(const WiredSetting); + + return d->s390NetType; +} + +void NetworkManager::WiredSetting::setS390Options(const QMap &options) +{ + Q_D(WiredSetting); + + d->s390Options = options; +} + +QMap NetworkManager::WiredSetting::s390Options() const +{ + Q_D(const WiredSetting); + + return d->s390Options; +} + +NetworkManager::WiredSetting::WakeOnLanFlags NetworkManager::WiredSetting::wakeOnLan() const +{ + Q_D(const WiredSetting); + + return d->wakeOnLan; +} + +void NetworkManager::WiredSetting::setWakeOnLan(NetworkManager::WiredSetting::WakeOnLanFlags wol) +{ + Q_D(WiredSetting); + + d->wakeOnLan = wol; +} + +QString NetworkManager::WiredSetting::wakeOnLanPassword() const +{ + Q_D(const WiredSetting); + + return d->wakeOnLanPassword; +} + +void NetworkManager::WiredSetting::setWakeOnLanPassword(const QString &password) +{ + Q_D(WiredSetting); + + d->wakeOnLanPassword = password; +} + +void NetworkManager::WiredSetting::setAssignedMacAddress(const QString &assignedMacAddress) +{ + Q_D(WiredSetting); + + d->assignedMacAddress = assignedMacAddress; +} + +QString NetworkManager::WiredSetting::assignedMacAddress() const +{ + Q_D(const WiredSetting); + + return d->assignedMacAddress; +} + +void NetworkManager::WiredSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_WIRED_PORT))) { + const QString port = setting.value(QLatin1String(NM_SETTING_WIRED_PORT)).toString(); + + if (port == "tp") { + setPort(Tp); + } else if (port == "aui") { + setPort(Aui); + } else if (port == "bnc") { + setPort(Bnc); + } else if (port == "mii") { + setPort(Mii); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_SPEED))) { + setSpeed(setting.value(QLatin1String(NM_SETTING_WIRED_SPEED)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_DUPLEX))) { + const QString duplex = setting.value(QLatin1String(NM_SETTING_WIRED_DUPLEX)).toString(); + + if (duplex == "half") { + setDuplexType(Half); + } else if (duplex == "full") { + setDuplexType(Full); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_AUTO_NEGOTIATE))) { + setAutoNegotiate(setting.value(QLatin1String(NM_SETTING_WIRED_AUTO_NEGOTIATE)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK))) { + setGenerateMacAddressMask(setting.value(QLatin1String(NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_MAC_ADDRESS))) { + setMacAddress(setting.value(QLatin1String(NM_SETTING_WIRED_MAC_ADDRESS)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_CLONED_MAC_ADDRESS))) { + setClonedMacAddress(setting.value(QLatin1String(NM_SETTING_WIRED_CLONED_MAC_ADDRESS)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST))) { + setMacAddressBlacklist(setting.value(QLatin1String(NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST)).toStringList()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_MTU))) { + setMtu(setting.value(QLatin1String(NM_SETTING_WIRED_MTU)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_S390_SUBCHANNELS))) { + setS390Subchannels(setting.value(QLatin1String(NM_SETTING_WIRED_S390_SUBCHANNELS)).toStringList()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_S390_NETTYPE))) { + const QString nettype = setting.value(QLatin1String(NM_SETTING_WIRED_S390_NETTYPE)).toString(); + + if (nettype == "qeth") { + setS390NetType(Qeth); + } else if (nettype == "lcs") { + setS390NetType(Lcs); + } else if (nettype == "ctc") { + setS390NetType(Ctc); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_S390_OPTIONS))) { + QMap tmp; + if (setting.value(QLatin1String(NM_SETTING_WIRED_S390_OPTIONS)).canConvert()) { + QDBusArgument arg = setting.value(QLatin1String(NM_SETTING_WIRED_S390_OPTIONS)).value(); + tmp = qdbus_cast(arg); + } else { + tmp = setting.value(QLatin1String(NM_SETTING_WIRED_S390_OPTIONS)).value(); + } + setS390Options(tmp); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_WAKE_ON_LAN))) { + setWakeOnLan((NetworkManager::WiredSetting::WakeOnLanFlags)setting.value(QLatin1String(NM_SETTING_WIRED_WAKE_ON_LAN)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD))) { + setWakeOnLanPassword(setting.value(QLatin1String(NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRED_ASSIGNED_MAC_ADDRESS))) { + setAssignedMacAddress(setting.value(QLatin1String(NM_SETTING_WIRED_ASSIGNED_MAC_ADDRESS)).toString()); + } +} + +QVariantMap NetworkManager::WiredSetting::toMap() const +{ + QVariantMap setting; + + switch (port()) { + case Tp: + setting.insert(QLatin1String(NM_SETTING_WIRED_PORT), "tp"); + break; + case Aui: + setting.insert(QLatin1String(NM_SETTING_WIRED_PORT), "aui"); + break; + case Bnc: + setting.insert(QLatin1String(NM_SETTING_WIRED_PORT), "bnc"); + break; + case Mii: + setting.insert(QLatin1String(NM_SETTING_WIRED_PORT), "mii"); + break; + case UnknownPort: // Make GCC hapy + break; + } + + // When autonegotiation is set we have to avoid setting speed and duplex, while + // when autonegotiation is disabled, we have to specify both + if (autoNegotiate()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_AUTO_NEGOTIATE), autoNegotiate()); + } else { + setting.insert(QLatin1String(NM_SETTING_WIRED_AUTO_NEGOTIATE), autoNegotiate()); + setting.insert(QLatin1String(NM_SETTING_WIRED_SPEED), speed()); + + switch (duplexType()) { + case Half: + setting.insert(QLatin1String(NM_SETTING_WIRED_DUPLEX), "half"); + break; + case Full: + setting.insert(QLatin1String(NM_SETTING_WIRED_DUPLEX), "full"); + break; + case UnknownDuplexType: + break; + } + } + + if (!generateMacAddressMask().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK), generateMacAddressMask()); + } + + if (!macAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_MAC_ADDRESS), macAddress()); + } + if (!clonedMacAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_CLONED_MAC_ADDRESS), clonedMacAddress()); + } + if (!macAddressBlacklist().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST), macAddressBlacklist()); + } + if (mtu()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_MTU), mtu()); + } + if (!s390Subchannels().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_S390_SUBCHANNELS), s390Subchannels()); + } + + switch (s390NetType()) { + case Qeth: + setting.insert(QLatin1String(NM_SETTING_WIRED_S390_NETTYPE), "qeth"); + break; + case Lcs: + setting.insert(QLatin1String(NM_SETTING_WIRED_S390_NETTYPE), "lcs"); + break; + case Ctc: + setting.insert(QLatin1String(NM_SETTING_WIRED_S390_NETTYPE), "ctc"); + break; + case Undefined: + break; + } + + if (!s390Options().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_S390_OPTIONS), QVariant::fromValue(s390Options())); + } + + setting.insert(QLatin1String(NM_SETTING_WIRED_WAKE_ON_LAN), (uint)wakeOnLan()); + + if (!wakeOnLanPassword().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD), wakeOnLanPassword()); + } + + if (!assignedMacAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRED_ASSIGNED_MAC_ADDRESS), assignedMacAddress()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::WiredSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_WIRED_PORT << ": " << setting.port() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_SPEED << ": " << setting.speed() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_DUPLEX << ": " << setting.duplexType() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_AUTO_NEGOTIATE << ": " << setting.autoNegotiate() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK << ": " << setting.generateMacAddressMask() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_MAC_ADDRESS << ": " << setting.macAddress() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_CLONED_MAC_ADDRESS << ": " << setting.clonedMacAddress() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST << ": " << setting.macAddressBlacklist() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_MTU << ": " << setting.mtu() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_S390_SUBCHANNELS << ": " << setting.s390Subchannels() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_S390_NETTYPE << ": " << setting.s390NetType() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_S390_OPTIONS << ": " << setting.s390Options() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_WAKE_ON_LAN << ": " << setting.wakeOnLan() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD << ": " << setting.wakeOnLanPassword() << '\n'; + dbg.nospace() << NM_SETTING_WIRED_ASSIGNED_MAC_ADDRESS << ": " << setting.assignedMacAddress() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting.h new file mode 100644 index 000000000..35fb4e730 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting.h @@ -0,0 +1,130 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRED_SETTING_H +#define NETWORKMANAGERQT_WIRED_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class WiredSettingPrivate; + +/** + * Represents wired setting + */ +class NETWORKMANAGERQT_EXPORT WiredSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum PortType { + UnknownPort = 0, + Tp, + Aui, + Bnc, + Mii, + }; + + enum DuplexType { + UnknownDuplexType = 0, + Half, + Full, + }; + + enum S390Nettype { + Undefined = 0, + Qeth, + Lcs, + Ctc, + }; + + enum WakeOnLanFlag { + WakeOnLanPhy = 1 << 1, + WakeOnLanUnicast = 1 << 2, + WakeOnLanMulticast = 1 << 3, + WakeOnLanBroadcast = 1 << 4, + WakeOnLanArp = 1 << 5, + WakeOnLanMagic = 1 << 6, + /* Special values */ + WakeOnLanDefault = 1 << 0, + WakeOnLanIgnore = 1 << 15, + }; + Q_DECLARE_FLAGS(WakeOnLanFlags, WakeOnLanFlag) + Q_FLAGS(WakeOnLanFlag) + + WiredSetting(); + explicit WiredSetting(const Ptr &other); + ~WiredSetting() override; + + QString name() const override; + + void setPort(PortType port); + PortType port() const; + + void setSpeed(quint32 speed); + quint32 speed() const; + + void setDuplexType(DuplexType type); + DuplexType duplexType() const; + + void setAutoNegotiate(bool autoNegotiate); + bool autoNegotiate() const; + + QString generateMacAddressMask() const; + void setGenerateMacAddressMask(const QString &mask); + + void setMacAddress(const QByteArray &address); + QByteArray macAddress() const; + + void setClonedMacAddress(const QByteArray &address); + QByteArray clonedMacAddress() const; + + void setMacAddressBlacklist(const QStringList &list); + QStringList macAddressBlacklist() const; + + void setMtu(quint32 mtu); + quint32 mtu() const; + + void setS390Subchannels(const QStringList &channels); + QStringList s390Subchannels() const; + + void setS390NetType(S390Nettype type); + S390Nettype s390NetType() const; + + void setS390Options(const QMap &options); + QMap s390Options() const; + + WakeOnLanFlags wakeOnLan() const; + void setWakeOnLan(WakeOnLanFlags wol); + + QString wakeOnLanPassword() const; + void setWakeOnLanPassword(const QString &password); + + QString assignedMacAddress() const; + void setAssignedMacAddress(const QString &assignedMacAddress); + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + WiredSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(WiredSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const WiredSetting &setting); + +Q_DECLARE_OPERATORS_FOR_FLAGS(WiredSetting::WakeOnLanFlags) + +} + +#endif // NETWORKMANAGERQT_WIRED_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting_p.h new file mode 100644 index 000000000..9cbbcec5f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wiredsetting_p.h @@ -0,0 +1,40 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRED_SETTING_P_H +#define NETWORKMANAGERQT_WIRED_SETTING_P_H + +#include +#include + +namespace NetworkManager +{ +class WiredSettingPrivate +{ +public: + WiredSettingPrivate(); + + QString name; + NetworkManager::WiredSetting::PortType port; + quint32 speed; + NetworkManager::WiredSetting::DuplexType duplex; + bool autoNegotiate; + QByteArray macAddress; + QByteArray clonedMacAddress; + QStringList macAddressBlacklist; + quint32 mtu; + QStringList s390Subchannels; + NetworkManager::WiredSetting::S390Nettype s390NetType; + QMap s390Options; + QString generateMacAddressMask; + NetworkManager::WiredSetting::WakeOnLanFlags wakeOnLan; + QString wakeOnLanPassword; + QString assignedMacAddress; +}; + +} + +#endif // NETWORKMANAGERQT_WIRED_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting.cpp new file mode 100644 index 000000000..e9a3d599e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting.cpp @@ -0,0 +1,386 @@ +/* + SPDX-FileCopyrightText: 2019 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wireguardsetting.h" +#include "wireguardsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 16, 0) +#define NM_SETTING_WIREGUARD_SETTING_NAME "wireguard" + +#define NM_SETTING_WIREGUARD_FWMARK "fwmark" +#define NM_SETTING_WIREGUARD_LISTEN_PORT "listen-port" +#define NM_SETTING_WIREGUARD_PRIVATE_KEY "private-key" +#define NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS "private-key-flags" +#define NM_SETTING_WIREGUARD_PEERS "peers" +#define NM_SETTING_WIREGUARD_MTU "mtu" +#define NM_SETTING_WIREGUARD_PEER_ROUTES "peer-routes" + +#define NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY "preshared-key" +#define NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY_FLAGS "preshared-key-flags" +#define NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY "public-key" +#endif + +NetworkManager::WireGuardSettingPrivate::WireGuardSettingPrivate() + : name(NM_SETTING_WIREGUARD_SETTING_NAME) + , fwmark(0) + , listenPort(0) + , mtu(0) + , peerRoutes(true) + , privateKeyFlags(NetworkManager::Setting::None) +{ +} + +NetworkManager::WireGuardSetting::WireGuardSetting() + : Setting(Setting::WireGuard) + , d_ptr(new WireGuardSettingPrivate()) +{ +} + +NetworkManager::WireGuardSetting::WireGuardSetting(const Ptr &other) + : Setting(other) + , d_ptr(new WireGuardSettingPrivate()) +{ + setFwmark(other->fwmark()); + setListenPort(other->listenPort()); + setMtu(other->mtu()); + setPeerRoutes(other->peerRoutes()); + setPeers(other->peers()); + setPrivateKey(other->privateKey()); + setPrivateKeyFlags(other->privateKeyFlags()); +} + +NetworkManager::WireGuardSetting::~WireGuardSetting() +{ + delete d_ptr; +} + +QString NetworkManager::WireGuardSetting::name() const +{ + Q_D(const WireGuardSetting); + + return d->name; +} + +quint32 NetworkManager::WireGuardSetting::fwmark() const +{ + Q_D(const WireGuardSetting); + + return d->fwmark; +} + +void NetworkManager::WireGuardSetting::setFwmark(quint32 fwmark) +{ + Q_D(WireGuardSetting); + + d->fwmark = fwmark; +} + +quint32 NetworkManager::WireGuardSetting::listenPort() const +{ + Q_D(const WireGuardSetting); + + return d->listenPort; +} + +void NetworkManager::WireGuardSetting::setListenPort(quint32 port) +{ + Q_D(WireGuardSetting); + + d->listenPort = port; +} + +quint32 NetworkManager::WireGuardSetting::mtu() const +{ + Q_D(const WireGuardSetting); + + return d->mtu; +} + +void NetworkManager::WireGuardSetting::setMtu(quint32 mtu) +{ + Q_D(WireGuardSetting); + + d->mtu = mtu; +} + +bool NetworkManager::WireGuardSetting::peerRoutes() const +{ + Q_D(const WireGuardSetting); + + return d->peerRoutes; +} + +void NetworkManager::WireGuardSetting::setPeerRoutes(bool peerRoutes) +{ + Q_D(WireGuardSetting); + + d->peerRoutes = peerRoutes; +} + +NMVariantMapList NetworkManager::WireGuardSetting::peers() const +{ + Q_D(const WireGuardSetting); + + return d->peers; +} + +void NetworkManager::WireGuardSetting::setPeers(const NMVariantMapList &peers) +{ + Q_D(WireGuardSetting); + + d->peers = peers; +} + +QString NetworkManager::WireGuardSetting::privateKey() const +{ + Q_D(const WireGuardSetting); + + return d->privateKey; +} + +void NetworkManager::WireGuardSetting::setPrivateKey(const QString &key) +{ + Q_D(WireGuardSetting); + + d->privateKey = key; +} + +NetworkManager::Setting::SecretFlags NetworkManager::WireGuardSetting::privateKeyFlags() const +{ + Q_D(const WireGuardSetting); + + return d->privateKeyFlags; +} + +void NetworkManager::WireGuardSetting::setPrivateKeyFlags(NetworkManager::Setting::SecretFlags flags) +{ + Q_D(WireGuardSetting); + + d->privateKeyFlags = flags; +} + +void NetworkManager::WireGuardSetting::secretsFromMap(const QVariantMap &secrets) +{ + if (secrets.contains(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY))) { + setPrivateKey(secrets.value(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_WIREGUARD_PEERS))) { + NMVariantMapList listOfPeers = qdbus_cast(secrets.value(QLatin1String(NM_SETTING_WIREGUARD_PEERS))); + NMVariantMapList origPeers = peers(); + + for (const QVariantMap &peer : listOfPeers) { + if (peer.contains(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY))) { + QString presharedKey = peer.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)).toString(); + QString publicKey = peer.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY)).toString(); + for (int i = 0; i < origPeers.size(); i++) { + if (origPeers[i][QLatin1String(NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY)].toString() == publicKey) { + origPeers[i].insert(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY), presharedKey); + } + } + } + } + setPeers(origPeers); + } +} + +QVariantMap NetworkManager::WireGuardSetting::secretsToMap() const +{ + QVariantMap secrets; + + if (!privateKey().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY), privateKey()); + } + + NMVariantMapList peersSecrets; + + for (const QVariantMap &map : peers()) { + if (map.contains(QLatin1String(NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY)) && map.contains(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY))) { + QVariantMap newMap; + newMap.insert(QLatin1String(NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY), map.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY))); + newMap.insert(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY), map.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY))); + + peersSecrets << newMap; + } + } + + if (!peersSecrets.isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_WIREGUARD_PEERS), QVariant::fromValue(peersSecrets)); + } + + return secrets; +} + +void NetworkManager::WireGuardSetting::secretsFromStringMap(const NMStringMap &map) +{ + QVariantMap secretsMap; + NMVariantMapList peers; + + auto it = map.constBegin(); + while (it != map.constEnd()) { + if (it.key() == QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY)) { + secretsMap.insert(it.key(), it.value()); + } + + if (it.key().startsWith(QLatin1String(NM_SETTING_WIREGUARD_PEERS)) && it.key().endsWith(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY))) { + QStringList peerStrList = it.key().split(QLatin1Char('.')); + + QVariantMap peer; + peer.insert(QLatin1String(NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY), peerStrList.at(1)); + peer.insert(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY), it.value()); + + peers << peer; + } + ++it; + } + + if (!peers.isEmpty()) { + secretsMap.insert(QLatin1String(NM_SETTING_WIREGUARD_PEERS), QVariant::fromValue(peers)); + } + + secretsFromMap(secretsMap); +} + +NMStringMap NetworkManager::WireGuardSetting::secretsToStringMap() const +{ + NMStringMap ret; + QVariantMap secretsMap = secretsToMap(); + + auto it = secretsMap.constBegin(); + while (it != secretsMap.constEnd()) { + if (it.key() == QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY)) { + ret.insert(it.key(), it.value().toString()); + } + + if (it.key() == QLatin1String(NM_SETTING_WIREGUARD_PEERS)) { + NMVariantMapList listOfPeers = qdbus_cast(it.value()); + + for (const QVariantMap &map : listOfPeers) { + const QString str = QStringLiteral("%1.%2.%3") + .arg(QLatin1String(NM_SETTING_WIREGUARD_PEERS)) + .arg(map.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY)).toString()) + .arg(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)); + ret.insert(str, map.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)).toString()); + } + } + ++it; + } + + return ret; +} + +QStringList NetworkManager::WireGuardSetting::needSecrets(bool requestNew) const +{ + QStringList secrets; + + if (!privateKeyFlags().testFlag(Setting::NotRequired)) { + if (privateKey().isEmpty() || requestNew) { + secrets << QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY); + } + } + + for (const QVariantMap &map : peers()) { + const QString presharedKey = map.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)).toString(); + SecretFlags preSharedKeyFlags = (SecretFlags)map.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY_FLAGS)).toInt(); + + if (!presharedKey.isEmpty()) { + continue; + } + + if (preSharedKeyFlags.testFlag(Setting::NotRequired)) { + continue; + } + + const QString str = QStringLiteral("%1.%2.%3") + .arg(QLatin1String(NM_SETTING_WIREGUARD_PEERS)) + .arg(map.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PUBLIC_KEY)).toString()) + .arg(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY)); + secrets << str; + } + + return secrets; +} + +void NetworkManager::WireGuardSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_WIREGUARD_FWMARK))) { + setFwmark(setting.value(QLatin1String(NM_SETTING_WIREGUARD_FWMARK)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIREGUARD_LISTEN_PORT))) { + setListenPort(setting.value(QLatin1String(NM_SETTING_WIREGUARD_LISTEN_PORT)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIREGUARD_MTU))) { + setMtu(setting.value(QLatin1String(NM_SETTING_WIREGUARD_MTU)).toInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIREGUARD_PEER_ROUTES))) { + setPeerRoutes(setting.value(QLatin1String(NM_SETTING_WIREGUARD_PEER_ROUTES)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIREGUARD_PEERS))) { + setPeers(qdbus_cast(setting.value(QLatin1String(NM_SETTING_WIREGUARD_PEERS)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY))) { + setPrivateKey(setting.value(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS))) { + setPrivateKeyFlags((SecretFlags)setting.value(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS)).toInt()); + } +} + +QVariantMap NetworkManager::WireGuardSetting::toMap() const +{ + QVariantMap setting; + + setting.insert(QLatin1String(NM_SETTING_WIREGUARD_FWMARK), fwmark()); + setting.insert(QLatin1String(NM_SETTING_WIREGUARD_LISTEN_PORT), listenPort()); + setting.insert(QLatin1String(NM_SETTING_WIREGUARD_MTU), mtu()); + setting.insert(QLatin1String(NM_SETTING_WIREGUARD_PEER_ROUTES), peerRoutes()); + + if (!peers().isEmpty()) { + // FIXME we seem to have SecretFlags as an int, but NM expects an uint, while this is not + // problem for rest of *-flags properties, it's problem for "preshared-key" which NM handless + // as GVariant and asks for "u" when getting it's value + NMVariantMapList fixedPeers = peers(); + for (QVariantMap &map : fixedPeers) { + if (map.contains(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY_FLAGS))) { + map.insert(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY_FLAGS), + map.value(QLatin1String(NM_WIREGUARD_PEER_ATTR_PRESHARED_KEY_FLAGS)).toUInt()); + } + } + + setting.insert(QLatin1String(NM_SETTING_WIREGUARD_PEERS), QVariant::fromValue(fixedPeers)); + } + + if (!privateKey().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY), privateKey()); + } + setting.insert(QLatin1String(NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS), (int)privateKeyFlags()); + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::WireGuardSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_WIREGUARD_FWMARK << ": " << setting.fwmark() << '\n'; + dbg.nospace() << NM_SETTING_WIREGUARD_LISTEN_PORT << ": " << setting.listenPort() << '\n'; + dbg.nospace() << NM_SETTING_WIREGUARD_MTU << ": " << setting.mtu() << '\n'; + dbg.nospace() << NM_SETTING_WIREGUARD_PEER_ROUTES << ": " << setting.peerRoutes() << '\n'; + dbg.nospace() << NM_SETTING_WIREGUARD_PEERS << ": " << setting.peers() << '\n'; + dbg.nospace() << NM_SETTING_WIREGUARD_PRIVATE_KEY << ": " << setting.privateKey() << '\n'; + dbg.nospace() << NM_SETTING_WIREGUARD_PRIVATE_KEY_FLAGS << ": " << setting.privateKeyFlags() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting.h b/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting.h new file mode 100644 index 000000000..487c6b705 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting.h @@ -0,0 +1,83 @@ +/* + SPDX-FileCopyrightText: 2019 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIREGUARD_SETTING_H +#define NETWORKMANAGERQT_WIREGUARD_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class WireGuardSettingPrivate; + +/** + * Represents generic setting + */ +class NETWORKMANAGERQT_EXPORT WireGuardSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + WireGuardSetting(); + explicit WireGuardSetting(const Ptr &other); + ~WireGuardSetting() override; + + QString name() const override; + + quint32 fwmark() const; + void setFwmark(quint32 fwmark); + + quint32 listenPort() const; + void setListenPort(quint32 port); + + quint32 mtu() const; + void setMtu(quint32 mtu); + + bool peerRoutes() const; + void setPeerRoutes(bool peerRoutes); + + NMVariantMapList peers() const; + void setPeers(const NMVariantMapList &peers); + + QString privateKey() const; + void setPrivateKey(const QString &key); + + SecretFlags privateKeyFlags() const; + void setPrivateKeyFlags(SecretFlags flags); + + void secretsFromMap(const QVariantMap &secrets) override; + + QVariantMap secretsToMap() const override; + + void secretsFromStringMap(const NMStringMap &map) override; + + NMStringMap secretsToStringMap() const override; + + /* + * Required "preshared-key" properties from "peers" property will be returned + * as strings in format "peers.public-key.preshared-key". + */ + QStringList needSecrets(bool requestNew = false) const override; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + WireGuardSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(WireGuardSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const WireGuardSetting &setting); + +} + +#endif // NETWORKMANAGERQT_WIREGUARD_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting_p.h new file mode 100644 index 000000000..b51cddfa0 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wireguardsetting_p.h @@ -0,0 +1,32 @@ +/* + SPDX-FileCopyrightText: 2019 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIREGUARD_SETTING_P_H +#define NETWORKMANAGERQT_WIREGUARD_SETTING_P_H + +#include + +namespace NetworkManager +{ +class WireGuardSettingPrivate +{ +public: + WireGuardSettingPrivate(); + + QString name; + + quint32 fwmark; + quint32 listenPort; + quint32 mtu; + bool peerRoutes; + NMVariantMapList peers; + QString privateKey; + NetworkManager::Setting::SecretFlags privateKeyFlags; +}; + +} + +#endif // NETWORKMANAGERQT_WIREGUARD_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting.cpp new file mode 100644 index 000000000..8d27badb7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting.cpp @@ -0,0 +1,737 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wirelesssecuritysetting.h" +#include "wirelesssecuritysetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_WIRELESS_SECURITY_PMF "pmf" +#endif + +NetworkManager::WirelessSecuritySettingPrivate::WirelessSecuritySettingPrivate() + : name(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) + , keyMgmt(NetworkManager::WirelessSecuritySetting::Unknown) + , wepTxKeyidx(0) + , authAlg(NetworkManager::WirelessSecuritySetting::None) + , wepKeyFlags(NetworkManager::Setting::None) + , wepKeyType(NetworkManager::WirelessSecuritySetting::NotSpecified) + , pskFlags(NetworkManager::Setting::None) + , leapPasswordFlags(NetworkManager::Setting::None) + , pmf(NetworkManager::WirelessSecuritySetting::DefaultPmf) +{ +} + +NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting() + : Setting(Setting::WirelessSecurity) + , d_ptr(new WirelessSecuritySettingPrivate()) +{ +} + +NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting(const Ptr &other) + : Setting(other) + , d_ptr(new WirelessSecuritySettingPrivate()) +{ + setKeyMgmt(other->keyMgmt()); + setWepTxKeyindex(other->wepTxKeyindex()); + setAuthAlg(other->authAlg()); + setProto(other->proto()); + setPairwise(other->pairwise()); + setGroup(other->group()); + setWepKey0(other->wepKey0()); + setWepKey1(other->wepKey1()); + setWepKey2(other->wepKey2()); + setWepKey3(other->wepKey3()); + setWepKeyFlags(other->wepKeyFlags()); + setWepKeyType(other->wepKeyType()); + setPsk(other->psk()); + setPskFlags(other->pskFlags()); + setLeapPassword(other->leapPassword()); + setLeapPasswordFlags(other->leapPasswordFlags()); + setPmf(other->pmf()); +} + +NetworkManager::WirelessSecuritySetting::~WirelessSecuritySetting() +{ + delete d_ptr; +} + +QString NetworkManager::WirelessSecuritySetting::name() const +{ + Q_D(const WirelessSecuritySetting); + + return d->name; +} + +void NetworkManager::WirelessSecuritySetting::setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt mgmt) +{ + Q_D(WirelessSecuritySetting); + + d->keyMgmt = mgmt; +} + +NetworkManager::WirelessSecuritySetting::KeyMgmt NetworkManager::WirelessSecuritySetting::keyMgmt() const +{ + Q_D(const WirelessSecuritySetting); + + return d->keyMgmt; +} + +void NetworkManager::WirelessSecuritySetting::setWepTxKeyindex(quint32 index) +{ + Q_D(WirelessSecuritySetting); + + d->wepTxKeyidx = index; +} + +quint32 NetworkManager::WirelessSecuritySetting::wepTxKeyindex() const +{ + Q_D(const WirelessSecuritySetting); + + return d->wepTxKeyidx; +} + +void NetworkManager::WirelessSecuritySetting::setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg alg) +{ + Q_D(WirelessSecuritySetting); + + d->authAlg = alg; +} + +NetworkManager::WirelessSecuritySetting::AuthAlg NetworkManager::WirelessSecuritySetting::authAlg() const +{ + Q_D(const WirelessSecuritySetting); + + return d->authAlg; +} + +void NetworkManager::WirelessSecuritySetting::setProto(const QList &list) +{ + Q_D(WirelessSecuritySetting); + + d->proto = list; +} + +QList NetworkManager::WirelessSecuritySetting::proto() const +{ + Q_D(const WirelessSecuritySetting); + + return d->proto; +} + +void NetworkManager::WirelessSecuritySetting::setPairwise(const QList &list) +{ + Q_D(WirelessSecuritySetting); + + d->pairwise = list; +} + +QList NetworkManager::WirelessSecuritySetting::pairwise() const +{ + Q_D(const WirelessSecuritySetting); + + return d->pairwise; +} + +void NetworkManager::WirelessSecuritySetting::setGroup(const QList &list) +{ + Q_D(WirelessSecuritySetting); + + d->group = list; +} + +QList NetworkManager::WirelessSecuritySetting::group() const +{ + Q_D(const WirelessSecuritySetting); + + return d->group; +} + +void NetworkManager::WirelessSecuritySetting::setLeapUsername(const QString &username) +{ + Q_D(WirelessSecuritySetting); + + d->leapUsername = username; +} + +QString NetworkManager::WirelessSecuritySetting::leapUsername() const +{ + Q_D(const WirelessSecuritySetting); + + return d->leapUsername; +} + +void NetworkManager::WirelessSecuritySetting::setWepKey0(const QString key) +{ + Q_D(WirelessSecuritySetting); + + d->wepKey0 = key; +} + +QString NetworkManager::WirelessSecuritySetting::wepKey0() const +{ + Q_D(const WirelessSecuritySetting); + + return d->wepKey0; +} + +void NetworkManager::WirelessSecuritySetting::setWepKey1(const QString key) +{ + Q_D(WirelessSecuritySetting); + + d->wepKey1 = key; +} + +QString NetworkManager::WirelessSecuritySetting::wepKey1() const +{ + Q_D(const WirelessSecuritySetting); + + return d->wepKey1; +} + +void NetworkManager::WirelessSecuritySetting::setWepKey2(const QString key) +{ + Q_D(WirelessSecuritySetting); + + d->wepKey2 = key; +} + +QString NetworkManager::WirelessSecuritySetting::wepKey2() const +{ + Q_D(const WirelessSecuritySetting); + + return d->wepKey2; +} + +void NetworkManager::WirelessSecuritySetting::setWepKey3(const QString key) +{ + Q_D(WirelessSecuritySetting); + + d->wepKey3 = key; +} + +QString NetworkManager::WirelessSecuritySetting::wepKey3() const +{ + Q_D(const WirelessSecuritySetting); + + return d->wepKey3; +} + +void NetworkManager::WirelessSecuritySetting::setWepKeyFlags(NetworkManager::Setting::SecretFlags type) +{ + Q_D(WirelessSecuritySetting); + + d->wepKeyFlags = type; +} + +NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::wepKeyFlags() const +{ + Q_D(const WirelessSecuritySetting); + + return d->wepKeyFlags; +} + +void NetworkManager::WirelessSecuritySetting::setWepKeyType(NetworkManager::WirelessSecuritySetting::WepKeyType type) +{ + Q_D(WirelessSecuritySetting); + + d->wepKeyType = type; +} + +NetworkManager::WirelessSecuritySetting::WepKeyType NetworkManager::WirelessSecuritySetting::wepKeyType() const +{ + Q_D(const WirelessSecuritySetting); + + return d->wepKeyType; +} + +void NetworkManager::WirelessSecuritySetting::setPsk(const QString &key) +{ + Q_D(WirelessSecuritySetting); + + d->psk = key; +} + +QString NetworkManager::WirelessSecuritySetting::psk() const +{ + Q_D(const WirelessSecuritySetting); + + return d->psk; +} + +void NetworkManager::WirelessSecuritySetting::setPskFlags(NetworkManager::Setting::SecretFlags type) +{ + Q_D(WirelessSecuritySetting); + + d->pskFlags = type; +} + +NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::pskFlags() const +{ + Q_D(const WirelessSecuritySetting); + + return d->pskFlags; +} + +void NetworkManager::WirelessSecuritySetting::setLeapPassword(const QString &password) +{ + Q_D(WirelessSecuritySetting); + + d->leapPassword = password; +} + +QString NetworkManager::WirelessSecuritySetting::leapPassword() const +{ + Q_D(const WirelessSecuritySetting); + + return d->leapPassword; +} + +void NetworkManager::WirelessSecuritySetting::setLeapPasswordFlags(NetworkManager::Setting::SecretFlags type) +{ + Q_D(WirelessSecuritySetting); + + d->leapPasswordFlags = type; +} + +NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::leapPasswordFlags() const +{ + Q_D(const WirelessSecuritySetting); + + return d->leapPasswordFlags; +} + +void NetworkManager::WirelessSecuritySetting::setPmf(NetworkManager::WirelessSecuritySetting::Pmf pmf) +{ + Q_D(WirelessSecuritySetting); + + d->pmf = pmf; +} + +NetworkManager::WirelessSecuritySetting::Pmf NetworkManager::WirelessSecuritySetting::pmf() const +{ + Q_D(const WirelessSecuritySetting); + + return d->pmf; +} + +void NetworkManager::WirelessSecuritySetting::secretsFromMap(const QVariantMap &secrets) +{ + if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) { + setWepKey0(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) { + setWepKey1(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) { + setWepKey2(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) { + setWepKey3(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) { + setPsk(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).toString()); + } + + if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) { + setLeapPassword(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).toString()); + } +} + +QVariantMap NetworkManager::WirelessSecuritySetting::secretsToMap() const +{ + QVariantMap secrets; + + if (!wepKey0().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), wepKey0()); + } + + if (!wepKey1().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), wepKey1()); + } + + if (!wepKey2().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), wepKey2()); + } + + if (!wepKey3().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), wepKey3()); + } + + if (!psk().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), psk()); + } + + if (!leapPassword().isEmpty()) { + secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), leapPassword()); + } + + return secrets; +} + +QStringList NetworkManager::WirelessSecuritySetting::needSecrets(bool requestNew) const +{ + QStringList secrets; + + if (keyMgmt() == Wep) { + if (!wepKeyFlags().testFlag(Setting::NotRequired)) { + switch (wepTxKeyindex()) { + case 0: + if (wepKey0().isEmpty() || requestNew) { + secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); + return secrets; + } + break; + case 1: + if (wepKey1().isEmpty() || requestNew) { + secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1); + return secrets; + } + break; + case 2: + if (wepKey2().isEmpty() || requestNew) { + secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2); + return secrets; + } + break; + case 3: + if (wepKey3().isEmpty() || requestNew) { + secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3); + return secrets; + } + break; + } + } + } + + if (keyMgmt() == WpaNone || keyMgmt() == WpaPsk || keyMgmt() == SAE) { + if (!pskFlags().testFlag(Setting::NotRequired)) { + if (psk().isEmpty() || requestNew) { + secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK); + return secrets; + } + } + } + + if (authAlg() == Leap && keyMgmt() == Ieee8021x) { + if (!leapPasswordFlags().testFlag(Setting::NotRequired)) { + if (leapPassword().isEmpty() || requestNew) { + secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD); + return secrets; + } + } + } + + return secrets; +} + +void NetworkManager::WirelessSecuritySetting::fromMap(const QVariantMap &map) +{ + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT))) { + const QString key = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)).toString(); + if (key == "none") { + setKeyMgmt(Wep); + } else if (key == "ieee8021x") { + setKeyMgmt(Ieee8021x); + } else if (key == "wpa-none") { + setKeyMgmt(WpaNone); + } else if (key == "wpa-psk") { + setKeyMgmt(WpaPsk); + } else if (key == "wpa-eap") { + setKeyMgmt(WpaEap); + } else if (key == "sae") { + setKeyMgmt(SAE); + } else if (key == "wpa-eap-suite-b-192") { + setKeyMgmt(WpaEapSuiteB192); + } + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX))) { + setWepTxKeyindex(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX)).toUInt()); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG))) { + const QString alg = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG)).toString(); + if (alg == "open") { + setAuthAlg(Open); + } else if (alg == "shared") { + setAuthAlg(Shared); + } else if (alg == "leap") { + setAuthAlg(Leap); + } + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO))) { + const QStringList strList = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO)).toStringList(); + QList list; + for (const QString &str : strList) { + if (str == "wpa") { + list.push_back(Wpa); + } else if (str == "rsn") { + list.push_back(Rsn); + } + } + setProto(list); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE))) { + const QStringList strList = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE)).toStringList(); + QList list; + for (const QString &str : strList) { + if (str == "wep40") { + list.push_back(Wep40); + } else if (str == "wep104") { + list.push_back(Wep104); + } else if (str == "tkip") { + list.push_back(Tkip); + } else if (str == "ccmp") { + list.push_back(Ccmp); + } + } + setPairwise(list); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP))) { + const QStringList strList = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP)).toStringList(); + QList list; + for (const QString &str : strList) { + if (str == "wep40") { + list.push_back(Wep40); + } else if (str == "wep104") { + list.push_back(Wep104); + } else if (str == "tkip") { + list.push_back(Tkip); + } else if (str == "ccmp") { + list.push_back(Ccmp); + } + } + setGroup(list); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME))) { + setLeapUsername(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME)).toString()); + } + + // Secrets + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) { + setWepKey0(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).toString()); + } + + // Secrets + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) { + setWepKey1(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).toString()); + } + + // Secrets + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) { + setWepKey2(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).toString()); + } + + // Secrets + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) { + setWepKey3(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).toString()); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS))) { + setWepKeyFlags((SecretFlags)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS)).toInt()); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE))) { + setWepKeyType((WepKeyType)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE)).toUInt()); + } + + // Secrets + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) { + setPsk(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).toString()); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS))) { + setPskFlags((SecretFlags)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS)).toInt()); + } + + // Secrets + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) { + setLeapPassword(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).toString()); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS))) { + setLeapPasswordFlags((SecretFlags)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS)).toInt()); + } + + if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF))) { + setPmf((Pmf)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF)).toInt()); + } +} + +QVariantMap NetworkManager::WirelessSecuritySetting::toMap() const +{ + QVariantMap setting; + + if (keyMgmt() == Wep) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "none"); + } else if (keyMgmt() == Ieee8021x) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "ieee8021x"); + } else if (keyMgmt() == WpaNone) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-none"); + } else if (keyMgmt() == WpaPsk) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-psk"); + } else if (keyMgmt() == WpaEap) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-eap"); + } else if (keyMgmt() == SAE) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "sae"); + } else if (keyMgmt() == WpaEapSuiteB192) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-eap-suite-b-192"); + } + + if (wepTxKeyindex()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), wepTxKeyindex()); + } + + if (authAlg() != None) { + if (authAlg() == Open) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "open"); + } else if (authAlg() == Shared) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "shared"); + } else if (authAlg() == Leap) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "leap"); + } + } + + if (!proto().isEmpty()) { + QStringList strList; + const auto protoList = proto(); + for (const WpaProtocolVersion &version : protoList) { + if (version == Wpa) { + strList << "wpa"; + } else if (version == Rsn) { + strList << "rsn"; + } + } + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO), strList); + } + + if (!pairwise().isEmpty()) { + QStringList strList; + const auto encryptions = pairwise(); + for (const WpaEncryptionCapabilities &capability : encryptions) { + if (capability == Wep40) { + strList << "wep40"; + } else if (capability == Wep104) { + strList << "wep104"; + } else if (capability == Tkip) { + strList << "tkip"; + } else if (capability == Ccmp) { + strList << "ccmp"; + } + } + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE), strList); + } + + if (!group().isEmpty()) { + QStringList strList; + const auto encryptions = group(); + for (const WpaEncryptionCapabilities &capability : encryptions) { + if (capability == Wep40) { + strList << "wep40"; + } else if (capability == Wep104) { + strList << "wep104"; + } else if (capability == Tkip) { + strList << "tkip"; + } else if (capability == Ccmp) { + strList << "ccmp"; + } + } + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP), strList); + } + + if (!leapUsername().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), leapUsername()); + } + + // Secrets + if (!wepKey0().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), wepKey0()); + } + + // Secrets + if (!wepKey1().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), wepKey1()); + } + + // Secrets + if (!wepKey2().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), wepKey2()); + } + + // Secrets + if (!wepKey3().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), wepKey3()); + } + + if (wepKeyFlags()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), (int)wepKeyFlags()); + } + + if (wepKeyType()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), wepKeyType()); + } + + // Secrets + if (!psk().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), psk()); + } + + if (pskFlags()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), (int)pskFlags()); + } + + // Secrets + if (!leapPassword().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), leapPassword()); + } + + if (leapPasswordFlags()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), (int)leapPasswordFlags()); + } + + if (pmf()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF), (int)pmf()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::WirelessSecuritySetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_KEY_MGMT << ": " << setting.keyMgmt() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX << ": " << setting.wepTxKeyindex() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_AUTH_ALG << ": " << setting.authAlg() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PROTO << ": " << setting.proto() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PAIRWISE << ": " << setting.pairwise() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_GROUP << ": " << setting.group() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME << ": " << setting.leapUsername() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY0 << ": " << setting.wepKey0() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY1 << ": " << setting.wepKey1() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY2 << ": " << setting.wepKey2() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY3 << ": " << setting.wepKey3() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS << ": " << setting.wepKeyFlags() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE << ": " << setting.wepKeyType() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PSK << ": " << setting.psk() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS << ": " << setting.pskFlags() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD << ": " << setting.leapPassword() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS << ": " << setting.leapPasswordFlags() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PMF << ": " << setting.pmf() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting.h b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting.h new file mode 100644 index 000000000..9c2b0afe4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting.h @@ -0,0 +1,146 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_H +#define NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_H + +#include "setting.h" +#include + +#include + +namespace NetworkManager +{ +class WirelessSecuritySettingPrivate; + +/** + * Represents wireless security setting + */ +class NETWORKMANAGERQT_EXPORT WirelessSecuritySetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + enum KeyMgmt { + Unknown = -1, + Wep, + Ieee8021x, + WpaNone, + WpaPsk, + WpaEap, + SAE, + WpaEapSuiteB192, + }; + enum AuthAlg { + None, + Open, + Shared, + Leap, + }; + enum WpaProtocolVersion { + Wpa, + Rsn, + }; + enum WpaEncryptionCapabilities { + Wep40, + Wep104, + Tkip, + Ccmp, + }; + enum WepKeyType { + NotSpecified, + Hex, + Passphrase, + }; + enum Pmf { + DefaultPmf, + DisablePmf, + OptionalPmf, + RequiredPmf, + }; + + WirelessSecuritySetting(); + explicit WirelessSecuritySetting(const Ptr &other); + ~WirelessSecuritySetting() override; + + QString name() const override; + + void setKeyMgmt(KeyMgmt mgmt); + KeyMgmt keyMgmt() const; + + void setWepTxKeyindex(quint32 index); + quint32 wepTxKeyindex() const; + + void setAuthAlg(AuthAlg alg); + AuthAlg authAlg() const; + + void setProto(const QList &list); + QList proto() const; + + void setPairwise(const QList &list); + QList pairwise() const; + + void setGroup(const QList &list); + QList group() const; + + void setLeapUsername(const QString &username); + QString leapUsername() const; + + void setWepKey0(const QString key); + QString wepKey0() const; + + void setWepKey1(const QString key); + QString wepKey1() const; + + void setWepKey2(const QString key); + QString wepKey2() const; + + void setWepKey3(const QString key); + QString wepKey3() const; + + void setWepKeyFlags(SecretFlags type); + SecretFlags wepKeyFlags() const; + + void setWepKeyType(WepKeyType type); + WepKeyType wepKeyType() const; + + void setPsk(const QString &key); + QString psk() const; + + void setPskFlags(SecretFlags type); + SecretFlags pskFlags() const; + + void setLeapPassword(const QString &password); + QString leapPassword() const; + + void setLeapPasswordFlags(SecretFlags type); + SecretFlags leapPasswordFlags() const; + + void setPmf(Pmf pmf); + Pmf pmf() const; + + void secretsFromMap(const QVariantMap &secrets) override; + + QVariantMap secretsToMap() const override; + + QStringList needSecrets(bool requestNew = false) const override; + + void fromMap(const QVariantMap &map) override; + + QVariantMap toMap() const override; + +protected: + WirelessSecuritySettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(WirelessSecuritySetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const WirelessSecuritySetting &setting); + +} + +#endif // NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting_p.h new file mode 100644 index 000000000..abd1e4cdf --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssecuritysetting_p.h @@ -0,0 +1,43 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_P_H +#define NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_P_H + +#include +#include + +namespace NetworkManager +{ +class WirelessSecuritySettingPrivate +{ +public: + WirelessSecuritySettingPrivate(); + + QString name; + NetworkManager::WirelessSecuritySetting::KeyMgmt keyMgmt; + quint32 wepTxKeyidx; + NetworkManager::WirelessSecuritySetting::AuthAlg authAlg; + QList proto; + QList pairwise; + QList group; + QString leapUsername; + QString wepKey0; + QString wepKey1; + QString wepKey2; + QString wepKey3; + NetworkManager::Setting::SecretFlags wepKeyFlags; + NetworkManager::WirelessSecuritySetting::WepKeyType wepKeyType; + QString psk; + NetworkManager::Setting::SecretFlags pskFlags; + QString leapPassword; + NetworkManager::Setting::SecretFlags leapPasswordFlags; + NetworkManager::WirelessSecuritySetting::Pmf pmf; +}; + +} + +#endif // NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting.cpp b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting.cpp new file mode 100644 index 000000000..cdce75c4f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting.cpp @@ -0,0 +1,517 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wirelesssetting.h" +#include "wirelesssetting_p.h" + +#include "utils.h" + +// define the deprecated&dropped values +#define NM_SETTING_WIRELESS_SEC "security" +#define NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS "assigned-mac-address" + +#include + +NetworkManager::WirelessSettingPrivate::WirelessSettingPrivate() + : name(NM_SETTING_WIRELESS_SETTING_NAME) + , mode(NetworkManager::WirelessSetting::Infrastructure) + , band(NetworkManager::WirelessSetting::Automatic) + , channel(0) + , rate(0) + , txPower(0) + , mtu(0) + , hidden(false) + , macAddressRandomization(NetworkManager::Setting::MacAddressRandomizationDefault) + , powersave(NetworkManager::WirelessSetting::PowerSaveDefault) +{ +} + +NetworkManager::WirelessSetting::WirelessSetting() + : Setting(Setting::Wireless) + , d_ptr(new WirelessSettingPrivate()) +{ +} + +NetworkManager::WirelessSetting::WirelessSetting(const Ptr &setting) + : Setting(setting) + , d_ptr(new WirelessSettingPrivate) +{ + setSsid(setting->ssid()); + setMode(setting->mode()); + setBand(setting->band()); + setChannel(setting->channel()); + setBssid(setting->bssid()); + setRate(setting->rate()); + setTxPower(setting->txPower()); + setMacAddress(setting->macAddress()); + setGenerateMacAddressMask(setting->generateMacAddressMask()); + setClonedMacAddress(setting->clonedMacAddress()); + setMacAddressBlacklist(setting->macAddressBlacklist()); + setMacAddressRandomization(setting->macAddressRandomization()); + setMtu(setting->mtu()); + setSeenBssids(setting->seenBssids()); + setPowerSave(setting->powerSave()); + setSecurity(setting->security()); + setHidden(setting->hidden()); + setAssignedMacAddress(setting->assignedMacAddress()); +} + +NetworkManager::WirelessSetting::~WirelessSetting() +{ + delete d_ptr; +} + +QString NetworkManager::WirelessSetting::name() const +{ + Q_D(const WirelessSetting); + + return d->name; +} + +void NetworkManager::WirelessSetting::setSsid(const QByteArray &ssid) +{ + Q_D(WirelessSetting); + + d->ssid = ssid; +} + +QByteArray NetworkManager::WirelessSetting::ssid() const +{ + Q_D(const WirelessSetting); + + return d->ssid; +} + +void NetworkManager::WirelessSetting::setMode(NetworkManager::WirelessSetting::NetworkMode mode) +{ + Q_D(WirelessSetting); + + d->mode = mode; +} + +NetworkManager::WirelessSetting::NetworkMode NetworkManager::WirelessSetting::mode() const +{ + Q_D(const WirelessSetting); + + return d->mode; +} + +void NetworkManager::WirelessSetting::setBand(NetworkManager::WirelessSetting::FrequencyBand band) +{ + Q_D(WirelessSetting); + + d->band = band; +} + +NetworkManager::WirelessSetting::FrequencyBand NetworkManager::WirelessSetting::band() const +{ + Q_D(const WirelessSetting); + + return d->band; +} + +void NetworkManager::WirelessSetting::setChannel(quint32 channel) +{ + Q_D(WirelessSetting); + + d->channel = channel; +} + +quint32 NetworkManager::WirelessSetting::channel() const +{ + Q_D(const WirelessSetting); + + return d->channel; +} + +void NetworkManager::WirelessSetting::setBssid(const QByteArray &bssid) +{ + Q_D(WirelessSetting); + + d->bssid = bssid; +} + +QByteArray NetworkManager::WirelessSetting::bssid() const +{ + Q_D(const WirelessSetting); + + return d->bssid; +} + +void NetworkManager::WirelessSetting::setRate(quint32 rate) +{ + Q_D(WirelessSetting); + + d->rate = rate; +} + +quint32 NetworkManager::WirelessSetting::rate() const +{ + Q_D(const WirelessSetting); + + return d->rate; +} + +void NetworkManager::WirelessSetting::setTxPower(quint32 power) +{ + Q_D(WirelessSetting); + + d->txPower = power; +} + +quint32 NetworkManager::WirelessSetting::txPower() const +{ + Q_D(const WirelessSetting); + + return d->txPower; +} + +void NetworkManager::WirelessSetting::setAssignedMacAddress(const QString &assignedMacAddress) +{ + Q_D(WirelessSetting); + + d->assignedMacAddress = assignedMacAddress; +} + +QString NetworkManager::WirelessSetting::assignedMacAddress() const +{ + Q_D(const WirelessSetting); + + return d->assignedMacAddress; +} + +void NetworkManager::WirelessSetting::setMacAddress(const QByteArray &address) +{ + Q_D(WirelessSetting); + + d->macAddress = address; +} + +QByteArray NetworkManager::WirelessSetting::macAddress() const +{ + Q_D(const WirelessSetting); + + return d->macAddress; +} + +void NetworkManager::WirelessSetting::setClonedMacAddress(const QByteArray &address) +{ + Q_D(WirelessSetting); + + d->assignedMacAddress = NetworkManager::macAddressAsString(address); +} + +QByteArray NetworkManager::WirelessSetting::clonedMacAddress() const +{ + Q_D(const WirelessSetting); + + return NetworkManager::macAddressFromString(d->assignedMacAddress.toUtf8()); +} + +void NetworkManager::WirelessSetting::setGenerateMacAddressMask(const QString &macAddressMask) +{ + Q_D(WirelessSetting); + + d->generateMacAddressMask = macAddressMask; +} + +QString NetworkManager::WirelessSetting::generateMacAddressMask() const +{ + Q_D(const WirelessSetting); + + return d->generateMacAddressMask; +} + +void NetworkManager::WirelessSetting::setMacAddressBlacklist(const QStringList &list) +{ + Q_D(WirelessSetting); + + d->macAddressBlacklist = list; +} + +QStringList NetworkManager::WirelessSetting::macAddressBlacklist() const +{ + Q_D(const WirelessSetting); + + return d->macAddressBlacklist; +} + +void NetworkManager::WirelessSetting::setMacAddressRandomization(NetworkManager::Setting::MacAddressRandomization randomization) +{ + Q_D(WirelessSetting); + + d->macAddressRandomization = randomization; +} + +NetworkManager::Setting::MacAddressRandomization NetworkManager::WirelessSetting::macAddressRandomization() const +{ + Q_D(const WirelessSetting); + + return d->macAddressRandomization; +} + +void NetworkManager::WirelessSetting::setMtu(quint32 mtu) +{ + Q_D(WirelessSetting); + + d->mtu = mtu; +} + +quint32 NetworkManager::WirelessSetting::mtu() const +{ + Q_D(const WirelessSetting); + + return d->mtu; +} + +void NetworkManager::WirelessSetting::setSeenBssids(const QStringList &list) +{ + Q_D(WirelessSetting); + + d->seenBssids = list; +} + +QStringList NetworkManager::WirelessSetting::seenBssids() const +{ + Q_D(const WirelessSetting); + + return d->seenBssids; +} + +void NetworkManager::WirelessSetting::setPowerSave(NetworkManager::WirelessSetting::PowerSave powersave) +{ + Q_D(WirelessSetting); + + d->powersave = powersave; +} + +NetworkManager::WirelessSetting::PowerSave NetworkManager::WirelessSetting::powerSave() const +{ + Q_D(const WirelessSetting); + + return d->powersave; +} + +void NetworkManager::WirelessSetting::setSecurity(const QString &security) +{ + Q_D(WirelessSetting); + + d->security = security; +} + +QString NetworkManager::WirelessSetting::security() const +{ + Q_D(const WirelessSetting); + + return d->security; +} + +void NetworkManager::WirelessSetting::setHidden(bool hidden) +{ + Q_D(WirelessSetting); + + d->hidden = hidden; +} + +bool NetworkManager::WirelessSetting::hidden() const +{ + Q_D(const WirelessSetting); + + return d->hidden; +} + +void NetworkManager::WirelessSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_SSID))) { + setSsid(setting.value(QLatin1String(NM_SETTING_WIRELESS_SSID)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MODE))) { + const QString mode = setting.value(QLatin1String(NM_SETTING_WIRELESS_MODE)).toString(); + if (mode == QLatin1String(NM_SETTING_WIRELESS_MODE_INFRA)) { + setMode(Infrastructure); + } else if (mode == QLatin1String(NM_SETTING_WIRELESS_MODE_ADHOC)) { + setMode(Adhoc); + } else if (mode == QLatin1String(NM_SETTING_WIRELESS_MODE_AP)) { + setMode(Ap); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_BAND))) { + const QString band = setting.value(QLatin1String(NM_SETTING_WIRELESS_BAND)).toString(); + if (band == "a") { + setBand(A); + } else if (band == "bg") { + setBand(Bg); + } + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_CHANNEL))) { + setChannel(setting.value(QLatin1String(NM_SETTING_WIRELESS_CHANNEL)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_BSSID))) { + setBssid(setting.value(QLatin1String(NM_SETTING_WIRELESS_BSSID)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_RATE))) { + setRate(setting.value(QLatin1String(NM_SETTING_WIRELESS_RATE)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_TX_POWER))) { + setTxPower(setting.value(QLatin1String(NM_SETTING_WIRELESS_TX_POWER)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS))) { + setAssignedMacAddress(setting.value(QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS))) { + setMacAddress(setting.value(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK))) { + setGenerateMacAddressMask(setting.value(QLatin1String(NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS))) { + setClonedMacAddress(setting.value(QLatin1String(NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS)).toByteArray()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST))) { + setMacAddressBlacklist(setting.value(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST)).toStringList()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION))) { + setMacAddressRandomization( + static_cast(setting.value(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION)).toUInt())); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MTU))) { + setMtu(setting.value(QLatin1String(NM_SETTING_WIRELESS_MTU)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS))) { + setSeenBssids(setting.value(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS)).toStringList()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_POWERSAVE))) { + setPowerSave(static_cast(setting.value(QLatin1String(NM_SETTING_WIRELESS_POWERSAVE)).toUInt())); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_SEC))) { + setSecurity(setting.value(QLatin1String(NM_SETTING_WIRELESS_SEC)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_HIDDEN))) { + setHidden(setting.value(QLatin1String(NM_SETTING_WIRELESS_HIDDEN)).toBool()); + } +} + +QVariantMap NetworkManager::WirelessSetting::toMap() const +{ + QVariantMap setting; + + if (!ssid().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SSID), ssid()); + } + + if (mode() == Infrastructure) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_MODE), QLatin1String(NM_SETTING_WIRELESS_MODE_INFRA)); + } else if (mode() == Adhoc) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_MODE), QLatin1String(NM_SETTING_WIRELESS_MODE_ADHOC)); + } else if (mode() == Ap) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_MODE), QLatin1String(NM_SETTING_WIRELESS_MODE_AP)); + } + + if (band() != Automatic) { + if (band() == A) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_BAND), "a"); + } else if (band() == Bg) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_BAND), "bg"); + } + } + + if (channel()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_CHANNEL), channel()); + } + + if (!bssid().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_BSSID), bssid()); + } + + if (rate()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_RATE), rate()); + } + + if (txPower()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_TX_POWER), txPower()); + } + + if (!assignedMacAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS), assignedMacAddress()); + } + + if (!macAddress().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS), macAddress()); + } + + if (!generateMacAddressMask().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK), generateMacAddressMask()); + } + + if (!macAddressBlacklist().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST), macAddressBlacklist()); + } + + setting.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION), macAddressRandomization()); + + if (mtu()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_MTU), mtu()); + } + + if (!seenBssids().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS), seenBssids()); + } + + setting.insert(QLatin1String(NM_SETTING_WIRELESS_POWERSAVE), powerSave()); + + if (!security().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SEC), security()); + } + + if (hidden()) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_HIDDEN), hidden()); + } + + return setting; +} + +QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::WirelessSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_WIRELESS_SSID << ": " << setting.ssid() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_MODE << ": " << setting.mode() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_BAND << ": " << setting.band() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_CHANNEL << ": " << setting.channel() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_BSSID << ": " << setting.bssid() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_RATE << ": " << setting.rate() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_TX_POWER << ": " << setting.txPower() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS << ": " << setting.assignedMacAddress() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_MAC_ADDRESS << ": " << setting.macAddress() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK << ": " << setting.generateMacAddressMask() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST << ": " << setting.macAddressBlacklist() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION << ": " << setting.macAddressRandomization() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_MTU << ": " << setting.mtu() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SEEN_BSSIDS << ": " << setting.seenBssids() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_POWERSAVE << ": " << setting.powerSave() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_SEC << ": " << setting.security() << '\n'; + dbg.nospace() << NM_SETTING_WIRELESS_HIDDEN << ": " << setting.hidden() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting.h b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting.h new file mode 100644 index 000000000..62c4df5a7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting.h @@ -0,0 +1,125 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRELESS_SETTING_H +#define NETWORKMANAGERQT_WIRELESS_SETTING_H + +#include "setting.h" +#include + +#include +#include + +namespace NetworkManager +{ +class WirelessSettingPrivate; + +/** + * Represents wireless setting + */ +class NETWORKMANAGERQT_EXPORT WirelessSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + enum NetworkMode { + Infrastructure, + Adhoc, + Ap, + }; + + enum FrequencyBand { + Automatic, + A, + Bg, + }; + + enum PowerSave { + PowerSaveDefault = 0, + PowerSaveIgnore = 1, + PowerSaveDisable = 2, + PowerSaveEnable = 3, + }; + + WirelessSetting(); + explicit WirelessSetting(const Ptr &setting); + ~WirelessSetting() override; + + QString name() const override; + + void setSsid(const QByteArray &ssid); + QByteArray ssid() const; + + void setMode(NetworkMode mode); + NetworkMode mode() const; + + void setBand(FrequencyBand band); + FrequencyBand band() const; + + void setChannel(quint32 channel); + quint32 channel() const; + + void setBssid(const QByteArray &bssid); + QByteArray bssid() const; + + void setRate(quint32 rate); + quint32 rate() const; + + void setTxPower(quint32 power); + quint32 txPower() const; + + void setAssignedMacAddress(const QString &assignedMacAddress); + QString assignedMacAddress() const; + + void setMacAddress(const QByteArray &address); + QByteArray macAddress() const; + + /// @deprecated since NM 1.4.0, will internally use assigned-mac-address property + void setClonedMacAddress(const QByteArray &address); + QByteArray clonedMacAddress() const; + + void setGenerateMacAddressMask(const QString &macAddressMask); + QString generateMacAddressMask() const; + + void setMacAddressBlacklist(const QStringList &list); + QStringList macAddressBlacklist() const; + + void setMacAddressRandomization(MacAddressRandomization randomization); + MacAddressRandomization macAddressRandomization() const; + + void setMtu(quint32 mtu); + quint32 mtu() const; + + void setSeenBssids(const QStringList &list); + QStringList seenBssids() const; + + void setPowerSave(PowerSave powersave); + PowerSave powerSave() const; + + /// @deprecated since NM 1.0.0 + void setSecurity(const QString &security); + QString security() const; + + void setHidden(bool hidden); + bool hidden() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + WirelessSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(WirelessSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const WirelessSetting &setting); + +} + +#endif // NETWORKMANAGERQT_WIRELESS_SETTING_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting_p.h b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting_p.h new file mode 100644 index 000000000..6856c5c51 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings/wirelesssetting_p.h @@ -0,0 +1,42 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRELESS_SETTING_P_H +#define NETWORKMANAGERQT_WIRELESS_SETTING_P_H + +#include + +namespace NetworkManager +{ +class WirelessSettingPrivate +{ +public: + WirelessSettingPrivate(); + + QString name; + QByteArray ssid; + NetworkManager::WirelessSetting::NetworkMode mode; + NetworkManager::WirelessSetting::FrequencyBand band; + quint32 channel; + QByteArray bssid; + quint32 rate; + quint32 txPower; + QByteArray macAddress; + QByteArray clonedMacAddress; + QStringList macAddressBlacklist; + quint32 mtu; + QStringList seenBssids; + QString security; + bool hidden; + QString generateMacAddressMask; + NetworkManager::Setting::MacAddressRandomization macAddressRandomization; + NetworkManager::WirelessSetting::PowerSave powersave; + QString assignedMacAddress; +}; + +} + +#endif // NETWORKMANAGERQT_WIRELESS_SETTING_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/settings_p.h b/panels/dock/tray/networkmanager-qt/src/settings_p.h new file mode 100644 index 000000000..d3bcd254b --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/settings_p.h @@ -0,0 +1,57 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_SETTINGS_P_H +#define NETWORKMANAGERQT_SETTINGS_P_H + +#include + +#include "dbus/settingsinterface.h" +#include "settings.h" + +class QDBusPendingCallWatcher; + +namespace NetworkManager +{ +class SettingsPrivate : public NetworkManager::SettingsNotifier +{ + Q_OBJECT + friend class NetworkManagerPrivate; + +public: + SettingsPrivate(); + Connection::List listConnections(); + NetworkManager::Connection::Ptr findConnectionByUuid(const QString &uuid); + QString hostname() const; + bool canModify() const; + QDBusPendingReply addConnection(const NMVariantMapMap &); + QDBusPendingReply addConnectionUnsaved(const NMVariantMapMap &); + QDBusPendingReply loadConnections(const QStringList &filenames); + void saveHostname(const QString &); + QDBusPendingReply reloadConnections(); + Connection::Ptr findRegisteredConnection(const QString &); + + OrgFreedesktopNetworkManagerSettingsInterface iface; + QMap connections; + bool m_canModify; + QString m_hostname; +protected Q_SLOTS: + void onConnectionAdded(const QDBusObjectPath &); + void onConnectionRemoved(const QDBusObjectPath &); + void onConnectionRemoved(const QString &); + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void propertiesChanged(const QVariantMap &properties); + void initNotifier(); + +protected: + void daemonUnregistered(); + void init(); +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/teamdevice.cpp b/panels/dock/tray/networkmanager-qt/src/teamdevice.cpp new file mode 100644 index 000000000..2dfb57e2c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/teamdevice.cpp @@ -0,0 +1,97 @@ +/* + SPDX-FileCopyrightText: 2013 Lukáš Tinkl + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "device_p.h" +#include "manager.h" +#include "manager_p.h" +#include "teamdevice_p.h" + +NetworkManager::TeamDevicePrivate::TeamDevicePrivate(const QString &path, TeamDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::TeamDevicePrivate::~TeamDevicePrivate() +{ +} + +NetworkManager::TeamDevice::TeamDevice(const QString &path, QObject *parent) + : Device(*new TeamDevicePrivate(path, this), parent) +{ + Q_D(TeamDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::TeamDevice::~TeamDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::TeamDevice::type() const +{ + return NetworkManager::Device::Team; +} + +bool NetworkManager::TeamDevice::carrier() const +{ + Q_D(const TeamDevice); + + return d->carrier; +} + +QString NetworkManager::TeamDevice::hwAddress() const +{ + Q_D(const TeamDevice); + + return d->hwAddress; +} + +QStringList NetworkManager::TeamDevice::slaves() const +{ + Q_D(const TeamDevice); + return d->slaves; +} + +QString NetworkManager::TeamDevice::config() const +{ + Q_D(const TeamDevice); + return d->config; +} + +void NetworkManager::TeamDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(TeamDevice); + + if (property == QLatin1String("Carrier")) { + carrier = value.toBool(); + Q_EMIT q->carrierChanged(carrier); + } else if (property == QLatin1String("HwAddress")) { + hwAddress = value.toString(); + Q_EMIT q->hwAddressChanged(hwAddress); + } else if (property == QLatin1String("Slaves")) { + QStringList list; + const QList opList = qdbus_cast>(value); + for (const QDBusObjectPath &op : opList) { + list << op.path(); + } + slaves = list; + Q_EMIT q->slavesChanged(slaves); + } else if (property == QLatin1String("Config")) { + config = value.toString(); + Q_EMIT q->configChanged(config); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/teamdevice.h b/panels/dock/tray/networkmanager-qt/src/teamdevice.h new file mode 100644 index 000000000..854b4eb0c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/teamdevice.h @@ -0,0 +1,82 @@ +/* + SPDX-FileCopyrightText: 2013 Lukáš Tinkl + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TEAM_DEVICE_H +#define NETWORKMANAGERQT_TEAM_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class TeamDevicePrivate; + +/** + * A team device interface + */ +class NETWORKMANAGERQT_EXPORT TeamDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(bool carrier READ carrier NOTIFY carrierChanged) + Q_PROPERTY(QString hwAddress READ hwAddress NOTIFY hwAddressChanged) + Q_PROPERTY(QStringList slaves READ slaves NOTIFY slavesChanged) + Q_PROPERTY(QString config READ config NOTIFY configChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + + explicit TeamDevice(const QString &path, QObject *parent = nullptr); + ~TeamDevice() override; + + Type type() const override; + + /** + * Indicates whether the physical carrier is found + */ + bool carrier() const; + /** + * Hardware address of the device + */ + QString hwAddress() const; + + /** + * Devices which are currently slaved to this device + */ + QStringList slaves() const; + + /** + * The JSON configuration currently applied on the device. + */ + QString config() const; + +Q_SIGNALS: + /** + * Emitted when the carrier of this device has changed + */ + void carrierChanged(bool plugged); + /** + * Emitted when the hardware address of this device has changed + */ + void hwAddressChanged(const QString &address); + + /** + * Emitted when the list of devices slaved to this device has changed + */ + void slavesChanged(const QStringList &slaves); + + /** + * Emitted when the JSON confugration which is currently applied has changed + */ + void configChanged(const QString &config); + +private: + Q_DECLARE_PRIVATE(TeamDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/teamdevice_p.h b/panels/dock/tray/networkmanager-qt/src/teamdevice_p.h new file mode 100644 index 000000000..1267fa17c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/teamdevice_p.h @@ -0,0 +1,43 @@ +/* + SPDX-FileCopyrightText: 2012-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TEAM_DEVICE_P_H +#define NETWORKMANAGERQT_TEAM_DEVICE_P_H + +#include "device_p.h" +#include "manager.h" +#include "manager_p.h" +#include "teamdevice.h" + +#include "teamdeviceinterface.h" + +namespace NetworkManager +{ +class TeamDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + TeamDevicePrivate(const QString &path, TeamDevice *q); + ~TeamDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceTeamInterface iface; + bool carrier; + QString config; + QString hwAddress; + QStringList slaves; + + Q_DECLARE_PUBLIC(TeamDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/tundevice.cpp b/panels/dock/tray/networkmanager-qt/src/tundevice.cpp new file mode 100644 index 000000000..41406addf --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/tundevice.cpp @@ -0,0 +1,115 @@ +/* + SPDX-FileCopyrightText: 2013 Lukáš Tinkl + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "manager_p.h" +#include "tundevice_p.h" + +NetworkManager::TunDevicePrivate::TunDevicePrivate(const QString &path, TunDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::TunDevicePrivate::~TunDevicePrivate() +{ +} + +NetworkManager::TunDevice::TunDevice(const QString &path, QObject *parent) + : Device(*new TunDevicePrivate(path, this), parent) +{ + Q_D(TunDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::TunDevice::~TunDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::TunDevice::type() const +{ + return NetworkManager::Device::Tun; +} + +qlonglong NetworkManager::TunDevice::owner() const +{ + Q_D(const TunDevice); + return d->owner; +} + +qlonglong NetworkManager::TunDevice::group() const +{ + Q_D(const TunDevice); + return d->group; +} + +QString NetworkManager::TunDevice::mode() const +{ + Q_D(const TunDevice); + return d->mode; +} + +bool NetworkManager::TunDevice::multiQueue() const +{ + Q_D(const TunDevice); + return d->multiQueue; +} + +bool NetworkManager::TunDevice::noPi() const +{ + Q_D(const TunDevice); + return d->noPi; +} + +bool NetworkManager::TunDevice::vnetHdr() const +{ + Q_D(const TunDevice); + return d->vnetHdr; +} + +QString NetworkManager::TunDevice::hwAddress() const +{ + Q_D(const TunDevice); + return d->hwAddress; +} + +void NetworkManager::TunDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(TunDevice); + + if (property == QLatin1String("Owner")) { + owner = value.toLongLong(); + Q_EMIT q->ownerChanged(owner); + } else if (property == QLatin1String("Group")) { + group = value.toLongLong(); + Q_EMIT q->groupChanged(group); + } else if (property == QLatin1String("Mode")) { + mode = value.toString(); + Q_EMIT q->modeChanged(mode); + } else if (property == QLatin1String("MultiQueue")) { + multiQueue = value.toBool(); + Q_EMIT q->multiQueueChanged(multiQueue); + } else if (property == QLatin1String("NoPi")) { + noPi = value.toBool(); + Q_EMIT q->noPiChanged(noPi); + } else if (property == QLatin1String("VnetHdr")) { + vnetHdr = value.toBool(); + Q_EMIT q->vnetHdrChanged(vnetHdr); + } else if (property == QLatin1String("HwAddress")) { + hwAddress = value.toString(); + Q_EMIT q->hwAddressChanged(hwAddress); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/tundevice.h b/panels/dock/tray/networkmanager-qt/src/tundevice.h new file mode 100644 index 000000000..44a2e0d74 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/tundevice.h @@ -0,0 +1,105 @@ +/* + SPDX-FileCopyrightText: 2013 Lukáš Tinkl + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TUN_DEVICE_H +#define NETWORKMANAGERQT_TUN_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class TunDevicePrivate; + +/** + * A tun device interface + */ +class NETWORKMANAGERQT_EXPORT TunDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(qlonglong owner READ owner NOTIFY ownerChanged) + Q_PROPERTY(qlonglong group READ group NOTIFY groupChanged) + Q_PROPERTY(QString mode READ mode NOTIFY modeChanged) + Q_PROPERTY(bool multiQueue READ multiQueue NOTIFY multiQueueChanged) + Q_PROPERTY(bool noPi READ noPi NOTIFY noPiChanged) + Q_PROPERTY(bool vnetHdr READ vnetHdr NOTIFY vnetHdrChanged) + Q_PROPERTY(QString hwAddress READ hwAddress NOTIFY hwAddressChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit TunDevice(const QString &path, QObject *parent = nullptr); + ~TunDevice() override; + + Type type() const override; + + /** + * The uid of the tunnel owner, or -1 if it has no owner. + */ + qlonglong owner() const; + /** + * The gid of the tunnel group, or -1 if it has no owner. + */ + qlonglong group() const; + /** + * The tunnel mode, either "tun" or "tap". + */ + QString mode() const; + /** + * The tunnel's "TUN_TAP_MQ" flag; true if callers can connect to the tap device multiple times, for multiple send/receive queues. + */ + bool multiQueue() const; + /** + * The tunnel's "TUN_NO_PI" flag; true if no protocol info is prepended to the tunnel packets. + */ + bool noPi() const; + /** + * The tunnel's "TUN_VNET_HDR" flag; true if the tunnel packets include a virtio network header. + */ + bool vnetHdr() const; + /** + * Hardware address of the device. + */ + QString hwAddress() const; + +Q_SIGNALS: + /** + * Emitted when the uid of the tunnel owner has changed + */ + void ownerChanged(qlonglong owner); + /** + * Emitted when the gid of the tunnel group has changed + */ + void groupChanged(qlonglong group); + /** + * Emitted when the tunnel mode has changed + */ + void modeChanged(const QString &mode); + /** + * Emitted when the tunnel's "TUN_TAP_MQ" flag has changed + */ + void multiQueueChanged(bool multiQueue); + /** + * Emitted when the tunnel's "TUN_NO_PI" flag has changed + */ + void noPiChanged(bool noPi); + /** + * Emitted when the tunnel's "TUN_VNET_HDR" flag has changed + */ + void vnetHdrChanged(bool vnetHdr); + /** + * Emitted when the hardware address of the device has changed + */ + void hwAddressChanged(const QString &hwAddress); + +private: + Q_DECLARE_PRIVATE(TunDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/tundevice_p.h b/panels/dock/tray/networkmanager-qt/src/tundevice_p.h new file mode 100644 index 000000000..dabfe7887 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/tundevice_p.h @@ -0,0 +1,43 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_TUN_DEVICE_P_H +#define NETWORKMANAGERQT_TUN_DEVICE_P_H + +#include "device_p.h" +#include "tundevice.h" +#include "tundeviceinterface.h" + +namespace NetworkManager +{ +class TunDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + TunDevicePrivate(const QString &path, TunDevice *q); + ~TunDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceTunInterface iface; + qlonglong owner; + qlonglong group; + QString mode; + bool multiQueue; + bool noPi; + bool vnetHdr; + QString hwAddress; + + Q_DECLARE_PUBLIC(TunDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/utils.cpp b/panels/dock/tray/networkmanager-qt/src/utils.cpp new file mode 100644 index 000000000..2acc7f230 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/utils.cpp @@ -0,0 +1,612 @@ +/* + SPDX-FileCopyrightText: 2009 Will Stephenson + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include + +#include "time.h" +#include "utils.h" + +QHostAddress NetworkManager::ipv6AddressAsHostAddress(const QByteArray &address) +{ + // Q_ASSERT(address.size() == 16); + Q_IPV6ADDR tmp; + for (int i = 0; i < 16; ++i) { + tmp[i] = address[i]; + } + QHostAddress hostaddress(tmp); + Q_ASSERT(hostaddress.protocol() == QAbstractSocket::IPv6Protocol); + + return hostaddress; +} + +QByteArray NetworkManager::ipv6AddressFromHostAddress(const QHostAddress &address) +{ + // Q_ASSERT(address.protocol() == QAbstractSocket::IPv6Protocol); + Q_IPV6ADDR tmp = address.toIPv6Address(); + QByteArray assembledAddress; + assembledAddress.reserve(16); + for (int i = 0; i < 16; ++i) { + assembledAddress.push_back(tmp[i]); + } + + return assembledAddress; +} + +QString NetworkManager::macAddressAsString(const QByteArray &ba) +{ + QStringList mac; + + for (int i = 0; i < ba.size(); ++i) { + mac << QString("%1").arg((quint8)ba[i], 2, 16, QLatin1Char('0')).toUpper(); + } + + return mac.join(":"); +} + +QByteArray NetworkManager::macAddressFromString(const QString &s) +{ + const QStringList macStringList = s.split(':'); + // Q_ASSERT(macStringList.size() == 6); + QByteArray ba; + if (!s.isEmpty()) { + ba.resize(6); + int i = 0; + + for (const QString &macPart : macStringList) { + ba[i++] = macPart.toUInt(nullptr, 16); + } + } + return ba; +} + +bool NetworkManager::macAddressIsValid(const QString &macAddress) +{ + QRegularExpression macAddressCheck(QStringLiteral("([a-fA-F0-9][a-fA-F0-9]:){5}[0-9a-fA-F][0-9a-fA-F]")); + + return macAddressCheck.match(macAddress).hasMatch(); +} + +bool NetworkManager::macAddressIsValid(const QByteArray &macAddress) +{ + return macAddressIsValid(macAddressAsString(macAddress)); +} + +int NetworkManager::findChannel(int freq) +{ + int channel; + if (freq < 2500) { + channel = 0; + int i = 0; + QList> bFreqs = getBFreqs(); + while (i < bFreqs.size()) { + if (bFreqs.at(i).second <= freq) { + channel = bFreqs.at(i).first; + } else { + break; + } + i++; + } + return channel; + } + channel = 0; + int i = 0; + QList> aFreqs = getAFreqs(); + while (i < aFreqs.size()) { + if (aFreqs.at(i).second <= freq) { + channel = aFreqs.at(i).first; + } else { + break; + } + i++; + } + + return channel; +} + +NetworkManager::WirelessSetting::FrequencyBand NetworkManager::findFrequencyBand(int freq) +{ + if (freq < 2500) { + return WirelessSetting::Bg; + } + + return WirelessSetting::A; +} + +bool NetworkManager::deviceSupportsApCiphers(NetworkManager::WirelessDevice::Capabilities interfaceCaps, + NetworkManager::AccessPoint::WpaFlags apCiphers, + WirelessSecurityType type) +{ + bool havePair = false; + bool haveGroup = true; + + if (type == NetworkManager::StaticWep) { + havePair = true; + } else { + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep40) && apCiphers.testFlag(NetworkManager::AccessPoint::PairWep40)) { + havePair = true; + } + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep104) && apCiphers.testFlag(NetworkManager::AccessPoint::PairWep104)) { + havePair = true; + } + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip) && apCiphers.testFlag(NetworkManager::AccessPoint::PairTkip)) { + havePair = true; + } + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp) && apCiphers.testFlag(NetworkManager::AccessPoint::PairCcmp)) { + havePair = true; + } + } + + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep40) && apCiphers.testFlag(NetworkManager::AccessPoint::GroupWep40)) { + haveGroup = true; + } + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep104) && apCiphers.testFlag(NetworkManager::AccessPoint::GroupWep104)) { + haveGroup = true; + } + if (type != StaticWep) { + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip) && apCiphers.testFlag(NetworkManager::AccessPoint::GroupTkip)) { + haveGroup = true; + } + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp) && apCiphers.testFlag(NetworkManager::AccessPoint::GroupCcmp)) { + haveGroup = true; + } + } + + return (havePair && haveGroup); +} + +// Keep this in sync with NetworkManager/libnm-core/nm-utils.c:nm_utils_security_valid() +bool NetworkManager::securityIsValid(WirelessSecurityType type, + NetworkManager::WirelessDevice::Capabilities interfaceCaps, + bool haveAp, + bool adhoc, + NetworkManager::AccessPoint::Capabilities apCaps, + NetworkManager::AccessPoint::WpaFlags apWpa, + NetworkManager::AccessPoint::WpaFlags apRsn) +{ + bool good = true; + + // kDebug() << "type(" << type << ") interfaceCaps(" << interfaceCaps << ") haveAp(" << haveAp << ") adhoc(" << adhoc << ") apCaps(" << apCaps << ") apWpa(" + // << apWpa << " apRsn(" << apRsn << ")"; + + if (!haveAp) { + if (type == NoneSecurity) { + return true; + } + if ((type == StaticWep) // + || ((type == DynamicWep) && !adhoc) // + || ((type == Leap) && !adhoc)) { + if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep40) || interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep104)) { + return true; + } else { + return false; + } + } + + // apCaps.testFlag(Privacy) == true for StaticWep, Leap and DynamicWep + // see libs/internals/wirelessinterfaceconnectionhelpers.cpp + + // TODO: this is not in nm-utils.c + // if (type == Knm::WirelessSecurity::WpaPsk + // || ((type == Knm::WirelessSecurity::WpaEap) && !adhoc)) { + // if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wpa) && + // !apCaps.testFlag(NetworkManager::AccessPoint::Privacy)) { + // return true; + // } + // } + // if (type == Knm::WirelessSecurity::Wpa2Psk + // || ((type == Knm::WirelessSecurity::Wpa2Eap) && !adhoc)) { + // if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn) && + // !apCaps.testFlag(NetworkManager::AccessPoint::Privacy)) { + // return true; + // } + // } + } + + switch (type) { + case NoneSecurity: + Q_ASSERT(haveAp); + if (apCaps.testFlag(NetworkManager::AccessPoint::Privacy)) { + return false; + } + if (apWpa || apRsn) { + return false; + } + break; + case Leap: /* require PRIVACY bit for LEAP? */ + if (adhoc) { + return false; + } + /* Fall through */ + case StaticWep: + Q_ASSERT(haveAp); + if (!apCaps.testFlag(NetworkManager::AccessPoint::Privacy)) { + return false; + } + if (apWpa || apRsn) { + if (!deviceSupportsApCiphers(interfaceCaps, apWpa, StaticWep)) { + if (!deviceSupportsApCiphers(interfaceCaps, apRsn, StaticWep)) { + return false; + } + } + } + break; + case DynamicWep: + if (adhoc) { + return false; + } + Q_ASSERT(haveAp); + if (apRsn || !(apCaps.testFlag(NetworkManager::AccessPoint::Privacy))) { + return false; + } + /* Some APs broadcast minimal WPA-enabled beacons that must be handled */ + if (apWpa) { + if (!apWpa.testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) { + return false; + } + if (!deviceSupportsApCiphers(interfaceCaps, apWpa, DynamicWep)) { + return false; + } + } + break; + case WpaPsk: + if (adhoc) { + return false; + } + + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wpa)) { + return false; + } + if (haveAp) { + if (apWpa.testFlag(NetworkManager::AccessPoint::KeyMgmtPsk)) { + if (apWpa.testFlag(NetworkManager::AccessPoint::PairTkip) // + && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip)) { + return true; + } + if (apWpa.testFlag(NetworkManager::AccessPoint::PairCcmp) // + && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { + return true; + } + } + return false; + } + break; + case Wpa2Psk: + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn)) { + return false; + } + if (haveAp) { + if (adhoc) { + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::IBSSRsn)) { + return false; + } + if (apRsn.testFlag(NetworkManager::AccessPoint::PairCcmp) // + && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { + return true; + } + } else { + if (apRsn.testFlag(NetworkManager::AccessPoint::KeyMgmtPsk)) { + if (apRsn.testFlag(NetworkManager::AccessPoint::PairTkip) // + && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip)) { + return true; + } + if (apRsn.testFlag(NetworkManager::AccessPoint::PairCcmp) // + && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { + return true; + } + } + } + return false; + } + break; + case WpaEap: + if (adhoc) { + return false; + } + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wpa)) { + return false; + } + if (haveAp) { + if (!apWpa.testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) { + return false; + } + /* Ensure at least one WPA cipher is supported */ + if (!deviceSupportsApCiphers(interfaceCaps, apWpa, WpaEap)) { + return false; + } + } + break; + case Wpa2Eap: + if (adhoc) { + return false; + } + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn)) { + return false; + } + if (haveAp) { + if (!apRsn.testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) { + return false; + } + /* Ensure at least one WPA cipher is supported */ + if (!deviceSupportsApCiphers(interfaceCaps, apRsn, Wpa2Eap)) { + return false; + } + } + break; + case SAE: + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn)) { + return false; + } + if (haveAp) { + if (adhoc) { + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::IBSSRsn)) { + return false; + } + if (apRsn.testFlag(NetworkManager::AccessPoint::PairCcmp) // + && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { + return true; + } + } else { + if (apRsn.testFlag(NetworkManager::AccessPoint::KeyMgmtSAE)) { + if (apRsn.testFlag(NetworkManager::AccessPoint::PairTkip) // + && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip)) { + return true; + } + if (apRsn.testFlag(NetworkManager::AccessPoint::PairCcmp) // + && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { + return true; + } + } + } + return false; + } + break; + case Wpa3SuiteB192: + if (adhoc) { + return false; + } + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn)) { + return false; + } + if (haveAp && !apRsn.testFlag(NetworkManager::AccessPoint::KeyMgmtEapSuiteB192)) { + return false; + } + break; + default: + good = false; + break; + } + + return good; +} + +NetworkManager::WirelessSecurityType NetworkManager::findBestWirelessSecurity(NetworkManager::WirelessDevice::Capabilities interfaceCaps, + bool haveAp, + bool adHoc, + NetworkManager::AccessPoint::Capabilities apCaps, + NetworkManager::AccessPoint::WpaFlags apWpa, + NetworkManager::AccessPoint::WpaFlags apRsn) +{ + // The ordering of this list is a pragmatic combination of security level and popularity. + // Therefore static WEP is before LEAP and Dynamic WEP because there is no way to detect + // if an AP is capable of Dynamic WEP and showing Dynamic WEP first would confuse + // Static WEP users. + const QList types = {NetworkManager::Wpa3SuiteB192, + NetworkManager::SAE, + NetworkManager::Wpa2Eap, + NetworkManager::Wpa2Psk, + NetworkManager::WpaEap, + NetworkManager::WpaPsk, + NetworkManager::StaticWep, + NetworkManager::DynamicWep, + NetworkManager::Leap, + NetworkManager::NoneSecurity}; + + for (NetworkManager::WirelessSecurityType type : types) { + if (NetworkManager::securityIsValid(type, interfaceCaps, haveAp, adHoc, apCaps, apWpa, apRsn)) { + return type; + } + } + return NetworkManager::UnknownSecurity; +} + +bool NetworkManager::wepKeyIsValid(const QString &key, NetworkManager::WirelessSecuritySetting::WepKeyType type) +{ + if (key.isEmpty()) { + return false; + } + + const int keylen = key.length(); + + if (type != WirelessSecuritySetting::NotSpecified) { + if (type == WirelessSecuritySetting::Hex) { + if (keylen == 10 || keylen == 26) { + /* Hex key */ + for (int i = 0; i < keylen; ++i) { + if (!(key.at(i).isDigit() || (key.at(i) >= 'A' && key.at(i) <= 'F') || (key.at(i) >= 'a' && key.at(i) <= 'f'))) { + return false; + } + } + return true; + } else if (keylen == 5 || keylen == 13) { + /* ASCII KEY */ + for (int i = 0; i < keylen; ++i) { + if (!key.at(i).isPrint()) { + return false; + } + } + return true; + } + + return false; + } else if (type == WirelessSecuritySetting::Passphrase) { + if (!keylen || keylen > 64) { + return false; + } + + return true; + } + } + + return false; +} + +bool NetworkManager::wpaPskIsValid(const QString &psk) +{ + if (psk.isEmpty()) { + return false; + } + + const int psklen = psk.length(); + + if (psklen < 8 || psklen > 64) { + return false; + } + + if (psklen == 64) { + /* Hex PSK */ + for (int i = 0; i < psklen; ++i) { + if (!psk.at(i).isLetterOrNumber()) { + return false; + } + } + } + + return true; +} + +NetworkManager::WirelessSecurityType NetworkManager::securityTypeFromConnectionSetting(const NetworkManager::ConnectionSettings::Ptr &settings) +{ + NetworkManager::WirelessSecuritySetting::Ptr wifiSecuritySetting = settings->setting(Setting::WirelessSecurity).dynamicCast(); + if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::Wep) { + return StaticWep; + } else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::Ieee8021x) { + if (wifiSecuritySetting->authAlg() == WirelessSecuritySetting::Leap) { + return Leap; + } else { + return DynamicWep; + } + } else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::WpaPsk) { + if (wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Wpa) && !wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Rsn)) { + return WpaPsk; + } + return Wpa2Psk; + } else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::WpaEap) { + if (wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Wpa) && !wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Rsn)) { + return WpaEap; + } + return Wpa2Eap; + } else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::SAE) { + return SAE; + } else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::WpaEapSuiteB192) { + return Wpa3SuiteB192; + } + + return NoneSecurity; +} + +QList> NetworkManager::getBFreqs() +{ + QList> freqs; + + freqs.append(QPair(1, 2412)); + freqs.append(QPair(2, 2417)); + freqs.append(QPair(3, 2422)); + freqs.append(QPair(4, 2427)); + freqs.append(QPair(5, 2432)); + freqs.append(QPair(6, 2437)); + freqs.append(QPair(7, 2442)); + freqs.append(QPair(8, 2447)); + freqs.append(QPair(9, 2452)); + freqs.append(QPair(10, 2457)); + freqs.append(QPair(11, 2462)); + freqs.append(QPair(12, 2467)); + freqs.append(QPair(13, 2472)); + freqs.append(QPair(14, 2484)); + + return freqs; +} + +QList> NetworkManager::getAFreqs() +{ + QList> freqs; + + freqs.append(QPair(7, 5035)); + freqs.append(QPair(8, 5040)); + freqs.append(QPair(9, 5045)); + freqs.append(QPair(11, 5055)); + freqs.append(QPair(12, 5060)); + freqs.append(QPair(16, 5080)); + freqs.append(QPair(34, 5170)); + freqs.append(QPair(36, 5180)); + freqs.append(QPair(38, 5190)); + freqs.append(QPair(40, 5200)); + freqs.append(QPair(42, 5210)); + freqs.append(QPair(44, 5220)); + freqs.append(QPair(46, 5230)); + freqs.append(QPair(48, 5240)); + freqs.append(QPair(52, 5260)); + freqs.append(QPair(56, 5280)); + freqs.append(QPair(60, 5300)); + freqs.append(QPair(64, 5320)); + freqs.append(QPair(100, 5500)); + freqs.append(QPair(104, 5520)); + freqs.append(QPair(108, 5540)); + freqs.append(QPair(112, 5560)); + freqs.append(QPair(116, 5580)); + freqs.append(QPair(120, 5600)); + freqs.append(QPair(124, 5620)); + freqs.append(QPair(128, 5640)); + freqs.append(QPair(132, 5660)); + freqs.append(QPair(136, 5680)); + freqs.append(QPair(140, 5700)); + freqs.append(QPair(149, 5745)); + freqs.append(QPair(153, 5765)); + freqs.append(QPair(157, 5785)); + freqs.append(QPair(161, 5805)); + freqs.append(QPair(165, 5825)); + freqs.append(QPair(183, 4915)); + freqs.append(QPair(184, 4920)); + freqs.append(QPair(185, 4925)); + freqs.append(QPair(187, 4935)); + freqs.append(QPair(188, 4940)); + freqs.append(QPair(189, 4945)); + freqs.append(QPair(192, 4960)); + freqs.append(QPair(196, 4980)); + + return freqs; +} + +QDateTime NetworkManager::clockBootTimeToDateTime(qlonglong clockBootime) +{ + clockid_t clk_id = CLOCK_BOOTTIME; + struct timespec tp; + int r; + + // now is used as a point of reference + // with the timespec that contains the number of msec since boot + QDateTime now = QDateTime::currentDateTime(); + r = clock_gettime(clk_id, &tp); + if (r == -1 && errno == EINVAL) { + clk_id = CLOCK_MONOTONIC; + r = clock_gettime(clk_id, &tp); + } + + // convert to msecs + long now_msecs = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; + + // diff the msecs and construct a QDateTime based on the offset + QDateTime res; + if (clockBootime > now_msecs) { + qlonglong offset = clockBootime - now_msecs; + res = QDateTime::fromMSecsSinceEpoch(now.toMSecsSinceEpoch() + offset); + } else { + qlonglong offset = now_msecs - clockBootime; + res = QDateTime::fromMSecsSinceEpoch(now.toMSecsSinceEpoch() - offset); + } + + return res; +} diff --git a/panels/dock/tray/networkmanager-qt/src/utils.h b/panels/dock/tray/networkmanager-qt/src/utils.h new file mode 100644 index 000000000..ab2843ff7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/utils.h @@ -0,0 +1,99 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_UTILS_H +#define NETWORKMANAGERQT_UTILS_H + +#include +#include + +#include "wirelessdevice.h" +#include "wirelesssecuritysetting.h" +#include "wirelesssetting.h" +#include + +namespace NetworkManager +{ +enum WirelessSecurityType { + UnknownSecurity = -1, + NoneSecurity, + StaticWep, + DynamicWep, + Leap, + WpaPsk, + WpaEap, + Wpa2Psk, + Wpa2Eap, + SAE, + Wpa3SuiteB192, +}; + +/** + * @return QHostAddress representation of an ipv6 address + * @param address byte array containing the binary representation of the address + */ +NETWORKMANAGERQT_EXPORT QHostAddress ipv6AddressAsHostAddress(const QByteArray &address); + +/** + * @return binary representation of an ipv6 address + * @param address qhostaddress containing the address + */ +NETWORKMANAGERQT_EXPORT QByteArray ipv6AddressFromHostAddress(const QHostAddress &address); + +/** + * @return String representation of a mac address. + * @param ba byte array containing the binary repesentation of the address + */ +NETWORKMANAGERQT_EXPORT QString macAddressAsString(const QByteArray &ba); + +/** + * @return binary repesentation of a mac address. + * @param s string representation of the address + */ +NETWORKMANAGERQT_EXPORT QByteArray macAddressFromString(const QString &s); + +NETWORKMANAGERQT_EXPORT bool macAddressIsValid(const QString &macAddress); +NETWORKMANAGERQT_EXPORT bool macAddressIsValid(const QByteArray &macAddress); + +/** + * @param freq frequency of a wireless network + * @return The frequency channel. + */ +NETWORKMANAGERQT_EXPORT int findChannel(int freq); + +NETWORKMANAGERQT_EXPORT NetworkManager::WirelessSetting::FrequencyBand findFrequencyBand(int freq); + +NETWORKMANAGERQT_EXPORT bool +deviceSupportsApCiphers(NetworkManager::WirelessDevice::Capabilities, NetworkManager::AccessPoint::WpaFlags ciphers, WirelessSecurityType type); + +NETWORKMANAGERQT_EXPORT bool securityIsValid(WirelessSecurityType type, + NetworkManager::WirelessDevice::Capabilities interfaceCaps, + bool haveAp, + bool adHoc, + NetworkManager::AccessPoint::Capabilities apCaps, + NetworkManager::AccessPoint::WpaFlags apWpa, + NetworkManager::AccessPoint::WpaFlags apRsn); + +NETWORKMANAGERQT_EXPORT WirelessSecurityType findBestWirelessSecurity(NetworkManager::WirelessDevice::Capabilities, + bool haveAp, + bool adHoc, + NetworkManager::AccessPoint::Capabilities apCaps, + NetworkManager::AccessPoint::WpaFlags apWpa, + NetworkManager::AccessPoint::WpaFlags apRsn); + +NETWORKMANAGERQT_EXPORT bool wepKeyIsValid(const QString &key, NetworkManager::WirelessSecuritySetting::WepKeyType type); + +NETWORKMANAGERQT_EXPORT bool wpaPskIsValid(const QString &psk); + +NETWORKMANAGERQT_EXPORT WirelessSecurityType securityTypeFromConnectionSetting(const NetworkManager::ConnectionSettings::Ptr &settings); + +NETWORKMANAGERQT_EXPORT QList> getBFreqs(); +NETWORKMANAGERQT_EXPORT QList> getAFreqs(); + +NETWORKMANAGERQT_EXPORT QDateTime clockBootTimeToDateTime(qlonglong clockBootime); +} + +#endif // NETWORKMANAGERQT_UTILS_H diff --git a/panels/dock/tray/networkmanager-qt/src/vethdevice.cpp b/panels/dock/tray/networkmanager-qt/src/vethdevice.cpp new file mode 100644 index 000000000..0230113ab --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vethdevice.cpp @@ -0,0 +1,62 @@ +/* + SPDX-FileCopyrightText: 2013 Lukáš Tinkl + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "manager.h" +#include "manager_p.h" +#include "vethdevice_p.h" + +NetworkManager::VethDevicePrivate::VethDevicePrivate(const QString &path, VethDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::VethDevicePrivate::~VethDevicePrivate() +{ +} + +NetworkManager::VethDevice::VethDevice(const QString &path, QObject *parent) + : Device(*new VethDevicePrivate(path, this), parent) +{ + Q_D(VethDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::VethDevice::~VethDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::VethDevice::type() const +{ + return NetworkManager::Device::Veth; +} + +QString NetworkManager::VethDevice::peer() const +{ + Q_D(const VethDevice); + return d->peer; +} + +void NetworkManager::VethDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(VethDevice); + + if (property == QLatin1String("Peer")) { + peer = value.toString(); + Q_EMIT q->peerChanged(peer); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/vethdevice.h b/panels/dock/tray/networkmanager-qt/src/vethdevice.h new file mode 100644 index 000000000..f2c100c1e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vethdevice.h @@ -0,0 +1,46 @@ +/* + SPDX-FileCopyrightText: 2013 Lukáš Tinkl + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VETH_DEVICE_H +#define NETWORKMANAGERQT_VETH_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class VethDevicePrivate; + +/** + * A veth device interface + */ +class NETWORKMANAGERQT_EXPORT VethDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(QString peer READ peer NOTIFY peerChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + + explicit VethDevice(const QString &path, QObject *parent = nullptr); + ~VethDevice() override; + + Type type() const override; + + QString peer() const; + +Q_SIGNALS: + void peerChanged(const QString &peer); + +private: + Q_DECLARE_PRIVATE(VethDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/vethdevice_p.h b/panels/dock/tray/networkmanager-qt/src/vethdevice_p.h new file mode 100644 index 000000000..2f74b9f4a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vethdevice_p.h @@ -0,0 +1,38 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VETH_DEVICE_P_H +#define NETWORKMANAGERQT_VETH_DEVICE_P_H + +#include "device_p.h" +#include "vethdevice.h" + +#include "vethdeviceinterface.h" + +namespace NetworkManager +{ +class VethDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + VethDevicePrivate(const QString &path, VethDevice *q); + ~VethDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceVethInterface iface; + QString peer; + + Q_DECLARE_PUBLIC(VethDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/vlandevice.cpp b/panels/dock/tray/networkmanager-qt/src/vlandevice.cpp new file mode 100644 index 000000000..8b08e4c07 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vlandevice.cpp @@ -0,0 +1,97 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "device_p.h" +#include "manager.h" +#include "vlandevice_p.h" + +NetworkManager::VlanDevicePrivate::VlanDevicePrivate(const QString &path, VlanDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , carrier(false) +{ +} + +NetworkManager::VlanDevice::~VlanDevice() +{ +} + +NetworkManager::VlanDevice::VlanDevice(const QString &path, QObject *parent) + : Device(*new VlanDevicePrivate(path, this), parent) +{ + Q_D(VlanDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::VlanDevicePrivate::~VlanDevicePrivate() +{ +} + +NetworkManager::Device::Type NetworkManager::VlanDevice::type() const +{ + return NetworkManager::Device::Vlan; +} + +bool NetworkManager::VlanDevice::carrier() const +{ + Q_D(const VlanDevice); + + return d->carrier; +} + +QString NetworkManager::VlanDevice::hwAddress() const +{ + Q_D(const VlanDevice); + + return d->hwAddress; +} + +NetworkManager::Device::Ptr NetworkManager::VlanDevice::parent() const +{ + if (NetworkManager::checkVersion(1, 0, 0)) { + Q_D(const VlanDevice); + + return NetworkManager::findNetworkInterface(d->parent); + } else { + return NetworkManager::Device::Ptr(nullptr); + } +} + +uint NetworkManager::VlanDevice::vlanId() const +{ + Q_D(const VlanDevice); + + return d->vlanId; +} + +void NetworkManager::VlanDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(VlanDevice); + + if (property == QLatin1String("Carrier")) { + carrier = value.toBool(); + Q_EMIT q->carrierChanged(carrier); + } else if (property == QLatin1String("HwAddress")) { + hwAddress = value.toString(); + Q_EMIT q->hwAddressChanged(hwAddress); + } else if (property == QLatin1String("Parent")) { + parent = value.value().path(); + Q_EMIT q->parentChanged(parent); + } else if (property == QLatin1String("VlanId")) { + vlanId = value.toUInt(); + Q_EMIT q->vlanIdChanged(vlanId); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/vlandevice.h b/panels/dock/tray/networkmanager-qt/src/vlandevice.h new file mode 100644 index 000000000..e421ca6b5 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vlandevice.h @@ -0,0 +1,79 @@ +/* + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VLAN_DEVICE_H +#define NETWORKMANAGERQT_VLAN_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class VlanDevicePrivate; + +/** + * A vlan device interface + */ +class NETWORKMANAGERQT_EXPORT VlanDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(bool carrier READ carrier NOTIFY carrierChanged) + Q_PROPERTY(QString hwAddress READ hwAddress NOTIFY hwAddressChanged) + Q_PROPERTY(uint vlanId READ vlanId NOTIFY vlanIdChanged) + Q_PROPERTY(NetworkManager::Device::Ptr parent READ parent NOTIFY parentChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + + explicit VlanDevice(const QString &path, QObject *parent = nullptr); + ~VlanDevice() override; + + Type type() const override; + + /** + * Indicates whether the physical carrier is found + */ + bool carrier() const; + /** + * Hardware address of the device + */ + QString hwAddress() const; + /** + * The parent device of this VLAN device + * @since 5.8.0 + */ + NetworkManager::Device::Ptr parent() const; + /** + * The VLAN ID of this VLAN interface + */ + uint vlanId() const; + +Q_SIGNALS: + /** + * Emitted when the carrier of this device has changed + */ + void carrierChanged(bool plugged); + /** + * Emitted when the hardware address of this device has changed + */ + void hwAddressChanged(const QString &address); + /** + * Emitted when the parent device of this device has changed + */ + void parentChanged(const QString &path); + /** + * Emitted when the VLAN ID of this device has changed + */ + void vlanIdChanged(uint id); + +private: + Q_DECLARE_PRIVATE(VlanDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/vlandevice_p.h b/panels/dock/tray/networkmanager-qt/src/vlandevice_p.h new file mode 100644 index 000000000..42aa47c28 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vlandevice_p.h @@ -0,0 +1,41 @@ +/* + SPDX-FileCopyrightText: 2012-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VLAN_DEVICE_P_H +#define NETWORKMANAGERQT_VLAN_DEVICE_P_H + +#include "device_p.h" +#include "manager_p.h" +#include "vlandevice.h" +#include "vlandeviceinterface.h" + +namespace NetworkManager +{ +class VlanDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + VlanDevicePrivate(const QString &path, VlanDevice *q); + ~VlanDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceVlanInterface iface; + bool carrier; + QString hwAddress; + QString parent; + uint vlanId; + + Q_DECLARE_PUBLIC(VlanDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/vpnconnection.cpp b/panels/dock/tray/networkmanager-qt/src/vpnconnection.cpp new file mode 100644 index 000000000..06f54a189 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vpnconnection.cpp @@ -0,0 +1,131 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "connection.h" +#include "device.h" +#include "nmdebug.h" +#include "settings.h" +#include "vpnconnection_p.h" + +NetworkManager::VpnConnectionPrivate::VpnConnectionPrivate(const QString &path, VpnConnection *q) + : ActiveConnectionPrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , q_ptr(q) +{ +} + +NetworkManager::VpnConnection::State NetworkManager::VpnConnectionPrivate::convertVpnConnectionState(uint state) +{ + return static_cast(state); +} + +NetworkManager::VpnConnection::StateChangeReason NetworkManager::VpnConnectionPrivate::convertVpnConnectionStateReason(uint reason) +{ + return static_cast(reason); +} + +NetworkManager::VpnConnection::VpnConnection(const QString &path, QObject *parent) + : ActiveConnection(*new VpnConnectionPrivate(path, this), parent) +{ + Q_D(VpnConnection); + + QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE, + d->path, + NetworkManagerPrivate::FDO_DBUS_PROPERTIES, + QLatin1String("PropertiesChanged"), + d, + SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList))); + connect(&d->iface, &OrgFreedesktopNetworkManagerVPNConnectionInterface::VpnStateChanged, d, &VpnConnectionPrivate::vpnStateChanged); + + // We need to get ActiveConnection's properties, because by default every ActiveConnection + // is basically a VpnConnection + QVariantMap initialProperties = + NetworkManagerPrivate::retrieveInitialProperties(OrgFreedesktopNetworkManagerConnectionActiveInterface::staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } + + // Try to retrieve VPN specific properties if this is a VPN connection + if (vpn()) { + // Get all VpnConnection's properties at once + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } + } +} + +NetworkManager::VpnConnection::~VpnConnection() +{ +} + +QString NetworkManager::VpnConnection::banner() const +{ + Q_D(const VpnConnection); + // return d->banner; // FIXME NM doesn't Q_EMIT the Banner property change + return d->iface.banner(); +} + +NetworkManager::VpnConnection::State NetworkManager::VpnConnection::state() const +{ + Q_D(const VpnConnection); + return d->state; +} + +void NetworkManager::VpnConnectionPrivate::dbusPropertiesChanged(const QString &interfaceName, + const QVariantMap &properties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(invalidatedProperties); + + if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.VPN.Connection")) { + propertiesChanged(properties); + } else { + ActiveConnectionPrivate::propertiesChanged(properties); + } +} + +void NetworkManager::VpnConnectionPrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(VpnConnection); + + if (property == QLatin1String("Banner")) { + banner = value.toString(); + Q_EMIT q->bannerChanged(banner); + } else if (property == QLatin1String("VpnState")) { + // Do not notify about changed VpnState twice, because there is also signal VpnStateChanged() from NetworkManager + state = NetworkManager::VpnConnectionPrivate::convertVpnConnectionState(value.toUInt()); + // NetworkManager::VpnConnection::StateChangeReason reason = + // NetworkManager::VpnConnectionPrivate::convertVpnConnectionStateReason(properties.key("Reason").toUInt()); Q_EMIT stateChanged(d->state, reason); + } else { + ActiveConnectionPrivate::propertyChanged(property, value); + } +} + +void NetworkManager::VpnConnectionPrivate::vpnStateChanged(uint newState, uint reason) +{ + Q_Q(VpnConnection); + Q_UNUSED(reason); + + state = NetworkManager::VpnConnectionPrivate::convertVpnConnectionState(newState); + NetworkManager::VpnConnection::StateChangeReason stateChangeReason = NetworkManager::VpnConnectionPrivate::convertVpnConnectionStateReason(reason); + Q_EMIT q->stateChanged(state, stateChangeReason); +} + +NetworkManager::VpnConnection::operator VpnConnection *() +{ + Q_D(VpnConnection); + if (d->vpn) { + return this; + } else { + return nullptr; + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/vpnconnection.h b/panels/dock/tray/networkmanager-qt/src/vpnconnection.h new file mode 100644 index 000000000..d6efc58a4 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vpnconnection.h @@ -0,0 +1,104 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VPNCONNECTION_H +#define NETWORKMANAGERQT_VPNCONNECTION_H + +#include + +#include "activeconnection.h" + +#include +#include + +namespace NetworkManager +{ +class Device; +class VpnConnectionPrivate; + +/** + * An active VPN connection + */ +class NETWORKMANAGERQT_EXPORT VpnConnection : public ActiveConnection +{ + Q_OBJECT + +public: + typedef QSharedPointer Ptr; + typedef QList List; + /** + * Enum describing the possible VPN connection states + */ + enum State { + Unknown = 0, /**< The state of the VPN connection is unknown. */ + Prepare, /**< The VPN connection is preparing to connect. */ + NeedAuth, /**< The VPN connection needs authorization credentials. */ + Connecting, /**< The VPN connection is being established. */ + GettingIpConfig, /**< The VPN connection is getting an IP address. */ + Activated, /**< The VPN connection is active. */ + Failed, /**< The VPN connection failed. */ + Disconnected, /**< The VPN connection is disconnected. */ + }; + + enum StateChangeReason { + UnknownReason = 0, /**< The reason for the VPN connection state change is unknown.*/ + NoneReason, /**< No reason was given for the VPN connection state change. */ + UserDisconnectedReason, /**< The VPN connection changed state because the user disconnected it. */ + DeviceDisconnectedReason, /**< The VPN connection changed state because the device it was using was disconnected. */ + ServiceStoppedReason, /**< The service providing the VPN connection was stopped. */ + IpConfigInvalidReason, /**< The IP config of the VPN connection was invalid. */ + ConnectTimeoutReason, /**< The connection attempt to the VPN service timed out. */ + ServiceStartTimeoutReason, /**< A timeout occurred while starting the service providing the VPN connection. */ + ServiceStartFailedReason, /**< Starting the service starting the service providing the VPN connection failed. */ + NoSecretsReason, /**< Necessary secrets for the VPN connection were not provided. */ + LoginFailedReason, /**< Authentication to the VPN server failed. */ + ConnectionRemovedReason, /**< The connection was deleted from settings. */ + }; + + /** + * Creates a new VpnConnection object. + * + * @param path the DBus path of the device + */ + explicit VpnConnection(const QString &path, QObject *parent = nullptr); + /** + * Destroys a VpnConnection object. + */ + ~VpnConnection() override; + /** + * Return the current login banner + */ + QString banner() const; + /** + * returns the current state + */ + NetworkManager::VpnConnection::State state() const; + /** + * operator for casting an ActiveConnection into a VpnConnection. Returns 0 if this + * object is not a VPN connection. Introduced to make it possible to create a VpnConnection + * object for every active connection, without creating an ActiveConnection object, checking + * if it's a VPN connection, deleting the ActiveConnection and creating a VpnConnection + */ + operator VpnConnection *(); + +Q_SIGNALS: + /** + * This signal is emitted when the connection @p banner has changed + */ + void bannerChanged(const QString &banner); + /** + * This signal is emitted when the VPN connection @p state has changed + */ + void stateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason); + +private: + Q_DECLARE_PRIVATE(VpnConnection) +}; + +} // namespace NetworkManager +#endif // NETWORKMANAGERQT_VPNCONNECTION_H diff --git a/panels/dock/tray/networkmanager-qt/src/vpnconnection_p.h b/panels/dock/tray/networkmanager-qt/src/vpnconnection_p.h new file mode 100644 index 000000000..84466eea3 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vpnconnection_p.h @@ -0,0 +1,49 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2013-2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VPNCONNECTION_P_H +#define NETWORKMANAGERQT_VPNCONNECTION_P_H + +#include "activeconnection_p.h" +#include "manager_p.h" +#include "vpnconnection.h" + +#include "vpnconnectioninterface.h" + +namespace NetworkManager +{ +class VpnConnectionPrivate : public ActiveConnectionPrivate +{ + Q_OBJECT +public: + VpnConnectionPrivate(const QString &path, VpnConnection *q); + + static NetworkManager::VpnConnection::State convertVpnConnectionState(uint state); + static NetworkManager::VpnConnection::StateChangeReason convertVpnConnectionStateReason(uint reason); + + QString banner; + NetworkManager::VpnConnection::State state; + OrgFreedesktopNetworkManagerVPNConnectionInterface iface; + + Q_DECLARE_PUBLIC(VpnConnection) + VpnConnection *q_ptr; + +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; + +private Q_SLOTS: + void dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties); + void vpnStateChanged(uint new_state, uint reason); +}; + +} + +#endif // NETWORKMANAGERQT_VPNCONNECTION_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/vpnplugin.cpp b/panels/dock/tray/networkmanager-qt/src/vpnplugin.cpp new file mode 100644 index 000000000..d6be031ac --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vpnplugin.cpp @@ -0,0 +1,118 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "vpnplugin.h" + +#include "manager_p.h" +#include "vpnplugininterface.h" + +class NetworkManager::VpnPluginPrivate +{ +public: + VpnPluginPrivate(const QString &path); + + VpnConnection::State state; + OrgFreedesktopNetworkManagerVPNPluginInterface iface; +}; + +NetworkManager::VpnPluginPrivate::VpnPluginPrivate(const QString &path) +#ifdef NMQT_STATIC + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ +} + +NetworkManager::VpnPlugin::VpnPlugin(const QString &path, QObject *parent) + : QObject(parent) + , d_ptr(new VpnPluginPrivate(path)) +{ + Q_D(VpnPlugin); + d->state = (NetworkManager::VpnConnection::State)d->iface.state(); + + QObject::connect(&d->iface, SIGNAL(Config(QVariantMap)), this, SLOT(setConfig(QVariantMap))); + QObject::connect(&d->iface, SIGNAL(Failure(uint)), this, SLOT(setFailure(QString))); + QObject::connect(&d->iface, SIGNAL(Ip4Config(QVariantMap)), this, SLOT(setIp4Config(QVariantMap))); + QObject::connect(&d->iface, SIGNAL(Ip6Config(QVariantMap)), this, SLOT(setIp6Config(QVariantMap))); + // QObject::connect(&d->iface, SIGNAL(LoginBanner(QString)), + // this, SLOT(onLoginBanner(QString))); + QObject::connect(&d->iface, SIGNAL(StateChanged(uint)), this, SLOT(onStateChanged(uint))); +} + +NetworkManager::VpnPlugin::~VpnPlugin() +{ + delete d_ptr; +} + +void NetworkManager::VpnPlugin::connect(const NMVariantMapMap &connection) +{ + Q_D(VpnPlugin); + + QDBusPendingReply<> reply = d->iface.Connect(connection); +} + +void NetworkManager::VpnPlugin::disconnect() +{ + Q_D(VpnPlugin); + + QDBusPendingReply<> reply = d->iface.Disconnect(); +} + +QString NetworkManager::VpnPlugin::needSecrets(const NMVariantMapMap &connection) +{ + Q_D(VpnPlugin); + + QDBusPendingReply reply = d->iface.NeedSecrets(connection); + + return reply.value(); +} + +void NetworkManager::VpnPlugin::setConfig(const QVariantMap &configuration) +{ + Q_D(VpnPlugin); + + QDBusPendingReply reply = d->iface.SetConfig(configuration); + + Q_EMIT configChanged(configuration); +} + +void NetworkManager::VpnPlugin::setFailure(const QString &reason) +{ + Q_D(VpnPlugin); + + QDBusPendingReply reply = d->iface.SetFailure(reason); + + // TODO + // Q_EMIT failureChanged(reason); +} + +void NetworkManager::VpnPlugin::setIp4Config(const QVariantMap &config) +{ + Q_D(VpnPlugin); + + QDBusPendingReply<> reply = d->iface.SetIp4Config(config); + + Q_EMIT ip4ConfigChanged(config); +} + +void NetworkManager::VpnPlugin::setIp6Config(const QVariantMap &config) +{ + Q_D(VpnPlugin); + + QDBusPendingReply<> reply = d->iface.SetIp6Config(config); + + Q_EMIT ip6ConfigChanged(config); +} + +void NetworkManager::VpnPlugin::onStateChanged(uint state) +{ + Q_D(VpnPlugin); + + d->state = (VpnConnection::State)state; + + Q_EMIT stateChanged(d->state); +} diff --git a/panels/dock/tray/networkmanager-qt/src/vpnplugin.h b/panels/dock/tray/networkmanager-qt/src/vpnplugin.h new file mode 100644 index 000000000..88a5750bb --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/vpnplugin.h @@ -0,0 +1,62 @@ +/* + SPDX-FileCopyrightText: 2012-2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_VPNPLUGIN_H +#define NETWORKMANAGERQT_VPNPLUGIN_H + +#include "generictypes.h" +#include "vpnconnection.h" +#include + +#include +#include + +namespace NetworkManager +{ +class VpnPluginPrivate; + +class NETWORKMANAGERQT_EXPORT VpnPlugin : public QObject +{ + Q_OBJECT + +public: + enum FailureType { + LoginFailed, + ConnectFailed, + BadIpConfig, + }; + + explicit VpnPlugin(const QString &path, QObject *parent = nullptr); + ~VpnPlugin() override; + +Q_SIGNALS: + void configChanged(const QVariantMap &configuration); + void failureChanged(uint reason); + void ip4ConfigChanged(const QVariantMap &ip4config); + void ip6ConfigChanged(const QVariantMap &ip6config); + void loginBannerChanged(const QString &banner); + void stateChanged(VpnConnection::State state); + +protected Q_SLOTS: + void connect(const NMVariantMapMap &connection); + void disconnect(); + QString needSecrets(const NMVariantMapMap &connection); + void setConfig(const QVariantMap &config); + void setFailure(const QString &reason); + void setIp4Config(const QVariantMap &config); + void setIp6Config(const QVariantMap &config); + void onStateChanged(uint state); + +protected: + VpnPluginPrivate *const d_ptr; + +private: + Q_DECLARE_PRIVATE(VpnPlugin) +}; + +} // namespace NetworkManager + +#endif // NETWORKMANAGERQT_VPNPLUGIN_H diff --git a/panels/dock/tray/networkmanager-qt/src/wimaxdevice.cpp b/panels/dock/tray/networkmanager-qt/src/wimaxdevice.cpp new file mode 100644 index 000000000..59b1b8e8f --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wimaxdevice.cpp @@ -0,0 +1,165 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wimaxdevice.h" +#include "manager_p.h" +#include "wimaxdevice_p.h" + +#include "nmdebug.h" + +NetworkManager::WimaxDevicePrivate::WimaxDevicePrivate(const QString &path, WimaxDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , wimaxIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , wimaxIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif +{ + qDBusRegisterMetaType>(); + const QList nsps = wimaxIface.nsps(); + for (const QDBusObjectPath &op : nsps) { + nspMap.insert(op.path(), NetworkManager::WimaxNsp::Ptr()); + // qCDebug(NMQT) << " " << op.path(); + } +} + +NetworkManager::WimaxDevice::WimaxDevice(const QString &path, QObject *parent) + : Device(*new WimaxDevicePrivate(path, this), parent) +{ + Q_D(WimaxDevice); + + connect(&d->wimaxIface, &OrgFreedesktopNetworkManagerDeviceWiMaxInterface::NspAdded, d, &WimaxDevicePrivate::nspAdded); + connect(&d->wimaxIface, &OrgFreedesktopNetworkManagerDeviceWiMaxInterface::NspRemoved, d, &WimaxDevicePrivate::nspRemoved); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->wimaxIface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::WimaxDevice::~WimaxDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::WimaxDevice::type() const +{ + return NetworkManager::Device::Wimax; +} + +QStringList NetworkManager::WimaxDevice::nsps() const +{ + Q_D(const WimaxDevice); + return d->nspMap.keys(); +} + +NetworkManager::WimaxNsp::Ptr NetworkManager::WimaxDevice::activeNsp() const +{ + Q_D(const WimaxDevice); + return findNsp(d->activeNsp); +} + +QString NetworkManager::WimaxDevice::hardwareAddress() const +{ + Q_D(const WimaxDevice); + return d->hardwareAddress; +} + +QString NetworkManager::WimaxDevice::bsid() const +{ + Q_D(const WimaxDevice); + return d->bsid; +} + +uint NetworkManager::WimaxDevice::centerFrequency() const +{ + Q_D(const WimaxDevice); + return d->centerFrequency; +} + +int NetworkManager::WimaxDevice::cinr() const +{ + Q_D(const WimaxDevice); + return d->cinr; +} + +int NetworkManager::WimaxDevice::rssi() const +{ + Q_D(const WimaxDevice); + return d->rssi; +} + +int NetworkManager::WimaxDevice::txPower() const +{ + Q_D(const WimaxDevice); + return d->txPower; +} + +NetworkManager::WimaxNsp::Ptr NetworkManager::WimaxDevice::findNsp(const QString &uni) const +{ + Q_D(const WimaxDevice); + NetworkManager::WimaxNsp::Ptr nsp; + QMap::ConstIterator mapIt = d->nspMap.constFind(uni); + if (mapIt != d->nspMap.constEnd() && !mapIt.value().isNull()) { + nsp = mapIt.value(); + } else { + nsp = NetworkManager::WimaxNsp::Ptr(new NetworkManager::WimaxNsp(uni), &QObject::deleteLater); + d->nspMap.insert(uni, nsp); + } + + return nsp; +} + +void NetworkManager::WimaxDevicePrivate::nspAdded(const QDBusObjectPath &nspPath) +{ + // qCDebug(NMQT) << nspPath.path(); + Q_Q(WimaxDevice); + if (!nspMap.contains(nspPath.path())) { + nspMap.insert(nspPath.path(), NetworkManager::WimaxNsp::Ptr()); + Q_EMIT q->nspAppeared(nspPath.path()); + } +} + +void NetworkManager::WimaxDevicePrivate::nspRemoved(const QDBusObjectPath &nspPath) +{ + // qCDebug(NMQT) << nspPath.path(); + Q_Q(WimaxDevice); + if (!nspMap.contains(nspPath.path())) { + qCDebug(NMQT) << "Access point list lookup failed for " << nspPath.path(); + } + Q_EMIT q->nspDisappeared(nspPath.path()); + nspMap.remove(nspPath.path()); +} + +void NetworkManager::WimaxDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(WimaxDevice); + + if (property == QLatin1String("ActiveNsp")) { + activeNsp = qdbus_cast(value).path(); + Q_EMIT q->activeNspChanged(activeNsp); + } else if (property == QLatin1String("HwAddress")) { + hardwareAddress = value.toString(); + Q_EMIT q->hardwareAddressChanged(hardwareAddress); + } else if (property == QLatin1String("Bsid")) { + bsid = value.toString(); + Q_EMIT q->bsidChanged(bsid); + } else if (property == QLatin1String("CenterFrequency")) { + centerFrequency = value.toUInt(); + Q_EMIT q->centerFrequencyChanged(centerFrequency); + } else if (property == QLatin1String("Cinr")) { + cinr = value.toInt(); + Q_EMIT q->cinrChanged(cinr); + } else if (property == QLatin1String("Rssi")) { + rssi = value.toInt(); + Q_EMIT q->rssiChanged(rssi); + } else if (property == QLatin1String("TxPower")) { + txPower = value.toInt(); + Q_EMIT q->txPowerChanged(txPower); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/wimaxdevice.h b/panels/dock/tray/networkmanager-qt/src/wimaxdevice.h new file mode 100644 index 000000000..c88516782 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wimaxdevice.h @@ -0,0 +1,139 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIMAXDEVICE_H +#define NETWORKMANAGERQT_WIMAXDEVICE_H + +#include + +#include "device.h" +#include "wimaxnsp.h" + +#include + +namespace NetworkManager +{ +class WimaxDevicePrivate; + +/** + * Wimax network interface + */ +class NETWORKMANAGERQT_EXPORT WimaxDevice : public Device +{ + Q_OBJECT + +public: + typedef QSharedPointer Ptr; + typedef QList List; + + /** + * Creates a new WimaxDevice object. + * + * @param path the DBus path of the device + */ + explicit WimaxDevice(const QString &path, QObject *parent = nullptr); + /** + * Destroys a WimaxDevice object. + */ + ~WimaxDevice() override; + /** + * Return the type + */ + Type type() const override; + /** + * List of network service providers currently visible to the hardware + */ + QStringList nsps() const; + /** + * Identifier of the NSP this interface is currently associated with + */ + WimaxNsp::Ptr activeNsp() const; + /** + * The ID of the serving base station as received from the network. + */ + QString bsid() const; + /** + * The hardware address currently used by the network interface + */ + QString hardwareAddress() const; + /** + * Center frequency (in KHz) of the radio channel the device is using to communicate with the network when connected. + */ + uint centerFrequency() const; + /** + * CINR (Carrier to Interference + Noise Ratio) of the current radio link in dB. + */ + int cinr() const; + /** + * RSSI of the current radio link in dBm. This value indicates how strong the raw received RF signal from the base station is, but does not indicate the + * overall quality of the radio link. + */ + int rssi() const; + /** + * Average power of the last burst transmitted by the device, in units of 0.5 dBm. i.e. a TxPower of -11 represents an actual device TX power of -5.5 dBm. + */ + int txPower() const; + + /** + * Finds NSP object given its Unique Network Identifier. + * + * @param uni the identifier of the AP to find from this network interface + * @returns a valid WimaxNsp object if a network having the given UNI for this device is known to the system, 0 otherwise + */ + NetworkManager::WimaxNsp::Ptr findNsp(const QString &uni) const; + +Q_SIGNALS: + /** + * This signal is emitted when the bitrate of this network has changed. + * + * @param bitrate the new bitrate value for this network + */ + void bitRateChanged(int bitrate); + /** + * The active NSP changed. + */ + void activeNspChanged(const QString &); + /** + * The BSID changed. + */ + void bsidChanged(const QString &); + /** + * The device changed its hardware address + */ + void hardwareAddressChanged(const QString &); + /** + * The device changed its center frequency + */ + void centerFrequencyChanged(uint); + /** + * The device changed its signal/noise ratio + */ + void cinrChanged(int); + /** + * The device changed its RSSI + */ + void rssiChanged(int); + /** + * The device changed its TxPower. + */ + void txPowerChanged(int); + /** + * A new NSP appeared + */ + void nspAppeared(const QString &); + /** + * A wireless access point disappeared + */ + void nspDisappeared(const QString &); + +private: + Q_DECLARE_PRIVATE(WimaxDevice) +}; + +} // namespace NetworkManager +#endif // NETWORKMANAGERQT_WIMAXDEVICE_H diff --git a/panels/dock/tray/networkmanager-qt/src/wimaxdevice_p.h b/panels/dock/tray/networkmanager-qt/src/wimaxdevice_p.h new file mode 100644 index 000000000..f0b6652ee --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wimaxdevice_p.h @@ -0,0 +1,45 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIMAXDEVICE_P_H +#define NETWORKMANAGERQT_WIMAXDEVICE_P_H + +#include "device_p.h" +#include "wimaxdeviceinterface.h" + +namespace NetworkManager +{ +class WimaxDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + explicit WimaxDevicePrivate(const QString &path, WimaxDevice *q); + OrgFreedesktopNetworkManagerDeviceWiMaxInterface wimaxIface; + QString hardwareAddress; + mutable QMap nspMap; + QString activeNsp; + uint centerFrequency; + int cinr; + QString bsid; + int rssi; + int txPower; + + Q_DECLARE_PUBLIC(WimaxDevice) +protected Q_SLOTS: + void nspAdded(const QDBusObjectPath &); + void nspRemoved(const QDBusObjectPath &); + +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/wimaxnsp.cpp b/panels/dock/tray/networkmanager-qt/src/wimaxnsp.cpp new file mode 100644 index 000000000..78198b60e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wimaxnsp.cpp @@ -0,0 +1,109 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "manager_p.h" +#include "nmdebug.h" +#include "wimaxdevice.h" +#include "wimaxnsp_p.h" + +namespace NetworkManager +{ +NetworkManager::WimaxNsp::NetworkType convertNetworkType(uint type) +{ + switch (type) { + case 0: + return NetworkManager::WimaxNsp::Unknown; + case 1: + return NetworkManager::WimaxNsp::Home; + case 2: + return NetworkManager::WimaxNsp::Partner; + case 3: + return NetworkManager::WimaxNsp::RoamingPartner; + } + return NetworkManager::WimaxNsp::Unknown; +} + +} + +NetworkManager::WimaxNspPrivate::WimaxNspPrivate(const QString &path, WimaxNsp *q) +#ifdef NMQT_STATIC + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , networkType(WimaxNsp::Unknown) + , signalQuality(0) + , q_ptr(q) +{ +} + +NetworkManager::WimaxNsp::WimaxNsp(const QString &path, QObject *parent) + : QObject(parent) + , d_ptr(new WimaxNspPrivate(path, this)) +{ + Q_D(WimaxNsp); + d->uni = path; + if (d->iface.isValid()) { + connect(&d->iface, &OrgFreedesktopNetworkManagerWiMaxNspInterface::PropertiesChanged, d, &WimaxNspPrivate::propertiesChanged); + d->networkType = convertNetworkType(d->iface.networkType()); + d->name = d->iface.name(); + d->signalQuality = d->iface.signalQuality(); + } +} + +NetworkManager::WimaxNsp::~WimaxNsp() +{ + Q_D(WimaxNsp); + delete d; +} + +QString NetworkManager::WimaxNsp::uni() const +{ + Q_D(const WimaxNsp); + return d->uni; +} + +NetworkManager::WimaxNsp::NetworkType NetworkManager::WimaxNsp::networkType() const +{ + Q_D(const WimaxNsp); + return d->networkType; +} + +QString NetworkManager::WimaxNsp::name() const +{ + Q_D(const WimaxNsp); + return d->name; +} + +uint NetworkManager::WimaxNsp::signalQuality() const +{ + Q_D(const WimaxNsp); + return d->signalQuality; +} + +void NetworkManager::WimaxNspPrivate::propertiesChanged(const QVariantMap &properties) +{ + Q_Q(WimaxNsp); + + QVariantMap::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + const QString property = it.key(); + if (property == QLatin1String("Name")) { + name = it->toString(); + Q_EMIT q->nameChanged(name); + } else if (property == QLatin1String("NetworkType")) { + networkType = convertNetworkType(it->toUInt()); + Q_EMIT q->networkTypeChanged(networkType); + } else if (property == QLatin1String("SignalQuality")) { + signalQuality = it->toUInt(); + Q_EMIT q->signalQualityChanged(signalQuality); + } else { + qCWarning(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; + } + ++it; + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/wimaxnsp.h b/panels/dock/tray/networkmanager-qt/src/wimaxnsp.h new file mode 100644 index 000000000..6c5abaaf6 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wimaxnsp.h @@ -0,0 +1,84 @@ +/* + SPDX-FileCopyrightText: 2011 Ilia Kats + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIMAXNSP_H +#define NETWORKMANAGERQT_WIMAXNSP_H + +#include + +#include + +namespace NetworkManager +{ +class WimaxNspPrivate; + +/** + * Wimax network service provider (access point) + */ +class NETWORKMANAGERQT_EXPORT WimaxNsp : public QObject +{ + Q_OBJECT +public: + typedef QSharedPointer Ptr; + typedef QList List; + /** + * network types a NSP can have + */ + enum NetworkType { + Unknown = 0x1, + Home = 0x2, + Partner = 0x3, + RoamingPartner = 0x4, + }; + + explicit WimaxNsp(const QString &path, QObject *parent = nullptr); + ~WimaxNsp() override; + + QString uni() const; + /** + * The network type of the NSP + */ + NetworkType networkType() const; + /** + * The name of the NSP + */ + QString name() const; + /** + * The current signal quality of the NSP, in percent + */ + uint signalQuality() const; + +Q_SIGNALS: + /** + * This signal is emitted when the network type of this NSP has changed. + * + * @param type the new type + */ + void networkTypeChanged(NetworkType type); + + /** + * This signal is emitted when the name of this NSP has changed + * + * @param name the new name for this NSP + */ + void nameChanged(const QString &name); + + /** + * This signal is emitted when the signal quality of this NSP has changed. + * + * @param quality the new quality + */ + void signalQualityChanged(uint quality); + +private: + Q_DECLARE_PRIVATE(WimaxNsp) + + WimaxNspPrivate *const d_ptr; +}; +} +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/wimaxnsp_p.h b/panels/dock/tray/networkmanager-qt/src/wimaxnsp_p.h new file mode 100644 index 000000000..b2da49e1e --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wimaxnsp_p.h @@ -0,0 +1,34 @@ +/* + SPDX-FileCopyrightText: 2014 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIMAXNSP_P_H +#define NETWORKMANAGERQT_WIMAXNSP_P_H + +#include "dbus/wimaxnspinterface.h" +#include "wimaxnsp.h" + +namespace NetworkManager +{ +class WimaxNspPrivate : public QObject +{ + Q_OBJECT +public: + WimaxNspPrivate(const QString &path, WimaxNsp *q); + + OrgFreedesktopNetworkManagerWiMaxNspInterface iface; + QString uni; + WimaxNsp::NetworkType networkType; + QString name; + uint signalQuality; + + Q_DECLARE_PUBLIC(WimaxNsp) + WimaxNsp *q_ptr; +private Q_SLOTS: + void propertiesChanged(const QVariantMap &properties); +}; +} + +#endif // NETWORKMANAGERQT_WIMAXNSP_P_H diff --git a/panels/dock/tray/networkmanager-qt/src/wireddevice.cpp b/panels/dock/tray/networkmanager-qt/src/wireddevice.cpp new file mode 100644 index 000000000..173763a95 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wireddevice.cpp @@ -0,0 +1,108 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wireddevice.h" +#include "manager.h" +#include "manager_p.h" +#include "wireddevice_p.h" + +#include "nmdebug.h" + +NetworkManager::WiredDevicePrivate::WiredDevicePrivate(const QString &path, WiredDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , wiredIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , wiredIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , bitrate(0) + , carrier(false) +{ +} + +NetworkManager::WiredDevicePrivate::~WiredDevicePrivate() +{ +} + +NetworkManager::WiredDevice::WiredDevice(const QString &path, QObject *parent) + : Device(*new NetworkManager::WiredDevicePrivate(path, this), parent) +{ + Q_D(WiredDevice); +#ifdef NMQT_STATIC + connect(&d->wiredIface, &OrgFreedesktopNetworkManagerDeviceWiredInterface::PropertiesChanged, d, &WiredDevicePrivate::propertiesChanged); +#endif + // Get all WiredDevices's properties at once + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->wiredIface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } + + +} + +NetworkManager::WiredDevice::~WiredDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::WiredDevice::type() const +{ + return NetworkManager::Device::Ethernet; +} + +QString NetworkManager::WiredDevice::hardwareAddress() const +{ + Q_D(const NetworkManager::WiredDevice); + return d->hardwareAddress; +} + +QString NetworkManager::WiredDevice::permanentHardwareAddress() const +{ + Q_D(const NetworkManager::WiredDevice); + return d->permanentHardwareAddress; +} + +int NetworkManager::WiredDevice::bitRate() const +{ + Q_D(const NetworkManager::WiredDevice); + return d->bitrate; +} + +bool NetworkManager::WiredDevice::carrier() const +{ + Q_D(const NetworkManager::WiredDevice); + return d->carrier; +} + +QStringList NetworkManager::WiredDevice::s390SubChannels() const +{ + Q_D(const NetworkManager::WiredDevice); + return d->s390SubChannels; +} + +void NetworkManager::WiredDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(NetworkManager::WiredDevice); + + if (property == QLatin1String("Carrier")) { + carrier = value.toBool(); + Q_EMIT q->carrierChanged(carrier); + } else if (property == QLatin1String("HwAddress")) { + hardwareAddress = value.toString(); + Q_EMIT q->hardwareAddressChanged(hardwareAddress); + } else if (property == QLatin1String("PermHwAddress")) { + permanentHardwareAddress = value.toString(); + Q_EMIT q->permanentHardwareAddressChanged(permanentHardwareAddress); + } else if (property == QLatin1String("Speed")) { + bitrate = value.toUInt() * 1000; + Q_EMIT q->bitRateChanged(bitrate); + } else if (property == QLatin1String("S390Subchannels")) { + s390SubChannels = value.toStringList(); + Q_EMIT q->s390SubChannelsChanged(s390SubChannels); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/wireddevice.h b/panels/dock/tray/networkmanager-qt/src/wireddevice.h new file mode 100644 index 000000000..dc1d89021 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wireddevice.h @@ -0,0 +1,90 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIREDDEVICE_H +#define NETWORKMANAGERQT_WIREDDEVICE_H + +#include + +#include "device.h" + +namespace NetworkManager +{ +class WiredDevicePrivate; + +/** + * A wired device interface + */ +class NETWORKMANAGERQT_EXPORT WiredDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(QString hardwareAddress READ hardwareAddress) + Q_PROPERTY(QString permanentHardwareAddress READ permanentHardwareAddress) + Q_PROPERTY(bool carrier READ carrier NOTIFY carrierChanged) + Q_PROPERTY(int bitRate READ bitRate NOTIFY bitRateChanged) + Q_PROPERTY(QStringList s390SubChannels READ s390SubChannels NOTIFY s390SubChannelsChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit WiredDevice(const QString &path, QObject *parent = nullptr); + ~WiredDevice() override; + /** + * Return the type + */ + Type type() const override; + /** + * Active hardware address of the device + */ + QString hardwareAddress() const; + /** + * Permanent hardware address of the device + */ + QString permanentHardwareAddress() const; + /** + * Design speed of the device, in megabits/second (Mb/s) + */ + int bitRate() const; + /** + * Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not) + */ + bool carrier() const; + /** + * Array of S/390 subchannels for S/390 or z/Architecture devices + */ + QStringList s390SubChannels() const; + +Q_SIGNALS: + /** + * Emitted when the design speed of the device has changed + */ + void bitRateChanged(int bitRate); + /** + * Emitted when the carrier of this device has changed + */ + void carrierChanged(bool plugged); + /** + * Emitted when the hardware address of this device has changed + */ + void hardwareAddressChanged(const QString &hwAddress); + /** + * Emitted when the permanent hardware address of this device has changed + */ + void permanentHardwareAddressChanged(const QString &permHwAddress); + /* + * Emitted when the array of s390SubChannels has changed + */ + void s390SubChannelsChanged(const QStringList &channels); + +private: + Q_DECLARE_PRIVATE(WiredDevice) +}; + +} + +#endif // NETWORKMANAGERQT_WIREDDEVICE_H diff --git a/panels/dock/tray/networkmanager-qt/src/wireddevice_p.h b/panels/dock/tray/networkmanager-qt/src/wireddevice_p.h new file mode 100644 index 000000000..fa271f93c --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wireddevice_p.h @@ -0,0 +1,39 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIREDDEVICE_P_H +#define NETWORKMANAGERQT_WIREDDEVICE_P_H + +#include "dbus/wireddeviceinterface.h" +#include "device_p.h" + +namespace NetworkManager +{ +class WiredDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + explicit WiredDevicePrivate(const QString &path, WiredDevice *q); + ~WiredDevicePrivate() override; + OrgFreedesktopNetworkManagerDeviceWiredInterface wiredIface; + QString hardwareAddress; + QString permanentHardwareAddress; + QStringList s390SubChannels; + int bitrate; + bool carrier; + + Q_DECLARE_PUBLIC(WiredDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; + +} // namespace NetworkManager + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/wireguarddevice.cpp b/panels/dock/tray/networkmanager-qt/src/wireguarddevice.cpp new file mode 100644 index 000000000..6706618ac --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wireguarddevice.cpp @@ -0,0 +1,84 @@ +/* + SPDX-FileCopyrightText: 2019 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wireguarddevice.h" +#include "manager_p.h" +#include "wireguarddevice_p.h" + +NetworkManager::WireGuardDevicePrivate::WireGuardDevicePrivate(const QString &path, WireGuardDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , listenPort(0) + , fwMark(0) +{ +} + +NetworkManager::WireGuardDevicePrivate::~WireGuardDevicePrivate() +{ +} + +NetworkManager::WireGuardDevice::WireGuardDevice(const QString &path, QObject *parent) + : Device(*new WireGuardDevicePrivate(path, this), parent) +{ + Q_D(WireGuardDevice); + + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } +} + +NetworkManager::WireGuardDevice::~WireGuardDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::WireGuardDevice::type() const +{ + return NetworkManager::Device::WireGuard; +} + +QByteArray NetworkManager::WireGuardDevice::publicKey() const +{ + Q_D(const WireGuardDevice); + + return d->publicKey; +} + +uint NetworkManager::WireGuardDevice::listenPort() const +{ + Q_D(const WireGuardDevice); + + return d->listenPort; +} + +uint NetworkManager::WireGuardDevice::fwMark() const +{ + Q_D(const WireGuardDevice); + + return d->fwMark; +} + +void NetworkManager::WireGuardDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(WireGuardDevice); + + if (property == QLatin1String("PublicKey")) { + publicKey = value.toByteArray(); + Q_EMIT q->publicKeyChanged(publicKey); + } else if (property == QLatin1String("ListenPort")) { + listenPort = value.toUInt(); + Q_EMIT q->listenPortChanged(listenPort); + } else if (property == QLatin1String("FwMark")) { + fwMark = value.toUInt(); + Q_EMIT q->fwMarkChanged(fwMark); + } else { + DevicePrivate::propertyChanged(property, value); + } +} diff --git a/panels/dock/tray/networkmanager-qt/src/wireguarddevice.h b/panels/dock/tray/networkmanager-qt/src/wireguarddevice.h new file mode 100644 index 000000000..4ffa4188a --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wireguarddevice.h @@ -0,0 +1,68 @@ +/* + SPDX-FileCopyrightText: 2019 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIREGUARD_DEVICE_H +#define NETWORKMANAGERQT_WIREGUARD_DEVICE_H + +#include "device.h" +#include + +namespace NetworkManager +{ +class WireGuardDevicePrivate; + +/** + * A WireGuard device interface + */ +class NETWORKMANAGERQT_EXPORT WireGuardDevice : public Device +{ + Q_OBJECT + Q_PROPERTY(QByteArray publicKey READ publicKey NOTIFY publicKeyChanged) + Q_PROPERTY(uint listenPort READ listenPort NOTIFY listenPortChanged) + Q_PROPERTY(uint fwMark READ fwMark NOTIFY fwMarkChanged) + +public: + typedef QSharedPointer Ptr; + typedef QList List; + explicit WireGuardDevice(const QString &path, QObject *parent = nullptr); + ~WireGuardDevice() override; + + Type type() const override; + + /** + * 32-byte public WireGuard key. + */ + QByteArray publicKey() const; + /** + * Local UDP listening port. + */ + uint listenPort() const; + /** + * Optional 32-bit mark used to set routing policy for outgoing encrypted packets. See: ip-rule(8) + */ + uint fwMark() const; + +Q_SIGNALS: + /** + * Emitted when the public key of this device has changed + */ + void publicKeyChanged(const QByteArray &publicKey); + /** + * Emitted when the listen port of this device has changed + */ + void listenPortChanged(uint listenPort); + /** + * Emitted when the fwmark of this device have changed + */ + void fwMarkChanged(uint fwMark); + +private: + Q_DECLARE_PRIVATE(WireGuardDevice) +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/wireguarddevice_p.h b/panels/dock/tray/networkmanager-qt/src/wireguarddevice_p.h new file mode 100644 index 000000000..dc814c7c7 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wireguarddevice_p.h @@ -0,0 +1,39 @@ +/* + SPDX-FileCopyrightText: 2019 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIREGUARD_DEVICE_P_H +#define NETWORKMANAGERQT_WIREGUARD_DEVICE_P_H + +#include "device_p.h" +#include "manager.h" +#include "wireguarddevice.h" + +#include "wireguarddeviceinterface.h" + +namespace NetworkManager +{ +class WireGuardDevicePrivate : public DevicePrivate +{ +public: + WireGuardDevicePrivate(const QString &path, WireGuardDevice *q); + ~WireGuardDevicePrivate() override; + + OrgFreedesktopNetworkManagerDeviceWireGuardInterface iface; + QByteArray publicKey; + uint listenPort; + uint fwMark; + + Q_DECLARE_PUBLIC(WireGuardDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; +}; +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/wirelessdevice.cpp b/panels/dock/tray/networkmanager-qt/src/wirelessdevice.cpp new file mode 100644 index 000000000..f85259141 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wirelessdevice.cpp @@ -0,0 +1,265 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wirelessdevice.h" +#include "wirelessdevice_p.h" + +#undef signals +#include +#define signals Q_SIGNALS + +#include "manager_p.h" + +#include "nmdebug.h" +#include "utils.h" + +NetworkManager::WirelessDevicePrivate::WirelessDevicePrivate(const QString &path, WirelessDevice *q) + : DevicePrivate(path, q) +#ifdef NMQT_STATIC + , wirelessIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) +#else + , wirelessIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) +#endif + , bitRate(0) +{ +} + +NetworkManager::WirelessDevice::WirelessDevice(const QString &path, QObject *parent) + : Device(*new WirelessDevicePrivate(path, this), parent) +{ + Q_D(WirelessDevice); + + qDBusRegisterMetaType>(); + +#ifdef NMQT_STATIC + connect(&d->wirelessIface, &OrgFreedesktopNetworkManagerDeviceWirelessInterface::PropertiesChanged, d, &WirelessDevicePrivate::propertiesChanged); +#endif + + connect(&d->wirelessIface, &OrgFreedesktopNetworkManagerDeviceWirelessInterface::AccessPointAdded, d, &WirelessDevicePrivate::accessPointAdded); + connect(&d->wirelessIface, &OrgFreedesktopNetworkManagerDeviceWirelessInterface::AccessPointRemoved, d, &WirelessDevicePrivate::accessPointRemoved); + + const QList aps = d->wirelessIface.accessPoints(); + // qCDebug(NMQT) << "AccessPoint list"; + for (const QDBusObjectPath &op : aps) { + // qCDebug(NMQT) << " " << op.path(); + d->accessPointAdded(op); + } + + // Get all WirelessDevices's properties at once + QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->wirelessIface.staticInterfaceName(), path); + if (!initialProperties.isEmpty()) { + d->propertiesChanged(initialProperties); + } + +} + +NetworkManager::WirelessDevice::~WirelessDevice() +{ +} + +NetworkManager::Device::Type NetworkManager::WirelessDevice::type() const +{ + return NetworkManager::Device::Wifi; +} + +QStringList NetworkManager::WirelessDevice::accessPoints() const +{ + Q_D(const WirelessDevice); + return d->apMap.keys(); +} + +QDBusPendingReply<> NetworkManager::WirelessDevice::requestScan(const QVariantMap &options) +{ + Q_D(WirelessDevice); + d->lastRequestScan = QDateTime::currentDateTime(); + return d->wirelessIface.RequestScan(options); +} + +NetworkManager::AccessPoint::Ptr NetworkManager::WirelessDevice::activeAccessPoint() const +{ + Q_D(const WirelessDevice); + return d->activeAccessPoint; +} + +QString NetworkManager::WirelessDevice::hardwareAddress() const +{ + Q_D(const WirelessDevice); + return d->hardwareAddress; +} + +QString NetworkManager::WirelessDevice::permanentHardwareAddress() const +{ + Q_D(const WirelessDevice); + return d->permanentHardwareAddress; +} + +NetworkManager::WirelessDevice::OperationMode NetworkManager::WirelessDevice::mode() const +{ + Q_D(const WirelessDevice); + return d->mode; +} + +int NetworkManager::WirelessDevice::bitRate() const +{ + Q_D(const WirelessDevice); + return d->bitRate; +} + +QDateTime NetworkManager::WirelessDevice::lastScan() const +{ + Q_D(const WirelessDevice); + return d->lastScan; +} + +QDateTime NetworkManager::WirelessDevice::lastRequestScan() const +{ + Q_D(const WirelessDevice); + return d->lastRequestScan; +} + +NetworkManager::WirelessDevice::Capabilities NetworkManager::WirelessDevice::wirelessCapabilities() const +{ + Q_D(const WirelessDevice); + return d->wirelessCapabilities; +} + +NetworkManager::AccessPoint::Ptr NetworkManager::WirelessDevice::findAccessPoint(const QString &uni) +{ + Q_D(WirelessDevice); + NetworkManager::AccessPoint::Ptr accessPoint; + + QMap::ConstIterator mapIt = d->apMap.constFind(uni); + if (mapIt != d->apMap.constEnd()) { + accessPoint = mapIt.value(); + } else if (!uni.isEmpty() && uni != QLatin1String("/")) { + d->accessPointAdded(QDBusObjectPath(uni)); + mapIt = d->apMap.constFind(uni); + if (mapIt != d->apMap.constEnd()) { + accessPoint = mapIt.value(); + } + } + + return accessPoint; +} + +NetworkManager::WirelessNetwork::List NetworkManager::WirelessDevice::networks() const +{ + Q_D(const WirelessDevice); + return d->networks.values(); +} + +NetworkManager::WirelessNetwork::Ptr NetworkManager::WirelessDevice::findNetwork(const QString &ssid) const +{ + Q_D(const WirelessDevice); + NetworkManager::WirelessNetwork::Ptr ret; + if (d->networks.contains(ssid)) { + ret = d->networks.value(ssid); + } + return ret; +} + +void NetworkManager::WirelessDevicePrivate::accessPointAdded(const QDBusObjectPath &accessPoint) +{ + // kDebug(1441) << apPath.path(); + Q_Q(WirelessDevice); + + if (!apMap.contains(accessPoint.path())) { + NetworkManager::AccessPoint::Ptr accessPointPtr(new NetworkManager::AccessPoint(accessPoint.path()), &QObject::deleteLater); + apMap.insert(accessPoint.path(), accessPointPtr); + Q_EMIT q->accessPointAppeared(accessPoint.path()); + + const QString ssid = accessPointPtr->ssid(); + if (!ssid.isEmpty() && !networks.contains(ssid)) { + NetworkManager::WirelessNetwork::Ptr wifiNetwork(new NetworkManager::WirelessNetwork(accessPointPtr, q), &QObject::deleteLater); + networks.insert(ssid, wifiNetwork); + connect(wifiNetwork.data(), &WirelessNetwork::disappeared, this, &WirelessDevicePrivate::removeNetwork); + Q_EMIT q->networkAppeared(ssid); + } + } +} + +void NetworkManager::WirelessDevicePrivate::accessPointRemoved(const QDBusObjectPath &accessPoint) +{ + // kDebug(1441) << apPath.path(); + Q_Q(WirelessDevice); + if (!apMap.contains(accessPoint.path())) { + qCDebug(NMQT) << "Access point list lookup failed for " << accessPoint.path(); + } + Q_EMIT q->accessPointDisappeared(accessPoint.path()); + apMap.remove(accessPoint.path()); +} + +void NetworkManager::WirelessDevicePrivate::removeNetwork(const QString &network) +{ + Q_Q(WirelessDevice); + + if (networks.contains(network)) { + networks.remove(network); + Q_EMIT q->networkDisappeared(network); + } +} + +void NetworkManager::WirelessDevicePrivate::propertyChanged(const QString &property, const QVariant &value) +{ + Q_Q(WirelessDevice); + + if (property == QLatin1String("ActiveAccessPoint")) { + QDBusObjectPath activeAccessPointTmp = qdbus_cast(value); + activeAccessPoint = q->findAccessPoint(activeAccessPointTmp.path()); + Q_EMIT q->activeAccessPointChanged(activeAccessPointTmp.path()); + } else if (property == QLatin1String("HwAddress")) { + hardwareAddress = value.toString(); + Q_EMIT q->hardwareAddressChanged(hardwareAddress); + } else if (property == QLatin1String("PermHwAddress")) { + permanentHardwareAddress = value.toString(); + Q_EMIT q->permanentHardwareAddressChanged(permanentHardwareAddress); + } else if (property == QLatin1String("Bitrate")) { + bitRate = value.toUInt(); + Q_EMIT q->bitRateChanged(bitRate); + } else if (property == QLatin1String("Mode")) { + mode = q->convertOperationMode(value.toUInt()); + Q_EMIT q->modeChanged(mode); + } else if (property == QLatin1String("WirelessCapabilities")) { + wirelessCapabilities = q->convertCapabilities(value.toUInt()); + Q_EMIT q->wirelessCapabilitiesChanged(wirelessCapabilities); + } else if (property == QLatin1String("LastScan")) { + lastScan = NetworkManager::clockBootTimeToDateTime(value.toLongLong()); + Q_EMIT q->lastScanChanged(lastScan); + } else if (property == QLatin1String("AccessPoints")) { + // TODO use this instead AccessPointAdded/Removed signals? + } else { + DevicePrivate::propertyChanged(property, value); + } +} + +NetworkManager::WirelessDevice::OperationMode NetworkManager::WirelessDevice::convertOperationMode(uint theirMode) +{ + NetworkManager::WirelessDevice::OperationMode ourMode = NetworkManager::WirelessDevice::Unknown; + switch (theirMode) { + case NM_802_11_MODE_UNKNOWN: + ourMode = NetworkManager::WirelessDevice::Unknown; + break; + case NM_802_11_MODE_ADHOC: + ourMode = NetworkManager::WirelessDevice::Adhoc; + break; + case NM_802_11_MODE_INFRA: + ourMode = NetworkManager::WirelessDevice::Infra; + break; + case NM_802_11_MODE_AP: + ourMode = NetworkManager::WirelessDevice::ApMode; + break; + default: + qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled mode" << theirMode; + } + return ourMode; +} + +NetworkManager::WirelessDevice::Capabilities NetworkManager::WirelessDevice::convertCapabilities(uint caps) +{ + return (NetworkManager::WirelessDevice::Capabilities)caps; +} diff --git a/panels/dock/tray/networkmanager-qt/src/wirelessdevice.h b/panels/dock/tray/networkmanager-qt/src/wirelessdevice.h new file mode 100644 index 000000000..f43d86766 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wirelessdevice.h @@ -0,0 +1,226 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Daniel Nicoletti + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRELESSDEVICE_H +#define NETWORKMANAGERQT_WIRELESSDEVICE_H + +#include "accesspoint.h" +#include "device.h" +#include "wirelessnetwork.h" +#include + +#include +#include + +namespace NetworkManager +{ +class WirelessDevicePrivate; + +/** + * A wireless network interface + */ +class NETWORKMANAGERQT_EXPORT WirelessDevice : public Device +{ + Q_OBJECT + +public: + typedef QSharedPointer Ptr; + typedef QList List; + + /** + * The device's current operating mode + */ + enum OperationMode { + Unknown = 0, /**< not associated with a network */ + Adhoc, /**< part of an adhoc network */ + Infra, /**< a station in an infrastructure wireless network */ + ApMode, /**< access point in an infrastructure network */ + }; + Q_ENUM(OperationMode) + /** + * Capabilities (currently all encryption/authentication related) of the device + * @note FreqValid, Freq2Ghz, Freq5Ghz are available in runtime NM >= 1.0.2 + */ + enum Capability { + NoCapability = 0x0, /**< Null capability */ + Wep40 = 0x1, /**< 40 bit WEP cipher */ + Wep104 = 0x2, /**< 104 bit WEP cipher */ + Tkip = 0x4, /**< TKIP encryption cipher */ + Ccmp = 0x8, /**< CCMP encryption cipher */ + Wpa = 0x10, /**< WPA authentication protocol */ + Rsn = 0x20, /**< RSN authethication protocol */ + ApCap = 0x40, /**< The device supports Access Point mode. */ + AdhocCap = 0x80, /**< The device supports Ad-Hoc mode. */ + FreqValid = 0x100, /**< The device properly reports information about supported frequencies */ + Freq2Ghz = 0x200, /**< The device supports 2.4Ghz frequencies */ + Freq5Ghz = 0x400, /**< The device supports 5Ghz frequencies */ + Mesh = 0x1000, /**< The device supports acting as a mesh point */ + IBSSRsn = 0x2000, /**< device supports WPA2/RSN in an IBSS network */ + }; + Q_DECLARE_FLAGS(Capabilities, Capability) + /** + * Creates a new WirelessDevice object. + * + * @param path the DBus path of the devise + */ + explicit WirelessDevice(const QString &path, QObject *parent = nullptr); + /** + * Destroys a WirelessDevice object. + */ + ~WirelessDevice() override; + /** + * Return the type + */ + Type type() const override; + /** + * List of wireless networks currently visible to the hardware + */ + QStringList accessPoints() const; + /** + * Asks the device for a new scan of available wireless networks + * @param options Options of scan + * No documentation for options yet, see + * https://projects.gnome.org/NetworkManager/developers/api/09/spec.html#org.freedesktop.NetworkManager.Device.Wireless + */ + QDBusPendingReply<> requestScan(const QVariantMap &options = QVariantMap()); + /** + * AccessPoint pointer this interface is currently associated with + */ + AccessPoint::Ptr activeAccessPoint() const; + /** + * The permanent hardware address of the network interface + */ + QString permanentHardwareAddress() const; + /** + * The hardware address currently used by the network interface + */ + QString hardwareAddress() const; + + /** + * Retrieves the operation mode of this network. + * + * @return the current mode + * @see OperationMode + */ + WirelessDevice::OperationMode mode() const; + /** + * Retrieves the effective bit rate currently attainable by this device. + * + * @return the bitrate in Kbit/s + */ + int bitRate() const; + /** + * The LastScan property value, converted to QDateTime + * @since 5.62.0 + * @note will always return invalid QDateTime when runtime NM < 1.12 + * @return + */ + QDateTime lastScan() const; + /** + * The time the last RequestScan function was called + * @since 5.62.0 + * @return + */ + QDateTime lastRequestScan() const; + /** + * Retrieves the capabilities of this wifi network. + * + * @return the flag set describing the capabilities + * @see Capabilities + */ + WirelessDevice::Capabilities wirelessCapabilities() const; + + /** + * Helper method to convert wire representation of operation mode to enum + */ + static WirelessDevice::OperationMode convertOperationMode(uint); + /** + * Helper method to convert wire representation of capabilities to enum + */ + static WirelessDevice::Capabilities convertCapabilities(uint); + /** + * Finds access point object given its Unique Network Identifier. + * + * @param uni the identifier of the AP to find from this network interface + * @returns a valid AccessPoint object if a network having the given UNI for this device is known to the system, 0 otherwise + */ + AccessPoint::Ptr findAccessPoint(const QString &uni); + + /** + * Return the current list of networks + */ + WirelessNetwork::List networks() const; + + /** + * Find a network with the given @p ssid, a Null object is + * returned if it can not be found + */ + WirelessNetwork::Ptr findNetwork(const QString &ssid) const; + +Q_SIGNALS: + /** + * This signal is emitted when the bitrate of this network has changed. + * + * @param bitrate the new bitrate value for this network + */ + void bitRateChanged(int bitrate); + /** + * The active network changed. + */ + void activeAccessPointChanged(const QString &); + /** + * The device switched operating mode. + */ + void modeChanged(WirelessDevice::OperationMode); + /** + * The device changed its capabilities + */ + void wirelessCapabilitiesChanged(Capabilities); + /** + * The device changed its hardware address + */ + void hardwareAddressChanged(const QString &); + /** + * The device changed its permanent hardware address + */ + void permanentHardwareAddressChanged(const QString &); + /** + * The device changed its properties + */ + void wirelessPropertiesChanged(uint); // TODO this is bogus, remove + /** + * A new wireless access point appeared + */ + void accessPointAppeared(const QString &uni); + /** + * A wireless access point disappeared + */ + void accessPointDisappeared(const QString &uni); + /** + * A wireless network appeared + */ + void networkAppeared(const QString &ssid); + /** + * A wireless network disappeared + */ + void networkDisappeared(const QString &ssid); + /** + * The LastScan property has changed, meaning a scan has just finished + * @since 5.62.0 + * @note will never be emitted when runtime NM < 1.12 + * @see lastScanTime + */ + void lastScanChanged(const QDateTime &dateTime); + +private: + Q_DECLARE_PRIVATE(WirelessDevice) +}; + +} // namespace NetworkManager +#endif // NETWORKMANAGERQT_WIRELESSDEVICE_H diff --git a/panels/dock/tray/networkmanager-qt/src/wirelessdevice_p.h b/panels/dock/tray/networkmanager-qt/src/wirelessdevice_p.h new file mode 100644 index 000000000..05e234e76 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wirelessdevice_p.h @@ -0,0 +1,50 @@ +/* + SPDX-FileCopyrightText: 2008, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRELESSDEVICE_P_H +#define NETWORKMANAGERQT_WIRELESSDEVICE_P_H + +#include "dbus/wirelessdeviceinterface.h" +#include "device_p.h" + +namespace NetworkManager +{ +class WirelessDevicePrivate : public DevicePrivate +{ + Q_OBJECT +public: + explicit WirelessDevicePrivate(const QString &path, WirelessDevice *q); + OrgFreedesktopNetworkManagerDeviceWirelessInterface wirelessIface; + QString permanentHardwareAddress; + QString hardwareAddress; + QHash networks; + QMap apMap; + // index of the active AP or -1 if none + AccessPoint::Ptr activeAccessPoint; + WirelessDevice::OperationMode mode; + uint bitRate; + WirelessDevice::Capabilities wirelessCapabilities; + QDateTime lastScan; + QDateTime lastRequestScan; + + Q_DECLARE_PUBLIC(WirelessDevice) +protected: + /** + * When subclassing make sure to call the parent class method + * if the property was not useful to your new class + */ + void propertyChanged(const QString &property, const QVariant &value) override; + +protected Q_SLOTS: + void accessPointAdded(const QDBusObjectPath &); + void accessPointRemoved(const QDBusObjectPath &); + void removeNetwork(const QString &network); +}; + +} + +#endif diff --git a/panels/dock/tray/networkmanager-qt/src/wirelessnetwork.cpp b/panels/dock/tray/networkmanager-qt/src/wirelessnetwork.cpp new file mode 100644 index 000000000..878773770 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wirelessnetwork.cpp @@ -0,0 +1,146 @@ +/* + SPDX-FileCopyrightText: 2009, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#include "wirelessnetwork.h" +#include "wirelessnetwork_p.h" + +#include "manager.h" +#include "wirelessdevice.h" + +NetworkManager::WirelessNetworkPrivate::WirelessNetworkPrivate(WirelessNetwork *q, WirelessDevice *device) + : q_ptr(q) + , wirelessNetworkInterface(device) +{ + QObject::connect(device, SIGNAL(accessPointAppeared(QString)), q, SLOT(accessPointAppeared(QString))); + QObject::connect(device, SIGNAL(accessPointDisappeared(QString)), q, SLOT(accessPointDisappeared(QString))); + QObject::connect(device, SIGNAL(activeAccessPointChanged(QString)), q, SLOT(updateStrength())); +} + +NetworkManager::WirelessNetworkPrivate::~WirelessNetworkPrivate() +{ +} + +void NetworkManager::WirelessNetworkPrivate::addAccessPointInternal(const NetworkManager::AccessPoint::Ptr &accessPoint) +{ + Q_Q(WirelessNetwork); + + QObject::connect(accessPoint.data(), SIGNAL(signalStrengthChanged(int)), q, SLOT(updateStrength())); + aps.insert(accessPoint->uni(), accessPoint); + updateStrength(); +} + +void NetworkManager::WirelessNetworkPrivate::accessPointAppeared(const QString &uni) +{ + if (!aps.contains(uni) && wirelessNetworkInterface) { + NetworkManager::AccessPoint::Ptr accessPoint = wirelessNetworkInterface->findAccessPoint(uni); + if (accessPoint && accessPoint->ssid() == ssid) { + addAccessPointInternal(accessPoint); + } + } +} + +void NetworkManager::WirelessNetworkPrivate::accessPointDisappeared(const QString &uni) +{ + Q_Q(WirelessNetwork); + aps.remove(uni); + if (aps.isEmpty()) { + Q_EMIT q->disappeared(ssid); + } else { + updateStrength(); + } +} + +void NetworkManager::WirelessNetworkPrivate::updateStrength() +{ + Q_Q(WirelessNetwork); + + int selectedStrength = -1; + NetworkManager::AccessPoint::Ptr selectedAp; + + if (!wirelessNetworkInterface) { + return; + } + + NetworkManager::AccessPoint::Ptr activeAp = wirelessNetworkInterface->activeAccessPoint(); + if (activeAp && activeAp->ssid() == ssid) { + // If the network has an active access point, use it as the referenceAp + selectedStrength = activeAp->signalStrength(); + selectedAp = activeAp; + } else { + // Otherwise, choose the access point with the strongest signal + for (const NetworkManager::AccessPoint::Ptr &iface : std::as_const(aps)) { + if (selectedStrength <= iface->signalStrength()) { + selectedStrength = iface->signalStrength(); + selectedAp = iface; + } + } + } + + if (selectedStrength != strength) { + strength = selectedStrength; + Q_EMIT q->signalStrengthChanged(strength); + } + + if (selectedAp && referenceAp != selectedAp) { + referenceAp = selectedAp; + Q_EMIT q->referenceAccessPointChanged(referenceAp->uni()); + } + // TODO: update the networks delayed + // kDebug() << "update strength" << ssid << strength; +} + +NetworkManager::WirelessNetwork::WirelessNetwork(const AccessPoint::Ptr &accessPoint, WirelessDevice *device) + : d_ptr(new WirelessNetworkPrivate(this, device)) +{ + Q_D(WirelessNetwork); + + d->strength = -1; + d->ssid = accessPoint->ssid(); + d->addAccessPointInternal(accessPoint); +} + +NetworkManager::WirelessNetwork::~WirelessNetwork() +{ + delete d_ptr; +} + +QString NetworkManager::WirelessNetwork::ssid() const +{ + Q_D(const WirelessNetwork); + return d->ssid; +} + +int NetworkManager::WirelessNetwork::signalStrength() const +{ + Q_D(const WirelessNetwork); + return d->strength; +} + +NetworkManager::AccessPoint::Ptr NetworkManager::WirelessNetwork::referenceAccessPoint() const +{ + Q_D(const WirelessNetwork); + return d->referenceAp; +} + +NetworkManager::AccessPoint::List NetworkManager::WirelessNetwork::accessPoints() const +{ + Q_D(const WirelessNetwork); + return d->aps.values(); +} + +QString NetworkManager::WirelessNetwork::device() const +{ + Q_D(const WirelessNetwork); + + if (d->wirelessNetworkInterface) { + return d->wirelessNetworkInterface->uni(); + } else { + return QString(); + } +} + +#include "moc_wirelessnetwork.cpp" diff --git a/panels/dock/tray/networkmanager-qt/src/wirelessnetwork.h b/panels/dock/tray/networkmanager-qt/src/wirelessnetwork.h new file mode 100644 index 000000000..de89590d9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wirelessnetwork.h @@ -0,0 +1,97 @@ +/* + SPDX-FileCopyrightText: 2009, 2011 Will Stephenson + SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRELESSNETWORK_H +#define NETWORKMANAGERQT_WIRELESSNETWORK_H + +#include "accesspoint.h" +#include + +#include +#include + +namespace NetworkManager +{ +class WirelessDevice; +class WirelessNetworkPrivate; + +/** + * This class represents a wireless network, which aggregates all + * access points with the same SSID + */ +class NETWORKMANAGERQT_EXPORT WirelessNetwork : public QObject +{ + Q_OBJECT + friend class WirelessDevice; + friend class WirelessDevicePrivate; + +public: + typedef QSharedPointer Ptr; + typedef QList List; + ~WirelessNetwork() override; + /** + * ESSID of the network + */ + QString ssid() const; + + /** + * Signal strength of the network. Syntactic sugar around tracking the reference access + * point and watching its signal strength + */ + int signalStrength() const; + + /** + * The uni of the current 'best' (strongest) Access Point. Note that this may change or disappear over time. + * Get the Access Point object using @ref WirelessDevice::findAccessPoint() on the NetworkInterface this network was obtained from. + * Use @ref WirelessDevice::accessPointDisappeared() or + * WirelessNetwork::referenceAccessPointChanged() to detect this. + */ + AccessPoint::Ptr referenceAccessPoint() const; + + /** + * List of access points + * @warning Subject to change, do not store! + */ + AccessPoint::List accessPoints() const; + + /** + * The uni of device associated with this network. + */ + QString device() const; + +Q_SIGNALS: + /** + * Indicate that the signal strength changed + * @param strength strength as a percentage. + */ + void signalStrengthChanged(int strength); + /** + * Indicate that the reference access point changed + * @param apUni new access point or empty string if none + */ + void referenceAccessPointChanged(const QString &apUni); + /** + * Indicate that this network has no more access points + * (meaning the network has disappeared from view of the network interface) + * @param ssid the SSID of this network + */ + void disappeared(const QString &ssid); + +private: + Q_DECLARE_PRIVATE(WirelessNetwork) + Q_PRIVATE_SLOT(d_func(), void accessPointAppeared(const QString &)) + Q_PRIVATE_SLOT(d_func(), void accessPointDisappeared(const QString &)) + Q_PRIVATE_SLOT(d_func(), void updateStrength()) + + WirelessNetworkPrivate *const d_ptr; + + explicit WirelessNetwork(const AccessPoint::Ptr &accessPoint, WirelessDevice *device); +}; + +} +#endif // NETWORKMANAGERQT_WIRELESSNETWORK_H diff --git a/panels/dock/tray/networkmanager-qt/src/wirelessnetwork_p.h b/panels/dock/tray/networkmanager-qt/src/wirelessnetwork_p.h new file mode 100644 index 000000000..237e4aee9 --- /dev/null +++ b/panels/dock/tray/networkmanager-qt/src/wirelessnetwork_p.h @@ -0,0 +1,42 @@ +/* + SPDX-FileCopyrightText: 2009, 2011 Will Stephenson + SPDX-FileCopyrightText: 2013 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +#ifndef NETWORKMANAGERQT_WIRELESSNETWORK_P_H +#define NETWORKMANAGERQT_WIRELESSNETWORK_P_H + +#include "wirelessdevice.h" + +#include + +namespace NetworkManager +{ +class WirelessNetworkPrivate +{ +public: + Q_DECLARE_PUBLIC(WirelessNetwork) + WirelessNetwork *q_ptr; + + WirelessNetworkPrivate(WirelessNetwork *q, WirelessDevice *); + ~WirelessNetworkPrivate(); + + void addAccessPointInternal(const AccessPoint::Ptr &accessPoint); + + QString ssid; + int strength; + QPointer wirelessNetworkInterface; + QHash aps; + AccessPoint::Ptr referenceAp; + +private Q_SLOTS: + void accessPointAppeared(const QString &uni); + void accessPointDisappeared(const QString &uni); + void updateStrength(); +}; + +} + +#endif diff --git a/panels/dock/tray/plugins/CMakeLists.txt b/panels/dock/tray/plugins/CMakeLists.txt index 609ab9ae4..12fdca71c 100644 --- a/panels/dock/tray/plugins/CMakeLists.txt +++ b/panels/dock/tray/plugins/CMakeLists.txt @@ -11,3 +11,4 @@ add_subdirectory("bluetooth") add_subdirectory("airplane-mode") add_subdirectory("notification") add_subdirectory("deepin-screen-recorder") +add_subdirectory("dde-network-core") diff --git a/panels/dock/tray/plugins/bluetooth/CMakeLists.txt b/panels/dock/tray/plugins/bluetooth/CMakeLists.txt index fc593036b..ac3e8d900 100644 --- a/panels/dock/tray/plugins/bluetooth/CMakeLists.txt +++ b/panels/dock/tray/plugins/bluetooth/CMakeLists.txt @@ -34,6 +34,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../quic target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces ../../frame + ../../frame/util ../../frame/qtdbusextended ./dbusinterface/generation_dbus_interface componments) diff --git a/panels/dock/tray/plugins/dde-network-core/CMakeLists.txt b/panels/dock/tray/plugins/dde-network-core/CMakeLists.txt new file mode 100644 index 000000000..ce4ee5f23 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.7) + +set(VERSION "2.0.18" CACHE STRING "define project version") +project(dde-network-core + VERSION ${VERSION} + DESCRIPTION "DDE Network Core" + HOMEPAGE_URL "https://github.com/linuxdeepin/dde-network-core" + LANGUAGES CXX C +) + +# 增加安全编译参数 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z relro -z now -z noexecstack -pie") + +option(ENABLE_DEEPIN_NMQT "enable nmqt patch on deepin" OFF) + +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) +set(QT_MAJOR_VERSION 6) +find_package(Qt6 COMPONENTS Core Widgets DBus Network LinguistTools REQUIRED) + +if (ENABLE_DEEPIN_NMQT) + add_definitions(-DUSE_DEEPIN_NMQT) +endif() + +message(STATUS DEEPIN_NMQT_TEST ": ${DEEPIN_NMQT_TEST}") + +add_subdirectory("src") +add_subdirectory("dock-network-plugin") diff --git a/panels/dock/tray/plugins/dde-network-core/README.md b/panels/dock/tray/plugins/dde-network-core/README.md new file mode 100644 index 000000000..00c8fca23 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/README.md @@ -0,0 +1,58 @@ +## DDE Network Core + +DDE network library framework + +## Dependencies +You can also check the "Depends" provided in the debian/control file. + +### Build dependencies +You can also check the "Build-Depends" provided in the debian/control file. + +## Installation + +### Build from source code + +1. Make sure you have installed all dependencies. + +2. Build: +``` +$ cd dde-network-core +$ mkdir Build +$ cd Build +$ cmake .. +$ make +``` + +3. Install: +``` +$ sudo make install +``` + +The executable binary file could be found at `/usr/bin/dde-network-dialog` after the installation is finished, and plugins will be placed into related module plugin directory. + +## Usage + +Execute `dde-network-dialog -h` to get more details. + +## Getting help + +You can press `F1` to start [deepin-manual](https://github.com/linuxdeepin/deepin-manual) when you focus on DDE Control Center network module. + +You may also find these channels useful if you encounter any other issues: + +* [Gitter](https://gitter.im/orgs/linuxdeepin/rooms) +* [IRC Channel](https://webchat.freenode.net/?channels=deepin) +* [Official Forum](https://bbs.deepin.org/) +* [Wiki](https://wiki.deepin.org/) +* [Developer Center](https://github.com/linuxdeepin/dde-network-core) + +## Getting involved + +We encourage you to report issues and contribute changes + +* [Contribution guide for developers](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers-en). (English) +* [开发者代码贡献指南](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers) (中文) + +## License + +DDE Network Core is licensed under [LGPL-3.0-or-later](LICENSE). diff --git a/panels/dock/tray/plugins/dde-network-core/README.zh_CN.md b/panels/dock/tray/plugins/dde-network-core/README.zh_CN.md new file mode 100644 index 000000000..f2a15a64e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/README.zh_CN.md @@ -0,0 +1,57 @@ +## DDE网络核心框架 +DDE网络核心框架是UOS桌面环境的网络连接框架。 + +## 依赖 +请查看“debian/control”文件中提供的“Depends”。 + +### 编译依赖 +请查看“debian/control”文件中提供的“Build-Depends”。 + +## 安装 + +### 构建过程 + +1. 确保已经安装了所有的编译依赖 + +2. 构建 +``` +$ cd dde-network-core +$ mkdir Build +$ cd Build +$ cmake .. +$ make +``` + +3. 安装 +``` +$ sudo make install +``` + +安装完成后可执行二进制文件在/usr/bin/dde-network-dialog,插件会放在相关模块的插件目录下。 + +## 用法 + +执行 `dde-network-dialog -h` 以获取更多详细信息。 + +## 获得帮助 + +当你使用DDE控制中心,进入网络模块时,您可以按 `F1` 启动 [deepin-manual](https://github.com/linuxdeepin/deepin-manual)。 + +如果您遇到任何其他问题,您可能还会发现这些渠道很有用: + +* [Gitter](https://gitter.im/orgs/linuxdeepin/rooms) +* [IRC Channel](https://webchat.freenode.net/?channels=deepin) +* [官方论坛](https://bbs.deepin.org/) +* [Wiki](https://wiki.deepin.org/) +* [项目地址](https://github.com/linuxdeepin/dde-network-core) + +## 贡献指南 + +我们鼓励您报告问题并做出更改 + +* [Contribution guide for developers](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers-en). (English) +* [开发者代码贡献指南](https://github.com/linuxdeepin/developer-center/wiki/Contribution-Guidelines-for-Developers) (中文) + +## License + +DDE网络核心框架在 [LGPL-3.0-or-later](LICENSE)下发布。 diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.cpp new file mode 100644 index 000000000..b0372108e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.cpp @@ -0,0 +1,444 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "devicestatushandler.h" + +#include +#include +#include + +DeviceStatusHandler::DeviceStatusHandler(QObject *parent) + : QObject(parent) +{ +} + +DeviceStatusHandler::~DeviceStatusHandler() +{ +} + +PluginState DeviceStatusHandler::pluginState() +{ + QList devices = NetworkController::instance()->devices(); + // 筛选出所有的有线和无线的状态 + QList wiredDevices; + QList wirelessDevice; + for (NetworkDeviceBase *deviceBase : devices) { + if (deviceBase->deviceType() == DeviceType::Wired) { + WiredDevice *device = static_cast(deviceBase); + wiredDevices << device; + } else if (deviceBase->deviceType() == DeviceType::Wireless) { + WirelessDevice *device = static_cast(deviceBase); + wirelessDevice << device; + } + } + + // 计算有线网络和无线网络的合并状态 + NetDeviceStatus wiredStat = wiredStatus(wiredDevices); + NetDeviceStatus wirelessStat = wirelessStatus(wirelessDevice); + return plugState(wiredStat, wirelessStat); +} + +NetDeviceStatus DeviceStatusHandler::wiredStatus(WiredDevice *device) +{ + // 如果当前网卡是禁用,直接返回禁用 + if (!device->isEnabled()) + return NetDeviceStatus::Disabled; + + // 网络是已连接,但是当前的连接状态不是Full,则认为网络连接成功,但是无法上网 + if (device->deviceStatus() == DeviceStatus::Activated + && NetworkController::instance()->connectivity() != Connectivity::Full) { + return NetDeviceStatus::ConnectNoInternet; + } + + // 获取IP地址失败 + if (!device->IPValid()) + return NetDeviceStatus::ObtainIpFailed; + + // 根据设备状态来直接获取返回值 + switch (device->deviceStatus()) { + case DeviceStatus::Unmanaged: + case DeviceStatus::Unavailable: return NetDeviceStatus::Nocable; + case DeviceStatus::Disconnected: return NetDeviceStatus::Disconnected; + case DeviceStatus::Prepare: + case DeviceStatus::Config: return NetDeviceStatus::Connecting; + case DeviceStatus::Needauth: return NetDeviceStatus::Authenticating; + case DeviceStatus::IpConfig: + case DeviceStatus::IpCheck: + case DeviceStatus::Secondaries: return NetDeviceStatus::ObtainingIP; + case DeviceStatus::Activated: return NetDeviceStatus::Connected; + case DeviceStatus::Deactivation: + case DeviceStatus::Failed: return NetDeviceStatus::ConnectFailed; + case DeviceStatus::IpConfilct: return NetDeviceStatus::IpConflicted; + default: return NetDeviceStatus::Unknown; + } + + Q_UNREACHABLE(); + return NetDeviceStatus::Unknown; +} + +NetDeviceStatus DeviceStatusHandler::wiredStatus(const QList &devices) +{ + QList deviceStatus; + for (WiredDevice *device : devices) + deviceStatus << wiredStatus(device); + + // 显示的规则:从allDeviceStatus列表中按照顺序遍历所有的状态, + // 再遍历所有的设备的状态,只要其中一个设备的状态满足当前的状态,就返回当前状态 + static QList allDeviceStatus = + { NetDeviceStatus::Authenticating, NetDeviceStatus::ObtainingIP, NetDeviceStatus::IpConflicted, + NetDeviceStatus::Connected, NetDeviceStatus::ConnectNoInternet, NetDeviceStatus::Connecting, + NetDeviceStatus::Disconnected, NetDeviceStatus::Disabled, NetDeviceStatus::Nocable, NetDeviceStatus::Unknown }; + for (int i = 0; i < allDeviceStatus.size(); i++) { + NetDeviceStatus status = allDeviceStatus[i]; + if (deviceStatus.contains(status)) + return status; + } + + return NetDeviceStatus::Unknown; +} + +NetDeviceStatus DeviceStatusHandler::wirelessStatus(WirelessDevice *device) +{ + if (!device->isEnabled()) + return NetDeviceStatus::Disabled; + + if (device->deviceStatus() == DeviceStatus::Activated + && device->connectivity() != Connectivity::Full) { + return NetDeviceStatus::ConnectNoInternet; + } + + if (!device->IPValid()) + return NetDeviceStatus::ObtainIpFailed; + + DeviceStatus status = device->deviceStatus(); + switch (status) { + case DeviceStatus::Unmanaged: + case DeviceStatus::Unavailable: + case DeviceStatus::Disconnected: return NetDeviceStatus::Disconnected; + case DeviceStatus::Prepare: + case DeviceStatus::Config: return NetDeviceStatus::Connecting; + case DeviceStatus::Needauth: return NetDeviceStatus::Authenticating; + case DeviceStatus::IpConfig: + case DeviceStatus::IpCheck: + case DeviceStatus::Secondaries: return NetDeviceStatus::ObtainingIP; + case DeviceStatus::Activated: return NetDeviceStatus::Connected; + case DeviceStatus::Deactivation: + case DeviceStatus::Failed: return NetDeviceStatus::ConnectFailed; + case DeviceStatus::IpConfilct: return NetDeviceStatus::IpConflicted; + default: return NetDeviceStatus::Unknown; + } + + Q_UNREACHABLE(); + return NetDeviceStatus::Unknown; +} + +NetDeviceStatus DeviceStatusHandler::wirelessStatus(const QList &devices) +{ + // 所有设备状态叠加 + QList devStatus; + for (WirelessDevice *device : devices) + devStatus << wirelessStatus(device); + + static QList allDeviceStatus = + { NetDeviceStatus::Authenticating, NetDeviceStatus::ObtainingIP, NetDeviceStatus::IpConflicted, + NetDeviceStatus::Connected, NetDeviceStatus::ConnectNoInternet, NetDeviceStatus::Connecting, + NetDeviceStatus::Disconnected, NetDeviceStatus::Disabled, NetDeviceStatus::Unknown}; + + for (int i = 0; i < allDeviceStatus.size(); i++) { + NetDeviceStatus status = allDeviceStatus[i]; + if (devStatus.contains(status)) + return status; + } + + return NetDeviceStatus::Unknown; +} + +PluginState DeviceStatusHandler::plugState(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + if (isUnknow(wiredStatus, wirelessStatus)) + return PluginState::Unknown; + + if (isDisabled(wiredStatus, wirelessStatus)) + return PluginState::Disabled; + + if (isWiredDisconnected(wiredStatus, wirelessStatus)) + return PluginState::WiredDisconnected; + + if (isWiredDisabled(wiredStatus, wirelessStatus)) + return PluginState::WiredDisabled; + + if (isWiredConnected(wiredStatus, wirelessStatus)) + return PluginState::WiredConnected; + + if (isWiredConnecting(wiredStatus, wirelessStatus)) + return PluginState::WiredConnecting; + + if (isWiredConnectNoInternet(wiredStatus, wirelessStatus)) + return PluginState::WiredConnectNoInternet; + + if (isNocable(wiredStatus, wirelessStatus)) + return PluginState::Nocable; + + if (isWiredFailed(wiredStatus, wirelessStatus)) + return PluginState::WiredFailed; + + if (isWirelessDisconnected(wiredStatus, wirelessStatus)) + return PluginState::WirelessDisconnected; + + if (isWirelessDisabled(wiredStatus, wirelessStatus)) + return PluginState::WirelessDisabled; + + if (isWirelessConnected(wiredStatus, wirelessStatus)) + return PluginState::WirelessConnected; + + if (isWirelessConnecting(wiredStatus, wirelessStatus)) + return PluginState::WirelessConnecting; + + if (isWirelessConnectNoInternet(wiredStatus, wirelessStatus)) + return PluginState::WirelessConnectNoInternet; + + if (isWirelessFailed(wiredStatus, wirelessStatus)) + return PluginState::WirelessFailed; + + if (isDisconnected(wiredStatus, wirelessStatus)) + return PluginState::Disconnected; + + if (wirelessStatus == NetDeviceStatus::IpConflicted) + return PluginState::WirelessIpConflicted; + + if (wiredStatus == NetDeviceStatus::IpConflicted) + return PluginState::WiredIpConflicted; + + if (isConnected(wiredStatus, wirelessStatus)) + return PluginState::Connected; + + if (isConnecting(wiredStatus, wirelessStatus)) + return PluginState::Connecting; + + if (isConnectNoInternet(wiredStatus, wirelessStatus)) + return PluginState::ConnectNoInternet; + + return PluginState::Failed; +} + +bool DeviceStatusHandler::isUnknow(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线和有线都是未知状态,则认为是未知状态(都没有网卡) + return (wiredStatus == NetDeviceStatus::Unknown + && wirelessStatus == NetDeviceStatus::Unknown); +} + +bool DeviceStatusHandler::isDisabled(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线无线都禁用,则认为是禁用状态 + return (wiredStatus == NetDeviceStatus::Disabled + && wirelessStatus == NetDeviceStatus::Disabled); +} + +bool DeviceStatusHandler::isWiredDisconnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 没有无线或者无线禁用的情况下, 有线设备开启、有线设备断开连接,有线设备获取IP失败,认为有线连接失败 + return ((wirelessStatus == NetDeviceStatus::Unknown && wiredStatus == NetDeviceStatus::Enabled) + || (wirelessStatus == NetDeviceStatus::Unknown && wiredStatus == NetDeviceStatus::Disconnected) + || (wirelessStatus == NetDeviceStatus::Unknown && wiredStatus == NetDeviceStatus::ObtainIpFailed) + || (wirelessStatus == NetDeviceStatus::Disabled && wiredStatus == NetDeviceStatus::Enabled) + || (wirelessStatus == NetDeviceStatus::Disabled && wiredStatus == NetDeviceStatus::Disconnected) + || (wirelessStatus == NetDeviceStatus::Disabled && wiredStatus == NetDeviceStatus::ObtainIpFailed)); +} + +bool DeviceStatusHandler::isWiredDisabled(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线禁用了,没有无线网卡 + return (wiredStatus == NetDeviceStatus::Disabled + && wirelessStatus == NetDeviceStatus::Unknown); +} + +bool DeviceStatusHandler::isWiredConnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 如果有线是连接状态,没有无线,无线启用,无线禁用,无线断开连接,无线获取IP失败,无线连接成功但是无网络 + // 无线连接失败,则认为是有线连接成功 + static QList wirelessFailuredStatus = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::ConnectNoInternet + , NetDeviceStatus::ConnectFailed }; + + return ((wiredStatus == NetDeviceStatus::Connected) + && (wirelessFailuredStatus.contains(wirelessStatus))); +} + +bool DeviceStatusHandler::isWiredConnecting(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线正在连接,正在认证,正在获取IP + // 没有无线,无线开启和禁用、连接成功,断开连接,获取IP失败,连接但是没有网络,连接失败 + // 这种情况认为是有线正在连接 + static QList wiredConnectingStatus = + { NetDeviceStatus::Connecting, NetDeviceStatus::Authenticating, NetDeviceStatus::ObtainingIP }; + static QList wirelessConnecting = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Connected + , NetDeviceStatus::Disconnected, NetDeviceStatus::ObtainIpFailed + , NetDeviceStatus::ConnectNoInternet, NetDeviceStatus::ConnectFailed }; + + return (wiredConnectingStatus.contains(wiredStatus) + && wirelessConnecting.contains(wirelessStatus)); +} + +bool DeviceStatusHandler::isWiredConnectNoInternet(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 没有无线,无线开启或禁用,无线断开连接,无线获取IP失败,无线连接失败 + // 有线连接但是没有网络 + // 这种情况认为是有线连接无网络 + static QList wirelessNoConnectStatus = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::ConnectFailed }; + + return (wiredStatus == NetDeviceStatus::ConnectNoInternet + && wirelessNoConnectStatus.contains(wirelessStatus)); +} + +bool DeviceStatusHandler::isNocable(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线不可用,没有无线或无线禁用,这种情况认为是网络不可用 + return (wiredStatus == NetDeviceStatus::Nocable + && (wirelessStatus == NetDeviceStatus::Unknown + || wirelessStatus == NetDeviceStatus::Disabled )); +} + +bool DeviceStatusHandler::isWiredFailed(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线连接失败,没有无线或无线禁用,这种情况认为是有线不可用 + return (wiredStatus == NetDeviceStatus::ConnectFailed + && (wirelessStatus == NetDeviceStatus::Unknown + || wirelessStatus == NetDeviceStatus::Disabled )); +} + +bool DeviceStatusHandler::isWirelessDisconnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线启用,断开连接,获取IP失败 + // 没有有线,有线禁用,有线无效,有线失败 + // 这种情况认为是无线断开连接 + static QList wirelessStatusOfDis = + { NetDeviceStatus::Enabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed }; + static QList wiredStatusOfDis = + { NetDeviceStatus::Unknown, NetDeviceStatus::Disabled + , NetDeviceStatus::Nocable, NetDeviceStatus::ConnectFailed }; + + return ((wirelessStatusOfDis.contains(wirelessStatus) + && wiredStatusOfDis.contains(wiredStatus)) + || (wirelessStatus == NetDeviceStatus::ConnectFailed + && wiredStatus == NetDeviceStatus::Nocable)); +} + +bool DeviceStatusHandler::isWirelessDisabled(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线禁用,没有有线,这种情况认为是无线禁用 + return (wirelessStatus == NetDeviceStatus::Disabled + && wiredStatus == NetDeviceStatus::Unknown); +} + +bool DeviceStatusHandler::isWirelessConnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 没有有线网卡,有线启用禁用,断开连接,获取IP失败,已经连接网络但是无法上网,无效和失败 + // 无线网络已连接,这种情况认为是无线网络已连接 + static QList wiredFailusStatus = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::ConnectNoInternet + , NetDeviceStatus::Nocable, NetDeviceStatus::ConnectFailed }; + + return (wiredFailusStatus.contains(wiredStatus) + && wirelessStatus == NetDeviceStatus::Connected); +} + +bool DeviceStatusHandler::isWirelessConnecting(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线状态:正在连接,正在认证, 正在获取IP + // 有线状态:没有有线,禁用,启用,连接成功,断开连接,获取IP失败,连接成功但是无法上网,无效,连接失败 + // 这种情况认为是无线正在连接 + static QList wirelessConnecting = + { NetDeviceStatus::Connecting, NetDeviceStatus::Authenticating + , NetDeviceStatus::ObtainingIP }; + + static QList wiredOfConnecting = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Connected + , NetDeviceStatus::Disconnected, NetDeviceStatus::ObtainIpFailed + , NetDeviceStatus::ConnectNoInternet, NetDeviceStatus::Nocable + , NetDeviceStatus::ConnectFailed }; + + return (wirelessConnecting.contains(wirelessStatus) + && wiredOfConnecting.contains(wiredStatus)); +} + +bool DeviceStatusHandler::isWirelessConnectNoInternet(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线状态:没有无线,启用,禁用,断开连接,获取IP失败,无效,失败 + // 无线是已连接但是无法上网,这种情况认为是无线已连接但是无法上网 + static QList allWiredStatus = + { NetDeviceStatus::Unknown, NetDeviceStatus::Enabled + , NetDeviceStatus::Disabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::Nocable + , NetDeviceStatus::ConnectFailed }; + + return (allWiredStatus.contains(wiredStatus) + && wirelessStatus == NetDeviceStatus::ConnectNoInternet); +} + +bool DeviceStatusHandler::isWirelessFailed(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线连接失败,在没有有线和有线禁用的情况下,认为无线连接失败 + return (wirelessStatus == NetDeviceStatus::ConnectFailed + && (wiredStatus == NetDeviceStatus::Unknown + || wiredStatus == NetDeviceStatus::Disabled)); +} + +bool DeviceStatusHandler::isDisconnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 无线启用,断开连接,获取IP失败,连接失败 + // 有线启用,断开连接,获取IP失败 + // 这种情况认为网络连接断开 + static QList disconectStatusWireless = + { NetDeviceStatus::Enabled, NetDeviceStatus::Disconnected + , NetDeviceStatus::ObtainIpFailed, NetDeviceStatus::ConnectFailed }; + + static QList disconnectStatusWired = + { NetDeviceStatus::Enabled, NetDeviceStatus::Disconnected, NetDeviceStatus::ObtainIpFailed }; + + return (disconectStatusWireless.contains(wirelessStatus) + && disconnectStatusWired.contains(wiredStatus)); +} + +bool DeviceStatusHandler::isConnected(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线和无线都连接成功,这种情况认为连接成功 + return (wirelessStatus == NetDeviceStatus::Connected + && wiredStatus == NetDeviceStatus::Connected); +} + +bool DeviceStatusHandler::isConnecting(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线正在连接,正在认证,正在获取IP + // 无线正在连接,正在认证,正在获取IP + // 这种情况认为是正在连接 + static QList connectingWired = + { NetDeviceStatus::Connecting, NetDeviceStatus::Authenticating + , NetDeviceStatus::ObtainingIP }; + + static QList connectingWireless = + { NetDeviceStatus::Connecting, NetDeviceStatus::Authenticating + , NetDeviceStatus::ObtainingIP }; + + return (connectingWired.contains(wiredStatus) + && connectingWireless.contains(wirelessStatus)); +} + +bool DeviceStatusHandler::isConnectNoInternet(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus) +{ + // 有线和无线都已经连接但是无法上网,这种情况认为是已连接但是无法上网 + return (wirelessStatus == NetDeviceStatus::ConnectNoInternet + && wiredStatus == NetDeviceStatus::ConnectNoInternet); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.h new file mode 100644 index 000000000..4dba551c9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/item/devicestatushandler.h @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DEVICESTATUSHANDLER_H +#define DEVICESTATUSHANDLER_H + +#include + +namespace dde { + namespace network { + class WiredDevice; + class WirelessDevice; + } +} + +using namespace dde::network; + +enum class NetDeviceStatus { + Unknown = 0, + Enabled, + Disabled, + Connected, + Disconnected, + Connecting, + Authenticating, + ObtainingIP, + ObtainIpFailed, + ConnectNoInternet, + IpConflicted, + Nocable, + ConnectFailed +}; + +enum class PluginState +{ + Unknown = 0, + Disabled, + Connected, + Disconnected, + Connecting, + Failed, + ConnectNoInternet, + WirelessDisabled, + WiredDisabled, + WirelessConnected, + WiredConnected, + WirelessDisconnected, + WiredDisconnected, + WirelessConnecting, + WiredConnecting, + WirelessConnectNoInternet, + WiredConnectNoInternet, + WirelessFailed, + WiredFailed, + WiredIpConflicted, + WirelessIpConflicted, + Nocable +}; + +#define DECLARE_STATIC_CHECKSTATUS(method) static bool method(const NetDeviceStatus &, const NetDeviceStatus &); + +class DeviceStatusHandler : public QObject +{ + Q_OBJECT + +public: + // 获取当前所有的设备列表的状态 + static PluginState pluginState(); + + static NetDeviceStatus wiredStatus(WiredDevice * device); + static NetDeviceStatus wiredStatus(const QList &devices); + static NetDeviceStatus wirelessStatus(WirelessDevice *device); + static NetDeviceStatus wirelessStatus(const QList &devices); + static PluginState plugState(const NetDeviceStatus &wiredStatus, const NetDeviceStatus &wirelessStatus); + +private: + explicit DeviceStatusHandler(QObject *parent = Q_NULLPTR); + ~DeviceStatusHandler(); + +private: + DECLARE_STATIC_CHECKSTATUS(isUnknow) + DECLARE_STATIC_CHECKSTATUS(isDisabled) + DECLARE_STATIC_CHECKSTATUS(isWiredDisconnected) + DECLARE_STATIC_CHECKSTATUS(isWiredDisabled) + DECLARE_STATIC_CHECKSTATUS(isWiredConnected) + DECLARE_STATIC_CHECKSTATUS(isWiredConnecting) + DECLARE_STATIC_CHECKSTATUS(isWiredConnectNoInternet) + DECLARE_STATIC_CHECKSTATUS(isNocable) + DECLARE_STATIC_CHECKSTATUS(isWiredFailed) + DECLARE_STATIC_CHECKSTATUS(isWirelessDisconnected) + DECLARE_STATIC_CHECKSTATUS(isWirelessDisabled) + DECLARE_STATIC_CHECKSTATUS(isWirelessConnected) + DECLARE_STATIC_CHECKSTATUS(isWirelessConnecting) + DECLARE_STATIC_CHECKSTATUS(isWirelessConnectNoInternet) + DECLARE_STATIC_CHECKSTATUS(isWirelessFailed) + DECLARE_STATIC_CHECKSTATUS(isDisconnected) + DECLARE_STATIC_CHECKSTATUS(isConnected) + DECLARE_STATIC_CHECKSTATUS(isConnecting) + DECLARE_STATIC_CHECKSTATUS(isConnectNoInternet) +}; + +#endif // DEVICESTATUSHANDLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/network.qrc b/panels/dock/tray/plugins/dde-network-core/common-plugin/network.qrc new file mode 100644 index 000000000..55271263d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/network.qrc @@ -0,0 +1,80 @@ + + + resources/light/network-wired-symbolic-connecting1.svg + resources/light/network-wired-symbolic-connecting2.svg + resources/light/network-wired-symbolic-connecting3.svg + resources/light/network-wired-symbolic-connecting4.svg + resources/light/network-wired-symbolic-connecting5.svg + resources/light/network-disabled-symbolic.svg + resources/light/network-error-symbolic.svg + resources/light/network-online-symbolic.svg + resources/light/network-offline-symbolic.svg + resources/light/network-wired-symbolic.svg + resources/light/network-none-symbolic.svg + resources/light/network-warning-symbolic.svg + resources/light/wireless-background.svg + resources/light/wireless-disconnect.svg + resources/light/wireless-offline-symbolic.svg + resources/light/wireless-0-symbolic.svg + resources/light/wireless-20-symbolic.svg + resources/light/wireless-40-symbolic.svg + resources/light/wireless-60-symbolic.svg + resources/light/wireless-80-symbolic.svg + resources/light/wireless-disconnect-symbolic.svg + resources/light/security.svg + resources/light/select.svg + resources/light/disconnect.svg + resources/light/refresh.svg + resources/light/wireless-disabled-symbolic.svg + resources/light/wireless6-0-symbolic.svg + resources/light/wireless6-20-symbolic.svg + resources/light/wireless6-40-symbolic.svg + resources/light/wireless6-60-symbolic.svg + resources/light/wireless6-80-symbolic.svg + resources/light/wireless6-no-route-symbolic.svg + resources/light/wireless6-offline-symbolic.svg + resources/light/wireless6-warning-symbolic.svg + + + resources/dark/network-wired-symbolic-connecting1.svg + resources/dark/network-wired-symbolic-connecting2.svg + resources/dark/network-wired-symbolic-connecting3.svg + resources/dark/network-wired-symbolic-connecting4.svg + resources/dark/network-wired-symbolic-connecting5.svg + resources/dark/network-disabled-symbolic.svg + resources/dark/network-error-symbolic.svg + resources/dark/network-online-symbolic.svg + resources/dark/network-offline-symbolic.svg + resources/dark/network-wired-symbolic.svg + resources/dark/network-none-symbolic.svg + resources/dark/network-warning-symbolic.svg + resources/dark/wireless-background.svg + resources/dark/wireless-disconnect.svg + resources/dark/wireless-offline-symbolic.svg + resources/dark/wireless-0-symbolic.svg + resources/dark/wireless-20-symbolic.svg + resources/dark/wireless-40-symbolic.svg + resources/dark/wireless-60-symbolic.svg + resources/dark/wireless-80-symbolic.svg + resources/dark/wireless-disconnect-symbolic.svg + resources/dark/security.svg + resources/dark/select.svg + resources/dark/disconnect.svg + resources/dark/refresh.svg + resources/dark/wireless-disabled-symbolic.svg + resources/dark/wireless6-0-symbolic.svg + resources/dark/wireless6-20-symbolic.svg + resources/dark/wireless6-40-symbolic.svg + resources/dark/wireless6-60-symbolic.svg + resources/dark/wireless6-80-symbolic.svg + resources/dark/wireless6-no-route-symbolic.svg + resources/dark/wireless6-offline-symbolic.svg + resources/dark/wireless6-warning-symbolic.svg + + + resources/common/list_select.png + resources/common/list_select@2x.png + resources/common/notify_close_press.png + resources/common/notify_close_press@2x.png + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.cpp new file mode 100644 index 000000000..4f729fe63 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.cpp @@ -0,0 +1,155 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkdialog.h" +#include "networkdialog/networkpanel.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +NETWORKPLUGIN_USE_NAMESPACE + +static const QString NetworkDialogApp = "dde-network-dialog"; //网络列表执行文件 +static QMap s_FunMap = { + { "password", &NetworkDialog::sendPassword }, + { "connect", &NetworkDialog::connectNetwork }, +}; + +NetworkDialog::NetworkDialog(QObject *parent) + : QObject(parent) + , m_server(nullptr) + , m_panel(new NetworkPanel()) +{ + connect(m_panel, &NetworkPanel::passwordChanged, this, &NetworkDialog::changePassword); +} + +NetworkDialog::~NetworkDialog() +{ +} + +void NetworkDialog::setServerName(const QString &name) +{ + if (m_server) + return; + + m_serverName = name; + m_server = new QLocalServer(this); + connect(m_server, SIGNAL(newConnection()), this, SLOT(newConnectionHandler())); + m_server->setSocketOptions(QLocalServer::WorldAccessOption); + + m_server->listen(m_serverName); +} + +bool NetworkDialog::closeOnClear() const +{ + return m_panel->closeOnClear(); +} + +void NetworkDialog::setCloseOnClear(bool closeOnClear) +{ + m_panel->setCloseOnClear(closeOnClear); +} + +void NetworkDialog::clear() +{ + m_panel->clear(); +} + +QWidget *NetworkDialog::panel() +{ + return m_panel->itemApplet(); +} + +void NetworkDialog::setConnectWireless(const QString &dev, const QString &ssid, bool wait) +{ + m_connectDev = dev; + m_connectSsid = ssid; + Q_EMIT requestShow(); + // 先响应requestShow将界面显示后再显示密码输入框,否则输入框无焦点 + QTimer::singleShot(100, this, [ = ]{ + m_panel->passwordError(dev, ssid, wait); + }); +} + +void NetworkDialog::newConnectionHandler() +{ + QLocalSocket *socket = m_server->nextPendingConnection(); + connect(socket, SIGNAL(readyRead()), this, SLOT(readyReadHandler())); + connect(socket, SIGNAL(disconnected()), this, SLOT(disconnectedHandler())); + m_clients.append(socket); +} + +void NetworkDialog::disconnectedHandler() +{ + QLocalSocket *socket = static_cast(sender()); + if (socket) { + sendPassword(socket, "{}"); + m_clients.removeAll(socket); + socket->deleteLater(); + } +} + +void NetworkDialog::changePassword(const QString &key, const QString &password, bool input) +{ + QJsonObject json; + json.insert("key", key); + json.insert("password", password); + json.insert("input", input); + + QJsonDocument doc; + doc.setObject(json); + QByteArray data = doc.toJson(QJsonDocument::Compact); + + for (auto it = m_clients.begin(); it != m_clients.end(); it++) { + (*it)->write("\npassword:" + data + "\n"); + } + Q_EMIT inputPassword(key, password, input); +} + +void NetworkDialog::readyReadHandler() +{ + QLocalSocket *socket = static_cast(sender()); + if (socket) { + QByteArray allData = socket->readAll(); + allData = m_lastData + allData; + qDebug() << "Receive data from client: " << allData; + QList dataArray = allData.split('\n'); + m_lastData = dataArray.last(); + for (const QByteArray &data : dataArray) { + int keyIndex = data.indexOf(':'); + if (keyIndex != -1) { + QString key = data.left(keyIndex); + QByteArray value = data.mid(keyIndex + 1); + if (s_FunMap.contains(key)) { + (this->*s_FunMap.value(key))(socket, value); + } + } + } + } +} + +void NetworkDialog::connectNetwork(QLocalSocket *socket, const QByteArray &data) +{ + QJsonDocument doc = QJsonDocument::fromJson(data); + if (doc.isObject()) { + QJsonObject obj = doc.object(); + setConnectWireless(obj.value("dev").toString(), obj.value("ssid").toString()); + } + socket->write("\nreceive:" + data + "\n"); +} + +void NetworkDialog::sendPassword(QLocalSocket *socket, const QByteArray &data) +{ + Q_UNUSED(socket); + QByteArray sendData = "\npassword:" + data + "\n"; + for (auto it = m_clients.begin(); it != m_clients.end(); it++) { + (*it)->write(sendData); + } +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.h new file mode 100644 index 000000000..f28d10675 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog.h @@ -0,0 +1,61 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKDIALOG_H +#define NETWORKDIALOG_H + +#include "utils.h" + +class QWidget; +class QLocalServer; +class QLocalSocket; +class NetworkPanel; + +NETWORKPLUGIN_BEGIN_NAMESPACE + +class NetworkDialog : public QObject +{ + Q_OBJECT + +public: + explicit NetworkDialog(QObject *parent = Q_NULLPTR); + ~NetworkDialog() override; + +Q_SIGNALS: + void requestShow(); + void inputPassword(const QString &key, const QString &password, bool input); + +public: + QWidget *panel(); + void setConnectWireless(const QString &dev, const QString &ssid, bool wait = true); + void setServerName(const QString &name); + + bool closeOnClear() const; + void setCloseOnClear(bool closeOnClear); + void clear(); + +private Q_SLOTS: + void newConnectionHandler(); + void readyReadHandler(); + void disconnectedHandler(); + void changePassword(const QString &key, const QString &password, bool input); + +public: + void connectNetwork(QLocalSocket *socket, const QByteArray &data); + void sendPassword(QLocalSocket *socket, const QByteArray &data); + +private: + QString m_connectDev; + QString m_connectSsid; + QByteArray m_lastData; + + QLocalServer *m_server; + QList m_clients; + QString m_serverName; + + NetworkPanel *m_panel; +}; + +NETWORKPLUGIN_END_NAMESPACE +#endif // NETWORKDIALOG_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.cpp new file mode 100644 index 000000000..d21b72b43 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.cpp @@ -0,0 +1,701 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "netitem.h" +#include "wirelessconnect.h" +#include "../thememanager.h" +#include "../networkpanel.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define SWITCH_WIDTH 50 +#define SWITCH_HEIGHT 24 + +DWIDGET_USE_NAMESPACE + +#define MAXTEXTWIDTH 180 +/** + * 单个列表项的基类 + */ +NetItem::NetItem(QWidget *parent) + : QObject(parent) + , m_standardItem(new DStandardItem) + , m_parentWidget(parent) +{ + m_standardItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + m_standardItem->setData(NetConnectionType::UnConnected, ConnectionStatusRole); + m_standardItem->setBackground(Qt::transparent); + m_standardItem->setTextColorRole(DPalette::BrightText); +} + +NetItem::~NetItem() +{ +} + +DStandardItem *NetItem::standardItem() +{ + return m_standardItem; +} + +/** + * @brief baseControllItem::baseControllItem + * 总线控制器 + */ +DeviceControllItem::DeviceControllItem(const DeviceType &deviceType, QWidget *parent) + : NetItem(parent) + , m_deviceType(deviceType) +{ + initItemText(); +} + +DeviceControllItem::~DeviceControllItem() +{ +} + +void DeviceControllItem::setDevices(const QList &devices) +{ + m_devices.clear(); + for (NetworkDeviceBase *device : devices) { + if (m_deviceType == device->deviceType()) { + connect(device, &NetworkDeviceBase::destroyed, this, [ this, device ] { + m_devices.removeOne(device); + standardItem()->setData(QVariant::fromValue>(m_devices), DeviceDataRole); + }); + m_devices << device; + } + } + + updateView(); +} + +DeviceType DeviceControllItem::deviceType() +{ + return m_deviceType; +} + +void DeviceControllItem::updateView() +{ + // 更新状态显示 + standardItem()->setData(QVariant::fromValue>(m_devices), DeviceDataRole); +} + +NetItemType DeviceControllItem::itemType() +{ + return DeviceControllViewItem; +} + +void DeviceControllItem::initItemText() +{ + // 创建左侧的切换文本 + standardItem()->setSizeHint(QSize(-1, 46)); + standardItem()->setFlags(Qt::ItemIsEnabled); + standardItem()->setData(NetItemType::DeviceControllViewItem, NetItemRole::TypeRole); + standardItem()->setData(QVariant::fromValue(m_deviceType), NetItemRole::DeviceTypeRole); + standardItem()->setFontSize(DFontSizeManager::T4); + + if (m_deviceType == DeviceType::Wireless) + standardItem()->setText(tr("Wireless Network")); + else + standardItem()->setText(tr("Wired Network")); +} + +WiredControllItem::WiredControllItem(QWidget *parent, WiredDevice *device) + : NetItem(parent) + , m_device(device) +{ + standardItem()->setSizeHint(QSize(-1, 46)); + standardItem()->setText(device->deviceName()); + standardItem()->setFlags(Qt::ItemIsEnabled); + standardItem()->setData(NetItemType::WiredControllViewItem, NetItemRole::TypeRole); + standardItem()->setData(QVariant::fromValue(DeviceType::Wired), NetItemRole::DeviceTypeRole); + standardItem()->setData(QVariant::fromValue(m_device), NetItemRole::DeviceDataRole); + standardItem()->setFontSize(DFontSizeManager::T5); + connect(m_device, &WiredDevice::destroyed, this, [ this ] { + m_device = nullptr; + standardItem()->setData(0, NetItemRole::DeviceDataRole); + }); +} + +WiredControllItem::~WiredControllItem() +{ +} + +WiredDevice *WiredControllItem::device() +{ + return m_device; +} + +void WiredControllItem::updateView() +{ + standardItem()->setText(m_device->deviceName()); +} + +NetItemType WiredControllItem::itemType() +{ + return WiredControllViewItem; +} + +WirelessControllItem::WirelessControllItem(QWidget *parent, WirelessDevice *device) + : NetItem(parent) + , m_device(device) +{ + standardItem()->setSizeHint(QSize(-1, 46)); + standardItem()->setText(device->deviceName()); + standardItem()->setFlags(Qt::ItemIsEnabled); + standardItem()->setData(NetItemType::WirelessControllViewItem, NetItemRole::TypeRole); + standardItem()->setData(QVariant::fromValue(m_device), NetItemRole::DeviceDataRole); + standardItem()->setData(QVariant::fromValue(DeviceType::Wireless), NetItemRole::DeviceTypeRole); + standardItem()->setFontSize(DFontSizeManager::T5); + connect(m_device, &WirelessDevice::destroyed, this, [ this ] { + m_device = nullptr; + standardItem()->setData(0, NetItemRole::DeviceDataRole); + }); +} + +WirelessControllItem::~WirelessControllItem() +{ +} + +WirelessDevice *WirelessControllItem::device() +{ + return m_device; +} + +void WirelessControllItem::updateView() +{ + standardItem()->setText(m_device->deviceName()); +} + +NetItemType WirelessControllItem::itemType() +{ + return WirelessControllViewItem; +} + +WiredItem::WiredItem(QWidget *parent, WiredDevice *device, WiredConnection *connection) + : NetItem(parent) + , m_connection(connection) + , m_device(device) +{ + initUi(); +} + +WiredItem::~WiredItem() +{ +} + +WiredConnection *WiredItem::connection() +{ + return m_connection; +} + +QString WiredItem::symbolicIcon(const bool &connected) const +{ + QString icon = connected ? QString("network-wired-symbolic") : QString("network-none-symbolic"); + return ThemeManager::ref().getIcon(icon); +} + +void WiredItem::updateView() +{ + // 更新显示的文本 + QFontMetrics ftm(standardItem()->font()); + QString displayText = ftm.elidedText(m_connection->connection()->id(), Qt::TextElideMode::ElideRight, MAXTEXTWIDTH); + standardItem()->setText(displayText); + // 更新当前的连接状态 + QString connectionIconFile; + switch (m_connection->status()) { + case ConnectionStatus::Activating: + standardItem()->setData(NetConnectionType::Connecting, ConnectionStatusRole); + connectionIconFile = symbolicIcon(false); + break; + case ConnectionStatus::Activated: + standardItem()->setData(NetConnectionType::Connected, ConnectionStatusRole); + connectionIconFile = symbolicIcon(true); + break; + default: + standardItem()->setData(NetConnectionType::UnConnected, ConnectionStatusRole); + connectionIconFile = symbolicIcon(false); + break; + } + + // 设置左侧的连接图标 + m_connectionIconAction->setIcon(QIcon(connectionIconFile)); +} + +NetItemType WiredItem::itemType() +{ + return WiredViewItem; +} + +void WiredItem::initUi() +{ + standardItem()->setSizeHint(QSize(-1, 36)); + + // 占位的 + DViewItemAction *emptyAction = new DViewItemAction(Qt::AlignLeft | Qt::AlignVCenter, + QSize(20, 20), QSize(20, 20), false); + + m_connectionIconAction = new DViewItemAction(Qt::AlignLeft | Qt::AlignVCenter, + QSize(20, 20), QSize(8, 20), false); + + standardItem()->setActionList(Qt::LeftEdge, { emptyAction, m_connectionIconAction }); + updateView(); + + standardItem()->setFlags(Qt::ItemIsEnabled); + standardItem()->setFontSize(DFontSizeManager::T6); + standardItem()->setData(NetItemType::WiredViewItem, NetItemRole::TypeRole); + standardItem()->setData(QVariant::fromValue(m_device), NetItemRole::DeviceDataRole); + standardItem()->setData(QVariant::fromValue(static_cast(m_connection)), NetItemRole::DataRole); + standardItem()->setData(QVariant::fromValue(DeviceType::Wired), NetItemRole::DeviceTypeRole); + connect(m_device, &WiredDevice::destroyed, this, [ this ] { + m_device = nullptr; + standardItem()->setData(0, NetItemRole::DeviceDataRole); + }); +} + +void WiredItem::connectNetwork() +{ + if (m_connection && !m_connection->connected()) { + m_device->connectNetwork(m_connection); + } +} + +WirelessItem::WirelessItem(QWidget *parent, WirelessDevice *device, AccessPoints *ap, NetworkPanel *panel) + : NetItem(parent) + , m_accessPoint(ap) + , m_device(device) + , m_securityAction(nullptr) + , m_wifiLabel(nullptr) + , m_connectionAction(nullptr) + , m_loadingStat(nullptr) + , m_connectionWidget(nullptr) + , m_stackWidget(nullptr) + , m_expandItem(nullptr) + , m_topItem(nullptr) + , m_passwdEdit(nullptr) + , m_ssidEdit(nullptr) + , m_wirelessConnect(new WirelessConnect(this, device, ap)) + , m_connectButton(nullptr) + , m_panel(panel) +{ + initUi(parent); + initConnection(); + if (m_accessPoint) { + m_wirelessConnect->setSsid(ap->ssid()); + QFontMetrics ftm(standardItem()->font()); + QString displayText = ftm.elidedText(m_accessPoint->ssid(), Qt::TextElideMode::ElideRight, MAXTEXTWIDTH); + standardItem()->setText(displayText); + } else { + m_wifiLabel->setVisible(false); + m_securityAction->setVisible(false); + standardItem()->setText(tr("Connect to hidden network")); + } +} + +WirelessItem::~WirelessItem() +{ + m_stackWidget->setParent(nullptr); + m_stackWidget->deleteLater(); +} + +const AccessPoints *WirelessItem::accessPoint() +{ + return m_accessPoint; +} + +const WirelessDevice *WirelessItem::wirelessDevice() +{ + return m_device; +} + +void WirelessItem::updateView() +{ + updateSrcirityIcon(); + updateWifiIcon(); + updateConnectionStatus(); +} + +NetItemType WirelessItem::itemType() +{ + return WirelessViewItem; +} + +QString WirelessItem::getStrengthStateString(int strength) +{ + if (5 >= strength) + return "0"; + + if (30 >= strength) + return "20"; + + if (55 >= strength) + return "40"; + + if (65 >= strength) + return "60"; + + return "80"; +} + +void WirelessItem::initUi(QWidget *parent) +{ + m_expandItem = new DViewItemAction(Qt::AlignBottom, QSize(PANELWIDTH, 20), QSize(PANELWIDTH, 20), false); + m_stackWidget = new DStackedWidget(parent); + // 初始化展开输入控件 + initExpandUi(); + m_expandItem->setWidget(m_stackWidget); + standardItem()->setActionList(Qt::BottomEdge, { m_expandItem }); + m_expandItem->setVisible(false); + // 左侧的加密图标 + m_securityAction = new DViewItemAction(Qt::AlignLeft , QSize(20, 35), QSize(20, 35), false); + updateSrcirityIcon(); + // 绘制WiFi图标 + m_wifiLabel = new DViewItemAction(Qt::AlignLeft , QSize(20, 35), QSize(8, 35), false); + updateWifiIcon(); + + standardItem()->setSizeHint(QSize(-1, 36)); + standardItem()->setActionList(Qt::LeftEdge, { m_securityAction, m_wifiLabel }); + + m_topItem = new DViewItemAction(Qt::AlignTop, QSize(-1, 1), QSize(-1, 1), false); + standardItem()->setActionList(Qt::TopEdge, { m_topItem }); + m_topItem->setVisible(false); + // 绘制右侧的连接图标 + standardItem()->setFlags(Qt::ItemIsEnabled); + updateConnectionStatus(); + if (m_accessPoint) { + standardItem()->setData(NetItemType::WirelessViewItem, NetItemRole::TypeRole); + } else { + standardItem()->setData(NetItemType::WirelessHiddenViewItem, NetItemRole::TypeRole); + } + standardItem()->setData(QVariant::fromValue(m_device), NetItemRole::DeviceDataRole); + standardItem()->setData(QVariant::fromValue(DeviceType::Wireless), NetItemRole::DeviceTypeRole); + standardItem()->setData(QVariant::fromValue(static_cast(m_accessPoint)), NetItemRole::DataRole); + standardItem()->setFontSize(DFontSizeManager::T6); + connect(m_device, &WirelessDevice::destroyed, this, [ this ] { + m_device = nullptr; + standardItem()->setData(0, NetItemRole::DeviceDataRole); + }); +} + +void WirelessItem::initConnection() +{ + connect(m_wirelessConnect, &WirelessConnect::passwordError, this, &WirelessItem::onInputPassword, Qt::QueuedConnection); +} + +void WirelessItem::updateSrcirityIcon() +{ + if (m_accessPoint && m_accessPoint->secured()) { + QString srcirityIcon = ThemeManager::ref().getIcon("security"); + // 更新加密图标 + m_securityAction->setIcon(QIcon(srcirityIcon)); + } else { + m_securityAction->setIcon(QIcon()); + } +} + +void WirelessItem::updateWifiIcon() +{ + if (!m_accessPoint) + return; + + bool isWlan6 = (m_accessPoint->type() == AccessPoints::WlanType::wlan6); + QString strength = getStrengthStateString(m_accessPoint->strength()); + QString iconRes = QString(isWlan6 ? QString("wireless6-%1-symbolic") + : QString("wireless-%1-symbolic")).arg(strength); + QString icon = ThemeManager::ref().getIcon(iconRes); + m_wifiLabel->setIcon(QIcon(icon)); +} + +void WirelessItem::updateConnectionStatus() +{ + if (!m_accessPoint) + return; + + switch (m_accessPoint->status()) { + case ConnectionStatus::Activating: + standardItem()->setData(NetConnectionType::Connecting, ConnectionStatusRole); + break; + case ConnectionStatus::Activated: + standardItem()->setData(NetConnectionType::Connected, ConnectionStatusRole); + expandWidget(ExpandWidget::Hide); + break; + default: + standardItem()->setData(NetConnectionType::UnConnected, ConnectionStatusRole); + break; + } +} + +void WirelessItem::onConnection() +{ + if (m_device->activeAccessPoints() == m_accessPoint) + m_device->disconnectNetwork(); +} + +void WirelessItem::expandWidget(ExpandWidget type, bool autoDisconnect) +{ + switch (type) { + case ExpandWidget::Hide: + if(m_expandItem->isVisible()) { + m_expandItem->setVisible(false); + m_topItem->setVisible(false); + standardItem()->setSizeHint(QSize(-1, 36)); + if (m_accessPoint) { + m_panel->changePassword(m_accessPoint->ssid(), QString(), false); + if(autoDisconnect && m_accessPoint->status() == ConnectionStatus::Activating) { + m_device->disconnectNetwork(); + } + } + m_ssidEdit->lineEdit()->clear(); + m_passwdEdit->clear(); + } + break; + case ExpandWidget::ShowSSID: + m_expandItem->setVisible(true); + m_topItem->setVisible(true); + standardItem()->setSizeHint(QSize(-1, 130)); + m_stackWidget->setCurrentIndex(type); + m_ssidEdit->lineEdit()->setFocus(); + QTimer::singleShot(50, m_ssidEdit->lineEdit(), SLOT(setFocus())); + break; + case ExpandWidget::ShowPassword: + // 如果当前需要输入密码的ap不是处理正在连接状态,则隐藏起来,目的是为了处理在控制中心快速切换ap导致连接状态错误的问题 + const QString ssidWaitingForPassword = m_panel->ssidWaitingForPassword(); + if (m_accessPoint && ssidWaitingForPassword == m_accessPoint->ssid()) { + if (m_accessPoint->status() != ConnectionStatus::Activating) { + expandWidget(ExpandWidget::Hide); + break; + } + // 有时候显示密码输入框时, ap的status还没有来得变更,有可能会在几毫秒(不确定)后变更,需要绑定信号进行处理 + connect(m_accessPoint, &AccessPoints::connectionStatusChanged, this, &WirelessItem::onApConnectionStatusChanged, Qt::UniqueConnection); + } + m_expandItem->setVisible(true); + m_topItem->setVisible(true); + standardItem()->setSizeHint(QSize(-1, 130)); + m_stackWidget->setCurrentIndex(type); + m_passwdEdit->lineEdit()->setFocus(); + checkInputValid(); + m_passwdEdit->setAlert(!m_passwdEdit->text().isEmpty()); + QTimer::singleShot(50, m_passwdEdit->lineEdit(), SLOT(setFocus())); + break; + } + emit sizeChanged(); +} + +void WirelessItem::onApConnectionStatusChanged(ConnectionStatus status) +{ + if (status != ConnectionStatus::Activating && expandVisible()) { + expandWidget(ExpandWidget::Hide); + } +} + +void WirelessItem::createPasswordEdit() +{ + // 密码输入窗 + DWidget *passwdWidget = new DWidget(m_stackWidget); + m_passwdEdit = new DPasswordEdit(passwdWidget); + m_passwdEdit->lineEdit()->setPlaceholderText(tr("Password")); + m_passwdEdit->lineEdit()->setMaxLength(256); + m_passwdEdit->setContextMenuPolicy(Qt::NoContextMenu); + m_passwdEdit->setFixedHeight(36); + m_passwdEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + DPushButton *cancelButtion = new DPushButton(tr("Cancel", "button"), passwdWidget); // 取消 + m_connectButton = new DSuggestButton(tr("Connect", "button"), passwdWidget); // 连接 + cancelButtion->setFixedHeight(36); + cancelButtion->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_connectButton->setFixedHeight(36); + m_connectButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + QHBoxLayout *line2 = new QHBoxLayout; + line2->setContentsMargins(0, 0, 0, 0); + + QVBoxLayout *layout = new QVBoxLayout(passwdWidget); + layout->setContentsMargins(0, 0, 10, 10); + line2->addWidget(cancelButtion); + line2->addSpacing(3); + line2->addWidget(m_connectButton); + + layout->addWidget(m_passwdEdit); + layout->addSpacing(10); + layout->addLayout(line2); + layout->addSpacing(7); + + passwdWidget->setLayout(layout); + m_stackWidget->addWidget(passwdWidget); + + connect(cancelButtion, &DPushButton::clicked, this, &WirelessItem::onCancel); + connect(m_connectButton, &DPushButton::clicked, this, &WirelessItem::onConnectNetwork); + connect(m_passwdEdit->lineEdit(), &QLineEdit::returnPressed, this, &WirelessItem::onConnectNetwork); + connect(m_passwdEdit->lineEdit(), &QLineEdit::textChanged, this, &WirelessItem::checkInputValid); + ThemeManager::ref().updateInputStyle(m_passwdEdit); +} + +void WirelessItem::createSsidEdit() +{ + // ssid输入窗 + DWidget *ssidWidget = new DWidget(m_stackWidget); + m_ssidEdit = new DLineEdit(ssidWidget); + m_ssidEdit->setPlaceholderText(tr("Name (SSID)")); + m_ssidEdit->lineEdit()->setMaxLength(256); + m_ssidEdit->setContextMenuPolicy(Qt::NoContextMenu); + m_ssidEdit->setFixedHeight(36); + m_ssidEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + DPushButton *cancelButtion = new DPushButton(tr("Cancel", "button"), ssidWidget); // 取消 + DPushButton *connectButton = new DSuggestButton(tr("Connect", "button"), ssidWidget); // 连接 + cancelButtion->setFixedHeight(36); + cancelButtion->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + connectButton->setFixedHeight(36); + connectButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + QHBoxLayout *line2 = new QHBoxLayout; + line2->setContentsMargins(0, 0, 0, 0); + + QVBoxLayout *layout = new QVBoxLayout(ssidWidget); + layout->setContentsMargins(0, 0, 10, 10); + line2->addWidget(cancelButtion); + line2->addSpacing(3); + line2->addWidget(connectButton); + + layout->addWidget(m_ssidEdit); + layout->addSpacing(10); + layout->addLayout(line2); + layout->addSpacing(7); + + ssidWidget->setLayout(layout); + m_stackWidget->addWidget(ssidWidget); + + connect(cancelButtion, &DPushButton::clicked, this, &WirelessItem::onCancel); + connect(connectButton, &DPushButton::clicked, this, &WirelessItem::onConnectHidden); + connect(m_ssidEdit->lineEdit(), &QLineEdit::returnPressed, this, &WirelessItem::onConnectHidden); + ThemeManager::ref().updateInputStyle(m_ssidEdit); +} + +void WirelessItem::initExpandUi() +{ + createPasswordEdit(); + createSsidEdit(); + m_stackWidget->setContentsMargins(0, 0, 0, 0); + m_stackWidget->setFixedSize(PANELWIDTH - 10, 92); +} + +void WirelessItem::connectNetwork() +{ + if (NetConnectionType::UnConnected == standardItem()->data(ConnectionStatusRole)) { + // 密码框未显示前尝试直接连接 + if (!m_expandItem->isVisible()) { + if (m_accessPoint) { + m_wirelessConnect->connectNetwork(); + } else { + expandWidget(ExpandWidget::ShowSSID); + } + } + } +} + +void WirelessItem::onConnectNetwork() +{ + QString password = m_passwdEdit->text(); + // 输入无效在checkInputValid里已判断 + if (m_wirelessConnect->passwordIsValid(password)) { + if (m_accessPoint) { + if (m_panel->changePassword(m_accessPoint->ssid(), password, true)) { + expandWidget(ExpandWidget::Hide, false); + return; + } + } + m_wirelessConnect->connectNetworkPassword(m_passwdEdit->text()); + expandWidget(ExpandWidget::Hide, false); + } +} + +void WirelessItem::onInputPassword(const QString oldPassword) +{ + m_passwdEdit->setText(oldPassword); + expandWidget(ExpandWidget::ShowPassword); +} + +void WirelessItem::expandPasswordInput() +{ + m_wirelessConnect->getoldPassword(); +} + +void WirelessItem::onAirplaneModeChanged(bool airplaneModeEnabled) +{ + m_stackWidget->setDisabled(airplaneModeEnabled); +} + +void WirelessItem::onConnectHidden() +{ + QString ssid = m_ssidEdit->text(); + if (!ssid.isEmpty()) { + expandWidget(ExpandWidget::Hide, false); + m_wirelessConnect->setSsid(ssid); + m_wirelessConnect->connectNetwork(); + } +} + +void WirelessItem::checkInputValid() +{ + bool isValid = m_wirelessConnect->passwordIsValid(m_passwdEdit->text()); + + m_passwdEdit->setAlert(false); + m_connectButton->setEnabled(isValid); +} + +bool WirelessItem::expandVisible() +{ + return m_expandItem->isVisible(); +} + +const QDateTime WirelessItem::timeStamp(WirelessConnection *connection) const +{ + NetworkManager::Connection::Ptr connect(new NetworkManager::Connection(connection->connection()->path())); + return connect->settings()->timestamp(); +} + +void WirelessItem::onCancel() +{ + if (m_accessPoint && (m_accessPoint->status() == ConnectionStatus::Activating || m_accessPoint->ssid() == m_device->activeAp())) { + m_device->disconnectNetwork(); + QList connections = m_device->items(); + // 断开连接后,找到最后一次连接的热点 + WirelessConnection *lastConnection = nullptr; + for (WirelessConnection *conn : connections) { + if (conn->accessPoints() == m_accessPoint) + continue; + + QDateTime ts = timeStamp(conn); + if (!ts.isValid()) + continue; + + if (!lastConnection || timeStamp(lastConnection) < ts) + lastConnection = conn; + } + + if (lastConnection) + m_device->connectNetwork(lastConnection->accessPoints()); + + } + + this->expandWidget(ExpandWidget::Hide); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.h new file mode 100644 index 000000000..fb8176879 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/netitem.h @@ -0,0 +1,249 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETITEM_H +#define NETITEM_H + +#include + +#include +#include +#include +#include + +#include + +class NetworkDevice; +class NetItem; +class WirelessConnect; +class QLabel; +class QPushButton; +class NetworkPanel; + +namespace dde { + namespace network { + class NetworkDeviceBase; + class WiredDevice; + class WirelessDevice; + class AccessPoints; + class WiredConnection; + class WirelessConnection; + enum class DeviceType; + } // namespace network +} // namespace dde + +using namespace dde::network; +namespace Dtk { + namespace Widget { + class DListView; + class DViewItemAction; + class DLoadingIndicator; + class DSpinner; + class DPasswordEdit; + class DLineEdit; + class DStandardItem; + } // namespace Widget +} // namespace Dtk + +DWIDGET_USE_NAMESPACE + +enum NetItemRole { + TypeRole = Qt::UserRole + 100, + DeviceDataRole, + DataRole, + ConnectionStatusRole, + MouseInBoundingRole, + DeviceTypeRole, + sortRole +}; + +#define PANELWIDTH 300 + +enum NetItemType { + DeviceControllViewItem = 0, // 总控开关 + WirelessControllViewItem, // 无线网卡开关 + WirelessViewItem, // 无线列表 + WirelessHiddenViewItem, // 无线隐藏列表 + WiredControllViewItem, // 有线网卡开关 + WiredViewItem // 有线列表 +}; + +enum NetConnectionType { + UnConnected = 0, // 未连接 + Connecting, // 正在连接 + Connected // 已连接 +}; + +class NetItem : public QObject +{ + Q_OBJECT + +public: + NetItem(QWidget *parent); + virtual ~NetItem(); + + virtual DStandardItem *standardItem(); + virtual void updateView() {} + virtual NetItemType itemType() = 0; + +private: + DStandardItem *m_standardItem; + QWidget *m_parentWidget; +}; + +class DeviceControllItem : public NetItem +{ + Q_OBJECT + +public: + DeviceControllItem(const DeviceType &deviceType, QWidget *parent); + ~DeviceControllItem() Q_DECL_OVERRIDE; + + void setDevices(const QList &devices); + DeviceType deviceType(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + +private: + void initItemText(); + +private: + QList m_devices; + DeviceType m_deviceType; +}; + +class WiredControllItem : public NetItem +{ + Q_OBJECT + +public: + WiredControllItem(QWidget *parent, WiredDevice *device); + ~WiredControllItem() Q_DECL_OVERRIDE; + + WiredDevice *device(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + +private: + WiredDevice *m_device; +}; + +class WirelessControllItem : public NetItem +{ + Q_OBJECT + +public: + WirelessControllItem(QWidget *parent, WirelessDevice *device); + ~WirelessControllItem() Q_DECL_OVERRIDE; + + WirelessDevice *device(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + +private: + WirelessDevice *m_device; +}; + +class WiredItem : public NetItem +{ + Q_OBJECT + +public: + WiredItem(QWidget *parent, WiredDevice *device, WiredConnection *connection); + ~WiredItem() Q_DECL_OVERRIDE; + + WiredConnection *connection(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + void connectNetwork(); + +private: + void initUi(); + QString symbolicIcon(const bool &connected) const; + void initConnection(); + +private: + WiredConnection *m_connection; + WiredDevice *m_device; + DViewItemAction *m_connectionIconAction; +}; + +class WirelessItem : public NetItem +{ + Q_OBJECT + +Q_SIGNALS: + void sizeChanged(); + +public: + enum ExpandWidget { + Hide = -1, + ShowPassword, + ShowSSID, + }; + +public: + WirelessItem(QWidget *parent, WirelessDevice *device, AccessPoints *ap, NetworkPanel *panel); + ~WirelessItem() Q_DECL_OVERRIDE; + + const AccessPoints *accessPoint(); + const WirelessDevice *wirelessDevice(); + void updateView() Q_DECL_OVERRIDE; + NetItemType itemType() Q_DECL_OVERRIDE; + static QString getStrengthStateString(int strength); + void expandWidget(ExpandWidget type, bool autoDisconnect = true); + void connectNetwork(); + void expandPasswordInput(); + bool expandVisible(); + +public Q_SLOTS: + void onAirplaneModeChanged(bool airplaneModeEnabled); + void onCancel(); + +private: + void initUi(QWidget *parent); + void initConnection(); + void updateSrcirityIcon(); + void updateWifiIcon(); + void updateConnectionStatus(); + void createPasswordEdit(); + void createSsidEdit(); + void initExpandUi(); + const QDateTime timeStamp(WirelessConnection *connection) const; + +private Q_SLOTS: + void onConnection(); + void onConnectNetwork(); + void onInputPassword(const QString oldPassword); + void onConnectHidden(); + void checkInputValid(); + void onApConnectionStatusChanged(ConnectionStatus); + +private: + AccessPoints *m_accessPoint; + WirelessDevice *m_device; + DViewItemAction *m_securityAction; + DViewItemAction *m_wifiLabel; + DViewItemAction *m_connectionAction; + DSpinner *m_loadingStat; + + QWidget *m_connectionWidget; + + DStackedWidget *m_stackWidget; + DViewItemAction *m_expandItem; + DViewItemAction *m_topItem; // 占空间 + + DPasswordEdit *m_passwdEdit; + DLineEdit *m_ssidEdit; + + WirelessConnect *m_wirelessConnect; + DPushButton *m_connectButton; + NetworkPanel *m_panel; +}; + +Q_DECLARE_METATYPE(NetItemType) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(DeviceType) + +#endif // NETWORKAPPLETMODEL_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.cpp new file mode 100644 index 000000000..676c614b0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.cpp @@ -0,0 +1,276 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "wirelessconnect.h" + +#include "wirelessdevice.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace dde::network; +using namespace NetworkManager; + +WirelessConnect::WirelessConnect(QObject *parent, dde::network::WirelessDevice *device, dde::network::AccessPoints *ap) + : QObject(parent) + , m_device(device) + , m_accessPoint(ap) + , m_needUpdate(false) +{ + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); +} + +WirelessConnect::~WirelessConnect() +{ +} + +void WirelessConnect::setSsid(const QString &ssid) +{ + m_ssid = ssid; + m_connectionSettings.clear(); +} + +bool WirelessConnect::passwordIsValid(const QString &password) +{ + WirelessSecuritySetting::KeyMgmt keyMgmt = WirelessSecuritySetting::WpaPsk; + if (m_connectionSettings) { + WirelessSecuritySetting::Ptr wsSetting = m_connectionSettings->setting(Setting::SettingType::WirelessSecurity).staticCast(); + keyMgmt = wsSetting->keyMgmt(); + } else { + keyMgmt = getKeyMgmtByAp(m_accessPoint); + } + if (keyMgmt == WirelessSecuritySetting::KeyMgmt::Wep) { + return wepKeyIsValid(password, WirelessSecuritySetting::WepKeyType::Passphrase); + } + return wpaPskIsValid(password); +} + +WirelessSecuritySetting::KeyMgmt WirelessConnect::getKeyMgmtByAp(dde::network::AccessPoints *ap) +{ + if (nullptr == ap) { + return WirelessSecuritySetting::WpaPsk; + } + AccessPoint::Ptr nmAp(new AccessPoint(ap->path())); + AccessPoint::Capabilities capabilities = nmAp->capabilities(); + AccessPoint::WpaFlags wpaFlags = nmAp->wpaFlags(); + AccessPoint::WpaFlags rsnFlags = nmAp->rsnFlags(); + + WirelessSecuritySetting::KeyMgmt keyMgmt = WirelessSecuritySetting::KeyMgmt::WpaNone; + + if (capabilities.testFlag(AccessPoint::Capability::Privacy) && !wpaFlags.testFlag(AccessPoint::WpaFlag::KeyMgmtPsk) && !wpaFlags.testFlag(AccessPoint::WpaFlag::KeyMgmt8021x)) { + keyMgmt = WirelessSecuritySetting::KeyMgmt::Wep; + } + + if (wpaFlags.testFlag(AccessPoint::WpaFlag::KeyMgmtPsk) || rsnFlags.testFlag(AccessPoint::WpaFlag::KeyMgmtPsk)) { + keyMgmt = WirelessSecuritySetting::KeyMgmt::WpaPsk; + } + + // 判断是否是wpa3加密的,因为wpa3加密方式,实际上是wpa2的扩展,所以其中会包含KeyMgmtPsk枚举值 + if (wpaFlags.testFlag(NetworkManager::AccessPoint::WpaFlag::KeyMgmtSAE) || rsnFlags.testFlag(NetworkManager::AccessPoint::WpaFlag::KeyMgmtSAE)) { + keyMgmt = NetworkManager::WirelessSecuritySetting::KeyMgmt::SAE; + } + + if (wpaFlags.testFlag(AccessPoint::WpaFlag::KeyMgmt8021x) || rsnFlags.testFlag(AccessPoint::WpaFlag::KeyMgmt8021x)) { + keyMgmt = WirelessSecuritySetting::KeyMgmt::WpaEap; + } + return keyMgmt; +} + +void WirelessConnect::initConnection() +{ + // 隐藏网络直接创建settings + if (m_accessPoint) { + NetworkManager::Connection::Ptr conn; + for (ActiveConnection::Ptr con : NetworkManager::activeConnections()) { + if (con->type() != ConnectionSettings::ConnectionType::Wireless || con->id() != m_ssid) + continue; + + NetworkManager::ConnectionSettings::Ptr connSettings = con->connection()->settings(); + NetworkManager::WirelessSetting::Ptr wSetting = connSettings->setting(NetworkManager::Setting::SettingType::Wireless).staticCast(); + if (wSetting.isNull()) + continue; + + QString settingMacAddress = wSetting->macAddress().toHex().toUpper(); + QString deviceMacAddress = m_device->realHwAdr().remove(":"); + if (!settingMacAddress.isEmpty() && settingMacAddress != deviceMacAddress) + continue; + + conn = findConnectionByUuid(con->uuid()); + break; + } + + if (conn.isNull()) { + for (auto item : m_device->items()) { + if (item->connection()->ssid() != m_ssid) + continue; + + QString uuid = item->connection()->uuid(); + if (!uuid.isEmpty()) { + conn = findConnectionByUuid(uuid); + if (!conn.isNull() && conn->isValid()) { + break; + } + } + } + } + if (!conn.isNull() && conn->isValid()) { + m_connectionSettings = conn->settings(); + } + } + // 没连接过的需要新建连接 + if (m_connectionSettings.isNull()) { + m_connectionSettings = QSharedPointer(new ConnectionSettings(ConnectionSettings::ConnectionType::Wireless)); + // 创建uuid + QString uuid = m_connectionSettings->createNewUuid(); + while (findConnectionByUuid(uuid)) { + qint64 second = QDateTime::currentDateTime().toSecsSinceEpoch(); + uuid.replace(24, QString::number(second).length(), QString::number(second)); + } + m_connectionSettings->setUuid(uuid); + m_connectionSettings->setId(m_ssid); + if (!m_accessPoint) { + m_connectionSettings->setting(Setting::SettingType::Wireless).staticCast()->setHidden(true); + } + qInfo() << "create connect:" << m_ssid << uuid << m_accessPoint; + if (m_accessPoint) { + m_connectionSettings->setting(Setting::Security8021x).staticCast()->setPasswordFlags(Setting::AgentOwned); + WirelessSecuritySetting::Ptr wsSetting = m_connectionSettings->setting(Setting::WirelessSecurity).dynamicCast(); + WirelessSecuritySetting::KeyMgmt keyMgmt = getKeyMgmtByAp(m_accessPoint); + if (keyMgmt != WirelessSecuritySetting::KeyMgmt::WpaNone) { + wsSetting->setKeyMgmt(keyMgmt); + if (keyMgmt == WirelessSecuritySetting::KeyMgmt::Wep) { + wsSetting->setWepKeyFlags(Setting::None); + } else if (keyMgmt == WirelessSecuritySetting::KeyMgmt::WpaPsk || keyMgmt == WirelessSecuritySetting::KeyMgmt::SAE) { + wsSetting->setPskFlags(Setting::None); + } + wsSetting->setInitialized(true); + } + } + WirelessSetting::Ptr wirelessSetting = m_connectionSettings->setting(Setting::Wireless).dynamicCast(); + wirelessSetting->setSsid(m_ssid.toUtf8()); + wirelessSetting->setInitialized(true); + m_needUpdate = true; + } +} + +void WirelessConnect::setPassword(const QString &password) +{ + WirelessSecuritySetting::Ptr wsSetting = m_connectionSettings->setting(Setting::SettingType::WirelessSecurity).staticCast(); + bool isHidden = m_connectionSettings->setting(Setting::SettingType::Wireless).staticCast()->hidden(); + WirelessSecuritySetting::KeyMgmt keyMgmt = isHidden ? getKeyMgmtByAp(m_accessPoint) : wsSetting->keyMgmt(); + wsSetting->setKeyMgmt(keyMgmt); + if (keyMgmt == WirelessSecuritySetting::KeyMgmt::Wep) { + wsSetting->setWepKey0(password); + } else if (keyMgmt == WirelessSecuritySetting::KeyMgmt::WpaPsk || keyMgmt == WirelessSecuritySetting::KeyMgmt::SAE) { + + wsSetting->setPsk(password); + + if (isHidden && keyMgmt == WirelessSecuritySetting::KeyMgmt::WpaPsk) { + wsSetting->setAuthAlg(WirelessSecuritySetting::AuthAlg::Open); + } + } + wsSetting->setInitialized(true); + m_needUpdate = true; +} + +/** + * @brief WirelessConnect::hasPassword + * @return 是否需要密码 + */ +bool WirelessConnect::hasPassword() +{ + if (m_accessPoint && m_accessPoint->secured()) { + // 已有Connection则尝试直接连接 + NetworkManager::Connection::Ptr conn = findConnectionByUuid(m_connectionSettings->uuid()); + return conn.isNull(); + } + + return (!m_accessPoint || m_accessPoint->secured()); +} + +void WirelessConnect::connectNetwork() +{ + initConnection(); + // 隐藏网络先尝试无密码连接 + if (m_accessPoint) { + if ((hasPassword())) { + emit passwordError(QString()); + return; + } + } + activateConnection(); +} + +void WirelessConnect::connectNetworkPassword(const QString password) +{ + initConnection(); + setPassword(password); + activateConnection(); +} + +void WirelessConnect::activateConnection() +{ + m_device->disconnectNetwork(); + NetworkManager::Connection::Ptr conn; + QString id = m_connectionSettings->id(); + ConnectionSettings::ConnectionType type = m_connectionSettings->connectionType(); + for (auto it : NetworkManager::listConnections()) { + if (type != it->settings()->connectionType() || id != it->name()) + continue; + + NetworkManager::WirelessSetting::Ptr wSetting = it->settings()->setting(NetworkManager::Setting::SettingType::Wireless).staticCast(); + if (wSetting.isNull()) + continue; + + const QString setingMacAddress = wSetting->macAddress().toHex().toUpper(); + const QString deviceMacAddress = m_device->realHwAdr().remove(":").toUpper(); + if (!setingMacAddress.isEmpty() && setingMacAddress != deviceMacAddress) + continue; + + m_connectionSettings->setUuid(it->uuid()); + conn = it; + break; + } + + QString accessPointPath; + if (m_accessPoint) { + accessPointPath = m_accessPoint->path(); + } + if (conn.isNull()) { + conn = findConnectionByUuid(m_connectionSettings->uuid()); + } + if (conn.isNull()) { + qInfo() << "addAndActivateConnection" << m_device->path() << accessPointPath; + addAndActivateConnection(m_connectionSettings->toMap(), m_device->path(), accessPointPath); + return; + } + // 隐藏网络或设置过密码的需要update + if (m_needUpdate) { + m_needUpdate = false; + QDBusPendingReply<> reply; + reply = conn->update(m_connectionSettings->toMap()); + reply.waitForFinished(); + if (reply.isError()) { + qInfo() << "error occurred while updating the connection" << reply.error(); + return; + } + } + qInfo() << "activateConnection" << conn->path() << m_device->path() << accessPointPath; + NetworkManager::activateConnection(conn->path(), m_device->path(), accessPointPath); +} + +void WirelessConnect::getoldPassword() +{ + // 旧密码不展示 + emit passwordError(QString()); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.h new file mode 100644 index 000000000..da4c5b865 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/item/wirelessconnect.h @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef WIRELESSCONNECT_H +#define WIRELESSCONNECT_H + +#include +#include +#include + +namespace dde { + namespace network { + class NetworkDeviceBase; + class WiredDevice; + class WirelessDevice; + class AccessPoints; + class WiredConnection; + enum class DeviceType; + } // namespace network +} // namespace dde + +class WirelessConnect : public QObject +{ + Q_OBJECT + +public: + explicit WirelessConnect(QObject *parent, dde::network::WirelessDevice *device, dde::network::AccessPoints *ap); + ~WirelessConnect() Q_DECL_OVERRIDE; + + void setSsid(const QString &ssid); + bool passwordIsValid(const QString &password); + void getoldPassword(); + +protected: + void setPassword(const QString &password); + bool hasPassword(); + void initConnection(); + void activateConnection(); + NetworkManager::WirelessSecuritySetting::KeyMgmt getKeyMgmtByAp(dde::network::AccessPoints *ap); + +public Q_SLOTS: + void connectNetwork(); + void connectNetworkPassword(const QString password); + +Q_SIGNALS: + void passwordError(const QString oldPassword); + +private: + dde::network::WirelessDevice *m_device; + dde::network::AccessPoints *m_accessPoint; + QString m_ssid; + bool m_needUpdate; + + NetworkManager::ConnectionSettings::Ptr m_connectionSettings; +}; + +#endif // WIRELESSCONNECT_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.cpp new file mode 100644 index 000000000..543f25472 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.cpp @@ -0,0 +1,1183 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkpanel.h" +#include "utils.h" +#include "item/netitem.h" +#include "item/devicestatushandler.h" +#include "thememanager.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define SWITCH_WIDTH 50 +#define SWITCH_HEIGHT 24 + +class ScrollArea : public QScrollArea +{ +public: + explicit ScrollArea(NetworkPanel *panel) + : QScrollArea(nullptr) + , m_panel(panel) + { + } + ~ScrollArea() override {} + + void setVisible(bool visible) override; + +private: + NetworkPanel *m_panel; +}; + +void ScrollArea::setVisible(bool visible) +{ + if (!visible && m_panel->closeOnClear()) { + m_panel->clear(); + } + QScrollArea::setVisible(visible); +} + +NetworkPanel::NetworkPanel(QObject *parent) + : QObject(parent) + , m_wirelessScanTimer(new QTimer(this)) + , m_closeOnClear(true) + , m_applet(new ScrollArea(this)) + , m_centerWidget(new QWidget(m_applet)) + , m_netListView(new DListView(m_centerWidget)) + , m_airplaneMode(new NetworkDBusProxy(this)) + , m_updateTimer(new QTimer(this)) +{ + initUi(); + if (NetworkController::instance()->devices().isEmpty()) { + // 当关闭网络后,不会收到activeConnectionChange信号,需要监听deviceAdded信号初始化连接 + connect(NetworkController::instance(), &NetworkController::deviceAdded, this, &NetworkPanel::initConnection); + } else { + initConnection(); + } +} + +NetworkPanel::~NetworkPanel() +{ + NetItem *oldSelectItem = selectItem(); + if (oldSelectItem) { + WirelessItem *item = static_cast(oldSelectItem); + if (item) { + const AccessPoints *ap = item->accessPoint(); + if (ap && ap->status() == ConnectionStatus::Activating) { + WirelessDevice *device = (const_cast(item->wirelessDevice())); + device->disconnectNetwork(); + } + } + } + + for (NetItem *item : m_items) + delete item; + + m_items.clear(); +} + +void NetworkPanel::initUi() +{ + m_netListView->setAccessibleName("list_network"); + m_netListView->setBackgroundType(DStyledItemDelegate::BackgroundType::ClipCornerBackground); + m_netListView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_netListView->setFrameShape(QFrame::NoFrame); + m_netListView->setViewportMargins(0, 0, 0, 0); + m_netListView->setItemSpacing(1); + m_netListView->setMouseTracking(true); + m_netListView->setItemMargins(QMargins(10, 0, 10, 0)); + m_netListView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + m_netListView->setItemRadius(0); + + NetworkDelegate *delegate = new NetworkDelegate(m_netListView); + delegate->setDBusAirplaneMode(m_airplaneMode); + delegate->setMargins(QMargins(10, 0, 6, 0)); + m_netListView->setItemDelegate(delegate); + connect(delegate, &NetworkDelegate::refreshClicked, this, &NetworkPanel::onRefreshClicked); + connect(delegate, &NetworkDelegate::enabledClicked, this, &NetworkPanel::onEnabledClicked); + connect(delegate, &NetworkDelegate::closeClicked, this, [] (const QModelIndex &index) { + // 获取该行数据对应的设备 + NetItemType type = index.data(NetItemRole::TypeRole).value(); + if (type == NetItemType::WiredViewItem) { + WiredDevice *device = index.data(NetItemRole::DeviceDataRole).value(); + WiredConnection *connection = static_cast(index.data(NetItemRole::DataRole).value()); + if (device && connection) { + if (connection->connected()) + device->disconnectNetwork(); + else + device->connectNetwork(connection); + } + } else if (type == NetItemType::WirelessViewItem || type == NetItemType::WirelessHiddenViewItem) { + WirelessDevice *device = index.data(NetItemRole::DeviceDataRole).value(); + AccessPoints *accessPoint = static_cast(index.data(NetItemRole::DataRole).value()); + if (device && accessPoint) { + if (device->activeAccessPoints() == accessPoint) + device->disconnectNetwork(); + } + } + }); + + m_model = new QStandardItemModel(this); + m_model->setSortRole(sortRole); + m_netListView->setModel(m_model); + + QVBoxLayout *centerLayout = new QVBoxLayout(m_centerWidget); + centerLayout->setContentsMargins(0, 0, 0, 0); + centerLayout->addWidget(m_netListView); + + m_applet->setFixedWidth(PANELWIDTH); + m_applet->setWidget(m_centerWidget); + m_applet->setFrameShape(QFrame::NoFrame); + m_applet->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_applet->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + m_centerWidget->setAutoFillBackground(false); + m_applet->viewport()->setAutoFillBackground(false); + m_applet->setVisible(false); + m_applet->installEventFilter(this); + m_applet->setFixedSize(PANELWIDTH, 0); + + setControlBackground(); + + // 支持在触摸屏上滚动 + QScroller::grabGesture(m_netListView->viewport(), QScroller::LeftMouseButtonGesture); + QScroller *scroller = QScroller::scroller(m_netListView->window()); + QScrollerProperties sp; + sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff); + scroller->setScrollerProperties(sp); +} + +void NetworkPanel::initConnection() +{ + static bool isConnectionInited = false; + if (isConnectionInited) { + return; + } + isConnectionInited = true; + // 主题发生变化触发的信号 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &NetworkPanel::onUpdatePlugView); + + // 连接信号 + disconnect(NetworkController::instance(), nullptr, this, nullptr); + NetworkController *networkController = NetworkController::instance(); + connect(networkController, &NetworkController::deviceAdded, this, &NetworkPanel::onDeviceAdded); + connect(networkController, &NetworkController::deviceRemoved, this, &NetworkPanel::onUpdatePlugView); + connect(networkController, &NetworkController::connectivityChanged, this, &NetworkPanel::onUpdatePlugView); + + // 点击列表的信号 + connect(m_netListView, &DListView::pressed, this, &NetworkPanel::onClickListView); + + int wirelessScanInterval = Utils::SettingValue("com.deepin.dde.dock", QByteArray(), "wireless-scan-interval", 10).toInt() * 1000; + m_wirelessScanTimer->setInterval(wirelessScanInterval); + // const QGSettings *gsetting = Utils::SettingsPtr("com.deepin.dde.dock", QByteArray(), this); + // if (gsetting) + // connect(gsetting, &QGSettings::changed, [ & ](const QString &key) { + // if (key == "wireless-scan-interval") { + // int interval = gsetting->get("wireless-scan-interval").toInt() * 1000; + // m_wirelessScanTimer->setInterval(interval); + // } + // }); + connect(m_wirelessScanTimer, &QTimer::timeout, [ & ] { + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() == DeviceType::Wireless) { + WirelessDevice *wirelessDevice = static_cast(device); + wirelessDevice->scanNetwork(); + } + } + }); + connect(m_updateTimer, &QTimer::timeout, this, &NetworkPanel::updateView); + m_updateTimer->setInterval(200); + m_updateTimer->setSingleShot(true); + + QTimer::singleShot(0, this, [ = ] { + onDeviceAdded(networkController->devices()); + updateView(); + }); +} + +void NetworkPanel::onEnabledClicked(const QModelIndex &index, const bool enabled) +{ + NetItemType itemType = index.data(TypeRole).value(); + switch (itemType) { + case NetItemType::DeviceControllViewItem: { + QList devices = index.data(DeviceDataRole).value>(); + for (NetworkDeviceBase *device : devices) { + if (device->isEnabled() != enabled) + device->setEnabled(enabled); + } + break; + } + case NetItemType::WiredControllViewItem: + case NetItemType::WirelessControllViewItem: { + NetworkDeviceBase *device = index.data(DeviceDataRole).value(); + if (device && device->isEnabled() != enabled) + device->setEnabled(enabled); + break; + } + default: + break; + } +} + +void NetworkPanel::onRefreshClicked(const QModelIndex &index) +{ + NetItemType itemType = index.data(TypeRole).value(); + if (itemType != NetItemType::WirelessControllViewItem) + return; + + WirelessDevice *device = index.data(DeviceDataRole).value(); + if (device) + device->scanNetwork(); +} + +void NetworkPanel::updateItems() +{ + auto findBaseController = [ this ] (DeviceType t)-> DeviceControllItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::DeviceControllViewItem) + continue; + + DeviceControllItem *pBaseCtrlItem = static_cast(item); + if (pBaseCtrlItem->deviceType() == t) + return pBaseCtrlItem; + } + + return Q_NULLPTR; + }; + + auto findWiredController = [ this ] (WiredDevice *device)-> WiredControllItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::WiredControllViewItem) + continue; + + WiredControllItem *wiredCtrlItem = static_cast(item); + if (wiredCtrlItem->device() == device) + return wiredCtrlItem; + } + + return Q_NULLPTR; + }; + + auto findWiredItem = [ this ] (WiredConnection *conn)-> WiredItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::WiredViewItem) + continue; + + WiredItem *wiredItem = static_cast(item); + if (wiredItem->connection() == conn) + return wiredItem; + } + + return Q_NULLPTR; + }; + + auto findWirelessController = [ this ] (WirelessDevice *device)-> WirelessControllItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::WirelessControllViewItem) + continue; + + WirelessControllItem *wiredCtrlItem = static_cast(item); + if (wiredCtrlItem->device() == device) + return wiredCtrlItem; + } + + return Q_NULLPTR; + }; + + auto findWirelessItem = [ this ] (const AccessPoints *ap, const WirelessDevice *device)-> WirelessItem * { + for (NetItem *item : m_items) { + if (item->itemType() != NetItemType::WirelessViewItem) + continue; + + WirelessItem *wirelessItem = static_cast(item); + const AccessPoints *apData = wirelessItem->accessPoint(); + const WirelessDevice *wirelessdevice = wirelessItem->wirelessDevice(); + if (apData == ap && wirelessdevice == device) + return wirelessItem; + } + + return Q_NULLPTR; + }; + + QList devices = NetworkController::instance()->devices(); + QList wiredDevices; + QList wirelessDevices; + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() == DeviceType::Wired) { + WiredDevice *dev = static_cast(device); + wiredDevices << dev; + } else if (device->deviceType() == DeviceType::Wireless) { + WirelessDevice *dev = static_cast(device); + wirelessDevices << dev; + } + } + + // 存在多个无线设备的情况下,需要显示总开关 + int sortIndex = 0; + QList items; + if (wirelessDevices.size() > 1) { + DeviceControllItem *ctrl = findBaseController(DeviceType::Wireless); + if (!ctrl) + ctrl = new DeviceControllItem(DeviceType::Wireless, m_netListView->viewport()); + else + ctrl->updateView(); + + ctrl->standardItem()->setData(sortIndex++, sortRole); + ctrl->setDevices(devices); + items << ctrl; + } + + // 遍历当前所有的无线网卡 + auto accessPoints = [] (WirelessDevice *device) { + if (device->isEnabled()) + return device->accessPointItems(); + + return QList(); + }; + + for (WirelessDevice *device : wirelessDevices) { + WirelessControllItem *ctrl = findWirelessController(device); + if (!ctrl) + ctrl = new WirelessControllItem(m_netListView->viewport(), static_cast(device)); + ctrl->updateView(); + + ctrl->standardItem()->setData(sortIndex++, sortRole); + items << ctrl; + if (device->isEnabled() && !device->hotspotEnabled()) { + QList aps = accessPoints(device); + // 按连接状态、强度、名称排序 + std::sort(aps.begin(), aps.end(), [](AccessPoints *a, AccessPoints *b) { + int aStatus = static_cast(a->status()) & 3; + int bStatus = static_cast(b->status()) & 3; + if (aStatus ^ bStatus) + return aStatus != 0; + if (a->strength() == b->strength()) + return a->ssid() <= b->ssid(); + return a->strength() > b->strength(); + }); + for (AccessPoints *ap : aps) { + WirelessItem *apCtrl = findWirelessItem(ap, device); + if (!apCtrl) { + apCtrl = new WirelessItem(m_netListView->viewport(), device, ap, this); + connect(apCtrl, &WirelessItem::sizeChanged, this, &NetworkPanel::refreshItems); + connect(m_airplaneMode, &NetworkDBusProxy::EnabledChanged, apCtrl, &WirelessItem::onAirplaneModeChanged); + } + apCtrl->updateView(); + apCtrl->onAirplaneModeChanged(m_airplaneMode->enabled()); + + apCtrl->standardItem()->setData(sortIndex++, sortRole); + items << apCtrl; + } + if (!m_airplaneMode->enabled()) { + // 连接隐藏网络 + WirelessItem *apCtrl = findWirelessItem(nullptr, device); + if (!apCtrl) { + apCtrl = new WirelessItem(m_netListView->viewport(), device, nullptr, this); + connect(apCtrl, &WirelessItem::sizeChanged, this, &NetworkPanel::refreshItems); + } + apCtrl->updateView(); + + apCtrl->standardItem()->setData(sortIndex++, sortRole); + items << apCtrl; + } + } + } + + // 存在多个有线设备的情况下,需要显示总开关 + if (wiredDevices.size() > 1) { + DeviceControllItem *ctrl = findBaseController(DeviceType::Wired); + if (!ctrl) + ctrl = new DeviceControllItem(DeviceType::Wired, m_netListView->viewport()); + ctrl->updateView(); + + ctrl->standardItem()->setData(sortIndex++, sortRole); + ctrl->setDevices(devices); + items << ctrl; + } + + auto wiredConnections = [ & ](WiredDevice *device) { + if (device->isEnabled()) + return device->items(); + + return QList(); + }; + + // 遍历当前所有的有线网卡 + for (WiredDevice *device : wiredDevices) { + WiredControllItem *ctrl = findWiredController(device); + if (!ctrl) + ctrl = new WiredControllItem(m_netListView->viewport(), device); + ctrl->updateView(); + + ctrl->standardItem()->setData(sortIndex++, sortRole); + items << ctrl; + + QList connItems = wiredConnections(device); + for (WiredConnection *conn : connItems) { + WiredItem *connectionCtrl = findWiredItem(conn); + if (!connectionCtrl) + connectionCtrl = new WiredItem(m_netListView->viewport(), device, conn); + connectionCtrl->updateView(); + + connectionCtrl->standardItem()->setData(sortIndex++, sortRole); + items << connectionCtrl; + } + } + + // 把原来列表中不存在的项放到移除列表中 + for (NetItem *item : m_items) { + if (!items.contains(item)) + delete item; + } + + m_items = items; +} + +void NetworkPanel::updateView() +{ + updateItems(); + refreshItems(); + passwordError(QString(), QString()); + // 网络设备数量大于1时,需要延迟发送信号,确保数据初始化完成,避免网络面板闪烁,解决bug119717 + QTimer::singleShot(200, this, [ this ] { + if (m_model->rowCount() > 0) + Q_EMIT updateFinished(); + }); +} + +void NetworkPanel::refreshItems() +{ + QList items; + QList rmRows; + for (NetItem *item : m_items) + items << item->standardItem(); + + for (int i = 0; i < m_model->rowCount(); i++) { + DStandardItem *item = static_cast(m_model->item(i)); + if (!items.contains(item)) + rmRows << i; + } + // 将row按照从大到小的顺序排序,否则会出现删除错误的问题 + std::sort(rmRows.begin(), rmRows.end(), [](const int row1, const int row2) { return row1 > row2; }); + for (int row : rmRows) + m_model->removeRow(row); + + // 从缓存中查找出当前列表不存在的Item,并插入到列表中 + QList currentItems; + for (int i = 0; i < m_model->rowCount(); i++) + currentItems << m_model->item(i); + + QList newItems; + for (QStandardItem *item : items) { + if (!currentItems.contains(item)) + newItems << item; + } + + for (QStandardItem *item : newItems) + m_model->appendRow(item); + + // 对列表进行重新排序 + m_model->sort(0); + + // 设置高度 + int height = 0; + int totalHeight = 0; + for (int i = 0; i < m_model->rowCount(); i++) { + QStandardItem *item = m_model->item(i); + QSize size = item->sizeHint(); + if (i < 16) + height += size.height(); + + totalHeight += size.height(); + } + + m_netListView->setFixedSize(PANELWIDTH, totalHeight); + m_centerWidget->setFixedSize(PANELWIDTH, totalHeight); + m_applet->setFixedSize(PANELWIDTH, height); + + m_netListView->update(); +} + +bool NetworkPanel::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == m_applet) { + switch (event->type()) { + case QEvent::Show: { + if (!m_wirelessScanTimer->isActive()) + m_wirelessScanTimer->start(); + break; + } + case QEvent::Hide: { + if (m_wirelessScanTimer->isActive()) + m_wirelessScanTimer->stop(); + break; + } + default: + break; + } + } + + return QObject::eventFilter(obj, event); +} + +int NetworkPanel::deviceCount(const DeviceType &devType) +{ + // 获取指定的设备类型的设备数量 + int count = 0; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *dev : devices) + if (dev->deviceType() == static_cast(devType)) + count++; + + return count; +} + +void NetworkPanel::onDeviceAdded(QList devices) +{ + // 处理新增设备的信号 + for (NetworkDeviceBase *device : devices) { + // 当网卡连接状态发生变化的时候重新绘制任务栏的图标 + connect(device, &NetworkDeviceBase::deviceStatusChanged, this, &NetworkPanel::onUpdatePlugView); + connect(device, &NetworkDeviceBase::activeConnectionChanged, this, &NetworkPanel::onUpdatePlugView); + switch (device->deviceType()) { + case DeviceType::Wired: { + WiredDevice *wiredDevice = static_cast(device); + + connect(wiredDevice, &WiredDevice::connectionAdded, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::connectionRemoved, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::connectionPropertyChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::deviceStatusChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::enableChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::connectionChanged, this, &NetworkPanel::onUpdatePlugView); + } break; + case DeviceType::Wireless: { + WirelessDevice *wirelessDevice = static_cast(device); + + connect(wirelessDevice, &WirelessDevice::networkAdded, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::networkRemoved, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::accessPointInfoChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::enableChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::connectionChanged, this, &NetworkPanel::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::hotspotEnableChanged, this, &NetworkPanel::onUpdatePlugView); + + wirelessDevice->scanNetwork(); + } break; + default: + break; + } + } + + onUpdatePlugView(); +} + +bool NetworkPanel::deviceEnabled(const DeviceType &deviceType) const +{ + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) + if (device->deviceType() == deviceType && device->isEnabled()) + return true; + + return false; +} + +void NetworkPanel::setDeviceEnabled(const DeviceType &deviceType, bool enabeld) +{ + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) + if (device->deviceType() == deviceType) + device->setEnabled(enabeld); +} + +QWidget *NetworkPanel::itemApplet() +{ + return m_applet; +} + +void NetworkPanel::setControlBackground() +{ + QPalette backgroud = m_applet->palette(); + backgroud.setColor(QPalette::Window, ThemeManager::ref().backgroundColor()); + m_applet->setAutoFillBackground(true); + m_applet->setPalette(backgroud); +} + +void NetworkPanel::onUpdatePlugView() +{ + if (!m_updateTimer->isActive()) { + m_updateTimer->start(); + } +} + +void NetworkPanel::onClickListView(const QModelIndex &index) +{ + // 如果当前点击的是连接隐藏网络或者无线网络,且开启了飞行模式,则不让点击 + NetItemType type = index.data(NetItemRole::TypeRole).value(); + if ((type == WirelessHiddenViewItem || type == WirelessViewItem) && m_airplaneMode->enabled()) + return; + + NetItem *oldSelectItem = selectItem(); + NetItem *newSelectItem = m_items.at(index.row()); + if (newSelectItem != oldSelectItem && oldSelectItem) { + WirelessItem *item = static_cast(oldSelectItem); + item->expandWidget(WirelessItem::Hide, false); // 选择切换时隐藏输入框 + } + switch (type) { + case WirelessHiddenViewItem: + case WirelessViewItem: { + WirelessItem *item = static_cast(newSelectItem); + item->connectNetwork(); + break; + } + case WiredViewItem: { + WiredItem *item = static_cast(newSelectItem); + item->connectNetwork(); + break; + } + default: + break; + } +} + +int NetworkPanel::getStrongestAp() +{ + int retStrength = -1; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != DeviceType::Wireless) + continue; + + WirelessDevice *dev = static_cast(device); + AccessPoints *ap = dev->activeAccessPoints(); + if (ap && retStrength < ap->strength()) + retStrength = ap->strength(); + } + + return retStrength; +} + +void NetworkPanel::passwordError(const QString &dev, const QString &ssid, bool wait) +{ + if (!ssid.isEmpty()) { + m_reconnectSsid = ssid; + m_reconnectDev = dev; + m_waitPassword = wait; + clear(); + } + if (!m_reconnectSsid.isEmpty()) { + QTimer::singleShot(0, this, &NetworkPanel::expandPasswordInput); + } +} + +bool NetworkPanel::changePassword(const QString &key, const QString &password, bool input) +{ + if (m_waitPassword) { + Q_EMIT passwordChanged(key, password, input); + m_waitPassword = false; + return true; + } + return false; +} + +QString NetworkPanel::ssidWaitingForPassword() const +{ + return m_reconnectSsid; +} + +bool NetworkPanel::closeOnClear() const +{ + return m_closeOnClear; +} + +void NetworkPanel::setCloseOnClear(bool closeOnClear) +{ + m_closeOnClear = closeOnClear; +} + +void NetworkPanel::clear() +{ + NetItem *oldSelectItem = selectItem(); + if (oldSelectItem) { + WirelessItem *selectItem = static_cast(oldSelectItem); + selectItem->expandWidget(WirelessItem::Hide); + } + m_applet->verticalScrollBar()->setValue(0); +} + +void NetworkPanel::expandPasswordInput() +{ + if (m_reconnectSsid.isEmpty()) { + return; + } + NetItem *oldSelectItem = selectItem(); + int y = 0; + for (NetItem *item : m_items) { + if (NetItemType::WirelessViewItem == item->itemType()) { + WirelessItem *wirelessItem = static_cast(item); + if (wirelessItem->accessPoint() + && (m_reconnectDev.isEmpty() || wirelessItem->wirelessDevice()->path() == m_reconnectDev) + && (wirelessItem->accessPoint()->ssid() == m_reconnectSsid)) { + if (item != oldSelectItem) { + if (oldSelectItem) { + WirelessItem *selectItem = static_cast(oldSelectItem); + selectItem->expandWidget(WirelessItem::Hide); // 选择切换时隐藏输入框 + } + wirelessItem->expandPasswordInput(); + int h = item->standardItem()->sizeHint().height() / 2; + m_applet->ensureVisible(0, y + h, 0, h); + } + m_reconnectSsid.clear(); + m_reconnectDev.clear(); + break; + } + } + y += item->standardItem()->sizeHint().height(); + } +} + +NetItem *NetworkPanel::selectItem() +{ + for (NetItem *item : m_items) { + if (NetItemType::WirelessViewItem == item->itemType() || NetItemType::WirelessHiddenViewItem == item->itemType()) { + WirelessItem *wirelessItem = static_cast(item); + if (wirelessItem->expandVisible()) { + return wirelessItem; + } + } + } + return nullptr; +} + +// 用于绘制分割线 +#define RIGHTMARGIN 13 +#define DIAMETER 16 + +NetworkDelegate::NetworkDelegate(QAbstractItemView *parent) + : DStyledItemDelegate(parent) + , m_parentWidget(parent) + , m_refreshIconTimer(new QTimer(this)) + , m_currentDegree(0) + , m_refreshTimer(new QTimer(this)) + , m_airplaneMode(nullptr) +{ + connect(m_refreshTimer, &QTimer::timeout, this, [this]() { + this->m_currentDegree += 14; + m_parentWidget->update(); + }); + + m_refreshIconTimer->setInterval(3); + connect(m_refreshIconTimer, &QTimer::timeout, this, [ this ] { + QList refreshIndexs = m_refreshAngle.keys(); + for (int i = refreshIndexs.size() - 1; i >= 0; i--) { + const QModelIndex &index = refreshIndexs[i]; + int angle = m_refreshAngle[index]; + if (angle >= 360) { + m_refreshAngle.remove(index); + } else { + angle += (angle <= 180 ? 5 : 8); + m_refreshAngle[index] = angle; + } + } + if (m_refreshAngle.size() == 0) { + if (m_refreshIconTimer->isActive()) + m_refreshIconTimer->stop(); + } + m_parentWidget->update(); + }); + + m_refreshTimer->setInterval(30); +} + +NetworkDelegate::~NetworkDelegate() +{ + if (m_refreshTimer->isActive()) + m_refreshTimer->stop(); +} + +void NetworkDelegate::setDBusAirplaneMode(NetworkDBusProxy *airplane) +{ + m_airplaneMode = airplane; +} + +void NetworkDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const +{ + option->state &= ~QStyle::State_MouseOver; + DStyledItemDelegate::initStyleOption(option, index); +} + +void NetworkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + bool drawLine = needDrawLine(index); + if (drawLine) { + // 绘制间隔线 + QRect rct = option.rect; + rct.setY(rct.top() + rct.height() - 2); + rct.setHeight(2); + painter->fillRect(rct, ThemeManager::ref().lineColor()); + } + // 鼠标移动的时候不 + bool isHoverItem = cantHover(index); + QRect rect = option.rect; + if (drawLine) + rect.setHeight(rect.height() - 2); + + if (!isHoverItem && (option.state & QStyle::State_MouseOver)) { + painter->fillRect(rect, ThemeManager::ref().itemBackgroundColor()); + } + + // 绘制无线网络左侧的刷新按钮 + if (index.data(TypeRole).value() == NetItemType::WirelessControllViewItem) + drawRefreshButton(painter, option, index); + + // 绘制开关按钮,因为如果直接在DStandardItem上使用DSwitchButton就会导致更新列表的时候引起错位,就使用绘制开关的方式来实现吧 + if (hasSwitchButton(index)) + drawSwitchButton(painter, option, index); + + // 绘制右侧的连接图标 + NetConnectionType connectionStatus = static_cast(index.data(NetItemRole::ConnectionStatusRole).toInt()); + if (connectionStatus == NetConnectionType::Connecting) { + if (!m_ConnectioningIndexs.contains(index)) + m_ConnectioningIndexs << index; + } else { + if (m_ConnectioningIndexs.contains(index)) + m_ConnectioningIndexs.removeOne(index); + } + + if (m_ConnectioningIndexs.size() > 0) { + if (!m_refreshTimer->isActive()) + m_refreshTimer->start(); + } else { + if (m_refreshTimer->isActive()) { + m_refreshTimer->stop(); + m_currentDegree = 0; + } + } + + switch (connectionStatus) { + case NetConnectionType::Connected: { + painter->setRenderHint(QPainter::Antialiasing, true); + + QRect rct = checkRect(option.rect); + painter->save(); + painter->setPen(QPen(Qt::NoPen)); + painter->setBrush(m_parentWidget->palette().color(QPalette::Highlight)); + + QPen pen(Qt::white, DIAMETER / 100.0 * 6.20, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin); + if (index.data(NetItemRole::MouseInBoundingRole).toBool()) + drawFork(painter, rct, pen, DIAMETER); + else + drawCheck(painter, rct, pen, DIAMETER); + + painter->restore(); + break; + } + case NetConnectionType::Connecting: { + QRect rct = checkRect(option.rect); + drawLoading(painter, rct, DIAMETER); + break; + } + default: + break; + } + + DStyledItemDelegate::paint(painter, option, index); +} + +bool NetworkDelegate::needDrawLine(const QModelIndex &index) const +{ + // 如果是最后一行,则无需绘制线条 + QModelIndex siblingIndex = index.siblingAtRow(index.row() + 1); + if (!siblingIndex.isValid()) + return false; + + // 如果是总控开关,无线开关和有线开关,下面都要分割线 + NetItemType itemType = index.data(TypeRole).value(); + if (itemType == NetItemType::DeviceControllViewItem + || itemType == NetItemType::WirelessControllViewItem + || itemType == NetItemType::WiredControllViewItem) + return true; + + NetItemType nextItemType = siblingIndex.data(TypeRole).value(); + return itemType != nextItemType; +} + +bool NetworkDelegate::cantHover(const QModelIndex &index) const +{ + NetItemType itemType = index.data(TypeRole).value(); + // 如果是无线网络或者连接隐藏网络项,且当前开启了飞行模式,则当前行不让点击 + if (itemType == NetItemType::WirelessViewItem || itemType == NetItemType::WirelessHiddenViewItem) + return (m_airplaneMode && m_airplaneMode->enabled()); + + return (itemType == NetItemType::DeviceControllViewItem + || itemType == NetItemType::WirelessControllViewItem + || itemType == NetItemType::WiredControllViewItem); +} + +bool NetworkDelegate::hasSwitchButton(const QModelIndex &index) const +{ + NetItemType itemType = index.data(TypeRole).value(); + // 如果是总控、有线网卡、无线网卡开关,则需要显示开关 + return (itemType == NetItemType::DeviceControllViewItem + || itemType == NetItemType::WirelessControllViewItem + || itemType == NetItemType::WiredControllViewItem); +} + +void NetworkDelegate::drawCheck(QPainter *painter, QRect &rect, QPen &pen, int radius) const +{ + painter->drawPie(rect, 0, 360 * 16); + painter->setPen(pen); + + QPointF points[3] = { + QPointF(rect.left() + radius / 100.0 * 32, rect.top() + radius / 100.0 * 57), + QPointF(rect.left() + radius / 100.0 * 45, rect.top() + radius / 100.0 * 70), + QPointF(rect.left() + radius / 100.0 * 75, rect.top() + radius / 100.0 * 35) + }; + + painter->drawPolyline(points, 3); +} + +void NetworkDelegate::drawFork(QPainter *painter, QRect &rect, QPen &pen, int radius) const +{ + painter->drawPie(rect, 0, 360 * 16); + pen.setCapStyle(Qt::RoundCap); + painter->setPen(pen); + + QPointF pointsl[2] = { + QPointF(rect.left() + radius / 100.0 * 35, rect.top() + radius / 100.0 * 35), + QPointF(rect.left() + radius / 100.0 * 65, rect.top() + radius / 100.0 * 65) + }; + + painter->drawPolyline(pointsl, 2); + + QPointF pointsr[2] = { + QPointF(rect.left() + radius / 100.0 * 65, rect.top() + radius / 100.0 * 35), + QPointF(rect.left() + radius / 100.0 * 35, rect.top() + radius / 100.0 * 65) + }; + + painter->drawPolyline(pointsr, 2); +} + +void NetworkDelegate::drawLoading(QPainter *painter, QRect &rect, int diameter) const +{ + painter->setRenderHint(QPainter::Antialiasing, true); + QList> indicatorColors; + for (int i = 0; i < 3; i++) + indicatorColors << createDefaultIndicatorColorList(m_parentWidget->palette().highlight().color()); + + double radius = diameter * 0.66; + auto center = QRectF(rect).center(); + auto indicatorRadius = radius / 2 / 2 * 1.1; + auto indicatorDegreeDelta = 360 / indicatorColors.count(); + +#define INDICATOR_SHADOW_OFFSET 10 + + for (int i = 0; i < indicatorColors.count(); ++i) { + QList colors = indicatorColors.value(i); + for (int j = 0; j < colors.count(); ++j) { + double degreeCurrent = m_currentDegree - j * INDICATOR_SHADOW_OFFSET + indicatorDegreeDelta * i; + auto x = (radius - indicatorRadius) * qCos(qDegreesToRadians(degreeCurrent)); + auto y = (radius - indicatorRadius) * qSin(qDegreesToRadians(degreeCurrent)); + + x = center.x() + x; + y = center.y() + y; + auto tl = QPointF(x - 1 * indicatorRadius, y - 1 * indicatorRadius); + QRectF rf(tl.x(), tl.y(), indicatorRadius * 2, indicatorRadius * 2); + + QPainterPath path; + path.addEllipse(rf); + + painter->fillPath(path, colors.value(j)); + } + } +} + +bool NetworkDelegate::switchIsEnabled(const QModelIndex &index) const +{ + if (!index.isValid()) + return false; + + NetItemType itemType = index.data(TypeRole).value(); + switch (itemType) { + case NetItemType::DeviceControllViewItem: { + QList devices = index.data(NetItemRole::DeviceDataRole).value>(); + for (NetworkDeviceBase *device : devices) { + if (device->isEnabled()) + return true; + } + return false; + } + case NetItemType::WiredControllViewItem:{ + NetworkDeviceBase *device = index.data(NetItemRole::DeviceDataRole).value(); + if (device) + return device->isEnabled(); + break; + } + case NetItemType::WirelessControllViewItem: { + NetworkDeviceBase *device = index.data(NetItemRole::DeviceDataRole).value(); + if (device) + return device->isEnabled() && !m_airplaneMode->enabled(); + break; + } + default: + break; + } + return false; +} + +void NetworkDelegate::drawRefreshButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + // 如果当前开关为关闭状态,则不显示刷新按钮 + if (!switchIsEnabled(index)) + return; + + QRect rctIcon(option.rect.width() - SWITCH_WIDTH - 36, option.rect.top() + (option.rect.height() - 20) / 2, 20, 20); + QPixmap pixmap = DIcon::loadNxPixmap(ThemeManager::ref().getIcon("refresh")); + painter->save(); + painter->setRenderHint(QPainter::Antialiasing, true); + if (m_refreshAngle.contains(index)) { + QPoint ptCenter(rctIcon.left() + rctIcon.width() / 2, rctIcon.top() + rctIcon.height() / 2); + painter->translate(ptCenter); + painter->rotate(m_refreshAngle[index]); + painter->drawPixmap(QRect(-10, -10, 20, 20), pixmap); + } else { + painter->drawPixmap(rctIcon, pixmap); + } + + painter->restore(); +} + +void NetworkDelegate::drawSwitchButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + painter->save(); + painter->setRenderHint(QPainter::Antialiasing, true); + QRect rctSwitch(option.rect.width() - SWITCH_WIDTH - 10, + option.rect.top() + (option.rect.height() - SWITCH_HEIGHT) / 2, + SWITCH_WIDTH, SWITCH_HEIGHT); + painter->setPen(Qt::NoPen); + DPalette palette = option.palette; + painter->setBrush(palette.color(DPalette::ColorRole::Button)); + painter->drawRoundedRect(rctSwitch, 8, 8); + bool isSwitchEnabled = switchIsEnabled(index); + NetItemType itemType = index.data(TypeRole).value(); + // 如果是总控、有线网卡、无线网卡开关,则需要显示开关 + QPalette::ColorRole colorRole = isSwitchEnabled ? QPalette::ColorRole::Highlight : DPalette::ColorRole::ButtonText; + if (m_airplaneMode->enabled() && itemType == NetItemType::WirelessControllViewItem) + painter->setBrush(palette.color(QPalette::ColorGroup::Disabled, colorRole)); + else + painter->setBrush(palette.color(colorRole)); + + isSwitchEnabled ? rctSwitch.setLeft(rctSwitch.left() + 20) : rctSwitch.setWidth(30); + painter->drawRoundedRect(rctSwitch, 8, 8); + + painter->restore(); +} + +bool NetworkDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) +{ + switch (event->type()) { + case QEvent::MouseMove: { + QMouseEvent *mouseEvent = static_cast(event); + QRect rct = checkRect(option.rect); + model->setData(index, rct.contains(mouseEvent->pos()), NetItemRole::MouseInBoundingRole); + m_parentWidget->update(); + break; + } + case QEvent::Leave: { + model->setData(index, false, NetItemRole::MouseInBoundingRole); + m_parentWidget->update(); + break; + } + case QEvent::MouseButtonPress: { + QMouseEvent *mouseEvent = static_cast(event); + if (index.data(TypeRole).value() == NetItemType::WirelessControllViewItem) { + if (!m_airplaneMode->enabled()) { + if (!m_refreshAngle.contains(index)) { + QRect rctSwitch(option.rect.width() - SWITCH_WIDTH - 36, option.rect.top() + (option.rect.height() - 20) / 2, 20, 20); + if (rctSwitch.contains(mouseEvent->pos())) { + Q_EMIT refreshClicked(index); + // 后面刷新图标是根据m_refreshAngle列表中是否存在来决定是否刷新的,因此,需要提前将m_refreshAngle填充数据 + m_refreshAngle[index] = 0; + if (!m_refreshIconTimer->isActive()) + m_refreshIconTimer->start(); + return true; + } + } + } + } + if (hasSwitchButton(index)) { + NetItemType itemType = index.data(TypeRole).value(); + // 以下三种情况可以点击按钮 + // 1: 飞行模式关闭 2: 当前是有线网卡 3: 当前是有线网卡总控 + if (!m_airplaneMode->enabled() || itemType == NetItemType::WiredControllViewItem + || (itemType == NetItemType::DeviceControllViewItem && index.data(NetItemRole::DeviceTypeRole).value() == DeviceType::Wired)) { + QRect rctSwitch(option.rect.width() - SWITCH_WIDTH - 10, + option.rect.top() + (option.rect.height() - SWITCH_HEIGHT) / 2, + SWITCH_WIDTH, SWITCH_HEIGHT); + if (rctSwitch.contains(mouseEvent->pos())) { + Q_EMIT enabledClicked(index, !switchIsEnabled(index)); + return true; + } + } + } else { + NetConnectionType connectionStatus = static_cast(index.data(NetItemRole::ConnectionStatusRole).toInt()); + QRect rct = checkRect(option.rect); + if (connectionStatus == NetConnectionType::Connected) { + if (rct.contains(mouseEvent->pos())) { + Q_EMIT closeClicked(index); + return true; + } + } + } + break; + } + default: + break; + } + + return DStyledItemDelegate::editorEvent(event, model, option, index); +} + +QRect NetworkDelegate::checkRect(const QRect &rct) const +{ + int left = rct.right() - RIGHTMARGIN - DIAMETER + 4; + int top = rct.top() + (DIAMETER / 2); // 连接图标绘制在顶端 + QRect rect; + rect.setLeft(left); + rect.setTop(top); + rect.setWidth(DIAMETER); + rect.setHeight(DIAMETER); + return rect; +} + +QList NetworkDelegate::createDefaultIndicatorColorList(QColor color) const +{ + QList colors; + QList opacitys; + opacitys << 100 << 30 << 15 << 10 << 5 << 4 << 3 << 2 << 1; + for (int i = 0; i < opacitys.count(); ++i) { + color.setAlpha(255 * opacitys.value(i) / 100); + colors << color; + } + return colors; +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.h new file mode 100644 index 000000000..3e48ebef1 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/networkpanel.h @@ -0,0 +1,149 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKPANEL_H +#define NETWORKPANEL_H + +#include "item/devicestatushandler.h" + +#include + +#include + +#include +#include + +namespace dde { + namespace network { + enum class DeviceType; + class NetworkDeviceBase; + class NetworkDBusProxy; + } +} + +class NetItem; +class QStandardItemModel; +class QTimer; +class QScrollArea; + +using namespace dde::network; + +DGUI_USE_NAMESPACE +DWIDGET_USE_NAMESPACE + +class NetworkPanel : public QObject +{ + Q_OBJECT + +Q_SIGNALS: + void updateFinished(); + void passwordChanged(const QString &key, const QString &password, bool input); + +public: + explicit NetworkPanel(QObject *parent = Q_NULLPTR); + ~NetworkPanel() override; + + QWidget *itemApplet(); + void passwordError(const QString &dev, const QString &ssid, bool wait = true); + + bool changePassword(const QString &key, const QString &password, bool input); + QString ssidWaitingForPassword() const; + bool closeOnClear() const; + void setCloseOnClear(bool closeOnClear); + void clear(); + +protected: + bool eventFilter(QObject *obj, QEvent *event) override; + +private: + void setControlBackground(); + void initUi(); + void updateItems(); + bool deviceEnabled(const DeviceType &deviceType) const; + void setDeviceEnabled(const DeviceType &deviceType, bool enabeld); + + int getStrongestAp(); + int deviceCount(const DeviceType &devType); + void expandPasswordInput(); + NetItem *selectItem(); + +private Q_SLOTS: + void initConnection(); + void onDeviceAdded(QList devices); + void onUpdatePlugView(); + void onEnabledClicked(const QModelIndex &index, const bool enabled); + void onRefreshClicked(const QModelIndex &index); + + void onClickListView(const QModelIndex &index); + void updateView(); // 更新网络列表内容大小 + void refreshItems(); + +private: + QTimer *m_wirelessScanTimer; + + bool m_closeOnClear; + + QStandardItemModel *m_model; + + QScrollArea *m_applet; + QWidget *m_centerWidget; + DListView *m_netListView; + + QList m_items; + // 记录无线设备Path,防止信号重复连接 + QSet m_wirelessDevicePath; + QString m_reconnectDev; + QString m_reconnectSsid; + bool m_waitPassword; + NetworkDBusProxy *m_airplaneMode; + QTimer *m_updateTimer; +}; + +class NetworkDelegate : public DStyledItemDelegate +{ + Q_OBJECT + +public: + explicit NetworkDelegate(QAbstractItemView *parent = Q_NULLPTR); + ~NetworkDelegate() Q_DECL_OVERRIDE; + void setDBusAirplaneMode(NetworkDBusProxy *airplane); + +Q_SIGNALS: + void refreshClicked(const QModelIndex &); + void closeClicked(const QModelIndex &); + void enabledClicked(const QModelIndex &, const bool); + +protected: + void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE; + + bool needDrawLine(const QModelIndex &index) const; + bool cantHover(const QModelIndex &index) const; + bool hasSwitchButton(const QModelIndex &index) const; + + void drawCheck(QPainter *painter, QRect &rect, QPen &pen, int radius) const; + void drawFork(QPainter *painter, QRect &rect, QPen &pen, int radius) const; + void drawLoading(QPainter *painter, QRect &rect, int diameter) const; + void drawRefreshButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void drawSwitchButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override; + + QRect checkRect(const QRect &rct) const; + + QList createDefaultIndicatorColorList(QColor color) const; + +private: + bool switchIsEnabled(const QModelIndex &index) const; + +private: + QAbstractItemView *m_parentWidget; + QTimer *m_refreshIconTimer; + mutable double m_currentDegree; + QTimer *m_refreshTimer; + NetworkDBusProxy *m_airplaneMode; + mutable QList m_ConnectioningIndexs; + mutable QMap m_refreshAngle; +}; + +#endif // NETWORKPANEL_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.cpp new file mode 100644 index 000000000..5c58107ab --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.cpp @@ -0,0 +1,133 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "thememanager.h" +#include "utils.h" + +#include +#include +#include + +DGUI_USE_NAMESPACE + +ThemeManager::ThemeManager(QObject *parent) + : QObject(parent) + , m_themeType(UnknownType) +{ + appThemeTypeChanged(Dtk::Gui::DGuiApplicationHelper::instance()->themeType()); + // 主题发生变化触发的信号 + connect(Dtk::Gui::DGuiApplicationHelper::instance(), &Dtk::Gui::DGuiApplicationHelper::themeTypeChanged, this, &ThemeManager::appThemeTypeChanged); +} + +ThemeManager::~ThemeManager() +{ +} + +QString ThemeManager::getIcon(QString path) +{ + if (path.startsWith("common")) { + return ":/" + path; + } + switch (m_themeType) { + case GreeterType: + case LockType: + case DarkType: + return ":/dark/" + path; + default: + return ":/light/" + path; + } +} + +void ThemeManager::setThemeType(ThemeType type) +{ + if (type != m_themeType) { + m_themeType = type; + emit themeChanged(m_themeType); + } +} + +void ThemeManager::updateInputStyle(Dtk::Widget::DLineEdit *inputEdit) +{ + switch (m_themeType) { + case GreeterType: + case LockType: { + QPalette editPalette = inputEdit->palette(); + editPalette.setColor(QPalette::Button, QColor(255, 255, 255, static_cast(0.2 * 255))); + inputEdit->setPalette(editPalette); + } break; + case DarkType: { + QPalette editPalette = inputEdit->palette(); + editPalette.setColor(QPalette::Button, QColor(255, 255, 255, static_cast(0.2 * 255))); + inputEdit->setPalette(editPalette); + } break; + case LightType: { + QPalette editPalette = inputEdit->palette(); + editPalette.setColor(QPalette::Button, QColor(0, 0, 0, static_cast(0.2 * 255))); + inputEdit->setPalette(editPalette); + } break; + default: + break; + } +} + +void ThemeManager::appThemeTypeChanged(Dtk::Gui::DGuiApplicationHelper::ColorType themeType) +{ + if (m_themeType >= UnknownType) { + switch (themeType) { + case Dtk::Gui::DGuiApplicationHelper::ColorType::DarkType: + setThemeType(DarkType); + break; + case Dtk::Gui::DGuiApplicationHelper::ColorType::LightType: + setThemeType(LightType); + break; + default: + break; + } + } +} + +QColor ThemeManager::backgroundColor() +{ + int alpha = Utils::isWaylandEnvironment() ? static_cast(0.5 * 255) : static_cast(0.03 * 255); + switch (m_themeType) { + case DarkType: + return QColor(0, 0, 0, alpha); + case GreeterType: + case LockType: + return QColor(235, 235, 235, static_cast(0.05 * 255)); + default: + return QColor(255, 255, 255, alpha); + } + Q_UNREACHABLE(); + return QColor(255, 255, 255, alpha); +} + +QColor ThemeManager::lineColor() +{ + switch (m_themeType) { + case DarkType: + return QColor(255, 255, 255, static_cast(0.05 * 255)); + case LockType: + return QColor(0, 0, 0, static_cast(0.1 * 255)); + default: + return QColor(0, 0, 0, static_cast(0.1 * 255)); + } + Q_UNREACHABLE(); + return QColor(255, 255, 255, static_cast(0.03 * 255)); +} + +QColor ThemeManager::itemBackgroundColor() +{ + switch (m_themeType) { + case DarkType: + return QColor(255, 255, 255, static_cast(255 * 0.10)); + case GreeterType: + case LockType: + return QColor(255, 255, 255, static_cast(255 * 0.10)); + default: + return QColor(0, 0, 0, static_cast(255 * 0.10)); + } + Q_UNREACHABLE(); + return QColor(255, 255, 255, static_cast(0.03 * 255)); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.h new file mode 100644 index 000000000..e08bfecef --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkdialog/thememanager.h @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef THEMEMANAGER_H +#define THEMEMANAGER_H + +#include +#include + +namespace Dtk { +namespace Widget { +class DLineEdit; +} +} + +class ThemeManager : public QObject, public Dtk::Core::DSingleton +{ + Q_OBJECT + + friend Dtk::Core::DSingleton; + +public: + enum ThemeType { + LockType, + GreeterType, + UnknownType, + LightType, + DarkType, + }; + +Q_SIGNALS: + void themeChanged(ThemeType type); + +public: + ~ThemeManager(); + QString getIcon(QString path); + QColor backgroundColor(); + QColor lineColor(); + QColor itemBackgroundColor(); + void setThemeType(ThemeType type); + void updateInputStyle(Dtk::Widget::DLineEdit *inputEdit); + +protected Q_SLOT: + void appThemeTypeChanged(Dtk::Gui::DGuiApplicationHelper::ColorType themeType); + +protected: + explicit ThemeManager(QObject *parent = nullptr); + +private: + ThemeType m_themeType; +}; + +#endif // THEMEMANAGER_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.cpp new file mode 100644 index 000000000..9714eee04 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.cpp @@ -0,0 +1,736 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkpluginhelper.h" +#include "widgets/tipswidget.h" +#include "utils.h" +#include "item/devicestatushandler.h" +#include "networkdialog.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "networkdbusproxy.h" + +NETWORKPLUGIN_USE_NAMESPACE + +NetworkPluginHelper::NetworkPluginHelper(NetworkDialog *networkDialog, QObject *parent) + : QObject(parent) + , m_pluginState(PluginState::Unknown) + , m_tipsWidget(new TipsWidget(nullptr)) + , m_switchWire(true) + , m_networkDialog(networkDialog) + , m_isDarkIcon(true) + , m_refreshIconTimer(new QTimer(this)) + , m_trayIcon(new QIcon(QIcon::fromTheme(":/light/wireless-disabled-symbolic"))) +{ + qDBusRegisterMetaType(); + initUi(); + initConnection(); +} + +NetworkPluginHelper::~NetworkPluginHelper() +{ + delete m_tipsWidget; + delete m_trayIcon; +} + +void NetworkPluginHelper::initUi() +{ + m_tipsWidget->setVisible(false); + m_tipsWidget->setSpliter(" : "); +} + +void NetworkPluginHelper::initConnection() +{ + // 主题发生变化触发的信号 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &NetworkPluginHelper::onUpdatePlugView); + + // 连接信号 + NetworkController *networkController = NetworkController::instance(); + connect(networkController, &NetworkController::deviceAdded, this, &NetworkPluginHelper::onDeviceAdded); + connect(networkController, &NetworkController::deviceRemoved, this, &NetworkPluginHelper::onUpdatePlugView); + connect(networkController, &NetworkController::connectivityChanged, this, &NetworkPluginHelper::onUpdatePlugView); + + m_refreshIconTimer->setInterval(200); + connect(m_refreshIconTimer, &QTimer::timeout, this, &NetworkPluginHelper::refreshIcon); + + refreshIcon(); + QTimer::singleShot(100, this, [ = ] { + onDeviceAdded(networkController->devices()); + refreshIcon(); + }); +} + +void NetworkPluginHelper::updatePluginState() +{ + m_pluginState = DeviceStatusHandler::pluginState(); +} + +PluginState NetworkPluginHelper::getPluginState() +{ + return m_pluginState; +} + +QList> NetworkPluginHelper::ipTipsMessage(const DeviceType &devType) +{ + DeviceType type = static_cast(devType); + QList> tipMessage; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != type) + continue; + + QStringList ipv4 = device->ipv4(); + if (ipv4.isEmpty() || ipv4[0].isEmpty()) + continue; + + QStringList ipv4Messages; + for (int i = 0; i < ipv4.size(); i++) { + ipv4Messages << (i < 3 ? ipv4[i] : "......"); + if (i >= 3) + break; + } + + tipMessage << QPair({ device->deviceName(), ipv4Messages }); + } + return tipMessage; +} + +void NetworkPluginHelper::updateTooltips() +{ + switch (m_pluginState) { + case PluginState::Connected: { + QList> textList; + textList << ipTipsMessage(DeviceType::Wireless) << ipTipsMessage(DeviceType::Wired); + m_tipsWidget->setContext(textList); + break; + } + case PluginState::WirelessConnected: + m_tipsWidget->setContext(ipTipsMessage(DeviceType::Wireless)); + break; + case PluginState::WiredConnected: + m_tipsWidget->setContext(ipTipsMessage(DeviceType::Wired)); + break; + case PluginState::Disabled: + case PluginState::WirelessDisabled: + case PluginState::WiredDisabled: { + QList> tips; + tips << QPair({ tr("Device disabled"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::Unknown: + case PluginState::Nocable: { + QList> tips; + tips << QPair({ tr("Network cable unplugged"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::Disconnected: + case PluginState::WirelessDisconnected: + case PluginState::WiredDisconnected: { + QList> tips; + tips << QPair({ tr("Not connected"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::Connecting: + case PluginState::WirelessConnecting: + case PluginState::WiredConnecting: { + QList> tips; + tips << QPair({ tr("Connecting"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::ConnectNoInternet: + case PluginState::WirelessConnectNoInternet: + case PluginState::WiredConnectNoInternet: { + QList> tips; + tips << QPair({ tr("Connected but no Internet access"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::Failed: + case PluginState::WirelessFailed: + case PluginState::WiredFailed: { + QList> tips; + tips << QPair({ tr("Connection failed"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + case PluginState::WiredIpConflicted: + case PluginState::WirelessIpConflicted: { + QList> tips; + tips << QPair({ tr("IP conflict"), QStringList() }); + m_tipsWidget->setContext(tips); + } + break; + } +} + +QIcon *NetworkPluginHelper::trayIcon() const +{ + return m_trayIcon; +} + +QIcon NetworkPluginHelper::icon(int colorType) const +{ + return QIcon::fromTheme(iconPath(colorType)); +} + +QString NetworkPluginHelper::iconPath(int colorType) const +{ + QString stateString; + QString iconString; + QString localPath = (colorType == DGuiApplicationHelper::ColorType::DarkType ? ":/dark/" : ":/light/"); + + switch (m_pluginState) { + case PluginState::Disabled: + case PluginState::WirelessDisabled: + stateString = "disabled"; + iconString = QString("wireless-%1-symbolic").arg(stateString); + break; + case PluginState::WiredDisabled: + stateString = "disabled"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + case PluginState::Connected: + case PluginState::WirelessConnected: { + bool isWlan6 = false; + AccessPoints *activeAp = getStrongestAp(); + if (activeAp) { + isWlan6 = (activeAp->type() == AccessPoints::WlanType::wlan6); + } + + stateString = getStrengthStateString(activeAp ? activeAp->strength() : 0); + if (isWlan6) { + iconString = QString("wireless6-%1-symbolic").arg(stateString); + } else { + iconString = QString("wireless-%1-symbolic").arg(stateString); + } + } + break; + case PluginState::WiredConnected: + stateString = "online"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + case PluginState::Disconnected: + case PluginState::WirelessDisconnected: + stateString = "0"; + iconString = QString("wireless-%1-symbolic").arg(stateString); + break; + case PluginState::WiredDisconnected: + stateString = "none"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + case PluginState::Connecting: { + if (QTime::currentTime().second() & 2) { + stateString = getStrengthStateString(QTime::currentTime().msec() / 10 % 100); + iconString = QString("wireless-%1-symbolic").arg(stateString); + } else { + const int index = QTime::currentTime().msec() / 200 % 10; + const int num = index + 1; + iconString = QString("network-wired-symbolic-connecting%1").arg(num); + } + break; + } + case PluginState::WirelessConnecting: { + stateString = getStrengthStateString(QTime::currentTime().msec() / 10 % 100); + iconString = QString("wireless-%1-symbolic").arg(stateString); + break; + } + case PluginState::WiredConnecting: { + const int index = QTime::currentTime().msec() / 200 % 10; + const int num = index + 1; + iconString = QString("network-wired-symbolic-connecting%1").arg(num); + break; + } + case PluginState::ConnectNoInternet: + case PluginState::WirelessConnectNoInternet: { + // 无线已连接但无法访问互联网 offline + bool isWlan6 = false; + AccessPoints *connectedAp = getConnectedAp(); + if (connectedAp) { + isWlan6 = (connectedAp->type() == AccessPoints::WlanType::wlan6); + } + + stateString = "offline"; + if (isWlan6) { + iconString = QString("wireless6-%1-symbolic").arg(stateString); + } else { + iconString = QString("wireless-%1-symbolic").arg(stateString); + } + break; + } + case PluginState::WiredConnectNoInternet: { + stateString = "warning"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + } + case PluginState::WiredFailed: { + // 有线连接失败none变为offline + stateString = "offline"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + } + case PluginState::Unknown: + case PluginState::Nocable: { + stateString = "error"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + } + case PluginState::WirelessIpConflicted: { + stateString = "offline"; + iconString = QString("wireless-%1-symbolic").arg(stateString); + break; + } + case PluginState::WiredIpConflicted: { + stateString = "offline"; + iconString = QString("network-%1-symbolic").arg(stateString); + break; + } + case PluginState::WirelessFailed: + case PluginState::Failed: { + // 无线连接失败改为 disconnect + stateString = "disconnect"; + iconString = QString("wireless-%1").arg(stateString); + break; + } + } + return localPath + iconString; +} + +void NetworkPluginHelper::refreshIcon() +{ + int colorType = m_isDarkIcon ? DGuiApplicationHelper::ColorType::DarkType : DGuiApplicationHelper::ColorType::LightType; + (*m_trayIcon) = icon(colorType); + emit iconChanged(); +} + +void NetworkPluginHelper::setIconDark(bool isDark) +{ + m_isDarkIcon = isDark; +} + +int NetworkPluginHelper::deviceCount(const DeviceType &devType) const +{ + // 获取指定的设备类型的设备数量 + int count = 0; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *dev : devices) + if (dev->deviceType() == static_cast(devType)) + count++; + + return count; +} + +void NetworkPluginHelper::onDeviceAdded(QList devices) +{ + // 处理新增设备的信号 + for (NetworkDeviceBase *device : devices) { + // 当网卡连接状态发生变化的时候重新绘制任务栏的图标 + connect(device, &NetworkDeviceBase::deviceStatusChanged, this, &NetworkPluginHelper::onUpdatePlugView); + + emit addDevice(device->path()); + switch (device->deviceType()) { + case DeviceType::Wired: { + WiredDevice *wiredDevice = static_cast(device); + + connect(wiredDevice, &WiredDevice::connectionAdded, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::connectionRemoved, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::connectionPropertyChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::enableChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &NetworkDeviceBase::connectionChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wiredDevice, &WiredDevice::activeConnectionChanged, this, &NetworkPluginHelper::onUpdatePlugView); + } break; + case DeviceType::Wireless: { + WirelessDevice *wirelessDevice = static_cast(device); + + connect(wirelessDevice, &WirelessDevice::networkAdded, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::networkAdded, this, &NetworkPluginHelper::onAccessPointsAdded); + connect(wirelessDevice, &WirelessDevice::networkRemoved, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::enableChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::connectionChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::hotspotEnableChanged, this, &NetworkPluginHelper::onUpdatePlugView); + connect(wirelessDevice, &WirelessDevice::activeConnectionChanged, this, &NetworkPluginHelper::onActiveConnectionChanged); + + wirelessDevice->scanNetwork(); + } break; + default: + break; + } + } + + onUpdatePlugView(); +} + +void NetworkPluginHelper::invokeMenuItem(const QString &menuId) +{ + switch (menuId.toInt()) { + case MenuItemKey::MenuEnable: + setDeviceEnabled(DeviceType::Wired, true); + if (wirelessIsActive()) + setDeviceEnabled(DeviceType::Wireless, true); + break; + case MenuItemKey::MenuDisable: + setDeviceEnabled(DeviceType::Wired, false); + if (wirelessIsActive()) + setDeviceEnabled(DeviceType::Wireless, false); + break; + case MenuItemKey::MenuWiredEnable: + setDeviceEnabled(DeviceType::Wired, true); + break; + case MenuItemKey::MenuWiredDisable: + setDeviceEnabled(DeviceType::Wired, false); + break; + case MenuItemKey::MenuWirelessEnable: + if (wirelessIsActive()) + setDeviceEnabled(DeviceType::Wireless, true); + break; + case MenuItemKey::MenuWirelessDisable: + if (wirelessIsActive()) + setDeviceEnabled(DeviceType::Wireless, false); + break; + case MenuItemKey::MenuSettings: + NetworkDBusProxy::ShowPage("network"); + break; + default: + break; + } +} + +bool NetworkPluginHelper::needShowControlCenter() +{ + QList devices = NetworkController::instance()->devices(); + // 如果没有网络设备,则直接唤起控制中心 + if (devices.size() == 0) + return true; + + for (NetworkDeviceBase *device : devices) { + if (!device->isEnabled()) + continue; + + if (device->deviceType() == DeviceType::Wired) { + WiredDevice *wiredDevice = static_cast(device); + // 只要有一个有线网卡存在连接列表,就让其弹出网络列表 + if (!wiredDevice->items().isEmpty()) + return false; + } else if (device->deviceType() == DeviceType::Wireless) { + WirelessDevice *wirelessDevice = static_cast(device); + if (!wirelessDevice->accessPointItems().isEmpty()) + return false; + } + } + + return true; +} + +bool NetworkPluginHelper::deviceEnabled(const DeviceType &deviceType) const +{ + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) + if (device->deviceType() == deviceType && device->isEnabled()) + return true; + + return false; +} + +void NetworkPluginHelper::setDeviceEnabled(const DeviceType &deviceType, bool enabeld) +{ + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) + if (device->deviceType() == deviceType) + device->setEnabled(enabeld); +} + +bool NetworkPluginHelper::wirelessIsActive() const +{ + dde::network::NetworkDBusProxy *networkInter = new dde::network::NetworkDBusProxy(); + networkInter->deleteLater(); + return !networkInter->enabled(); +} + +QString NetworkPluginHelper::getStrengthStateString(int strength) const +{ + if (5 >= strength) + return "0"; + + if (30 >= strength) + return "20"; + + if (55 >= strength) + return "40"; + + if (65 >= strength) + return "60"; + + return "80"; +} + +AccessPoints *NetworkPluginHelper::getStrongestAp() const +{ + AccessPoints *maxAps = nullptr; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != DeviceType::Wireless) + continue; + + WirelessDevice *dev = static_cast(device); + AccessPoints *ap = dev->activeAccessPoints(); + if (ap && (!maxAps || maxAps->strength() < ap->strength())) + maxAps = ap; + } + + return maxAps; +} + +AccessPoints *NetworkPluginHelper::getConnectedAp() const +{ + AccessPoints *connectedAp = nullptr; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != DeviceType::Wireless) + continue; + + WirelessDevice *dev = static_cast(device); + AccessPoints *ap = dev->activeAccessPoints(); + if (ap && ap->connected() && (!connectedAp || connectedAp->strength() < ap->strength())) + connectedAp = ap; + } + + return connectedAp; +} + +const QString NetworkPluginHelper::contextMenu(bool hasSetting) const +{ + int wiredCount = deviceCount(DeviceType::Wired); + int wirelessCount = deviceCount(DeviceType::Wireless); + bool wiredEnabled = deviceEnabled(DeviceType::Wired); + bool wirelessEnabeld = deviceEnabled(DeviceType::Wireless); + QList items; + if (wiredCount && wirelessCount) { + items.reserve(3); + QMap wireEnable; + if (wiredEnabled) { + wireEnable["itemId"] = QString::number(MenuWiredDisable); + wireEnable["itemText"] = tr("Disable wired connection"); + } else { + wireEnable["itemId"] = QString::number(MenuWiredEnable); + wireEnable["itemText"] = tr("Enable wired connection"); + } + + wireEnable["isActive"] = true; + items.push_back(wireEnable); + + QMap wirelessEnable; + if (wirelessEnabeld) { + wirelessEnable["itemText"] = tr("Disable wireless connection"); + wirelessEnable["itemId"] = QString::number(MenuWirelessDisable); + } else { + wirelessEnable["itemText"] = tr("Enable wireless connection"); + wirelessEnable["itemId"] = QString::number(MenuWirelessEnable); + } + + wirelessEnable["isActive"] = wirelessIsActive(); + items.push_back(wirelessEnable); + } else if (wiredCount || wirelessCount) { + items.reserve(2); + QMap enable; + if (wiredEnabled || wirelessEnabeld) { + enable["itemId"] = QString::number(MenuDisable); + enable["itemText"] = tr("Disable network"); + } else { + enable["itemId"] = QString::number(MenuEnable); + enable["itemText"] = tr("Enable network"); + } + + enable["isActive"] = (wirelessCount > 0 ? wirelessIsActive() : true); + items.push_back(enable); + } + if (hasSetting) { + QMap settings; + settings["itemId"] = QString::number(MenuSettings); + settings["itemText"] = tr("Network settings"); + settings["isActive"] = true; + items.push_back(settings); + } + QMap menu; + menu["items"] = items; + menu["checkableMenu"] = false; + menu["singleCheck"] = false; + + return QJsonDocument::fromVariant(menu).toJson(); +} + +QWidget *NetworkPluginHelper::itemTips() +{ + return m_tipsWidget->height() == 0 ? nullptr : m_tipsWidget; +} + +void NetworkPluginHelper::onUpdatePlugView() +{ + updatePluginState(); + updateTooltips(); + refreshIcon(); + emit viewUpdate(); +} + +void NetworkPluginHelper::onActiveConnectionChanged() +{ + WirelessDevice *wireless = static_cast(sender()); + DeviceStatus status = wireless->deviceStatus(); + if (status == DeviceStatus::Disconnected + || status == DeviceStatus::Deactivation) + return; + + QString wirelessPath = wireless->path(); + for (auto conn : NetworkManager::activeConnections()) { + if (!conn->id().isEmpty() && conn->devices().contains(wirelessPath)) { + NetworkManager::ConnectionSettings::Ptr connSettings = conn->connection()->settings(); + NetworkManager::WirelessSetting::Ptr wSetting = connSettings->setting(NetworkManager::Setting::SettingType::Wireless).staticCast(); + if (wSetting.isNull()) + continue; + + const QString settingMacAddress = wSetting->macAddress().toHex().toUpper(); + const QString deviceMacAddress = wireless->realHwAdr().remove(":"); + if (!settingMacAddress.isEmpty() && settingMacAddress != deviceMacAddress) + continue; + + // 隐藏网络配置错误时提示重连 + if (wSetting && wSetting->hidden()) { + NetworkManager::WirelessSecuritySetting::Ptr wsSetting = connSettings->setting(NetworkManager::Setting::SettingType::WirelessSecurity).staticCast(); + if (wsSetting && NetworkManager::WirelessSecuritySetting::KeyMgmt::Unknown == wsSetting->keyMgmt()) { + for (auto ap : wireless->accessPointItems()) { + if (ap->ssid() == wSetting->ssid() && ap->secured() && ap->strength() > 0) { + // 隐藏网络逻辑是要输入密码重连,所以后端无等待,前端重连 + m_networkDialog->setConnectWireless(wireless->path(), ap->ssid(), false); + break; + } + } + } + } + } + } + + onUpdatePlugView(); +} + +bool NetworkPluginHelper::needSetPassword(AccessPoints *accessPoint) const +{ + // 如果当前热点不是隐藏热点,或者当前热点不是加密热点,则需要设置密码(因为这个函数只是处理隐藏且加密的热点) + if (!accessPoint->hidden() || !accessPoint->secured()) + return false; + + WirelessDevice *wirelessDevice = nullptr; + QList devices = NetworkController::instance()->devices(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() == DeviceType::Wireless && device->path() == accessPoint->devicePath()) { + wirelessDevice = static_cast(device); + break; + } + } + + // 如果连这个连接的设备都找不到,则无需设置密码 + if (!wirelessDevice) + return false; + + // 查找该热点对应的连接的UUID + NetworkManager::Connection::Ptr connection; + NetworkManager::WirelessDevice::Ptr device(new NetworkManager::WirelessDevice(wirelessDevice->path())); + NetworkManager::Connection::List connectionlist = device->availableConnections(); + for (NetworkManager::Connection::Ptr conn : connectionlist) { + NetworkManager::WirelessSetting::Ptr wSetting = conn->settings()->setting(NetworkManager::Setting::SettingType::Wireless).staticCast(); + if (wSetting.isNull()) + continue; + + if (wSetting->ssid() != accessPoint->ssid()) + continue; + + connection = conn; + break; + } + + if (connection.isNull()) + return true; + + // 查找该连接对应的密码配置信息 + NetworkManager::ConnectionSettings::Ptr settings = connection->settings(); + if (settings.isNull()) + return true; + + NetworkManager::WirelessSecuritySetting::Ptr securitySetting = + settings->setting(NetworkManager::Setting::SettingType::WirelessSecurity).staticCast(); + + NetworkManager::WirelessSecuritySetting::KeyMgmt keyMgmt = securitySetting->keyMgmt(); + if (keyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaNone || keyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::Unknown) + return true; + + NetworkManager::Setting::SettingType sType = NetworkManager::Setting::SettingType::WirelessSecurity; + if (keyMgmt == NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaEap) + sType = NetworkManager::Setting::SettingType::Security8021x; + + QDBusPendingReply reply; + reply = connection->secrets(settings->setting(sType)->name()); + + reply.waitForFinished(); + if (reply.isError() || !reply.isValid()) + return true; + + NMVariantMapMap sSecretsMapMap = reply.value(); + QSharedPointer setting = settings->setting(sType).staticCast(); + setting->secretsFromMap(sSecretsMapMap.value(setting->name())); + + if (securitySetting.isNull()) + return true; + + QString psk; + switch (keyMgmt) { + case NetworkManager::WirelessSecuritySetting::KeyMgmt::Wep: + psk = securitySetting->wepKey0(); + break; + case NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaPsk: + default: + psk = securitySetting->psk(); + break; + } + + // 如果该密码存在,则无需调用设置密码信息 + return psk.isEmpty(); +} + +void NetworkPluginHelper::handleAccessPointSecure(AccessPoints *accessPoint) +{ + if (needSetPassword(accessPoint)) + m_networkDialog->setConnectWireless(accessPoint->devicePath(), accessPoint->ssid()); +} + +void NetworkPluginHelper::onAccessPointsAdded(QList newAps) +{ + for (AccessPoints *newAp : newAps) { + connect(newAp, &AccessPoints::securedChanged, this, [ this, newAp ] { + handleAccessPointSecure(newAp); + }); + handleAccessPointSecure(newAp); + } +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.h new file mode 100644 index 000000000..86bd176e1 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/networkpluginhelper.h @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKPLUGINHELPER_H +#define NETWORKPLUGINHELPER_H +#include "utils.h" +#include "item/devicestatushandler.h" + +#include + +#include + + +DGUI_USE_NAMESPACE + +namespace dde { +namespace network { +enum class DeviceType; +class NetworkDeviceBase; +class AccessPoints; +} // namespace network +} // namespace dde + +class QTimer; +class NetItem; + +namespace dde { +namespace networkplugin { + +class NetworkDialog; +class TipsWidget; + +class NetworkPluginHelper : public QObject +{ + Q_OBJECT + +public: + enum MenuItemKey : int { + MenuSettings = 1, + MenuEnable, + MenuDisable, + MenuWiredEnable, + MenuWiredDisable, + MenuWirelessEnable, + MenuWirelessDisable, + }; + +Q_SIGNALS: + void sendIpConflictDect(int); + void addDevice(const QString &devicePath); + void viewUpdate(); + void iconChanged(); + +public: + explicit NetworkPluginHelper(NetworkDialog *networkDialog, QObject *parent = Q_NULLPTR); + ~NetworkPluginHelper(); + + void invokeMenuItem(const QString &menuId); + bool needShowControlCenter(); + const QString contextMenu(bool hasSetting) const; + QWidget *itemTips(); + PluginState getPluginState(); + void updatePluginState(); + void updateTooltips(); // 更新提示的内容 + + QIcon *trayIcon() const; + QIcon icon(int colorType) const; + QString iconPath(int colorType) const; + void refreshIcon(); + void setIconDark(bool isDark); + +private: + void initUi(); + void initConnection(); + bool deviceEnabled(const DeviceType &deviceType) const; + void setDeviceEnabled(const DeviceType &deviceType, bool enabeld); + bool wirelessIsActive() const; + QString getStrengthStateString(int strength) const; + dde::network::AccessPoints *getStrongestAp() const; + dde::network::AccessPoints *getConnectedAp() const; + + void handleAccessPointSecure(AccessPoints *accessPoint); + + int deviceCount(const DeviceType &devType) const; + QList> ipTipsMessage(const DeviceType &devType); + bool needSetPassword(AccessPoints *accessPoint) const; + +private Q_SLOTS: + void onDeviceAdded(QList devices); + void onUpdatePlugView(); + void onActiveConnectionChanged(); + + void onAccessPointsAdded(QList newAps); + +private: + PluginState m_pluginState; + + TipsWidget *m_tipsWidget; + bool m_switchWire; + QPixmap m_iconPixmap; + + QSet m_devicePaths; // 记录无线设备Path,防止信号重复连接 + QString m_lastActiveWirelessDevicePath; + NetworkDialog *m_networkDialog; + QIcon *m_trayIcon; + QTimer *m_refreshIconTimer; + bool m_isDarkIcon; // 是深色主题 +}; +} +} + +#endif // NETWORKPLUGINHELPER_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/plugin_global.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/plugin_global.h new file mode 100644 index 000000000..c04199596 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/plugin_global.h @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef PLUGIN_GLOBAL_H +#define PLUGIN_GLOBAL_H + +#define NETWORKPLUGIN_BEGIN_NAMESPACE namespace dde { namespace networkplugin { +#define NETWORKPLUGIN_END_NAMESPACE }} +#define NETWORKPLUGIN_USE_NAMESPACE using namespace dde::networkplugin; +#define NETWORKPLUGIN_NAMESPACE dde::networkplugin + + +#endif diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select.png b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select.png new file mode 100644 index 000000000..886736105 Binary files /dev/null and b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select.png differ diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select@2x.png b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select@2x.png new file mode 100644 index 000000000..a04e6e4d5 Binary files /dev/null and b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/list_select@2x.png differ diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press.png b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press.png new file mode 100644 index 000000000..d6dbc2124 Binary files /dev/null and b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press.png differ diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press@2x.png b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press@2x.png new file mode 100644 index 000000000..7d67765b4 Binary files /dev/null and b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/common/notify_close_press@2x.png differ diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/disconnect.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/disconnect.svg new file mode 100644 index 000000000..f18f360a1 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/disconnect.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-disabled-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-disabled-symbolic.svg new file mode 100644 index 000000000..0588d0f06 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-disabled-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-error-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-error-symbolic.svg new file mode 100644 index 000000000..0e5ec862f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-error-symbolic.svg @@ -0,0 +1,8 @@ + + + network-error-unknown + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-none-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-none-symbolic.svg new file mode 100644 index 000000000..2f0b286bc --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-none-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-offline-symbolic.svg new file mode 100644 index 000000000..6e9cd759c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-offline-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-online-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-online-symbolic.svg new file mode 100644 index 000000000..b014c7e22 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-online-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-warning-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-warning-symbolic.svg new file mode 100644 index 000000000..258a63b6f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-warning-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting1.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting1.svg new file mode 100644 index 000000000..4df47e0d9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting1.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting1 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting2.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting2.svg new file mode 100644 index 000000000..0dc1af6f3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting2.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting2 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting3.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting3.svg new file mode 100644 index 000000000..4c6ce3716 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting3.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting3 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting4.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting4.svg new file mode 100644 index 000000000..487a15eb7 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting4.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting4 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting5.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting5.svg new file mode 100644 index 000000000..1f76ba5ce --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic-connecting5.svg @@ -0,0 +1,13 @@ + + + + network-wired-symbolic-connecting5 + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic.svg new file mode 100644 index 000000000..b014c7e22 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/network-wired-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/refresh.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/refresh.svg new file mode 100644 index 000000000..5ef071ada --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/refresh.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/security.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/security.svg new file mode 100644 index 000000000..b126160dc --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/security.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/select.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/select.svg new file mode 100644 index 000000000..e1c2b319c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/select.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-0-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-0-symbolic.svg new file mode 100644 index 000000000..e6bebf631 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-0-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-20-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-20-symbolic.svg new file mode 100644 index 000000000..3d4a6e780 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-20-symbolic.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-40-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-40-symbolic.svg new file mode 100644 index 000000000..30669f645 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-40-symbolic.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-60-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-60-symbolic.svg new file mode 100644 index 000000000..0985e6a04 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-60-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-80-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-80-symbolic.svg new file mode 100644 index 000000000..137e21c9f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-80-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-background.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-background.svg new file mode 100644 index 000000000..ba17ed434 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-background.svg @@ -0,0 +1,18 @@ + + + + wireless-background-48px + Created with Sketch. + + + + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disabled-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disabled-symbolic.svg new file mode 100644 index 000000000..670c64c78 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disabled-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect-symbolic.svg new file mode 100644 index 000000000..5a5a0ff5f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect-symbolic.svg @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect.svg new file mode 100644 index 000000000..724b3902a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-disconnect.svg @@ -0,0 +1,14 @@ + + + + wireless-disconnect + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-offline-symbolic.svg new file mode 100644 index 000000000..fbbdf9422 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless-offline-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-0-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-0-symbolic.svg new file mode 100644 index 000000000..d0adcf653 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-0-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-none-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-20-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-20-symbolic.svg new file mode 100644 index 000000000..fb967806d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-20-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-low-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-40-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-40-symbolic.svg new file mode 100644 index 000000000..cabd8198f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-40-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-medium-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-60-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-60-symbolic.svg new file mode 100644 index 000000000..71c88c81a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-60-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-high-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-80-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-80-symbolic.svg new file mode 100644 index 000000000..3a6fa4a68 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-80-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-full-symbolic + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-no-route-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-no-route-symbolic.svg new file mode 100644 index 000000000..db5f2b951 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-no-route-symbolic.svg @@ -0,0 +1,8 @@ + + + network-wirelss-6-no-route-symbolic + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-offline-symbolic.svg new file mode 100644 index 000000000..3e6526b35 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-offline-symbolic.svg @@ -0,0 +1,11 @@ + + + network-wireless-6-offline-symbolic + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-warning-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-warning-symbolic.svg new file mode 100644 index 000000000..7945aceec --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/dark/wireless6-warning-symbolic.svg @@ -0,0 +1,11 @@ + + + network-wireless-6-warning-symbolic + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/disconnect.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/disconnect.svg new file mode 100644 index 000000000..cf2971327 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/disconnect.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-disabled-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-disabled-symbolic.svg new file mode 100644 index 000000000..d6d5fc20d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-disabled-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-error-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-error-symbolic.svg new file mode 100644 index 000000000..aa96bd677 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-error-symbolic.svg @@ -0,0 +1,8 @@ + + + network-error-unknown-dark + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-none-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-none-symbolic.svg new file mode 100644 index 000000000..9e0bc5e31 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-none-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-offline-symbolic.svg new file mode 100644 index 000000000..f0fd47362 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-offline-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-online-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-online-symbolic.svg new file mode 100644 index 000000000..50d901c62 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-online-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-warning-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-warning-symbolic.svg new file mode 100644 index 000000000..ebd1e11d3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-warning-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting1.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting1.svg new file mode 100644 index 000000000..e3127d2fd --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting1.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting2.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting2.svg new file mode 100644 index 000000000..46534627a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting2.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting3.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting3.svg new file mode 100644 index 000000000..5efbbc6d9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting3.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting4.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting4.svg new file mode 100644 index 000000000..a1d03e412 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting4.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting5.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting5.svg new file mode 100644 index 000000000..9247612c1 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic-connecting5.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic.svg new file mode 100644 index 000000000..50d901c62 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/network-wired-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/refresh.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/refresh.svg new file mode 100644 index 000000000..dc2950711 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/refresh.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/security.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/security.svg new file mode 100644 index 000000000..6301d47de --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/security.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/select.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/select.svg new file mode 100644 index 000000000..4071c706a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/select.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-0-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-0-symbolic.svg new file mode 100644 index 000000000..d5babcbee --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-0-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-20-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-20-symbolic.svg new file mode 100644 index 000000000..5ffe56aab --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-20-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-40-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-40-symbolic.svg new file mode 100644 index 000000000..d6f6c012e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-40-symbolic.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-60-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-60-symbolic.svg new file mode 100644 index 000000000..2b3dc7c92 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-60-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-80-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-80-symbolic.svg new file mode 100644 index 000000000..20bcbc2fc --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-80-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-background.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-background.svg new file mode 100644 index 000000000..ba17ed434 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-background.svg @@ -0,0 +1,18 @@ + + + + wireless-background-48px + Created with Sketch. + + + + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disabled-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disabled-symbolic.svg new file mode 100644 index 000000000..cf5fdd82a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disabled-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect-symbolic.svg new file mode 100644 index 000000000..ec80d3197 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect-symbolic.svg @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect.svg new file mode 100644 index 000000000..ac0e27b67 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-disconnect.svg @@ -0,0 +1,14 @@ + + + + wireless-disconnect + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-offline-symbolic.svg new file mode 100644 index 000000000..3c35a9ae9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless-offline-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-0-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-0-symbolic.svg new file mode 100644 index 000000000..43f6b9aff --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-0-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-none-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-20-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-20-symbolic.svg new file mode 100644 index 000000000..c097f8882 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-20-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-low-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-40-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-40-symbolic.svg new file mode 100644 index 000000000..fde3f1e27 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-40-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-medium-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-60-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-60-symbolic.svg new file mode 100644 index 000000000..0a0c0a251 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-60-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-high-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-80-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-80-symbolic.svg new file mode 100644 index 000000000..3eae7b0a9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-80-symbolic.svg @@ -0,0 +1,13 @@ + + + network-wireless-6-signal-full-symbolic-dark + + + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-no-route-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-no-route-symbolic.svg new file mode 100644 index 000000000..f1e5dbc03 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-no-route-symbolic.svg @@ -0,0 +1,8 @@ + + + network-wirelss-6-no-route-symbolic-dark + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-offline-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-offline-symbolic.svg new file mode 100644 index 000000000..ac90da349 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-offline-symbolic.svg @@ -0,0 +1,11 @@ + + + network-wireless-6-offline-symbolic-dark + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-warning-symbolic.svg b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-warning-symbolic.svg new file mode 100644 index 000000000..7173ff96e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/resources/light/wireless6-warning-symbolic.svg @@ -0,0 +1,11 @@ + + + network-wireless-6-warning-symbolic-dark + + + + + + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.cpp new file mode 100644 index 000000000..575fdc457 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.cpp @@ -0,0 +1,330 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "secretagent.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_PRINT qDebug() << __FILE__ << "line:" << __LINE__ << "function:" << __FUNCTION__ << "Message:" + +NETWORKPLUGIN_USE_NAMESPACE + +SecretAgent::SecretAgent(bool greeter, QObject *parent) + : NetworkManager::SecretAgent(QStringLiteral("com.deepin.system.network.SecretAgent"), parent) +{ + m_greeter = greeter; + qInfo() << "register secret agent: com.deepin.system.network.SecretAgent mode: " << (m_greeter ? "greeter" : "lock"); + + qDBusRegisterMetaType(); +} + +SecretAgent::~SecretAgent() = default; + +NMVariantMapMap SecretAgent::GetSecrets(const NMVariantMapMap &connection, + const QDBusObjectPath &connection_path, + const QString &setting_name, + const QStringList &hints, + uint flags) +{ + DEBUG_PRINT << "Path:" << connection_path.path(); + DEBUG_PRINT << "Setting name:" << setting_name; + DEBUG_PRINT << "Hints:" << hints; + DEBUG_PRINT << "Flags:" << flags; + + const QString callId = connection_path.path() % setting_name; + for (const SecretsRequest &request : m_calls) { + if (request == callId) { + qWarning() << "GetSecrets was called again! This should not happen, cancelling first call" << connection_path.path() + << setting_name; + CancelGetSecrets(connection_path, setting_name); + break; + } + } + + setDelayedReply(true); + SecretsRequest request(SecretsRequest::GetSecrets); + request.callId = callId; + request.connection = connection; + request.connection_path = connection_path; + request.flags = static_cast(flags); + request.hints = hints; + request.setting_name = setting_name; + request.message = message(); + m_calls << request; + + processNext(); + + return {}; +} + +void SecretAgent::SaveSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) +{ + setDelayedReply(true); + SecretsRequest::Type type; + if (hasSecrets(connection)) { + type = SecretsRequest::SaveSecrets; + } else { + type = SecretsRequest::DeleteSecrets; + } + SecretsRequest request(type); + request.connection = connection; + request.connection_path = connection_path; + request.message = message(); + m_calls << request; + + processNext(); +} + +void SecretAgent::DeleteSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) +{ + setDelayedReply(true); + SecretsRequest request(SecretsRequest::DeleteSecrets); + request.connection = connection; + request.connection_path = connection_path; + request.message = message(); + m_calls << request; + + processNext(); +} + +void SecretAgent::CancelGetSecrets(const QDBusObjectPath &connection_path, const QString &setting_name) +{ + QString callId = connection_path.path() % setting_name; + for (int i = 0; i < m_calls.size(); ++i) { + SecretsRequest request = m_calls.at(i); + if (request.type == SecretsRequest::GetSecrets && callId == request.callId) { + if (m_ssid == request.ssid) { + DEBUG_PRINT << "process finished (agent canceled)"; + m_ssid.clear(); + } + sendError(SecretAgent::AgentCanceled, QStringLiteral("Agent canceled the password dialog"), request.message); + m_calls.removeAt(i); + break; + } + } + + processNext(); +} + +void SecretAgent::onInputPassword(const QString &key, const QString &password, bool input) +{ + for (int i = 0; i < m_calls.size(); ++i) { + SecretsRequest &request = m_calls[i]; + if (request.type == SecretsRequest::GetSecrets && request.ssid == key) { + if (input) { + QJsonObject resultJsonObj; + QJsonArray secretsJsonArray; + secretsJsonArray.append(password); + resultJsonObj.insert("secrets", secretsJsonArray); + + NetworkManager::ConnectionSettings::Ptr connectionSettings = + NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(request.connection)); + NetworkManager::Setting::Ptr setting = connectionSettings->setting(request.setting_name); + auto needSecrets = setting->needSecrets(request.flags & RequestNew); + if (!password.isEmpty() && !needSecrets.isEmpty()) { + QVariantMap result; + result.insert(needSecrets.first(), password); + request.connection[request.setting_name] = result; + sendSecrets(request.connection, request.message); + } + } else { + sendError(SecretAgent::UserCanceled, QStringLiteral("user canceled"), request.message); + } + } + } +} + +void SecretAgent::processNext() +{ + int i = 0; + while (i < m_calls.size()) { + SecretsRequest &request = m_calls[i]; + switch (request.type) { + case SecretsRequest::GetSecrets: + if (processGetSecrets(request)) { + m_calls.removeAt(i); + continue; + } + break; + case SecretsRequest::SaveSecrets: + if (processSaveSecrets(request)) { + m_calls.removeAt(i); + continue; + } + break; + case SecretsRequest::DeleteSecrets: + if (processDeleteSecrets(request)) { + m_calls.removeAt(i); + continue; + } + break; + } + ++i; + } +} + +bool SecretAgent::processGetSecrets(SecretsRequest &request) +{ + if (!m_ssid.isEmpty()) { + return false; + } + + NetworkManager::ConnectionSettings::Ptr connectionSettings = + NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(request.connection)); + NetworkManager::Setting::Ptr setting = connectionSettings->setting(request.setting_name); + + const bool requestNew = request.flags & RequestNew; + const bool userRequested = request.flags & UserRequested; + const bool allowInteraction = request.flags & AllowInteraction; + const bool isVpn = (setting->type() == NetworkManager::Setting::Vpn); + + if (isVpn) { + NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); + if (vpnSetting->serviceType() == QLatin1String("org.freedesktop.NetworkManager.ssh") && vpnSetting->data()["auth-type"] == QLatin1String("ssh-agent")) { + QString authSock = qgetenv("SSH_AUTH_SOCK"); + qDebug() << Q_FUNC_INFO << "Sending SSH auth socket" << authSock; + + if (authSock.isEmpty()) { + sendError(SecretAgent::NoSecrets, QStringLiteral("SSH_AUTH_SOCK not present"), request.message); + } else { + NMStringMap secrets; + secrets.insert(QStringLiteral("ssh-auth-sock"), authSock); + + QVariantMap secretData; + secretData.insert(QStringLiteral("secrets"), QVariant::fromValue(secrets)); + request.connection[request.setting_name] = secretData; + sendSecrets(request.connection, request.message); + } + return true; + } + } + + if (!m_greeter) { + if (!requestNew) { + // 需要去解锁密码环,取密码 + return false; + } + + NMStringMap secretsMap; + setting->secretsFromStringMap(secretsMap); + if (!(isVpn) && setting->needSecrets(requestNew).isEmpty()) { + // Enough secrets were retrieved from storage + request.connection[request.setting_name] = setting->secretsToMap(); + sendSecrets(request.connection, request.message); + return true; + } + } + + if (requestNew || (allowInteraction && !setting->needSecrets(requestNew).isEmpty()) || (allowInteraction && userRequested) + || (isVpn && allowInteraction)) { + DEBUG_PRINT << "process request secrets"; + + // 只处理无线的 + if (connectionSettings->connectionType() != NetworkManager::ConnectionSettings::Wireless) { + sendError(SecretAgent::InternalError, QStringLiteral("dss can only handle wireless"), request.message); + return true; + } + + if (!userRequested) { + sendError(SecretAgent::AgentCanceled, QStringLiteral("dss only support user quest"), request.message); + return true; + } + + QString devPath; + NetworkManager::ActiveConnection::List actives = NetworkManager::activeConnections(); + for (auto it = actives.begin(); it != actives.end(); ++it) { + if ((*it)->connection()->path() == request.connection_path.path()) { + devPath = (*it)->devices().first(); + break; + } + } + m_ssid = connectionSettings->id(); + request.ssid = m_ssid; + DEBUG_PRINT << "requestPassword" << devPath << connectionSettings->id(); + Q_EMIT requestPassword(devPath, connectionSettings->id(), true); + return false; + } else if (isVpn && userRequested) { // just return what we have + NMVariantMapMap result; + NetworkManager::VpnSetting::Ptr vpnSetting; + vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); + // FIXME workaround when NM is asking for secrets which should be system-stored, if we send an empty map it + // won't ask for additional secrets with AllowInteraction flag which would display the authentication dialog + if (vpnSetting->secretsToMap().isEmpty()) { + // Insert an empty secrets map as it was before I fixed it in NetworkManagerQt to make sure NM will ask again + // with flags we need + QVariantMap secretsMap; + secretsMap.insert(QStringLiteral("secrets"), QVariant::fromValue(NMStringMap())); + result.insert(QStringLiteral("vpn"), secretsMap); + } else { + result.insert(QStringLiteral("vpn"), vpnSetting->secretsToMap()); + } + sendSecrets(result, request.message); + return true; + } else if (setting->needSecrets().isEmpty()) { + NMVariantMapMap result; + result.insert(setting->name(), setting->secretsToMap()); + sendSecrets(result, request.message); + return true; + } else { + sendError(SecretAgent::InternalError, QStringLiteral("dss did not know how to handle the request"), request.message); + return true; + } +} + +bool SecretAgent::processSaveSecrets(SecretsRequest &request) const +{ + if (!request.saveSecretsWithoutReply) { + QDBusMessage reply = request.message.createReply(); + if (!QDBusConnection::systemBus().send(reply)) { + qWarning() << "Failed put save secrets reply into the queue"; + } + } + + return true; +} + +bool SecretAgent::processDeleteSecrets(SecretsRequest &request) const +{ + QDBusMessage reply = request.message.createReply(); + if (!QDBusConnection::systemBus().send(reply)) { + qWarning() << "Failed put delete secrets reply into the queue"; + } + + return true; +} + +bool SecretAgent::hasSecrets(const NMVariantMapMap &connection) const +{ + NetworkManager::ConnectionSettings connectionSettings(connection); + for (const NetworkManager::Setting::Ptr &setting : connectionSettings.settings()) { + if (!setting->secretsToMap().isEmpty()) { + return true; + } + } + + return false; +} + +void SecretAgent::sendSecrets(const NMVariantMapMap &secrets, const QDBusMessage &message) const +{ + QDBusMessage reply; + reply = message.createReply(QVariant::fromValue(secrets)); + if (!QDBusConnection::systemBus().send(reply)) { + qWarning() << "Failed put the secret into the queue"; + } +} + diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.h new file mode 100644 index 000000000..53bde3f9f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/secretagent.h @@ -0,0 +1,100 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef SECRETAGENT_H +#define SECRETAGENT_H + +#include "utils.h" + +#include + +NETWORKPLUGIN_BEGIN_NAMESPACE + +class SecretsRequest +{ +public: + enum Type { + GetSecrets, + SaveSecrets, + DeleteSecrets, + }; + explicit SecretsRequest(Type _type) + : type(_type) + , flags(NetworkManager::SecretAgent::None) + , saveSecretsWithoutReply(false) + { + } + inline bool operator==(const QString &other) const + { + return callId == other; + } + Type type; + QString callId; + NMVariantMapMap connection; + QDBusObjectPath connection_path; + QString setting_name; + QStringList hints; + NetworkManager::SecretAgent::GetSecretsFlags flags; + /** + * When a user connection is called on GetSecrets, + * the secret agent is supposed to save the secrets + * typed by user, when true proccessSaveSecrets + * should skip the DBus reply. + */ + bool saveSecretsWithoutReply; + QDBusMessage message; + QString ssid; +}; + +class Q_DECL_EXPORT SecretAgent : public NetworkManager::SecretAgent +{ + Q_OBJECT + +public: + explicit SecretAgent(bool greeter = false, QObject *parent = nullptr); + + ~SecretAgent() override; + +Q_SIGNALS: + void secretsError(const QString &connectionPath, const QString &message) const; + void requestPassword(const QString &dev, const QString &ssid, bool wait); + +public Q_SLOTS: + NMVariantMapMap GetSecrets(const NMVariantMapMap &, const QDBusObjectPath &, const QString &, const QStringList &, uint) override; + void SaveSecrets(const NMVariantMapMap &connection, const QDBusObjectPath &connection_path) override; + void DeleteSecrets(const NMVariantMapMap &, const QDBusObjectPath &) override; + void CancelGetSecrets(const QDBusObjectPath &, const QString &) override; + + void onInputPassword(const QString &key, const QString &password, bool input); + +private: + void processNext(); + /** + * @brief processGetSecrets requests + * @param request the request we are processing + * @param ignoreWallet true if the code should avoid Wallet + * normally if it failed to open + * @return true if the item was processed + */ + bool processGetSecrets(SecretsRequest &request); + bool processSaveSecrets(SecretsRequest &request) const; + bool processDeleteSecrets(SecretsRequest &request) const; + + /** + * @brief hasSecrets verifies if the desired connection has secrets to store + * @param connection map with or without secrets + * @return true if the connection has secrets, false otherwise + */ + bool hasSecrets(const NMVariantMapMap &connection) const; + void sendSecrets(const NMVariantMapMap &secrets, const QDBusMessage &message) const; + bool needConnectNetwork(const NMVariantMapMap &connectionMap) const; + + QString m_ssid; + QList m_calls; + bool m_greeter; +}; + +NETWORKPLUGIN_END_NAMESPACE + +#endif // SECRETAGENT_H diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/utils.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/utils.h new file mode 100644 index 000000000..ed2682402 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/utils.h @@ -0,0 +1,199 @@ +// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef UTILS +#define UTILS +#include +#include +#include +#include +#include + +#include "plugin_global.h" + +namespace Utils { + +#define ICBC_CONF_FILE "/etc/deepin/icbc.conf" + +// /** +// * @brief SettingsPtr 根据给定信息返回一个QGSettings指针 +// * @param schema_id The id of the schema +// * @param path If non-empty, specifies the path for a relocatable schema +// * @param parent 创建指针的付对象 +// * @return +// */ +// inline const QGSettings *SettingsPtr(const QString &schema_id, const QByteArray &path = QByteArray(), QObject *parent = nullptr) { +// if (QGSettings::isSchemaInstalled(schema_id.toUtf8())) { +// QGSettings *settings = new QGSettings(schema_id.toUtf8(), path, parent); +// return settings; +// } +// qDebug() << "Cannot find gsettings, schema_id:" << schema_id; +// return nullptr; +// } + +// /** +// * @brief SettingsPtr 根据给定信息返回一个QGSettings指针 +// * @param module 传入QGSettings构造函数时,会添加"com.deepin.dde.dock.module."前缀 +// * @param path If non-empty, specifies the path for a relocatable schema +// * @param parent 创建指针的付对象 +// * @return +// */ +// inline const QGSettings *ModuleSettingsPtr(const QString &module, const QByteArray &path = QByteArray(), QObject *parent = nullptr) { +// return SettingsPtr("com.deepin.dde.dock.module." + module, path, parent); +// } + +/* convert 'some-key' to 'someKey' or 'SomeKey'. + * the second form is needed for appending to 'set' for 'setSomeKey' + */ +inline QString qtify_name(const char *name) +{ + bool next_cap = false; + QString result; + + while (*name) { + if (*name == '-') { + next_cap = true; + } else if (next_cap) { + result.append(QChar(*name).toUpper().toLatin1()); + next_cap = false; + } else { + result.append(*name); + } + + name++; + } + + return result; +} + +/** + * @brief SettingValue 根据给定信息返回获取的值 + * @param schema_id The id of the schema + * @param path If non-empty, specifies the path for a relocatable schema + * @param key 对应信息的key值 + * @param fallback 如果找不到信息,返回此默认值 + * @return + */ +inline const QVariant SettingValue(const QString &schema_id, const QByteArray &path = QByteArray(), const QString &key = QString(), const QVariant &fallback = QVariant()){ + // const QGSettings *settings = SettingsPtr(schema_id, path); + + // if (settings && ((settings->keys().contains(key)) || settings->keys().contains(qtify_name(key.toUtf8().data())))) { + // QVariant v = settings->get(key); + // delete settings; + // return v; + // } else{ + // qDebug() << "Cannot find gsettings, schema_id:" << schema_id + // << " path:" << path << " key:" << key + // << "Use fallback value:" << fallback; + // return fallback; + // } + return fallback; +} + +inline QPixmap renderSVG(const QString &path, const QSize &size, const qreal devicePixelRatio) { + QImageReader reader; + QPixmap pixmap; + reader.setFileName(path); + if (reader.canRead()) { + reader.setScaledSize(size * devicePixelRatio); + pixmap = QPixmap::fromImage(reader.read()); + pixmap.setDevicePixelRatio(devicePixelRatio); + } + else { + pixmap.load(path); + } + + return pixmap; +} + +inline QScreen *screenAt(const QPoint &point) { + for (QScreen *screen : qApp->screens()) { + const QRect r { screen->geometry() }; + const QRect rect { r.topLeft(), r.size() * screen->devicePixelRatio() }; + if (rect.contains(point)) { + return screen; + } + } + + return nullptr; +} + +//!!! 注意:这里传入的QPoint是未计算缩放的 +inline QScreen *screenAtByScaled(const QPoint &point) { + for (QScreen *screen : qApp->screens()) { + const QRect r { screen->geometry() }; + QRect rect { r.topLeft(), r.size() * screen->devicePixelRatio() }; + if (rect.contains(point)) { + return screen; + } + } + + return nullptr; +} + +inline bool isSettingConfigured(const QString& id, const QString& path, const QString& keyName) { + // if (!QGSettings::isSchemaInstalled(id.toUtf8())) { + // return false; + // } + // QGSettings setting(id.toUtf8(), path.toUtf8()); + // QVariant v = setting.get(keyName); + // if (!v.isValid()) { + // return false; + // } + // return v.toBool(); + return false; +} + +/** +* @brief 比较两个插件版本号的大小 +* @param pluginApi1 第一个插件版本号 +* @param pluginApi2 第二个插件版本号 +* @return 0:两个版本号相等,1:第一个版本号大,-1:第二个版本号大 +*/ +inline int comparePluginApi(const QString &pluginApi1, const QString &pluginApi2) { + // 版本号相同 + if (pluginApi1 == pluginApi2) + return 0; + + // 拆分版本号 + QStringList subPluginApis1 = pluginApi1.split(".", Qt::SkipEmptyParts, Qt::CaseSensitive); + QStringList subPluginApis2 = pluginApi2.split(".", Qt::SkipEmptyParts, Qt::CaseSensitive); + for (int i = 0; i < subPluginApis1.size(); ++i) { + auto subPluginApi1 = subPluginApis1[i]; + if (subPluginApis2.size() > i) { + auto subPluginApi2 = subPluginApis2[i]; + + // 相等判断下一个子版本号 + if (subPluginApi1 == subPluginApi2) + continue; + + // 转成整形比较 + if (subPluginApi1.toInt() > subPluginApi2.toInt()) { + return 1; + } else { + return -1; + } + } + } + + // 循环结束但是没有返回,说明子版本号个数不同,且前面的子版本号都相同 + // 子版本号多的版本号大 + if (subPluginApis1.size() > subPluginApis2.size()) { + return 1; + } else { + return -1; + } +} + +/** +* @brief 当前是否处于wayland的环境 +* @return true:是,false:否 +*/ +inline bool isWaylandEnvironment() +{ + return QGuiApplication::platformName().startsWith("wayland", Qt::CaseInsensitive); +} +} + +#endif // UTILS diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.cpp b/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.cpp new file mode 100644 index 000000000..45c7d4a54 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.cpp @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "tipswidget.h" + +#include +#include +#include + +#define MARGIN 10 + +NETWORKPLUGIN_USE_NAMESPACE + +TipsWidget::TipsWidget(QWidget *parent) + : QFrame(parent) +{ +} + +void TipsWidget::setContext(const QList> &textList) +{ + m_textList = textList; + + int width = 0; + int height = 0; + int titleWidth = 0; + for (QPair textPair : m_textList) + titleWidth = qMax(titleWidth, fontMetrics().horizontalAdvance(textPair.first)); + + for (QPair textPair : m_textList) { + QString key = textPair.first; + QStringList values = textPair.second; + if (values.size() > 0) { + for (const QString &value : values) { + QString text = m_spliter + value; + width = qMax(width, fontMetrics().horizontalAdvance(text) + MARGIN * 2); + height += fontMetrics().boundingRect(text).height(); + } + } else { + height += fontMetrics().boundingRect(key).height(); + width = MARGIN * 2; + } + } + + width += titleWidth; + setFixedSize(width, height); + + update(); +} + +void TipsWidget::setSpliter(const QString &spliter) +{ + m_spliter = spliter; +} + +// 计算右侧文字的左侧位置 +int TipsWidget::calcValueX() +{ + int nMaxWidth = 0; + for (QPair textPair : m_textList) { + int nCurrentTextWidth = fontMetrics().boundingRect(textPair.first).width(); + nMaxWidth = qMax(nMaxWidth, nCurrentTextWidth); + } + return MARGIN + nMaxWidth + fontMetrics().horizontalAdvance(m_spliter); +} + +/** + * @brief TipsWidget::paintEvent 任务栏插件提示信息绘制 + * @param event + */ +void TipsWidget::paintEvent(QPaintEvent *event) +{ + QFrame::paintEvent(event); + + QPainter painter(this); + painter.setPen(QPen(palette().brightText(), 1)); + + QTextOption option; + option.setAlignment(Qt::AlignLeft | Qt::AlignVCenter); + + int y = 0; + int valueX = calcValueX(); + for (QPair textPair : m_textList) { + QString key = textPair.first; + QStringList values = textPair.second; + QString displayText = (values.size() > 0 ? (QString("%1%2").arg(key).arg(m_spliter)) : key); + int lineHeight = fontMetrics().boundingRect(displayText).height(); + painter.drawText(QRect(MARGIN, y, rect().width(), lineHeight), displayText, option); + for (const QString &text : values) { + int textHeight = fontMetrics().boundingRect(text).height(); + painter.drawText(QRect(valueX, y, rect().width(), textHeight), text, option); + y += textHeight; + } + } +} + +bool TipsWidget::event(QEvent *event) +{ + if (event->type() == QEvent::FontChange) + setContext(m_textList); + + return QFrame::event(event); +} diff --git a/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.h b/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.h new file mode 100644 index 000000000..022941256 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/common-plugin/widgets/tipswidget.h @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef TIPSWIDGET_H +#define TIPSWIDGET_H + +#include "../plugin_global.h" + +#include + +NETWORKPLUGIN_BEGIN_NAMESPACE + +class TipsWidget : public QFrame +{ + Q_OBJECT + +public: + explicit TipsWidget(QWidget *parent = nullptr); + + void setContext(const QList> &textList); + void setSpliter(const QString &spliter); + +protected: + void paintEvent(QPaintEvent *event) override; + bool event(QEvent *event) override; + int calcValueX(); + +private: + QList> m_textList; + QString m_spliter; +}; + +NETWORKPLUGIN_END_NAMESPACE + +#endif // TIPSWIDGET_H diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/CMakeLists.txt b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/CMakeLists.txt new file mode 100644 index 000000000..464f3248a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.7) + +set(PLUGIN_NAME "dock-network-plugin") + +project(${PLUGIN_NAME}) +# 启用 qt moc 的支持 +set(CMAKE_AUTOMOC ON) +# 启用 qrc 资源文件的支持 +set(CMAKE_AUTORCC ON) + +file(GLOB_RECURSE SRCS "*.h" "*.cpp" "item/*.h" "item/*.cpp" "../common-plugin/*.h" "../common-plugin/*.cpp") + +find_package(Qt6 COMPONENTS Core Widgets DBus Network LinguistTools REQUIRED) +find_package(PkgConfig REQUIRED) +find_package(Dtk6 REQUIRED COMPONENTS Core) +find_package(Dtk6 REQUIRED COMPONENTS Widget) + +file(GLOB TS_FILES "translations/*.ts") +qt_add_translation(QM_FILES ${TS_FILES}) +add_custom_target(language ALL DEPENDS ${QM_FILES}) + +add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN") +add_library(${PLUGIN_NAME} SHARED ${SRCS} ../common-plugin/network.qrc) + +target_include_directories(${PLUGIN_NAME} PUBLIC + ${NETINTERFACEINCLUDE} + "../common-plugin" + "../../../interfaces" +) + +target_link_libraries(${PLUGIN_NAME} PRIVATE + dde-network-core_static +) + +install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/tmp/plugins/quick-trays) +# 安装 .qm 文件 +install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/${PLUGIN_NAME}/tmp/translations) diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/lupdate.sh b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/lupdate.sh new file mode 100755 index 000000000..f1456e52e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/lupdate.sh @@ -0,0 +1,10 @@ +#!/bin/bash +if [ ! -d "translations/" ];then + mkdir translations +fi +cd ./translations +rm -f dock-hotspot-plugin_en_US.ts +lupdate ../ ../../src ../../common-plugin -ts -no-ui-lines -locations none -no-obsolete dock-network-plugin_en_US.ts +cd ../ + +tx push -s --branch m23 diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/network.json b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/network.json new file mode 100644 index 000000000..5060fce05 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/network.json @@ -0,0 +1,5 @@ +{ + "api": "2.0.0", + "primary" : true, + "depends-daemon-dbus-service": "org.deepin.dde.Network1" +} diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.cpp b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.cpp new file mode 100644 index 000000000..23b2d5ea6 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.cpp @@ -0,0 +1,343 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkplugin.h" +#include "networkpluginhelper.h" +#include "networkdialog.h" +#include "quickpanel.h" +#include "item/devicestatushandler.h" +#include "networkdialog/thememanager.h" + +#include + +#include + +#include +#include +#include +#include + +#define STATE_KEY "enabled" + +NETWORKPLUGIN_USE_NAMESPACE + +NetworkPlugin::NetworkPlugin(QObject *parent) + : QObject(parent) + , m_networkHelper(Q_NULLPTR) + , m_networkDialog(Q_NULLPTR) + , m_quickPanel(Q_NULLPTR) + , m_clickTime(-10000) +{ + NetworkController::setIPConflictCheck(true); + QTranslator *translator = new QTranslator(this); + QString languagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + QString("dock-network-plugin/tmp/translations"), + QStandardPaths::LocateDirectory); + translator->load(QString(languagePath+"/dock-network-plugin_%1.qm").arg(QLocale::system().name())); + QCoreApplication::installTranslator(translator); +} + +NetworkPlugin::~NetworkPlugin() +{ +} + +const QString NetworkPlugin::pluginName() const +{ + return "network"; +} + +const QString NetworkPlugin::pluginDisplayName() const +{ + return tr("Network"); +} + +void NetworkPlugin::init(PluginProxyInterface *proxyInter) +{ + m_proxyInter = proxyInter; + if (m_networkHelper) + return; + + m_networkDialog = new NetworkDialog(this); + m_networkDialog->setServerName("dde-network-dialog" + QString::number(getuid()) + "dock"); + m_networkHelper.reset(new NetworkPluginHelper(m_networkDialog)); + connect(m_networkHelper.data(), &NetworkPluginHelper::iconChanged, this, &NetworkPlugin::onIconUpdated); + m_quickPanel = new QuickPanel(); + + if (!pluginIsDisable()) + loadPlugin(); + + connect(m_networkDialog, &NetworkDialog::requestShow, this, &NetworkPlugin::showNetworkDialog); + + connect(m_quickPanel, &QuickPanel::iconClicked, this, [this]() { + m_networkHelper->invokeMenuItem(m_quickPanel->userData().toString()); + }); + connect(m_quickPanel, &QuickPanel::panelClicked, this, &NetworkPlugin::showNetworkDialog); + + m_networkHelper->setIconDark(Dtk::Gui::DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType); + // 主题发生变化触发的信号 + connect(Dtk::Gui::DGuiApplicationHelper::instance(), &Dtk::Gui::DGuiApplicationHelper::themeTypeChanged, this, [this]() { + m_networkHelper->setIconDark(Dtk::Gui::DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType); + }); +} + +void NetworkPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) +{ + Q_UNUSED(checked) + + if (itemKey == NETWORK_KEY) + m_networkHelper->invokeMenuItem(menuId); +} + +void NetworkPlugin::refreshIcon(const QString &itemKey) +{ + if (itemKey == NETWORK_KEY) + emit m_networkHelper->viewUpdate(); +} + +void NetworkPlugin::pluginStateSwitched() +{ + m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable()); + + refreshPluginItemsVisible(); +} + +bool NetworkPlugin::pluginIsDisable() +{ + return !m_proxyInter->getValue(this, STATE_KEY, true).toBool(); +} + +const QString NetworkPlugin::itemCommand(const QString &itemKey) +{ + Q_UNUSED(itemKey) + if (m_networkHelper->needShowControlCenter()) { + return QString("dbus-send --print-reply " + "--dest=org.deepin.dde.ControlCenter1" + "/org/deepin/dde/ControlCenter1" + "org.deepin.dde.ControlCenter1.ShowModule " + "\"string:network\""); + } + + return QString(); +} + +const QString NetworkPlugin::itemContextMenu(const QString &itemKey) +{ + return QString(); +} + +QWidget *NetworkPlugin::itemWidget(const QString &itemKey) +{ + if (itemKey == QUICK_ITEM_KEY) { + return m_quickPanel; + } + return Q_NULLPTR; +} + +QWidget *NetworkPlugin::itemTipsWidget(const QString &itemKey) +{ + if (itemKey == NETWORK_KEY && !m_networkDialog->panel()->isVisible()) + return m_networkHelper->itemTips(); + + return Q_NULLPTR; +} + +QWidget *NetworkPlugin::itemPopupApplet(const QString &itemKey) +{ + Q_UNUSED(itemKey); + return m_networkDialog->panel(); +} + +int NetworkPlugin::itemSortKey(const QString &itemKey) +{ + const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); + return m_proxyInter->getValue(this, key, 3).toInt(); +} + +void NetworkPlugin::setSortKey(const QString &itemKey, const int order) +{ + const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); + m_proxyInter->saveValue(this, key, order); +} + +void NetworkPlugin::pluginSettingsChanged() +{ + refreshPluginItemsVisible(); +} + +PluginFlags NetworkPlugin::flags() const +{ + return PluginFlag::Type_Common | PluginFlag::Quick_Multi | PluginFlag::Attribute_CanDrag | PluginFlag::Attribute_CanInsert | PluginFlag::Attribute_CanSetting; +} + +void NetworkPlugin::loadPlugin() +{ + m_proxyInter->itemAdded(this, NETWORK_KEY); +} + +void NetworkPlugin::refreshPluginItemsVisible() +{ + if (pluginIsDisable()) + m_proxyInter->itemRemoved(this, NETWORK_KEY); + else + m_proxyInter->itemAdded(this, NETWORK_KEY); +} + +void NetworkPlugin::updateQuickPanel() +{ + QList devices = NetworkController::instance()->devices(); + int wiredConnectionCount = 0; + int wirelessConnectionCount = 0; + QString wiredConnection; + QString wirelessConnection; + QList wiredList; + QList wirelessList; + + for (NetworkDeviceBase *device : devices) { + switch (device->deviceType()) { + case DeviceType::Wired: { + WiredDevice *wiredDevice = static_cast(device); + wiredList.append(wiredDevice); + if (wiredDevice->isConnected()) { + QList items = wiredDevice->items(); + for (WiredConnection *item : items) { + if (item->status() == ConnectionStatus::Activated) { + wiredConnectionCount++; + wiredConnection = item->connection()->id(); + } + } + } + } break; + case DeviceType::Wireless: { + WirelessDevice *wirelessDevice = static_cast(device); + wirelessList.append(wirelessDevice); + if (wirelessDevice->isConnected()) { + QList items = wirelessDevice->items(); + for (WirelessConnection *item : items) { + if (item->status() == ConnectionStatus::Activated) { + wirelessConnectionCount++; + wirelessConnection = item->connection()->ssid(); + } + } + } + } break; + default: + break; + } + } + + if (!wirelessList.isEmpty()) { + NetDeviceStatus status = DeviceStatusHandler::wirelessStatus(wirelessList); + updateQuickPanelDescription(status, wirelessConnectionCount, wirelessConnection, NetworkPluginHelper::MenuWirelessEnable); + m_quickPanel->setText(tr("Wireless Network")); + m_quickPanel->setIcon(QIcon::fromTheme(ThemeManager::ref().getIcon("wireless-80-symbolic"))); + } else if (!wiredList.isEmpty()) { + NetDeviceStatus status = DeviceStatusHandler::wiredStatus(wiredList); + updateQuickPanelDescription(status, wiredConnectionCount, wiredConnection, NetworkPluginHelper::MenuWiredEnable); + m_quickPanel->setText(tr("Wired Network")); + m_quickPanel->setIcon(QIcon::fromTheme(ThemeManager::ref().getIcon("network-wired-symbolic"))); + } else { + m_quickPanel->setText(pluginDisplayName()); + m_quickPanel->setDescription(description()); + m_quickPanel->setActive(false); + m_quickPanel->setUserData(NetworkPluginHelper::MenuSettings); + m_quickPanel->setIcon(QIcon::fromTheme(ThemeManager::ref().getIcon("network-error-symbolic"))); + } +} + +void NetworkPlugin::updateQuickPanelDescription(NetDeviceStatus status, int connectionCount, const QString &Connection, int enableMenu) +{ + QString statusName = networkStateName(status); + bool isEnabled = (status != NetDeviceStatus::Disabled); + + if (statusName.isEmpty() && connectionCount != 0) { + if (connectionCount == 1) { + m_quickPanel->setDescription(Connection); + } else { + m_quickPanel->setDescription(tr("Connected") + QString(" (%1)").arg(connectionCount)); + } + } else { + m_quickPanel->setDescription(statusName); + } + m_quickPanel->setActive(isEnabled); + m_quickPanel->setUserData(isEnabled ? (enableMenu + 1) : enableMenu); +} + +QString NetworkPlugin::networkStateName(NetDeviceStatus status) const +{ + switch (status) { + case NetDeviceStatus::Disabled: + return tr("Device disabled"); + case NetDeviceStatus::Unknown: + case NetDeviceStatus::Nocable: + return tr("Network cable unplugged"); + case NetDeviceStatus::Disconnected: + return tr("Not connected"); + case NetDeviceStatus::Connecting: + case NetDeviceStatus::Authenticating: + return tr("Connecting"); + case NetDeviceStatus::ObtainingIP: + case NetDeviceStatus::ObtainIpFailed: + return tr("Obtaining address"); + case NetDeviceStatus::ConnectNoInternet: + return tr("Connected but no Internet access"); + case NetDeviceStatus::IpConflicted: + return tr("IP conflict"); + case NetDeviceStatus::ConnectFailed: + return tr("Connection failed"); + default: + break; + } + return QString(); +} + +void NetworkPlugin::onIconUpdated() +{ + // update quick panel + m_proxyInter->updateDockInfo(this, DockPart::QuickPanel); + // update quick plugin area + m_proxyInter->updateDockInfo(this, DockPart::QuickShow); + + updateQuickPanel(); +} + +QIcon NetworkPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) +{ + switch(dockPart) { + case DockPart::DCCSetting: + case DockPart::QuickShow: + return m_networkHelper->icon(themeType); + default: + break; + } + + return QIcon(); +} + +PluginsItemInterface::PluginMode NetworkPlugin::status() const +{ + // get the plugin status + PluginState plugState = m_networkHelper->getPluginState(); + switch (plugState) { + case PluginState::Unknown: + case PluginState::Disabled: + case PluginState::Nocable: + return PluginMode::Disabled; + default: + break; + } + + return PluginMode::Active; +} + +QString NetworkPlugin::description() const +{ + return m_quickPanel ? m_quickPanel->description() : QString(); +} + +void NetworkPlugin::showNetworkDialog() +{ + if (m_networkDialog->panel()->isVisible()) + return; + m_proxyInter->requestSetAppletVisible(this, NETWORK_KEY, true); +} diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.h b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.h new file mode 100644 index 000000000..21d661624 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/networkplugin.h @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKPLUGIN_H +#define NETWORKPLUGIN_H + +#include "pluginsiteminterface.h" +#include "../common-plugin/utils.h" + +#define NETWORK_KEY "network-item-key" + +NETWORKPLUGIN_BEGIN_NAMESPACE +class NetworkPluginHelper; +class NetworkDialog; +class TrayIcon; +NETWORKPLUGIN_END_NAMESPACE + +class QuickPanel; +enum class NetDeviceStatus; + +class NetworkPlugin : public QObject, PluginsItemInterface +{ + Q_OBJECT + + Q_INTERFACES(PluginsItemInterface) + Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "network.json") + +public Q_SLOTS: + void showNetworkDialog(); + +public: + explicit NetworkPlugin(QObject *parent = Q_NULLPTR); + ~NetworkPlugin() Q_DECL_OVERRIDE; + + const QString pluginName() const override; + const QString pluginDisplayName() const override; + void init(PluginProxyInterface *proxyInter) override; + void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) override; + void refreshIcon(const QString &itemKey) override; + void pluginStateSwitched() override; + bool pluginIsAllowDisable() override { return true; } + bool pluginIsDisable() override; + const QString itemCommand(const QString &itemKey) override; + const QString itemContextMenu(const QString &itemKey) override; + QWidget *itemWidget(const QString &itemKey) override; + QWidget *itemTipsWidget(const QString &itemKey) override; + QWidget *itemPopupApplet(const QString &itemKey) override; + + int itemSortKey(const QString &itemKey) override; + void setSortKey(const QString &itemKey, const int order) override; + + void pluginSettingsChanged() override; + PluginFlags flags() const override; + +protected: + QIcon icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) override; + PluginMode status() const override; + QString description() const override; + +private: + void loadPlugin(); + void refreshPluginItemsVisible(); + void updateQuickPanel(); + void updateQuickPanelDescription(NetDeviceStatus status, int connectionCount, const QString &Connection, int enableMenu); + QString networkStateName(NetDeviceStatus status) const; + +private Q_SLOTS: + void onIconUpdated(); + +private: + QScopedPointer m_networkHelper; + NETWORKPLUGIN_NAMESPACE::NetworkDialog *m_networkDialog; + QuickPanel *m_quickPanel; + int m_clickTime; +}; + +#endif // NETWORKPLUGIN_H diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.cpp b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.cpp new file mode 100644 index 000000000..6966592e2 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.cpp @@ -0,0 +1,212 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "quickpanel.h" + +#include +#include +#include + +#include +#include +#include + +DWIDGET_USE_NAMESPACE + +const QSize IconSize(24, 24); // 图标大小 + +class HighlightIconEngine : public QIconEngine +{ +public: + explicit HighlightIconEngine(QIcon icon = QIcon()) + : QIconEngine() + , m_icon(icon) + { + } + + virtual void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) + { + QSize pixmapSize = rect.size(); + qreal scale = 1; + if (painter->device() && (!QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps))) + scale = painter->device()->devicePixelRatioF(); + + pixmapSize *= scale; + + QPixmap pm = m_icon.pixmap(pixmapSize, mode, state); + if (pm.isNull()) + return; + + if (state == QIcon::On) { + QPainter pa(&pm); + pa.setCompositionMode(QPainter::CompositionMode_SourceIn); + pa.fillRect(pm.rect(), qApp->palette().highlight()); + } + + pm.setDevicePixelRatio(scale); + painter->drawPixmap(rect, pm); + } + + virtual QIconEngine *clone() const + { + return new HighlightIconEngine(m_icon); + } + +private: + QIcon m_icon; +}; + +QuickPanel::QuickPanel(QWidget *parent) + : QWidget(parent) + , m_iconButton(new DIconButton(this)) + , m_text(new DLabel(this)) + , m_description(new DLabel(this)) + , m_hover(false) +{ + initUi(); + initConnect(); +} + +const QVariant &QuickPanel::userData() const +{ + return m_userData; +} + +void QuickPanel::setUserData(const QVariant &data) +{ + m_userData = data; +} + +const QString QuickPanel::text() const +{ + return m_text->text(); +} + +const QString QuickPanel::description() const +{ + return m_description->text(); +} + +void QuickPanel::setIcon(const QIcon &icon) +{ + m_iconButton->setIcon(QIcon(new HighlightIconEngine(icon))); +} + +void QuickPanel::setText(const QString &text) +{ + m_text->setText(text); +} + +void QuickPanel::setDescription(const QString &description) +{ + m_description->setText(description); + m_description->setToolTip(description); +} + +void QuickPanel::setActive(bool active) +{ + m_iconButton->setChecked(active); +} + +void QuickPanel::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::RenderHint::Antialiasing); + const DPalette &dp = palette(); + painter.setPen(Qt::NoPen); + painter.setBrush(dp.brush(m_hover ? DPalette::ObviousBackground : DPalette::ItemBackground)); + painter.drawRoundedRect(rect(), 8, 8); +} + +void QuickPanel::mouseReleaseEvent(QMouseEvent *event) +{ + if (!m_iconButton->rect().contains(event->pos()) && rect().contains(event->pos())) { + emit panelClicked(); + } +} + +void QuickPanel::enterEvent(QEnterEvent *event) +{ + setHover(true); +} + +void QuickPanel::leaveEvent(QEvent *event) +{ + setHover(false); +} + +bool QuickPanel::eventFilter(QObject *watched, QEvent *event) +{ + switch (event->type()) { + case QEvent::Enter: + setHover(false); + break; + case QEvent::Leave: + setHover(true); + break; + default: + break; + } + return QWidget::eventFilter(watched, event); +} + +void QuickPanel::initUi() +{ + QHBoxLayout *mainLayout = new QHBoxLayout(this); + // 文本 + QWidget *labelWidget = new QWidget(this); + QVBoxLayout *layout = new QVBoxLayout(labelWidget); + layout->setContentsMargins(0, 10, 0, 10); + layout->setSpacing(0); + QFont nameFont = DFontSizeManager::instance()->t6(); + nameFont.setBold(true); + m_text->setFont(nameFont); + m_text->setElideMode(Qt::ElideRight); + layout->addWidget(m_text); + m_description->setFont(DFontSizeManager::instance()->t10()); + m_description->setElideMode(Qt::ElideRight); + layout->addWidget(m_description); + + // 图标 + m_iconButton->setEnabledCircle(true); + m_iconButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_iconButton->setIconSize(IconSize); + m_iconButton->installEventFilter(this); + m_iconButton->setCheckable(true); + + // 进入图标 + QWidget *expandWidget = new QWidget(this); + QVBoxLayout *expandLayout = new QVBoxLayout(expandWidget); + QLabel *enterIcon = new QLabel(expandWidget); + qreal ratio = devicePixelRatioF(); + QSize size = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? QSize(16, 16) : QSize(16, 16) * ratio; + QPixmap enterPixmap = DStyle::standardIcon(style(), DStyle::SP_ArrowEnter).pixmap(size); + enterPixmap.setDevicePixelRatio(ratio); + enterIcon->setPixmap(enterPixmap); + expandLayout->setContentsMargins(0, 0, 0, 0); + expandLayout->setSpacing(0); + expandLayout->addWidget(enterIcon); + + mainLayout->setContentsMargins(10, 0, 10, 0); + mainLayout->setSpacing(0); + mainLayout->addWidget(m_iconButton); + mainLayout->addSpacing(10); + mainLayout->addWidget(labelWidget); + mainLayout->addStretch(); + mainLayout->addWidget(expandWidget); +} + +void QuickPanel::initConnect() +{ + connect(m_iconButton, &DIconButton::clicked, this, &QuickPanel::iconClicked); +} + +void QuickPanel::setHover(bool hover) +{ + if (hover == m_hover) + return; + + m_hover = hover; + update(); +} diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.h b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.h new file mode 100644 index 000000000..3224fbcfb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/quickpanel.h @@ -0,0 +1,62 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef QUICKPANEL_H +#define QUICKPANEL_H + +#include +#include +#include + +namespace Dtk { +namespace Widget { +class DLabel; +class DIconButton; +} +} + +class QuickPanel : public QWidget +{ + Q_OBJECT + +public: + explicit QuickPanel(QWidget *parent = nullptr); + const QVariant &userData() const; + void setUserData(const QVariant &data); + const QString text() const; + const QString description() const; + +public Q_SLOTS: + void setIcon(const QIcon &icon); + void setText(const QString &text); + void setDescription(const QString &description); + void setActive(bool active); + +Q_SIGNALS: + void panelClicked(); + void iconClicked(); + +protected: + void paintEvent(QPaintEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + void enterEvent(QEnterEvent *event) override; + void leaveEvent(QEvent *event) override; + bool eventFilter(QObject *watched, QEvent *event) override; + +private: + void initUi(); + void initConnect(); + void setHover(bool hover); + +private: + QVariant m_userData; + + Dtk::Widget::DIconButton *m_iconButton; + Dtk::Widget::DLabel *m_text; + Dtk::Widget::DLabel *m_description; + + bool m_hover; +}; + +#endif // QUICKPANEL_H diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin.ts new file mode 100644 index 000000000..be67a9974 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin.ts @@ -0,0 +1,283 @@ + + + + + DeviceControllItem + + Wireless Network + + + + Wired Network + + + + + NetworkPlugin + + Network + + + + Wireless Network + + + + Wired Network + + + + Connected + + + + Device disabled + + + + Network cable unplugged + + + + Not connected + + + + Connecting + + + + Obtaining address + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + + + + Password + + + + Cancel + button + + + + Connect + button + + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + + + + SSID + + + + Protocol + + + + Security Type + + + + Band + + + + Channel + + + + Interface + + + + MAC + + + + IPv4 + + + + Netmask + + + + Gateway + + + + Primary DNS + + + + IPv6 + + + + Prefix + + + + Speed + + + + + dde::network::NetworkDeviceRealize + + Device disabled + + + + Connected but no Internet access + + + + Not connected + + + + Network cable unplugged + + + + Connecting + + + + Authenticating + + + + Obtaining IP address + + + + Connected + + + + Disconnected + + + + IP conflict + + + + Failed + + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + + + + Wired Network %1 + + + + Wireless Network + + + + Wireless Network %1 + + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + + + + Network cable unplugged + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + Connection failed + + + + IP conflict + + + + Disable wired connection + + + + Enable wired connection + + + + Disable wireless connection + + + + Enable wireless connection + + + + Disable network + + + + Enable network + + + + Network settings + + + + diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ar.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ar.ts new file mode 100644 index 000000000..905281607 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ar.ts @@ -0,0 +1,201 @@ + + + NetworkPlugin + + Network + الشبكة + + + + dde::network::NetworkDetails + + Hotspot + نقطة الإتصال + + + SSID + SSID + + + Protocol + + + + Security Type + + + + Band + الحزمة + + + Channel + القناة + + + Interface + الواجهة + + + MAC + ماك + + + IPv4 + IPv4 + + + Netmask + قناع الشبكة + + + Gateway + البوابة + + + Primary DNS + DNS رئيسي + + + IPv6 + IPv6 + + + Prefix + البادئة + + + Speed + السرعة + + + + dde::network::NetworkDeviceRealize + + Device disabled + جهاز ملغى + + + Connected but no Internet access + متصل لكن لا يوجد اتصال بالإنترنت + + + Not connected + غير متصل + + + Network cable unplugged + سلك الشبكة غير موصول + + + Connecting + يتصل + + + Authenticating + المصادقة + + + Obtaining IP address + جاري الحصول على عنوان IP + + + Connected + متصل + + + Disconnected + غير متصل + + + IP conflict + + + + Failed + فشل + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + شبكة سلكية + + + Wired Network %1 + شبكة سلكية 1% + + + Wireless Network + شبكة لاسلكية + + + Wireless Network %1 + الشبكة اللاسلكية : %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + جهاز ملغى + + + Network cable unplugged + سلك الشبكة غير موصول + + + Not connected + غير متصل + + + Connecting + يتصل + + + Connected but no Internet access + متصل لكن لا يوجد اتصال بالإنترنت + + + Connection failed + + + + IP conflict + + + + Disable wired connection + تعطيل الاتصال السلكي + + + Enable wired connection + تفعيل الاتصال السلكي + + + Disable wireless connection + تعطيل الاتصال اللاسلكي + + + Enable wireless connection + تفعيل الاتصال اللاسلكي + + + Disable network + تعطيل الشبكة + + + Enable network + تمكين الشبكة + + + Network settings + إعدادات الشبكة + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_az.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_az.ts new file mode 100644 index 000000000..5ecdef90e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_az.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Simsiz şəbəkə + + + Wired Network + Naqilli şəbəkə + + + + NetworkPlugin + + Network + Şəbəkə + + + Wireless Network + + + + Wired Network + Naqilli şəbəkə + + + Device disabled + Cihaz söndürülüb + + + Network cable unplugged + Şəbəkə kabeli çıxarılıb + + + Not connected + Bağlantı yoxdur + + + Connecting + Qoşulur + + + Connected but no Internet access + Qoşulub, lakin internetə giriş yoxdur + + + IP conflict + İP ziddiyyəti + + + Connection failed + Qoşulma alınmadı + + + + WirelessItem + + Connect to hidden network + Gizli şəbəkəyə qoşulun + + + Password + Şifrə + + + Cancel + button + İmtina + + + Connect + button + Qoşulun + + + Name (SSID) + Ad (SSİD) + + + + dde::network::NetworkDetails + + Hotspot + Qoşulma nöqtəsi + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Təhlükəsizlik növü + + + Band + Aralıq + + + Channel + Kanal + + + Interface + İnterfeys + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Şəbəkə maskası + + + Gateway + Şəbəkə keçidi + + + Primary DNS + Birinci DNS + + + IPv6 + IPv6 + + + Prefix + Prefiks + + + Speed + Sürət + + + + dde::network::NetworkDeviceRealize + + Device disabled + Cihaz söndürülüb + + + Connected but no Internet access + Qoşulub, lakin internetə giriş yoxdur + + + Not connected + Bağlantı yoxdur + + + Network cable unplugged + Şəbəkə kabeli çıxarılıb + + + Connecting + Qoşulur... + + + Authenticating + Doğrulanır + + + Obtaining IP address + İP ünvanları alınır + + + Connected + Qoşuldu + + + Disconnected + Bağlantı kəsildi + + + IP conflict + İP ziddiyyəti + + + Failed + Uğursuz + + + Obtaining address + Ünvan alınır + + + + dde::network::NetworkProcesser + + Wired Network + Simli şəbəkə + + + Wired Network %1 + Simli şəbəkəsi %1 + + + Wireless Network + Simsiz şəbəkə + + + Wireless Network %1 + Simsiz şəbəkə %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Cihaz söndürülüb + + + Network cable unplugged + Şəbəkə kabeli çıxarılıb + + + Not connected + Bağlantı yoxdur + + + Connecting + Qoşulur... + + + Connected but no Internet access + Qoşulub, lakin internetə giriş yoxdur + + + Connection failed + Qoşulma alınmadı + + + IP conflict + İP ziddiyyəti + + + Disable wired connection + Simli bağlantını söndürmək + + + Enable wired connection + Simli bağlantını qoşmaq + + + Disable wireless connection + Simsiz bağlantını söndürmək + + + Enable wireless connection + Simsiz bağlantını qoşmaq + + + Disable network + Şəbəkəni söndürmək + + + Enable network + Şəbəkəni qoşmaq + + + Network settings + Şəbəkə ayarları + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_bo.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_bo.ts new file mode 100644 index 000000000..3cce45ce5 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_bo.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + སྐུད་མེད་དྲ་རྒྱ། + + + Wired Network + སྐུད་ཡོད་དྲ་རྒྱ། + + + + NetworkPlugin + + Network + དྲ་རྒྱ། + + + Wireless Network + + + + Wired Network + སྐུད་ཡོད་དྲ་རྒྱ། + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + ཡིབ་དྲ་དང་མཐུད་པ། + + + Password + གསང་ཨང་འཇུག་རོགས། + + + Cancel + button + འདོར་བ། + + + Connect + button + འབྲེལ་མཐུད། + + + Name (SSID) + དྲ་བའི་མིང་(SSID)ནང་འཇུག་བྱེད་རོགས། + + + + dde::network::NetworkDetails + + Hotspot + ཚ་གནས། + + + SSID + SSID + + + Protocol + གྲོས་མཐུན། + + + Security Type + བདེ་འཇགས་རིགས། + + + Band + བྱུང་རིམ། + + + Channel + དྲ་རྒྱའི་རྒྱུ་ལམ། + + + Interface + མཐུད་ཁ། + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + བུ་དྲ་ཡིབ་ཨང་། + + + Gateway + དྲ་སྒོ། + + + Primary DNS + སྔོན་འདེམས་DNS + + + IPv6 + IPv6 + + + Prefix + སྔོན་སྦྱོར། + + + Speed + མྱུར་ཚད། + + + + dde::network::NetworkDeviceRealize + + Device disabled + སྒྲིག་ཆས་སྤྱོད་མི་ཆོག + + + Connected but no Internet access + དྲ་རྒྱ་དང་འབྲེལ་ཟིན་ཡང་མཉམ་སྦྲེལ་དྲ་རྒྱར་འཛུལ་མི་ཐུབ། + + + Not connected + སྦྲེལ་མེད་པ། + + + Network cable unplugged + དྲ་སྐུད་མཐུད་མི་འདུག + + + Connecting + སྦྲེལ་བཞིན་པ། + + + Authenticating + ར་སྤྲོད་བྱེད་བཞིན་པ། + + + Obtaining IP address + IP གནས་ཡུལ་འཚོལ་བཞིན་པ། + + + Connected + སྦྲེལ་ཟིན། + + + Disconnected + བཅད་ཟིན། + + + IP conflict + IPགནས་ཡུལ་འགལ་ཟླ་བྱུང་བ། + + + Failed + ཕམ་པ། + + + Obtaining address + གནས་ཡུལ་འཚོལ་བཞིན་པ། + + + + dde::network::NetworkProcesser + + Wired Network + སྐུད་ཡོད་དྲ་རྒྱ། + + + Wired Network %1 + སྐུད་ཡོད་དྲ་རྒྱ་%1 + + + Wireless Network + སྐུད་མེད་དྲ་རྒྱ། + + + Wireless Network %1 + སྐུད་མེད་དྲ་རྒྱ་%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + སྒྲིག་ཆས་སྤྱོད་མི་ཆོག + + + Network cable unplugged + དྲ་སྐུད་མཐུད་མི་འདུག + + + Not connected + སྦྲེལ་མེད་པ། + + + Connecting + སྦྲེལ་བཞིན་པ། + + + Connected but no Internet access + དྲ་རྒྱ་དང་འབྲེལ་ཟིན་ཡང་མཉམ་སྦྲེལ་དྲ་རྒྱར་འཛུལ་མི་ཐུབ། + + + Connection failed + འབྲེལ་མཐུད་བྱེད་མ་ཐུབ། + + + IP conflict + IPགནས་ཡུལ་འགལ་ཟླ་བྱུང་བ། + + + Disable wired connection + སྐུད་ཡོད་དྲ་རྒྱ་ཁ་རྒྱོབ། + + + Enable wired connection + སྐུད་ཡོད་དྲ་རྒྱ་སྤྱོད་པ། + + + Disable wireless connection + སྐུད་མེད་དྲ་རྒྱ་ཁ་རྒྱོབ། + + + Enable wireless connection + སྐུད་མེད་དྲ་རྒྱ་སྤྱོད་པ། + + + Disable network + དྲ་རྒྱ་ཁ་རྒྱོབ། + + + Enable network + དྲ་རྒྱ་སྤྱོད་པ། + + + Network settings + དྲ་རྒྱ་སྒྲིག་འགོད། + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ca.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ca.ts new file mode 100644 index 000000000..da3d1eacb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ca.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + Xarxa sense fil + + + Wired Network + Xarxa amb fil + + + + NetworkPlugin + + Network + Xarxa + + + Wireless Network + Xarxa sense fil + + + Wired Network + Xarxa amb fil + + + Connected + + + + Device disabled + Dispositiu inhabilitat + + + Network cable unplugged + Cable de xarxa desendollat + + + Not connected + No connectat + + + Connecting + Es connecta + + + Obtaining address + + + + Connected but no Internet access + Connectat però sense accés a Internet + + + IP conflict + Conflicte d'IP + + + Connection failed + Ha fallat la connexió. + + + + WirelessItem + + Connect to hidden network + Connecta amb una xarxa oculta + + + Password + Contrasenya + + + Cancel + button + Cancel·la + + + Connect + button + Connecta + + + Name (SSID) + Nom (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Punt d'accés + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Tipus de seguretat + + + Band + Banda + + + Channel + Canal + + + Interface + Interfície + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Màscara de xarxa + + + Gateway + Passarel·la + + + Primary DNS + DNS primari + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Velocitat + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositiu inhabilitat + + + Connected but no Internet access + Connectat però sense accés a Internet + + + Not connected + No connectat + + + Network cable unplugged + Cable de xarxa desendollat + + + Connecting + Es connecta + + + Authenticating + S'autentica + + + Obtaining IP address + S'obté l'adreça IP + + + Connected + Connectat + + + Disconnected + Desconnectat + + + IP conflict + Conflicte d'IP + + + Failed + Ha fallat + + + Obtaining address + S'obté l'adreça + + + + dde::network::NetworkProcesser + + Wired Network + Xarxa amb fil + + + Wired Network %1 + Xarxa amb fil %1 + + + Wireless Network + Xarxa sense fil + + + Wireless Network %1 + Xarxa sense fil %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositiu inhabilitat + + + Network cable unplugged + Cable de xarxa desendollat + + + Not connected + No connectat + + + Connecting + Es connecta + + + Connected but no Internet access + Connectat però sense accés a Internet + + + Connection failed + Ha fallat la connexió. + + + IP conflict + Conflicte d'IP + + + Disable wired connection + Inhabilita la connexió amb fil + + + Enable wired connection + Habilita la connexió amb fil + + + Disable wireless connection + Inhabilita la connexió sense fil + + + Enable wireless connection + Habilita la connexió sense fil + + + Disable network + Inhabilita la xarxa + + + Enable network + Habilita la xarxa + + + Network settings + Configuració de la xarxa + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_cs.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_cs.ts new file mode 100644 index 000000000..fa885ee46 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_cs.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Bezdrátová síť + + + Wired Network + Drátová síť + + + + NetworkPlugin + + Network + Síť + + + Wireless Network + + + + Wired Network + Drátová síť + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Připojit se ke skryté síti + + + Password + Heslo + + + Cancel + button + Zrušit + + + Connect + button + Připojit + + + Name (SSID) + Název (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Přípojný bod + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Typ zabezpečení + + + Band + Pásmo + + + Channel + Kanál + + + Interface + Rozhraní + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Maska sítě + + + Gateway + Brána + + + Primary DNS + Hlavní DNS + + + IPv6 + IPv6 + + + Prefix + Předpona + + + Speed + Rychlost + + + + dde::network::NetworkDeviceRealize + + Device disabled + Zařízení zakázáno + + + Connected but no Internet access + Připojeno, ale bez přístupu k internetu + + + Not connected + Nepřipojeno + + + Network cable unplugged + Síťový kabel odpojen + + + Connecting + Připojuje se + + + Authenticating + Ověřování + + + Obtaining IP address + Získávání IP adresy + + + Connected + Připojeno + + + Disconnected + Odpojeno + + + IP conflict + Střet IP adres + + + Failed + Nepodařilo se + + + Obtaining address + Získávání adresy + + + + dde::network::NetworkProcesser + + Wired Network + Drátová síť + + + Wired Network %1 + Drátová síť %1 + + + Wireless Network + Bezdrátová síť + + + Wireless Network %1 + Bezdrátová síť %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Zařízení zakázáno + + + Network cable unplugged + Síťový kabel odpojen + + + Not connected + Nepřipojeno + + + Connecting + Připojuje se + + + Connected but no Internet access + Připojeno, ale bez přístupu k Internetu + + + Connection failed + Připojení se nezdařilo + + + IP conflict + Střet IP adres + + + Disable wired connection + Vypnout drátové připojení + + + Enable wired connection + Zapnout drátové připojení + + + Disable wireless connection + Vypnout bezdrátové připojení + + + Enable wireless connection + Zapnout bezdrátové připojení + + + Disable network + Zakázat síť + + + Enable network + Povolit síť + + + Network settings + Nastavení sítě + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_da.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_da.ts new file mode 100644 index 000000000..d4b8543fa --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_da.ts @@ -0,0 +1,201 @@ + + + NetworkPlugin + + Network + Netværk + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + + + + Security Type + + + + Band + Bånd + + + Channel + Kanal + + + Interface + Grænseflade + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmaske + + + Gateway + Gateway + + + Primary DNS + Primær DNS + + + IPv6 + IPv6 + + + Prefix + Præfiks + + + Speed + Hastighed + + + + dde::network::NetworkDeviceRealize + + Device disabled + Enhed deaktiveret + + + Connected but no Internet access + Tilsluttet men ingen internetadgang + + + Not connected + Ikke tilsluttet + + + Network cable unplugged + Netværkskablet er frakoblet + + + Connecting + Opretter forbindelse + + + Authenticating + Autentificering + + + Obtaining IP address + Indhenter IP-adresse + + + Connected + Tilsluttet + + + Disconnected + Afbrudt + + + IP conflict + + + + Failed + Mislykkedet + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Kablet netværk + + + Wired Network %1 + Kablet netværk %1 + + + Wireless Network + Trådløst netværk + + + Wireless Network %1 + Trådløst netværk %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Enhed deaktiveret + + + Network cable unplugged + Netværkskablet er frakoblet + + + Not connected + Ikke tilsluttet + + + Connecting + Opretter forbindelse + + + Connected but no Internet access + Tilsluttet men ingen internetadgang + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Deaktivér kablet forbindelse + + + Enable wired connection + Aktivér kablet forbindelse + + + Disable wireless connection + Deaktivér trådløs forbindelse + + + Enable wireless connection + Aktivér trådløs forbindelse + + + Disable network + Deaktivér netværk + + + Enable network + Aktivér netværk + + + Network settings + Netværksindstillinger + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_de.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_de.ts new file mode 100644 index 000000000..2ef751222 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_de.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Drahtlosnetzwerk + + + Wired Network + Kabelgebundenes Netzwerk + + + + NetworkPlugin + + Network + Netzwerk + + + Wireless Network + + + + Wired Network + Kabelgebundenes Netzwerk + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Mit verstecktem Netzwerk verbinden + + + Password + Passwort + + + Cancel + button + Abbrechen + + + Connect + button + Verbinden + + + Name (SSID) + Name (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protokoll + + + Security Type + Sicherheitstyp + + + Band + Band + + + Channel + Kanal + + + Interface + Schnittstelle + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netzmaske + + + Gateway + Gateway + + + Primary DNS + Primärer DNS + + + IPv6 + IPv6 + + + Prefix + Präfix + + + Speed + Geschwindigkeit + + + + dde::network::NetworkDeviceRealize + + Device disabled + Gerät deaktiviert + + + Connected but no Internet access + Verbunden, aber kein Internetzugang + + + Not connected + Nicht verbunden + + + Network cable unplugged + Netzwerkkabel abgezogen + + + Connecting + Wird verbunden + + + Authenticating + Wird authentifiziert + + + Obtaining IP address + IP-Adresse wird abgerufen + + + Connected + Verbunden + + + Disconnected + Getrennt + + + IP conflict + IP Konflikt + + + Failed + Fehlgeschlagen + + + Obtaining address + Adresse wird abgerufen + + + + dde::network::NetworkProcesser + + Wired Network + Kabelgebundenes Netzwerk + + + Wired Network %1 + Kabelgebundenes Netzwerk %1 + + + Wireless Network + Drahtlosnetzwerk + + + Wireless Network %1 + Drahtlosnetzwerk %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Gerät deaktiviert + + + Network cable unplugged + Netzwerkkabel abgezogen + + + Not connected + Nicht verbunden + + + Connecting + Wird verbunden + + + Connected but no Internet access + Verbunden, aber kein Internetzugang + + + Connection failed + Verbindung fehlgeschlagen + + + IP conflict + IP Konflikt + + + Disable wired connection + Kabelgebundene Verbindung deaktivieren + + + Enable wired connection + Kabelgebundene Verbindung aktivieren + + + Disable wireless connection + Drahtlosverbindung deaktivieren + + + Enable wireless connection + Drahtlosverbindung aktivieren + + + Disable network + Netzwerk deaktivieren + + + Enable network + Netzwerk aktivieren + + + Network settings + Netzwerkeinstellungen + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_el.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_el.ts new file mode 100644 index 000000000..6d1af6638 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_el.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Ασύρματο Δίκτυο + + + Wired Network + Ενσύρματο Δίκτυο + + + + NetworkPlugin + + Network + Δίκτυο + + + Wireless Network + + + + Wired Network + Ενσύρματο Δίκτυο + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Σύνδεση σε κρυφό δίκτυο + + + Password + Κωδικός πρόσβασης + + + Cancel + button + Ακύρωση + + + Connect + button + Σύνδεση + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Πρωτόκολλο + + + Security Type + Τύπος Ασφαλείας + + + Band + Mπάντα + + + Channel + Kανάλι + + + Interface + Διεπαφή + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Μάσκα Δικτύου + + + Gateway + Gateway + + + Primary DNS + Πρωτεύον DNS + + + IPv6 + IPv6 + + + Prefix + Πρόθεμα + + + Speed + Ταχύτητα + + + + dde::network::NetworkDeviceRealize + + Device disabled + Συσκευή Αποσυνδέθηκε + + + Connected but no Internet access + Συνδεδεμένο αλλά χωρίς πρόσβαση στο διαδίκτυο + + + Not connected + Δεν Συνδέθηκε + + + Network cable unplugged + Το καλώδιο δικτύου, αποσυνδέθηκε + + + Connecting + Σύνδεση + + + Authenticating + Πιστοποίηση + + + Obtaining IP address + Απόκτηση Διεύθυνσης IP + + + Connected + Συνδέθηκε + + + Disconnected + Αποσυνδέθηκε + + + IP conflict + Αντιτίθεση IP + + + Failed + Αποτυχία + + + Obtaining address + Απόκτηση Διεύθυνσης + + + + dde::network::NetworkProcesser + + Wired Network + Ενσύρματο Δίκτυο + + + Wired Network %1 + Ενσύρματο Δίκτυο %1 + + + Wireless Network + Ασύρματο Δίκτυο + + + Wireless Network %1 + Ασύρματο Δίκτυο %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Συσκευή Αποσυνδέθηκε + + + Network cable unplugged + Το καλώδιο δικτύου, αποσυνδέθηκε + + + Not connected + Δεν Συνδέθηκε + + + Connecting + Σύνδεση + + + Connected but no Internet access + Συνδεδεμένο αλλά χωρίς πρόσβαση στο διαδίκτυο + + + Connection failed + Αποτυχία σύνδεσης + + + IP conflict + Αντιτίθεση IP + + + Disable wired connection + Απενεργοποιήστε την ενσύρματη σύνδεση + + + Enable wired connection + Ενεργοποιήστε την ενσύρματη σύνδεση + + + Disable wireless connection + Απενεργοποιήστε την ασύρματη σύνδεση + + + Enable wireless connection + Ενεργοποιήστε την ασύρματη σύνδεση + + + Disable network + Απενεργοποίηση δικτύου + + + Enable network + Ενεργοποίηση δικτύου + + + Network settings + Ρυθμίσεις δικτύου + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_AU.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_AU.ts new file mode 100644 index 000000000..b192aeddb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_AU.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Wireless Network + + + Wired Network + Wired Network + + + + NetworkPlugin + + Network + Network + + + Wireless Network + + + + Wired Network + Wired Network + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Connect to hidden network + + + Password + Password + + + Cancel + button + Cancel + + + Connect + button + Connect + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Security Type + + + Band + Band + + + Channel + Channel + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmask + + + Gateway + Gateway + + + Primary DNS + Primary DNS + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Speed + + + + dde::network::NetworkDeviceRealize + + Device disabled + Device disabled + + + Connected but no Internet access + Connected but no Internet access + + + Not connected + Not connected + + + Network cable unplugged + Network cable unplugged + + + Connecting + Connecting + + + Authenticating + Authenticating + + + Obtaining IP address + Obtaining IP address + + + Connected + Connected + + + Disconnected + Disconnected + + + IP conflict + + + + Failed + Failed + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Wired Network + + + Wired Network %1 + Wired Network %1 + + + Wireless Network + Wireless Network + + + Wireless Network %1 + Wired Network %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Device disabled + + + Network cable unplugged + Network cable unplugged + + + Not connected + Not connected + + + Connecting + Connecting + + + Connected but no Internet access + Connected but no Internet access + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Disable wired connection + + + Enable wired connection + Enable wired connection + + + Disable wireless connection + Disable wireless connection + + + Enable wireless connection + Enable wireless connection + + + Disable network + Disable network + + + Enable network + Enable network + + + Network settings + Network settings + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_US.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_US.ts new file mode 100644 index 000000000..bd1016b8a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_en_US.ts @@ -0,0 +1,283 @@ + + + + + DeviceControllItem + + Wireless Network + Wireless Network + + + Wired Network + Wired Network + + + + NetworkPlugin + + Network + Network + + + Wireless Network + Wireless Network + + + Wired Network + Wired Network + + + Connected + Connected + + + Device disabled + Device disabled + + + Network cable unplugged + Network cable unplugged + + + Not connected + Not connected + + + Connecting + Connecting + + + Obtaining address + Obtaining address + + + Connected but no Internet access + Connected but no Internet access + + + IP conflict + IP conflict + + + Connection failed + Connection failed + + + + WirelessItem + + Connect to hidden network + Connect to hidden network + + + Password + Password + + + Cancel + button + Cancel + + + Connect + button + Connect + + + Name (SSID) + Name (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Security Type + + + Band + Band + + + Channel + Channel + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmask + + + Gateway + Gateway + + + Primary DNS + Primary DNS + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Speed + + + + dde::network::NetworkDeviceRealize + + Device disabled + Device disabled + + + Connected but no Internet access + Connected but no Internet access + + + Not connected + Not connected + + + Network cable unplugged + Network cable unplugged + + + Connecting + Connecting + + + Authenticating + Authenticating + + + Obtaining IP address + Obtaining IP address + + + Connected + Connected + + + Disconnected + Disconnected + + + IP conflict + IP conflict + + + Failed + Failed + + + Obtaining address + Obtaining address + + + + dde::network::NetworkProcesser + + Wired Network + Wired Network + + + Wired Network %1 + Wired Network %1 + + + Wireless Network + Wireless Network + + + Wireless Network %1 + Wireless Network %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Device disabled + + + Network cable unplugged + Network cable unplugged + + + Not connected + Not connected + + + Connecting + Connecting + + + Connected but no Internet access + Connected but no Internet access + + + Connection failed + Connection failed + + + IP conflict + IP conflict + + + Disable wired connection + Disable wired connection + + + Enable wired connection + Enable wired connection + + + Disable wireless connection + Disable wireless connection + + + Enable wireless connection + Enable wireless connection + + + Disable network + Disable network + + + Enable network + Enable network + + + Network settings + Network settings + + + diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_es.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_es.ts new file mode 100644 index 000000000..7d974cd60 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_es.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Red inalámbrica + + + Wired Network + Red cableada + + + + NetworkPlugin + + Network + Red + + + Wireless Network + + + + Wired Network + Red cableada + + + Device disabled + Dispositivo deshabilitado + + + Network cable unplugged + Cable de red desconectado + + + Not connected + Sin conexión + + + Connecting + Conectando + + + Connected but no Internet access + Conectado pero sin acceso a Internet + + + IP conflict + Conflicto de IP + + + Connection failed + Conexión fallida + + + + WirelessItem + + Connect to hidden network + Conectarse a una red oculta + + + Password + Contraseña + + + Cancel + button + Cancelar + + + Connect + button + Conectar + + + Name (SSID) + Nombre (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Punto de acceso + + + SSID + SSID + + + Protocol + Protocolo + + + Security Type + Tipo de seguridad + + + Band + Banda + + + Channel + Canal + + + Interface + Interfaz + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Máscara de red + + + Gateway + Puerta de enlace + + + Primary DNS + DNS primario + + + IPv6 + IPv6 + + + Prefix + Prefijo + + + Speed + Velocidad + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo deshabilitado + + + Connected but no Internet access + Conectado pero sin acceso a Internet + + + Not connected + Sin conexión + + + Network cable unplugged + Cable de red desconectado + + + Connecting + Conectando + + + Authenticating + Autentificando + + + Obtaining IP address + Obteniendo dirección IP + + + Connected + Conectado + + + Disconnected + Desconectado + + + IP conflict + Conflicto de IP + + + Failed + Fallido + + + Obtaining address + Obtención de la dirección + + + + dde::network::NetworkProcesser + + Wired Network + Red cableada + + + Wired Network %1 + Red cableada %1 + + + Wireless Network + Red inalámbrica + + + Wireless Network %1 + Red inalámbrica %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo deshabilitado + + + Network cable unplugged + Cable de red desconectado + + + Not connected + Sin conexión + + + Connecting + Conectando + + + Connected but no Internet access + Conectado pero sin acceso a Internet + + + Connection failed + Conexión fallida + + + IP conflict + Conflicto de IP + + + Disable wired connection + Desactivar conexión por cable + + + Enable wired connection + Activar conexión por cable + + + Disable wireless connection + Desactivar conexión inalámbrica + + + Enable wireless connection + Activar conexión inalámbrica + + + Disable network + Desactivar red + + + Enable network + Activar red + + + Network settings + Ajustes de red + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fa.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fa.ts new file mode 100644 index 000000000..9f8a65c64 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fa.ts @@ -0,0 +1,275 @@ + + + DeviceControllItem + + + Wireless Network + شبکه بیسیم + + + + Wired Network + شبکه کابلی + + + + NetworkPanel + + + Wired connection: %1 + اتصال سیمی %1 + + + + Wired Network + شبکه کابلی + + + + Wireless connection: %1 + + + + + Wireless Network + شبکه بیسیم + + + + Device disabled + دستگاه غیرفعال است + + + + Network cable unplugged + کابل شبکه وصل نشده است + + + + Not connected + متصل نیست + + + + Connecting + در حال اتصال + + + + Connected but no Internet access + متصل است اما دسترسی به اینترنت ندارد + + + + Connection failed + + + + + Disable wired connection + + + + + Enable wired connection + + + + + Disable wireless connection + + + + + Enable wireless connection + + + + + Disable network + غیر فعال کردن شبکه + + + + Enable network + فعال کردن شبکه + + + + Network settings + تنظیمات شبکه + + + + IP conflict + + + + + NetworkPlugin + + + Network + شبکه + + + + dde::network::NetworkController + + + Wired Network + شبکه کابلی + + + + Wired Network %1 + شبکه سیمی %1 + + + + Wireless Network + شبکه بیسیم + + + + Wireless Network %1 + شبکه بی سیم %1 + + + + dde::network::NetworkDetails + + + Hotspot + هات اسپات + + + + SSID + SSID + + + + Protocol + + + + + Security Type + + + + + Band + باند + + + + Channel + کانال + + + + Interface + رابط + + + + MAC + MAC + + + + IPv4 + IPv4 + + + + Gateway + درگاه + + + + Primary DNS + DNS اولیه + + + + Netmask + Netmask + + + + IPv6 + IPv6 + + + + Prefix + پیشوند + + + + Speed + سرعت + + + + dde::network::NetworkDeviceBase + + + Disconnected + قطع اتصال + + + + Connecting + در حال اتصال + + + + Authenticating + تأیید اعتبار + + + + Obtaining address + + + + + Connected + متصل شده + + + + Failed + عدم اعمال + + + + Device disabled + دستگاه غیرفعال است + + + + Connected but no Internet access + متصل است اما دسترسی به اینترنت ندارد + + + + Not connected + متصل نیست + + + + Network cable unplugged + کابل شبکه وصل نشده است + + + + Obtaining IP address + در حال به دست آوردن نشانی IP + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fi.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fi.ts new file mode 100644 index 000000000..2e279fcb0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fi.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Langaton verkko + + + Wired Network + Kaapeli + + + + NetworkPlugin + + Network + Verkko + + + Wireless Network + + + + Wired Network + Kaapeli + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Yhdistä piilotettuun verkkoon + + + Password + Salasana + + + Cancel + button + Peruuta + + + Connect + button + Yhdistä + + + Name (SSID) + Nimi (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Tukiasema + + + SSID + SSID + + + Protocol + Protokolla + + + Security Type + Suojaustyyppi + + + Band + Taajuusalue + + + Channel + Kanava + + + Interface + Liitäntä + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Verkkopeite + + + Gateway + Yhdyskäytävä + + + Primary DNS + Ensisijainen DNS + + + IPv6 + IPv6 + + + Prefix + Etuliite + + + Speed + Nopeus + + + + dde::network::NetworkDeviceRealize + + Device disabled + Laite suljettu + + + Connected but no Internet access + Yhdistetty, mutta ei internet osoitetta + + + Not connected + Ei yhteyttä + + + Network cable unplugged + Verkkokaapeli irrotettu + + + Connecting + Yhdistää + + + Authenticating + Todennus + + + Obtaining IP address + Hakee IP osoitetta + + + Connected + Yhdistetty + + + Disconnected + Katkaistu + + + IP conflict + IP ristiriita + + + Failed + Epäonnistui + + + Obtaining address + Osoitteen haku + + + + dde::network::NetworkProcesser + + Wired Network + Kaapeli + + + Wired Network %1 + Kaapeli %1 + + + Wireless Network + Langaton verkko + + + Wireless Network %1 + Langaton verkko: %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Laite suljettu + + + Network cable unplugged + Verkkokaapeli irrotettu + + + Not connected + Ei yhteyttä + + + Connecting + Yhdistää + + + Connected but no Internet access + Yhdistetty, mutta ei internet osoitetta + + + Connection failed + Yhteys epäonnistui + + + IP conflict + IP ristiriita + + + Disable wired connection + Poista kiinteä yhteys + + + Enable wired connection + Kytke kiinteä yhteys + + + Disable wireless connection + Poista langaton käytöstä + + + Enable wireless connection + Kytke langaton käyttöön + + + Disable network + Poista verkko käytöstä + + + Enable network + Kytke verkko käyttöön + + + Network settings + Verkon asetukset + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fr.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fr.ts new file mode 100644 index 000000000..b6fd80a6d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_fr.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Réseau sans fil + + + Wired Network + Réseau filaire + + + + NetworkPlugin + + Network + Réseau + + + Wireless Network + + + + Wired Network + Réseau filaire + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Se connecter à un réseau caché + + + Password + Mot de passe + + + Cancel + button + Annuler + + + Connect + button + Relier + + + Name (SSID) + Nom (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Point d'accès + + + SSID + SSID + + + Protocol + Protocole + + + Security Type + Type de sécurité + + + Band + Bande + + + Channel + Canal + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Masque de réseau + + + Gateway + passerelle + + + Primary DNS + DNS primaire + + + IPv6 + IPv6 + + + Prefix + Préfixe + + + Speed + Vitesse + + + + dde::network::NetworkDeviceRealize + + Device disabled + Périphérique désactivé + + + Connected but no Internet access + Connecté mais pas d’accès internet + + + Not connected + Pas connecté + + + Network cable unplugged + Câble réseau débranché + + + Connecting + Connexion en cours + + + Authenticating + Authentification + + + Obtaining IP address + Obtention d'adresse IP + + + Connected + Connecté + + + Disconnected + Déconnecté + + + IP conflict + Conflit IP + + + Failed + Échoué + + + Obtaining address + Obtenir l'adresse + + + + dde::network::NetworkProcesser + + Wired Network + Réseau filaire + + + Wired Network %1 + Réseau filaire %1 + + + Wireless Network + Réseau sans fil + + + Wireless Network %1 + Réseau sans fil %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Périphérique désactivé + + + Network cable unplugged + Câble réseau débranché + + + Not connected + Pas connecté + + + Connecting + Connexion en cours + + + Connected but no Internet access + Connecté mais pas d’accès internet + + + Connection failed + La connexion a échoué + + + IP conflict + Conflit IP + + + Disable wired connection + Désactiver la connexion filaire + + + Enable wired connection + Activer la connexion filaire + + + Disable wireless connection + Désactiver la connexion sans fil + + + Enable wireless connection + Activer la connexion sans fil + + + Disable network + Désactiver le réseau + + + Enable network + Activer le réseau + + + Network settings + Paramètres réseau + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_gl_ES.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_gl_ES.ts new file mode 100644 index 000000000..bf680af54 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_gl_ES.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rede sen fíos + + + Wired Network + Rede con fíos + + + + NetworkPlugin + + Network + Rede + + + Wireless Network + + + + Wired Network + Rede con fíos + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Conectar a unha rede oculta + + + Password + Contrasinal + + + Cancel + button + Cancelar + + + Connect + button + Conectar + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Punto de acceso + + + SSID + SSID + + + Protocol + Protocolo + + + Security Type + Tipo de seguranza + + + Band + Banda + + + Channel + Canle + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Máscara de rede + + + Gateway + Pasarela + + + Primary DNS + DNS primario + + + IPv6 + IPv6 + + + Prefix + Prefixo + + + Speed + Velocidade + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo desactivado + + + Connected but no Internet access + Conectado pero sen acceso a internet + + + Not connected + Sen conexión + + + Network cable unplugged + Cabo de rede desconectado + + + Connecting + Conectando + + + Authenticating + Autenticando + + + Obtaining IP address + Obtendo o enderezo IP + + + Connected + Conectado + + + Disconnected + Desconectado + + + IP conflict + + + + Failed + Con erros + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Rede con fíos + + + Wired Network %1 + Rede con fíos % 1 + + + Wireless Network + Rede sen fíos + + + Wireless Network %1 + Rede sen fíos %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo desactivado + + + Network cable unplugged + Cabo de rede desconectado + + + Not connected + Sen conexión + + + Connecting + Conectando + + + Connected but no Internet access + Conectado pero sen acceso a internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Desactivar a conexión con fíos + + + Enable wired connection + Activa a conexión con fíos + + + Disable wireless connection + Desactivar a conexión sen fíos + + + Enable wireless connection + Activar a conexión sen fíos + + + Disable network + Desactivar a rede + + + Enable network + Activar a rede + + + Network settings + Axustes da rede + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hi_IN.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hi_IN.ts new file mode 100644 index 000000000..c5f216012 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hi_IN.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + केबल रहित नेटवर्क + + + Wired Network + केबल नेटवर्क + + + + NetworkPlugin + + Network + नेटवर्क + + + Wireless Network + + + + Wired Network + केबल नेटवर्क + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + छुपे नेटवर्क से जुड़ें + + + Password + कूटशब्द + + + Cancel + button + रद्द करें + + + Connect + button + कनेक्ट करें + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + हॉटस्पॉट + + + SSID + SSID + + + Protocol + प्रोटोकॉल + + + Security Type + सुरक्षा प्रकार + + + Band + बैंड + + + Channel + चैनल + + + Interface + इंटरफेस + + + MAC + MAC + + + IPv4 + आईपीवी4 + + + Netmask + Netmask + + + Gateway + नेटवर्क गेटवे + + + Primary DNS + प्राथमिक DNS + + + IPv6 + आईपीवी6 + + + Prefix + नेटवर्क उपसर्ग + + + Speed + गति + + + + dde::network::NetworkDeviceRealize + + Device disabled + उपकरण निष्क्रिय है + + + Connected but no Internet access + कनेक्ट है परंतु नेटवर्क हेतु अभिगम नहीं है + + + Not connected + कनेक्ट नहीं है + + + Network cable unplugged + नेटवर्क केबल हटी हुई है + + + Connecting + कनेक्ट हो रहा है + + + Authenticating + प्रमाणीकृत किया जा रहा है + + + Obtaining IP address + IP अड्रेस प्राप्त किया जा रहा है + + + Connected + कनेक्ट है + + + Disconnected + डिस्कनेक्ट है + + + IP conflict + आईपी विरोधाभास + + + Failed + विफल रहा + + + Obtaining address + नेटवर्क पता प्राप्त करना जारी + + + + dde::network::NetworkProcesser + + Wired Network + केबल नेटवर्क + + + Wired Network %1 + केबल नेटवर्क %1 + + + Wireless Network + केबल रहित नेटवर्क + + + Wireless Network %1 + केबल रहित नेटवर्क %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + उपकरण निष्क्रिय है + + + Network cable unplugged + नेटवर्क केबल हटी हुई है + + + Not connected + कनेक्ट नहीं है + + + Connecting + कनेक्ट हो रहा है + + + Connected but no Internet access + कनेक्ट है परंतु नेटवर्क हेतु अभिगम नहीं है + + + Connection failed + कनेक्ट करना विफल रहा + + + IP conflict + आईपी विरोधाभास + + + Disable wired connection + केबल कनेक्शन निष्क्रिय करें + + + Enable wired connection + केबल कनेक्शन सक्रिय करें + + + Disable wireless connection + केबल रहित कनेक्शन निष्क्रिय करें + + + Enable wireless connection + केबल रहित कनेक्शन सक्रिय करें + + + Disable network + नेटवर्क निष्क्रिय करें + + + Enable network + नेटवर्क सक्रिय करें + + + Network settings + नेटवर्क सेटिंग्स + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hr.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hr.ts new file mode 100644 index 000000000..d4882db30 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hr.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Bežična mreža + + + Wired Network + Žična mreža + + + + NetworkPlugin + + Network + Mreža + + + Wireless Network + + + + Wired Network + Žična mreža + + + Device disabled + Uređaj je onemogućen + + + Network cable unplugged + Mrežni kabel je isključen + + + Not connected + Nije spojeno + + + Connecting + Povezujem se + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Poveži na skrivenu mrežu + + + Password + Lozinka + + + Cancel + button + Otkaži + + + Connect + button + Poveži + + + Name (SSID) + Ime (SSID) + + + + dde::network::NetworkDetails + + Hotspot + + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Vrsta sigurnosti + + + Band + Frekvencija + + + Channel + Kanal + + + Interface + Sučelje + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Maska podmreže + + + Gateway + Pristupnik + + + Primary DNS + Primaran DNS + + + IPv6 + IPv6 + + + Prefix + Prefiks + + + Speed + Brzina + + + + dde::network::NetworkDeviceRealize + + Device disabled + Uređaj je onemogućen + + + Connected but no Internet access + Spojen ali nema pristupa internetu + + + Not connected + Nije spojeno + + + Network cable unplugged + Mrežni kabel je isključen + + + Connecting + Povezujem se + + + Authenticating + Autentifikacija + + + Obtaining IP address + Dobivam IP adresu + + + Connected + Spojeno + + + Disconnected + Odspojeno + + + IP conflict + + + + Failed + Neuspjelo + + + Obtaining address + Dobivanje adrese + + + + dde::network::NetworkProcesser + + Wired Network + Žična mreža + + + Wired Network %1 + Žična mreža %1 + + + Wireless Network + Bežična mreža + + + Wireless Network %1 + Bežična mreža %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Uređaj je onemogućen + + + Network cable unplugged + Mrežni kabel je isključen + + + Not connected + Nije spojeno + + + Connecting + Povezujem se + + + Connected but no Internet access + Spojen ali nema pristupa internetu + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Onemogući žično povezivanje + + + Enable wired connection + Omogući žično povezivanje + + + Disable wireless connection + Onemogući bežično povezivaqnje + + + Enable wireless connection + Omogući bežično povezivanje + + + Disable network + Onemogući mrežu + + + Enable network + Omogući mrežu + + + Network settings + Mrežne postavke + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hu.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hu.ts new file mode 100644 index 000000000..34cb39467 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_hu.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Vezeték nélküli hálózat + + + Wired Network + Vezetékes hálózat + + + + NetworkPlugin + + Network + Hálózat + + + Wireless Network + Vezeték nélküli hálózat + + + Wired Network + Vezetékes hálózat + + + Device disabled + Eszköz letiltva + + + Network cable unplugged + A hálózati kábel kihúzva + + + Not connected + Nincs csatlakozva + + + Connecting + Csatlakozás + + + Connected but no Internet access + Csatlakoztatva, de nincs internet hozzáférés + + + IP conflict + IP cím ütközés + + + Connection failed + A kapcsolódás sikertelen + + + + WirelessItem + + Connect to hidden network + Csatlakozás rejtett hálózathoz + + + Password + Jelszó + + + Cancel + button + Mégsem + + + Connect + button + Kapcsolódás + + + Name (SSID) + Név (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protokoll + + + Security Type + Biztonság típusa + + + Band + Sáv + + + Channel + Csatorna + + + Interface + Felület + + + MAC + MAC cím + + + IPv4 + IPv4 + + + Netmask + Hálózati maszk + + + Gateway + Átjáró + + + Primary DNS + Elsődleges DNS + + + IPv6 + IPv6 + + + Prefix + Előtag + + + Speed + Sebesség + + + + dde::network::NetworkDeviceRealize + + Device disabled + Eszköz letiltva + + + Connected but no Internet access + Csatlakoztatva, de nincs internet hozzáférés + + + Not connected + Nincs csatlakozva + + + Network cable unplugged + A hálózati kábel kihúzva + + + Connecting + Csatlakozás + + + Authenticating + Hitelesítés + + + Obtaining IP address + IP cím lekérése + + + Connected + Csatlakozva + + + Disconnected + Szétkapcsolva + + + IP conflict + IP cím ütközés + + + Failed + Sikertelen + + + Obtaining address + Cím lekérése + + + + dde::network::NetworkProcesser + + Wired Network + Vezetékes hálózat + + + Wired Network %1 + Vezetékes hálózat %1 + + + Wireless Network + Vezeték nélküli hálózat + + + Wireless Network %1 + Vezeték nélküli hálózat %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Eszköz letiltva + + + Network cable unplugged + A hálózati kábel kihúzva + + + Not connected + Nincs csatlakozva + + + Connecting + Csatlakozás + + + Connected but no Internet access + Csatlakoztatva, de nincs internet hozzáférés + + + Connection failed + A kapcsolódás sikertelen + + + IP conflict + IP cím ütközés + + + Disable wired connection + Vezetékes kapcsolat letiltása + + + Enable wired connection + Vezetékes kapcsolat engedélyezése + + + Disable wireless connection + Vezeték-nélküli kapcsolat letiltása + + + Enable wireless connection + Vezeték nélküli kapcsolat engedélyezése + + + Disable network + Hálózat letiltása + + + Enable network + Hálózat engedélyezése + + + Network settings + Hálózati beállítások + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_it.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_it.ts new file mode 100644 index 000000000..b08185a43 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_it.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Connessione WiFi + + + Wired Network + Connessione cablata + + + + NetworkPlugin + + Network + Rete + + + Wireless Network + + + + Wired Network + Connessione cablata + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Connetti ad una rete nascosta + + + Password + Password + + + Cancel + button + Annulla + + + Connect + button + Connetti + + + Name (SSID) + Nome (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocollo + + + Security Type + Tipo sicurezza + + + Band + Banda + + + Channel + Canale + + + Interface + Interfaccia + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmask + + + Gateway + Gateway + + + Primary DNS + DNS Primario + + + IPv6 + IPv6 + + + Prefix + Prefisso + + + Speed + Velocità + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo disattivato + + + Connected but no Internet access + Connesso senza accesso ad internet + + + Not connected + Non connesso + + + Network cable unplugged + Cavo di rete scollegato + + + Connecting + Connessione in corso + + + Authenticating + Autentificazione in corso + + + Obtaining IP address + Ottenimento indirizzo IP + + + Connected + Connesso + + + Disconnected + Disconnesso + + + IP conflict + Conflitto IP + + + Failed + Connessione fallita + + + Obtaining address + Ottenimento indirizzo + + + + dde::network::NetworkProcesser + + Wired Network + Connessione cablata + + + Wired Network %1 + Connessione cablata %1 + + + Wireless Network + Connessione WiFi + + + Wireless Network %1 + Rete wireless %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo disattivato + + + Network cable unplugged + Cavo di rete scollegato + + + Not connected + Non connesso + + + Connecting + Connessione in corso + + + Connected but no Internet access + Connesso senza accesso ad internet + + + Connection failed + Connessione fallita + + + IP conflict + Conflitto IP + + + Disable wired connection + Disattiva connessione cablata + + + Enable wired connection + Attiva connessione cablata + + + Disable wireless connection + Disattiva connessione WiFi + + + Enable wireless connection + Attiva connessione WiFi + + + Disable network + Disabilita Rete + + + Enable network + Abilita Rete + + + Network settings + Impostazioni Rete + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ja.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ja.ts new file mode 100644 index 000000000..509e556a8 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ja.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + 無線ネットワーク + + + Wired Network + 有線ネットワーク + + + + NetworkPlugin + + Network + ネットワーク + + + Wireless Network + + + + Wired Network + 有線ネットワーク + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + 非表示のネットワークへ接続 + + + Password + パスワード + + + Cancel + button + キャンセル + + + Connect + button + 接続 + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + ホットスポット + + + SSID + SSID + + + Protocol + プロトコル + + + Security Type + セキュリティタイプ + + + Band + バンド + + + Channel + チャンネル + + + Interface + インターフェース + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + ネットマスク + + + Gateway + ゲートウェイ + + + Primary DNS + プライマリ DNS + + + IPv6 + IPv6 + + + Prefix + プレフィックス + + + Speed + 速度 + + + + dde::network::NetworkDeviceRealize + + Device disabled + デバイスが無効 + + + Connected but no Internet access + 接続済み、インターネットアクセスなし + + + Not connected + 未接続 + + + Network cable unplugged + ネットワークケーブル未接続 + + + Connecting + 接続試行中 + + + Authenticating + 認証中 + + + Obtaining IP address + IP アドレスを取得中 + + + Connected + 接続済み + + + Disconnected + 切断 + + + IP conflict + + + + Failed + 失敗 + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + 有線ネットワーク + + + Wired Network %1 + 有線ネットワーク %1 + + + Wireless Network + 無線ネットワーク + + + Wireless Network %1 + 無線接続 %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + デバイスが無効 + + + Network cable unplugged + ネットワークケーブル未接続 + + + Not connected + 未接続 + + + Connecting + 接続試行中 + + + Connected but no Internet access + 接続済み、インターネットアクセスなし + + + Connection failed + + + + IP conflict + + + + Disable wired connection + 有線接続を無効にする + + + Enable wired connection + 有線接続を有効にする + + + Disable wireless connection + 無線接続を無効にする + + + Enable wireless connection + 無線接続を有効にする + + + Disable network + ネットワークを無効にする + + + Enable network + ネットワークを有効にする + + + Network settings + ネットワーク設定 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_kab.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_kab.ts new file mode 100644 index 000000000..aa84380a0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_kab.ts @@ -0,0 +1,201 @@ + + + NetworkPlugin + + Network + Azeḍḍa + + + + dde::network::NetworkDetails + + Hotspot + + + + SSID + SSID + + + Protocol + Apṛutukul + + + Security Type + Anaw n tɣellist + + + Band + Tasfift + + + Channel + Abadu + + + Interface + Agrudem + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Tagelmust n uzeṭṭa + + + Gateway + Tileggit + + + Primary DNS + DNS agejdan + + + IPv6 + IPv6 + + + Prefix + Uzwir + + + Speed + Arured + + + + dde::network::NetworkDeviceRealize + + Device disabled + Ibenk yensa + + + Connected but no Internet access + Yeqqen maca ulac adduf ɣer internet + + + Not connected + Ur yeqqin ara + + + Network cable unplugged + Agatu n uzeḍḍa yenser + + + Connecting + Tuqqna + + + Authenticating + Asesteb + + + Obtaining IP address + Awway n tansa n IP + + + Connected + Yeqqen + + + Disconnected + Yeffeɣ seg tuqqna + + + IP conflict + + + + Failed + Ur yeddi ara + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Azeṭṭa agatwan + + + Wired Network %1 + Azeḍḍa s tnelli %1 + + + Wireless Network + Azeṭṭa war tinelli + + + Wireless Network %1 + Azeṭṭa war tinelli %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Ibenk yensa + + + Network cable unplugged + Agatu n uzeḍḍa yenser + + + Not connected + Ur yeqqin ara + + + Connecting + Tuqqna + + + Connected but no Internet access + Yeqqen maca ulac adduf ɣer internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Sens tuqqna n tnelli + + + Enable wired connection + Srmed tuqqna n tnelli + + + Disable wireless connection + Sens tuqqna war tinelli + + + Enable wireless connection + Sermed tuqqna war tinelli + + + Disable network + Sens azeḍḍa + + + Enable network + Sexsi azeḍḍa + + + Network settings + Iɣewwaren n uzeḍḍa + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ko.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ko.ts new file mode 100644 index 000000000..0b7489a40 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ko.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + 무선 네트워크 + + + Wired Network + 유선 네트워크 + + + + NetworkPlugin + + Network + 네트워크 + + + Wireless Network + + + + Wired Network + 유선 네트워크 + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + 숨겨진 네트워크에 연결 + + + Password + 비밀번호 + + + Cancel + button + 취소 + + + Connect + button + 연결 + + + Name (SSID) + 명칭(SSID) + + + + dde::network::NetworkDetails + + Hotspot + 핫스팟 + + + SSID + SSID + + + Protocol + 프로토콜 + + + Security Type + 보안 유형 + + + Band + 밴드 + + + Channel + 채널 + + + Interface + 인터페이스 + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + 넷마스크 + + + Gateway + 게이트웨이 + + + Primary DNS + 기본 DNS + + + IPv6 + IPv6 + + + Prefix + 접두사 + + + Speed + 속도 + + + + dde::network::NetworkDeviceRealize + + Device disabled + 디바이스 사용해제됨 + + + Connected but no Internet access + 연결됨, 인터넷 없음 + + + Not connected + 연결되지 않음 + + + Network cable unplugged + 네트워크 케이블이 연결되어 있지 않습니다. + + + Connecting + 연결 중 + + + Authenticating + 인증 중 + + + Obtaining IP address + IP 주소 가져오는 중 + + + Connected + 연결됨 + + + Disconnected + 연결 끊김 + + + IP conflict + IP 충돌 + + + Failed + 실패 + + + Obtaining address + 주소 불러오는 중 + + + + dde::network::NetworkProcesser + + Wired Network + 유선 네트워크 + + + Wired Network %1 + 유선 네트워크 %1 + + + Wireless Network + 무선 네트워크 + + + Wireless Network %1 + 무선 네트워크 %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + 디바이스 사용해제됨 + + + Network cable unplugged + 네트워크 케이블이 연결되어 있지 않습니다. + + + Not connected + 연결되지 않음 + + + Connecting + 연결 중 + + + Connected but no Internet access + 연결됨, 인터넷 없음 + + + Connection failed + 연결 실패 + + + IP conflict + IP 충돌 + + + Disable wired connection + 유선 연결 사용안함 + + + Enable wired connection + 유선 연결 사용가능 + + + Disable wireless connection + 무선 연결 사용안함 + + + Enable wireless connection + 무선 연결 사용가능 + + + Disable network + 네트워크 사용안함 + + + Enable network + 네트워크 사용 + + + Network settings + 네트워크 설정 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_lt.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_lt.ts new file mode 100644 index 000000000..843b90f35 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_lt.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Belaidis tinklas + + + Wired Network + Laidinis tinklas + + + + NetworkPlugin + + Network + Tinklas + + + Wireless Network + + + + Wired Network + Laidinis tinklas + + + Device disabled + Įrenginys išjungtas + + + Network cable unplugged + Atjungtas tinklo laidas + + + Not connected + Neprijungta + + + Connecting + Jungiamasi + + + Connected but no Internet access + Prisijungta, bet nėra prieigos prie interneto + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Prisijungti prie paslėpto tinklo + + + Password + Slaptažodis + + + Cancel + button + Atsisakyti + + + Connect + button + Prisijungti + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Prieigos taškas + + + SSID + SSID + + + Protocol + Protokolas + + + Security Type + Saugumo tipas + + + Band + Juosta + + + Channel + Kanalas + + + Interface + Sąsaja + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Tinklo kaukė + + + Gateway + Tinklų sietuvas + + + Primary DNS + Pirminis DNS + + + IPv6 + IPv6 + + + Prefix + Priešdelis + + + Speed + Greitis + + + + dde::network::NetworkDeviceRealize + + Device disabled + Įrenginys išjungtas + + + Connected but no Internet access + Prisijungta, bet nėra prieigos prie interneto + + + Not connected + Neprijungta + + + Network cable unplugged + Atjungtas tinklo laidas + + + Connecting + Jungiamasi + + + Authenticating + Nustatoma tapatybė + + + Obtaining IP address + Gaunamas IP adresas + + + Connected + Prisijungta + + + Disconnected + Atsijungta + + + IP conflict + + + + Failed + Nepavyko + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Laidinis tinklas + + + Wired Network %1 + Laidinis tinklas %1 + + + Wireless Network + Belaidis tinklas + + + Wireless Network %1 + Belaidis tinklas %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Įrenginys išjungtas + + + Network cable unplugged + Atjungtas tinklo laidas + + + Not connected + Neprijungta + + + Connecting + Jungiamasi + + + Connected but no Internet access + Prisijungta, bet nėra prieigos prie interneto + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Išjungti laidinį ryšį + + + Enable wired connection + Įjungti laidinį ryšį + + + Disable wireless connection + Išjungti belaidį ryšį + + + Enable wireless connection + Įjungti belaidį ryšį + + + Disable network + Išjungti tinklą + + + Enable network + Įjungti tinklą + + + Network settings + Tinklo nustatymai + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ms.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ms.ts new file mode 100644 index 000000000..a0ed33ef3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ms.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rangkaian Tanpa Wayar + + + Wired Network + Rangkaian Berwayar + + + + NetworkPlugin + + Network + Rangkaian + + + Wireless Network + + + + Wired Network + Rangkaian Berwayar + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Sambung ke rangkaian tersembunyi + + + Password + Kata Laluan + + + Cancel + button + Batal + + + Connect + button + Sambung + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Kawasan Khas + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Jenis Keselamatan + + + Band + Jalur + + + Channel + Saluran + + + Interface + Antara Muka + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Topeng Rangkaian + + + Gateway + Get Laluan + + + Primary DNS + DNS Utama + + + IPv6 + IPv6 + + + Prefix + Awalan + + + Speed + Kelajuan + + + + dde::network::NetworkDeviceRealize + + Device disabled + Peranti dilumpuhkan + + + Connected but no Internet access + Bersambung tetapi tiada capaian Internet + + + Not connected + Tidak bersambung + + + Network cable unplugged + Kabel rangkaian telah dicabut + + + Connecting + Menyambung + + + Authenticating + Mengesahihkan + + + Obtaining IP address + Mendapatkan alamat IP + + + Connected + Bersambung + + + Disconnected + Terputus + + + IP conflict + IP berkonflik + + + Failed + Gagal + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Rangkaian Berwayar + + + Wired Network %1 + Rangkaian Berwayar %1 + + + Wireless Network + Rangkaian Tanpa Wayar + + + Wireless Network %1 + Sambungan Tanpa Wayar %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Peranti dilumpuhkan + + + Network cable unplugged + Kabel rangkaian telah dicabut + + + Not connected + Tidak bersambung + + + Connecting + Menyambung + + + Connected but no Internet access + Bersambung tetapi tiada capaian Internet + + + Connection failed + Sambungan gagal + + + IP conflict + IP berkonflik + + + Disable wired connection + Lumpuhkan sambungan berwayar + + + Enable wired connection + Benarkan sambungan berwayar + + + Disable wireless connection + Lumpuhkan sambungan tanpa wayar + + + Enable wireless connection + Benarkan sambungan tanpa wayar + + + Disable network + Lumpuhkan rangkaian + + + Enable network + Benarkan rangkaian + + + Network settings + Tetapan rangkaian + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_nl.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_nl.ts new file mode 100644 index 000000000..19e065884 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_nl.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Draadloos netwerk + + + Wired Network + Bekabeld netwerk + + + + NetworkPlugin + + Network + Netwerk + + + Wireless Network + + + + Wired Network + Bekabeld netwerk + + + Device disabled + Apparaat uitgeschakeld + + + Network cable unplugged + Geen netwerkkabel aangesloten + + + Not connected + Niet verbonden + + + Connecting + Bezig met verbinden… + + + Connected but no Internet access + Verbonden, maar geen internettoegang + + + IP conflict + IP-conflict + + + Connection failed + Verbinding mislukt + + + + WirelessItem + + Connect to hidden network + Verbinden met verborgen netwerk + + + Password + Wachtwoord + + + Cancel + button + Annuleren + + + Connect + button + Verbinden + + + Name (SSID) + Naam (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Soort beveiliging + + + Band + Band + + + Channel + Kanaal + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Netmasker + + + Gateway + Gateway + + + Primary DNS + Primaire dns-server + + + IPv6 + IPv6 + + + Prefix + Voorvoegsel + + + Speed + Snelheid + + + + dde::network::NetworkDeviceRealize + + Device disabled + Apparaat uitgeschakeld + + + Connected but no Internet access + Verbonden, maar geen internettoegang + + + Not connected + Niet verbonden + + + Network cable unplugged + Geen netwerkkabel aangesloten + + + Connecting + Bezig met verbinden… + + + Authenticating + Bezig met authenticeren… + + + Obtaining IP address + Bezig met verkrijgen van ip-adres… + + + Connected + Verbonden + + + Disconnected + Niet verbonden + + + IP conflict + IP-conflict + + + Failed + Mislukt + + + Obtaining address + Bezig met verkrijgen van adres… + + + + dde::network::NetworkProcesser + + Wired Network + Bekabeld netwerk + + + Wired Network %1 + Bekabeld netwerk: %1 + + + Wireless Network + Draadloos netwerk + + + Wireless Network %1 + Draadloos netwerk: %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Apparaat uitgeschakeld + + + Network cable unplugged + Geen netwerkkabel aangesloten + + + Not connected + Niet verbonden + + + Connecting + Bezig met verbinden… + + + Connected but no Internet access + Verbonden, maar geen internettoegang + + + Connection failed + Verbinding mislukt + + + IP conflict + IP-conflict + + + Disable wired connection + Bekabelde verbinding uitschakelen + + + Enable wired connection + Bekabelde verbinding inschakelen + + + Disable wireless connection + Draadloze verbinding uitschakelen + + + Enable wireless connection + Draadloze verbinding inschakelen + + + Disable network + Netwerk uitschakelen + + + Enable network + Netwerk inschakelen + + + Network settings + Netwerkinstellingen + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pl.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pl.ts new file mode 100644 index 000000000..a8f27f07c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pl.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + Sieć bezprzewodowa + + + Wired Network + Sieć przewodowa + + + + NetworkPlugin + + Network + Sieć + + + Wireless Network + Sieć bezprzewodowa + + + Wired Network + Sieć przewodowa + + + Connected + + + + Device disabled + Urządzenie wyłączone + + + Network cable unplugged + Kabel sieciowy odłączony + + + Not connected + Nie połączono + + + Connecting + Łączenie + + + Obtaining address + + + + Connected but no Internet access + Połączono, brak dostępu do Internetu + + + IP conflict + Konflikt adresów IP + + + Connection failed + Połączenie nieudane + + + + WirelessItem + + Connect to hidden network + Połącz z siecią ukrytą + + + Password + Hasło + + + Cancel + button + Anuluj + + + Connect + button + Połącz + + + Name (SSID) + Nazwa (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protokół + + + Security Type + Typ zabezpieczenia + + + Band + Pasmo + + + Channel + Kanał + + + Interface + Interfejs + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Maska sieci + + + Gateway + Brama + + + Primary DNS + Podstawowy DNS + + + IPv6 + IPv6 + + + Prefix + Prefiks + + + Speed + Prędkość + + + + dde::network::NetworkDeviceRealize + + Device disabled + Urządzenie wyłączone + + + Connected but no Internet access + Połączono, brak dostępu do Internetu + + + Not connected + Nie połączono + + + Network cable unplugged + Kabel sieciowy odłączony + + + Connecting + Łączenie + + + Authenticating + Uwierzytelnianie + + + Obtaining IP address + Uzyskiwanie adresu IP + + + Connected + Połączono + + + Disconnected + Rozłączono + + + IP conflict + Konflikt IP + + + Failed + Wystąpił błąd + + + Obtaining address + Uzyskiwanie adresu + + + + dde::network::NetworkProcesser + + Wired Network + Połączenie przewodowe + + + Wired Network %1 + Połączenie przewodowe %1 + + + Wireless Network + Połączenie bezprzewodowe + + + Wireless Network %1 + Połączenie bezprzewodowe %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Urządzenie wyłączone + + + Network cable unplugged + Kabel sieciowy odłączony + + + Not connected + Nie połączono + + + Connecting + Łączenie + + + Connected but no Internet access + Połączono, brak dostępu do Internetu + + + Connection failed + Połączenie nieudane + + + IP conflict + Konflikt IP + + + Disable wired connection + Wyłącz połączenie przewodowe + + + Enable wired connection + Włącz połączenie przewodowe + + + Disable wireless connection + Wyłącz połączenie bezprzewodowe + + + Enable wireless connection + Włącz połączenie bezprzewodowe + + + Disable network + Wyłącz sieć + + + Enable network + Włącz sieć + + + Network settings + Ustawienia sieci + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt.ts new file mode 100644 index 000000000..aaacc8089 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rede sem fios + + + Wired Network + Rede por cabo + + + + NetworkPlugin + + Network + Rede + + + Wireless Network + + + + Wired Network + Rede por cabo + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Ligar a uma rede oculta + + + Password + Palavra-passe + + + Cancel + button + Cancelar + + + Connect + button + Ligar + + + Name (SSID) + Nome (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Ponto de Acesso + + + SSID + SSID + + + Protocol + Protocolo + + + Security Type + Tipo de Segurança + + + Band + Banda + + + Channel + Canal + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Máscara de rede + + + Gateway + Gateway + + + Primary DNS + DNS Principal + + + IPv6 + IPv6 + + + Prefix + Prefixo + + + Speed + Velocidade + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo desativado + + + Connected but no Internet access + Ligado mas sem acesso à Internet + + + Not connected + Não ligado + + + Network cable unplugged + Cabo de rede desligado + + + Connecting + A ligar + + + Authenticating + A autenticar + + + Obtaining IP address + A obter endereço de IP + + + Connected + Ligado + + + Disconnected + Desligado + + + IP conflict + Conflito de IP + + + Failed + Falha + + + Obtaining address + A obter endereço + + + + dde::network::NetworkProcesser + + Wired Network + Rede por cabo + + + Wired Network %1 + Rede por cabo %1 + + + Wireless Network + Rede sem fios + + + Wireless Network %1 + Rede sem fios %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo desativado + + + Network cable unplugged + Cabo de rede desligado + + + Not connected + Não ligado + + + Connecting + A ligar + + + Connected but no Internet access + Ligado mas sem acesso à Internet + + + Connection failed + Falha na ligação + + + IP conflict + Conflito de IP + + + Disable wired connection + Desativar ligação por cabo + + + Enable wired connection + Ativar ligação por cabo + + + Disable wireless connection + Desativar ligação sem fios + + + Enable wireless connection + Ativar ligação sem fios + + + Disable network + Desativar rede + + + Enable network + Ativar rede + + + Network settings + Definições de rede + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt_BR.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt_BR.ts new file mode 100644 index 000000000..ff1247eb2 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_pt_BR.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rede Wi-Fi + + + Wired Network + Rede Cabeada + + + + NetworkPlugin + + Network + Rede + + + Wireless Network + + + + Wired Network + Rede Cabeada + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Conectar-se à rede oculta + + + Password + Senha + + + Cancel + button + Cancelar + + + Connect + button + Conectar + + + Name (SSID) + Nome (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocolo + + + Security Type + Tipo de Segurança + + + Band + Frequência + + + Channel + Canal + + + Interface + Interface + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Máscara de Sub-rede + + + Gateway + Gateway + + + Primary DNS + DNS Primário + + + IPv6 + IPv6 + + + Prefix + Prefixo + + + Speed + Velocidade + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispositivo desabilitado + + + Connected but no Internet access + Conectado, sem internet + + + Not connected + Não conectado + + + Network cable unplugged + Cabo de rede desconectado + + + Connecting + Conectando + + + Authenticating + Autenticando + + + Obtaining IP address + Obtendo endereço IP + + + Connected + Conectado + + + Disconnected + Desconectado + + + IP conflict + Conflito de IP + + + Failed + Falhou + + + Obtaining address + Obtendo endereço + + + + dde::network::NetworkProcesser + + Wired Network + Rede Cabeada + + + Wired Network %1 + Rede Cabeada %1 + + + Wireless Network + Rede Wi-Fi + + + Wireless Network %1 + Rede Wi-Fi %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispositivo desabilitado + + + Network cable unplugged + Cabo de rede desconectado + + + Not connected + Não conectado + + + Connecting + Conectando + + + Connected but no Internet access + Conectado, sem internet + + + Connection failed + A conexão falhou + + + IP conflict + Conflito de IP + + + Disable wired connection + Desativar conexão cabeada + + + Enable wired connection + Ativar conexão cabeada + + + Disable wireless connection + Desativar conexão Wi-Fi + + + Enable wireless connection + Ativar conexão Wi-Fi + + + Disable network + Desativar rede + + + Enable network + Ativar rede + + + Network settings + Configurações de rede + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ro.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ro.ts new file mode 100644 index 000000000..7f64c62e0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ro.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Rețea fără fir + + + Wired Network + Rețea conectată + + + + NetworkPlugin + + Network + Reţea + + + Wireless Network + + + + Wired Network + Rețea conectată + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Conectare la rețele ascunse + + + Password + Parola + + + Cancel + button + Anulează + + + Connect + button + Conectare + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protocol + + + Security Type + Tip Securitate + + + Band + Bandă + + + Channel + Canal + + + Interface + Interfață + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Mască de rețea + + + Gateway + Portalul + + + Primary DNS + DNS primar + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Viteză + + + + dde::network::NetworkDeviceRealize + + Device disabled + Dispozitiv Dezactivat + + + Connected but no Internet access + Conectat dar fară acces Internet + + + Not connected + Neconectat + + + Network cable unplugged + Cablu Reţea Deconectat + + + Connecting + Conectare + + + Authenticating + Autentificare + + + Obtaining IP address + Obţinere Adresă IP + + + Connected + Conectat + + + Disconnected + Deconectat + + + IP conflict + + + + Failed + Eșuat + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Rețea conectată + + + Wired Network %1 + Rețea Cablu %1 + + + Wireless Network + Rețea fără fir + + + Wireless Network %1 + Rețea fără fir %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Dispozitiv Dezactivat + + + Network cable unplugged + Cablu Reţea Deconectat + + + Not connected + Neconectat + + + Connecting + Conectare + + + Connected but no Internet access + Conectat dar fară acces Internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Dezactivați conexiunea prin cablu + + + Enable wired connection + Activați conexiunea prin cablu + + + Disable wireless connection + Dezactivați conexiunea fără fir + + + Enable wireless connection + Activați conexiunea fără fir + + + Disable network + Dezactivați conexiunea la rețea + + + Enable network + Activați rețeaua + + + Network settings + Configurări de rețea + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ru.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ru.ts new file mode 100644 index 000000000..d3d398a37 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ru.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Беспроводная сеть + + + Wired Network + Проводная сеть + + + + NetworkPlugin + + Network + Сеть + + + Wireless Network + + + + Wired Network + Проводная сеть + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Подключиться к скрытой сети + + + Password + Пароль + + + Cancel + button + Отмена + + + Connect + button + Подключить + + + Name (SSID) + Имя (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Точка доступа + + + SSID + SSID + + + Protocol + Протокол + + + Security Type + Тип безопасности + + + Band + Диапазон + + + Channel + Канал + + + Interface + Интерфейс + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Маска сети + + + Gateway + Шлюз + + + Primary DNS + Основной DNS + + + IPv6 + IPv6 + + + Prefix + Префикс + + + Speed + Скорость + + + + dde::network::NetworkDeviceRealize + + Device disabled + Устройство отключено + + + Connected but no Internet access + Подключено, без доступа к Интернету + + + Not connected + Не подключено + + + Network cable unplugged + Сетевой кабель отключен + + + Connecting + Соединение + + + Authenticating + Аутентификация + + + Obtaining IP address + Получение IP адреса + + + Connected + Подключено + + + Disconnected + Отключено + + + IP conflict + Конфликт IP-адресов + + + Failed + Ошибка + + + Obtaining address + Получение адреса + + + + dde::network::NetworkProcesser + + Wired Network + Проводная сеть + + + Wired Network %1 + Проводная сеть %1 + + + Wireless Network + Беспроводная сеть + + + Wireless Network %1 + Беспроводная сеть %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Устройство отключено + + + Network cable unplugged + Сетевой кабель отключен + + + Not connected + Не подключено + + + Connecting + Соединение + + + Connected but no Internet access + Подключено, без доступа к Интернету + + + Connection failed + Ошибка подключения + + + IP conflict + Конфликт IP-адресов + + + Disable wired connection + Отключить проводное соединение + + + Enable wired connection + Включить проводное соединение + + + Disable wireless connection + Отключить проводное соединение + + + Enable wireless connection + Включить проводное соединение + + + Disable network + Отключить сеть + + + Enable network + Включить сеть + + + Network settings + Настройки сети + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_si.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_si.ts new file mode 100644 index 000000000..e7f49d0f9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_si.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + රැහැන් රහිත ජාලය + + + Wired Network + රැහැන්ගත ජාලය + + + + NetworkPlugin + + Network + ජාලය + + + Wireless Network + + + + Wired Network + රැහැන්ගත ජාලය + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + සැඟවුණු ජාලයකට සම්බන්ධ වන්න + + + Password + මුර පදය + + + Cancel + button + අවලංගු කරන්න + + + Connect + button + සම්බන්ධ කරන්න + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + හොට්ස්පොට් + + + SSID + SSID + + + Protocol + ප්රොටෝකෝලය + + + Security Type + ආරක්ෂක වර්ගය + + + Band + කලාපය + + + Channel + නාලිකාව + + + Interface + අතුරුමුහුණත + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + නෙට්මාස්ක් + + + Gateway + දොරටුව-gateway + + + Primary DNS + ප්‍රාථමික DNS + + + IPv6 + IPv6 + + + Prefix + උපසර්ගය + + + Speed + වේගය + + + + dde::network::NetworkDeviceRealize + + Device disabled + උපාංගය අක්‍රීය කර ඇත + + + Connected but no Internet access + ජාලගතව ඇතත් අන්තර්ජාල ප්‍රවේශය නොමැත + + + Not connected + සම්බන්ධතා නොමැත + + + Network cable unplugged + ජාල කේබලය විසන්ධි කර ඇත + + + Connecting + සම්බන්ධ වෙමින් පවතී + + + Authenticating + සත්‍යාපනය කිරීම + + + Obtaining IP address + IP ලිපිනය ලබා ගැනීම + + + Connected + සම්බන්ධයි + + + Disconnected + විසන්ධි වි ඇත + + + IP conflict + + + + Failed + අසමත් විය + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + රැහැන්ගත ජාලය + + + Wired Network %1 + රැහැන්ගත ජාලය %1 + + + Wireless Network + රැහැන් රහිත ජාලය + + + Wireless Network %1 + රැහැන් රහිත ජාලය %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + උපාංගය අක්‍රීය කර ඇත + + + Network cable unplugged + ජාල කේබලය විසන්ධි කර ඇත + + + Not connected + සම්බන්ධතා නොමැත + + + Connecting + සම්බන්ධ වෙමින් පවතී + + + Connected but no Internet access + ජාලගතව ඇතත් අන්තර්ජාල ප්‍රවේශය නොමැත + + + Connection failed + + + + IP conflict + + + + Disable wired connection + රැහැන් සම්බන්ධතාවය අක්‍රීය කරන්න + + + Enable wired connection + රැහැන් සම්බන්ධතාවය සක්‍රීය කරන්න + + + Disable wireless connection + රැහැන් රහිත සම්බන්ධතාවය අක්‍රීය කරන්න + + + Enable wireless connection + රැහැන් රහිත සම්බන්ධතාවය සක්‍රීය කරන්න + + + Disable network + ජාලය අක්‍රීය කරන්න + + + Enable network + ජාලය සක්‍රීය කරන්න + + + Network settings + ජාල සැකසුම් + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sk.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sk.ts new file mode 100644 index 000000000..cfdddf464 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sk.ts @@ -0,0 +1,201 @@ + + + NetworkPlugin + + Network + Sieť + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + + + + Security Type + + + + Band + Pásmo + + + Channel + Kanál + + + Interface + Rozhranie + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Maska + + + Gateway + Brána + + + Primary DNS + Primárna DNS + + + IPv6 + IPv6 + + + Prefix + Prefix + + + Speed + Rýchlosť + + + + dde::network::NetworkDeviceRealize + + Device disabled + Zariadenie zakázané + + + Connected but no Internet access + Pripojené, ale bez prístupu na internet + + + Not connected + Nepripojené + + + Network cable unplugged + Sieťový kábel odpojený + + + Connecting + Pripájanie + + + Authenticating + Overujem + + + Obtaining IP address + Získavanie IP adresy + + + Connected + Pripojené + + + Disconnected + Odpojené + + + IP conflict + + + + Failed + Zlyhanie + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Drôtová sieť + + + Wired Network %1 + Káblová sieť %1 + + + Wireless Network + Bezdrôtová sieť + + + Wireless Network %1 + Bezdrôtová sieť %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Zariadenie zakázané + + + Network cable unplugged + Sieťový kábel odpojený + + + Not connected + Nepripojené + + + Connecting + Pripájanie + + + Connected but no Internet access + Pripojené, ale bez prístupu na internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Vypnúť káblové pripojenie + + + Enable wired connection + Zapnúť káblové pripojenie + + + Disable wireless connection + Vypnúť bezdrôtové pripojenie + + + Enable wireless connection + Zapnúť bezdrôtové pripojenie + + + Disable network + Zakázať sieť + + + Enable network + Povoliť sieť + + + Network settings + Nastavenia siete + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sl.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sl.ts new file mode 100644 index 000000000..0aa524821 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sl.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Brezžično omrežje + + + Wired Network + Ožičeno omrežje + + + + NetworkPlugin + + Network + Omrežje + + + Wireless Network + + + + Wired Network + Ožičeno omrežje + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Povezava na skrito omrežje + + + Password + Geslo + + + Cancel + button + Prekini + + + Connect + button + Poveži + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Dostopna točka + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Vrsta varnosti + + + Band + Pas + + + Channel + Kanal + + + Interface + Vmesnik + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Omrežna maska + + + Gateway + Prehod + + + Primary DNS + Prednostni DNS + + + IPv6 + IPv6 + + + Prefix + Predpona + + + Speed + Hitrost + + + + dde::network::NetworkDeviceRealize + + Device disabled + Naprava onemogočena + + + Connected but no Internet access + Povezano, brez dostopa do spleta + + + Not connected + Brez povezave + + + Network cable unplugged + Omrežni kabel je izklopljen + + + Connecting + Povezovanje + + + Authenticating + Overjanje + + + Obtaining IP address + Pridobivanje IP naslova + + + Connected + Povezava vzpostavljena + + + Disconnected + Povezava prekinjena + + + IP conflict + IP spor + + + Failed + Ni uspelo + + + Obtaining address + Pridobivanje naslova + + + + dde::network::NetworkProcesser + + Wired Network + Ožičeno omrežje + + + Wired Network %1 + Žično omrežje %1 + + + Wireless Network + Brezžično omrežje + + + Wireless Network %1 + Brezžično omrežje %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Naprava onemogočena + + + Network cable unplugged + Omrežni kabel je izklopljen + + + Not connected + Brez povezave + + + Connecting + Povezovanje + + + Connected but no Internet access + Povezano, brez dostopa do spleta + + + Connection failed + Povezava ni uspela + + + IP conflict + IP spor + + + Disable wired connection + Onemogoči žično povezavo + + + Enable wired connection + Omogoči žično povezavo + + + Disable wireless connection + Onemogoči brezžično povezavo + + + Enable wireless connection + Omogoči brezžično povezavo + + + Disable network + Onemogoči omrežje + + + Enable network + Omogoči omrežje + + + Network settings + Nastavitve omrežja + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sq.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sq.ts new file mode 100644 index 000000000..88f02592d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sq.ts @@ -0,0 +1,273 @@ + + + DeviceControllItem + + Wireless Network + Rrjet Pa Fill + + + Wired Network + Rrjet Me Fill + + + + NetworkPlugin + + Network + Rrjet + + + Wireless Network + + + + Wired Network + Rrjet Me Fill + + + Device disabled + Pajisje e çaktivizuar + + + Network cable unplugged + Kablloja e rrjetit është e hequr + + + Not connected + Jo e lidhur + + + Connecting + Po lidhet + + + Connected but no Internet access + E lidhur, por pa hyrje Internet + + + IP conflict + Përplasje IP-sh + + + Connection failed + Lidhja dështoi + + + + WirelessItem + + Connect to hidden network + Lidhu me rrjet të fshehur + + + Password + Fjalëkalim + + + Cancel + button + Anuloje + + + Connect + button + Lidhu + + + Name (SSID) + Emër (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Hotspot + + + SSID + SSID + + + Protocol + Protokoll + + + Security Type + Lloj Sigurie + + + Band + Bandë + + + Channel + Kanal + + + Interface + Ndërfaqe + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + NetMask-ë + + + Gateway + Kanal + + + Primary DNS + DNS Parësore + + + IPv6 + IPv6 + + + Prefix + Parashtesë + + + Speed + Shpejtësi + + + + dde::network::NetworkDeviceRealize + + Device disabled + Pajisje e çaktivizuar + + + Connected but no Internet access + E lidhur, por pa hyrje Internet + + + Not connected + Jo e lidhur + + + Network cable unplugged + Kablloja e rrjetit është e hequr + + + Connecting + Po lidhet + + + Authenticating + Po bëhet mirëfilltësim + + + Obtaining IP address + Po merret adresë IP + + + Connected + E lidhur + + + Disconnected + E shkëputur + + + IP conflict + Përplasje IP-sh + + + Failed + U dështua + + + Obtaining address + Po merret adresë + + + + dde::network::NetworkProcesser + + Wired Network + Rrjet Me Fill + + + Wired Network %1 + Rrjet Me Fill %1 + + + Wireless Network + Rrjet Pa Fill + + + Wireless Network %1 + Rrjet Pa Fill %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Pajisje e çaktivizuar + + + Network cable unplugged + Kablloja e rrjetit është e hequr + + + Not connected + Jo e lidhur + + + Connecting + Po lidhet + + + Connected but no Internet access + E lidhur, por pa hyrje Internet + + + Connection failed + Lidhja dështoi + + + IP conflict + Përplasje IP-sh + + + Disable wired connection + Çaktivizo lidhje me fill + + + Enable wired connection + Aktivizo lidhje me fill + + + Disable wireless connection + Çaktivizo lidhje pa fill + + + Enable wireless connection + Aktivizo lidhje pa fill + + + Disable network + Çaktivizo rrjetin + + + Enable network + Aktivizo rrjetin + + + Network settings + Rregullime rrjeti + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sr.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sr.ts new file mode 100644 index 000000000..db6d2cd68 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_sr.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Бежична мрежа + + + Wired Network + Жична мрежа + + + + NetworkPlugin + + Network + Мрежа + + + Wireless Network + + + + Wired Network + Жична мрежа + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Повежи се на скривену мрежу + + + Password + Лозинка + + + Cancel + button + Откажи + + + Connect + button + Повежи се + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Врућа тачка + + + SSID + ССИД + + + Protocol + Протокол + + + Security Type + Врста безбедности + + + Band + Опсег + + + Channel + Канал + + + Interface + Сучеље + + + MAC + МАК + + + IPv4 + ИПв4 + + + Netmask + Мрежна маска + + + Gateway + Мрежни пролаз + + + Primary DNS + Основни ДНС + + + IPv6 + ИПв6 + + + Prefix + Префикс + + + Speed + Брзина протока + + + + dde::network::NetworkDeviceRealize + + Device disabled + Уређај је онемогућен + + + Connected but no Internet access + Повезани сте, али нема интернета + + + Not connected + Нисте повезани + + + Network cable unplugged + Мрежни кабл је ископчан + + + Connecting + Повезивање + + + Authenticating + Идентификовање + + + Obtaining IP address + Прибављање ИП адресе + + + Connected + Повезани сте + + + Disconnected + Нисте поевзани + + + IP conflict + ИП сукоб + + + Failed + Неуспешно + + + Obtaining address + Прибављање адресе + + + + dde::network::NetworkProcesser + + Wired Network + Жична мрежа + + + Wired Network %1 + Жичана мрежа %1 + + + Wireless Network + Бежична мрежа + + + Wireless Network %1 + Бежична мрежа %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Уређај је онемогућен + + + Network cable unplugged + Мрежни кабл је ископчан + + + Not connected + Нисте повезани + + + Connecting + Повезивање + + + Connected but no Internet access + Повезани сте, али нема интернета + + + Connection failed + Неуспешно повезивање + + + IP conflict + ИП сукоб + + + Disable wired connection + Искључи жичану везу + + + Enable wired connection + Укључи жичану везу + + + Disable wireless connection + Искључи бежичану везу + + + Enable wireless connection + Укључи бежичану везу + + + Disable network + Искључи мрежу + + + Enable network + Укључи мрежу + + + Network settings + Подешавање мреже + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_tr.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_tr.ts new file mode 100644 index 000000000..55824fb25 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_tr.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Kablosuz Ağ + + + Wired Network + Kablolu Ağ + + + + NetworkPlugin + + Network + + + + Wireless Network + + + + Wired Network + Kablolu Ağ + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Gizli ağa bağlan + + + Password + Parola + + + Cancel + button + İptal + + + Connect + button + Bağlan + + + Name (SSID) + İsim (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Bağlantı Noktası + + + SSID + SSID + + + Protocol + Protokol + + + Security Type + Güvenlik Türü + + + Band + Bant + + + Channel + Kanal + + + Interface + Arayüz + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Ağ Maskesi + + + Gateway + Ağ Geçidi + + + Primary DNS + Birincil DNS + + + IPv6 + IPv6 + + + Prefix + Ön Ek + + + Speed + Hız + + + + dde::network::NetworkDeviceRealize + + Device disabled + Aygıt devre dışı + + + Connected but no Internet access + Bağlandı ancak İnternet erişimi yok + + + Not connected + Bağlı değil + + + Network cable unplugged + Ağ kablosu takılı değil + + + Connecting + Bağlanıyor + + + Authenticating + Kimlik doğrulanıyor + + + Obtaining IP address + IP adresi elde ediliyor + + + Connected + Bağlandı + + + Disconnected + Bağlantı kesildi + + + IP conflict + IP çakışması + + + Failed + Başarısız + + + Obtaining address + Adres elde ediliyor + + + + dde::network::NetworkProcesser + + Wired Network + Kablolu Ağ + + + Wired Network %1 + Kablolu Ağ %1 + + + Wireless Network + Kablosuz Ağ + + + Wireless Network %1 + Kablosuz Ağ%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Aygıt devre dışı + + + Network cable unplugged + Ağ kablosu takılı değil + + + Not connected + Bağlı değil + + + Connecting + Bağlanıyor + + + Connected but no Internet access + Bağlandı ancak İnternet erişimi yok + + + Connection failed + Bağlantı başarısız + + + IP conflict + IP çakışması + + + Disable wired connection + Kablolu bağlantıyı devre dışı bırak + + + Enable wired connection + Kablolu bağlantıyı etkinleştir + + + Disable wireless connection + Kablosuz bağlantıyı devre dışı bırak + + + Enable wireless connection + Kablosuz bağlantıyı etkinleştir + + + Disable network + Ağı devre dışı bırak + + + Enable network + Ağı etkinleştir + + + Network settings + Ay ayarları + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ug.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ug.ts new file mode 100644 index 000000000..b75630823 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_ug.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + سىمسىز تور + + + Wired Network + سىملىق تور + + + + NetworkPlugin + + Network + تور + + + Wireless Network + + + + Wired Network + سىملىق تور + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + يوشۇرۇن تورغا ئۇلاش + + + Password + پارولنى كىرگۈزۈڭ + + + Cancel + button + بىكار قىلىش + + + Connect + button + ئۇلاش + + + Name (SSID) + تور نامىنى كىرگۈزۈڭ(SSID) + + + + dde::network::NetworkDetails + + Hotspot + ھەمبەھىر نۇقتىسى + + + SSID + SSID + + + Protocol + كېلىشىم + + + Security Type + بىخەتەرلىك تۈرى + + + Band + دولقۇن بۆلىكى + + + Channel + قانال + + + Interface + ئۇلىنىش ئېغىزى + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + تور قەۋىتى + + + Gateway + تور قانىلى + + + Primary DNS + شەخسىي DNS + + + IPv6 + IPv6 + + + Prefix + قوشۇمچە + + + Speed + تېزلىكى + + + + dde::network::NetworkDeviceRealize + + Device disabled + ئۈسكۈنە ئىشلىتىش چەكلەندى + + + Connected but no Internet access + تورغا ئۇلاندى،ئەمما تورنى زىيارەت قىلالمىدى + + + Not connected + ئۇلانمىدى + + + Network cable unplugged + تور سىمى ئۇلانمىغان + + + Connecting + ئۇلىنىۋاتىدۇ + + + Authenticating + دەلىللەۋاتىدۇ + + + Obtaining IP address + IP ئادرېسىغا ئېرىشىش + + + Connected + ئۇلاندى + + + Disconnected + ئۈزۈلدى + + + IP conflict + IP ئادرېس توقۇنۇشۇپ قالدى + + + Failed + مەغلۇب بولدى + + + Obtaining address + ئادرېسىغا ئېرىشىۋاتىدۇ + + + + dde::network::NetworkProcesser + + Wired Network + سىملىق تور + + + Wired Network %1 + سىملىق تور%1 + + + Wireless Network + سىمسىز تور + + + Wireless Network %1 + سىمسىز تور%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + ئۈسكۈنە ئىشلىتىش چەكلەندى + + + Network cable unplugged + تور سىمى ئۇلانمىغان + + + Not connected + ئۇلانمىدى + + + Connecting + ئۇلىنىۋاتىدۇ + + + Connected but no Internet access + تورغا ئۇلاندى،ئەمما تورنى زىيارەت قىلالمىدى + + + Connection failed + ئۇلىنىش مەغلۇپ بولدى + + + IP conflict + IP ئادرېس توقۇنۇشۇپ قالدى + + + Disable wired connection + سىملىق تورنى تاقاش + + + Enable wired connection + سىملىق تورنى ئېچىش + + + Disable wireless connection + سىمسىز تورنى تاقاش + + + Enable wireless connection + سىمسىز تورنى ئېچىش + + + Disable network + تورنى تاقاش + + + Enable network + تورنى قوزغىتىش + + + Network settings + تور تەڭشىكى + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_uk.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_uk.ts new file mode 100644 index 000000000..769935f45 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_uk.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + Бездротова мережа + + + Wired Network + Провідна мережа + + + + NetworkPlugin + + Network + Мережа + + + Wireless Network + Бездротова мережа + + + Wired Network + Провідна мережа + + + Connected + + + + Device disabled + Пристрій вимкнено + + + Network cable unplugged + Кабель мережі від'єднано + + + Not connected + Не з'єднано + + + Connecting + З'єднання + + + Obtaining address + + + + Connected but no Internet access + З'єднано, але немає доступу до інтернету + + + IP conflict + Конфлікт IP + + + Connection failed + Не вдалося встановити з'єднання + + + + WirelessItem + + Connect to hidden network + Встановлення з'єднання із прихованою мережею + + + Password + Пароль + + + Cancel + button + Скасувати + + + Connect + button + З'єднатися + + + Name (SSID) + Назва (SSID) + + + + dde::network::NetworkDetails + + Hotspot + Точка доступу + + + SSID + SSID + + + Protocol + Протокол + + + Security Type + Тип захисту + + + Band + Група + + + Channel + Канал + + + Interface + Інтерфейс + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Маска мережі + + + Gateway + Шлюз + + + Primary DNS + Основний DNS + + + IPv6 + IPv6 + + + Prefix + Префікс + + + Speed + Швидкість + + + + dde::network::NetworkDeviceRealize + + Device disabled + Пристрій вимкнено + + + Connected but no Internet access + З'єднано, але немає доступу до інтернету + + + Not connected + Не з'єднано + + + Network cable unplugged + Кабель мережі від'єднано + + + Connecting + З'єднання + + + Authenticating + Розпізнавання + + + Obtaining IP address + Отримуємо IP-адресу + + + Connected + З'єднано + + + Disconnected + Роз'єднано + + + IP conflict + Конфлікт IP + + + Failed + Помилка + + + Obtaining address + Отримання адреси + + + + dde::network::NetworkProcesser + + Wired Network + Дротова мережа + + + Wired Network %1 + Дротова мережа %1 + + + Wireless Network + Бездротова мережа + + + Wireless Network %1 + Бездротова мережа %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Пристрій вимкнено + + + Network cable unplugged + Кабель мережі від'єднано + + + Not connected + Не з'єднано + + + Connecting + З'єднання + + + Connected but no Internet access + З'єднано, але немає доступу до інтернету + + + Connection failed + Не вдалося встановити з'єднання + + + IP conflict + Конфлікт IP + + + Disable wired connection + Вимкнути дротове з'єднання + + + Enable wired connection + Увімкнути дротове з'єднання + + + Disable wireless connection + Вимкнути бездротове з'єднання + + + Enable wireless connection + Увімкнути бездротове з'єднання + + + Disable network + Вимкнути мережу + + + Enable network + Увімкнути мережу + + + Network settings + Параметри мережі + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_vi.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_vi.ts new file mode 100644 index 000000000..03d1dfc39 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_vi.ts @@ -0,0 +1,269 @@ + + + DeviceControllItem + + Wireless Network + Mạng không dây + + + Wired Network + Mạng kết nối dây + + + + NetworkPlugin + + Network + Mạng + + + Wireless Network + + + + Wired Network + Mạng kết nối dây + + + Device disabled + + + + Not connected + + + + Connecting + + + + Connected but no Internet access + + + + IP conflict + + + + Connection failed + + + + + WirelessItem + + Connect to hidden network + Kết nối với mạng ẩn + + + Password + Mật mã + + + Cancel + button + Hủy + + + Connect + button + Kết nối + + + Name (SSID) + + + + + dde::network::NetworkDetails + + Hotspot + Điểm truy cập + + + SSID + SSID + + + Protocol + Giao thức + + + Security Type + Loại bảo mật + + + Band + Băng tần + + + Channel + Kênh + + + Interface + Giao diện + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + Mặt nạ mạng + + + Gateway + Cổng vào + + + Primary DNS + DNS Đầu + + + IPv6 + IPv6 + + + Prefix + Tiền tố + + + Speed + Tốt độ + + + + dde::network::NetworkDeviceRealize + + Device disabled + Thiết bị bị vô hiệu hóa + + + Connected but no Internet access + Đã kết nối nhưng không có truy cập Internet + + + Not connected + Không được kết nối + + + Network cable unplugged + Mạng dây đã ngắt + + + Connecting + Đang kết nối + + + Authenticating + Đang xác nhận + + + Obtaining IP address + Đang lấy địa chỉ IP + + + Connected + Đã kết nối + + + Disconnected + Đã ngắt kết nối + + + IP conflict + + + + Failed + Thất bại + + + Obtaining address + + + + + dde::network::NetworkProcesser + + Wired Network + Mạng kết nối dây + + + Wired Network %1 + Mạng kết nối dây %1 + + + Wireless Network + Mạng không dây + + + Wireless Network %1 + Mạng Không dây %1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + Thiết bị bị vô hiệu hóa + + + Network cable unplugged + Mạng dây đã ngắt + + + Not connected + Không được kết nối + + + Connecting + Đang kết nối + + + Connected but no Internet access + Đã kết nối nhưng không có truy cập Internet + + + Connection failed + + + + IP conflict + + + + Disable wired connection + Tắt kết nối mạng dây + + + Enable wired connection + Mở kết nối mạng dây + + + Disable wireless connection + Tắt kết nối wifi + + + Enable wireless connection + Bật kết nối wifi + + + Disable network + Vô hiệu hóa mạng + + + Enable network + Cho phép mạng + + + Network settings + Thiết lập mạng + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_CN.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_CN.ts new file mode 100644 index 000000000..9124fc4a8 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_CN.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + 无线网络 + + + Wired Network + 有线网络 + + + + NetworkPlugin + + Network + 网络 + + + Wireless Network + 无线网络 + + + Wired Network + 有线网络 + + + Connected + 已连接 + + + Device disabled + 设备已禁用 + + + Network cable unplugged + 未插入网线 + + + Not connected + 未连接 + + + Connecting + 正在连接 + + + Obtaining address + 获取地址中 + + + Connected but no Internet access + 已连接网络但无法访问互联网 + + + IP conflict + IP地址冲突 + + + Connection failed + 连接失败 + + + + WirelessItem + + Connect to hidden network + 连接到隐藏网络 + + + Password + 请输入密码 + + + Cancel + button + 取 消 + + + Connect + button + 连 接 + + + Name (SSID) + 请输入网络名称(SSID) + + + + dde::network::NetworkDetails + + Hotspot + 热点 + + + SSID + SSID + + + Protocol + 协议 + + + Security Type + 安全类型 + + + Band + 频段 + + + Channel + 网络通道 + + + Interface + 接口 + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + 子网掩码 + + + Gateway + 网关 + + + Primary DNS + 首选DNS + + + IPv6 + IPv6 + + + Prefix + 前缀 + + + Speed + 速率 + + + + dde::network::NetworkDeviceRealize + + Device disabled + 设备已禁用 + + + Connected but no Internet access + 已连接网络但无法访问互联网 + + + Not connected + 未连接 + + + Network cable unplugged + 未插入网线 + + + Connecting + 正在连接 + + + Authenticating + 认证中 + + + Obtaining IP address + 正在获取IP地址 + + + Connected + 已连接 + + + Disconnected + 已断开 + + + IP conflict + IP地址冲突 + + + Failed + 失败 + + + Obtaining address + 获取地址中 + + + + dde::network::NetworkProcesser + + Wired Network + 有线网络 + + + Wired Network %1 + 有线网络%1 + + + Wireless Network + 无线网络 + + + Wireless Network %1 + 无线网络%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + 设备已禁用 + + + Network cable unplugged + 未插入网线 + + + Not connected + 未连接 + + + Connecting + 正在连接 + + + Connected but no Internet access + 已连接网络但无法访问互联网 + + + Connection failed + 连接失败 + + + IP conflict + IP地址冲突 + + + Disable wired connection + 关闭有线网络 + + + Enable wired connection + 启用有线网络 + + + Disable wireless connection + 关闭无线网络 + + + Enable wireless connection + 启用无线网络 + + + Disable network + 关闭网络 + + + Enable network + 启用网络 + + + Network settings + 网络设置 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_HK.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_HK.ts new file mode 100644 index 000000000..aceae9ddf --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_HK.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + 無線網絡 + + + Wired Network + 有線網絡 + + + + NetworkPlugin + + Network + 網絡 + + + Wireless Network + 無線網絡 + + + Wired Network + 有線網絡 + + + Connected + 已連接 + + + Device disabled + 設備已禁用 + + + Network cable unplugged + 未插入網線 + + + Not connected + 未連接 + + + Connecting + 正在連接 + + + Obtaining address + 獲取地址中 + + + Connected but no Internet access + 已連接網絡但無法訪問互聯網 + + + IP conflict + IP位址衝突 + + + Connection failed + 連接失敗 + + + + WirelessItem + + Connect to hidden network + 連接到隱藏網絡 + + + Password + 請輸入密碼 + + + Cancel + button + 取 消 + + + Connect + button + 連 接 + + + Name (SSID) + 請輸入網絡名稱(SSID) + + + + dde::network::NetworkDetails + + Hotspot + 熱點 + + + SSID + SSID + + + Protocol + 協議 + + + Security Type + 安全類型 + + + Band + 頻段 + + + Channel + 網絡通道 + + + Interface + 接口 + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + 子網掩碼 + + + Gateway + 網關 + + + Primary DNS + 首選DNS + + + IPv6 + IPv6 + + + Prefix + 前綴 + + + Speed + 速率 + + + + dde::network::NetworkDeviceRealize + + Device disabled + 設備已禁用 + + + Connected but no Internet access + 已連接網絡但無法訪問互聯網 + + + Not connected + 未連接 + + + Network cable unplugged + 未插入網線 + + + Connecting + 正在連接 + + + Authenticating + 認證中 + + + Obtaining IP address + 正在獲取IP位址 + + + Connected + 已連接 + + + Disconnected + 已斷開 + + + IP conflict + IP位址衝突 + + + Failed + 失敗 + + + Obtaining address + 獲取地址中 + + + + dde::network::NetworkProcesser + + Wired Network + 有線網絡 + + + Wired Network %1 + 有線網絡%1 + + + Wireless Network + 無線網絡 + + + Wireless Network %1 + 無線網絡%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + 設備已禁用 + + + Network cable unplugged + 未插入網線 + + + Not connected + 未連接 + + + Connecting + 正在連接 + + + Connected but no Internet access + 已連接網絡但無法訪問互聯網 + + + Connection failed + 連接失敗 + + + IP conflict + IP位址衝突 + + + Disable wired connection + 關閉有線網絡 + + + Enable wired connection + 啟用有線網絡 + + + Disable wireless connection + 關閉無線網絡 + + + Enable wireless connection + 啟用無線網絡 + + + Disable network + 關閉網絡 + + + Enable network + 啟用網絡 + + + Network settings + 網絡設定 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_TW.ts b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_TW.ts new file mode 100644 index 000000000..f02e3d4d6 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/dock-network-plugin/translations/dock-network-plugin_zh_TW.ts @@ -0,0 +1,281 @@ + + + DeviceControllItem + + Wireless Network + 無線網路 + + + Wired Network + 有線網路 + + + + NetworkPlugin + + Network + 網路 + + + Wireless Network + 無線網路 + + + Wired Network + 有線網路 + + + Connected + 已連接 + + + Device disabled + 裝置已禁用 + + + Network cable unplugged + 未插入網路線 + + + Not connected + 未連接 + + + Connecting + 正在連線 + + + Obtaining address + 獲取地址中 + + + Connected but no Internet access + 已連接網路但無法訪問網路 + + + IP conflict + IP位址衝突 + + + Connection failed + 連線失敗 + + + + WirelessItem + + Connect to hidden network + 連接到隱藏網路 + + + Password + 請輸入密碼 + + + Cancel + button + 取 消 + + + Connect + button + 連 接 + + + Name (SSID) + 請輸入網路名稱(SSID) + + + + dde::network::NetworkDetails + + Hotspot + 熱點 + + + SSID + SSID + + + Protocol + 協議 + + + Security Type + 安全類型 + + + Band + 頻段 + + + Channel + 網路通道 + + + Interface + 介面 + + + MAC + MAC + + + IPv4 + IPv4 + + + Netmask + 子網掩碼 + + + Gateway + 網關 + + + Primary DNS + 首選DNS + + + IPv6 + IPv6 + + + Prefix + 前綴 + + + Speed + 速率 + + + + dde::network::NetworkDeviceRealize + + Device disabled + 裝置已禁用 + + + Connected but no Internet access + 已連接網路但無法訪問網路 + + + Not connected + 未連接 + + + Network cable unplugged + 未插入網路線 + + + Connecting + 正在連線 + + + Authenticating + 認證中 + + + Obtaining IP address + 正在獲取IP位址 + + + Connected + 已連接 + + + Disconnected + 已斷開 + + + IP conflict + IP位址衝突 + + + Failed + 失敗 + + + Obtaining address + 獲取地址中 + + + + dde::network::NetworkProcesser + + Wired Network + 有線網路 + + + Wired Network %1 + 有線網路%1 + + + Wireless Network + 無線網路 + + + Wireless Network %1 + 無線網路%1 + + + + dde::networkplugin::NetworkPluginHelper + + Device disabled + 裝置已禁用 + + + Network cable unplugged + 未插入網路線 + + + Not connected + 未連接 + + + Connecting + 正在連線 + + + Connected but no Internet access + 已連接網路但無法訪問網路 + + + Connection failed + 連線失敗 + + + IP conflict + IP位址衝突 + + + Disable wired connection + 關閉有線網路 + + + Enable wired connection + 啟用有線網路 + + + Disable wireless connection + 關閉無線網路 + + + Enable wireless connection + 啟用無線網路 + + + Disable network + 關閉網路 + + + Enable network + 啟用網路 + + + Network settings + 網路設定 + + + \ No newline at end of file diff --git a/panels/dock/tray/plugins/dde-network-core/src/CMakeLists.txt b/panels/dock/tray/plugins/dde-network-core/src/CMakeLists.txt new file mode 100644 index 000000000..a1e277aa8 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/CMakeLists.txt @@ -0,0 +1,68 @@ +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +file(GLOB_RECURSE SOURCEFILES "*.h" "*.cpp") +add_library(${PROJECT_NAME} SHARED ${SOURCEFILES}) + +find_package(Qt6 COMPONENTS Core DBus Network REQUIRED) +find_package(Dtk6 COMPONENTS Core Widget REQUIRED) + +target_include_directories(${PROJECT_NAME} PUBLIC + realize + ${NETINTERFACEINCLUDE} + "../common-plugin/" +) + +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt6::Core + Qt6::DBus + Qt6::Network + Dtk6::Core + Dtk6::Gui + Dtk6::Widget + KF5NetworkManagerQt_static +) + +set_target_properties(${PROJECT_NAME} PROPERTIES + VERSION ${CMAKE_PROJECT_VERSION} + SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR} +) + +########### static lib for tests ############### +add_library(${PROJECT_NAME}_static STATIC + ${SOURCEFILES} +) +target_link_libraries(${PROJECT_NAME}_static PUBLIC + Qt6::Core + Qt6::DBus + Qt6::Network + Dtk6::Core + Dtk6::Gui + Dtk6::Widget + KF5NetworkManagerQt_static +) +target_include_directories(${PROJECT_NAME}_static PUBLIC + "$" +) +set_target_properties(${PROJECT_NAME}_static PROPERTIES POSITION_INDEPENDENT_CODE ON) + +configure_file(dde-network-core.pc.in ../dde-network-core.pc @ONLY) + +set(INTERFACEFILES + dslcontroller.h + hotspotcontroller.h + networkconst.h + networkcontroller.h + networkdetails.h + networkdevicebase.h + proxycontroller.h + vpncontroller.h + wireddevice.h + wirelessdevice.h) + +# install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +# install(FILES ${CMAKE_BINARY_DIR}/dde-network-core.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +# install(FILES ${INTERFACEFILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libddenetworkcore) +# install(FILES ../config/org.deepin.dde.network.json DESTINATION ${CMAKE_INSTALL_DATADIR}/dsg/configs/org.deepin.dde.network) diff --git a/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.cpp b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.cpp new file mode 100644 index 000000000..19984479e --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.cpp @@ -0,0 +1,184 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dccdbusinterface.h" +#include "dccdbusinterface_p.h" + +#include +#include +#include +#include +#include +#include +#include + +const QString DBusService = QStringLiteral("org.freedesktop.DBus"); +const QString DBusPath = QStringLiteral("/org/freedesktop/DBus"); +const QString DBusInterface = QStringLiteral("org.freedesktop.DBus"); +const QString NameOwnerChanged = QStringLiteral("NameOwnerChanged"); + +const QString PropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); +const QString PropertiesChanged = QStringLiteral("PropertiesChanged"); +const static char *PropertyName = "propname"; + +using namespace dde::network; + +DCCDBusInterfacePrivate::DCCDBusInterfacePrivate(DCCDBusInterface *interface, QObject *parent) + : QObject(interface) + , m_parent(parent) + , q_ptr(interface) +{ + QDBusMessage message = QDBusMessage::createMethodCall(DBusService, DBusPath, DBusInterface, "NameHasOwner"); + message << interface->service(); + interface->connection().callWithCallback(message, this, SLOT(onDBusNameHasOwner(bool))); + + QStringList argumentMatch; + argumentMatch << interface->interface(); + interface->connection().connect(interface->service(), interface->path(), PropertiesInterface, PropertiesChanged, argumentMatch, QString(), this, SLOT(onPropertiesChanged(QString, QVariantMap, QStringList))); +} + +QVariant DCCDBusInterfacePrivate::demarshall(const QMetaProperty &metaProperty, const QVariant &value) +{ + if (value.userType() == metaProperty.userType()) + return value; + + QVariant result = QVariant(metaProperty.metaType(), nullptr); + if (value.userType() == qMetaTypeId()) { + QDBusArgument dbusArg = value.value(); + QDBusMetaType::demarshall(dbusArg, metaProperty.metaType(), result.data()); + } + + return result; +} + +QVariant DCCDBusInterfacePrivate::updateProp(const char *propname, const QVariant &value) +{ + QVariant result; + const QMetaObject *metaObj = m_parent->metaObject(); + int i = metaObj->indexOfProperty(propname); + if (i != -1) { + QMetaProperty metaProperty = metaObj->property(i); + result = demarshall(metaProperty, value); + m_propertyMap.insert(propname, result); + QMetaObject::invokeMethod(m_parent, propname + QString("Changed").toLatin1(), Qt::DirectConnection, QGenericArgument(result.typeName(), result.data())); + } else + qInfo() << "invalid property changed:" << propname << value; + + return result; +} + +void DCCDBusInterfacePrivate::initDBusConnection() +{ + Q_Q(DCCDBusInterface); + QDBusConnection connection = q->connection(); + QStringList signalList; + QDBusInterface inter(q->service(), q->path(), q->interface(), connection); + const QMetaObject *meta = inter.metaObject(); + for (int i = meta->methodOffset(); i < meta->methodCount(); ++i) { + const QMetaMethod &method = meta->method(i); + if (method.methodType() == QMetaMethod::Signal) { + signalList << method.methodSignature(); + } + } + const QMetaObject *parentMeta = m_parent->metaObject(); + for (const QString &signal : signalList) { + int i = parentMeta->indexOfSignal(QMetaObject::normalizedSignature(signal.toLatin1())); + if (i != -1) { + const QMetaMethod &parentMethod = parentMeta->method(i); + connection.connect(q->service(), q->path(), q->interface(), parentMethod.name(), m_parent, QT_STRINGIFY(QSIGNAL_CODE) + parentMethod.methodSignature()); + } + } +} + +void DCCDBusInterfacePrivate::onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties) +{ + Q_UNUSED(interfaceName) + Q_UNUSED(invalidatedProperties) + for (QVariantMap::const_iterator it = changedProperties.cbegin(); it != changedProperties.cend(); ++it) + updateProp((it.key() + m_suffix).toLatin1(), it.value()); +} + +void DCCDBusInterfacePrivate::onAsyncPropertyFinished(QDBusPendingCallWatcher *w) +{ + QDBusPendingReply reply = *w; + if (!reply.isError()) { + updateProp(w->property(PropertyName).toString().toLatin1(), reply.value()); + } + w->deleteLater(); +} + +void DCCDBusInterfacePrivate::onDBusNameHasOwner(bool valid) +{ + Q_Q(DCCDBusInterface); + if (valid) + initDBusConnection(); + else + q->connection().connect(DBusService, DBusPath, DBusInterface, NameOwnerChanged, this, SLOT(onDBusNameOwnerChanged(QString, QString, QString))); +} + +void DCCDBusInterfacePrivate::onDBusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOWner) +{ + Q_Q(DCCDBusInterface); + if (name == q->service() && oldOwner.isEmpty()) { + initDBusConnection(); + q->connection().disconnect(DBusService, DBusPath, DBusInterface, NameOwnerChanged, this, SLOT(onDBusNameOwnerChanged(QString, QString, QString))); + } +} +////////////////////////////////////////////////////////// +DCCDBusInterface::DCCDBusInterface(const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, interface.toLatin1(), connection, parent) + , d_ptr(new DCCDBusInterfacePrivate(this, parent)) +{ +} + +DCCDBusInterface::~DCCDBusInterface() +{ +} + +QString DCCDBusInterface::suffix() const +{ + Q_D(const DCCDBusInterface); + return d->m_suffix; +} + +void DCCDBusInterface::setSuffix(const QString &suffix) +{ + Q_D(DCCDBusInterface); + d->m_suffix = suffix; +} + +inline QString originalPropname(const char *propname, QString suffix) +{ + QString propStr(propname); + return propStr.left(propStr.length() - suffix.length()); +} + +QVariant DCCDBusInterface::property(const char *propname) +{ + Q_D(DCCDBusInterface); + if (d->m_propertyMap.contains(propname)) + return d->m_propertyMap.value(propname); + + QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), PropertiesInterface, QStringLiteral("Get")); + msg << interface() << originalPropname(propname, d->m_suffix); + QDBusPendingReply prop = connection().asyncCall(msg); + if (prop.value().isValid()) + return d->updateProp(propname, prop.value()); + + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(prop, this); + watcher->setProperty(PropertyName, propname); + connect(watcher, &QDBusPendingCallWatcher::finished, d, &DCCDBusInterfacePrivate::onAsyncPropertyFinished); + if (d->m_propertyMap.contains(propname)) + return d->m_propertyMap.value(propname); + + return QVariant(); +} + +void DCCDBusInterface::setProperty(const char *propname, const QVariant &value) +{ + Q_D(const DCCDBusInterface); + QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), PropertiesInterface, QStringLiteral("Set")); + msg << interface() << originalPropname(propname, d->m_suffix) << value; + connection().asyncCall(msg); +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.h b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.h new file mode 100644 index 000000000..9087903b5 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface.h @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DCCDBUSINTERFACE_H +#define DCCDBUSINTERFACE_H + +#include + +namespace dde { +namespace network { + +class DCCDBusInterfacePrivate; + +class DCCDBusInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + explicit DCCDBusInterface(const QString &service, const QString &path, const QString &interface = QString(), + const QDBusConnection &connection = QDBusConnection::sessionBus(), QObject *parent = nullptr); + virtual ~DCCDBusInterface() override; + + QString suffix() const; + void setSuffix(const QString &suffix); + + QVariant property(const char *propname); + void setProperty(const char *propname, const QVariant &value); + +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(DCCDBusInterface) + Q_DISABLE_COPY(DCCDBusInterface) +}; + +} +} + +#endif // DCCDBUSINTERFACE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface_p.h b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface_p.h new file mode 100644 index 000000000..842b83aff --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dccdbusinterface_p.h @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later +#ifndef DCCDBUSINTERFACE_P_H +#define DCCDBUSINTERFACE_P_H + +#include "dccdbusinterface.h" + +class QDBusPendingCallWatcher; + +namespace dde { +namespace network { + +class DCCDBusInterfacePrivate : public QObject +{ + Q_OBJECT + +public: + explicit DCCDBusInterfacePrivate(DCCDBusInterface *interface, QObject *parent); + QVariant demarshall(const QMetaProperty &metaProperty, const QVariant &value); + QVariant updateProp(const char *propname, const QVariant &value); + void initDBusConnection(); + +private Q_SLOTS: + void onPropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties); + void onAsyncPropertyFinished(QDBusPendingCallWatcher *w); + void onDBusNameHasOwner(bool valid); + void onDBusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOWner); + +public: + QObject *m_parent; + QString m_suffix; + QVariantMap m_propertyMap; + + DCCDBusInterface *q_ptr; + Q_DECLARE_PUBLIC(DCCDBusInterface) +}; + +} +} + +#endif // DCCDBUSINTERFACE_P_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/dde-network-core.pc.in b/panels/dock/tray/plugins/dde-network-core/src/dde-network-core.pc.in new file mode 100644 index 000000000..0020bb661 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dde-network-core.pc.in @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@/libddenetworkcore + +Name: libddenetworkcore +Description: networkcore interface +Version: @VERSION@ +Libs: -L${libdir} -ldde-network-core +Cflags: -I${includedir} diff --git a/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.cpp new file mode 100644 index 000000000..98db6da12 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.cpp @@ -0,0 +1,178 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dslcontroller.h" +#include "networkdevicebase.h" +#include "networkdbusproxy.h" + +#include + +#include + +using namespace dde::network; +using namespace NetworkManager; + +DSLController::DSLController(NetworkDBusProxy *networkInter, QObject *parent) + : QObject(parent) + , m_networkInter(networkInter) +{ + Q_ASSERT(m_networkInter); +} + +DSLController::~DSLController() +{ +} + +void DSLController::connectItem(DSLItem *item) +{ + // 查找该连接对应的设备的path + QString devicePath = "/"; + if (m_deviceInfo.contains(item->connection()->hwAddress())) + devicePath = m_deviceInfo[item->connection()->hwAddress()]; + + m_networkInter->ActivateConnection(item->connection()->uuid(), QDBusObjectPath(devicePath)); +} + +void DSLController::connectItem(const QString &uuid) +{ + // 根据UUID查找对应的DSL项,然后连接 + for (DSLItem *item : m_items) { + if (item->connection()->uuid() == uuid) { + connectItem(item); + break; + } + } +} + +void DSLController::disconnectItem() +{ + if (!m_activePath.isEmpty()) + deactivateConnection(m_activePath); +} + +void DSLController::updateDevice(const QList &devices) +{ + m_deviceInfo.clear(); + for (NetworkDeviceBase *device : devices) + m_deviceInfo[device->realHwAdr()] = device->path(); +} + +void DSLController::updateDSLItems(const QJsonArray &dsljson) +{ + // 更新DSL具体项的数据,先从列表中查找是否存在当前连接的path,如果找到,就直接更新, + // 没有找到的情况下就新建一个连接,并且将新连接添加到新列表中 + QStringList paths; + QList newItems, changeItems; + for (QJsonValue value : dsljson) { + QJsonObject dsl = value.toObject(); + QString path = dsl.value("Path").toString(); + DSLItem *item = findItem(path); + if (!item) { + item = new DSLItem; + m_items << item; + newItems << item; + } else { + if (item->connection()->id() != dsl.value("Id").toString()) + changeItems << item; + } + + item->setConnection(dsl); + paths << path; + } + + // 如果ID发生变化的数量大于0,则向外抛出连接变化的信号 + if (changeItems.size()) + Q_EMIT itemChanged(changeItems); + + // 如果新连接列表的数量大于0,则向外抛出连接新增的信号 + if (newItems.size() > 0) + Q_EMIT itemAdded(newItems); + + QList rmItems; + for (DSLItem *item : m_items) { + if (!paths.contains(item->connection()->path())) + rmItems << item; + } + + for (DSLItem *item : rmItems) + m_items.removeOne(item); + + // 如果有连接移除,则向外抛出连接移除的信号 + if (rmItems.size() > 0) + Q_EMIT itemRemoved(rmItems); + + for (DSLItem *item : rmItems) + delete item; +} + +void DSLController::updateActiveConnections(const QJsonObject &connectionJson) +{ + // 先保存所有的连接状态 + QMap allConnectionStatus; + // 恢复所有的状态为未连接 + for (DSLItem *item : m_items) { + allConnectionStatus[item->connection()->uuid()] = item->status(); + item->setConnectionStatus(ConnectionStatus::Deactivated); + } + + m_activePath.clear(); + bool statusChanged = false; + // 找到对应的连接,将其修改成连接成功 + QStringList keys = connectionJson.keys(); + for (int i = 0; i < keys.size(); i++) { + QString key = keys[i]; + QJsonObject json = connectionJson.value(key).toObject(); + QString uuid = json.value("Uuid").toString(); + DSLItem *dslItem = findDSLItemByUuid(uuid); + if (dslItem) { + ConnectionStatus state = convertConnectionStatus(json.value("State").toInt()); + dslItem->setConnectionStatus(state); + if (state == ConnectionStatus::Activated) + m_activePath = key; + if (allConnectionStatus.contains(uuid)) { + ConnectionStatus oldStatus = allConnectionStatus[uuid]; + if (!statusChanged && oldStatus != state) + statusChanged = true; + } + } + } + + if (statusChanged) + Q_EMIT activeConnectionChanged(); +} + +DSLItem *DSLController::findItem(const QString &path) +{ + for (DSLItem *item : m_items) { + if (item->connection()->path() == path) + return item; + } + + return Q_NULLPTR; +} + +DSLItem *DSLController::findDSLItemByUuid(const QString &uuid) +{ + // 根据uuid在列表中查询指定的dsl连接 + for (DSLItem *item : m_items) { + if (item->connection()->uuid() == uuid) + return item; + } + + return Q_NULLPTR; +} + +/** + * @brief UDSLItem::connection + * @return + */ +DSLItem::DSLItem() + : ControllItems() +{ +} + +DSLItem::~DSLItem() +{ +} + diff --git a/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.h b/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.h new file mode 100644 index 000000000..14ad52b46 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/dslcontroller.h @@ -0,0 +1,73 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DSLCONTROLLER_H +#define DSLCONTROLLER_H + +#include "networkconst.h" +#include "netutils.h" + +#include +#include + +namespace dde { + +namespace network { + +class DSLItem; +class NetworkDeviceBase; +class NetworkDBusProxy; + +class DSLController : public QObject +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + void connectItem(DSLItem *item); // 连接到当前的DSL + void connectItem(const QString &uuid); // 根据UUID连接当前DSL + void disconnectItem(); // 断开连接 + inline QList items() const { return m_items; } // 返回所有的DSL列表 + +Q_SIGNALS: + void itemAdded(const QList &); // 新增DSL项目 + void itemRemoved(const QList &); // 移除DSL项目 + void itemChanged(const QList &); // 项目发生变化(一般是ID发生了变化) + void activeConnectionChanged(); // 连接状态发生变化 + +protected: + explicit DSLController(NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + ~DSLController(); + + void updateDevice(const QList &devices); + void updateDSLItems(const QJsonArray &dsljson); + void updateActiveConnections(const QJsonObject &connectionJson); // 更新DSL的活动连接信息 + +private: + DSLItem *findItem(const QString &path); + DSLItem *findDSLItemByUuid(const QString &uuid); + +private: + QList m_items; + NetworkDBusProxy *m_networkInter; + QMap m_deviceInfo; + QString m_activePath; +}; + +class DSLItem : public ControllItems +{ + friend class DSLController; + +protected: + DSLItem(); + ~DSLItem(); +}; + +} + +} + +#endif // UDSLCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.cpp new file mode 100644 index 000000000..333b01f2d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.cpp @@ -0,0 +1,351 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "hotspotcontroller.h" +#include "wirelessdevice.h" +#include "networkdbusproxy.h" + +#include +#include +#include + +#include + +using namespace dde::network; +using namespace NetworkManager; + +HotspotController::HotspotController(NetworkDBusProxy *networkInter, QObject *parent) + : QObject(parent) + , m_networkInter(networkInter) +{ + Q_ASSERT(m_networkInter); +} + +HotspotController::~HotspotController() +{ +} + +void HotspotController::setEnabled(WirelessDevice *device, const bool enable) +{ + QList deviceHotsItem = items(device); + if (enable) { + auto getTimeStamp = [](const QString &path) { + NetworkManager::Connection::Ptr connection(new NetworkManager::Connection(path)); + return connection->settings()->timestamp(); + }; + // 在打开热点的时候,默认打开上次打开的热点 + auto lastNode = std::max_element(deviceHotsItem.begin(), deviceHotsItem.end(), [ getTimeStamp ](HotspotItem *item1, HotspotItem *item2) { + return getTimeStamp(item1->connection()->path()) < getTimeStamp(item2->connection()->path()); + }); + if (lastNode != deviceHotsItem.end()) + m_networkInter->ActivateConnection((*lastNode)->connection()->uuid(), QDBusObjectPath(device->path())); + } else { + // 在关闭热点的时候,找到当前已经连接的热点,并断开它的连接 + disconnectItem(device); + } +} + +bool HotspotController::enabled(WirelessDevice *device) +{ + return device->hotspotEnabled(); +} + +bool HotspotController::supportHotspot() +{ + return m_devices.size() > 0; +} + +void HotspotController::connectItem(HotspotItem *item) +{ + // 获取当前连接的UUID和设备的path + m_networkInter->ActivateConnection(item->connection()->uuid(), QDBusObjectPath(item->devicePath())); +} + +void HotspotController::connectItem(WirelessDevice *device, const QString &uuid) +{ + for (HotspotItem *item : m_hotspotItems) { + if (item->device() == device && item->connection()->uuid() == uuid) { + connectItem(item); + break; + } + } +} + +void HotspotController::disconnectItem(WirelessDevice *device) +{ + QList deviceHotspotsItem = items(device); + for (HotspotItem *item : deviceHotspotsItem) { + if (item->status() == ConnectionStatus::Activated && + !item->activeConnection().isEmpty()) { + deactivateConnection(item->activeConnection()); + } + } +} + +QList HotspotController::items(WirelessDevice *device) +{ + // 获取当前设备对应的所有的热点 + QList items; + for (HotspotItem *item : m_hotspotItems) { + if (item->device() == device) + items << item; + } + + return items; +} + +QList HotspotController::devices() +{ + return m_devices; +} + +HotspotItem *HotspotController::findItem(WirelessDevice *device, const QJsonObject &json) +{ + // 从列表中查找指定UUID的连接 + for (HotspotItem *item : m_hotspotItems) { + if (item->device() == device + && item->connection()->uuid() == json.value("Uuid").toString()) + return item; + } + + return Q_NULLPTR; +} + +bool HotspotController::isHotspotConnection(const QString &uuid) +{ + for (HotspotItem *item : m_hotspotItems) { + if (item->connection()->uuid() == uuid) + return true; + } + + return false; +} + +void HotspotController::updateActiveConnection(const QJsonObject &activeConnections) +{ + QList activeDevices; + // 先保存所有的连接状态 + QMap allConnectionStatus; + for (HotspotItem *item : m_hotspotItems) { + allConnectionStatus[item->connection()->uuid()] = item->status(); + item->setConnectionStatus(ConnectionStatus::Deactivated); + item->setActiveConnection(""); + } + + // 在这里记录一个标记,用来表示是否发送活动连接发生变化的信号, + // 因为这个连接更新后,紧接着会调用获取活动连接信息的信号,响应这个信号会调用下面的updateActiveConnectionInfo函数 + bool activeConnChanged = false; + + QStringList keys = activeConnections.keys(); + for (int i = 0; i < keys.size(); i++) { + QString path = keys[i]; + QJsonObject activeConnection = activeConnections.value(path).toObject(); + + QString uuid = activeConnection.value("Uuid").toString(); + + if (!isHotspotConnection(uuid)) + continue; + + ConnectionStatus state = convertConnectionStatus(activeConnection.value("State").toInt()); + + QJsonArray devicePaths = activeConnection.value("Devices").toArray(); + for (const QJsonValue jsonValue : devicePaths) { + QString devicePath = jsonValue.toString(); + WirelessDevice *device = findDevice(devicePath); + HotspotItem *hotspotItem = findItem(device, activeConnection); + if (!hotspotItem) + continue; + + hotspotItem->setConnectionStatus(state); + hotspotItem->setActiveConnection(path); + if (!allConnectionStatus.contains(uuid)) + continue; + + ConnectionStatus oldConnectionStatus = allConnectionStatus[uuid]; + // 上一次热点的连接状态为正在激活,当前连接状态为激活 + // 或者上一次热点的连接状态为正在取消激活,当前连接状态为取消激活,将其判断为最近一次有效的连接 + // 此时去更新热点开关的使能状态 + if ((oldConnectionStatus == ConnectionStatus::Activating && state == ConnectionStatus::Activated) + || (oldConnectionStatus == ConnectionStatus::Deactivating && state == ConnectionStatus::Deactivated)) { + Q_EMIT enableHotspotSwitch(true); + } + + if (oldConnectionStatus != hotspotItem->status()) { + activeConnChanged = true; + if (!activeDevices.contains(device)) + activeDevices << device; + } + } + } + if (activeConnChanged) + Q_EMIT activeConnectionChanged(activeDevices); +} + +WirelessDevice *HotspotController::findDevice(const QString &path) +{ + for (WirelessDevice *device : m_devices) { + if (device->path() == path) + return device; + } + + return Q_NULLPTR; +} + +void HotspotController::updateDevices(const QList &devices) +{ + QList tmpDevices = m_devices; + m_devices.clear(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() != DeviceType::Wireless) + continue; + + if (!device->supportHotspot()) + continue; + + if (!device->isEnabled()) + continue; + + m_devices << static_cast(device); + } + + // 移除不在列表中的热点的数据,防止数据更新不及时访问了野指针 + for (auto it = m_hotspotItems.begin(); it != m_hotspotItems.end();) { + if (!m_devices.contains((*it)->device())) { + delete (*it); + it = m_hotspotItems.erase(it); + } else { + ++it; + } + } + + bool hotspotEnabled = (m_devices.size() > 0); + if ((tmpDevices.size() > 0) != hotspotEnabled) + Q_EMIT enabledChanged(hotspotEnabled); + + // 查找移除的设备 + QList rmDevices; + for (WirelessDevice *device : tmpDevices) { + if (!m_devices.contains(device)) + rmDevices << device; + } + + // 查找新增的设备 + QList newDevices; + for (WirelessDevice *device : m_devices) { + if (!tmpDevices.contains(device)) + newDevices << device; + } + + // 告诉外面有新增的热点设备 + if (newDevices.size() > 0) + Q_EMIT deviceAdded(newDevices); + + // 告诉外面有移除的热点设备 + if (rmDevices.size() > 0) + Q_EMIT deviceRemove(rmDevices); +} + +void HotspotController::updateConnections(const QJsonArray &jsons) +{ + // 筛选出通用的(HwAddress为空)热点和指定HwAddress的热点 + QList commonConnections; + QMap> deviceConnections; + for (QJsonValue jsonValue : jsons) { + QJsonObject json = jsonValue.toObject(); + QString hwAddress = json.value("HwAddress").toString(); + if (hwAddress.isEmpty()) + commonConnections << json; + else + deviceConnections[hwAddress] << json; + } + + // 将所有热点的UUID缓存,用来对比不存在的热点,删除不存在的热点 + QMap> newItems; + QMap> infoChangeItems; + QStringList allHotsItem; + // HwAddress为空的热点适用于所有的设备,HwAddress不为空的热点只适用于指定的设备 + for (WirelessDevice *device : m_devices) { + QList hotspotJsons = commonConnections; + if (deviceConnections.contains(device->realHwAdr())) + hotspotJsons << deviceConnections[device->realHwAdr()]; + + for (QJsonValue value : hotspotJsons) { + QJsonObject json = value.toObject(); + HotspotItem *item = findItem(device, json); + if (!item) { + item = new HotspotItem(device); + m_hotspotItems << item; + newItems[device] << item; + } else { + if (item->connection()->ssid() != json.value("Ssid").toString()) + infoChangeItems[device] << item; + } + + item->setConnection(json); + QString pathName = QString("%1-%2").arg(device->path()).arg(json.value("Path").toString()); + allHotsItem << pathName; + } + } + + // 若现有连接发生变化,则抛出变化的信号 + if (infoChangeItems.size() > 0) + Q_EMIT itemChanged(infoChangeItems); + + // 如果有新增的连接,则发送新增连接的信号 + if (newItems.size() > 0) + Q_EMIT itemAdded(newItems); + + QMap> rmItemsMap; + QList rmItems; + // 删除列表中不存在的设备 + for (HotspotItem *item : m_hotspotItems) { + QString pathKey = QString("%1-%2").arg(item->device()->path()).arg(item->connection()->path()); + if (!allHotsItem.contains(pathKey)) { + rmItemsMap[item->device()] << item; + rmItems << item; + } + } + + // 从原来的列表中移除已经删除的对象 + for (HotspotItem *item : rmItems) + m_hotspotItems.removeOne(item); + + // 如果有删除的连接,向外发送删除的信号 + if (rmItemsMap.size() > 0) + Q_EMIT itemRemoved(rmItemsMap); + + // 清空已经删除的对象 + for (HotspotItem *item : rmItems) + delete item; +} + +/** + * @brief UHotspotItem::UHotspotItem + */ + +HotspotItem::HotspotItem(WirelessDevice *device) + : ControllItems() + , m_device(device) + , m_devicePath(m_device->path()) +{ +} + +HotspotItem::~HotspotItem() +{ +} + +QString HotspotItem::name() const +{ + return connection()->id(); +} + +WirelessDevice *HotspotItem::device() const +{ + return m_device; +} + +QString HotspotItem::devicePath() const +{ + return m_devicePath; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.h b/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.h new file mode 100644 index 000000000..2270cc6a7 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/hotspotcontroller.h @@ -0,0 +1,93 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef HOTSPOTCONTROLLER_H +#define HOTSPOTCONTROLLER_H + +#include "networkconst.h" +#include "netutils.h" + +#include +#include + +namespace dde { + +namespace network { + +class Connection; +class HotspotItem; +class WirelessDevice; +class NetworkDeviceBase; +class NetworkDBusProxy; + +class HotspotController : public QObject +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + void setEnabled(WirelessDevice *device, const bool enable); // 开启还是关闭个人热点 + bool enabled(WirelessDevice *device); // 设备的热点是否可用 + bool supportHotspot(); // 是否支持个人热点 + void connectItem(HotspotItem *item); // 连接到个人热点 + void connectItem(WirelessDevice *device, const QString &uuid); // 连接到个人热点 + void disconnectItem(WirelessDevice *device); // 断开连接 + QList items(WirelessDevice *device); // 返回列表 + QList devices(); // 获取支持热点的设备列表 + +Q_SIGNALS: + void enabledChanged(const bool &); // 热点是否可用发生了变化 + void itemAdded(const QMap> &); // 新增连接的信号 + void itemRemoved(const QMap> &); // 删除连接的信号 + void itemChanged(const QMap> &); // 连接信息改变的信号 + void activeConnectionChanged(const QList &); // 活动连接发生变化 + void deviceAdded(const QList &); // 新增热点设备 + void deviceRemove(const QList &); // 删除热点设备 + void enableHotspotSwitch(const bool &); // 使能热点开关 + +protected: + explicit HotspotController(NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + ~HotspotController(); + + void updateDevices(const QList &devices); + void updateConnections(const QJsonArray &jsons); + HotspotItem *findItem(WirelessDevice *device, const QJsonObject &json); + + void updateActiveConnection(const QJsonObject &activeConnections); + + WirelessDevice *findDevice(const QString &path); + bool isHotspotConnection(const QString &uuid); + +private: + QList m_devices; + QList m_hotspotItems; + NetworkDBusProxy *m_networkInter; +}; + +class HotspotItem : public ControllItems +{ + friend class HotspotController; + +public: + QString name() const; // 个人热点名称 + WirelessDevice *device() const; // 当前热点对应的无线设备 + +protected: + HotspotItem(WirelessDevice *device); + ~HotspotItem(); + + QString devicePath() const; // 返回设备的路径 + +private: + WirelessDevice *m_device; + QString m_devicePath; +}; + +} + +} + +#endif // UHOTSPOTCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.cpp b/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.cpp new file mode 100644 index 000000000..ba8a9d9ce --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.cpp @@ -0,0 +1,307 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "ipconfilctchecker.h" +#include "networkdevicebase.h" +#include "realize/netinterface.h" +#include "networkdbusproxy.h" + +#include +#include +#include +#include +#include + +#include +#include + +const static QString networkService = "org.deepin.dde.Network1"; +const static QString networkPath = "/org/deepin/dde/Network1"; + +using namespace dde::network; + +IPConfilctChecker::IPConfilctChecker(NetworkProcesser *networkProcesser, const bool ipChecked, QObject *parent) + : QObject(parent) + , m_networkInter(new NetworkDBusProxy(this)) + , m_networkProcesser(networkProcesser) + , m_ipNeedCheck(ipChecked) + , m_thread(new QThread(this)) +{ + this->moveToThread(m_thread); + + Q_ASSERT(m_networkProcesser); + connect(m_networkInter, &NetworkDBusProxy::IPConflict, this, &IPConfilctChecker::onIPConfilct); // IP冲突发出的信号 + // 构造所有的设备冲突检测对象 + connect(m_networkProcesser, &NetworkProcesser::deviceAdded, this, &IPConfilctChecker::onDeviceAdded, Qt::QueuedConnection); + m_thread->start(); +} + +IPConfilctChecker::~IPConfilctChecker() +{ +} + +void IPConfilctChecker::release() +{ + m_thread->quit(); + m_thread->wait(); +} + +void IPConfilctChecker::onDeviceAdded(QList devices) +{ + for (NetworkDeviceBase *device : devices) { + DeviceIPChecker *ipChecker = new DeviceIPChecker(device, m_networkInter, this); + connect(ipChecker, &DeviceIPChecker::conflictStatusChanged, this, &IPConfilctChecker::conflictStatusChanged); + if (m_ipNeedCheck) + connect(ipChecker, &DeviceIPChecker::ipConflictCheck, this, &IPConfilctChecker::onSenderIPInfo); + m_deviceCheckers << ipChecker; + } +} + +void IPConfilctChecker::clearUnExistDevice() +{ + QList devices = m_networkProcesser->devices(); + for (DeviceIPChecker *ipChecker : m_deviceCheckers) { + if (!devices.contains(ipChecker->device())) { + m_deviceCheckers.removeOne(ipChecker); + delete ipChecker; + } + } +} + +void IPConfilctChecker::onIPConfilct(const QString &ip, const QString &macAddress) +{ + // 此处通过调用后台获取IP地址,如果直接使用当前网络库中设备的IP地址,就有如下问题 + // 如果是在控制中心修改手动IP的话,从当前库中获取到的IP地址就不是最新的地址,因此此处需要从后台获取实时IP + QString activeConnectionInfo =m_networkInter->GetActiveConnectionInfo(); + handlerIpConflict(ip, macAddress, activeConnectionInfo); +} + +void IPConfilctChecker::onSenderIPInfo(const QStringList &ips) +{ + for (const QString &ip : ips) { + m_networkInter->RequestIPConflictCheck(ip, ""); + QThread::msleep(500); + } +} + +void IPConfilctChecker::handlerIpConflict(const QString &ip, const QString &macAddress, const QString &activeConnectionInfo) +{ + QMap deviceIps = parseDeviceIp(activeConnectionInfo); + NetworkDeviceBase *conflictDevice = Q_NULLPTR; + if (deviceIps.contains(ip)) + conflictDevice = deviceIps[ip]; + else { + // 可能是修改前的ip,从现存的checker里找是否有存在的,并更新ip。 + for (DeviceIPChecker *checker : m_deviceCheckers) { + if (checker->ipV4().contains(ip)) { + QStringList ips; + for (auto it = deviceIps.begin(); it != deviceIps.end(); it++) { + if (it.value() == checker->device()) + ips << it.key(); + } + + if (ips.isEmpty()) { + // 已经没有checker 对应的device 了,应该销毁这个checker + m_deviceCheckers.removeOne(checker); + if (checker->ipConflicted()) { + conflictStatusChanged(checker->device(), false); + } + checker->deleteLater(); + } else { + checker->setDeviceInfo(ips, macAddress); + checker->handlerIpConflict(); + } + } + } + return; + } + + // 如果不是本机IP,不做任何处理 + if (!conflictDevice) { + return; + } + + // 先从列表中查找对应的设备检测对象 + DeviceIPChecker *ipChecker = Q_NULLPTR; + for (DeviceIPChecker *checker : m_deviceCheckers) { + if (checker->device() == conflictDevice) { + ipChecker = checker; + break; + } + } + + if (!ipChecker) { + ipChecker = new DeviceIPChecker(conflictDevice, m_networkInter, this); + connect(ipChecker, &DeviceIPChecker::conflictStatusChanged, this, &IPConfilctChecker::conflictStatusChanged); + if (m_ipNeedCheck) + connect(ipChecker, &DeviceIPChecker::ipConflictCheck, this, &IPConfilctChecker::onSenderIPInfo); + m_deviceCheckers << ipChecker; + } + + QStringList ips; + for (auto it = deviceIps.begin(); it != deviceIps.end(); it++) { + if (it.value() == conflictDevice) + ips << it.key(); + } + + ipChecker->setDeviceInfo(ips, macAddress); + ipChecker->handlerIpConflict(); +} + +QMap IPConfilctChecker::parseDeviceIp(const QString &activeConnectionInfo) +{ + QMap tmpDevicePath; + QList devices = m_networkProcesser->devices(); + for (NetworkDeviceBase *device : devices) + tmpDevicePath[device->path()] = device; + + QJsonParseError error; + QJsonDocument json = QJsonDocument::fromJson(activeConnectionInfo.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) + return QMap(); + + QMap deviceIp; + const QJsonArray &infoArray = json.array(); + for (const QJsonValue &infoValue : infoArray) { + QJsonObject info = infoValue.toObject(); + if (!info.contains("IPv4") && !info.contains("Ip4")) + continue; + + const QString devicePath = info.value("Device").toString(); + if (!tmpDevicePath.contains(devicePath)) + continue; + + NetworkDeviceBase *device = tmpDevicePath[devicePath]; + + if (info.contains("IPv4")) { + QJsonObject ipv4TopObject = info.value("IPv4").toObject(); + QJsonArray ipv4Addresses = ipv4TopObject.value("Addresses").toArray(); + for (const QJsonValue addr : ipv4Addresses) { + const QJsonObject addrObject = addr.toObject(); + QString ipAddr = addrObject.value("Address").toString(); + ipAddr = ipAddr.remove("\""); + deviceIp[ipAddr] = device; + } + } else { + QJsonValue ipv4Info = info.value("Ip4"); + QJsonObject ipv4Object = ipv4Info.toObject(); + const QString ipv4 = ipv4Object.value("Address").toString(); + if (ipv4.isEmpty()) + continue; + + deviceIp[ipv4] = device; + } + } + + return deviceIp; +} + +/** + * @brief 构造函数 + * @param device 对应的设备 + * @param netInter + * @param parent + */ +DeviceIPChecker::DeviceIPChecker(NetworkDeviceBase *device, NetworkDBusProxy *netInter, QObject *parent) + : QObject(parent) + , m_device(device) + , m_networkInter(netInter) + , m_conflictCount(0) + , m_clearCount(0) + , m_count(0) + , m_ipConflicted(false) +{ + auto requestConflictCheck = [ this ] () { + // 当设备的IP地址发生变化的时候,请求IP冲突, 只有在上一次请求和该次请求发生的时间大于2秒,才发出信号 + m_ipV4 = m_device->ipv4(); + if (!m_ipV4.isEmpty()) { + m_changeIpv4s << m_ipV4; + QTimer::singleShot(800, this, [ this ] { + if (m_changeIpv4s.size() > 0) { + emit ipConflictCheck(m_changeIpv4s[m_changeIpv4s.size() - 1]); + m_changeIpv4s.clear(); + } + }); + } + }; + connect(device, &NetworkDeviceBase::ipV4Changed, this, requestConflictCheck); + connect(device, &NetworkDeviceBase::enableChanged, this, requestConflictCheck); + + QTimer *timer = new QTimer(this); + + connect(timer, &QTimer::timeout, this, [this] () { + if (m_ipConflicted) { + // 如果确定是有冲突,则冷却至少5秒检测一次,直到冲突解除。 + emit ipConflictCheck(m_ipV4); + } else { + // 如果无冲突, 则冷却至少180秒检测一次。 + if ((m_count++ % 36) == 0) { + emit ipConflictCheck(m_ipV4); + } + } + }); + timer->start(5000); +} + +DeviceIPChecker::~DeviceIPChecker() +{ +} + +NetworkDeviceBase *DeviceIPChecker::device() +{ + return m_device; +} + +void DeviceIPChecker::setDeviceInfo(const QStringList &ipv4, const QString &macAddress) +{ + m_ipV4 = ipv4; + m_macAddress = macAddress; +} + +void DeviceIPChecker::handlerIpConflict() +{ + if (m_macAddress.isEmpty()) { + m_conflictCount = 0; + // 如果MAC地址为空,则表示IP冲突已经解决,则让每个网卡恢复之前的状态 + if (m_clearCount < 3 && m_ipConflicted) { + emit ipConflictCheck(m_ipV4); + } else { + // 拿到最后一次设备冲突的状态 + bool lastConfilctStatus = m_ipConflicted; + m_ipConflicted = false; + + // IP冲突状态发生变化的时候才会发送该信号 + if (lastConfilctStatus) + Q_EMIT conflictStatusChanged(m_device, false); + } + m_clearCount++; + } else { + m_clearCount = 0; + + // 如果少于两次,则继续确认 + if (m_conflictCount < 1 && !m_ipConflicted) { + emit ipConflictCheck(m_ipV4); + } else { + // 如果大于3次,则认为当前IP冲突了 + // 拿到最后一次设备冲突的状态 + bool lastConflictStatus = m_ipConflicted; + m_ipConflicted = true; + + // 最后一次IP不冲突,本次IP冲突的时候才发送设备状态变化的信号 + if (!lastConflictStatus) + Q_EMIT conflictStatusChanged(m_device, true); + } + m_conflictCount++; + } +} + +QStringList DeviceIPChecker::ipV4() +{ + return m_ipV4; +} + +bool DeviceIPChecker::ipConflicted() +{ + return m_ipConflicted; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.h b/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.h new file mode 100644 index 000000000..e5f7d2351 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/ipconfilctchecker.h @@ -0,0 +1,86 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef IPCONFILCTCHECKER_H +#define IPCONFILCTCHECKER_H + +#include +#include "netutils.h" + +#include "networkconst.h" + +class QThread; + +namespace dde { +namespace network { + +class NetworkDeviceBase; +class NetworkProcesser; +class DeviceIPChecker; +class NetworkDBusProxy; + +class IPConfilctChecker : public QObject +{ + Q_OBJECT + +Q_SIGNALS: + void conflictStatusChanged(NetworkDeviceBase *, const bool); + +public: + explicit IPConfilctChecker(NetworkProcesser *networkProcesser, const bool ipChecked, QObject *parent = nullptr); + ~IPConfilctChecker(); + + void release(); + +private Q_SLOT: + void onDeviceAdded(QList devices); + void onIPConfilct(const QString &ip, const QString &macAddress); + void onSenderIPInfo(const QStringList &ips); + +private: + void handlerIpConflict(const QString &ip, const QString &macAddress, const QString &activeConnectionInfo); + QMap parseDeviceIp(const QString &activeConnectionInfo); + void clearUnExistDevice(); + +private: + NetworkDBusProxy *m_networkInter; + NetworkProcesser *m_networkProcesser; + QList m_deviceCheckers; + bool m_ipNeedCheck; + QThread *m_thread; +}; + +class DeviceIPChecker : public QObject +{ + Q_OBJECT + +Q_SIGNALS: + void conflictStatusChanged(NetworkDeviceBase *, const bool); + void ipConflictCheck(const QStringList &); + +public: + explicit DeviceIPChecker(NetworkDeviceBase *device, NetworkDBusProxy *netInter, QObject *parent); + ~DeviceIPChecker(); + NetworkDeviceBase *device(); + void setDeviceInfo(const QStringList &ipv4, const QString &macAddress); + void handlerIpConflict(); + QStringList ipV4(); + bool ipConflicted(); + +private: + NetworkDeviceBase *m_device; + NetworkDBusProxy *m_networkInter; + QStringList m_ipV4; + QString m_macAddress; + int m_conflictCount; + int m_clearCount; + int m_count; + bool m_ipConflicted; + QList m_changeIpv4s; +}; + +} +} + +#endif // IPCONFILCTCHECKER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/netutils.cpp b/panels/dock/tray/plugins/dde-network-core/src/netutils.cpp new file mode 100644 index 000000000..ad901a352 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/netutils.cpp @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "netutils.h" + +namespace dde { +namespace network { + +Connectivity connectivityValue(uint sourceConnectivity) +{ + switch (sourceConnectivity) { + case 0: return Connectivity::Unknownconnectivity; + case 1: return Connectivity::Noconnectivity; + case 2: return Connectivity::Portal; + case 3: return Connectivity::Limited; + case 4: return Connectivity::Full; + default: break; + } + + return Connectivity::Unknownconnectivity; +} + +DeviceStatus convertDeviceStatus(int sourceDeviceStatus) +{ + switch (sourceDeviceStatus) { + case 0: return DeviceStatus::Unknown; + case 10: return DeviceStatus::Unmanaged; + case 20: return DeviceStatus::Unavailable; + case 30: return DeviceStatus::Disconnected; + case 40: return DeviceStatus::Prepare; + case 50: return DeviceStatus::Config; + case 60: return DeviceStatus::Needauth; + case 70: return DeviceStatus::IpConfig; + case 80: return DeviceStatus::IpCheck; + case 90: return DeviceStatus::Secondaries; + case 100: return DeviceStatus::Activated; + case 110: return DeviceStatus::Deactivation; + case 120: return DeviceStatus::Failed; + default: break; + } + + return DeviceStatus::Unknown; +} + +ConnectionStatus convertConnectionStatus(int sourceConnectionStatus) +{ + switch (sourceConnectionStatus) { + case 0: return ConnectionStatus::Unknown; + case 1: return ConnectionStatus::Activating; + case 2: return ConnectionStatus::Activated; + case 3: return ConnectionStatus::Deactivating; + case 4: return ConnectionStatus::Deactivated; + } + + return ConnectionStatus::Unknown; +} + +} +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/netutils.h b/panels/dock/tray/plugins/dde-network-core/src/netutils.h new file mode 100644 index 000000000..fdf89a300 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/netutils.h @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETUTILS_H +#define NETUTILS_H + +#include "networkconst.h" + +#include + +namespace dde { +namespace network { + +// an alias for numeric zero, no flags set. +#define DEVICE_INTERFACE_FLAG_NONE 0 +// the interface is enabled from the administrative point of view. Corresponds to kernel IFF_UP. +#define DEVICE_INTERFACE_FLAG_UP 0x1 +// the physical link is up. Corresponds to kernel IFF_LOWER_UP. +#define DEVICE_INTERFACE_FLAG_LOWER_UP 0x2 +// the interface has carrier. In most cases this is equal to the value of @NM_DEVICE_INTERFACE_FLAG_LOWER_UP +#define DEVICE_INTERFACE_FLAG_CARRIER 0x10000 + +// wifi6的标记 +#define AP_FLAGS_HE 0x10 + +Connectivity connectivityValue(uint sourceConnectivity); +DeviceStatus convertDeviceStatus(int sourceDeviceStatus); +ConnectionStatus convertConnectionStatus(int sourceConnectionStatus); + +} +} +#endif // UTILS_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkconst.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkconst.cpp new file mode 100644 index 000000000..5b8ea5ad4 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkconst.cpp @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkconst.h" + +namespace dde { + +namespace network { + +Connection::Connection() +{ +} + +Connection::~Connection() +{ +} + +QString Connection::path() +{ + return m_data.value("Path").toString(); +} + +QString Connection::uuid() +{ + return m_data.value("Uuid").toString(); +} + +QString Connection::id() +{ + return m_data.value("Id").toString(); +} + +QString Connection::hwAddress() +{ + return m_data.value("HwAddress").toString(); +} + +QString Connection::clonedAddress() +{ + return m_data.value("ClonedAddress").toString(); +} + +QString Connection::ssid() +{ + return m_data.value("Ssid").toString(); +} + +void Connection::updateConnection(const QJsonObject &data) +{ + m_data = data; +} + +// 连接具体项的基类 +ControllItems::ControllItems() + : m_connection(new Connection) + , m_status(ConnectionStatus::Unknown) +{ +} + +ControllItems::~ControllItems() +{ + delete m_connection; +} + +Connection *ControllItems::connection() const +{ + return m_connection; +} + +QString ControllItems::activeConnection() const +{ + return m_activeConnection; +} + +void ControllItems::setConnection(const QJsonObject &jsonObj) +{ + m_connection->updateConnection(jsonObj); +} + +void ControllItems::setActiveConnection(const QString &activeConnection) +{ + m_activeConnection = activeConnection; +} + +ConnectionStatus ControllItems::status() const +{ + return m_status; +} + +bool ControllItems::connected() const +{ + return (status() == ConnectionStatus::Activated); +} + +void ControllItems::setConnectionStatus(const ConnectionStatus &status) +{ + m_status = status; +} + +} + +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkconst.h b/panels/dock/tray/plugins/dde-network-core/src/networkconst.h new file mode 100644 index 000000000..f35f2c877 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkconst.h @@ -0,0 +1,181 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKCONST_H +#define NETWORKCONST_H + +#include +#include +#include + +namespace dde { + +namespace network { + +/* + * 系统代理类型 + */ +enum class SysProxyType { + Http = 0, // http类型 + Https, // https类型 + Ftp, // ftp类型 + Socks // socks类型 +}; + +/* + * 应用代理类型 + */ +enum class AppProxyType { + Http = 0, // http类型 + Socks4, // sock4类型 + Socks5 // sock5类型 +}; + +/* + * 设备类型 + */ +enum class DeviceType { + Unknown = 0, // 未知设备 + Wired, // 有线网卡 + Wireless // 无线网卡 +}; + +/* + * @brief 设备状态 + */ +enum class DeviceStatus { + Unknown = 0, // 未知状态 + Unmanaged = 10, // 未管理 + Unavailable = 20, // 不可用 + Disconnected = 30, // 断开连接 + Prepare = 40, // 正在准备状态 + Config = 50, // 正在配置连接信息 + Needauth = 60, // 需要认证 + IpConfig = 70, // 正在配置IP + IpCheck = 80, // 正在进行IP检验 + Secondaries = 90, // 设备正在等待第二个在当前设备连接成功之前必须激活的连接(例如VPN) + Activated = 100, // 激活状态,也就是连接成功 + Deactivation = 110, // 断开连接 + Failed = 120, // 连接失败 + IpConfilct = 121 // ip冲突 +}; + +/* + * 连接状态 + */ +enum class Connectivity { + /* 网络连接未知。这意味着连接检查已禁用(例如,在服务器上安装)或尚未运行。 + 图形外壳程序应假定Internet连接可用,并且不显示强制门户窗口。*/ + Unknownconnectivity = 0, + /* 主机未连接到任何网络。没有活动的连接包含默认的Internet路由,因此甚至尝试进行连 + 接检查也没有意义。图形shell应使用此状态来指示网络连接不可用。*/ + Noconnectivity, + /* Internet连接被捕获的入口网关劫持。图形shell可以打开sandboxed web浏览器窗口 + (因为捕获的门户通常会尝试对https连接进行中间人攻击),以便对网关进行身份验证, + 并在浏览器窗口关闭时使用CheckConnectivity()重新触发连接检查。*/ + Portal, + Limited, // 主机已连接到网络,似乎无法访问完整的Internet,但尚未检测到捕获的门户 + Full // 主机已连接到网络,并且似乎能够访问完整的Internet。 +}; + +/*** + * 加载网络的方式 + */ + +enum class ServiceLoadType { + LoadFromInter = 0, // 从后台加载 + LoadFromManager, // 从NetworkManager加载 + LoadFromService // 从后台服务加载(备用) +}; + +/** + * @brief 系统代理配置 + */ +struct SysProxyConfig +{ + SysProxyType type; // 系统代理类型,是一个枚举变量(http,https,ftp,socks) + QString url; // 代理的URL,一般用于自动代理的URL,手动代理的代理值 + uint port; // 代理的端口,一般是手动代理 +}; +/** + * @brief 应用代理配置 + */ +struct AppProxyConfig +{ + AppProxyType type; // 应用代理类型,枚举变量(http,socks4,socks5) + QString ip; // IP地址 + uint port; // 端口 + QString username; // 用户名 + QString password; // 密码 +}; + +enum class ProxyMethod { + Init = -1, // 初始化状态,用来对数据进行初始化 + None = 0, // 没有设置,对应字符串”none”,如果设置成这个,此时是关闭代理 + Auto, // 自动模式,对应字符串”auto” + Manual // 手动模式,对应字符串”manual” +}; + +/** + * @brief 当前网络连接状态 + */ +enum class ConnectionStatus { + Unknown = 0, // 普通状态 + Activating = 1, // 连接中 + Activated = 2, // 连接成功 + Deactivating = 3, // 断开连接中 + Deactivated = 4 // 连接已断开 +}; + +class Connection +{ + friend class ControllItems; + +public: + QString path(); // 对应connections数据中的path + QString uuid(); // 对应connections数据中的uuid + QString id(); // 对应connections数据中的id + QString hwAddress(); // 对应connections数据中的hwAddress + QString clonedAddress(); // 对应connections数据中的clonedAddress + QString ssid(); // 对应connections数据中的Ssid + +protected: + Connection(); + ~Connection(); + void updateConnection(const QJsonObject &data); + +private: + QJsonObject m_data; +}; + +class ControllItems +{ +public: + ControllItems(); + virtual ~ControllItems(); + + Connection *connection() const; + QString activeConnection() const; + + bool connected() const; //网络是否连接成功 + virtual ConnectionStatus status() const; // 当前连接的连接状态 + +protected: + void setConnection(const QJsonObject &jsonObj); + void setActiveConnection(const QString &activeConnection); + virtual void setConnectionStatus(const ConnectionStatus &status); + +private: + Connection *m_connection; + QString m_activeConnection; + ConnectionStatus m_status; +}; + +} + +} +Q_DECLARE_METATYPE(dde::network::ControllItems); +Q_DECLARE_METATYPE(dde::network::ControllItems *); + +#endif // UNETWORKCONST_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.cpp new file mode 100644 index 000000000..0ccaa68d3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.cpp @@ -0,0 +1,116 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dslcontroller.h" +#include "hotspotcontroller.h" +#include "networkcontroller.h" +#include "networkdetails.h" +#include "networkdevicebase.h" +#include "proxycontroller.h" +#include "vpncontroller.h" +#include "wireddevice.h" +#include "wirelessdevice.h" +#include "netutils.h" +#include "realize/networkmanagerprocesser.h" +#include "realize/networkinterprocesser.h" + +using namespace dde::network; + +// 默认是异步方式 +bool NetworkController::m_sync = false; +// 只有任务栏需要检测IP冲突,因此任务栏需要调用相关的接口来检测,其他的应用是不需要检测冲突的 +bool NetworkController::m_checkIpConflicted = false; +// 默认从网络后台检测 +ServiceLoadType NetworkController::m_serviceLoadType = ServiceLoadType::LoadFromInter; + +NetworkController::NetworkController() + : QObject(Q_NULLPTR) + , m_proxyController(Q_NULLPTR) + , m_vpnController(Q_NULLPTR) + , m_dslController(Q_NULLPTR) + , m_hotspotController(Q_NULLPTR) +{ + if (m_serviceLoadType == ServiceLoadType::LoadFromManager) + m_processer = new NetworkManagerProcesser(this); + else + m_processer = new NetworkInterProcesser(m_sync, m_checkIpConflicted, this); + + connect(m_processer, &NetworkProcesser::deviceAdded, this, &NetworkController::deviceAdded); + connect(m_processer, &NetworkProcesser::deviceRemoved, this, &NetworkController::deviceRemoved); + connect(m_processer, &NetworkProcesser::connectivityChanged, this, &NetworkController::connectivityChanged); + connect(m_processer, &NetworkProcesser::connectionChanged, this, &NetworkController::connectionChanged); + connect(m_processer, &NetworkProcesser::activeConnectionChange, this, &NetworkController::activeConnectionChange); +} + +NetworkController::~NetworkController() +{ +} + +NetworkController *NetworkController::instance() +{ + static NetworkController instance; + return &instance; +} + +void NetworkController::setActiveSync(const bool sync) +{ + m_sync = sync; +} + +void NetworkController::setServiceType(const ServiceLoadType serviceType) +{ + m_serviceLoadType = serviceType; +} + +void NetworkController::setIPConflictCheck(const bool &checkIp) +{ + m_checkIpConflicted = checkIp; +} + +void NetworkController::updateSync(const bool sync) +{ + NetworkInterProcesser *processer = qobject_cast(m_processer); + if (processer) + processer->updateSync(sync); +} + +ProxyController *NetworkController::proxyController() +{ + return m_processer->proxyController(); +} + +VPNController *NetworkController::vpnController() +{ + return m_processer->vpnController(); +} + +DSLController *NetworkController::dslController() +{ + return m_processer->dslController(); +} + +HotspotController *NetworkController::hotspotController() +{ + return m_processer->hotspotController(); +} + +QList NetworkController::networkDetails() +{ + return m_processer->networkDetails(); +} + +QList NetworkController::devices() const +{ + return m_processer->devices(); +} + +Connectivity NetworkController::connectivity() +{ + return m_processer->connectivity(); +} + +void NetworkController::retranslate() +{ + m_processer->retranslate(); +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.h b/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.h new file mode 100644 index 000000000..0b2077932 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkcontroller.h @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKCONTROLLER_H +#define NETWORKCONTROLLER_H + +#include "networkconst.h" + +#include + +namespace dde { + +namespace network { + +class ProxyController; +class VPNController; +class DSLController; +class HotspotController; +class NetworkDetails; +class NetworkDeviceBase; +class NetworkProcesser; + +enum InterfaceFlags { + NM_DEVICE_INTERFACE_FLAG_NONE = 0, // an alias for numeric zero, no flags set. + NM_DEVICE_INTERFACE_FLAG_UP = 0x1, // the interface is enabled from the administrative point of view. Corresponds to kernel IFF_UP. + NM_DEVICE_INTERFACE_FLAG_LOWER_UP = 0x2, // the physical link is up. Corresponds to kernel IFF_LOWER_UP. + NM_DEVICE_INTERFACE_FLAG_CARRIER = 0x10000, // the interface has carrier. In most cases this is equal to the value of @NM_DEVICE_INTERFACE_FLAG_LOWER_UP +}; + +class NetworkController : public QObject +{ + Q_OBJECT + +public: + static NetworkController *instance(); // 对外返回的单例 + static void setActiveSync(const bool sync = false); // 设置QDbus服务通讯的方式 ,true表示同步获取,false表示异步获取 + static void setServiceType(const ServiceLoadType serviceType); // 是否系统级(用于在登录界面,此时尚未进入用户,无法访问用户接口) + static void setIPConflictCheck(const bool &checkIp); // 设置是否主动检测IP冲突 + void updateSync(const bool sync); // 用于中途更新同步或异步方式 + + ProxyController *proxyController(); // 返回代理控制管理器 + VPNController *vpnController(); // 返回VPN控制器 + DSLController *dslController(); // DSL控制器 + HotspotController *hotspotController(); // 个人热点控制器 + QList networkDetails(); // 网络详情 + QList devices() const; // 当前网络设备列表 + Connectivity connectivity(); // 获取网络连接状态 + void retranslate(); // 更新翻译 + +Q_SIGNALS: + void deviceAdded(QList); // 新增设备发出的信号 + void deviceRemoved(QList); // 移除设备发出的信号 + void connectivityChanged(const Connectivity &) const; // 网络连接状态发生变化的时候发出的信号 + void connectionChanged(); // 连接信息发生变化的时候触发的信号 + void activeConnectionChange(); // 网络数据发生变化 + +protected: + explicit NetworkController(); + ~NetworkController(); + +private: + NetworkProcesser *m_processer; + ProxyController *m_proxyController; + VPNController *m_vpnController; + DSLController *m_dslController; + HotspotController *m_hotspotController; + QList m_networkDetails; + static bool m_sync; + static ServiceLoadType m_serviceLoadType; + static bool m_checkIpConflicted; +}; + +} + +} + +#endif // UNETWORKCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.cpp new file mode 100644 index 000000000..55d67fc52 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.cpp @@ -0,0 +1,255 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkdbusproxy.h" +#include "dccdbusinterface.h" + +#include +#include +#include +#include +#include + +const QString NetworkService = QStringLiteral("org.deepin.dde.Network1"); +const QString NetworkPath = QStringLiteral("/org/deepin/dde/Network1"); +const QString NetworkInterface = QStringLiteral("org.deepin.dde.Network1"); + +const QString ProxyChainsService = QStringLiteral("org.deepin.dde.Network1"); +const QString ProxyChainsPath = QStringLiteral("/org/deepin/dde/Network1/ProxyChains"); +const QString ProxyChainsInterface = QStringLiteral("org.deepin.dde.Network1.ProxyChains"); + +const QString AirplaneModeService = QStringLiteral("org.deepin.dde.AirplaneMode1"); +const QString AirplaneModePath = QStringLiteral("/org/deepin/dde/AirplaneMode1"); +const QString AirplaneModeInterface = QStringLiteral("org.deepin.dde.AirplaneMode1"); + +const QString PropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); +const QString PropertiesChanged = QStringLiteral("PropertiesChanged"); +using namespace dde::network; + +NetworkDBusProxy::NetworkDBusProxy(QObject *parent) + : QObject(parent) + , m_networkInter(new DCCDBusInterface(NetworkService, NetworkPath, NetworkInterface, QDBusConnection::sessionBus(), this)) + , m_proxyChainsInter(new DCCDBusInterface(ProxyChainsService, ProxyChainsPath, ProxyChainsInterface, QDBusConnection::sessionBus(), this)) + , m_airplaneModeInter(new DCCDBusInterface(AirplaneModeService, AirplaneModePath, AirplaneModeInterface, QDBusConnection::systemBus(), this)) +{ +} + +// networkInter property +QString NetworkDBusProxy::activeConnections() +{ + return qvariant_cast(m_networkInter->property("ActiveConnections")); +} + +QString NetworkDBusProxy::connections() +{ + return qvariant_cast(m_networkInter->property("Connections")); +} + +uint NetworkDBusProxy::connectivity() +{ + return qvariant_cast(m_networkInter->property("Connectivity")); +} + +QString NetworkDBusProxy::devices() +{ + return qvariant_cast(m_networkInter->property("Devices")); +} + +bool NetworkDBusProxy::networkingEnabled() +{ + return qvariant_cast(m_networkInter->property("NetworkingEnabled")); +} +void NetworkDBusProxy::setNetworkingEnabled(bool value) +{ + m_networkInter->setProperty("NetworkingEnabled", QVariant::fromValue(value)); +} + +uint NetworkDBusProxy::state() +{ + return qvariant_cast(m_networkInter->property("State")); +} + +bool NetworkDBusProxy::vpnEnabled() +{ + return qvariant_cast(m_networkInter->property("VpnEnabled")); +} +void NetworkDBusProxy::setVpnEnabled(bool value) +{ + m_networkInter->setProperty("VpnEnabled", QVariant::fromValue(value)); +} + +QString NetworkDBusProxy::wirelessAccessPoints() +{ + return qvariant_cast(m_networkInter->property("WirelessAccessPoints")); +} +// proxyChains property +QString NetworkDBusProxy::iP() +{ + return qvariant_cast(m_proxyChainsInter->property("IP")); +} + +QString NetworkDBusProxy::password() +{ + return qvariant_cast(m_proxyChainsInter->property("Password")); +} + +uint NetworkDBusProxy::port() +{ + return qvariant_cast(m_proxyChainsInter->property("Port")); +} + +QString NetworkDBusProxy::type() +{ + return qvariant_cast(m_proxyChainsInter->property("Type")); +} + +QString NetworkDBusProxy::user() +{ + return qvariant_cast(m_proxyChainsInter->property("User")); +} + +bool NetworkDBusProxy::enabled() +{ + return qvariant_cast(m_airplaneModeInter->property("Enabled")); +} + +void NetworkDBusProxy::ShowPage(const QString &url) +{ + QDBusMessage message = QDBusMessage::createMethodCall("org.deepin.dde.ControlCenter1", "/org/deepin/dde/ControlCenter1", "org.deepin.dde.ControlCenter1", "ShowPage"); + message << QVariant::fromValue(url); + QDBusConnection::sessionBus().asyncCall(message); +} +// networkInter property +void NetworkDBusProxy::EnableDevice(const QDBusObjectPath &devPath, bool enabled) +{ + m_networkInter->asyncCall(QStringLiteral("EnableDevice"), QVariant::fromValue(devPath), QVariant::fromValue(enabled)); +} + +QString NetworkDBusProxy::GetProxyMethod() +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("GetProxyMethod"))); +} + +void NetworkDBusProxy::SetProxyMethod(const QString &proxyMode) +{ + m_networkInter->asyncCall(QStringLiteral("SetProxyMethod"), QVariant::fromValue(proxyMode)); +} + +void NetworkDBusProxy::SetProxyMethod(const QString &proxyMode, QObject *receiver, const char *member) +{ + QList argumentList; + argumentList << QVariant::fromValue(proxyMode); + m_networkInter->callWithCallback(QStringLiteral("SetProxyMethod"), argumentList, receiver, member); +} + +QString NetworkDBusProxy::GetProxyIgnoreHosts() +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("GetProxyIgnoreHosts"))); +} + +void NetworkDBusProxy::SetProxyIgnoreHosts(const QString &ignoreHosts) +{ + m_networkInter->asyncCall(QStringLiteral("SetProxyIgnoreHosts"), QVariant::fromValue(ignoreHosts)); +} + +void NetworkDBusProxy::SetProxyIgnoreHosts(const QString &ignoreHosts, QObject *receiver, const char *member) +{ + QList argumentList; + argumentList << QVariant::fromValue(ignoreHosts); + m_networkInter->callWithCallback(QStringLiteral("SetProxyIgnoreHosts"), argumentList, receiver, member); +} + +QString NetworkDBusProxy::GetAutoProxy() +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("GetAutoProxy"))); +} + +void NetworkDBusProxy::SetAutoProxy(const QString &proxyAuto) +{ + m_networkInter->asyncCall(QStringLiteral("SetAutoProxy"), QVariant::fromValue(proxyAuto)); +} + +void NetworkDBusProxy::SetAutoProxy(const QString &proxyAuto, QObject *receiver, const char *member) +{ + QList argumentList; + argumentList << QVariant::fromValue(proxyAuto); + m_networkInter->callWithCallback(QStringLiteral("SetAutoProxy"), argumentList, receiver, member); +} + +QStringList NetworkDBusProxy::GetProxy(const QString &proxyType) +{ + QStringList out; + QDBusMessage reply = m_networkInter->call(QDBus::Block, QStringLiteral("GetProxy"), QVariant::fromValue(proxyType)); + if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 2) { + out << qdbus_cast(reply.arguments().at(0)); + out << qdbus_cast(reply.arguments().at(1)); + } + return out; +} + +void NetworkDBusProxy::SetProxy(const QString &proxyType, const QString &host, const QString &port) +{ + m_networkInter->asyncCall(QStringLiteral("SetProxy"), QVariant::fromValue(proxyType), QVariant::fromValue(host), QVariant::fromValue(port)); +} + +void NetworkDBusProxy::SetProxy(const QString &proxyType, const QString &host, const QString &port, QObject *receiver, const char *member) +{ + QList argumentList; + argumentList << QVariant::fromValue(proxyType) << QVariant::fromValue(host) << QVariant::fromValue(port); + m_networkInter->callWithCallback(QStringLiteral("SetProxy"), argumentList, receiver, member); +} + +QString NetworkDBusProxy::GetActiveConnectionInfo() +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("GetActiveConnectionInfo"))); +} + +QDBusObjectPath NetworkDBusProxy::ActivateConnection(const QString &uuid, const QDBusObjectPath &devicePath) +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("ActivateConnection"), QVariant::fromValue(uuid), QVariant::fromValue(devicePath))); +} + +QDBusObjectPath NetworkDBusProxy::ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath) +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("ActivateAccessPoint"), QVariant::fromValue(uuid), QVariant::fromValue(apPath), QVariant::fromValue(devPath))); +} + +bool NetworkDBusProxy::ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath, QObject *receiver, const char *member, const char *errorSlot) +{ + QList argumentList; + argumentList << QVariant::fromValue(uuid) << QVariant::fromValue(apPath) << QVariant::fromValue(devPath); + return m_networkInter->callWithCallback(QStringLiteral("ActivateAccessPoint"), argumentList, receiver, member, errorSlot); +} + +void NetworkDBusProxy::DisconnectDevice(const QDBusObjectPath &devPath) +{ + m_networkInter->asyncCall(QStringLiteral("DisconnectDevice"), QVariant::fromValue(devPath)); +} + +void NetworkDBusProxy::RequestIPConflictCheck(const QString &ip, const QString &ifc) +{ + m_networkInter->asyncCall(QStringLiteral("RequestIPConflictCheck"), QVariant::fromValue(ip), QVariant::fromValue(ifc)); +} + +bool NetworkDBusProxy::IsDeviceEnabled(const QDBusObjectPath &devPath) +{ + return QDBusPendingReply(m_networkInter->asyncCall(QStringLiteral("IsDeviceEnabled"), QVariant::fromValue(devPath))); +} + +void NetworkDBusProxy::RequestWirelessScan() +{ + m_networkInter->asyncCall(QStringLiteral("RequestWirelessScan")); +} + +void NetworkDBusProxy::Set(const QString &type0, const QString &ip, uint port, const QString &user, const QString &password) +{ + m_proxyChainsInter->asyncCall(QStringLiteral("Set"), QVariant::fromValue(type0), QVariant::fromValue(ip), QVariant::fromValue(port), QVariant::fromValue(user), QVariant::fromValue(password)); +} + +uint NetworkDBusProxy::Notify(const QString &in0, uint in1, const QString &in2, const QString &in3, const QString &in4, const QStringList &in5, const QVariantMap &in6, int in7) +{ + QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify"); + message << QVariant::fromValue(in0) << QVariant::fromValue(in1) << QVariant::fromValue(in2) << QVariant::fromValue(in3) << QVariant::fromValue(in4) << QVariant::fromValue(in5) << QVariant::fromValue(in6) << QVariant::fromValue(in7); + return QDBusPendingReply(QDBusConnection::sessionBus().asyncCall(message)); +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.h b/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.h new file mode 100644 index 000000000..11af97e9c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdbusproxy.h @@ -0,0 +1,125 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKDBUSPROXY_H +#define NETWORKDBUSPROXY_H +#include +#include +class QDBusInterface; +class QDBusMessage; + +namespace dde { +namespace network { + +class DCCDBusInterface; + +class NetworkDBusProxy : public QObject +{ + Q_OBJECT +public: + explicit NetworkDBusProxy(QObject *parent = nullptr); + // networkInter + Q_PROPERTY(QString ActiveConnections READ activeConnections NOTIFY ActiveConnectionsChanged) + QString activeConnections(); + Q_PROPERTY(QString Connections READ connections NOTIFY ConnectionsChanged) + QString connections(); + Q_PROPERTY(uint Connectivity READ connectivity NOTIFY ConnectivityChanged) + uint connectivity(); + Q_PROPERTY(QString Devices READ devices NOTIFY DevicesChanged) + QString devices(); + Q_PROPERTY(bool NetworkingEnabled READ networkingEnabled WRITE setNetworkingEnabled NOTIFY NetworkingEnabledChanged) + bool networkingEnabled(); + void setNetworkingEnabled(bool value); + Q_PROPERTY(uint State READ state NOTIFY StateChanged) + uint state(); + Q_PROPERTY(bool VpnEnabled READ vpnEnabled WRITE setVpnEnabled NOTIFY VpnEnabledChanged) + bool vpnEnabled(); + void setVpnEnabled(bool value); + Q_PROPERTY(QString WirelessAccessPoints READ wirelessAccessPoints NOTIFY WirelessAccessPointsChanged) + QString wirelessAccessPoints(); + // proxyChains + Q_PROPERTY(QString IP READ iP NOTIFY IPChanged) + QString iP(); + Q_PROPERTY(QString Password READ password NOTIFY PasswordChanged) + QString password(); + Q_PROPERTY(uint Port READ port NOTIFY PortChanged) + uint port(); + Q_PROPERTY(QString Type READ type NOTIFY TypeChanged) + QString type(); + Q_PROPERTY(QString User READ user NOTIFY UserChanged) + QString user(); + // airplaneMode + Q_PROPERTY(bool Enabled READ enabled NOTIFY EnabledChanged) + bool enabled(); + + static void ShowPage(const QString &url); + +Q_SIGNALS: // SIGNALS + // networkInter + void AccessPointAdded(const QString &in0, const QString &in1); + void AccessPointPropertiesChanged(const QString &in0, const QString &in1); + void AccessPointRemoved(const QString &in0, const QString &in1); + void ActiveConnectionInfoChanged(); + void DeviceEnabled(const QString &device, bool enabled); + void IPConflict(const QString &in0, const QString &in1); + // begin property changed signals + void ActiveConnectionsChanged(const QString &value) const; + void ConnectionsChanged(const QString &value) const; + void ConnectivityChanged(uint value) const; + void DevicesChanged(const QString &value) const; + void NetworkingEnabledChanged(bool value) const; + void StateChanged(uint value) const; + void VpnEnabledChanged(bool value) const; + void WirelessAccessPointsChanged(const QString &value) const; + // proxyChains + // begin property changed signals + void IPChanged(const QString &value) const; + void PasswordChanged(const QString &value) const; + void PortChanged(uint value) const; + void TypeChanged(const QString &value) const; + void UserChanged(const QString &value) const; + // airplaneMode + // begin property changed signals + void BluetoothEnabledChanged(bool value) const; + void EnabledChanged(bool value) const; + void WifiEnabledChanged(bool value) const; + +public Q_SLOTS: + // networkInter + void EnableDevice(const QDBusObjectPath &devPath, bool enabled); + QString GetProxyMethod(); + void SetProxyMethod(const QString &proxyMode); + void SetProxyMethod(const QString &proxyMode, QObject *receiver, const char *member); + QString GetProxyIgnoreHosts(); + void SetProxyIgnoreHosts(const QString &ignoreHosts); + void SetProxyIgnoreHosts(const QString &ignoreHosts, QObject *receiver, const char *member); + QString GetAutoProxy(); + void SetAutoProxy(const QString &proxyAuto); + void SetAutoProxy(const QString &proxyAuto, QObject *receiver, const char *member); + QStringList GetProxy(const QString &proxyType); // 返回值待处理 + void SetProxy(const QString &proxyType, const QString &host, const QString &port); + void SetProxy(const QString &proxyType, const QString &host, const QString &port, QObject *receiver, const char *member); + QString GetActiveConnectionInfo(); + QDBusObjectPath ActivateConnection(const QString &uuid, const QDBusObjectPath &devicePath); + QDBusObjectPath ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath); + bool ActivateAccessPoint(const QString &uuid, const QDBusObjectPath &apPath, const QDBusObjectPath &devPath, QObject *receiver, const char *member, const char *errorSlot); + void DisconnectDevice(const QDBusObjectPath &devPath); + void RequestIPConflictCheck(const QString &ip, const QString &ifc); + bool IsDeviceEnabled(const QDBusObjectPath &devPath); + void RequestWirelessScan(); + + // proxyChains + void Set(const QString &type0, const QString &ip, uint port, const QString &user, const QString &password); + // Notifications + static uint Notify(const QString &in0, uint in1, const QString &in2, const QString &in3, const QString &in4, const QStringList &in5, const QVariantMap &in6, int in7); + +private: + DCCDBusInterface *m_networkInter; + DCCDBusInterface *m_proxyChainsInter; + DCCDBusInterface *m_airplaneModeInter; +}; + +} +} +#endif // NETWORKDBUSPROXY_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdetails.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkdetails.cpp new file mode 100644 index 000000000..387fc5b4a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdetails.cpp @@ -0,0 +1,268 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkdetails.h" +#include "networkdevicebase.h" +#include "wireddevice.h" +#include "wirelessdevice.h" + +#include + +#include +#include +#include +#include + +#include + +using namespace NetworkManager; +using namespace dde::network; + +NetworkDetails::NetworkDetails(QObject *parent) + : QObject(parent) +{ +} + +NetworkDetails::~NetworkDetails() +{ +} + +static const QString compressedIpv6Addr(const QString &ipv6Adr) +{ + if (ipv6Adr.contains("::")) + return ipv6Adr; + + // NOTE(sbw): Calculate longest zero sequence, ensure + int start = 0, len = 0; + int maxStart = 0, maxLen = 0; + const QStringList &sequence = ipv6Adr.split(':'); + for (int i = 0; i != sequence.size(); i++) { + if (sequence[i] == "0000") { + len += 5; + } else { + if (len > maxLen) { + maxStart = start; + maxLen = len; + } + start = (i + 1) * 5; + len = 0; + } + } + + if (maxLen) + return QString(ipv6Adr).replace(maxStart, maxLen, ':'); + + if (len > maxLen) { + if (start) + return QString(ipv6Adr).replace(start, len, ':'); + + return QString("::"); + } + + return ipv6Adr; +} + +QString NetworkDetails::prefixToNetMask(int prefixLength) +{ + uint32_t mask = (0xFFFFFFFF << (32 - prefixLength)) & 0xFFFFFFFF; + uint8_t m1 = mask >> 24; + uint8_t m2 = (mask >> 16) & 0xFF; + uint8_t m3 = (mask >> 8) & 0xFF; + uint8_t m4 = mask & 0xFF; + return QString("%1.%2.%3.%4").arg(m1).arg(m2).arg(m3).arg(m4); +} + +void NetworkDetails::updateData(const QJsonObject &info) +{ + m_items.clear(); + m_name.clear(); + m_devicePath = info.value("Device").toString(); + const QString type = info.value("ConnectionType").toString(); + const bool isHotspot = type == "wireless-hotspot"; + const bool isWireless = type == "wireless"; + QJsonObject hotspotInfo = info.value("Hotspot").toObject(); + if (isHotspot) { + m_name = tr("Hotspot"); + appendInfo(tr("SSID"), hotspotInfo.value("Ssid").toString()); + } else { + m_name = info.value("ConnectionName").toString(); + } + + if (isWireless) { + // 协议 + const QString &protocol = info.value("Protocol").toString(); + if (!protocol.isEmpty()) + appendInfo(tr("Protocol"), protocol); + + // 安全类型 + const QString &securityType = info.value("Security").toString(); + appendInfo(tr("Security Type"), securityType); + + // 网络通道 + const QString &channel = QString::number(hotspotInfo.value("Channel").toInt()); + if (!channel.isEmpty()) + appendInfo(tr("Channel"), channel); + } + if (isWireless || isHotspot) { + // 频段 + const QString &band = hotspotInfo.value("Band").toString(); + QString bandInfo = band == "a" ? "5 GHz" : (band == "bg" ? "2.4 GHz" : "automatic"); + appendInfo(tr("Band"), bandInfo); + } + if (isHotspot) { + const QString securityType = info.value("Security").toString(); + appendInfo(tr("Security Type"), securityType); + } + // 接口 + const auto device = info.value("DeviceInterface").toString(); + if (!device.isEmpty()) + appendInfo(tr("Interface"), device); + // MAC地址 + const QString mac = info.value("HwAddress").toString(); + if (!mac.isEmpty()) + appendInfo(tr("MAC"), mac); + if (!isHotspot) { + // ipv4 + if (info.contains("IPv4")) { + QJsonObject ipv4TopObject = info["IPv4"].toObject(); + QJsonArray ipv4Array = ipv4TopObject.value("Addresses").toArray(); + for (const QJsonValue ipv4Value : ipv4Array) { + const QJsonObject ipv4Object = ipv4Value.toObject(); + QString ip = ipv4Object.value("Address").toString(); + ip = ip.remove("\""); + if(ip != "0.0.0.0"){ + appendInfo(tr("IPv4"), ip); + } + int prefix = ipv4Object.value("Prefix").toInt(); + QString ip4Netmask = prefixToNetMask(prefix); + if (!ip4Netmask.isEmpty()) + appendInfo(tr("Netmask"), ip4Netmask); + } + const QString gateway = ipv4TopObject.value("Gateway").toString(); + if (!gateway.isEmpty()) + appendInfo(tr("Gateway"), gateway); + + const auto ip4PrimaryDns = ipv4TopObject.value("Nameservers").toArray(); + if (!ip4PrimaryDns.isEmpty()) + appendInfo(tr("Primary DNS"), ip4PrimaryDns.first().toString()); + } else { + const auto ipv4 = info.value("Ip4").toObject(); + if (!ipv4.isEmpty()) { + // ipv4 地址 + const auto ip4Addr = ipv4.value("Address").toString(); + if (!ip4Addr.isEmpty() and ip4Addr != "0.0.0.0") { + appendInfo(tr("IPv4"), ip4Addr); + } + // ipv4 子网掩码 + const auto ip4Netmask = ipv4.value("Mask").toString(); + if (!ip4Netmask.isEmpty()) + appendInfo(tr("Netmask"), ip4Netmask); + // ipv4 网关 + const auto gateway = ipv4.value("Gateways").toArray(); + if (!gateway.isEmpty()) + appendInfo(tr("Gateway"), gateway.first().toString()); + // ipv4 首选DNS + const auto ip4PrimaryDns = ipv4.value("Dnses").toArray(); + if (!ip4PrimaryDns.isEmpty()) + appendInfo(tr("Primary DNS"), ip4PrimaryDns.first().toString()); + } + } + // ipv6 + if (info.contains("IPv6")) { + QJsonObject ipv6TopObject = info["IPv6"].toObject(); + QJsonArray ipv6Array = ipv6TopObject.value("Addresses").toArray(); + for (const QJsonValue ipv6Value : ipv6Array) { + const QJsonObject ipv6Object = ipv6Value.toObject(); + QString ip = ipv6Object.value("Address").toString(); + ip = ip.remove("\""); + if(ip != "0::0"){ + appendInfo(tr("IPv6"), ip); + } + QString ip6Prefix = QString::number(ipv6Object.value("Prefix").toInt()); + if (!ip6Prefix.isEmpty()) + appendInfo(tr("Prefix"), ip6Prefix); + } + const QString gateway = ipv6TopObject.value("Gateway").toString(); + if (!gateway.isEmpty()) + appendInfo(tr("Gateway"), gateway); + + const auto ip4PrimaryDns = ipv6TopObject.value("Nameservers").toArray(); + if (!ip4PrimaryDns.isEmpty()) + appendInfo(tr("Primary DNS"), ip4PrimaryDns.first().toString()); + } else { + const auto ipv6 = info.value("Ip6").toObject(); + if (!ipv6.isEmpty()) { + // ipv6地址 + const auto& ipv6Address = ipv6Infomation(info, InfoType::Ip); + if(ipv6Address != "0::0"){ + appendInfo(tr("IPv6"), compressedIpv6Addr(ipv6Address)); + } + // ipv6前缀 + const auto ip6Prefix = QString::number(ipv6.value("Prefix").toInt()); + if (!ip6Prefix.isEmpty()) + appendInfo(tr("Prefix"), ip6Prefix); + // ipv6网关 + appendInfo(tr("Gateway"), compressedIpv6Addr(ipv6Infomation(info, InfoType::Gateway))); + + // ipv6 首选DNS + const auto ip6PrimaryDns = ipv6.value("Dnses").toArray(); + if (!ip6PrimaryDns.isEmpty()) + appendInfo(tr("Primary DNS"), compressedIpv6Addr(ip6PrimaryDns.first().toString())); + } + } + // 速率 + const QString speed = info.value("Speed").toString(); + if (!speed.isEmpty()) + appendInfo(tr("Speed"), speed); + } +} + +void NetworkDetails::appendInfo(const QString &title, const QString &value) +{ + m_items << qMakePair(title, value); +} + +QString NetworkDetails::ipv6Infomation(QJsonObject connectinfo, NetworkDetails::InfoType type) +{ + NetworkManager::Connection::Ptr connection = findConnectionByUuid(connectinfo.value("ConnectionUuid").toString()); + if (connection.isNull()) + return QString(); + + ConnectionSettings::Ptr connectionSettings = connection->settings(); + Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(Setting::Ipv6).staticCast(); + if (ipv6Setting.isNull()) + return QString(); + + QList addressInfos = ipv6Setting->addresses(); + if (ipv6Setting->method() == Ipv6Setting::Manual) { + if (addressInfos.count() == 0) { + qDebug() << "ipv6Setting error! "; + return QString(); + } + + switch (type) { + case Ip: + return addressInfos[0].ip().toString(); + case Gateway: + return addressInfos[0].gateway().toString(); + } + } + + if (ipv6Setting->method() == Ipv6Setting::Automatic || ipv6Setting->method() == Ipv6Setting::LinkLocal) { + const auto ipv6 = connectinfo.value("Ip6").toObject(); + switch (type) { + case Ip: + return ipv6.value("Address").toString(); + case Gateway: + return ipv6.value("Address").toString(); + } + } + + return QString(); +} + +QString NetworkDetails::devicePath() +{ + return m_devicePath; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdetails.h b/panels/dock/tray/plugins/dde-network-core/src/networkdetails.h new file mode 100644 index 000000000..fca1e4625 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdetails.h @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKDETAILS_H +#define NETWORKDETAILS_H + +#include + +class QJsonObject; + +namespace dde { + +namespace network { + +class NetworkDeviceBase; + +class NetworkDetails : QObject +{ + Q_OBJECT + + friend class NetworkController; + friend class NetworkInterProcesser; + +private: + enum InfoType { + Ip, + Gateway + }; + +public: + // 连接的网络名称 + inline QString name() { return m_name; } + inline QList> items() { return m_items; } + +private: + NetworkDetails(QObject *parent = Q_NULLPTR); + ~NetworkDetails(); + + void updateData(const QJsonObject &info); + void appendInfo(const QString &title, const QString &value); + QString ipv6Infomation(QJsonObject connectinfo, InfoType type); + QString devicePath(); + + QString prefixToNetMask(int prefixLength); + +private: + QString m_name; + QString m_devicePath; + QList> m_items; +}; + +} + +} + +#endif // UNETWORKDETAILS_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.cpp b/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.cpp new file mode 100644 index 000000000..f268bccf3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.cpp @@ -0,0 +1,176 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "realize/netinterface.h" +#include "networkdevicebase.h" +#include "netutils.h" + +using namespace dde::network; + +bool NetworkDeviceBase::IPValid() +{ + // 判读获取IP地址失败需要满足最后一个状态为未连接,上一个状态为失败,并且包含Config和IpConfig + if (m_statusQueue.size() == MaxQueueSize + && m_statusQueue[MaxQueueSize - 1] == DeviceStatus::Disconnected + && m_statusQueue[MaxQueueSize - 2] == DeviceStatus::Failed + && m_statusQueue.contains(DeviceStatus::Config) + && m_statusQueue.contains(DeviceStatus::IpConfig)) { + return false; + } + + return true; +} + +DeviceStatus NetworkDeviceBase::deviceStatus() const +{ + return deviceRealize()->deviceStatus(); +} + +QString NetworkDeviceBase::interface() const +{ + return deviceRealize()->interface(); +} + +QString NetworkDeviceBase::driver() const +{ + return deviceRealize()->driver(); +} + +bool NetworkDeviceBase::managed() const +{ + return deviceRealize()->managed(); +} + +QString NetworkDeviceBase::vendor() const +{ + return deviceRealize()->vendor(); +} + +QString NetworkDeviceBase::uniqueUuid() const +{ + return deviceRealize()->uniqueUuid(); +} + +bool NetworkDeviceBase::usbDevice() const +{ + return deviceRealize()->usbDevice(); +} + +QString NetworkDeviceBase::path() const +{ + return deviceRealize()->path(); +} + +QString NetworkDeviceBase::activeAp() const +{ + return deviceRealize()->activeAp(); +} + +bool NetworkDeviceBase::supportHotspot() const +{ + return deviceRealize()->supportHotspot(); +} + +QString NetworkDeviceBase::realHwAdr() const +{ + return deviceRealize()->realHwAdr(); +} + +QString NetworkDeviceBase::usingHwAdr() const +{ + return deviceRealize()->usingHwAdr(); +} + +QStringList NetworkDeviceBase::ipv4() const +{ + return deviceRealize()->ipv4(); +} + +QStringList NetworkDeviceBase::ipv6() const +{ + return deviceRealize()->ipv6(); +} + +QJsonObject NetworkDeviceBase::activeConnectionInfo() const +{ + return deviceRealize()->activeConnectionInfo(); +} + +void NetworkDeviceBase::setEnabled(bool enabled) +{ + deviceRealize()->setEnabled(enabled); +} + +void NetworkDeviceBase::disconnectNetwork() +{ + deviceRealize()->disconnectNetwork(); +} + +Connectivity NetworkDeviceBase::connectivity() +{ + return deviceRealize()->connectivity(); +} + +void NetworkDeviceBase::setName(const QString &name) +{ + if (m_name != name) { + m_name = name; + Q_EMIT nameChanged(name); + } +} + +QString NetworkDeviceBase::deviceName() +{ + return m_name; +} + +NetworkDeviceBase::NetworkDeviceBase(NetworkDeviceRealize *deviceInter, QObject *parent) + : QObject(parent) + , m_deviceInterface(deviceInter) + , m_enabled(true) +{ + Q_ASSERT(m_deviceInterface); + m_deviceInterface->setDevice(this); + + connect(m_deviceInterface, &NetworkDeviceRealize::deviceStatusChanged, this, &NetworkDeviceBase::deviceStatusChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::enableChanged, this, &NetworkDeviceBase::enableChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::connectionChanged, this, &NetworkDeviceBase::connectionChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::nameChanged, this, &NetworkDeviceBase::nameChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::removed, this, &NetworkDeviceBase::removed); + connect(m_deviceInterface, &NetworkDeviceRealize::activeConnectionChanged, this, &NetworkDeviceBase::activeConnectionChanged); + connect(m_deviceInterface, &NetworkDeviceRealize::ipV4Changed, this, &NetworkDeviceBase::ipV4Changed); +} + +NetworkDeviceBase::~NetworkDeviceBase() +{ + delete m_deviceInterface; +} + +NetworkDeviceRealize *NetworkDeviceBase::deviceRealize() const +{ + return m_deviceInterface; +} + +void NetworkDeviceBase::enqueueStatus(const DeviceStatus &status) +{ + if (m_statusQueue.size() >= MaxQueueSize) + m_statusQueue.dequeue(); + + m_statusQueue.enqueue(status); +} + +QString NetworkDeviceBase::getStatusName() +{ + return deviceRealize()->getStatusName(); +} + +QString NetworkDeviceBase::statusStringDetail() +{ + return deviceRealize()->statusStringDetail(); +} + +bool NetworkDeviceBase::isEnabled() const +{ + return m_deviceInterface->isEnabled(); +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.h b/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.h new file mode 100644 index 000000000..30d947e55 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/networkdevicebase.h @@ -0,0 +1,106 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKDEVICEBASE_H +#define NETWORKDEVICEBASE_H + +#include "networkconst.h" + +#include +#include + +namespace dde { + +namespace network { + +class NetworkDeviceRealize; + +#define MaxQueueSize 4 + +class NetworkDeviceBase : public QObject +{ + Q_OBJECT + + friend class NetworkController; + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + friend class IPConfilctChecker; + + Q_PROPERTY(QString statusName READ getStatusName) + Q_PROPERTY(QString statusDetail READ statusStringDetail) // 当前状态详细说明,取代statusStringDetail接口 + Q_PROPERTY(bool enabled READ isEnabled) // 当前网卡是否启用,对应于isEnabled() 接口,向外提供接口的同时,这里也给出属性 + Q_PROPERTY(bool IPValid READ IPValid) // IP是否合法,对应于isIPValid接口 + Q_PROPERTY(QString interface READ interface) // 对应于interface() 接口 + Q_PROPERTY(QString driver READ driver) // 对应于driver()接口 + Q_PROPERTY(bool managed READ managed) // 对应于managed接口 + Q_PROPERTY(QString vendor READ vendor) // 对应于vendor接口 + Q_PROPERTY(QString uniqueUuid READ uniqueUuid) // 对应于uniqueUuid接口 + Q_PROPERTY(bool usbDevice READ usbDevice) // 对应于usbDevice接口 + Q_PROPERTY(QString path READ path) // 对应于path接口 + Q_PROPERTY(QString activeAp READ activeAp) // 对应于ActiveAp接口 + Q_PROPERTY(bool supportHotspot READ supportHotspot) // 对应于supportHotspot接口 + Q_PROPERTY(QString realHwAdr READ realHwAdr) // 对应于realHwAdr接口 + Q_PROPERTY(QString usingHwAdr READ usingHwAdr) // 对应于usingHwAdr接口 + Q_PROPERTY(QStringList ipv4 READ ipv4) // 对应于ipv4接口 + Q_PROPERTY(QStringList ipv6 READ ipv6) // 对应于ipv6接口 + Q_PROPERTY(QString deviceName READ deviceName WRITE setName NOTIFY nameChanged) // 对应于设备名称 + +Q_SIGNALS: + void deviceStatusChanged(const DeviceStatus &) const; // 状态发生变化的时候触发的信号 + void enableChanged(const bool) const; // 开启设备或禁用设备的时候发出的信号(参数值True表示开启设备,False表示禁用设备) + void connectionChanged(); // 连接发生变化的时候触发的信号 + void nameChanged(const QString &); // 网卡名称发生变化的时候触发的信号 + void removed(); // 设备移除 + void activeConnectionChanged(); // 活动连接发生变化的时候发出的信号 + void ipV4Changed(); // IPV4地址变化 + +public: + bool isEnabled() const; // 当前的网卡是否启用 + virtual bool isConnected() const = 0; // 当前网络的网络是否处于连接状态 + bool IPValid(); // IP是否合法 + virtual DeviceType deviceType() const = 0; // 设备类型 未识别 无线网卡 有线网卡,直接在子类中返回当前的类型即可 + DeviceStatus deviceStatus() const; // 设备状态 + QString interface() const; // 返回设备上的Interface + QString driver() const; // 驱动,对应于备上返回值的Driver + bool managed() const; // 对应于设备上返回值的Managed + QString vendor() const; // 对应于设备上返回值的Vendor + QString uniqueUuid() const; // 网络设备的唯一的UUID,对应于设备上返回值的UniqueUuid + bool usbDevice() const; // 是否是USB设备,对应于设备上返回值的UsbDevice + QString path() const; // 设备路径,对应于设备上返回值的Path + QString activeAp() const; // 对应于设备上返回值的ActiveAp + bool supportHotspot() const; // 是否支持热点,对应于设备上返回值的SupportHotspot + QString realHwAdr() const; // mac地址 + QString usingHwAdr() const; // 正在使用的mac地址 + QStringList ipv4() const; // IPV4地址 + QStringList ipv6() const; // IPV6地址 + QJsonObject activeConnectionInfo() const; // 获取当前活动连接的信息 + void setEnabled(bool enabled); // 开启或禁用网卡 + void disconnectNetwork(); // 断开网络连接,该方法是一个虚方法,具体在子类 + Connectivity connectivity(); + virtual void setName(const QString &name); // 设置设备的名称 + virtual QString deviceName(); // 设备名称 + +protected: + explicit NetworkDeviceBase(NetworkDeviceRealize *deviceInter, QObject *parent = Q_NULLPTR); + virtual ~NetworkDeviceBase(); + NetworkDeviceRealize *deviceRealize() const; + void enqueueStatus(const DeviceStatus &status); + virtual bool getHotspotEnabeld() { return false; } + +protected: + QString getStatusName(); + QString statusStringDetail(); + +private: + NetworkDeviceRealize *m_deviceInterface; + bool m_enabled; + QQueue m_statusQueue; + QString m_name; +}; + +} + +} + +#endif // UNETWORKDEVICEBASE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.cpp new file mode 100644 index 000000000..62ec619d3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.cpp @@ -0,0 +1,325 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "proxycontroller.h" +#include "networkdbusproxy.h" + +#include +#include + +using namespace dde::network; + +ProxyController::ProxyController(NetworkDBusProxy *networkInter, QObject *parent) + : QObject(parent) + , m_networkInter(networkInter) + , m_proxyMothod(ProxyMethod::Init) +{ + Q_ASSERT(m_networkInter); + // 设置成同步的方式,目的是为了在初始化的时候能正确的返回应用代理的数据, + // 否则,如果是异步的方式,那么在初始化的时候查询应用代理的数据的时候,返回空 + // 后续ProxyChains的每个信号都会触发一次,将会触发多次appProxyChanged信号 + // 连接应用代理的相关的槽 + connect(m_networkInter, &NetworkDBusProxy::IPChanged, this, &ProxyController::onIPChanged); + connect(m_networkInter, &NetworkDBusProxy::PasswordChanged, this, &ProxyController::onPasswordChanged); + connect(m_networkInter, &NetworkDBusProxy::TypeChanged, this, &ProxyController::onTypeChanged); + connect(m_networkInter, &NetworkDBusProxy::UserChanged, this, &ProxyController::onUserChanged); + connect(m_networkInter, &NetworkDBusProxy::PortChanged, this, &ProxyController::onPortChanged); + // 初始化应用代理的相关的数据 + m_appProxyConfig.type = appProxyType(m_networkInter->type()); + m_appProxyConfig.ip = m_networkInter->iP(); + m_appProxyConfig.port = m_networkInter->port(); + m_appProxyConfig.username = m_networkInter->user(); + m_appProxyConfig.password = m_networkInter->password(); + // 判断是否存在proxychains4来决定是否存在应用代理 + m_appProxyExist = !QStandardPaths::findExecutable("proxychains4").isEmpty(); +} + +ProxyController::~ProxyController() +{ +} + +void ProxyController::setProxyMethod(const ProxyMethod &pm) +{ + // 设置代理模式,手动模式,自动模式和关闭代理 + QString methodName = convertProxyMethod(pm); + m_networkInter->SetProxyMethod(methodName, this, SLOT(queryProxyMethod())); +} + +void ProxyController::setProxyIgnoreHosts(const QString &hosts) +{ + m_networkInter->SetProxyIgnoreHosts(hosts, this, SLOT(queryProxyIgnoreHosts())); +} + +void ProxyController::setAutoProxy(const QString &proxy) +{ + m_networkInter->SetAutoProxy(proxy, this, SLOT(queryAutoProxy())); +} + +void ProxyController::setProxy(const SysProxyType &type, const QString &addr, const QString &port) +{ + QString uType = convertSysProxyType(type); + switch (type) { + case SysProxyType::Ftp: + m_networkInter->SetProxy(uType, addr, port, this, SLOT(queryProxyDataByFtp())); + break; + case SysProxyType::Http: + m_networkInter->SetProxy(uType, addr, port, this, SLOT(queryProxyDataByHttp())); + break; + case SysProxyType::Https: + m_networkInter->SetProxy(uType, addr, port, this, SLOT(queryProxyDataByHttps())); + break; + case SysProxyType::Socks: + m_networkInter->SetProxy(uType, addr, port, this, SLOT(queryProxyDataBySocks())); + break; + } +} + +void ProxyController::setAppProxy(const AppProxyConfig &config) +{ + m_networkInter->Set(appProxyType(config.type), config.ip, config.port, config.username, config.password); +} + +AppProxyConfig ProxyController::appProxy() const +{ + return m_appProxyConfig; +} + +SysProxyConfig ProxyController::proxy(const SysProxyType &type) const +{ + // 根据列表的类型返回实际的配置 + for (SysProxyConfig config : m_sysProxyConfig) { + if (config.type == type) + return config; + } + + return SysProxyConfig(); +} + +bool ProxyController::appProxyExist() const +{ + return m_appProxyExist; +} + +void ProxyController::querySysProxyData() +{ + // 查询系统代理的数据 + m_sysProxyConfig.clear(); + + static QStringList proxyTypes = {"http", "https", "ftp", "socks"}; + + // 依次获取每种类型的数据,并填充到列表中 + for (QString type : proxyTypes) + queryProxyDataByType(type); + + // 查询自动代理 + queryAutoProxy(); + // 查询代理模式 + queryProxyMethod(); + // 查询忽略的主机 + queryProxyIgnoreHosts(); +} + +void ProxyController::queryAutoProxy() +{ + QString autoProxyURL = m_networkInter->GetAutoProxy(); + if (m_autoProxyURL != autoProxyURL) { + m_autoProxyURL = autoProxyURL; + Q_EMIT autoProxyChanged(autoProxyURL); + } +} + +QString ProxyController::convertProxyMethod(const ProxyMethod &method) +{ + switch (method) { + case ProxyMethod::Auto: return "auto"; + case ProxyMethod::Manual: return "manual"; + default: break; + } + + return "none"; +} + +QString ProxyController::convertSysProxyType(const SysProxyType &type) +{ + switch (type) { + case SysProxyType::Ftp: return "ftp"; + case SysProxyType::Http: return "http"; + case SysProxyType::Https: return "https"; + case SysProxyType::Socks: return "socks"; + } + + return "http"; +} + +SysProxyType ProxyController::convertSysProxyType(const QString &type) +{ + if (type == "ftp") + return SysProxyType::Ftp; + + if (type == "http") + return SysProxyType::Http; + + if (type == "https") + return SysProxyType::Https; + + if (type == "socks") + return SysProxyType::Socks; + + return SysProxyType::Http; +} + +void ProxyController::queryProxyDataByFtp() +{ + queryProxyDataByType("ftp"); +} + +void ProxyController::queryProxyDataByHttp() +{ + queryProxyDataByType("http"); +} + +void ProxyController::queryProxyDataByHttps() +{ + queryProxyDataByType("https"); +} + +void ProxyController::queryProxyDataBySocks() +{ + queryProxyDataByType("socks"); +} + +void ProxyController::queryProxyDataByType(const QString &type) +{ + SysProxyType uType = convertSysProxyType(type); + QStringList proxy = m_networkInter->GetProxy(type); + if (proxy.size() != 2) + return; + bool finded = false; + // 先查找原来是否存在响应的代理,如果存在,就直接更新最新的数据 + for (SysProxyConfig &conf : m_sysProxyConfig) { + if (conf.type == uType) { + QString url = proxy.at(0); + uint port = proxy.at(1).toUInt(); + if (url != conf.url || port != conf.port) { + conf.url = url; + conf.port = port; + Q_EMIT proxyChanged(conf); + } + finded = true; + break; + } + } + // 如果不存在,直接将数据放入内存中 + if (!finded) { + SysProxyConfig proxyConfig; + proxyConfig.url = proxy.at(0); + proxyConfig.port = proxy.at(1).toUInt(); + proxyConfig.type = uType; + m_sysProxyConfig << proxyConfig; + Q_EMIT proxyChanged(proxyConfig); + } +} + +ProxyMethod ProxyController::convertProxyMethod(const QString &method) +{ + // 根据传入的字符串获取代理模式的枚举值 + if (method == "auto") + return ProxyMethod::Auto; + + if (method == "manual") + return ProxyMethod::Manual; + + return ProxyMethod::None; +} + +void ProxyController::queryProxyMethod() +{ + // 查询代理模式 + ProxyMethod method = convertProxyMethod(m_networkInter->GetProxyMethod()); + if (method != m_proxyMothod) { + m_proxyMothod = method; + Q_EMIT proxyMethodChanged(method); + } +} + +void ProxyController::queryProxyIgnoreHosts() +{ + // 查询忽略的代理主机 + QString proxyIgnoreHosts = m_networkInter->GetProxyIgnoreHosts(); + if (m_proxyIgnoreHosts != proxyIgnoreHosts) { + m_proxyIgnoreHosts = proxyIgnoreHosts; + Q_EMIT proxyIgnoreHostsChanged(proxyIgnoreHosts); + } +} + +void ProxyController::onIPChanged(const QString &value) +{ + // 应用代理的IP发生变化 + if (value != m_appProxyConfig.ip) { + m_appProxyConfig.ip = value; + Q_EMIT appIPChanged(value); + } +} + +void ProxyController::onPasswordChanged(const QString &value) +{ + // 应用代理的密码发生变化 + if (value != m_appProxyConfig.password) { + m_appProxyConfig.password = value; + Q_EMIT appPasswordChanged(value); + } +} + +AppProxyType ProxyController::appProxyType(const QString &v) +{ + if (v == "http") + return AppProxyType::Http; + + if (v == "socks4") + return AppProxyType::Socks4; + + if (v == "socks5") + return AppProxyType::Socks5; + + return AppProxyType::Http; +} + +QString ProxyController::appProxyType(const AppProxyType &v) +{ + switch (v) { + case AppProxyType::Http: return "http"; + case AppProxyType::Socks4: return "socks4"; + case AppProxyType::Socks5: return "socks5"; + } + + return "http"; +} + +void ProxyController::onTypeChanged(const QString &value) +{ + // 应用代理类型发生变化 + AppProxyType t = appProxyType(value); + if (t != m_appProxyConfig.type) { + m_appProxyConfig.type = t; + Q_EMIT appTypeChanged(t); + } +} + +void ProxyController::onUserChanged(const QString &value) +{ + // 应用代理用户名发生变化 + if (value != m_appProxyConfig.username) { + m_appProxyConfig.username = value; + Q_EMIT appUsernameChanged(value); + } +} + +void ProxyController::onPortChanged(uint value) +{ + // 应用代理端口发生变化 + if (value != m_appProxyConfig.port) { + m_appProxyConfig.port = value; + Q_EMIT appPortChanged(value); + } +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.h b/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.h new file mode 100644 index 000000000..6f228026c --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/proxycontroller.h @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef PROXYCONTROLLER_H +#define PROXYCONTROLLER_H + +#include "networkconst.h" +#include "netutils.h" + +#include + +namespace dde { + +namespace network { +class NetworkDBusProxy; + +class ProxyController : public QObject +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + /* 系统代理 */ + void querySysProxyData(); // 查询系统代理,一般在控制中心点击的时候实时调用 + void setProxyMethod(const ProxyMethod &pm); // 设置代理模式 + inline ProxyMethod proxyMethod() const { return m_proxyMothod; } // 返回代理模式 + void setProxyIgnoreHosts(const QString &hosts); // 设置忽略的主机 + inline QString proxyIgnoreHosts() const { return m_proxyIgnoreHosts; } // 返回代理主机列表 + void setAutoProxy(const QString &proxy); // 设置自动代理的配置URL + inline QString autoProxy() { return m_autoProxyURL; } // 返回自动代理的配置URL + void setProxy(const SysProxyType &type, + const QString &addr, const QString &port); // 设置代理信息,type是一个枚举类型,一般是manual模式下设置 + SysProxyConfig proxy(const SysProxyType &type) const; // 获取对应类型下的系统代理数据 + + /* 应用代理 */ + bool appProxyExist() const; + void setAppProxy(const AppProxyConfig &config); // 设置应用代理数据 + AppProxyConfig appProxy() const; // 获取应用代理数据 + +Q_SIGNALS: + /* 系统代理 */ + void autoProxyChanged(const QString &); // 自动代理发生变化 + void proxyChanged(const SysProxyConfig &); // 某种代理数据发生变化的时候触发的信号 + void proxyMethodChanged(const ProxyMethod &); // 代理模式发生变化 + void proxyIgnoreHostsChanged(const QString &); // 忽略的主机发生变化 + /* 应用代理 */ + void appIPChanged(const QString &ip); // 应用代理IP发生变化 + void appPasswordChanged(const QString &password); // 应用代理密码发生变化 + void appTypeChanged(const AppProxyType &type); // 应用代理类型发生变化 + void appUsernameChanged(const QString &username); // 应用代理用户名发生变化 + void appPortChanged(const uint &port); // 应用代理端口发生变化 + +protected: + explicit ProxyController(NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + ~ProxyController(); + + ProxyMethod convertProxyMethod(const QString &method); // 将代理模式字符串转换为枚举 + QString convertProxyMethod(const ProxyMethod &method); // 将代理模式枚举转换为字符串 + + QString convertSysProxyType(const SysProxyType &type); // 将代理模式枚举值转换为字符串 + SysProxyType convertSysProxyType(const QString &type); // 将代理模式字符串转换为枚举值 + + AppProxyType appProxyType(const QString &v); // 系统代理类型转换,字符串到枚举 + QString appProxyType(const AppProxyType &v); // 系统代理类型转换,枚举到字符串 + +private Q_SLOTS: + void onIPChanged(const QString &value); + void onPasswordChanged(const QString &value); + void onTypeChanged(const QString &value); + void onUserChanged(const QString &value); + void onPortChanged(uint value); + + void queryAutoProxy(); // 查询自动代理的URL + void queryProxyMethod(); // 查询自动代理模式 + void queryProxyIgnoreHosts(); // 查询代理忽略的主机 + void queryProxyDataByType(const QString &type); // 查询代理数据 + + void queryProxyDataByFtp(); + void queryProxyDataByHttp(); + void queryProxyDataByHttps(); + void queryProxyDataBySocks(); +private: + NetworkDBusProxy *m_networkInter; + QList m_sysProxyConfig; + QString m_autoProxyURL; + ProxyMethod m_proxyMothod; + QString m_proxyIgnoreHosts; + AppProxyConfig m_appProxyConfig; + bool m_appProxyExist; +}; + +} + +} + +#endif // UPROXYCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.cpp new file mode 100644 index 000000000..ef242438d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.cpp @@ -0,0 +1,838 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "deviceinterrealize.h" +#include "wireddevice.h" +#include "wirelessdevice.h" +#include "networkdbusproxy.h" + +#include +#include + +using namespace dde::network; + +#define UNKNOW_MODE 0 +#define ADHOC_MODE 1 +#define INFRA_MODE 2 +#define AP_MODE 3 + +#define ACTIVATING 1 +#define ACTIVATED 2 +#define DEACTIVATING 3 +#define DEACTIVATED 4 + +const QStringList DeviceInterRealize::ipv4() +{ + if (!isConnected() || !isEnabled()) + return QStringList(); + + if (m_activeInfoData.contains("IPv4")) { + QJsonObject ipv4TopObject = m_activeInfoData["IPv4"].toObject(); + QJsonArray ipv4Array = ipv4TopObject.value("Addresses").toArray(); + QStringList ipv4s; + for (const QJsonValue ipv4Value : ipv4Array) { + const QJsonObject ipv4Object = ipv4Value.toObject(); + QString ip = ipv4Object.value("Address").toString(); + ip = ip.remove("\""); + ipv4s << ip; + } + ipv4s = getValidIPV4(ipv4s); + return ipv4s; + } + + // 返回IPv4地址 + QJsonValue ipJsonData = m_activeInfoData["Ip4"]; + QJsonObject objIpv4 = ipJsonData.toObject(); + return { objIpv4.value("Address").toString() }; +} + +const QStringList DeviceInterRealize::ipv6() +{ + if (!isConnected() || !isEnabled() || !m_activeInfoData.contains("Ip6")) + return QStringList(); + + if (m_activeInfoData.contains("IPv6")) { + QJsonObject ipv6TopObject = m_activeInfoData["IPv6"].toObject(); + QJsonArray ipv6Array = ipv6TopObject.value("Addresses").toArray(); + QStringList ipv6s; + for (const QJsonValue ipv6Value : ipv6Array) { + const QJsonObject ipv6Object = ipv6Value.toObject(); + QString ip = ipv6Object.value("Address").toString(); + ip = ip.remove("\""); + ipv6s << ip; + } + return ipv6s; + } + + // 返回IPv4地址 + QJsonValue ipJsonData = m_activeInfoData["Ip6"]; + QJsonObject objIpv6 = ipJsonData.toObject(); + return { objIpv6.value("Address").toString() }; +} + +QJsonObject DeviceInterRealize::activeConnectionInfo() const +{ + return m_activeInfoData; +} + +QStringList DeviceInterRealize::getValidIPV4(const QStringList &ipv4s) +{ + if (ipv4s.size() > 1 || ipv4s.size() == 0) + return ipv4s; + + // 检查IP列表,如果发现有IP为0.0.0.0,则让其重新获取一次,保证IP获取正确 + // 这种情况一般发生在关闭热点后,因此在此处处理 + if (isIpv4Address(ipv4s[0])) + return ipv4s; + + const QString activeConnInfo = m_networkInter->GetActiveConnectionInfo(); + QJsonParseError error; + QJsonDocument json = QJsonDocument::fromJson(activeConnInfo.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) + return ipv4s; + + if (!json.isArray()) + return ipv4s; + + QJsonArray infoArray = json.array(); + for (const QJsonValue ipInfo : infoArray) { + const QJsonObject ipObject = ipInfo.toObject(); + if (ipObject.value("Device").toString() != this->path()) + continue; + + if (!ipObject.contains("IPv4")) + return ipv4s; + + QJsonObject ipV4Object = ipObject.value("IPv4").toObject(); + if (!ipV4Object.contains("Addresses")) + return ipv4s; + + QStringList ipAddresses; + QJsonArray ipv4Addresses = ipV4Object.value("Addresses").toArray(); + for (const QJsonValue addr : ipv4Addresses) { + const QJsonObject addressObject = addr.toObject(); + QString ip = addressObject.value("Address").toString(); + if (isIpv4Address(ip)) + ipAddresses << ip; + } + if (ipAddresses.size() > 0) { + m_activeInfoData = ipObject; + return ipAddresses; + } + } + + return ipv4s; +} + +bool DeviceInterRealize::isIpv4Address(const QString &ip) const +{ + QHostAddress ipAddr(ip); + if (ipAddr == QHostAddress(QHostAddress::Null) || ipAddr == QHostAddress(QHostAddress::AnyIPv4) + || ipAddr.protocol() != QAbstractSocket::NetworkLayerProtocol::IPv4Protocol) { + return false; + } + + QRegularExpression regExpIP("((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[\\.]){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"); + return regExpIP.match(ip).hasMatch(); +} + +void DeviceInterRealize::setEnabled(bool enabled) +{ + m_networkInter->EnableDevice(QDBusObjectPath(path()), enabled); +} + +Connectivity DeviceInterRealize::connectivity() +{ + return m_connectivity; +} + +void DeviceInterRealize::deviceConnectionFailed() +{ + // 连接失败 +// Q_EMIT connectionFailed(item); + Q_EMIT deviceStatusChanged(DeviceStatus::Failed); +} + +void DeviceInterRealize::deviceConnectionSuccess() +{ + Q_EMIT deviceStatusChanged(DeviceStatus::Activated); +} + +DeviceInterRealize::DeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent) + : NetworkDeviceRealize(ipChecker, parent) + , m_networkInter(networkInter) + , m_enabled(true) + , m_connectivity(Connectivity::Full) +{ +} + +DeviceInterRealize::~DeviceInterRealize() +{ +} + +NetworkDBusProxy *DeviceInterRealize::networkInter() +{ + return m_networkInter; +} + +void DeviceInterRealize::updateDeviceInfo(const QJsonObject &info) +{ + m_data = info; + DeviceStatus stat = convertDeviceStatus(info.value("State").toInt()); + + setDeviceStatus(stat); +} + +void DeviceInterRealize::initDeviceInfo() +{ + if (m_networkInter) { + // 状态发生变化后,获取设备的实时信息 + m_enabled = m_networkInter->IsDeviceEnabled(QDBusObjectPath(path())); + } +} + +void DeviceInterRealize::setDeviceEnabledStatus(const bool &enabled) +{ + m_enabled = enabled; + Q_EMIT enableChanged(enabled); +} + +void DeviceInterRealize::updateActiveConnectionInfo(const QList &infos) +{ + const QStringList oldIpv4 = ipv4(); + m_activeInfoData = QJsonObject(); + for (const QJsonObject &info : infos) { + if (info.value("ConnectionType").toString() == deviceKey()) { + // 如果找到了当前硬件地址的连接信息,则直接使用这个数据 + m_activeInfoData = info; + break; + } + } + + // 获取到完整的IP地址后,向外发送连接改变的信号 + if (!m_activeInfoData.isEmpty()) + Q_EMIT connectionChanged(); + + QStringList ipv4s = ipv4(); + bool ipChanged = false; + if (oldIpv4.size() != ipv4s.size()) { + ipChanged = true; + } else { + for (const QString &ip : ipv4s) { + if (!oldIpv4.contains(ip)) { + ipChanged = true; + break; + } + } + } + if (ipChanged) + Q_EMIT ipV4Changed(); +} + +void DeviceInterRealize::setDeviceStatus(const DeviceStatus &status) +{ + // 如果是开启热点,就让其renweus断开的状态 + DeviceStatus stat = status; + if (mode() == AP_MODE) + stat = DeviceStatus::Disconnected; + + NetworkDeviceRealize::setDeviceStatus(stat); +} + +int DeviceInterRealize::mode() const +{ + if (m_data.contains("Mode")) + return m_data.value("Mode").toInt(); + + return UNKNOW_MODE; +} + +/** + * @brief 有线设备类的具体实现 + */ + +WiredDeviceInterRealize::WiredDeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent) + : DeviceInterRealize(ipChecker, networkInter, parent) +{ +} + +WiredDeviceInterRealize::~WiredDeviceInterRealize() +{ + for (auto item : m_connections) { + delete item; + } + m_connections.clear(); +} + +bool WiredDeviceInterRealize::connectNetwork(WiredConnection *connection) +{ + if (!connection) + return false; + + networkInter()->ActivateConnection(connection->connection()->uuid(), QDBusObjectPath(path())); + return true; +} + +void WiredDeviceInterRealize::disconnectNetwork() +{ + networkInter()->DisconnectDevice(QDBusObjectPath(path())); +} + +bool WiredDeviceInterRealize::isConnected() const +{ + for (WiredConnection *connection : m_connections) { + if (connection->connected()) + return true; + } + + return false; +} + +QList WiredDeviceInterRealize::wiredItems() const +{ + return m_connections; +} + +WiredConnection *WiredDeviceInterRealize::findConnection(const QString &path) +{ + for (WiredConnection *conn : m_connections) { + if (conn->connection()->path() == path) + return conn; + } + + return Q_NULLPTR; +} + +void WiredDeviceInterRealize::setDeviceEnabledStatus(const bool &enabled) +{ + if (!enabled) { + // 禁用网卡的情况下,先清空连接信息 + for (WiredConnection *connection : m_connections) + connection->setConnectionStatus(ConnectionStatus::Deactivated); + } + + DeviceInterRealize::setDeviceEnabledStatus(enabled); +} + +void WiredDeviceInterRealize::updateConnection(const QJsonArray &info) +{ + QList newWiredConnections; + QList changedWiredConnections; + QStringList connPaths; + for (const QJsonValue &jsonValue : info) { + const QJsonObject &jsonObj = jsonValue.toObject(); + const QString IfcName = jsonObj.value("IfcName").toString(); + if (!IfcName.isEmpty() && IfcName != interface()) + continue; + + const QString path = jsonObj.value("Path").toString(); + WiredConnection *conn = findConnection(path); + if (!conn) { + conn = new WiredConnection; + m_connections << conn; + newWiredConnections << conn; + } else { + if (conn->connection()->id() != jsonObj.value("Id").toString() + || conn->connection()->ssid() != jsonObj.value("Ssid").toString()) + changedWiredConnections << conn; + } + + conn->setConnection(jsonObj); + if (!connPaths.contains(path)) + connPaths << path; + } + + QList rmConns; + for (WiredConnection *connection : m_connections) { + if (!connPaths.contains(connection->connection()->path())) + rmConns << connection; + } + + for (WiredConnection *connection : rmConns) + m_connections.removeOne(connection); + + if (changedWiredConnections.size()) + Q_EMIT connectionPropertyChanged(changedWiredConnections); + + if (newWiredConnections.size() > 0) + Q_EMIT connectionAdded(newWiredConnections); + + if (rmConns.size() > 0) + Q_EMIT connectionRemoved(rmConns); + + // 提交改变信号后,删除不在的连接 + for (WiredConnection *connection : rmConns) + delete connection; + + // 排序 + sortWiredItem(m_connections); +} + +WiredConnection *WiredDeviceInterRealize::findWiredConnectionByUuid(const QString &uuid) +{ + for (WiredConnection *connection : m_connections) { + if (connection->connection()->uuid() == uuid) + return connection; + } + + return Q_NULLPTR; +} + +static ConnectionStatus convertStatus(int status) +{ + if (status == ACTIVATING) + return ConnectionStatus::Activating; + + if (status == ACTIVATED) + return ConnectionStatus::Activated; + + if (status == DEACTIVATING) + return ConnectionStatus::Deactivating; + + if (status == DEACTIVATED) + return ConnectionStatus::Deactivated; + + return ConnectionStatus::Unknown; +} + +void WiredDeviceInterRealize::updateActiveInfo(const QList &info) +{ + bool changeStatus = false; + // 根据返回的UUID找到对应的连接,找到State=2的连接变成连接成功状态 + for (const QJsonObject &activeInfo : info) { + const QString uuid = activeInfo.value("Uuid").toString(); + WiredConnection *connection = findWiredConnectionByUuid(uuid); + if (!connection) + continue; + + ConnectionStatus status = convertStatus(activeInfo.value("State").toInt()); + if (connection->status() != status) { + connection->setConnectionStatus(status); + changeStatus = true; + } + } + + // 调用基类的函数,更改设备的状态,同时向外发送信号 + DeviceInterRealize::updateActiveInfo(info); + if (changeStatus) + Q_EMIT activeConnectionChanged(); +} + +QString WiredDeviceInterRealize::deviceKey() +{ + return "wired"; +} + +/** + * @brief WirelessDeviceInterRealize::WirelessDeviceInterRealize + * @param networkInter + * @param parent + */ + +bool WirelessDeviceInterRealize::isConnected() const +{ + for (AccessPoints *ap : m_accessPoints) { + if (ap->status() == ConnectionStatus::Activated) + return true; + } + + return false; +} + +QList WirelessDeviceInterRealize::accessPointItems() const +{ + if (needShowAccessPoints()) + return m_accessPoints; + + return QList(); +} + +void WirelessDeviceInterRealize::scanNetwork() +{ + networkInter()->RequestWirelessScan(); +} + +void WirelessDeviceInterRealize::connectNetwork(const AccessPoints *item) +{ + WirelessConnection *wirelessConn = findConnectionByAccessPoint(item); + if (!wirelessConn) + return; + + const QString uuid = wirelessConn->connection()->uuid(); + const QString apPath = item->path(); + const QString devPath = path(); + + qInfo() << "Connect to the AP, uuid:" << uuid << ", access point path:" << apPath << ", device path:" << devPath; + networkInter()->ActivateAccessPoint(uuid, QDBusObjectPath(apPath), QDBusObjectPath(devPath), this, SLOT(deviceConnectionSuccess()), SLOT(deviceConnectionFailed())); +} + +AccessPoints *WirelessDeviceInterRealize::activeAccessPoints() const +{ + // 如果网卡是关闭的状态下,肯定是没有连接 + if (!isEnabled()) + return Q_NULLPTR; + + for (AccessPoints *ap : m_accessPoints) { + if (ap->connected()) + return ap; + } + + return Q_NULLPTR; +} + +void WirelessDeviceInterRealize::disconnectNetwork() +{ + networkInter()->DisconnectDevice(QDBusObjectPath(path())); +} + +QList WirelessDeviceInterRealize::items() const +{ + QList lstItems; + for (WirelessConnection *item : m_connections) { + if (item->accessPoints()) + lstItems << item; + } + + return lstItems; +} + +WirelessDeviceInterRealize::WirelessDeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent) + : DeviceInterRealize(ipChecker, networkInter, parent) +{ +} + +WirelessDeviceInterRealize::~WirelessDeviceInterRealize() +{ + clearListData(m_accessPoints); + clearListData(m_connections); +} + +WirelessConnection *WirelessDeviceInterRealize::findConnectionByPath(const QString &path) +{ + for (WirelessConnection *conn : m_connections) { + if (conn->connection()->path() == path) + return conn; + } + + return Q_NULLPTR; +} + +AccessPoints *WirelessDeviceInterRealize::findAccessPoint(const QString &ssid) +{ + for (AccessPoints *accessPoint : m_accessPoints) { + if (accessPoint->ssid() == ssid) + return accessPoint; + } + + return Q_NULLPTR; +} + +WirelessConnection *WirelessDeviceInterRealize::findConnectionByAccessPoint(const AccessPoints *accessPoint) +{ + if (!accessPoint) + return Q_NULLPTR; + + for (WirelessConnection *connection : m_connections) { + if (connection->accessPoints() == accessPoint) + return connection; + + if (connection->connection()->ssid() == accessPoint->ssid()) + return connection; + } + + return Q_NULLPTR; +} + +/** + * @brief 同步热点和连接的信息 + */ +void WirelessDeviceInterRealize::syncConnectionAccessPoints() +{ + if (m_accessPoints.isEmpty()) { + clearListData(m_connections); + return; + } + + QList connections; + // 找到每个热点对应的Connection,并将其赋值 + for (AccessPoints *accessPoint : m_accessPoints) { + WirelessConnection *connection = findConnectionByAccessPoint(accessPoint); + if (!connection) { + connection = WirelessConnection::createConnection(accessPoint); + m_connections << connection; + } + + connection->m_accessPoints = accessPoint; + connections << connection; + } + updateActiveInfo(); + // 删除列表中没有AccessPoints的Connection,让两边保持数据一致 + QList rmConns; + for (WirelessConnection *connection : m_connections) { + if (!connections.contains(connection)) + rmConns << connection; + } + + for (WirelessConnection *rmConnection : rmConns) { + m_connections.removeOne(rmConnection); + delete rmConnection; + } +} + +void WirelessDeviceInterRealize::updateActiveInfo() +{ + if (m_activeAccessPoints.isEmpty()) + return; + + QList tmpApList = m_accessPoints; + // 遍历活动连接列表,找到对应的wlan,改变其连接状态,State赋值即可 + bool changed = false; + AccessPoints *activeAp = Q_NULLPTR; + for (const QJsonObject &aapInfo : m_activeAccessPoints) { + int connectionStatus = aapInfo.value("State").toInt(); + QString ssid = aapInfo.value("Id").toString(); + AccessPoints *ap = findAccessPoint(ssid); + if (!ap) + continue; + + tmpApList.removeAll(ap); + ConnectionStatus status = convertConnectionStatus(connectionStatus); + if (ap->status() == status) + continue; + + ap->updateConnectionStatus(status); + changed = true; + if (ap->status() == ConnectionStatus::Activated) + activeAp = ap; + } + + // 将其它连接变成普通状态 + for (AccessPoints *ap : tmpApList) + ap->updateConnectionStatus(ConnectionStatus::Unknown); + + if (changed) { + Q_EMIT activeConnectionChanged(); + } + + // 如果发现其中一个连接成功,将这个连接成功的信号移到最上面,然后则向外发送连接成功的信号 + if (activeAp) { + int pos = m_accessPoints.indexOf(activeAp); + m_accessPoints.move(pos, 0); + Q_EMIT connectionSuccess(activeAp); + } + + // 调用基类的方法触发连接发生变化,同时向外抛出连接变化的信号 + DeviceInterRealize::updateActiveInfo(m_activeAccessPoints); +} + +QList WirelessDeviceInterRealize::wirelessItems() const +{ + return m_connections; +} + +bool WirelessDeviceInterRealize::needShowAccessPoints() const +{ + // Mode=3表示开启热点 + if (mode() == AP_MODE) + return false; + // 如果当前设备热点为空(关闭热点),则让显示所有的网络列表 + return m_hotspotInfo.isEmpty(); +} + +void WirelessDeviceInterRealize::updateActiveConnectionInfo(const QList &infos) +{ + bool enabledHotspotOld = hotspotEnabled(); + + m_hotspotInfo = QJsonObject(); + for (const QJsonObject &info : infos) { + const QString devicePath = info.value("Device").toString(); + const QString connectionType = info.value("ConnectionType").toString(); + if (devicePath == this->path() && connectionType == "wireless-hotspot") { + m_hotspotInfo = info; + setDeviceStatus(DeviceStatus::Disconnected); + break; + } + } + + bool enabledHotspot = hotspotEnabled(); + if (enabledHotspotOld != enabledHotspot) + Q_EMIT hotspotEnableChanged(enabledHotspot); + + DeviceInterRealize::updateActiveConnectionInfo(infos); +} + +bool dde::network::WirelessDeviceInterRealize::hotspotEnabled() +{ + return !m_hotspotInfo.isEmpty(); +} + +void WirelessDeviceInterRealize::updateAccesspoint(const QJsonArray &json) +{ + auto isWifi6 = [](const QJsonObject &json) { + if (json.contains("Flags")) { + int flag = json.value("Flags").toInt(); + if (flag & AP_FLAGS_HE) + return true; + } + + return false; + }; + + // 先过滤相同的ssid,找出信号强度最大的那个 + QMap ssidMaxStrength; + QMap ssidPath; + QMap wifi6Ssids; + for (const QJsonValue &jsonValue : json) { + const QJsonObject obj = jsonValue.toObject(); + const QString ssid = obj.value("Ssid").toString(); + const int strength = obj.value("Strength").toInt(); + const QString path = obj.value("Path").toString(); + if (ssidMaxStrength.contains(ssid)) { + const int nOldStrength = ssidMaxStrength.value(ssid); + if (nOldStrength < strength) { + // 找到了对应的热点,更新热点的信号强度 + ssidMaxStrength[ssid] = strength; + ssidPath[ssid] = path; + } + } else { + // 第一次直接插入SSID和信号强度和路径 + ssidMaxStrength[ssid] = strength; + ssidPath[ssid] = path; + } + if (isWifi6(obj)) + wifi6Ssids[ssid] = obj.value("Flags").toInt(); + } + + QList newAp; + QList changedAp; + QStringList ssids; + for (const QJsonValue &jsonValue : json) { + QJsonObject accessInfo = jsonValue.toObject(); + const QString ssid = accessInfo.value("Ssid").toString(); + const QString maxSsidPath = ssidPath.value(ssid); + const QString path = accessInfo.value("Path").toString(); + if (path != maxSsidPath) + continue; + + // 如果当前的SSID存在WiFi6,就让其显示WiFi6的属性 + if (wifi6Ssids.contains(ssid)) + accessInfo["extendFlags"] = wifi6Ssids[ssid]; + + // 从网络列表中查找现有的网络 + AccessPoints *accessPoint = findAccessPoint(ssid); + if (!accessPoint) { + // 如果没有找到这个网络,就新建一个网络,添加到网络列表 + accessPoint = new AccessPoints(accessInfo, this); + accessPoint->m_devicePath = this->path(); + m_accessPoints << accessPoint; + newAp << accessPoint; + } else { + int strength = accessInfo.value("Strength").toInt(); + if (accessPoint->strength() != strength) + changedAp << accessPoint; + + accessPoint->updateAccessPoints(accessInfo); + } + + if (!ssids.contains(ssid)) + ssids << ssid; + } + + if (changedAp.size()) + Q_EMIT accessPointInfoChanged(changedAp); + + if (newAp.size() > 0) + Q_EMIT networkAdded(newAp); + + // 更新网络和连接的关系 + QList rmAccessPoints; + for (AccessPoints *ap : m_accessPoints) { + if (!ssids.contains(ap->ssid())) + rmAccessPoints << ap; + } + + if (rmAccessPoints.size() > 0) { + for (AccessPoints *ap : rmAccessPoints) + m_accessPoints.removeOne(ap); + + Q_EMIT networkRemoved(rmAccessPoints); + } + + for (AccessPoints *ap : rmAccessPoints) + ap->deleteLater(); + + createConnection(m_connectionJson); + syncConnectionAccessPoints(); +} + +void WirelessDeviceInterRealize::setDeviceEnabledStatus(const bool &enabled) +{ + if (!enabled) { + // 禁用网卡的情况下,直接清空原来的连接信息 + m_activeAccessPoints.clear(); + // 向外抛出删除wlan连接的信号,这里暂时不清空AccessPoints列表,防止再打开网卡的时候重复创建 + Q_EMIT networkRemoved(m_accessPoints); + } + + DeviceInterRealize::setDeviceEnabledStatus(enabled); +} + +void WirelessDeviceInterRealize::updateConnection(const QJsonArray &info) +{ + m_connectionJson = info; + + createConnection(info); + + syncConnectionAccessPoints(); +} + +void WirelessDeviceInterRealize::createConnection(const QJsonArray &info) +{ + QStringList connPaths; + for (const QJsonValue &jsonValue : info) { + const QJsonObject &jsonObj = jsonValue.toObject(); + const QString hwAddress = jsonObj.value("HwAddress").toString(); + if (!hwAddress.isEmpty() && hwAddress != realHwAdr()) + continue; + + // only update its own connection instead of all devices connection. + const QString ifcName = jsonObj.value("IfcName").toString(); + if (!ifcName.isEmpty() && ifcName != interface()) + continue; + + const QString path = jsonObj.value("Path").toString(); + WirelessConnection *connection = findConnectionByPath(path); + if (!connection) { + connection = new WirelessConnection; + m_connections << connection; + } + + connection->setConnection(jsonObj); + if (!connPaths.contains(path)) + connPaths << path; + } + + QList rmConns; + for (WirelessConnection *conn : m_connections) { + if (!connPaths.contains(conn->connection()->path())) + rmConns << conn; + } + + // 提交改变信号后,删除不在的连接 + for (WirelessConnection *conn : rmConns) { + m_connections.removeOne(conn); + delete conn; + } +} + +void WirelessDeviceInterRealize::updateActiveInfo(const QList &info) +{ + m_activeAccessPoints = info; + updateActiveInfo(); +} + +QString WirelessDeviceInterRealize::deviceKey() +{ + return "wireless"; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.h b/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.h new file mode 100644 index 000000000..08c8ea5ce --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/deviceinterrealize.h @@ -0,0 +1,165 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DEVICEINTERREALIZE_H +#define DEVICEINTERREALIZE_H + +#include "netinterface.h" +#include "networkconst.h" +#include "netutils.h" + +#include +#include + +namespace dde { + +namespace network { + +#define MaxQueueSize 4 +class NetworkDBusProxy; +class DeviceInterRealize : public NetworkDeviceRealize +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkDeviceBase; + +public: + inline bool isEnabled() const override { return m_enabled; } // 当前的网卡是否启用 + inline QString interface() const override { return m_data.value("Interface").toString(); } // 返回设备上的Interface + inline QString driver() const override { return m_data.value("Driver").toString(); } // 驱动,对应于备上返回值的Driver + inline bool managed() const override { return m_data.value("Managed").toBool(); } // 对应于设备上返回值的Managed + inline QString vendor() const override { return m_data.value("Vendor").toString(); } // 对应于设备上返回值的Vendor + inline QString uniqueUuid() const override { return m_data.value("UniqueUuid").toString(); } // 网络设备的唯一的UUID,对应于设备上返回值的UniqueUuid + inline bool usbDevice() const override { return m_data.value("UsbDevice").toBool(); } // 是否是USB设备,对应于设备上返回值的UsbDevice + inline QString path() const override { return m_data.value("Path").toString(); } // 设备路径,对应于设备上返回值的Path + inline QString activeAp() const override { return m_data.value("ActiveAp").toString(); } // 对应于设备上返回值的ActiveAp + inline bool supportHotspot() const override { return m_data.value("SupportHotspot").toBool(); } // 是否支持热点,对应于设备上返回值的SupportHotspot + inline QString realHwAdr() const override { return m_data.value("HwAddress").toString(); } // mac地址 + inline QString usingHwAdr() const override { return m_data.value("ClonedAddress").toString(); } // 正在使用的mac地址 + const QStringList ipv4() override; // IPV4地址 + const QStringList ipv6() override; // IPV6地址 + QJsonObject activeConnectionInfo() const override; // 获取当前活动连接的信息 + void setEnabled(bool enabled) override; // 开启或禁用网卡 + Connectivity connectivity(); + +protected Q_SLOTS: + void deviceConnectionFailed(); + void deviceConnectionSuccess(); + +protected: + explicit DeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + virtual ~DeviceInterRealize() override; + NetworkDBusProxy *networkInter(); + void updateDeviceInfo(const QJsonObject &info); + void initDeviceInfo(); + QStringList getValidIPV4(const QStringList &ipv4s); + bool isIpv4Address(const QString &ip) const; + virtual bool isConnected() const = 0; // 当前网络的网络是否处于连接状态 + virtual void updateConnection(const QJsonArray &info) = 0; + virtual QString deviceKey() = 0; // 返回设备对应的key值 + virtual void setDeviceEnabledStatus(const bool &enabled); + virtual void updateActiveInfo(const QList &) {} // 当前连接发生变化,例如从一个连接切换到另外一个连接 + virtual void updateActiveConnectionInfo(const QList &infos); // 当前连接发生变化后,获取设备的活动信息,例如IP等 + void setDeviceStatus(const DeviceStatus &status) override; + int mode() const; + +private: + NetworkDBusProxy *m_networkInter; + QJsonObject m_data; + QJsonObject m_activeInfoData; + bool m_enabled; + Connectivity m_connectivity; + QQueue m_statusQueue; + QString m_name; +}; + +class WiredDeviceInterRealize : public DeviceInterRealize +{ + Q_OBJECT + + friend class NetworkInterProcesser; + +private: + WiredDeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent); + ~WiredDeviceInterRealize() override; + +public: + bool connectNetwork(WiredConnection *connection) override; // 连接网络,连接成功抛出deviceStatusChanged信号 + void disconnectNetwork() override; // 断开网络连接 + QList wiredItems() const override; // 有线网络连接列表 + +private: + bool isConnected() const override; // 是否连接网络,重写基类的虚函数 + void updateConnection(const QJsonArray &info) override; + void updateActiveInfo(const QList &info) override; + QString deviceKey() override; + WiredConnection *findConnection(const QString &path); + WiredConnection *findWiredConnectionByUuid(const QString &uuid); + void setDeviceEnabledStatus(const bool &enabled) override; + +private: + QList m_connections; +}; + +class WirelessDeviceInterRealize : public DeviceInterRealize +{ + Q_OBJECT + + friend class NetworkInterProcesser; + +public: + QList accessPointItems() const override; // 当前网卡上所有的网络列表 + void scanNetwork() override; // 重新加载所有的无线网络列表 + void connectNetwork(const AccessPoints *item) override; // 连接网络,连接成功抛出deviceStatusChanged信号 + void disconnectNetwork() override; // 断开连接 + QList items() const; // 无线网络连接列表 + AccessPoints *activeAccessPoints() const override; // 当前活动的无线连接 + +protected: + WirelessDeviceInterRealize(IPConfilctChecker *ipChecker, NetworkDBusProxy *networkInter, QObject *parent); + ~WirelessDeviceInterRealize() override; + +private: + bool isConnected() const override; // 是否连接网络,重写基类的虚函数 + AccessPoints *findAccessPoint(const QString &ssid); + WirelessConnection *findConnectionByAccessPoint(const AccessPoints *accessPoint); + void syncConnectionAccessPoints(); + void updateActiveInfo(); + QList wirelessItems() const override; // 无线网络连接列表 + bool needShowAccessPoints() const; // 是否需要显示所有的无线网络,一般情况下,在开启热点后,不显示无线网络 + +protected: + void updateConnection(const QJsonArray &info) override; + void createConnection(const QJsonArray &info); + void updateActiveInfo(const QList &info) override; + QString deviceKey() override; + WirelessConnection *findConnectionByPath(const QString &path); + void updateAccesspoint(const QJsonArray &json); + void setDeviceEnabledStatus(const bool &enabled) override; + void updateActiveConnectionInfo(const QList &infos) override; + bool hotspotEnabled() override; + + template + void clearListData(QList &dataList) { + for (T *data : dataList) + delete data; + + dataList.clear(); + } + +private: + QList m_connections; + QList m_accessPoints; + QJsonObject m_activeHotspotInfo; + QList m_activeAccessPoints; + QJsonObject m_hotspotInfo; + QJsonArray m_connectionJson; +}; + +} + +} + +#endif // INTERDEVICE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.cpp new file mode 100644 index 000000000..10a57f162 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.cpp @@ -0,0 +1,762 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "devicemanagerrealize.h" +#include "netutils.h" +#include "networkdevicebase.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +using namespace dde::network; +using namespace NetworkManager; + +DeviceManagerRealize::DeviceManagerRealize(IPConfilctChecker *ipChecker, QSharedPointer device, QObject *parent) + : NetworkDeviceRealize(ipChecker, parent) + , m_wDevice(device) + , m_activeWiredConnection(Q_NULLPTR) + , m_activeWirelessConnection(Q_NULLPTR) +{ + // 初始化有线连接 + onWiredConnectionChanged(); + // 初始化无线连接 + onWirelessConnectionChanged(); + // 初始化信号槽的连接 + initSigSlotConnection(); + // 改变状态 + changeStatus(m_wDevice->state()); + // 获取是否开启热点 + m_hotspotEnabled = getHotspotIsEnabled(); +} + +void DeviceManagerRealize::initSigSlotConnection() +{ + connect(m_wDevice.get(), &NetworkManager::Device::availableConnectionChanged, this, &DeviceManagerRealize::onWiredConnectionChanged); + connect(m_wDevice.get(), &NetworkManager::Device::stateChanged, this, &DeviceManagerRealize::onStatusChanged); + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + if (!wirelessDevice.isNull()) { + connect(wirelessDevice.get(), &NetworkManager::WirelessDevice::accessPointAppeared, this, &DeviceManagerRealize::onWirelessConnectionChanged); + connect(wirelessDevice.get(), &NetworkManager::WirelessDevice::accessPointDisappeared, this, &DeviceManagerRealize::onWirelessConnectionChanged); + connect(wirelessDevice.get(), &NetworkManager::WirelessDevice::activeAccessPointChanged, this, &DeviceManagerRealize::onWirelessConnectionChanged); + connect(wirelessDevice.get(), &NetworkManager::WirelessDevice::modeChanged, this, [ this ] { + bool oldEnabled = m_hotspotEnabled; + m_hotspotEnabled = getHotspotIsEnabled(); + if (m_hotspotEnabled) + setDeviceStatus(DeviceStatus::Disconnected); + if (oldEnabled != m_hotspotEnabled) + Q_EMIT hotspotEnableChanged(m_hotspotEnabled); + }); + } + } + + QDBusConnection::systemBus().connect("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", "DeviceEnabled", this, SLOT(onDeviceEnabledChanged(QDBusObjectPath, bool))); +} + +DeviceManagerRealize::~DeviceManagerRealize() +{ +} + +bool DeviceManagerRealize::isEnabled() const +{ + QDBusInterface dbusInter("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", QDBusConnection::systemBus()); + QDBusPendingCall reply = dbusInter.asyncCall("IsDeviceEnabled", m_wDevice->uni()); + reply.waitForFinished(); + QDBusPendingReply replyResult = reply.reply(); + return replyResult.argumentAt(0).toBool(); +} + +QString DeviceManagerRealize::interface() const +{ + return m_wDevice->interfaceName(); +} + +QString DeviceManagerRealize::driver() const +{ + return m_wDevice->driver(); +} + +bool DeviceManagerRealize::managed() const +{ + return m_wDevice->managed(); +} + +QString DeviceManagerRealize::vendor() const +{ + return QString(); +} + +QString DeviceManagerRealize::uniqueUuid() const +{ + return m_wDevice->udi(); +} + +bool DeviceManagerRealize::usbDevice() const +{ + return false; +} + +QString DeviceManagerRealize::path() const +{ + return m_wDevice->uni(); +} + +QString DeviceManagerRealize::activeAp() const +{ + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + AccessPoint::Ptr ap = wirelessDevice->activeAccessPoint(); + if (ap) + return ap->ssid(); + } + + return QString(); +} + +bool DeviceManagerRealize::supportHotspot() const +{ + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + return (wirelessDevice->wirelessCapabilities().testFlag(NetworkManager::WirelessDevice::ApCap)); + } + + return false; +} + +QString DeviceManagerRealize::realHwAdr() const +{ + if (m_wDevice->type() == NetworkManager::Device::Ethernet) { + QSharedPointer device = m_wDevice.staticCast(); + return device->hardwareAddress(); + } + + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + QSharedPointer device = m_wDevice.staticCast(); + return device->hardwareAddress(); + } + + return QString(); +} + +QString DeviceManagerRealize::usingHwAdr() const +{ + return QString(); +} + +const QStringList DeviceManagerRealize::ipv4() +{ + if (!device() || !device()->isConnected() || !isEnabled()) + return QStringList(); + + NetworkManager::IpAddresses ipv4AddrList = m_wDevice->ipV4Config().addresses(); + QStringList ipv4s; + for (const IpAddress &ipAddr : ipv4AddrList) + ipv4s << ipAddr.ip().toString(); + + return ipv4s; +} + +const QStringList DeviceManagerRealize::ipv6() +{ + if (!device() || !device()->isConnected() || !isEnabled()) + return QStringList(); + + NetworkManager::IpAddresses ipv6AddrList = m_wDevice->ipV6Config().addresses(); + QStringList ipv6s; + for (const IpAddress &ipAddr : ipv6AddrList) + ipv6s << ipAddr.ip().toString(); + + return ipv6s; +} + +QJsonObject DeviceManagerRealize::activeConnectionInfo() const +{ + return QJsonObject(); +} + +void DeviceManagerRealize::setEnabled(bool enabled) +{ + bool currentEnabled = isEnabled(); + if (currentEnabled != enabled) { + qInfo() << "set Device " << m_wDevice->uni() << " enabled:" << (enabled ? "true" : "false"); + QDBusInterface dbusInter("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", QDBusConnection::systemBus()); + QDBusReply reply = dbusInter.call("EnableDevice", m_wDevice->uni(), enabled); + if (enabled) { + // 如果是开启,则让其自动连接 + QString activeConnectionPath = reply.value().path(); + if (activeConnectionPath != "/") { + NetworkManager::activateConnection(activeConnectionPath, m_wDevice->uni(), QString()); + qInfo() << "connected:" << activeConnectionPath; + } + } + } +} + +void DeviceManagerRealize::disconnectNetwork() +{ + NetworkManager::ActiveConnection::Ptr activeConnection = m_wDevice->activeConnection(); + if (!activeConnection.isNull()) + NetworkManager::deactivateConnection(activeConnection->path()); +} + +QList DeviceManagerRealize::accessPointItems() const +{ + if (m_wDevice->type() == NetworkManager::Device::Wifi) + return m_accessPoints; + + return QList(); +} + +void DeviceManagerRealize::scanNetwork() +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return; + + NetworkManager::WirelessDevice::Ptr device = m_wDevice.staticCast(); + device->requestScan(); +} + +void DeviceManagerRealize::connectNetwork(const AccessPoints *item) +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return; + + WirelessConnection *conn = findConnectionByAccessPoint(item, m_wirelessConnections); + if (conn) + NetworkManager::activateConnection(conn->connection()->path(), m_wDevice->uni(), ""); +} + +QList DeviceManagerRealize::wirelessItems() const +{ + return m_wirelessConnections; +} + +AccessPoints *DeviceManagerRealize::activeAccessPoints() const +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return nullptr; + + QSharedPointer device = m_wDevice.staticCast(); + AccessPoint::Ptr currentActiveAp = device->activeAccessPoint(); + if (!currentActiveAp.isNull()) { + for (AccessPoints *ap : m_accessPoints) { + if (ap->ssid() == currentActiveAp->ssid()) + return ap; + } + } + + return nullptr; +} + +bool DeviceManagerRealize::connectNetwork(WiredConnection *connection) +{ + if (m_wDevice->type() != NetworkManager::Device::Ethernet) + return false; + + NetworkManager::activateConnection(connection->connection()->path(), m_wDevice->uni(), ""); + return true; +} + +QList DeviceManagerRealize::wiredItems() const +{ + return m_wiredConnections; +} + +void DeviceManagerRealize::onWiredConnectionChanged() +{ + if (m_wDevice->type() != NetworkManager::Device::Ethernet) + return; + + NetworkManager::Connection::List connections = m_wDevice->availableConnections(); + QList newConnection; + QList allConnection; + for (QSharedPointer conn : connections) { + if (conn->settings()->connectionType() != ConnectionSettings::ConnectionType::Wired) + continue; + + QJsonObject json = createConnectionJson(conn); + WiredConnection *wiredConn = findWiredConnection(conn->path()); + if (!wiredConn) { + wiredConn = new WiredConnection(); + newConnection << wiredConn; + } + wiredConn->setConnection(json); + allConnection << wiredConn; + } + QList rmConnection; + for (WiredConnection *conn : m_wiredConnections) { + if (!allConnection.contains(conn)) { + m_wiredConnections.removeOne(conn); + rmConnection << conn; + } + } + sortWiredItem(allConnection); + + m_wiredConnections = allConnection; + if (newConnection.size() > 0 || rmConnection.size() > 0) { + if (newConnection.size() > 0) + Q_EMIT connectionAdded(newConnection); + + if (rmConnection.size() > 0) + Q_EMIT connectionRemoved(rmConnection); + + for (WiredConnection *conn : rmConnection) { + if (conn == m_activeWiredConnection) + m_activeWiredConnection = Q_NULLPTR; + + delete conn; + } + } +} + +void DeviceManagerRealize::changeWiredStatus(Device::State newstate) +{ + if (m_wDevice->type() != NetworkManager::Device::Ethernet) + return; + + // 查看当前活动连接是否存在与连接列表中,如果不存在,就将当前活动连接置空 + if (m_activeWiredConnection && !m_wiredConnections.contains(m_activeWiredConnection)) + m_activeWiredConnection = Q_NULLPTR; + + ConnectionStatus oldStatus = ConnectionStatus::Unknown; + if (m_activeWiredConnection) + oldStatus = m_activeWiredConnection->status(); + + NetworkManager::ActiveConnection::Ptr activeConn = m_wDevice->activeConnection(); + if (activeConn.isNull()) { + // 断开了连接以后,如果以前存在连接,则向外抛出断开的信号 + if (m_activeWiredConnection) { + m_activeWiredConnection->setConnectionStatus(ConnectionStatus::Deactivated); + m_activeWiredConnection = nullptr; + Q_EMIT activeConnectionChanged(); + } + return; + } + + WiredConnection *currentConnection = findWiredConnectionByUuid(activeConn->uuid()); + if (!currentConnection) { + return; + } + + ConnectionStatus newStatus = convertStatus(newstate); + if (m_activeWiredConnection && currentConnection != m_activeWiredConnection) { + m_activeWiredConnection->setConnectionStatus(ConnectionStatus::Deactivated); + oldStatus = ConnectionStatus::Unknown; + } + if(oldStatus != newStatus){ + m_activeWiredConnection = currentConnection; + currentConnection->setConnectionStatus(newStatus); + Q_EMIT activeConnectionChanged(); + } +} + +void DeviceManagerRealize::changeWirelessStatus(Device::State newstate) +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return; + + if (m_activeWirelessConnection && !m_wirelessConnections.contains(m_activeWirelessConnection)) + m_activeWirelessConnection = Q_NULLPTR; + + ConnectionStatus oldStatus = ConnectionStatus::Unknown; + if (m_activeWirelessConnection) { + AccessPoints *activePoint = findAccessPoints(m_activeWirelessConnection->connection()->ssid()); + if (activePoint) + oldStatus = activePoint->status(); + } + + NetworkManager::ActiveConnection::Ptr activeConn = m_wDevice->activeConnection(); + if (activeConn.isNull()) { + if (m_activeWirelessConnection) { + AccessPoints *ap = findAccessPoints(m_activeWirelessConnection->connection()->ssid()); + if (ap) + ap->updateConnectionStatus(ConnectionStatus::Deactivated); + + m_activeWirelessConnection = nullptr; + Q_EMIT activeConnectionChanged(); + } + return; + } + + WirelessConnection *currentConnection = findWirelessConnectionBySsid(activeConn->id()); + if (!currentConnection) { + Q_EMIT activeConnectionChanged(); + return; + } + + if (m_activeWirelessConnection && m_activeWirelessConnection != currentConnection) { + AccessPoints *ap = findAccessPoints(m_activeWirelessConnection->connection()->ssid()); + if (ap) + ap->updateConnectionStatus(ConnectionStatus::Deactivated); + oldStatus = ConnectionStatus::Unknown; + } + + ConnectionStatus newStatus = convertStatus(newstate); + if (newStatus != oldStatus) { + m_activeWirelessConnection = currentConnection; + AccessPoints *ap = findAccessPoints(currentConnection->connection()->ssid()); + if (ap) { + ap->updateConnectionStatus(newStatus); + Q_EMIT activeConnectionChanged(); + } + } +} + +WirelessConnection *DeviceManagerRealize::findWirelessConnectionByUuid(const QString &uuid) +{ + for (WirelessConnection *conn : m_wirelessConnections) { + if (conn->connection()->uuid() == uuid) + return conn; + } + + return Q_NULLPTR; +} + +void DeviceManagerRealize::changeStatus(Device::State newstate) +{ + // 转换当前获取的状态为设备的状态 + setDeviceStatus(convertDeviceStatus(newstate)); + switch (m_wDevice->type()) { + case NetworkManager::Device::Ethernet: + changeWiredStatus(newstate); + break; + case NetworkManager::Device::Wifi: + changeWirelessStatus(newstate); + break; + default: break; + } +} + +bool DeviceManagerRealize::getHotspotIsEnabled() +{ + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + NetworkManager::WirelessDevice::OperationMode mode = wirelessDevice->mode(); + return (mode == NetworkManager::WirelessDevice::OperationMode::ApMode); +} + +bool DeviceManagerRealize::hotspotEnabled() +{ + return m_hotspotEnabled; +} + +void DeviceManagerRealize::onStatusChanged(Device::State newstate, Device::State oldstate, Device::StateChangeReason reason) +{ + Q_UNUSED(oldstate); + Q_UNUSED(reason); + + changeStatus(newstate); +} + +void DeviceManagerRealize::onDeviceEnabledChanged(QDBusObjectPath path, bool enabled) +{ + if (m_wDevice && m_wDevice->uni() == path.path()) { + Q_EMIT enableChanged(enabled); + } +} + +WiredConnection *DeviceManagerRealize::findWiredConnectionByUuid(const QString &uuid) +{ + for (WiredConnection *conn : m_wiredConnections) { + if (conn->connection()->uuid() == uuid) + return conn; + } + + return Q_NULLPTR; +} + +void DeviceManagerRealize::onWirelessConnectionChanged() +{ + if (m_wDevice->type() != NetworkManager::Device::Wifi) + return; + + NetworkManager::Connection::List connections = m_wDevice->availableConnections(); + QList newConnection; + QList allConnection; + for (QSharedPointer conn : connections) { + if (conn->settings()->connectionType() != ConnectionSettings::ConnectionType::Wireless) + continue; + + const QJsonObject json = createConnectionJson(conn); + WirelessConnection *wirelessConn = findWirelessConnection(conn->path()); + if (!wirelessConn) { + wirelessConn = new WirelessConnection(); + newConnection << wirelessConn; + } + + wirelessConn->setConnection(json); + allConnection << wirelessConn; + } + + createWlans(allConnection); +} + +void DeviceManagerRealize::createWlans(QList &allConnections) +{ + QList newAps, allAccessPoints; + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + NetworkManager::WirelessNetwork::List networks = wirelessDevice->networks(); + for (QSharedPointer network : networks) { + QSharedPointer ap = network->referenceAccessPoint(); + const QJsonObject json = createWlanJson(ap); + AccessPoints *accessPoint = findAccessPoints(ap->ssid()); + if (!accessPoint) { + accessPoint = new AccessPoints(json); + accessPoint->m_devicePath = path(); + newAps << accessPoint; + } else { + accessPoint->updateAccessPoints(json); + } + + allAccessPoints << accessPoint; + } + QList rmAps; + for (AccessPoints *ap : m_accessPoints) { + if (!allAccessPoints.contains(ap)) { + m_accessPoints.removeOne(ap); + rmAps << ap; + } + } + // 在信号发送之前同步accessPoints数据,因为在抛出信号后,外面可能通过获取内部所有的WLAN数据来更新内容,此时需要保证WLAN列表是最新的 + m_accessPoints = allAccessPoints; + // 确保激活的在列表中 + AccessPoint::Ptr activeAp = wirelessDevice->activeAccessPoint(); + if (!activeAp.isNull()) { + const QJsonObject json = createWlanJson(activeAp); + AccessPoints *accessPoint = findAccessPoints(activeAp->ssid()); + if (!accessPoint) { + accessPoint = new AccessPoints(json); + newAps << accessPoint; + allAccessPoints << accessPoint; + m_accessPoints << accessPoint; + } else { + accessPoint->updateAccessPoints(json); + } + } + syncWlanAndConnections(allConnections); + + // 删除不存在的Connections,也放在信号发送之前,原因和accessPoints一样 + QList rmConnections; + for (WirelessConnection *conn : m_wirelessConnections) { + if (!allConnections.contains(conn) && !rmConnections.contains(conn)) + rmConnections << conn; + } + + if (rmConnections.contains(m_activeWirelessConnection)) + m_activeWirelessConnection = Q_NULLPTR; + + m_wirelessConnections = allConnections; + + if (rmAps.size() > 0 || newAps.size() > 0) { + if (newAps.size() > 0) { + Q_EMIT networkAdded(newAps); + // 新增无线网络之前最好先刷新网络列表状态,因为考虑到连接隐藏网络的时候,没有触发网络状态变化信号,因此此处需要手动调用 + changeStatus(m_wDevice->state()); + } + + if (rmAps.size() > 0) + Q_EMIT networkRemoved(rmAps); + + for (AccessPoints *ap : rmAps) + delete ap; + } + + // 删除无用的数据 + for (WirelessConnection *rmConn : rmConnections) + delete rmConn; +} + +void DeviceManagerRealize::syncWlanAndConnections(QList &allConnections) +{ + if (m_accessPoints.isEmpty()) { + clearListData(allConnections); + return; + } + + QList connections; + // 找到每个热点对应的Connection,并将其赋值 + for (AccessPoints *accessPoint : m_accessPoints) { + WirelessConnection *connection = findConnectionByAccessPoint(accessPoint, allConnections); + if (!connection) { + connection = WirelessConnection::createConnection(accessPoint); + m_wirelessConnections << connection; + } + + connection->m_accessPoints = accessPoint; + connections << connection; + } + // 删除列表中没有AccessPoints的Connection,让两边保持数据一致 + QList rmConns; + for (WirelessConnection *connection : allConnections) { + if (!connections.contains(connection)) + rmConns << connection; + } + + for (WirelessConnection *rmConnection : rmConns) { + allConnections.removeOne(rmConnection); + + // 如果当前所有的无线连接列表中有不存在的连接,那么需要将其从无线连接中移除,然后再delete + // 因为后面会将m_wirelessConnections中不存在于allConnections的连接delete,如果 + // 此处不从m_wirelessConnections移除掉这个connection,那么后面就会出现删除两次引起报错 + if (m_wirelessConnections.contains(rmConnection)) + m_wirelessConnections.removeOne(rmConnection); + + delete rmConnection; + } + + allConnections = connections; +} + +AccessPoints *DeviceManagerRealize::findAccessPoints(const QString &ssid) +{ + for (AccessPoints *ap : m_accessPoints) { + if (ap->ssid() == ssid) + return ap; + } + + return Q_NULLPTR; +} + +QJsonObject DeviceManagerRealize::createWlanJson(QSharedPointer ap) +{ + QJsonObject jsonObject; + jsonObject.insert("Ssid", ap->ssid()); + jsonObject.insert("Strength", ap->signalStrength()); + bool secured = ap->capabilities() == AccessPoint::Capability::Privacy || ap->wpaFlags() != 0 || ap->rsnFlags() != 0; + jsonObject.insert("Secured", secured); + jsonObject.insert("SecuredInEap", secured); + jsonObject.insert("Flags", static_cast(ap->capabilities())); + int frequency = static_cast(ap->frequency()); + jsonObject.insert("Frequency", frequency); + jsonObject.insert("Path", ap->uni()); + return jsonObject; +} + +QJsonObject DeviceManagerRealize::createConnectionJson(QSharedPointer networkConnection) +{ + QJsonObject json; + json.insert("Path", networkConnection->path()); + json.insert("Uuid", networkConnection->uuid()); + json.insert("Id", networkConnection->settings()->id()); + json.insert("HwAddress", realHwAdr()); + json.insert("ClonedAddress", realHwAdr()); + json.insert("Ssid", networkConnection->name()); + return json; +} + +WirelessConnection *DeviceManagerRealize::findConnectionByAccessPoint(const AccessPoints *accessPoint, QList &allConnections) +{ + for (WirelessConnection *connection : allConnections) { + if (connection->accessPoints() == accessPoint) + return connection; + + if (connection->connection()->ssid() == accessPoint->ssid()) + return connection; + } + + return Q_NULLPTR; +} + +WiredConnection *DeviceManagerRealize::findWiredConnection(const QString &path) +{ + for (WiredConnection *connection : m_wiredConnections) { + if (connection->connection()->path() == path) + return connection; + } + + return Q_NULLPTR; +} + +WirelessConnection *DeviceManagerRealize::findWirelessConnectionBySsid(const QString &ssid) +{ + for (WirelessConnection *connection : m_wirelessConnections) { + if (connection->connection()->ssid() == ssid) + return connection; + } + + return Q_NULLPTR; +} + +WirelessConnection *DeviceManagerRealize::findWirelessConnection(const QString &path) +{ + for (WirelessConnection *connection : m_wirelessConnections) { + if (connection->connection()->path() == path) + return connection; + } + + return Q_NULLPTR; +} + +ConnectionStatus DeviceManagerRealize::convertStatus(Device::State state) +{ + switch (state) { + case Device::State::Failed: + case Device::State::Unmanaged: + case Device::State::Unavailable: + case Device::State::Disconnected: + return ConnectionStatus::Deactivated; + case Device::State::Preparing: + case Device::State::NeedAuth: + case Device::State::CheckingIp: + case Device::State::ConfiguringIp: + case Device::State::ConfiguringHardware: + case Device::State::WaitingForSecondaries: + return ConnectionStatus::Activating; + case Device::State::Activated: + return ConnectionStatus::Activated; + case Device::State::Deactivating: + return ConnectionStatus::Deactivating; + default: break; + } + + return ConnectionStatus::Unknown; +} + +DeviceStatus DeviceManagerRealize::convertDeviceStatus(Device::State state) +{ + if (m_wDevice->type() == NetworkManager::Device::Wifi) { + // 如果当前网卡开启了热点,则认为它是连接断开的状态 + NetworkManager::WirelessDevice::Ptr wirelessDevice = m_wDevice.staticCast(); + if (wirelessDevice->mode() == NetworkManager::WirelessDevice::OperationMode::ApMode) + return DeviceStatus::Disconnected; + } + switch (state) { + case Device::State::Failed: + return DeviceStatus::Failed; + case Device::State::NeedAuth: + return DeviceStatus::Needauth; + case Device::State::Activated: + return DeviceStatus::Activated; + case Device::State::Preparing: + return DeviceStatus::Prepare; + case Device::State::Unmanaged: + return DeviceStatus::Unmanaged; + case Device::State::CheckingIp: + return DeviceStatus::IpCheck; + case Device::State::Unavailable: + return DeviceStatus::Unavailable; + case Device::State::Deactivating: + return DeviceStatus::Deactivation; + case Device::State::Disconnected: + return DeviceStatus::Disconnected; + case Device::State::ConfiguringIp: + case Device::State::ConfiguringHardware: + return DeviceStatus::Config; + case Device::State::WaitingForSecondaries: + return DeviceStatus::Secondaries; + default: break; + } + + return DeviceStatus::Unknown; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.h b/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.h new file mode 100644 index 000000000..98e5de6cb --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/devicemanagerrealize.h @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DEVICEMANAGERREALIZE_H +#define DEVICEMANAGERREALIZE_H + +#include "netinterface.h" + +#include + +namespace NetworkManager { +class WirelessNetwork; +class AccessPoint; +} + +using namespace NetworkManager; + +namespace dde { +namespace network { + +class DeviceManagerRealize : public NetworkDeviceRealize +{ + Q_OBJECT + +public: + explicit DeviceManagerRealize(IPConfilctChecker *ipChecker, QSharedPointer device, QObject *parent = nullptr); + ~DeviceManagerRealize() override; + +protected: + bool isEnabled() const override; // 当前的网卡是否启用 + QString interface() const override; // 返回设备上的Interface + QString driver() const override; // 驱动,对应于备上返回值的Driver + bool managed() const override; // 对应于设备上返回值的Managed + QString vendor() const override; // 对应于设备上返回值的Vendor + QString uniqueUuid() const override; // 网络设备的唯一的UUID,对应于设备上返回值的UniqueUuid + bool usbDevice() const override; // 是否是USB设备,对应于设备上返回值的UsbDevice + QString path() const override; // 设备路径,对应于设备上返回值的Path + QString activeAp() const override; // 对应于设备上返回值的ActiveAp + bool supportHotspot() const override; // 是否支持热点,对应于设备上返回值的SupportHotspot + QString realHwAdr() const override; // mac地址 + QString usingHwAdr() const override; // 正在使用的mac地址 + const QStringList ipv4() override; // IPV4地址 + const QStringList ipv6() override; // IPV6地址 + QJsonObject activeConnectionInfo() const override; // 获取当前活动连接的信息 + void setEnabled(bool enabled) override; // 开启或禁用网卡 + void disconnectNetwork() override; // 断开网络连接,该方法是一个虚方法,具体在子类 + + // 无线网络接口 + QList accessPointItems() const override; // 当前网卡上所有的网络列表 + void scanNetwork() override; // 重新加载所有的无线网络列表 + void connectNetwork(const AccessPoints *item) override; // 连接网络,连接成功抛出deviceStatusChanged信号 + QList wirelessItems() const override; // 无线网络连接列表 + AccessPoints *activeAccessPoints() const override; // 当前活动的无线连接 + + // 有线网络接口 + bool connectNetwork(WiredConnection *connection) override; // 连接网络,连接成功抛出deviceStatusChanged信号 + QList wiredItems() const override; // 有线网络连接列表 + +private: + template + void clearListData(QList &dataList) { + for (T *data : dataList) + delete data; + + dataList.clear(); + } + +private: + void initSigSlotConnection(); + void createWlans(QList &allConnections); + void syncWlanAndConnections(QList &allConnections); + + AccessPoints *findAccessPoints(const QString &ssid); + QJsonObject createWlanJson(QSharedPointer ap); + QJsonObject createConnectionJson(QSharedPointer networkConnection); + WirelessConnection *findConnectionByAccessPoint(const AccessPoints *accessPoint, QList &allConnections); + + WiredConnection *findWiredConnection(const QString &path); + WiredConnection *findWiredConnectionByUuid(const QString &uuid); + WirelessConnection *findWirelessConnectionBySsid(const QString &ssid); + WirelessConnection *findWirelessConnection(const QString &path); + WirelessConnection *findWirelessConnectionByUuid(const QString &uuid); + ConnectionStatus convertStatus(Device::State state); + DeviceStatus convertDeviceStatus(Device::State state); + + void changeWiredStatus(Device::State newstate); + void changeWirelessStatus(Device::State newstate); + void changeStatus(Device::State newstate); + + bool getHotspotIsEnabled(); + bool hotspotEnabled() override; + +private slots: + void onWiredConnectionChanged(); + void onWirelessConnectionChanged(); + void onStatusChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason); + void onDeviceEnabledChanged(QDBusObjectPath path, bool enabled); + +private: + QSharedPointer m_wDevice; + QList m_accessPoints; + QList m_wiredConnections; + QList m_wirelessConnections; + WiredConnection *m_activeWiredConnection; + WirelessConnection *m_activeWirelessConnection; + bool m_hotspotEnabled; + QQueue m_statusQueue; +}; + +} +} +#endif // DEVICEMANAGERREALIZE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.cpp new file mode 100644 index 000000000..7376642d0 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.cpp @@ -0,0 +1,386 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "netinterface.h" +#include "networkdevicebase.h" + +#include +#include + +namespace dde { +namespace network { + +NetworkProcesser::NetworkProcesser(QObject *parent) + : QObject (parent) +{ +} + +NetworkProcesser::~NetworkProcesser() +{ +} + +QList NetworkProcesser::networkDetails() +{ + return QList(); +} + +ProxyController *NetworkProcesser::proxyController() +{ + return Q_NULLPTR; +} + +VPNController *NetworkProcesser::vpnController() +{ + return Q_NULLPTR; +} + +DSLController *NetworkProcesser::dslController() +{ + return Q_NULLPTR; +} + +HotspotController *NetworkProcesser::hotspotController() +{ + return Q_NULLPTR; +} + +void NetworkProcesser::updateDeviceName() +{ + QList wiredDevice; + QList wirelessDevice; + + QList allDevices = this->devices(); + for (NetworkDeviceBase *device : allDevices) { + if (device->deviceType() == DeviceType::Wired) + wiredDevice << device; + else if (device->deviceType() == DeviceType::Wireless) + wirelessDevice << device; + } + + // 更改有线设备的名称 + if (wiredDevice.size() == 1) { + wiredDevice[0]->setName(tr("Wired Network")); + } else if (wiredDevice.size() > 1) { + for (int i = 0; i < wiredDevice.size(); i++) { + QString name = QString(tr("Wired Network %1")).arg(i + 1); + wiredDevice[i]->setName(name); + } + } + + // 更改无线设备的名称 + if (wirelessDevice.size() == 1) { + wirelessDevice[0]->setName(tr("Wireless Network")); + } else if (wirelessDevice.size() > 1) { + for (int i = 0; i < wirelessDevice.size(); i++) { + QString name = QString(tr("Wireless Network %1")).arg(i + 1); + wirelessDevice[i]->setName(name); + } + } +} + +void NetworkProcesser::retranslate() +{ + updateDeviceName(); +} + +/** + * @brief 设备接口基类,具体实现在子类中实现 + * @return + */ +void NetworkDeviceRealize::setDevice(NetworkDeviceBase *device) +{ + m_device = device; +} + +bool NetworkDeviceRealize::isEnabled() const +{ + return false; +} + +bool NetworkDeviceRealize::IPValid() +{ + // 判读获取IP地址失败需要满足最后一个状态为未连接,上一个状态为失败,并且包含Config和IpConfig + return !(m_statusQueue.size() == MaxQueueSize + && m_statusQueue[MaxQueueSize - 1] == DeviceStatus::Disconnected + && m_statusQueue[MaxQueueSize - 2] == DeviceStatus::Failed + && m_statusQueue.contains(DeviceStatus::Config) + && m_statusQueue.contains(DeviceStatus::IpConfig)); +} + +QString NetworkDeviceRealize::interface() const +{ + return QString(); +} + +QString NetworkDeviceRealize::driver() const +{ + return QString(); +} + +bool NetworkDeviceRealize::managed() const +{ + return false; +} + +QString NetworkDeviceRealize::vendor() const +{ + return QString(); +} + +QString NetworkDeviceRealize::uniqueUuid() const +{ + return QString(); +} + +bool NetworkDeviceRealize::usbDevice() const +{ + return false; +} + +QString NetworkDeviceRealize::path() const +{ + return QString(); +} + +QString NetworkDeviceRealize::activeAp() const +{ + return QString(); +} + +bool NetworkDeviceRealize::supportHotspot() const +{ + return false; +} + +QString NetworkDeviceRealize::realHwAdr() const +{ + return QString(); +} + +QString NetworkDeviceRealize::usingHwAdr() const +{ + return QString(); +} + +const QStringList NetworkDeviceRealize::ipv4() +{ + return QStringList(); +} + +const QStringList NetworkDeviceRealize::ipv6() +{ + return QStringList(); +} + +QJsonObject NetworkDeviceRealize::activeConnectionInfo() const +{ + return QJsonObject(); +} + +void NetworkDeviceRealize::setEnabled(bool enabled) +{ + Q_UNUSED(enabled); +} + +void NetworkDeviceRealize::disconnectNetwork() +{ +} + +Connectivity NetworkDeviceRealize::connectivity() +{ + return m_connectivity; +} + +DeviceStatus NetworkDeviceRealize::deviceStatus() const +{ + if (m_ipConflicted) + return DeviceStatus::IpConfilct; + + return m_deviceStatus; +} + +QList NetworkDeviceRealize::accessPointItems() const +{ + return QList(); +} + +void NetworkDeviceRealize::connectNetwork(const AccessPoints *item) +{ + Q_UNUSED(item); +} + +QList NetworkDeviceRealize::wirelessItems() const +{ + return QList(); +} + +AccessPoints *NetworkDeviceRealize::activeAccessPoints() const +{ + return nullptr; +} + +bool NetworkDeviceRealize::connectNetwork(WiredConnection *connection) +{ + Q_UNUSED(connection); + return false; +} + +QList NetworkDeviceRealize::wiredItems() const +{ + return QList(); +} + +NetworkDeviceRealize::NetworkDeviceRealize(IPConfilctChecker *ipConflictChecker, QObject *parent) + : QObject (parent) + , m_device(nullptr) + , m_connectivity(Connectivity::Full) + , m_deviceStatus(DeviceStatus::Unknown) + , m_ipConflictChecker(ipConflictChecker) + , m_ipConflicted(false) +{ + Q_ASSERT(m_ipConflictChecker); + connect(m_ipConflictChecker, &IPConfilctChecker::conflictStatusChanged, this, &NetworkDeviceRealize::onConflictStatusChanged); +} + +NetworkDeviceRealize::~NetworkDeviceRealize() +{ +} + +NetworkDeviceBase *NetworkDeviceRealize::device() const +{ + return m_device; +} + +QString NetworkDeviceRealize::statusStringDetail() +{ + if (!isEnabled() || !m_device) + return tr("Device disabled"); + + if (m_deviceStatus == DeviceStatus::Activated && m_connectivity != Connectivity::Full) + return tr("Connected but no Internet access"); + + // 确认 没有获取IP显示未连接状态(DHCP服务关闭) + if (!IPValid()) + return tr("Not connected"); + + switch (m_deviceStatus) { + case DeviceStatus::Unknown: + case DeviceStatus::Unmanaged: + case DeviceStatus::Unavailable: { + switch (m_device->deviceType()) { + case DeviceType::Unknown: return QString(); + case DeviceType::Wired: return tr("Network cable unplugged"); + default: break; + } + break; + } + case DeviceStatus::Disconnected: return tr("Not connected"); + case DeviceStatus::Prepare: + case DeviceStatus::Config: return tr("Connecting"); + case DeviceStatus::Needauth: return tr("Authenticating"); + case DeviceStatus::IpConfig: + case DeviceStatus::IpCheck: + case DeviceStatus::Secondaries: return tr("Obtaining IP address"); + case DeviceStatus::Activated: return tr("Connected"); + case DeviceStatus::Deactivation: return tr("Disconnected"); + case DeviceStatus::IpConfilct: return tr("IP conflict"); + default: break; + } + + return tr("Failed"); +} + +QString NetworkDeviceRealize::getStatusName() +{ + if (hotspotEnabled()) + return tr("Disconnected"); + + switch (m_deviceStatus) { + case DeviceStatus::Unmanaged: + case DeviceStatus::Unavailable: + case DeviceStatus::Disconnected: return tr("Disconnected"); + case DeviceStatus::Prepare: + case DeviceStatus::Config: return tr("Connecting"); + case DeviceStatus::Needauth: return tr("Authenticating"); + case DeviceStatus::IpConfig: + case DeviceStatus::IpCheck: return tr("Obtaining address"); + case DeviceStatus::Activated: return tr("Connected"); + case DeviceStatus::Deactivation: return tr("Disconnected"); + case DeviceStatus::Failed: return tr("Failed"); + case DeviceStatus::IpConfilct: return tr("IP conflict"); + default:; + } + + return QString(); +} + +void NetworkDeviceRealize::enqueueStatus(const DeviceStatus &status) +{ + if (m_statusQueue.size() >= MaxQueueSize) + m_statusQueue.dequeue(); + + m_statusQueue.enqueue(status); +} + +void NetworkDeviceRealize::setDeviceStatus(const DeviceStatus &status) +{ + if (m_deviceStatus == status) + return; + + m_deviceStatus = status; + enqueueStatus(status); + // 状态发生变化后,需要向外抛出一个信号 + Q_EMIT deviceStatusChanged(status); +} + +void NetworkDeviceRealize::sortWiredItem(QList &items) +{ + // 按照最后面的数字从小到大排序,如果名字中没有数字,就按照创建的先后顺序来排序(path数字的大小) + std::sort(items.begin(), items.end(), [ ] (WiredConnection *conn1, WiredConnection *conn2) { + QString lastChar1 = conn1->connection()->id().right(1); + QString lastChar2 = conn2->connection()->id().right(1); + int rightCount = 3; + int index1 = 0; + int index2 = 0; + bool ok1 = false, ok2 = false; + do { + if (!ok1) { + lastChar1 = conn1->connection()->id().right(rightCount); + index1 = lastChar1.toInt(&ok1); + } + if (!ok2) { + lastChar2 = conn2->connection()->id().right(rightCount); + index2 = lastChar2.toInt(&ok2); + } + if ((ok1 && ok2) || rightCount <= 0) + break; + + rightCount--; + } while (true); + + if (ok1 && ok2) + return index1 < index2; + QString path1 = conn1->connection()->path(); + QString path2 = conn2->connection()->path(); + path1 = path1.replace("\\", "/"); + path2 = path2.replace("\\", "/"); + QString configName1 = path1.mid(path1.lastIndexOf("/") + 1); + QString configName2 = path2.mid(path2.lastIndexOf("/") + 1); + return configName1.toInt() < configName2.toInt(); + }); +} + +void NetworkDeviceRealize::onConflictStatusChanged(NetworkDeviceBase *device, const bool confilcted) +{ + if (device != m_device) + return; + + if (m_ipConflicted != confilcted) { + m_ipConflicted = confilcted; + Q_EMIT deviceStatusChanged(deviceStatus()); + } +} + +} +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.h b/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.h new file mode 100644 index 000000000..7de0c1a94 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/netinterface.h @@ -0,0 +1,150 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETINTERFACE_H +#define NETINTERFACE_H + +#include "networkconst.h" + +#include +#include + +namespace dde { +namespace network { + +class NetworkDeviceBase; +class ProxyController; +class VPNController; +class DSLController; +class HotspotController; +class NetworkDetails; +class DSLItem; +class VPNItem; +class HotspotItem; +class WirelessDevice; +class AccessPoints; +class WiredDevice; +class WiredConnection; +class WirelessConnection; +class IPConfilctChecker; + +class NetworkProcesser : public QObject +{ + Q_OBJECT + +public: + virtual QList devices() = 0; + virtual Connectivity connectivity() = 0; + virtual QList networkDetails(); + virtual ProxyController *proxyController(); // 返回代理控制管理器 + virtual VPNController *vpnController(); // 返回VPN控制器 + virtual DSLController *dslController(); // DSL控制器 + virtual HotspotController *hotspotController(); // 个人热点控制器 + virtual void retranslate(); // 更新翻译 + +protected: + explicit NetworkProcesser(QObject *parent); + virtual ~NetworkProcesser(); + +Q_SIGNALS: + void deviceAdded(QList); // 新增设备发出的信号 + void deviceRemoved(QList); // 移除设备发出的信号 + void connectivityChanged(const Connectivity &) const; // 网络连接状态发生变化的时候发出的信号 + void connectionChanged(); // 连接信息发生变化的时候触发的信号 + void activeConnectionChange(); // 网络数据发生变化 + +protected: + void updateDeviceName(); // 更新设备名称 +}; + +class NetworkDeviceRealize : public QObject +{ + Q_OBJECT + + friend class NetworkDeviceBase; + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +Q_SIGNALS: + void deviceStatusChanged(const DeviceStatus &) const; // 状态发生变化的时候触发的信号 + void enableChanged(const bool) const; // 开启设备或禁用设备的时候发出的信号(参数值True表示开启设备,False表示禁用设备) + void connectionChanged(); // 连接发生变化的时候触发的信号 + void nameChanged(const QString &); // 网卡名称发生变化的时候触发的信号 + void removed(); // 设备移除 + // 无线网络信号 + void networkAdded(QList); // wlan新增网络 + void networkRemoved(QList); // wlan列表减少网络 + void connectionSuccess(const AccessPoints *); // 连接无线网络wlan成功,参数为对应的wlan + void hotspotEnableChanged(const bool &); // 热点是否可用发生变化 + void accessPointInfoChanged(const QList &); // wlan信号强度发生变化的网络 + void activeConnectionChanged(); // 活动连接发生变化的时候发出的信号 + // 有线设备的信号 + void connectionAdded(const QList); // 新增连接 + void connectionRemoved(const QList); // 删除连接 + void connectionPropertyChanged(const QList &); // 连接属性发生变化 + void ipV4Changed(); // IPv4地址发生变化 + +public: + void setDevice(NetworkDeviceBase *device); // 设置当前的设备 + virtual bool isEnabled() const; // 当前的网卡是否启用 + virtual bool IPValid(); // IP是否合法 + virtual QString interface() const; // 返回设备上的Interface + virtual QString driver() const; // 驱动,对应于备上返回值的Driver + virtual bool managed() const; // 对应于设备上返回值的Managed + virtual QString vendor() const; // 对应于设备上返回值的Vendor + virtual QString uniqueUuid() const; // 网络设备的唯一的UUID,对应于设备上返回值的UniqueUuid + virtual bool usbDevice() const; // 是否是USB设备,对应于设备上返回值的UsbDevice + virtual QString path() const; // 设备路径,对应于设备上返回值的Path + virtual QString activeAp() const; // 对应于设备上返回值的ActiveAp + virtual bool supportHotspot() const; // 是否支持热点,对应于设备上返回值的SupportHotspot + virtual QString realHwAdr() const; // mac地址 + virtual QString usingHwAdr() const; // 正在使用的mac地址 + virtual const QStringList ipv4(); // IPV4地址 + virtual const QStringList ipv6(); // IPV6地址 + virtual QJsonObject activeConnectionInfo() const; // 获取当前活动连接的信息 + virtual void setEnabled(bool enabled); // 开启或禁用网卡 + virtual void disconnectNetwork(); // 断开网络连接,该方法是一个虚方法,具体在子类 + Connectivity connectivity(); + virtual DeviceStatus deviceStatus() const; + + // 无线网络接口 + virtual QList accessPointItems() const; // 当前网卡上所有的网络列表 + virtual void scanNetwork() {} // 重新加载所有的无线网络列表 + virtual void connectNetwork(const AccessPoints *item); // 连接网络,连接成功抛出deviceStatusChanged信号 + virtual QList wirelessItems() const; // 无线网络连接列表 + virtual AccessPoints *activeAccessPoints() const; // 当前活动的无线连接 + virtual bool hotspotEnabled() { return false; } // 无线网络是否开启热点 + + // 有线网络接口 + virtual bool connectNetwork(WiredConnection *connection); // 连接网络,连接成功抛出deviceStatusChanged信号 + virtual QList wiredItems() const; // 有线网络连接列表 + +protected: + NetworkDeviceRealize(IPConfilctChecker *ipConflictChecker, QObject *parent); + virtual ~NetworkDeviceRealize(); + + NetworkDeviceBase *device() const; + + virtual QString statusStringDetail(); + virtual QString getStatusName(); + void enqueueStatus(const DeviceStatus &status); + virtual void setDeviceStatus(const DeviceStatus &status); + void sortWiredItem(QList &items); + +private Q_SLOTS: + void onConflictStatusChanged(NetworkDeviceBase *device, const bool confilcted); + +private: + NetworkDeviceBase *m_device; + Connectivity m_connectivity; + QQueue m_statusQueue; + DeviceStatus m_deviceStatus; + IPConfilctChecker *m_ipConflictChecker; + bool m_ipConflicted; +}; + +} +} + +#endif // INTERFACE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.cpp new file mode 100644 index 000000000..7759c76e9 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.cpp @@ -0,0 +1,683 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "networkinterprocesser.h" +#include "ipconfilctchecker.h" +#include "networkdbusproxy.h" + +#include "dslcontroller.h" +#include "hotspotcontroller.h" +#include "networkdetails.h" +#include "networkdevicebase.h" +#include "proxycontroller.h" +#include "vpncontroller.h" +#include "wireddevice.h" +#include "wirelessdevice.h" +#include "deviceinterrealize.h" + +#include +#include +#include + +namespace dde { +namespace network { + + +#define CHANGE_CONNECTIONS "ConnectionsChanged" +#define CHANGE_ACTIVECONNECTIONS "ActiveConnectionsChanged" +#define CHANGE_WIRELESSACCESSPOINTS "WirelessAccessPointsChanged" + +NetworkInterProcesser::NetworkInterProcesser(bool sync, bool ipCheck, QObject *parent) + : NetworkProcesser(parent) + , m_proxyController(Q_NULLPTR) + , m_vpnController(Q_NULLPTR) + , m_dslController(Q_NULLPTR) + , m_hotspotController(Q_NULLPTR) + , m_networkInter(new NetworkDBusProxy(this)) + , m_connectivity(Connectivity::Full) + , m_sync(sync) + , m_changedTimer(new QTimer(this)) + , m_ipChecker(new IPConfilctChecker(this, ipCheck)) +{ + initConnection(); + initDeviceService(); +} + +NetworkInterProcesser::~NetworkInterProcesser() +{ + m_ipChecker->release(); + m_ipChecker->deleteLater(); +} + +void NetworkInterProcesser::initNetData(NetworkDBusProxy *networkInt) +{ + onDevicesChanged(networkInt->devices()); + doChangeConnectionList(networkInt->connections()); + doChangeAccesspoint(networkInt->wirelessAccessPoints()); + doChangeActiveConnections(networkInt->activeConnections()); +} + +void NetworkInterProcesser::updateSync(const bool sync) +{ + m_sync = sync; +} + +void NetworkInterProcesser::initDeviceService() +{ + // 同步的方式来获取设备列表和连接列表 + initNetData(m_networkInter); +} + +void NetworkInterProcesser::initConnection() +{ + // 定为100毫秒内,基本上连接、活动连接和热点发生变化的时候都会在100毫秒内发出信号 + // 这里需要用一个timer来执行,因为在实际情况中,ConnectionsChanged信号和ActiveConnectionsChanged信号发出的前后顺序 + // 可能会乱,如果先发送ActiveConnectionsChanged,而此时ConnectionsChanged信号却还没有发出来,此时连接列表可能为空(初次启动) + // 导致后发出的ConnectionsChanged中的所有的连接获取到的连接状态可能是错误的,所以此处用一个定时器来接收,这样就算发送的顺序是乱的, + // 但是它们都能在100毫秒内全部返回,这样在定时器里按照顺序来处理这些信号的数据,保证数据的准确性 + m_changedTimer->setInterval(100); + auto onDataChanged = [ this ](const char *infoName, const QString infoValue) { + // 这里需要用QStringList来保存,因为对于ActiveConnectionsChanged信号来说,在多个网卡存在的情况下,这个信号会发送多次 + // 每次的内容可能会不一样,例如断开连接,第一次发送的信号是第一个网卡的连接状态,第二次发送的信号是第二个网卡的连接状态,必须保证每个 + // 信号都能被正确接收并处理,否则就会出现信号丢失引起状态不正确的问题 + QStringList infoValues = m_changedTimer->property(infoName).toStringList(); + // 移除重复的,不能调用QStringList的removeDuplicates方法,因为这样移除可能会导致将最新的给移除引起错误 + if (infoValues.contains(infoValue)) + infoValues.removeOne(infoValue); + infoValues << infoValue; + m_changedTimer->setProperty(infoName, infoValues); + if (!m_changedTimer->isActive()) + m_changedTimer->start(); + }; + + connect(m_changedTimer, &QTimer::timeout, this, &NetworkInterProcesser::onConnectionInfoChanged); + connect(m_networkInter, &NetworkDBusProxy::DevicesChanged, this, &NetworkInterProcesser::onDevicesChanged); // 设备状态发生变化 + connect(m_networkInter, &NetworkDBusProxy::ConnectionsChanged, this, [ onDataChanged ](const QString &connections) { // 连接发生变化 + onDataChanged(CHANGE_CONNECTIONS, connections); + }); + connect(m_networkInter, &NetworkDBusProxy::ActiveConnectionsChanged, this, [ onDataChanged ](const QString &activeConnections) { // 当前活动连接发生变化 + onDataChanged(CHANGE_ACTIVECONNECTIONS, activeConnections); + }); + connect(m_networkInter, &NetworkDBusProxy::WirelessAccessPointsChanged, this, [ onDataChanged ](const QString &accessPoints) { // 热点发生变化 + onDataChanged(CHANGE_WIRELESSACCESSPOINTS, accessPoints); + }); + connect(m_networkInter, &NetworkDBusProxy::DeviceEnabled, this, &NetworkInterProcesser::onDeviceEnableChanged); // 关闭设备或启用设备 + + connect(m_networkInter, &NetworkDBusProxy::ConnectivityChanged, this, &NetworkInterProcesser::onConnectivityChanged); // 网络状态发生变化 + + connect(m_networkInter, &NetworkDBusProxy::ActiveConnectionInfoChanged, this, [this] { + QString activeConnectionInfo = m_networkInter->GetActiveConnectionInfo(); + activeConnInfoChanged(activeConnectionInfo); + }); +} + +NetworkDeviceBase *NetworkInterProcesser::findDevices(const QString &path) const +{ + // 查找指定路径的设备 + for (NetworkDeviceBase *device : m_devices) { + if (device->path() == path) + return device; + } + + return Q_NULLPTR; +} + +static DeviceType deviceType(const QString &type) +{ + if (type == "wireless") + return DeviceType::Wireless; + + if (type == "wired") + return DeviceType::Wired; + + return DeviceType::Unknown; +} + +void NetworkInterProcesser::onDevicesChanged(const QString &value) +{ + if (value.isEmpty()) + return; + + bool unManager = false; + const QJsonObject data = QJsonDocument::fromJson(value.toUtf8()).object(); + QStringList devPaths; + QList newDevices; + QStringList keys = data.keys(); + for (int i = 0; i < keys.size(); i++) { + QString key = keys[i]; + DeviceType type = deviceType(key); + if (type == DeviceType::Unknown) + continue; + + QJsonArray deviceList = data.value(key).toArray(); + for (const QJsonValue jsonValue : deviceList) { + const QJsonObject &deviceInfo = jsonValue.toObject(); + const QString path = deviceInfo.value("Path").toString(); + if (!deviceInfo.value("Managed").toBool()) { + // 如果managed为false,且在设备列表中未找到,则不添加到设备 + NetworkDeviceBase *device = findDevices(path); + if (!device) + continue; + + unManager = true; + } + + // 根据标志位InterfaceFlags判断网络连接是否有效(无线网络不需要根据这个标志位来判断,因为无线网络在开启飞行模式后,这个标志位会变成0,但是需要显示无线网卡) + if (type != DeviceType::Wireless) { + if (!deviceInfo.value("InterfaceFlags").isUndefined()) { + if (!(deviceInfo.value("InterfaceFlags").toInt() & DEVICE_INTERFACE_FLAG_UP)) { + continue; + } + } + } + + NetworkDeviceBase *device = findDevices(path); + if (!device) { + switch (type) { + case DeviceType::Wireless: { + DeviceInterRealize *wirelessRealize = new WirelessDeviceInterRealize(m_ipChecker, m_networkInter, nullptr); + device = new WirelessDevice(wirelessRealize, this); + wirelessRealize->updateDeviceInfo(deviceInfo); + break; + } + case DeviceType::Wired: { + DeviceInterRealize *wiredRealize = new WiredDeviceInterRealize(m_ipChecker, m_networkInter, nullptr); + device = new WiredDevice(wiredRealize, this); + wiredRealize->updateDeviceInfo(deviceInfo); + break; + } + default: + break; + } + if (device) { + newDevices << device; + m_devices << device; + } + } else { + DeviceInterRealize *deviceRealized = static_cast(device->deviceRealize()); + deviceRealized->updateDeviceInfo(deviceInfo); + } + if (device) { + // 将所有的设备路径添加到缓存中 + if (!devPaths.contains(device->path())) + devPaths << device->path(); + } + } + } + // 对设备进行排序,有线网络始终排在无线网络前面 + auto getPathIndex = [ ](const QString path)->int { + int index = path.lastIndexOf("/"); + QString tmpIndexValue = path.mid(index + 1); + return tmpIndexValue.toInt(); + }; + + std::sort(m_devices.begin(), m_devices.end(), [ = ] (NetworkDeviceBase *dev1, NetworkDeviceBase *dev2) { + if (dev1->deviceType() == DeviceType::Wired && dev2->deviceType() == DeviceType::Wireless) + return true; + + if (dev1->deviceType() == DeviceType::Wireless && dev2->deviceType() == DeviceType::Wired) + return false; + + return getPathIndex(dev1->path()) < getPathIndex(dev2->path()); + }); + // 更新设备的连接信息,因为读取设备状态信息的时候,需要这个连接信息 + updateDeviceConnectiveInfo(); + // 删除已经移除的设备 + QList rmDevices; + for (NetworkDeviceBase *device : m_devices) { + if (!devPaths.contains(device->path())) + rmDevices << device; + } + + for (NetworkDeviceBase *device : rmDevices) + m_devices.removeOne(device); + + if (newDevices.size() > 0 || rmDevices.size() > 0) { + // 更新设备名称 + updateDeviceName(); + + // 告诉外面新增的设备列表 + if (newDevices.size() > 0) { + // 初始化设备的数据,包括设备是否可用等信息 + bool wirelessExist = false; + for (NetworkDeviceBase *device : newDevices) { + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->initDeviceInfo(); + if (device->deviceType() == DeviceType::Wireless) + wirelessExist = true; + } + + // 更新设备的时候,同时需要更新连接信息,因为可能连接的信号发生在设备更新信息之前 + updateConnectionsInfo(newDevices); + // 如果新增的设备中存在无线网卡,则同时需要更新wlan的信息,因为存在如下情况 + // 如果关闭热点的时候,会先移除设备,然后再新增设备,此时如果不更新wlan,这种情况下,新增的那个无线设备的wlan就会为空 + if (wirelessExist) + doChangeAccesspoint(m_networkInter->wirelessAccessPoints()); + } + // 设备列表发生变化的同时,需要同时更新网络连接状态 + doChangeActiveConnections(m_networkInter->activeConnections()); + + // 设备列表发生变化的同时,需要同时更新DSL的相关的信息,因为DSL里面用到了设备的信息,需要获取设备路径等 + updateDSLData(); + + // 设备列表发生变化后,同时也需要更新设备热点的信息 + updateDeviceHotpot(); + + // 发送删除的设备列表信号,此时这些设备对象还未析构,外面调用来处理响应的操作,统一在一个线程中处理 + if (rmDevices.size() > 0) { + for (NetworkDeviceBase *device : rmDevices) + Q_EMIT device->removed(); + + Q_EMIT deviceRemoved(rmDevices); + // 在移除设备后,需要立刻将网络详情中对应的项移除 + updateNetworkDetails(); + } + + // 需要将新增设备的信号放到更新设备数据之后,因为外部接收到新增设备信号的时候,需要更新设备信息,如果放到更新设备数据前面,则里面的数据不是最新的数据 + if (newDevices.size() > 0) + Q_EMIT deviceAdded(newDevices); + + // 一定要将删除设备放到最后,因为在发出信号后,外面可能还会用到 + for (NetworkDeviceBase *device : rmDevices) + delete device; + } + // 如果发现有Manager=false的对象,则让它等一秒后从设备列表中移除manager==false的对象,因为可能是关闭热点引起的Manager=false + if (unManager) { + QTimer::singleShot(1000, this, [ this ] { + QList unManagerDevices; + for (NetworkDeviceBase *device : m_devices) { + if (!device->managed()) + unManagerDevices << device; + } + + if (unManagerDevices.size() > 0) { + for (NetworkDeviceBase *device : unManagerDevices) + m_devices.removeOne(device); + + for (NetworkDeviceBase *device : unManagerDevices) + Q_EMIT device->removed(); + + Q_EMIT deviceRemoved(unManagerDevices); + // 在移除设备后,需要立刻将网络详情中对应的项移除 + updateNetworkDetails(); + // 删除对象 + for (NetworkDeviceBase *device : unManagerDevices) + delete device; + } + }); + } +} + +void NetworkInterProcesser::doChangedData(changedFunction func, const char *infoName) +{ + QStringList changeDatas = m_changedTimer->property(infoName).toStringList(); + if (!changeDatas.isEmpty()) { + for (QString changeData : changeDatas) + (this->*func)(changeData); + + changeDatas.clear(); + m_changedTimer->setProperty(infoName, changeDatas); + } +} + +void NetworkInterProcesser::onConnectionInfoChanged() +{ + // 触发数据改变的顺序,1.无线网络 2.连接信息 3.活动连接信息,理由如下 + // 连接信息中更新无线连接的时候,需要从无线网络中获取wlan数据进行同步,所以需要先同步无线网络(wlan), + // 活动连接信息需要更新的是已经存在的连接,因此需要先同步连接信息,活动连接信息放到最后同步 + doChangedData(&NetworkInterProcesser::doChangeAccesspoint, CHANGE_WIRELESSACCESSPOINTS); + doChangedData(&NetworkInterProcesser::doChangeConnectionList, CHANGE_CONNECTIONS); + doChangedData(&NetworkInterProcesser::doChangeActiveConnections, CHANGE_ACTIVECONNECTIONS); + if (m_changedTimer->isActive()) + m_changedTimer->stop(); +} + +void NetworkInterProcesser::doChangeConnectionList(const QString &connections) +{ + if (connections.isEmpty()) + return; + + m_connections = QJsonDocument::fromJson(connections.toUtf8()).object(); + updateConnectionsInfo(m_devices); + + // 更新VPN的数据 + if (m_vpnController && m_connections.contains("vpn")) + m_vpnController->updateVPNItems(m_connections.value("vpn").toArray()); + + // 更新DSL的数据 + updateDSLData(); + + // 更新热点的数据 + updateDeviceHotpot(); + + // 向外抛出信号告知连接发生了变化 + Q_EMIT connectionChanged(); +} + +void NetworkInterProcesser::doChangeActiveConnections(const QString &activeConnections) +{ + // 初次进来的时候,活动连接内容为空,此时需要返回。 + // 如果不判断这个的话,那么在初始化的时候就会向外部发送activeConnectionChange信号,引起网络列表的显示的问题 + if (activeConnections.isEmpty()) + return; + + activeInfoChanged(activeConnections); + // 同步IP地址等信息 + QString activeConnectionInfo =m_networkInter->GetActiveConnectionInfo(); + activeConnInfoChanged(activeConnectionInfo); + onConnectivityChanged(m_networkInter->connectivity()); + updateDeviceConnectiveInfo(); +} + +void NetworkInterProcesser::updateDeviceConnectiveInfo() +{ + for (NetworkDeviceBase *device : m_devices) + device->deviceRealize()->m_connectivity = m_connectivity; +} + +void NetworkInterProcesser::activeConnInfoChanged(const QString &conns) +{ + // 当没有激活的连接时,需要更新对应的连接信息和网络详细信息为空 + if (conns == "null") { + for (NetworkDeviceBase *device : m_devices){ + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->updateActiveConnectionInfo(QList()); + m_networkDetails.clear(); + } + + Q_EMIT activeConnectionChange(); + + return; + } + + QJsonParseError error; + m_activeConnectionInfo = QJsonDocument::fromJson(conns.toUtf8(), &error).array(); + if (error.error == QJsonParseError::NoError) { + QMultiMap deviceInfoMap; + for (QJsonValue jsonValue : m_activeConnectionInfo) { + QJsonObject connInfo = jsonValue.toObject(); + const QString devPath = connInfo.value("Device").toString(); + NetworkDeviceBase *device = findDevices(devPath); + if (!device) + continue; + + deviceInfoMap.insert(device, connInfo); + } + + for (auto it = deviceInfoMap.begin(); it != deviceInfoMap.end(); it++) { + NetworkDeviceBase *device = it.key(); + QList json = deviceInfoMap.values(device); + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->updateActiveConnectionInfo(json); + } + // 对于没有发送的设备,直接让其显示空 + for (NetworkDeviceBase *device : m_devices) { + if (!deviceInfoMap.contains(device)) { + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->updateActiveConnectionInfo(QList()); + } + } + } + // 同时需要更新网络信息 + updateNetworkDetails(); + + Q_EMIT activeConnectionChange(); +} + +void NetworkInterProcesser::doChangeAccesspoint(const QString &accessPoints) +{ + if (accessPoints.isEmpty()) + return; + + const QJsonObject json = QJsonDocument::fromJson(accessPoints.toUtf8()).object(); + + for (NetworkDeviceBase *device : m_devices) { + // 只有无线网卡才会有wlan连接信息 + if (device->deviceType() == DeviceType::Wireless) { + WirelessDevice *d = static_cast(device); + if (json.contains(d->path())) { + QJsonArray array = json.value(d->path()).toArray(); + + WirelessDeviceInterRealize *deviceRealize = qobject_cast(d->deviceRealize()); + if (deviceRealize) + deviceRealize->updateAccesspoint(array); + } + } + } +} + +void NetworkInterProcesser::onDeviceEnableChanged(const QString &devicePath, bool enabled) +{ + NetworkDeviceBase *device = findDevices(devicePath); + if (device) { + DeviceInterRealize *interDevice = static_cast(device->deviceRealize()); + interDevice->setDeviceEnabledStatus(enabled); + // 如果改设备是无线设备,且支持热点,则更新热点的信息 + if (!m_hotspotController) + return; + // 如果当前设备是无线设备切当前设备支持热点,则更新当前设备的热点信息 + if (device->deviceType() == DeviceType::Wireless && device->supportHotspot()) + updateDeviceHotpot(); + } +} + +void NetworkInterProcesser::onConnectivityChanged(uint conectivity) +{ + Connectivity conn = static_cast(conectivity); + if (conn == m_connectivity) + return; + + m_connectivity = conn; + updateDeviceConnectiveInfo(); + Q_EMIT connectivityChanged(m_connectivity); +} + +void NetworkInterProcesser::updateConnectionsInfo(const QList &devices) +{ + if (devices.isEmpty() || m_connections.isEmpty()) + return; + + static QList> devConnInfo + = {{ "wired", DeviceType::Wired }, { "wireless", DeviceType::Wireless }}; + + for (const QPair &connInfo : devConnInfo) { + if (m_connections.contains(connInfo.first)) { + const QJsonArray &connlist = m_connections.value(connInfo.first).toArray(); + for (NetworkDeviceBase *device : devices) { + if (device->deviceType() == connInfo.second) { + DeviceInterRealize *deviceInter = static_cast(device->deviceRealize()); + deviceInter->updateConnection(connlist); + } + } + } + } +} + +void NetworkInterProcesser::activeInfoChanged(const QString &conns) +{ + // 当前活动连接发生变化 + m_activeConection = QJsonDocument::fromJson(conns.toUtf8()).object(); + QMap> devActiveConn; + for (const QJsonValue info : m_activeConection) { + const QJsonObject connInfo = info.toObject(); + const QJsonArray devArray = connInfo.value("Devices").toArray(); + for (const QJsonValue &value : devArray) { + const QString devPath = value.toString(); + devActiveConn[devPath] << connInfo; + } + } + + // 更新DSL的活动连接信息 + if (m_dslController) + m_dslController->updateActiveConnections(m_activeConection); + + // 更新设备的活动连接信息 + for (auto it = devActiveConn.begin(); it != devActiveConn.end(); it++) { + const QString devPath = it.key(); + NetworkDeviceBase *device = findDevices(devPath); + if (!device) + continue; + + const QList devInfos = it.value(); + DeviceInterRealize *deviceInt = static_cast(device->deviceRealize()); + deviceInt->updateActiveInfo(devInfos); + } + + // 更新热点的活动连接信息 + if (m_hotspotController) + m_hotspotController->updateActiveConnection(m_activeConection); + + // 更新VPN的活动连接信息 + if (m_vpnController) + m_vpnController->updateActiveConnection(m_activeConection); +} + +Connectivity NetworkInterProcesser::connectivity() +{ + return m_connectivity; +} + +QList NetworkInterProcesser::devices() +{ + return m_devices; +} + +QList NetworkInterProcesser::networkDetails() +{ + return m_networkDetails; +} + +void NetworkInterProcesser::updateDeviceHotpot() +{ + if (!m_hotspotController) + return; + + m_hotspotController->updateDevices(m_devices); + + if (!m_connections.contains("wireless-hotspot")) + return; + + const QJsonArray hotspots = m_connections.value("wireless-hotspot").toArray(); + // 更新连接的信息 + m_hotspotController->updateConnections(hotspots); +} + +void NetworkInterProcesser::updateNetworkDetails() +{ + QStringList devicePaths; + for (NetworkDeviceBase *device : m_devices) { + if (!device->isEnabled()) + continue; + + devicePaths << device->path(); + } + + + // 删除多余的网络详情的数据 + if (m_networkDetails.size() >= m_activeConnectionInfo.size()) { + for (int i = m_networkDetails.size() - 1; i >= m_activeConnectionInfo.size(); i--) { + NetworkDetails *detail = m_networkDetails[i]; + m_networkDetails.removeOne(detail); + delete detail; + } + } + + // 遍历网络详情列表,更新内存中的记录 + for (int i = 0; i < m_activeConnectionInfo.size(); i++) { + QJsonObject activeConnection = m_activeConnectionInfo.at(i).toObject(); + + NetworkDetails *detail = Q_NULLPTR; + if (i < m_networkDetails.size()) { + detail = m_networkDetails[i]; + } else { + detail = new NetworkDetails(this); + m_networkDetails << detail; + } + + detail->updateData(activeConnection); + } + + // 删除不在设备列表中的项 + const auto details = m_networkDetails; + for (NetworkDetails *detail : details) { + if (!devicePaths.contains(detail->devicePath())) { + m_networkDetails.removeOne(detail); + delete detail; + } + } + + if (m_devices.size() > 0) { + std::sort(m_networkDetails.begin(), m_networkDetails.end(), [ & ] (NetworkDetails *detail1, NetworkDetails *detail2) { + int index1 = -1; + int index2 = -1; + for (int i = 0; i < m_devices.size(); i++) { + NetworkDeviceBase *device = m_devices[i]; + if (device->path() == detail1->devicePath()) + index1 = i; + else if (device->path() == detail2->devicePath()) + index2 = i; + } + + return index1 < index2; + }); + } +} + +void NetworkInterProcesser::updateDSLData() +{ + if (!m_dslController || !m_connections.contains("pppoe")) + return; + + m_dslController->updateDevice(m_devices); + m_dslController->updateDSLItems(m_connections.value("pppoe").toArray()); + m_dslController->updateActiveConnections(m_activeConection); +} + +ProxyController *NetworkInterProcesser::proxyController() +{ + // 因为有的地方不会调用这个接口,所以该对象延迟创建 + if (!m_proxyController) + m_proxyController = new ProxyController(m_networkInter, this); + + return m_proxyController; +} + +VPNController *NetworkInterProcesser::vpnController() +{ + // 延迟创建 + if (!m_vpnController) { + m_vpnController = new VPNController(m_networkInter, this); + if (m_connections.contains("vpn")) + m_vpnController->updateVPNItems(m_connections.value("vpn").toArray()); + m_vpnController->updateActiveConnection(m_activeConection); + } + + return m_vpnController; +} + +DSLController *NetworkInterProcesser::dslController() +{ + // 延迟创建 + if (!m_dslController) { + m_dslController = new DSLController(m_networkInter, this); + updateDSLData(); + } + + return m_dslController; +} + +HotspotController *NetworkInterProcesser::hotspotController() +{ + // 延迟创建 + if (!m_hotspotController) { + m_hotspotController = new HotspotController(m_networkInter, this); + updateDeviceHotpot(); + m_hotspotController->updateActiveConnection(m_activeConection); + } + + return m_hotspotController; +} + +} +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.h b/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.h new file mode 100644 index 000000000..93cbd1687 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/networkinterprocesser.h @@ -0,0 +1,98 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKPROCESSER_H +#define NETWORKPROCESSER_H + +#include "netinterface.h" +#include "netutils.h" + +#include + +class QTimer; + +namespace dde { +namespace network { + +class NetworkDeviceBase; +class ProxyController; +class VPNController; +class DSLController; +class HotspotController; +class NetworkDetails; +class IPConfilctChecker; +class NetworkDBusProxy; + +class NetworkInterProcesser : public NetworkProcesser +{ + Q_OBJECT + + friend class NetworkController; + + typedef void (NetworkInterProcesser::*changedFunction)(const QString &); + +protected: + explicit NetworkInterProcesser(bool sync, bool ipCheck, QObject *parent); + ~NetworkInterProcesser() override; + + void initDeviceService(); + void initConnection(); + void initNetData(NetworkDBusProxy *networkInt); // 填充基本数据 + + void updateSync(const bool sync); + + NetworkDeviceBase *findDevices(const QString &path) const; // 根据设备path查找设备 + void updateConnectionsInfo(const QList &devices); // 更新设备连接信息 + void activeInfoChanged(const QString &conns); // 更新活动连接信息 + void updateDeviceConnectiveInfo(); // 更新设备信号连接强度信息 + void activeConnInfoChanged(const QString &conns); // 活动连接信息发生变化 + void updateDeviceHotpot(); // 更新热点设备数据 + + void updateNetworkDetails(); // 更新网络连接信息 + + void updateDSLData(); // 更新DSL的数据 + void updateVPNActiveConnection(); // 更新VPN的活动连接信息 + + void doChangeConnectionList(const QString &connections); + void doChangeActiveConnections(const QString &activeConnections); + void doChangeAccesspoint(const QString &accessPoints); + + void doChangedData(changedFunction func, const char *infoName); + +protected: + ProxyController *proxyController() override; // 返回代理控制管理器 + VPNController *vpnController() override; // 返回VPN控制器 + DSLController *dslController() override; // DSL控制器 + HotspotController *hotspotController() override; // 个人热点控制器 + Connectivity connectivity() override; // 获取当前的信号 + QList devices() override; // 获取当前的所有的设备 + QList networkDetails() override; // 获取设备的网络详情 + +protected Q_SLOTS: + void onDevicesChanged(const QString &value); + void onConnectionInfoChanged(); // 变化的网络连接的状态 + void onDeviceEnableChanged(const QString &devicePath, bool enabled); + void onConnectivityChanged(uint conectivity); + +private: + ProxyController *m_proxyController; + VPNController *m_vpnController; + DSLController *m_dslController; + HotspotController *m_hotspotController; + QList m_devices; + NetworkDBusProxy *m_networkInter; + QJsonObject m_connections; + Connectivity m_connectivity; + QJsonArray m_activeConnectionInfo; + QJsonObject m_activeConection; + QList m_networkDetails; + bool m_sync; + QTimer *m_changedTimer; + IPConfilctChecker *m_ipChecker; +}; + +} +} + +#endif // NETWORKPROCESSER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.cpp b/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.cpp new file mode 100644 index 000000000..bb7e3329f --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.cpp @@ -0,0 +1,317 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "devicemanagerrealize.h" +#include "dslcontroller.h" +#include "hotspotcontroller.h" +#include "networkdevicebase.h" +#include "networkmanagerprocesser.h" +#include "proxycontroller.h" +#include "vpncontroller.h" +#include "ipconfilctchecker.h" +#include "networkdbusproxy.h" + +#include +#include +#include + +#include +#include + +#include +#include + +using namespace dde::network; +using namespace NetworkManager; + +const static QString networkService = "org.deepin.dde.Network1"; +const static QString networkPath = "/org/deepin/dde/Network1"; + +NetworkManagerProcesser::NetworkManagerProcesser(QObject *parent) + : NetworkProcesser(parent) + , m_proxyController(Q_NULLPTR) + , m_vpnController(Q_NULLPTR) + , m_dslController(Q_NULLPTR) + , m_hotspotController(Q_NULLPTR) + , m_networkInter(Q_NULLPTR) + , m_connectivity(dde::network::Connectivity::Unknownconnectivity) + , m_ipChecker(new IPConfilctChecker(this, false)) +{ + Device::List allDevices = NetworkManager::networkInterfaces(); + for (Device::Ptr device : allDevices) + onDeviceAdded(device->uni()); + + initConnections(); + onConnectivityChanged(NetworkManager::connectivity()); +} + +NetworkManagerProcesser::~NetworkManagerProcesser() +{ + m_ipChecker->release(); + m_ipChecker->deleteLater(); +} + +void NetworkManagerProcesser::initConnections() +{ + connect(NetworkManager::notifier(), &Notifier::deviceAdded, this, &NetworkManagerProcesser::onDeviceAdded); + connect(NetworkManager::notifier(), &Notifier::deviceRemoved, this, &NetworkManagerProcesser::onDeviceRemove); + connect(NetworkManager::notifier(), &Notifier::connectivityChanged, this, &NetworkManagerProcesser::onConnectivityChanged); + QDBusConnection::systemBus().connect("org.deepin.dde.Network1", "/org/deepin/dde/Network1", "org.deepin.dde.Network1", "DeviceEnabled", this, SLOT(onDeviceEnabledChanged(QDBusObjectPath, bool))); +} + +QList NetworkManagerProcesser::devices() +{ + return m_devices; +} + +dde::network::Connectivity NetworkManagerProcesser::connectivity() +{ + return m_connectivity; +} + +QList NetworkManagerProcesser::networkDetails() +{ + return m_details; +} + +ProxyController *NetworkManagerProcesser::proxyController() +{ + if (!m_proxyController) + m_proxyController = new ProxyController(networkInter(), this); + + return m_proxyController; +} + +VPNController *NetworkManagerProcesser::vpnController() +{ + if (!m_vpnController) + m_vpnController = new VPNController(networkInter(), this); + + return m_vpnController; +} + +DSLController *NetworkManagerProcesser::dslController() +{ + if (!m_dslController) + m_dslController = new DSLController(networkInter(), this); + + return m_dslController; +} + +HotspotController *NetworkManagerProcesser::hotspotController() +{ + if (!m_hotspotController) + m_hotspotController = new HotspotController(networkInter(), this); + + return m_hotspotController; +} + +void NetworkManagerProcesser::sortDevice() +{ + auto getPathIndex = [](const QString path)->int { + int index = path.lastIndexOf("/"); + QString tmpIndexValue = path.mid(index + 1); + return tmpIndexValue.toInt(); + }; + // 有线网络始终在无线网络的前面,如果两者都是有线或者无线网络,则按照path的顺序来排序 + std::sort(m_devices.begin(), m_devices.end(), [ = ](NetworkDeviceBase *device1, NetworkDeviceBase *device2) { + if (device1->deviceType() == DeviceType::Wired && device2->deviceType() == DeviceType::Wireless) + return true; + + if (device1->deviceType() == DeviceType::Wireless && device2->deviceType() == DeviceType::Wired) + return false; + + return getPathIndex(device1->path()) < getPathIndex(device2->path()); + }); +} + +void NetworkManagerProcesser::onDeviceAdded(const QString &uni) +{ + auto deviceExist = [ this ] (const QString &uni)->bool { + for (NetworkDeviceBase *device : m_devices) { + if (device->path() == uni) + return true; + } + + return false; + }; + + if (deviceExist(uni)) + return; + + Device::Ptr currentDevice(nullptr); + Device::List allDevices = NetworkManager::networkInterfaces(); + for (Device::Ptr device : allDevices) { + if (device->uni() != uni) + continue; + + if (device->type() == Device::Wifi || device->type() == Device::Ethernet) + currentDevice = device; + + break; + } + + if (!currentDevice) + return; + + auto createDevice = [ = ](const Device::Ptr &device)->NetworkDeviceBase * { + if (device->type() == Device::Wifi) { + // 无线网络 + NetworkManager::WirelessDevice::Ptr wDevice = device.staticCast(); + DeviceManagerRealize *deviceRealize = new DeviceManagerRealize(m_ipChecker, wDevice); + return new WirelessDevice(deviceRealize, Q_NULLPTR); + } + + if (device->type() == Device::Ethernet) { + // 有线网络 + NetworkManager::WiredDevice::Ptr wDevice = device.staticCast(); + DeviceManagerRealize *deviceRealize = new DeviceManagerRealize(m_ipChecker, wDevice); + return new WiredDevice(deviceRealize, Q_NULLPTR); + } + + return nullptr; + }; + + // 无线网卡不管是否down,都显示,因为在开启飞行模式后,需要显示网卡的信息 + auto deviceCreateOrRemove = [this, deviceExist, + createDevice](const Device::Ptr &device) { + bool hasFlag = true; + #ifdef USE_DEEPIN_NMQT + hasFlag = device->interfaceFlags() & DEVICE_INTERFACE_FLAG_UP; + #endif + if (device->managed() && (hasFlag || device->type() == Device::Wifi)) { + // 如果由非manager变成manager的模式,则新增设备 + if (!deviceExist(device->uni())) { + NetworkDeviceBase *newDevice = createDevice(device); + if (newDevice) { + m_devices << newDevice; + sortDevice(); + updateDeviceName(); + Q_EMIT deviceAdded({ newDevice }); + } + } + } else { + // 如果由manager变成非manager模式,则移除设备 + NetworkDeviceBase *rmDevice = nullptr; + for (NetworkDeviceBase *dev : m_devices) { + if (dev->path() == device->uni()) { + m_devices.removeOne(dev); + rmDevice = dev; + break; + } + } + if (rmDevice) { + Q_EMIT rmDevice->removed(); + sortDevice(); + updateDeviceName(); + Q_EMIT deviceRemoved({ rmDevice }); + delete rmDevice; + rmDevice = nullptr; + } + } + }; + + NetworkDeviceBase *newDevice = Q_NULLPTR; + bool hasFlag = true; +#ifdef USE_DEEPIN_NMQT + hasFlag = currentDevice->interfaceFlags() & DEVICE_INTERFACE_FLAG_UP; +#endif + if (currentDevice->managed() && (hasFlag || currentDevice->type() == Device::Wifi)) + newDevice = createDevice(currentDevice); +#ifdef USE_DEEPIN_NMQT + connect(currentDevice.get(), &Device::interfaceFlagsChanged, this, [ currentDevice, deviceCreateOrRemove ] { + deviceCreateOrRemove(currentDevice); + }); +#endif + connect(currentDevice.get(), &Device::managedChanged, this, [ currentDevice, deviceCreateOrRemove ] { + deviceCreateOrRemove(currentDevice); + }); + + if (newDevice) { + m_devices << newDevice; + sortDevice(); + updateDeviceName(); + Q_EMIT deviceAdded({ newDevice }); + } +} + +void NetworkManagerProcesser::onDeviceRemove(const QString &uni) +{ + NetworkDeviceBase *rmDevice = Q_NULLPTR; + for (NetworkDeviceBase *device : m_devices) { + if (device->path() == uni) { + m_devices.removeOne(device); + rmDevice = device; + break; + } + } + + if (rmDevice) { + Q_EMIT rmDevice->removed(); + sortDevice(); + updateDeviceName(); + Q_EMIT deviceRemoved({ rmDevice }); + delete rmDevice; + } +} + +void NetworkManagerProcesser::onConnectivityChanged(NetworkManager::Connectivity conntity) +{ + dde::network::Connectivity ctity; + switch (conntity) { + case NetworkManager::Connectivity::Full: { + ctity = dde::network::Connectivity::Full; + break; + } + case NetworkManager::Connectivity::Portal: { + ctity = dde::network::Connectivity::Portal; + break; + } + case NetworkManager::Connectivity::Limited: { + ctity = dde::network::Connectivity::Limited; + break; + } + case NetworkManager::Connectivity::NoConnectivity: { + ctity = dde::network::Connectivity::Noconnectivity; + break; + } + case NetworkManager::Connectivity::UnknownConnectivity: { + ctity = dde::network::Connectivity::Unknownconnectivity; + break; + } + } + if (m_connectivity != ctity) { + m_connectivity = ctity; + for (NetworkDeviceBase *device : m_devices) { + DeviceManagerRealize *deviceRealize = static_cast(device->deviceRealize()); + deviceRealize->m_connectivity = m_connectivity; + } + Q_EMIT connectivityChanged(m_connectivity); + } +} + +void NetworkManagerProcesser::onDeviceEnabledChanged(QDBusObjectPath path, bool enabled) +{ + NetworkDeviceBase *device = findDevice(path.path()); + if (device) + Q_EMIT device->enableChanged(enabled); +} + +NetworkDeviceBase *NetworkManagerProcesser::findDevice(const QString devicePath) +{ + for (NetworkDeviceBase *device : m_devices) { + if (device->path() == devicePath) + return device; + } + + return Q_NULLPTR; +} + +NetworkDBusProxy *NetworkManagerProcesser::networkInter() +{ + if (!m_networkInter) + m_networkInter = new NetworkDBusProxy(this); + + return m_networkInter; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.h b/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.h new file mode 100644 index 000000000..3f61fa9b3 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/realize/networkmanagerprocesser.h @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef NETWORKMANAGERPROCESSER_H +#define NETWORKMANAGERPROCESSER_H + +#include "netinterface.h" +#include "networkconst.h" +#include "netutils.h" + +#include + +namespace dde { +namespace network { + +class NetworkDeviceBase; +class IPConfilctChecker; +class NetworkDBusProxy; + +class NetworkManagerProcesser : public NetworkProcesser +{ + Q_OBJECT + +public: + explicit NetworkManagerProcesser(QObject *parent = Q_NULLPTR); + ~NetworkManagerProcesser() override; + +protected: + QList devices() override; + dde::network::Connectivity connectivity() override; + QList networkDetails() override; + ProxyController *proxyController() override; // 返回代理控制管理器 + VPNController *vpnController() override; // 返回VPN控制器 + DSLController *dslController() override; // DSL控制器 + HotspotController *hotspotController() override; // 个人热点控制器 + +private: + void initConnections(); + NetworkDeviceBase *findDevice(const QString devicePath); + NetworkDBusProxy *networkInter(); + void sortDevice(); + +private slots: + void onDeviceAdded(const QString &uni); + void onDeviceRemove(const QString &uni); + void onConnectivityChanged(NetworkManager::Connectivity conntity); + void onDeviceEnabledChanged(QDBusObjectPath path, bool enabled); + +private: + QList m_devices; + QList m_details; + ProxyController *m_proxyController; + VPNController *m_vpnController; + DSLController *m_dslController; + HotspotController *m_hotspotController; + NetworkDBusProxy *m_networkInter; + dde::network::Connectivity m_connectivity; + IPConfilctChecker *m_ipChecker; +}; + +} +} + +#endif // NETWORKMANAGERPROCESSER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.cpp b/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.cpp new file mode 100644 index 000000000..29828672a --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.cpp @@ -0,0 +1,172 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "vpncontroller.h" +#include "networkconst.h" +#include "networkdbusproxy.h" + +#include "networkmanagerqt/manager.h" + +#include + +using namespace dde::network; +using namespace NetworkManager; + +void VPNController::setEnabled(const bool enabled) +{ + m_networkInter->setVpnEnabled(enabled); +} + +void VPNController::connectItem(VPNItem *item) +{ + connectItem(item->connection()->uuid()); +} + +void VPNController::connectItem(const QString &uuid) +{ + m_networkInter->ActivateConnection(uuid, QDBusObjectPath("/")); +} + +void VPNController::disconnectItem() +{ + if (!m_activePath.isEmpty()) + deactivateConnection(m_activePath); +} + +VPNController::VPNController(NetworkDBusProxy *networkInter, QObject *parent) + : QObject(parent) + , m_networkInter(networkInter) + , m_enabled(false) +{ + Q_ASSERT(m_networkInter); + connect(m_networkInter, &NetworkDBusProxy::VpnEnabledChanged, this, &VPNController::onEnableChanged); + onEnableChanged(m_networkInter->vpnEnabled()); +} + +VPNController::~VPNController() +{ +} + +void VPNController::updateVPNItems(const QJsonArray &vpnArrays) +{ + // 更新列表中的VPN状态 + QList newVpns; + QList changeVpns; + QStringList paths; + for (const QJsonValue jsonValue : vpnArrays) { + QJsonObject vpn = jsonValue.toObject(); + QString path = vpn.value("Path").toString(); + VPNItem *item = findItem(path); + if (!item) { + item = new VPNItem; + item->setConnection(vpn); + m_vpnItems << item; + newVpns << item; + } else { + if (item->connection()->id() != vpn.value("Id").toString()) + changeVpns << item; + + item->setConnection(vpn); + } + + paths << path; + } + + if (changeVpns.size()) + Q_EMIT itemChanged(changeVpns); + + if (newVpns.size()) + Q_EMIT itemAdded(newVpns); + + // 将列表中不存在的VPN删除 + QList rmVpns; + for (VPNItem *item : m_vpnItems) { + if (!paths.contains(item->connection()->path())) + rmVpns << item; + } + + for (VPNItem *item : rmVpns) + m_vpnItems.removeOne(item); + + if (rmVpns.size() > 0) + Q_EMIT itemRemoved(rmVpns); + + // 删除移除的对象 + for (VPNItem *item : rmVpns) + delete item; +} + +void VPNController::updateActiveConnection(const QJsonObject &activeConection) +{ + // 先将所有的连接都置为未连接状态 + QMap allConnectionStatus; + for (VPNItem *item : m_vpnItems) { + allConnectionStatus[item->connection()->uuid()] = item->status(); + item->setConnectionStatus(ConnectionStatus::Deactivated); + } + + // 获取当前所有的活动连接,并记录活动连接是否发生过变化 + m_activePath.clear(); + bool statusChanged = false; + QStringList keys = activeConection.keys(); + for (QString key : keys) { + QJsonObject json = activeConection.value(key).toObject(); + VPNItem *vpnItem = findItemByUuid(json.value("Uuid").toString()); + if (vpnItem) { + ConnectionStatus state = convertConnectionStatus(json.value("State").toInt()); + vpnItem->setConnectionStatus(state); + if (state == ConnectionStatus::Activated) + m_activePath = key; + + QString uuid = vpnItem->connection()->uuid(); + if (allConnectionStatus.contains(uuid)) { + ConnectionStatus oldStatus = allConnectionStatus[uuid]; + if (!statusChanged && oldStatus != state) + statusChanged = true; + } + } + } + + if (statusChanged) + Q_EMIT activeConnectionChanged(); +} + +VPNItem *VPNController::findItem(const QString &path) +{ + for (VPNItem *item : m_vpnItems) { + if (item->connection()->path() == path) + return item; + } + + return Q_NULLPTR; +} + +VPNItem *VPNController::findItemByUuid(const QString &uuid) +{ + for (VPNItem *item : m_vpnItems) { + if (item->connection()->uuid() == uuid) + return item; + } + + return Q_NULLPTR; +} + +void VPNController::onEnableChanged(const bool enabled) +{ + m_enabled = enabled; + Q_EMIT enableChanged(enabled); +} + +/** + * @brief UVPNItem详细项 + */ + +VPNItem::VPNItem() + : ControllItems() +{ +} + +VPNItem::~VPNItem() +{ +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.h b/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.h new file mode 100644 index 000000000..485fccb00 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/vpncontroller.h @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef VPNCONTROLLER_H +#define VPNCONTROLLER_H + +#include "networkconst.h" +#include "netutils.h" + +#include + +namespace dde { + +namespace network { +class NetworkDBusProxy; +class VPNItem; + +class VPNController : public QObject +{ + Q_OBJECT + + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + void setEnabled(const bool enabled); // 开启或者关闭VPN + inline bool enabled() const { return m_enabled; } // VPN开启还是关闭 + void connectItem(VPNItem *item); // 连接VPN + void connectItem(const QString &uuid); // 连接VPN(重载函数) + void disconnectItem(); // 断开当前活动VPN连接 + inline QList items() { return m_vpnItems; } // 获取所有的VPN列表 + +Q_SIGNALS: + void enableChanged(const bool); // 开启关闭VPN发出的信号 + void itemAdded(const QList &); // 新增VPN发出的信号 + void itemRemoved(const QList &); // 移除VPN发出的信号 + void itemChanged(const QList &); // VPN项发生变化(ID) + void activeConnectionChanged(); // 活动连接发生变化的时候发出的信号 + +protected: + explicit VPNController(NetworkDBusProxy *networkInter, QObject *parent = Q_NULLPTR); + ~VPNController(); + + void updateVPNItems(const QJsonArray &vpnArrays); + void updateActiveConnection(const QJsonObject &activeConection); + +private: + VPNItem *findItem(const QString &path); + VPNItem *findItemByUuid(const QString &uuid); + +private Q_SLOTS: + void onEnableChanged(const bool enabled); + +private: + NetworkDBusProxy *m_networkInter; + bool m_enabled; + QList m_vpnItems; + QString m_activePath; +}; + +class VPNItem : public ControllItems +{ + friend class VPNController; + +protected: + VPNItem(); + ~VPNItem(); +}; + +} + +} + +#endif // UVPNCONTROLLER_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/wireddevice.cpp b/panels/dock/tray/plugins/dde-network-core/src/wireddevice.cpp new file mode 100644 index 000000000..aa5a04e4d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/wireddevice.cpp @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "wireddevice.h" +#include "networkconst.h" +#include "realize/netinterface.h" + +using namespace dde::network; + +WiredDevice::WiredDevice(NetworkDeviceRealize *devcieRealize, QObject *parent) + : NetworkDeviceBase(devcieRealize, parent) +{ + connect(devcieRealize, &NetworkDeviceRealize::connectionAdded, this, &WiredDevice::connectionAdded); + connect(devcieRealize, &NetworkDeviceRealize::connectionRemoved, this, &WiredDevice::connectionRemoved); + connect(devcieRealize, &NetworkDeviceRealize::connectionPropertyChanged, this, &WiredDevice::connectionPropertyChanged); + connect(devcieRealize, &NetworkDeviceRealize::activeConnectionChanged, this, &WiredDevice::activeConnectionChanged); +} + +WiredDevice::~WiredDevice() +{ +} + +bool WiredDevice::connectNetwork(WiredConnection *connection) +{ + NetworkDeviceRealize *deviceInterface = deviceRealize(); + return deviceInterface->connectNetwork(connection); +} + +bool WiredDevice::connectNetwork(const QString &path) +{ + QList wiredItems = items(); + for (WiredConnection *connection : wiredItems) { + if (connection->connection()->path() == path) + return connectNetwork(connection); + } + + return false; +} + +bool WiredDevice::isConnected() const +{ + QList wiredItems = items(); + for (WiredConnection *connection : wiredItems) { + if (connection->connected()) + return true; + } + + return false; +} + +DeviceType WiredDevice::deviceType() const +{ + return DeviceType::Wired; +} + +QList WiredDevice::items() const +{ + return deviceRealize()->wiredItems(); +} + +WiredConnection::WiredConnection() + : ControllItems() +{ +} + +WiredConnection::~WiredConnection() +{ +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/wireddevice.h b/panels/dock/tray/plugins/dde-network-core/src/wireddevice.h new file mode 100644 index 000000000..a17e5e997 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/wireddevice.h @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef WIREDDEVICE_H +#define WIREDDEVICE_H + +#include "networkdevicebase.h" + +namespace dde { + +namespace network { + +class WiredConnection; + +class WiredDevice : public NetworkDeviceBase +{ + Q_OBJECT + + friend class NetworkController; + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +private: + WiredDevice(NetworkDeviceRealize *devcieRealize, QObject *parent); + ~WiredDevice() override; + +Q_SIGNALS: + void connectionAdded(const QList); // 新增连接 + void connectionRemoved(const QList); // 删除连接 + void connectionPropertyChanged(const QList &); // 连接属性发生变化 + +public: + bool connectNetwork(WiredConnection *connection); // 连接网络,连接成功抛出deviceStatusChanged信号 + bool connectNetwork(const QString &path); // 连接网络重载函数,参数为配置路径 + bool isConnected() const override; // 是否连接网络,重写基类的虚函数 + DeviceType deviceType() const override; // 返回设备类型,适应基类统一的接口 + QList items() const; // 有线网络连接列表 +}; + +class WiredConnection : public ControllItems +{ + friend class WiredDevice; + friend class WiredDeviceInterRealize; + friend class DeviceManagerRealize; + +protected: + WiredConnection(); + ~WiredConnection(); + +}; + +} + +} + +#endif // UWIREDDEVICE_H diff --git a/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.cpp b/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.cpp new file mode 100644 index 000000000..780ae4b9d --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.cpp @@ -0,0 +1,237 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "wirelessdevice.h" +#include "netutils.h" +#include "realize/netinterface.h" + +using namespace dde::network; + +bool WirelessDevice::isConnected() const +{ + QList aps = deviceRealize()->accessPointItems(); + return std::any_of(aps.begin(), aps.end(), [](const AccessPoints *ap) { + return ap->status() == ConnectionStatus::Activated; + }); +} + +DeviceType WirelessDevice::deviceType() const +{ + return DeviceType::Wireless; +} + +QList WirelessDevice::accessPointItems() const +{ + /* 理论上,如果网卡是禁用状态,这里应该直接返回空列表 + * 但是由于在禁用网卡或者打开网卡的时候,后台的反应比较慢,控制中心无法实时获取,所以这里暂时让其先返回所有的网络列表, + * 等后台反应慢的问题改好后,再把注释打开 + * if (!isEnabled()) + return QList();*/ + + return deviceRealize()->accessPointItems(); +} + +void WirelessDevice::scanNetwork() +{ + deviceRealize()->scanNetwork(); +} + +void WirelessDevice::connectNetwork(const AccessPoints *item) +{ + deviceRealize()->connectNetwork(item); +} + +AccessPoints *WirelessDevice::activeAccessPoints() const +{ + return deviceRealize()->activeAccessPoints(); +} + +bool WirelessDevice::hotspotEnabled() const +{ + return deviceRealize()->hotspotEnabled(); +} + +void WirelessDevice::connectNetwork(const QString &ssid) +{ + AccessPoints *apConnection = findAccessPoint(ssid); + if (apConnection) + connectNetwork(apConnection); +} + +QList WirelessDevice::items() const +{ + return deviceRealize()->wirelessItems(); +} + +WirelessDevice::WirelessDevice(NetworkDeviceRealize *networkInter, QObject *parent) + : NetworkDeviceBase(networkInter, parent) +{ + connect(networkInter, &NetworkDeviceRealize::networkAdded, this, &WirelessDevice::networkAdded); + connect(networkInter, &NetworkDeviceRealize::networkRemoved, this, &WirelessDevice::networkRemoved); + connect(networkInter, &NetworkDeviceRealize::connectionSuccess, this, &WirelessDevice::connectionSuccess); + connect(networkInter, &NetworkDeviceRealize::hotspotEnableChanged, this, &WirelessDevice::hotspotEnableChanged); + connect(networkInter, &NetworkDeviceRealize::accessPointInfoChanged, this, &WirelessDevice::accessPointInfoChanged); +} + +WirelessDevice::~WirelessDevice() +{ +} + +AccessPoints *WirelessDevice::findAccessPoint(const QString &ssid) +{ + QList accessPoints = deviceRealize()->accessPointItems(); + for (AccessPoints *accessPoint : accessPoints) { + if (accessPoint->ssid() == ssid) + return accessPoint; + } + + return Q_NULLPTR; +} + +/** + * @brief 无线网络连接 + */ +AccessPoints::AccessPoints(const QJsonObject &json, QObject *parent) + : QObject(parent) + , m_json(json) + , m_status(ConnectionStatus::Unknown) +{ +} + +AccessPoints::~AccessPoints() +{ +} + +QString AccessPoints::ssid() const +{ + return m_json.value("Ssid").toString(); +} + +int AccessPoints::strength() const +{ + if (m_json.isEmpty()) + return -1; + + return m_json.value("Strength").toInt(); +} + +bool AccessPoints::secured() const +{ + return m_json.value("Secured").toBool(); +} + +bool AccessPoints::securedInEap() const +{ + return m_json.value("SecuredInEap").toBool(); +} + +int AccessPoints::frequency() const +{ + return m_json.value("Frequency").toInt(); +} + +QString AccessPoints::path() const +{ + return m_json.value("Path").toString(); +} + +QString AccessPoints::devicePath() const +{ + return m_devicePath; +} + +bool AccessPoints::connected() const +{ + return (m_status == ConnectionStatus::Activated); +} + +ConnectionStatus AccessPoints::status() const +{ + return m_status; +} + +bool AccessPoints::hidden() const +{ + if (m_json.contains("Hidden")) + return m_json.value("Hidden").toBool(); + + return false; +} + +AccessPoints::WlanType AccessPoints::type() const +{ + // 根据需求,在当前Wlan未连接的情况下,才判断是否有同名Wlan中存在Wlan6,如果当前已连接,则直接判断 + if (!connected()) { + // 如果是重名的Wlan,则判断同名的Wlan的Flags是否为Wlan6 + if (m_json.contains("extendFlags")) { + int flag = m_json.value("extendFlags").toInt(); + if (flag & AP_FLAGS_HE) + return WlanType::wlan6; + } + } + + if (m_json.contains("Flags")) { + int flag = m_json.value("Flags").toInt(); + if (flag & AP_FLAGS_HE) + return WlanType::wlan6; + } + + return WlanType::wlan; +} + +void AccessPoints::updateAccessPoints(const QJsonObject &json) +{ + int nOldStrength = strength(); + bool oldSecured = secured(); + m_json = json; + int nStrength = strength(); + if (nOldStrength != -1 && nStrength != nOldStrength) + Q_EMIT strengthChanged(nStrength); + + bool newSecured = secured(); + if (oldSecured != newSecured) + Q_EMIT securedChanged(newSecured); +} + +void AccessPoints::updateConnectionStatus(ConnectionStatus status) +{ + if (m_status == status) + return; + + m_status = status; + Q_EMIT connectionStatusChanged(status); +} + +/** + * @brief 无线连接信息 + */ +AccessPoints *WirelessConnection::accessPoints() const +{ + return m_accessPoints; +} + +ConnectionStatus WirelessConnection::status() const +{ + return m_accessPoints ? m_accessPoints->status() :ConnectionStatus::Unknown; +} + +WirelessConnection::WirelessConnection() + : ControllItems() + , m_accessPoints(Q_NULLPTR) +{ +} + +WirelessConnection::~WirelessConnection() +{ +} + +WirelessConnection *WirelessConnection::createConnection(AccessPoints *ap) +{ + WirelessConnection *wirelessConnection = new WirelessConnection; + QJsonObject json; + json.insert("Ssid", ap->ssid()); + wirelessConnection->setConnection(json); + wirelessConnection->m_accessPoints = ap; + return wirelessConnection; +} diff --git a/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.h b/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.h new file mode 100644 index 000000000..8645e3777 --- /dev/null +++ b/panels/dock/tray/plugins/dde-network-core/src/wirelessdevice.h @@ -0,0 +1,138 @@ +// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef WIRELESSDEVICE_H +#define WIRELESSDEVICE_H + +#include "networkdevicebase.h" + +namespace dde { + +namespace network { + +class AccessPoints; +class WirelessConnection; +class NetworkDeviceRealize; +/** + * @brief 无线网络设备-无线网卡 + */ +class WirelessDevice : public NetworkDeviceBase +{ + Q_OBJECT + + friend class NetworkController; + friend class NetworkInterProcesser; + friend class NetworkManagerProcesser; + +public: + bool isConnected() const override; // 是否连接网络,重写基类的虚函数 + DeviceType deviceType() const override; // 返回设备类型,适应基类统一的接口 + QList accessPointItems() const; // 当前网卡上所有的网络列表 + void scanNetwork(); // 重新加载所有的无线网络列表 + void connectNetwork(const AccessPoints *item); // 连接网络,连接成功抛出deviceStatusChanged信号 + void connectNetwork(const QString &ssid); // 连接网络,重载函数 + QList items() const; // 无线网络连接列表 + AccessPoints *activeAccessPoints() const; // 当前活动的无线连接 + bool hotspotEnabled() const; // 是否开启热点 + +Q_SIGNALS: + void networkAdded(QList); // wlan新增网络 + void networkRemoved(QList); // wlan列表减少网络 + void connectionSuccess(const AccessPoints *); // 连接无线网络wlan成功,参数为对应的wlan + void hotspotEnableChanged(const bool &); // 热点是否可用发生变化 + void accessPointInfoChanged(const QList &); // wlan信号强度发生变化的网络 + +protected: + WirelessDevice(NetworkDeviceRealize *networkInter, QObject *parent); + ~WirelessDevice() override; + +private: + AccessPoints *findAccessPoint(const QString &ssid); +}; + +/** + * @brief 无线网络连接-wlan + */ + +class AccessPoints : public QObject +{ + Q_OBJECT + + friend class WirelessDevice; + friend class WirelessDeviceInterRealize; + friend class DeviceManagerRealize; + + Q_PROPERTY(QString ssid READ ssid) + Q_PROPERTY(int strength READ strength) + Q_PROPERTY(bool secured READ secured) + Q_PROPERTY(bool securedInEap READ securedInEap) + Q_PROPERTY(int frequency READ frequency) + Q_PROPERTY(QString path READ path) + Q_PROPERTY(QString devicePath READ devicePath) + Q_PROPERTY(bool connected READ connected) + +public: + enum class WlanType { wlan, wlan6 }; + +protected: + AccessPoints(const QJsonObject &json, QObject *parent = Q_NULLPTR); + ~AccessPoints(); + +public: + QString ssid() const; // 网络SSID,对应于返回接口中的Ssid + int strength() const; // 信号强度,对应于返回接口中的Strength + bool secured() const; // 是否加密,对应于返回接口中的Secured + bool securedInEap() const; // 对应于返回接口中的SecuredInEap + int frequency() const; // 频率,对应于返回接口中的Frequency + QString path() const; // 路径,对应于返回接口中的Path + QString devicePath() const; // 对应的设备的路径,为返回接口中的key值 + bool connected() const; // 网络是否连接成功 + ConnectionStatus status() const; // 当前网络的连接状态 + bool hidden() const; // 是否为隐藏网络 + WlanType type() const; + +Q_SIGNALS: + void strengthChanged(const int) const; // 当前信号强度变化 + void connectionStatusChanged(ConnectionStatus); + void securedChanged(bool); + +protected: + void updateAccessPoints(const QJsonObject &json); + void updateConnectionStatus(ConnectionStatus); + +private: + QJsonObject m_json; + QString m_devicePath; + ConnectionStatus m_status; +}; + +/** + * @brief 无线连接信息 + */ + +class WirelessConnection: public ControllItems +{ + friend class WirelessDevice; + friend class WirelessDeviceInterRealize; + friend class DeviceManagerRealize; + +public: + AccessPoints *accessPoints() const; // 返回当前对应的wlan的指针 + ConnectionStatus status() const override; + +protected: + WirelessConnection(); + virtual ~WirelessConnection() override; + + static WirelessConnection *createConnection(AccessPoints *ap); + +private: + AccessPoints *m_accessPoints; +}; + +} + +} + +#endif // UWIRELESSDEVICE_H diff --git a/panels/dock/tray/plugins/display/CMakeLists.txt b/panels/dock/tray/plugins/display/CMakeLists.txt index 428d9267c..8195ff866 100644 --- a/panels/dock/tray/plugins/display/CMakeLists.txt +++ b/panels/dock/tray/plugins/display/CMakeLists.txt @@ -34,6 +34,7 @@ target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces ../../widgets ../../frame + ../../frame/util ../../frame/qtdbusextended ./dbusinterface/generation_dbus_interface componments) diff --git a/panels/dock/tray/plugins/keyboard-layout/CMakeLists.txt b/panels/dock/tray/plugins/keyboard-layout/CMakeLists.txt index 2fe400398..b459b109b 100644 --- a/panels/dock/tray/plugins/keyboard-layout/CMakeLists.txt +++ b/panels/dock/tray/plugins/keyboard-layout/CMakeLists.txt @@ -25,6 +25,7 @@ target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces ./dbusinterface ./dbusinterface/generation_dbus_interface + ../../frame/util ../../frame/qtdbusextended) target_link_libraries(${PLUGIN_NAME} PRIVATE diff --git a/panels/dock/tray/plugins/pluginmanager/CMakeLists.txt b/panels/dock/tray/plugins/pluginmanager/CMakeLists.txt index d713262f7..d0f178850 100644 --- a/panels/dock/tray/plugins/pluginmanager/CMakeLists.txt +++ b/panels/dock/tray/plugins/pluginmanager/CMakeLists.txt @@ -28,6 +28,7 @@ add_library(${PLUGIN_NAME} SHARED ${SRCS}) set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../loader/) target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ./pluginadapter + ../../frame/util ../../frame/drag ../../frame/dbusinterface ../../frame/dbusinterface/generation_dbus_interface/ diff --git a/panels/dock/tray/plugins/shutdown/CMakeLists.txt b/panels/dock/tray/plugins/shutdown/CMakeLists.txt index ef3a58d78..d3efc5b77 100644 --- a/panels/dock/tray/plugins/shutdown/CMakeLists.txt +++ b/panels/dock/tray/plugins/shutdown/CMakeLists.txt @@ -26,6 +26,7 @@ add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN") add_library(${PLUGIN_NAME} SHARED ${SRCS} shutdown.qrc) set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../) target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} + ../../frame/util ../../interfaces ../../widgets) target_link_libraries(${PLUGIN_NAME} PRIVATE diff --git a/panels/dock/tray/plugins/sound/CMakeLists.txt b/panels/dock/tray/plugins/sound/CMakeLists.txt index dffbf4432..ffaf8a221 100644 --- a/panels/dock/tray/plugins/sound/CMakeLists.txt +++ b/panels/dock/tray/plugins/sound/CMakeLists.txt @@ -33,6 +33,7 @@ target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces ../../widgets ../../frame + ../../frame/util ../../frame/accessible ../../frame/qtdbusextended )