Initial commit

This commit is contained in:
jzxc95 2022-06-10 14:12:39 +08:00
commit 84b1e7c4e7
81 changed files with 6674 additions and 0 deletions

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
shine <shenghuang@ubuntukylin.com>

674
COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# NAME
kylin-nm - kylin network monitor used in ubuntu-kylin operation system
# DESCRIPTION
kylin-nm is a Qt based applet and uses some interface provided by NetworkManager.
It provides a GUI for users to connect or disconnect wired or wireless network which managed by NetworkManager.
Users can also create new wired network and configure a old network.
By click button at left bottom in the main window, a network configure window of NetworkManager will show in the screen.
Users can get some information about network directly by clicking one item in the network list, these information shown in extension area.
# BUILD KYLIN-NM
down the source sode
install dependency packages(see cntrol files in the debian directory)
execute debuild command in the root directory of project
execute sudo dpkg -i packagename.deb to install

View File

@ -0,0 +1,2 @@
# Triggers added by dh_makeshlibs/12.10kylin1
activate-noawait ldconfig

View File

@ -0,0 +1 @@
908edb1dea29bfaa43ee5b97a0a5925e89ab3a2d 9526db1579983f1afadd66ff9ae17cf4b74167b7 cfb2d74f62354e96ddeee21d97db424f0083d6fe

View File

@ -0,0 +1,13 @@
Package: kylin-nm-plugin-dbgsym
Package-Type: ddeb
Source: kylin-nm-plugin
Version: 3.20.0.0
Auto-Built-Package: debug-symbols
Architecture: amd64
Maintainer: Kylin Team <team+kylin@tracker.debian.org>
Installed-Size: 3683
Depends: kylin-nm-plugin (= 3.20.0.0)
Section: debug
Priority: optional
Description: debug symbols for kylin-nm-plugin
Build-Ids: 908edb1dea29bfaa43ee5b97a0a5925e89ab3a2d 9526db1579983f1afadd66ff9ae17cf4b74167b7 cfb2d74f62354e96ddeee21d97db424f0083d6fe

View File

@ -0,0 +1,3 @@
181cb30cab816cd7323d9090fba952dd usr/lib/debug/.build-id/90/8edb1dea29bfaa43ee5b97a0a5925e89ab3a2d.debug
e43ca5539b4713789d75b2fccbdbd6b5 usr/lib/debug/.build-id/95/26db1579983f1afadd66ff9ae17cf4b74167b7.debug
e537b90ca8c081d3dd50a5f43bcf8fc3 usr/lib/debug/.build-id/cf/b2d74f62354e96ddeee21d97db424f0083d6fe.debug

6
debian/changelog vendored Normal file
View File

@ -0,0 +1,6 @@
kylin-nm-plugin (3.20.0.0) v101; urgency=medium
* new
-- zhaoshixu <zhaoshixu@kylinos.cn> Wed, 08 Jun 2022 10:00:53 +0800

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
9

40
debian/control vendored Normal file
View File

@ -0,0 +1,40 @@
Source: kylin-nm-plugin
Section: utils
Priority: optional
Maintainer: Kylin Team <team+kylin@tracker.debian.org>
Uploaders: handsome_feng <jianfengli@ubuntukylin.com>
Build-Depends: debhelper (>=9),
qtbase5-dev,
qt5-qmake,
qtchooser,
qtscript5-dev,
qttools5-dev-tools,
qtbase5-dev-tools,
libqt5x11extras5-dev,
libgsettings-qt-dev,
libkf5windowsystem-dev,
libx11-dev,
libqt5svg5-dev,
libkf5networkmanagerqt-dev (>= 5.36.0),
libnm-dev,
libcap-dev,
libnma-dev,
libsecret-1-dev,
kylin-nm-dev,
libkysdk-qtwidgets-dev,
Standards-Version: 4.5.0
Rules-Requires-Root: no
Homepage: https://github.com/ukui/kylin-nm
Vcs-Git: https://github.com/ukui/kylin-nm.git
Vcs-Browser: https://github.com/ukui/kylin-nm
Package: kylin-nm-plugin
Architecture: any
Depends: network-manager (>=1.2.6),
libkysdk-qtwidgets,
${shlibs:Depends},
${misc:Depends}
Description: Gui Applet tool for display and edit network simply
Kylin NM is a Applet tool for managing network settings simply.
It has beautiful UI and very comfortable to use.
It's better work together with UKUI.

25
debian/copyright vendored Normal file
View File

@ -0,0 +1,25 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: kylin-nm-dev
Upstream-Contact: Kylin Team <ukui@kylinos.cn>
Source: https://github.com/ukui/kylin-nm
Files: *
Copyright: 2019, Tianjin KYLIN Information Technology Co., Ltd.
License: GPL-3+
License: GPL-3+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
.
This package 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 Genaral Public License for more details.
.
You should have received a copy og the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
.
On Debian systems, the complete text of the GNU General
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".

1
debian/kylin-nm.manpages vendored Normal file
View File

@ -0,0 +1 @@
man/kylin-nm-plugin.1

34
debian/rules vendored Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/make -f
export QT_SELECT=5
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
QMAKE_OPTS = DEFINES+=NO_DEBUG_ON_CONSOLE
MAKE_OPTS = PREFIX=/usr QMAKE=qmake LRELEASE=lrelease QMAKE_OPTS="$(QMAKE_OPTS)"
override_dh_auto_configure:
QT_SELECT=qt5 dh_auto_configure \
-- "QMAKE_CXXFLAGS=$(CFLAGS)" \
kylin-nm.pro
%:
dh $@
override_dh_install:
dh_install
override_dh_missing:
dh_missing --fail-missing
override_dh_auto_clean:
[ ! -d .moc ] || $(RM) -r .moc
[ ! -d .obj ] || $(RM) -r .obj
[ ! -d .ui ] || $(RM) -r .ui
[ ! -f Makefile ] || dh_auto_clean
override_dh_auto_build:
dh_auto_build -- $(MAKE_OPTS)
override_dh_shlibdeps:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info

1
debian/source/format vendored Normal file
View File

@ -0,0 +1 @@
3.0 (native)

2
debian/watch vendored Normal file
View File

@ -0,0 +1,2 @@
version=4
https://github.com/ukui/kylin-nm/releases .*/kylin-nm_(\d\S+)\.orig\.tar\.gz

18
kylin-nm.pro Normal file
View File

@ -0,0 +1,18 @@
TEMPLATE = subdirs
CONFIG += ordered \
qt
SUBDIRS = \
plugins/plugin.pro \
libnm-kylin \
# kylin-nm-gui \
# kylin-nm-server \
#kylin-nm-gui.depends = libnm-kylin
#kylin-nm-server.depends = libnm-kylin
#TRANSLATIONS += \
# translations/kylin-nm_zh_CN.ts \
# translations/kylin-nm_tr.ts \
# translations/kylin-nm_bo.ts

View File

@ -0,0 +1,192 @@
#include "kynetworkicon.h"
//#include <QDBusArgument>
#define EXCELLENT_SIGNAL 80
#define GOOD_SIGNAL 55
#define OK_SIGNAL 30
#define LOW_SIGNAL 5
#define NONE_SIGNAL 0
#define EXCELLENT_SIGNAL_ICON "network-wireless-signal-excellent-symbolic"
#define GOOD_SIGNAL_ICON "network-wireless-signal-good-symbolic"
#define OK_SIGNAL_ICON "network-wireless-signal-ok-symbolic"
#define LOW_SIGNAL_ICON "network-wireless-signal-weak-symbolic"
#define NONE_SIGNAL_ICON "network-wireless-signal-none-symbolic"
#define EXCELLENT_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-excellent-error-symbolic"
#define GOOD_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-good-error-symbolic"
#define OK_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-ok-error-symbolic"
#define LOW_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-weak-error-symbolic"
#define NONE_SIGNAL_LIMIT_ICON "ukui-network-wireless-signal-none-error-symbolic"
KyNetworkIcon::KyNetworkIcon(QWidget *parent):
QPushButton(parent)
{
qRegisterMetaType<KySecuType>("KyConnectState");
qRegisterMetaType<KyConnectionType>("KyConnectionType");
thread = new QThread;
manager = new KyNetworkManager();
manager->moveToThread(thread);
thread->start();
loadIcons.append(QIcon::fromTheme("kylin-network-1"));
loadIcons.append(QIcon::fromTheme("kylin-network-2"));
loadIcons.append(QIcon::fromTheme("kylin-network-3"));
loadIcons.append(QIcon::fromTheme("kylin-network-4"));
loadIcons.append(QIcon::fromTheme("kylin-network-5"));
loadIcons.append(QIcon::fromTheme("kylin-network-6"));
loadIcons.append(QIcon::fromTheme("kylin-network-7"));
loadIcons.append(QIcon::fromTheme("kylin-network-8"));
loadIcons.append(QIcon::fromTheme("kylin-network-9"));
loadIcons.append(QIcon::fromTheme("kylin-network-10"));
loadIcons.append(QIcon::fromTheme("kylin-network-11"));
loadIcons.append(QIcon::fromTheme("kylin-network-12"));
updateIcon();
initConnect();
loadingTimer = new QTimer(this);
connect(loadingTimer, &QTimer::timeout, this, &KyNetworkIcon::onSetTrayIconLoading);
refreshTimer = new QTimer(this);
connect(loadingTimer, &QTimer::timeout, this, &KyNetworkIcon::updateIcon);
refreshTimer->start(10 * 1000);
}
KyNetworkIcon::~KyNetworkIcon()
{
delete thread;
delete manager;
thread = nullptr;
manager = nullptr;
}
void KyNetworkIcon::initConnect()
{
connect(manager, &KyNetworkManager::wiredStateChange, this, &KyNetworkIcon::onWiredStateChange);
connect(manager, &KyNetworkManager::wirelessStateChange, this, &KyNetworkIcon::onWirelessStateChange);
connect(manager, &KyNetworkManager::connectivityChanged, [=](){
qDebug() << "connectivityChanged";
updateIcon();
});
connect(manager, &KyNetworkManager::primaryConnectionTypeChanged, [=](){
qDebug() << "primaryConnectionTypeChanged";
updateIcon();
});
}
void KyNetworkIcon::updateIcon()
{
int signalStrength = 0;
KyConnectionType connectType;
manager->getPrimaryConnectionType(connectType);
qDebug() << "getPrimaryConnectionType" << connectType;
if (connectType == CONNECT_TYPE_WIRED) {
this->setIcon(QIcon::fromTheme("network-wired-symbolic"));
iconStatus = IconActiveType::LAN_CONNECTED;
} else if (connectType == CONNECT_TYPE_WIRELESS) {
signalStrength = manager->getAcivateWifiSignal();
iconStatus = IconActiveType::WLAN_CONNECTED;
} else {
this->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
iconStatus = IconActiveType::NOT_CONNECTED;
}
KyConnectivity connecttivity;
manager->getConnectivity(connecttivity);
if (connecttivity != CONNECTIVITY_FULL) {
if (iconStatus == IconActiveType::LAN_CONNECTED) {
this->setIcon(QIcon::fromTheme("network-error-symbolic"));
iconStatus = IconActiveType::LAN_CONNECTED_LIMITED;
} else if (iconStatus == IconActiveType::WLAN_CONNECTED) {
iconStatus = IconActiveType::WLAN_CONNECTED_LIMITED;
}
}
if (iconStatus == IconActiveType::WLAN_CONNECTED) {
if (signalStrength > EXCELLENT_SIGNAL){
this->setIcon(QIcon::fromTheme(EXCELLENT_SIGNAL_ICON));
} else if (signalStrength > GOOD_SIGNAL) {
this->setIcon(QIcon::fromTheme(GOOD_SIGNAL_ICON));
} else if (signalStrength > OK_SIGNAL) {
this->setIcon(QIcon::fromTheme(OK_SIGNAL_ICON));
} else if (signalStrength > LOW_SIGNAL) {
this->setIcon(QIcon::fromTheme(LOW_SIGNAL_ICON));
} else {
this->setIcon(QIcon::fromTheme(NONE_SIGNAL_ICON));
}
} else if (iconStatus == IconActiveType::WLAN_CONNECTED_LIMITED) {
if (signalStrength > EXCELLENT_SIGNAL){
this->setIcon(QIcon::fromTheme(EXCELLENT_SIGNAL_LIMIT_ICON));
} else if (signalStrength > GOOD_SIGNAL) {
this->setIcon(QIcon::fromTheme(GOOD_SIGNAL_LIMIT_ICON));
} else if (signalStrength > OK_SIGNAL) {
this->setIcon(QIcon::fromTheme(OK_SIGNAL_LIMIT_ICON));
} else if (signalStrength > LOW_SIGNAL) {
this->setIcon(QIcon::fromTheme(LOW_SIGNAL_LIMIT_ICON));
} else {
this->setIcon(QIcon::fromTheme(NONE_SIGNAL_LIMIT_ICON));
}
}
qDebug() << "iconStatus" << iconStatus;
}
void KyNetworkIcon::startLoading()
{
qDebug() << "startLoading";
if (!loadingTimer->isActive()) {
loadingTimer->start(60);
}
}
void KyNetworkIcon::stopLoading()
{
qDebug() << "stopLoading";
if (loadingTimer->isActive()) {
loadingTimer->stop();
}
}
void KyNetworkIcon::onSetTrayIconLoading()
{
if (currentIconIndex > 11) {
currentIconIndex = 0;
}
this->setIcon(loadIcons.at(currentIconIndex));
currentIconIndex ++;
}
void KyNetworkIcon::onWiredStateChange(QString deviceName, QString uuid, KyConnectState state)
{
Q_UNUSED(deviceName)
Q_UNUSED(uuid)
qDebug() << "onWiredStateChange" << state;
if (state == CONNECT_STATE_ACTIVATING
|| state == CONNECT_STATE_DEACTIVATING) {
startLoading();
} else {
stopLoading();
updateIcon();
}
}
void KyNetworkIcon::onWirelessStateChange(QString deviceName, QString ssid, QString uuid, KyConnectState state)
{
Q_UNUSED(deviceName)
Q_UNUSED(ssid)
Q_UNUSED(uuid)
qDebug() << "onWirelessStateChange" << state;
if (state == CONNECT_STATE_ACTIVATING
|| state == CONNECT_STATE_DEACTIVATING) {
startLoading();
} else {
stopLoading();
updateIcon();
}
}

View File

@ -0,0 +1,53 @@
#ifndef KYNETWORKICON_H
#define KYNETWORKICON_H
#include "libnm-base-kylin_global.h"
#include <kylin-nm/kylinnetworkmanager.h>
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QThread>
enum IconActiveType {
NOT_CONNECTED = 0,
LAN_CONNECTED,
WLAN_CONNECTED,
LAN_CONNECTED_LIMITED,
WLAN_CONNECTED_LIMITED,
ACTIVATING,
};
class LIBNMBASEKYLIN_EXPORT KyNetworkIcon : public QPushButton
{
Q_OBJECT
public:
KyNetworkIcon(QWidget *parent = nullptr);
~KyNetworkIcon();
private:
KyNetworkManager* manager;
QThread* thread;
QTimer *loadingTimer;
QTimer *refreshTimer;
int currentIconIndex=0;
QList<QIcon> loadIcons;
IconActiveType iconStatus = IconActiveType::NOT_CONNECTED;
void initConnect();
void startLoading();
void stopLoading();
private Q_SLOTS:
void onSetTrayIconLoading();
void updateIcon();
void onWiredStateChange(QString deviceName, QString uuid, KyConnectState state);
void onWirelessStateChange(QString deviceName, QString ssid, QString uuid, KyConnectState state);
};
#endif // KYNETWORKICON_H

View File

@ -0,0 +1,41 @@
QT += core gui widgets dbus network
TEMPLATE = lib
DEFINES += LIBNMICONKYLIN_LIBRARY
CONFIG += c++14 qt link_pkgconfig no_keywords
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
PKGCONFIG += kylin-nm-base
#INCLUDEPATH += $$PWD/../libnm-base-kylin/
#INCLUDEPATH += /usr/include/KF5/NetworkManagerQt
#LIBS += -L$$PWD/../libnm-base-kylin/ -l kylin-nm-base
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
kynetworkicon.cpp
HEADERS += \
kynetworkicon.h
# Default rules for deployment.
unix {
target.path = /usr/lib
manager.path = /usr/include/kylin-nm
manager.files = kynetworkicon.h
INSTALLS += manager
}
!isEmpty(target.path): INSTALLS += target

View File

@ -0,0 +1,9 @@
TEMPLATE = subdirs
SUBDIRS += \
# libnm-base-kylin \
# libnm-external-kylin \
libnm-icon-kylin
#libnm-external-kylin.depends = libnm-base-kylin
#libnm-icon-kylin.depends = libnm-base-kylin

20
man/kylin-nm-plugin.1 Normal file
View File

@ -0,0 +1,20 @@
.\" Man page for Kylin-nm
.TH KYLIN-NM 1 "20 September 2019" "UKUI Desktop Environment"
.\" Please adjust this date when revising the manpage.
.\"
.SH "NAME"
kylin-nm \- The tool for the UKUI Desktop Environment
.SH "SYNOPSIS"
.B kylin-nm
.SH "DESCRIPTION"
The \fBkylin-nm\fR program is a part of the ukui-indicators, It provides network manager for the the UKUI Desktop Environment. Detect the system disk automatically, Can pop up and open the device.
.PP
This manual page documents the \fBkylin-nm\fR command.
.P
.SH "BUGS"
.SS Should you encounter any bugs, they may be reported at:
https://github.com/ukui/kylin-nm/issues
.SH "AUTHORS"
.SS This Man Page has been written for the UKUI Desktop Environment by:
shine <shenghuang@ubuntukylin.com> (2019)
.SH "SEE ALSO"

View File

@ -0,0 +1,19 @@
#include "deviceframe.h"
#define LAYOUT_MARGINS 24,0,0,0
#define FRAME_HEIGHT 36
DeviceFrame::DeviceFrame(QString devName, QWidget *parent) : QFrame(parent)
{
this->setFixedHeight(FRAME_HEIGHT);
QHBoxLayout *deviceLayout = new QHBoxLayout(this);
deviceLayout->setContentsMargins(LAYOUT_MARGINS);
setLayout(deviceLayout);
deviceLabel = new QLabel(this);
deviceLabel->setText(devName);
deviceLabel->setDisabled(true);
deviceLayout->addWidget(deviceLabel);
deviceLayout->addStretch();
}

View File

@ -0,0 +1,17 @@
#ifndef DEVICEFRAME_H
#define DEVICEFRAME_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
class DeviceFrame : public QFrame
{
public:
DeviceFrame(QString devName, QWidget *parent = nullptr);
public:
QLabel * deviceLabel = nullptr;
};
#endif // DEVICEFRAME_H

View File

@ -0,0 +1,23 @@
#include "divider.h"
#include <QPainter>
#include <QApplication>
Divider::Divider(QWidget * parent) : QFrame(parent)
{
this->setFixedHeight(1);
}
void Divider::paintEvent(QPaintEvent * e)
{
QPainter p(this);
// QColor color = qApp->palette().color(QPalette::BrightText);
// color.setAlphaF(0.08);
p.save();
p.setBrush(Qt::black);
p.setPen(Qt::transparent);
p.drawRoundedRect(this->rect(), 6, 6);
p.restore();
return QFrame::paintEvent(e);
}

View File

@ -0,0 +1,15 @@
#ifndef DIVIDER_H
#define DIVIDER_H
#include <QFrame>
class Divider : public QFrame
{
public:
Divider(QWidget * parent = nullptr);
~Divider() = default;
protected:
void paintEvent(QPaintEvent *event);
};
#endif // DIVIDER_H

View File

@ -0,0 +1,36 @@
#include "drownlabel.h"
#include "deviceframe.h"
#define ICONSIZE 16,16
DrownLabel::DrownLabel(QString devName, QWidget * parent) : QLabel(parent)
{
m_devName = devName;
setFixedSize(36,36);
loadPixmap(isChecked);
this->setProperty("useIconHighlightEffect", 0x2);
}
DrownLabel::~DrownLabel()
{
}
void DrownLabel::setDropDownStatus(bool status)
{
isChecked = status;
loadPixmap(isChecked);
}
void DrownLabel::loadPixmap(bool isChecked)
{
if (isChecked) {
setPixmap(QIcon::fromTheme("ukui-up-symbolic").pixmap(ICONSIZE));
} else {
setPixmap(QIcon::fromTheme("ukui-down-symbolic").pixmap(ICONSIZE));
}
}
void DrownLabel::mouseReleaseEvent(QMouseEvent *event)
{
emit labelClicked();
QWidget::mouseReleaseEvent(event);
}

View File

@ -0,0 +1,27 @@
#ifndef DROWNLABEL_H
#define DROWNLABEL_H
#include <QObject>
#include <QLabel>
#include <QWidget>
#include <QMouseEvent>
class DrownLabel : public QLabel
{
Q_OBJECT
public:
explicit DrownLabel(QString devName, QWidget * parent = nullptr);
~DrownLabel();
void setDropDownStatus(bool status);
QString m_devName;
bool isChecked = true;
private:
void loadPixmap(bool isChecked);
protected:
virtual void mouseReleaseEvent(QMouseEvent * event);
Q_SIGNALS:
void labelClicked();
};
#endif // DROWNLABEL_H

View File

@ -0,0 +1,105 @@
#include "infobutton.h"
#include <QEvent>
#include <QPainter>
#include <QApplication>
#include <QDebug>
#define BUTTON_SIZE 36,36
#define ICON_SIZE 16,16
#define BACKGROUND_COLOR QColor(0,0,0,0)
#define FOREGROUND_COLOR_NORMAL qApp->palette().text().color()
#define FOREGROUND_COLOR_HOVER QColor(55,144,250,255)
#define FOREGROUND_COLOR_PRESS QColor(36,109,212,255)
#define OUTER_PATH 8,8,16,16
#define INNER_PATH 9,9,14,14
#define TEXT_POS 14,5,16,16,0
#define BUTTON_SIZE 36,36
#define THEME_SCHAME "org.ukui.style"
#define COLOR_THEME "styleName"
InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
{
this->setFixedSize(BUTTON_SIZE);
initUI();
const QByteArray style_id(THEME_SCHAME);
if (QGSettings::isSchemaInstalled(style_id)) {
m_styleGsettings = new QGSettings(style_id);
connect(m_styleGsettings, &QGSettings::changed, this, &InfoButton::onGSettingChaned);
} else {
qDebug() << "Gsettings interface \"org.ukui.style\" is not exist!";
}
}
void InfoButton::initUI()
{
this->setFixedSize(BUTTON_SIZE);
m_backgroundColor = BACKGROUND_COLOR;
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
}
void InfoButton::onGSettingChaned(const QString &key)
{
if (key == COLOR_THEME) {
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
this->repaint();
}
}
void InfoButton::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
pal.setColor(QPalette::Base, m_backgroundColor);
pal.setColor(QPalette::Text, m_foregroundColor);
QPainterPath cPath;
cPath.addRect(0, 0, ICON_SIZE);
cPath.addEllipse(0, 0, ICON_SIZE);
QPainterPath outerPath;
outerPath.addEllipse(OUTER_PATH);
QPainterPath innerPath;
innerPath.addEllipse(INNER_PATH);
outerPath -= innerPath;
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
painter.setBrush(pal.color(QPalette::Base));
painter.drawPath(cPath);
painter.fillPath(outerPath, pal.color(QPalette::Text));
painter.setPen(m_foregroundColor);
QFont font("Noto Sans CJK SC", 11, QFont::Normal, false);
painter.setFont(font);
painter.drawText(TEXT_POS, "i");
}
void InfoButton::enterEvent(QEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_HOVER;
this->repaint();
}
void InfoButton::leaveEvent(QEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
this->repaint();
}
void InfoButton::mousePressEvent(QMouseEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_PRESS;
this->repaint();
return QPushButton::mousePressEvent(event);
}
void InfoButton::mouseReleaseEvent(QMouseEvent *event)
{
m_foregroundColor = FOREGROUND_COLOR_HOVER;
this->repaint();
return QPushButton::mouseReleaseEvent(event);
}

View File

@ -0,0 +1,35 @@
#ifndef INFOBUTTON_H
#define INFOBUTTON_H
#include <QPushButton>
#include <QIcon>
#include <QGSettings>
class InfoButton : public QPushButton
{
Q_OBJECT
public:
explicit InfoButton(QWidget * parent = nullptr);
~InfoButton() = default;
protected:
void paintEvent(QPaintEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
void initUI();
private:
QColor m_backgroundColor;
QColor m_foregroundColor;
//监听主题的Gsettings
QGSettings * m_styleGsettings = nullptr;
private Q_SLOTS:
void onGSettingChaned(const QString &key);
};
#endif // INFOBUTTON_H

View File

@ -0,0 +1,327 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "switchbutton.h"
#include <QDebug>
#define THEME_QT_SCHEMA "org.ukui.style"
#define THEME_GTK_SCHEMA "org.mate.interface"
#define TIMER_INTERVAL 5 //每隔5ms动画移动一次
#define MOVING_STEPS 40 //动画总共移动40次
SwitchButton::SwitchButton(QWidget *parent, bool useDisableStyle) :
QWidget(parent)
{
// this->resize(QSize(52, 24));
this->setFixedSize(QSize(50, 24));
checked = false;
hover = false;
disabled = false;
isMoving = false;
isAnimation = true;
m_useDisableStyle = useDisableStyle;
space = 4;
rectRadius = height()/2;
mStep = width()/MOVING_STEPS;//也就是40次动画就可以走完每次时间间隔是固定的5ms
mStartX = 0;
mEndX= 0;
mTimer = new QTimer(this);
mTimer->setInterval(TIMER_INTERVAL);//动画更新时间
connect(mTimer, SIGNAL(timeout()), this, SLOT(updatevalue()));
if(QGSettings::isSchemaInstalled(THEME_GTK_SCHEMA) && QGSettings::isSchemaInstalled(THEME_QT_SCHEMA)) {
QByteArray qtThemeID(THEME_QT_SCHEMA);
QByteArray gtkThemeID(THEME_GTK_SCHEMA);
m_gtkThemeSetting = new QGSettings(gtkThemeID,QByteArray(),this);
m_qtThemeSetting = new QGSettings(qtThemeID,QByteArray(),this);
QString style = m_qtThemeSetting->get("styleName").toString();
changeColor(style);
connect(m_qtThemeSetting,&QGSettings::changed, [this] (const QString &key) {
QString style = m_qtThemeSetting->get("styleName").toString();
if (key == "styleName") {
changeColor(style);
}
});
}
}
SwitchButton::~SwitchButton()
{
}
void SwitchButton::paintEvent(QPaintEvent *){
QPainter painter(this);
//启用反锯齿
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setCompositionMode(QPainter::CompositionMode_Source);
drawBg(&painter);
if(!isAnimation)//动画如果禁用则圆形滑块isMoving始终为false
isMoving =false;
if(isMoving)
animation(&painter);
drawSlider(&painter);
painter.end();
}
void SwitchButton::changeColor(const QString &themes) {
if (hover) {
return ;//在鼠标下,禁止切换颜色鼠标离开时切换颜色
}
if (themes == "ukui-dark" || themes == "ukui-black") {
bgColorOff = QColor(OFF_BG_DARK_COLOR);
bgColorOn = QColor(ON_BG_DARK_COLOR);
rectColorEnabled = QColor(ENABLE_RECT_DARK_COLOR);
rectColorDisabled = QColor(DISABLE_RECT_DARK_COLOR);
sliderColorDisabled = QColor(DISABLE_RECT_DARK_COLOR);
sliderColorEnabled = QColor(ENABLE_RECT_DARK_COLOR);
bgHoverOnColor = QColor(ON_HOVER_BG_DARK_COLOR);
bgHoverOffColor = QColor(OFF_HOVER_BG_DARK_COLOR);
bgColorDisabled = QColor(DISABLE_DARK_COLOR);
} else {
bgColorOff = QColor(OFF_BG_LIGHT_COLOR);
bgColorOn = QColor(ON_BG_LIGHT_COLOR);
rectColorEnabled = QColor(ENABLE_RECT_LIGHT_COLOR);
rectColorDisabled = QColor(DISABLE_RECT_LIGHT_COLOR);
sliderColorDisabled = QColor(DISABLE_RECT_LIGHT_COLOR);
sliderColorEnabled = QColor(ENABLE_RECT_LIGHT_COLOR);
bgHoverOnColor = QColor(ON_HOVER_BG_LIGHT_COLOR);
bgHoverOffColor = QColor(OFF_HOVER_BG_LIGHT_COLOR);
bgColorDisabled = QColor(DISABLE_LIGHT_COLOR);
}
}
//动画绘制
void SwitchButton::animation(QPainter *painter){
painter->save();
int h = height();
int w = width();
painter->setPen(Qt::NoPen);
//颜色设置
if(checked){
//开关在左侧时
painter->setBrush(bgColorOn);
rect.setRect(0,0,h+mStartX,h);
}else{
painter->setBrush(bgColorOff);
rect.setRect(mStartX,0,w-mStartX,h);
}
painter->drawRoundedRect(rect,rectRadius,rectRadius);
painter->restore();
}
//绘制背景
void SwitchButton::drawBg(QPainter *painter){
int w = width();
int h = height();
painter->save();
painter->setPen(Qt::NoPen);
if (disabled && m_useDisableStyle) {
painter->setPen(Qt::NoPen);
painter->setBrush(bgColorDisabled);
} else {
if(checked){
if(isMoving){
painter->setBrush(bgColorOff);
rect.setRect(mStartX,0,w-mStartX,h);
}else {
painter->setBrush(bgColorOn);
rect.setRect(0, 0, w, h);
}
}else{
if(isMoving){
painter->setBrush(bgColorOn);
rect.setRect(0,0,mStartX+h,h);
}
else {
painter->setBrush(bgColorOff);
rect.setRect(0, 0, w, h);
}
}
}
//半径为高度的一半
painter->drawRoundedRect(rect,rectRadius,rectRadius);
painter->restore();
}
//绘制滑块,也就是圆形按钮
void SwitchButton::drawSlider(QPainter *painter){
painter->save();
painter->setPen(Qt::NoPen);
if (!disabled || !m_useDisableStyle){
painter->setBrush(sliderColorEnabled);
}
else
painter->setBrush(sliderColorDisabled);
if (disabled) {
if (!checked){
QRect smallRect(8, height() / 2 - 2, 10 , 4);
painter->drawRoundedRect(smallRect,3,3);
}else{
QRect smallRect(width() - 8 * 2, height() / 2 - 2, 10 , 4);
painter->drawRoundedRect(smallRect,3,3);
}
}
QRect rect(0, 0, width(), height());
int sliderWidth = rect.height() - space * 2;
QRect sliderRect(mStartX + space, space, sliderWidth, sliderWidth);
painter->drawEllipse(sliderRect);
painter->restore();
}
void SwitchButton::mousePressEvent(QMouseEvent *){
qDebug()<<isMoving<<checked<<disabled;
if (isMoving) {
return ;
}
if(disabled){
mEndX = 0;
Q_EMIT disabledClick();
return ;
}else{
checked = !checked;
Q_EMIT checkedChanged(checked);
mStep = width() / MOVING_STEPS;
if (checked){
//circle out
// endX = width() - height() + space;
//circle in
mEndX = width() - height();
}
else {
mEndX = 0;
}
mTimer->start();
isMoving = true;
}
}
void SwitchButton::resizeEvent(QResizeEvent *){
//每次开始的x坐标都是跳过圆角从直线的地方开始计算
mStep = width() / MOVING_STEPS;
if (checked){
//circle out
// startX = width() - height() + space;
//circle in
mStartX = width() - height();
}
else
mStartX = 0;
rectRadius = height()/2;
update();
}
void SwitchButton::enterEvent(QEvent *event) {
bgColorOn = bgHoverOnColor;
bgColorOff = bgHoverOffColor;
hover = true;
update();
return QWidget::enterEvent(event);
}
void SwitchButton::leaveEvent(QEvent *event) {
hover = false;
QString style = m_qtThemeSetting->get("styleName").toString();
changeColor(style);
update();
return QWidget::leaveEvent(event);
}
//根据事件向左还是向右移动
void SwitchButton::updatevalue(){
if (checked)
if (mStartX < mEndX-mStep){
mStartX = mStartX + mStep;
}
else{
mStartX = mEndX;
mTimer->stop();
isMoving = false;
}
else{
if (mStartX > mEndX+mStep){
mStartX = mStartX - mStep;
}
else{
mStartX = mEndX;
mTimer->stop();
isMoving = false;
}
}
update();
}
void SwitchButton::setChecked(bool checked){
if (this->checked != checked){
this->checked = checked;
Q_EMIT checkedChanged(checked);
update();
}
mStep = width() / MOVING_STEPS;
if (checked){
//circle out
// endX = width() - height() + space;
//circle in
mEndX = width() - height();
}
else{
mEndX = 0;
}
mTimer->start();
isMoving = true;
}
bool SwitchButton::isChecked(){
return this->checked;
}
void SwitchButton::setDisabledFlag(bool value)
{
disabled = value;
update();
}
bool SwitchButton::getDisabledFlag()
{
return disabled;
}
void SwitchButton::setAnimation(bool on){
isAnimation = on;
}

View File

@ -0,0 +1,121 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef SWITCHBUTTON_H
#define SWITCHBUTTON_H
#include <QWidget>
#include <QTimer>
#include <QPainter>
#include <QPainterPath>
#include <QEvent>
#include <QGSettings/QGSettings>
#define OFF_BG_DARK_COLOR "#404040"
#define OFF_HOVER_BG_DARK_COLOR "#666666"
#define ON_BG_DARK_COLOR "#3790FA"
#define ON_HOVER_BG_DARK_COLOR "#40A9FB"
#define DISABLE_DARK_COLOR "#474747"
#define DISABLE_RECT_DARK_COLOR "#6E6E6E"
#define ENABLE_RECT_DARK_COLOR "#FFFFFF"
#define OFF_BG_LIGHT_COLOR "#E0E0E0"
#define OFF_HOVER_BG_LIGHT_COLOR "#B3B3B3"
#define ON_BG_LIGHT_COLOR "#3790FA"
#define ON_HOVER_BG_LIGHT_COLOR "#40A9FB"
#define DISABLE_LIGHT_COLOR "#E9E9E9"
#define DISABLE_RECT_LIGHT_COLOR "#B3B3B3"
#define ENABLE_RECT_LIGHT_COLOR "#FFFFFF"
class SwitchButton : public QWidget
{
Q_OBJECT
public:
SwitchButton(QWidget *parent = 0, bool useDisableStyle = true);
~SwitchButton();
void setChecked(bool checked);
void setAnimation(bool on);
bool isChecked();
void setDisabledFlag(bool);
bool getDisabledFlag();
protected:
void mousePressEvent(QMouseEvent *);
void resizeEvent(QResizeEvent *);
void paintEvent(QPaintEvent *);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void drawBg(QPainter * painter);
void drawSlider(QPainter * painter);
void changeColor(const QString &themes);
private:
bool checked; //切换的判断
bool disabled;
void animation(QPainter *painter);
QRect rect;
bool isMoving; //滑块动作判断
bool isAnimation; // 是否允许动画执行
QColor bgColorOff;
QColor bgColorOn;
QColor bgHoverOnColor;
QColor bgHoverOffColor;
QColor bgColorDisabled;
QColor sliderColorEnabled;
QColor sliderColorDisabled;
QColor rectColorEnabled;
QColor rectColorDisabled;
QColor sliderColorOff;
QColor sliderColorOn;
QGSettings *m_qtThemeSetting;
QGSettings *m_gtkThemeSetting;
int space; //滑块离背景间隔
int rectRadius; //圆角角度
int mStep; //移动步长
int mStartX;
int mEndX;
bool hover;
QTimer * mTimer;
bool m_useDisableStyle;
private Q_SLOTS:
void updatevalue();
Q_SIGNALS:
void checkedChanged(bool checked);
void disabledClick();
};
#endif // SWITCHBUTTON_H

View File

@ -0,0 +1,8 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(divider)
SOURCES += \
$$PWD/DeviceFrame/deviceframe.cpp \
HEADERS += \
$$PWD/DeviceFrame/deviceframe.h \

View File

@ -0,0 +1,9 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(drownlabel)
SOURCES += \
$$PWD/Divider/divider.cpp \
HEADERS += \
$$PWD/Divider/divider.h \

View File

@ -0,0 +1,9 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(drownlabel)
SOURCES += \
$$PWD/DrownLabel/drownlabel.cpp \
HEADERS += \
$$PWD/DrownLabel/drownlabel.h \

View File

@ -0,0 +1,9 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(infobutton)
SOURCES += \
$$PWD/InfoButton/infobutton.cpp \
HEADERS += \
$$PWD/InfoButton/infobutton.h \

View File

@ -0,0 +1,8 @@
#LIBINTERFACE_NAME = $$qtLibraryTarget(divider)
SOURCES += \
$$PWD/Divider/divider.cpp \
HEADERS += \
$$PWD/Divider/divider.h \

View File

@ -0,0 +1,155 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "mobilehotspot.h"
#include <QDebug>
MobileHotspot::MobileHotspot() : mFirstLoad(true) {
QTranslator* translator = new QTranslator(this);
qDebug() << "/usr/share/kylin-nm/mobilehotspot/" + QLocale::system().name();
if (!translator->load("/usr/share/kylin-nm/mobilehotspot/" + QLocale::system().name())) {
qDebug() << "load failed";
}
QApplication::installTranslator(translator);
pluginName = tr("MobileHotspot");
qDebug() << pluginName;
pluginType = NETWORK;
qDBusRegisterMetaType<QMap<QString, bool> >();
qDBusRegisterMetaType<QMap<QString, int> >();
needLoad = isExitWirelessDevice();
}
MobileHotspot::~MobileHotspot()
{
if (!mFirstLoad) {
// delete pluginWidget;
// pluginWidget = nullptr;
}
}
QString MobileHotspot::plugini18nName() {
return pluginName;
}
int MobileHotspot::pluginTypes() {
return pluginType;
}
QWidget *MobileHotspot::pluginUi() {
if (mFirstLoad) {
mFirstLoad = false;
pluginWidget = new MobileHotspotWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
}
return pluginWidget;
}
const QString MobileHotspot::name() const {
return QStringLiteral("mobilehotspot");
}
bool MobileHotspot::isEnable() const
{
qDebug() << needLoad;
return needLoad;
}
bool MobileHotspot::isShowOnHomePage() const
{
return false;
}
QIcon MobileHotspot::icon() const
{
return QIcon();
}
QString MobileHotspot::translationPath() const
{
return "/usr/share/kylin-nm/mobilehotspot/%1.ts";
}
void MobileHotspot::initSearchText()
{
//~ contents_path /mobilehotspot/mobilehotspot
tr("mobilehotspot");
//~ contents_path /mobilehotspot/mobilehotspot open
tr("mobilehotspot open");
}
bool MobileHotspot::isExitWirelessDevice()
{
QDBusInterface *interface = new QDBusInterface("com.kylin.network", "/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if (!interface->isValid()) {
qDebug() << "/com/kylin/network is invalid";
return false;
}
QDBusMessage result = interface->call(QStringLiteral("getDeviceListAndEnabled"),1);
if(result.type() == QDBusMessage::ErrorMessage) {
qWarning() << "getWirelessDeviceList error:" << result.errorMessage();
return false;
}
auto dbusArg = result.arguments().at(0).value<QDBusArgument>();
QMap<QString, bool> deviceListMap;
dbusArg >> deviceListMap;
QDBusReply<QMap<QString, int> > capReply = interface->call("getWirelessDeviceCap");
if (!capReply.isValid()) {
qDebug()<<"execute dbus method 'getWirelessDeviceCap' is invalid in func initInterfaceInfo()" <<capReply.error().type() ;
return false;
}
QMap<QString, int> devCapMap = capReply.value();
if (deviceListMap.isEmpty()) {
qDebug() << "no wireless device";
return false;
} else {
QMap<QString, bool>::Iterator iter = deviceListMap.begin();
while (iter != deviceListMap.end()) {
QString interfaceName = iter.key();
if (!devCapMap.contains(interfaceName)) {
iter++;
continue;
}
if (deviceListMap[interfaceName] & 0x01) {
qDebug() << "wireless device" << interfaceName << "support hotspot";
return true;
}
iter++;
}
}
qDebug() << "no wireless device support hotspot";
return false;
}

View File

@ -0,0 +1,78 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef MOBILEHOTSPOT_H
#define MOBILEHOTSPOT_H
#include <QObject>
#include <QtPlugin>
#include <QTranslator>
#include <QApplication>
#include <QDBusMessage>
#include <QDBusObjectPath>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDBusMetaType>
#include "interface.h"
#include "switchbutton.h"
#include "hoverbtn.h"
#include "mobilehotspotwidget.h"
namespace Ui {
class MobileHotspot;
}
class MobileHotspot : public QObject, CommonInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface")
Q_INTERFACES(CommonInterface)
public:
MobileHotspot();
~MobileHotspot();
QString plugini18nName() Q_DECL_OVERRIDE;
int pluginTypes() Q_DECL_OVERRIDE;
QWidget * pluginUi() Q_DECL_OVERRIDE;
const QString name() const Q_DECL_OVERRIDE;
bool isShowOnHomePage() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
bool isEnable() const Q_DECL_OVERRIDE;
QString translationPath() const Q_DECL_OVERRIDE;
private:
void initSearchText();
bool isExitWirelessDevice();
QString pluginName;
int pluginType;
MobileHotspotWidget *pluginWidget;
private:
bool mFirstLoad;
bool needLoad;
};
#endif // MOBILEHOTSPOT_H

View File

@ -0,0 +1,42 @@
QT += widgets network dbus gui core
TEMPLATE = lib
CONFIG += plugin
TARGET = $$qtLibraryTarget(mobilehotspot)
DESTDIR = ../..
target.path = $$[QT_INSTALL_LIBS]/ukui-control-center
trans.files = translations/*
trans.path = /usr/share/kylin-nm/mobilehotspot/
INCLUDEPATH += \
$$PROJECT_COMPONENTSOURCE \
$$PROJECT_ROOTDIR \
/usr/include/ukcc/interface \
/usr/include/ukcc/widgets
LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt -lukcc
CONFIG += c++11 \
link_pkgconfig \
PKGCONFIG += gsettings-qt \
#DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
mobilehotspot.cpp \
mobilehotspotwidget.cpp
HEADERS += \
mobilehotspot.h \
mobilehotspotwidget.h \
libukcc_global.h
INSTALLS += target \
trans
TRANSLATIONS += \
translations/zh_CN.ts \
translations/tr.ts \
translations/bo.ts

View File

@ -0,0 +1,676 @@
#include "mobilehotspotwidget.h"
#include <QDebug>
#define LABEL_RECT 17, 0, 105, 23
#define CONTENTS_MARGINS 0, 0, 0, 0
#define FRAME_MIN_SIZE 550, 60
#define FRAME_MAX_SIZE 16777215, 16777215
#define CONTECT_FRAME_MAX_SIZE 16777215, 60
#define LABLE_MIN_WIDTH 140
#define COMBOBOX_MIN_WIDTH 200
#define LINE_MAX_SIZE 16777215, 1
#define LINE_MIN_SIZE 0, 1
#define LAYOUT_LEFT_MARGINS 8
#define WIRELESS 1
#define AP_NAME_MAX_LENGTH 32
const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch";
const QString WIRELESS_SWITCH = "wirelessswitch";
void MobileHotspotWidget::showDesktopNotify(const QString &message)
{
QDBusInterface iface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
QDBusConnection::sessionBus());
QList<QVariant> args;
args<<(tr("ukui control center"))
<<((unsigned int) 0)
<<QString("/usr/share/icons/ukui-icon-theme-default/24x24/devices/gnome-dev-ethernet.png")
<<tr("ukui control center desktop message") //显示的是什么类型的信息
<<message //显示的具体信息
<<QStringList()
<<QVariantMap()
<<(int)-1;
iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args);
}
MobileHotspotWidget::MobileHotspotWidget(QWidget *parent) : QWidget(parent)
{
mVlayout = new QVBoxLayout(this);
mVlayout->setContentsMargins(CONTENTS_MARGINS);
qDBusRegisterMetaType<QMap<QString, bool> >();
qDBusRegisterMetaType<QMap<QString, int> >();
qDBusRegisterMetaType<QVector<QStringList> >();
qDBusRegisterMetaType<QMap<QString, QVector<QStringList> >>();
initUI();
m_switchBtn->installEventFilter(this);
m_interface = new QDBusInterface("com.kylin.network", "/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if(!m_interface->isValid()) {
qDebug() << "dbus interface com.kylin.network is invaild";
m_switchBtn->setChecked(false);
setUiEnabled(false);
}
m_hostName = getHostName();
initDbusConnect();
initInterfaceInfo();
getApInfo();
connect(m_switchBtn, &SwitchButton::checkedChanged, this, &MobileHotspotWidget::setUiEnabled);
connect(m_interfaceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=]() {
m_interfaceName = m_interfaceComboBox->currentText();
updateBandCombox();
});
connect(m_pwdShowBox, &QCheckBox::clicked, this, [=]() {
if (m_pwdNameLine->echoMode() == QLineEdit::Password) {
m_pwdNameLine->setEchoMode(QLineEdit::Normal);
} else {
m_pwdNameLine->setEchoMode(QLineEdit::Password);
}
});
}
MobileHotspotWidget::~MobileHotspotWidget()
{
delete m_interface;
}
bool MobileHotspotWidget::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseButtonDblClick && watched == m_switchBtn) {
return true;
}
if (event->type() == QEvent::MouseButtonPress) {
if (watched == m_switchBtn) {
if (!m_interface->isValid()) {
return true;
}
if (m_switchBtn->getDisabledFlag()) {
showDesktopNotify(tr("wirless switch is close or no wireless device"));
return true;
}
if (m_switchBtn->isChecked()) {
showDesktopNotify(tr("start to close hotspot"));
QDBusReply<void> reply = m_interface->call("deactiveWirelessAp", m_apNameLine->text(), m_uuid);
if (!reply.isValid()) {
qDebug() << "[MobileHotspotWidget] call deactiveWirelessAp failed ";
return true;
}
} else {
if (m_apNameLine->text().isEmpty() || m_interfaceName.isEmpty())
{
showDesktopNotify(tr("hotpots name or device is invalid"));
return true;
}
if (m_pwdNameLine->text().length() < 8) {
showDesktopNotify(tr("can not create hotspot with password length less than eight!"));
return true;
}
showDesktopNotify(tr("start to open hotspot ") + m_apNameLine->text());
QDBusReply<void> reply = m_interface->call("activeWirelessAp",
m_apNameLine->text(),
m_pwdNameLine->text(),
m_freqBandComboBox->currentText(),
m_interfaceComboBox->currentText());
if (!reply.isValid()) {
qDebug() << "[MobileHotspotWidget] call deactiveWirelessAp failed ";
return true;
}
}
return true;
}
}
return QWidget::eventFilter(watched, event);
}
void MobileHotspotWidget::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
}
void MobileHotspotWidget::initUI()
{
QFrame *hotspotFrame = new QFrame(this);
hotspotFrame->setMinimumSize(FRAME_MIN_SIZE);
hotspotFrame->setMaximumSize(FRAME_MAX_SIZE);
hotspotFrame->setFrameShape(QFrame::Box);
QVBoxLayout *hotspotLyt = new QVBoxLayout(hotspotFrame);
hotspotLyt->setContentsMargins(0, 0, 0, 0);
m_hotspotTitleLabel = new TitleLabel(this);
m_hotspotTitleLabel->setText(tr("Hotspot"));
setSwitchFrame();
setApNameFrame();
setPasswordFrame();
setFreqBandFrame();
setInterFaceFrame();
switchAndApNameLine = myLine();
apNameAndPwdLine = myLine();
pwdAndfreqBandLine = myLine();
freqBandAndInterfaceLine = myLine();
/* add widget */
hotspotLyt->addWidget(m_switchFrame);
hotspotLyt->addWidget(switchAndApNameLine);
hotspotLyt->addWidget(m_ApNameFrame);
hotspotLyt->addWidget(apNameAndPwdLine);
hotspotLyt->addWidget(m_passwordFrame);
hotspotLyt->addWidget(pwdAndfreqBandLine);
hotspotLyt->addWidget(m_freqBandFrame);
hotspotLyt->addWidget(freqBandAndInterfaceLine);
hotspotLyt->addWidget(m_interfaceFrame);
hotspotLyt->setSpacing(0);
mVlayout->addWidget(m_hotspotTitleLabel);
mVlayout->setSpacing(8);
mVlayout->addWidget(hotspotFrame);
mVlayout->addStretch();
}
void MobileHotspotWidget::initDbusConnect()
{
if(m_interface->isValid()) {
connect(m_interface,SIGNAL(activateFailed(QString)), this, SLOT(onActivateFailed(QString)), Qt::QueuedConnection);
connect(m_interface,SIGNAL(deactivateFailed(QString)), this, SLOT(onDeactivateFailed(QString)), Qt::QueuedConnection);
connect(m_interface,SIGNAL(deviceStatusChanged()), this, SLOT(onDeviceStatusChanged()), Qt::QueuedConnection);
connect(m_interface,SIGNAL(deviceNameChanged(QString, QString, int)), this, SLOT(onDeviceNameChanged(QString, QString, int)), Qt::QueuedConnection);
connect(m_interface,SIGNAL(hotspotDeactivated(QString, QString)), this, SLOT(onHotspotDeactivated(QString, QString)), Qt::QueuedConnection);
connect(m_interface,SIGNAL(hotspotActivated(QString, QString, QString)), this, SLOT(onHotspotActivated(QString, QString, QString)), Qt::QueuedConnection);
connect(m_interface, SIGNAL(wlanactiveConnectionStateChanged(QString, QString, QString, int)), this, SLOT(onActiveConnectionChanged(QString, QString, QString, int)), Qt::QueuedConnection);
}
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
onGsettingChanged(WIRELESS_SWITCH);
connect(m_switchGsettings, &QGSettings::changed, this, &MobileHotspotWidget::onGsettingChanged, Qt::QueuedConnection);
}
connect(m_apNameLine, &QLineEdit::textEdited, this, &MobileHotspotWidget::onApLineEditTextEdit);
}
void MobileHotspotWidget::onApLineEditTextEdit(QString text)
{
int count = 0;
int i = 0;
for ( ; i < text.length(); ++i) {
count += text.mid(i,1).toLocal8Bit().length();
if (count > AP_NAME_MAX_LENGTH) {
break;
}
}
m_apNameLine->setText(text.left(i));
}
void MobileHotspotWidget::onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, int status)
{
if(m_uuid == uuid && status == 4) {
showDesktopNotify(tr("hotspot already close"));
m_switchBtn->setChecked(false);
setUiEnabled(false);
m_uuid.clear();
}
}
void MobileHotspotWidget::onGsettingChanged(const QString &key)
{
if (key == WIRELESS_SWITCH) {
bool status = m_switchGsettings->get(WIRELESS_SWITCH).toBool();
if (!status) {
// if (m_switchBtn->isChecked()) {
// if(m_interface->isValid()) {
// QDBusReply<void> reply = m_interface->call("deactiveWirelessAp",
// m_apNameLine->text(),
// m_pwdNameLine->text(),
// m_interfaceComboBox->currentText());
// if (!reply.isValid()) {
// qDebug() << "[MobileHotspotWidget] call deactiveWirelessAp failed ";
// return true;
// }
// }
// }
m_switchBtn->setChecked(status);
m_uuid.clear();
m_switchBtn->setDisabledFlag(true);
} else {
m_switchBtn->setDisabledFlag(false);
}
}
}
void MobileHotspotWidget::initInterfaceInfo()
{
if(!m_interface->isValid()) {
return;
}
m_interfaceComboBox->clear();
QDBusReply<QMap<QString, bool> > reply = m_interface->call("getDeviceListAndEnabled",WIRELESS);
if (!reply.isValid()) {
qDebug()<<"execute dbus method 'getDeviceListAndEnabled' is invalid in func initInterfaceInfo()";
setWidgetHidden(true);
return;
}
QMap<QString, bool> devMap = reply.value();
QDBusReply<QMap<QString, int> > capReply = m_interface->call("getWirelessDeviceCap");
if (!capReply.isValid()) {
qDebug()<<"execute dbus method 'getWirelessDeviceCap' is invalid in func initInterfaceInfo()" <<capReply.error().type() ;
setWidgetHidden(true);
return;
}
QMap<QString, int> devCapMap = capReply.value();
if (devMap.isEmpty()) {
qDebug() << "no wireless device";
setWidgetHidden(true);
m_switchBtn->setDisabledFlag(true);
} else {
QMap<QString, bool>::Iterator iter = devMap.begin();
while (iter != devMap.end()) {
QString interfaceName = iter.key();
if (devCapMap[interfaceName] & 0x01) {
m_interfaceComboBox->addItem(interfaceName);
}
iter++;
}
if (m_interfaceComboBox->count() > 0) {
setWidgetHidden(false);
m_interfaceName = m_interfaceComboBox->currentText();
if (m_interfaceComboBox->count() == 1) {
updateBandCombox();
}
} else {
qDebug() << "no useable wireless device";
setWidgetHidden(true);
}
}
}
void MobileHotspotWidget::getApInfo()
{
if (!m_interface->isValid()) {
return;
}
if (m_interfaceComboBox->count() <= 0) {
m_switchBtn->setChecked(false);
setWidgetHidden(true);
qWarning() << "getApInfo but interface is empty";
return;
}
QDBusReply<QStringList> reply = m_interface->call("getStoredApInfo");
if (!reply.isValid()) {
qDebug()<<"execute dbus method 'getStoredApInfo' is invalid in func getObjectPath()";
}
QStringList apInfo = reply.value();
if (apInfo.isEmpty()) {
qDebug() << "no stored hotspot info";
m_apNameLine->setText(m_hostName);
m_pwdNameLine->setText("12345678");
return;
} else {
int index = m_interfaceComboBox->findText(apInfo.at(2));
if (index >= 0) {
m_apNameLine->setText(apInfo.at(0));
m_pwdNameLine->setText(apInfo.at(1));
m_interfaceComboBox->setCurrentIndex(index);
m_interfaceName = apInfo.at(2);
if (apInfo.at(3) == "true") {
m_switchBtn->setChecked(true);
setUiEnabled(true);
m_uuid = apInfo.at(4);
} else {
m_switchBtn->setChecked(false);
setUiEnabled(false);
}
} else {
qDebug() << "no such interface " << apInfo.at(2);
}
}
}
void MobileHotspotWidget::setSwitchFrame()
{
/* Open */
m_switchFrame = new QFrame(this);
m_switchFrame->setFrameShape(QFrame::Shape::NoFrame);
m_switchFrame->setMinimumSize(FRAME_MIN_SIZE);
m_switchFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
QHBoxLayout *switchLayout = new QHBoxLayout();
m_switchLabel = new QLabel(tr("Open"), this);
m_switchLabel->setMinimumWidth(LABLE_MIN_WIDTH);
m_switchBtn = new SwitchButton(this);
switchLayout->addSpacing(LAYOUT_LEFT_MARGINS);
switchLayout->addWidget(m_switchLabel);
switchLayout->addStretch();
switchLayout->addWidget(m_switchBtn);
m_switchFrame->setLayout(switchLayout);
}
void MobileHotspotWidget::setApNameFrame()
{
/* ApName */
m_ApNameFrame = new QFrame(this);
m_ApNameFrame->setFrameShape(QFrame::Shape::NoFrame);
m_ApNameFrame->setMinimumSize(FRAME_MIN_SIZE);
m_ApNameFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
QHBoxLayout *apNameHLayout = new QHBoxLayout();
m_apNameLabel = new QLabel(tr("Wi-Fi Name"), this);
m_apNameLabel->setMinimumWidth(LABLE_MIN_WIDTH);
m_apNameLine = new QLineEdit(this);
m_apNameLine->setMinimumWidth(COMBOBOX_MIN_WIDTH);
m_apNameLine->setMaxLength(AP_NAME_MAX_LENGTH);
apNameHLayout->addSpacing(LAYOUT_LEFT_MARGINS);
apNameHLayout->addWidget(m_apNameLabel);
apNameHLayout->addWidget(m_apNameLine);
m_ApNameFrame->setLayout(apNameHLayout);
}
void MobileHotspotWidget::setPasswordFrame()
{
/* Password */
m_passwordFrame = new QFrame(this);
m_passwordFrame->setFrameShape(QFrame::Shape::NoFrame);
m_passwordFrame->setMinimumSize(FRAME_MIN_SIZE);
m_passwordFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
QHBoxLayout *passwordHLayout = new QHBoxLayout();
m_pwdLabel = new QLabel(tr("Password"), this);
m_pwdLabel->setMinimumWidth(LABLE_MIN_WIDTH);
m_pwdNameLine = new QLineEdit(this);
m_pwdNameLine->setMinimumWidth(COMBOBOX_MIN_WIDTH);
m_pwdNameLine->setEchoMode(QLineEdit::Password);
passwordHLayout->addSpacing(LAYOUT_LEFT_MARGINS);
passwordHLayout->addWidget(m_pwdLabel);
passwordHLayout->addWidget(m_pwdNameLine);
m_passwordFrame->setLayout(passwordHLayout);
m_pwdShowBox = new QCheckBox(this);
m_pwdShowBox->setStyleSheet("QCheckBox::indicator {width: 18px; height: 9px;}"
"QCheckBox::indicator:checked {image: url(:/img/plugins/mobilehotspot/show-pwd.png);}"
"QCheckBox::indicator:unchecked {image: url(:/img/plugins/mobilehotspot/hide-pwd.png);}");
m_pwdShowBox->setCursor(Qt::PointingHandCursor);
m_pwdShowBox->setFixedSize(30, m_pwdNameLine->height());
//防止文本框输入内容位于按钮之下
QMargins margins = m_pwdNameLine->textMargins();
m_pwdNameLine->setTextMargins(margins.left(), margins.top(), m_pwdShowBox->width(), margins.bottom());
QHBoxLayout *pSearchLayout = new QHBoxLayout();
pSearchLayout->addStretch();
pSearchLayout->addWidget(m_pwdShowBox);
pSearchLayout->setSpacing(0);
pSearchLayout->setContentsMargins(0, 0, 0, 0);
m_pwdNameLine->setLayout(pSearchLayout);
m_pwdNameLine->setEchoMode(QLineEdit::Password);
}
void MobileHotspotWidget::setFreqBandFrame()
{
/* frequency band */
m_freqBandFrame = new QFrame(this);
m_freqBandFrame->setFrameShape(QFrame::Shape::NoFrame);
m_freqBandFrame->setMinimumSize(FRAME_MIN_SIZE);
m_freqBandFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
QHBoxLayout *freqBandHLayout = new QHBoxLayout();
m_freqBandLabel = new QLabel(tr("Frequency band"), this);
m_freqBandLabel->setMinimumWidth(LABLE_MIN_WIDTH);
m_freqBandComboBox = new QComboBox(this);
m_freqBandComboBox->setInsertPolicy(QComboBox::NoInsert);
m_freqBandComboBox->setMinimumWidth(COMBOBOX_MIN_WIDTH);
m_freqBandComboBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
m_freqBandComboBox->addItem("2.4Ghz");
m_freqBandComboBox->addItem("5Ghz");
freqBandHLayout->addSpacing(LAYOUT_LEFT_MARGINS);
freqBandHLayout->addWidget(m_freqBandLabel);
freqBandHLayout->addWidget(m_freqBandComboBox);
m_freqBandFrame->setLayout(freqBandHLayout);
}
void MobileHotspotWidget::setInterFaceFrame()
{
/* key tips */
m_interfaceFrame = new QFrame(this);
m_interfaceFrame->setFrameShape(QFrame::Shape::NoFrame);
m_interfaceFrame->setMinimumSize(FRAME_MIN_SIZE);
m_interfaceFrame->setMaximumSize(CONTECT_FRAME_MAX_SIZE);
QHBoxLayout *interfaceHLayout = new QHBoxLayout;
m_interfaceLabel = new QLabel(tr("Net card"), this);
m_interfaceLabel->setMinimumWidth(LABLE_MIN_WIDTH);
m_interfaceComboBox = new QComboBox(this);
m_interfaceComboBox->setInsertPolicy(QComboBox::NoInsert);
m_interfaceComboBox->setMinimumWidth(COMBOBOX_MIN_WIDTH);
m_interfaceComboBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
interfaceHLayout->addSpacing(LAYOUT_LEFT_MARGINS);
interfaceHLayout->addWidget(m_interfaceLabel);
interfaceHLayout->addWidget(m_interfaceComboBox);
m_interfaceFrame->setLayout(interfaceHLayout);
}
void MobileHotspotWidget::onActivateFailed(QString errorMessage)
{
if (errorMessage.indexOf("hotspot")) {
//todo
// showDesktopNotify(errorMessage);
}
}
void MobileHotspotWidget::onDeactivateFailed(QString errorMessage)
{
if (errorMessage.indexOf("hotspot")) {
// showDesktopNotify(errorMessage);
}
}
//设备插拔
void MobileHotspotWidget::onDeviceStatusChanged()
{
initInterfaceInfo();
getApInfo();
}
void MobileHotspotWidget::onDeviceNameChanged(QString oldName, QString newName, int type)
{
if (WIRELESS != type) {
return;
}
int index = m_interfaceComboBox->findText(oldName);
if (index >= 0) {
m_interfaceComboBox->setItemText(index, newName);
if (m_interfaceName == oldName) {
m_interfaceName = newName;
}
}
}
//热点断开
void MobileHotspotWidget::onHotspotDeactivated(QString devName, QString ssid)
{
if (!m_switchBtn->isChecked()) {
return;
}
if (devName == m_interfaceComboBox->currentText() && ssid == m_apNameLine->text()) {
m_switchBtn->setChecked(false);
m_uuid.clear();
// setUiEnabled(true);
showDesktopNotify(tr("hotspot already close"));
}
}
//热点连接
void MobileHotspotWidget::onHotspotActivated(QString devName, QString ssid, QString uuid)
{
qDebug() << "onHotspotActivated" <<devName << ssid << uuid;
if (m_switchBtn->isChecked()) {
return;
}
if (devName == m_interfaceComboBox->currentText() && ssid == m_apNameLine->text()) {
m_switchBtn->setChecked(true);
m_uuid = uuid;
// setUiEnabled(false);
showDesktopNotify(tr("hotspot already open"));
} else {
QStringList info;
if (!getApInfoBySsid(devName, ssid, info)) {
return;
}
int index = m_interfaceComboBox->findText(devName);
if (index >= 0) {
showDesktopNotify(tr("hotspot already open"));
m_apNameLine->setText(ssid);
m_interfaceComboBox->setCurrentIndex(index);
m_switchBtn->setChecked(true);
m_switchBtn->setDisabledFlag(false);
m_pwdNameLine->setText(info.at(0));
m_interfaceName = devName;
updateBandCombox();
index = m_freqBandComboBox->findText(info.at(1));
if (index >= 0) {
m_freqBandComboBox->setCurrentIndex(index);
}
m_uuid = uuid;
} else {
qDebug() << "no such device in combo box";
}
}
}
bool MobileHotspotWidget::getApInfoBySsid(QString devName, QString ssid, QStringList &info)
{
info.clear();
if(!m_interface->isValid()) {
return false;
}
QDBusReply<QStringList> reply = m_interface->call("getApInfoBySsid", devName, ssid);
if (!reply.isValid()) {
qDebug()<<"execute dbus method 'getApInfoBySsid' is invalid in func getApInfoBySsid()";
}
info = reply.value();
if (info.size() != 2) {
return false;
} else {
return true;
}
}
void MobileHotspotWidget::setUiEnabled(bool enable)
{
qDebug() << "switch mode change to " << enable;
if (enable) {
m_pwdNameLine->setFocusPolicy(Qt::NoFocus);
m_freqBandComboBox->setEnabled(false);
m_interfaceComboBox->setEnabled(false);
m_apNameLine->setFocusPolicy(Qt::NoFocus);
} else {
m_pwdNameLine->setFocusPolicy(Qt::ClickFocus);
m_freqBandComboBox->setEnabled(true);
m_interfaceComboBox->setEnabled(true);
m_apNameLine->setFocusPolicy(Qt::ClickFocus);
}
}
void MobileHotspotWidget::setWidgetHidden(bool isHidden)
{
m_ApNameFrame->setHidden(isHidden);
m_passwordFrame->setHidden(isHidden);
m_freqBandFrame->setHidden(isHidden);
m_interfaceFrame->setHidden(isHidden);
switchAndApNameLine->setHidden(isHidden);
apNameAndPwdLine->setHidden(isHidden);
pwdAndfreqBandLine->setHidden(isHidden);
freqBandAndInterfaceLine->setHidden(isHidden);
if (isHidden) {
m_switchBtn->setChecked(false);
m_switchBtn->setDisabledFlag(true);
m_interfaceName = "";
m_uuid = "";
} else {
m_switchBtn->setDisabledFlag(false);
onGsettingChanged(WIRELESS_SWITCH);
}
}
void MobileHotspotWidget::updateBandCombox()
{
m_freqBandComboBox->clear();
QDBusReply<QMap<QString, int> > capReply = m_interface->call("getWirelessDeviceCap");
if (!capReply.isValid()) {
qDebug()<<"execute dbus method 'getWirelessDeviceCap' is invalid in func initInterfaceInfo()" << capReply.error().message();
setWidgetHidden(true);
return;
}
QMap<QString, int> devCapMap = capReply.value();
if (devCapMap[m_interfaceName] & 0x02) {
m_freqBandComboBox->addItem("2.4Ghz");
}
if (devCapMap[m_interfaceName] & 0x04) {
m_freqBandComboBox->addItem("5Ghz");
}
}
QFrame* MobileHotspotWidget::myLine()
{
QFrame *line = new QFrame(this);
line->setMinimumSize(QSize(LINE_MIN_SIZE));
line->setMaximumSize(QSize(LINE_MAX_SIZE));
line->setLineWidth(0);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
return line;
}
QString MobileHotspotWidget::getHostName()
{
int count = 0;
while (count < 3) {
QDBusInterface hostInterface("org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
"org.freedesktop.hostname1",
QDBusConnection::systemBus());
if (hostInterface.isValid()) {
return hostInterface.property("Hostname").value<QString>();
} else {
count++;
}
}
return "default";
}

View File

@ -0,0 +1,119 @@
#ifndef MOBILEHOTSPOTWIDGET_H
#define MOBILEHOTSPOTWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QHBoxLayout>
#include <QPushButton>
#include <QComboBox>
#include <QLineEdit>
#include <QCheckBox>
#include <QTranslator>
#include <QApplication>
#include <QDBusMessage>
#include <QDBusObjectPath>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDBusMetaType>
#include "switchbutton.h"
#include "titlelabel.h"
class MobileHotspotWidget : public QWidget
{
Q_OBJECT
public:
explicit MobileHotspotWidget(QWidget *parent = nullptr);
~MobileHotspotWidget();
private:
QFrame *m_switchFrame = nullptr; //开关
QFrame *m_ApNameFrame = nullptr; //wifi名称
QFrame *m_passwordFrame = nullptr; //密码
QFrame *m_freqBandFrame = nullptr; //频带
QFrame *m_interfaceFrame = nullptr; //网卡
SwitchButton *m_switchBtn;
TitleLabel *m_hotspotTitleLabel;
QLabel *m_switchLabel;
QLabel *m_apNameLabel;
QLabel *m_pwdLabel;
QLabel *m_freqBandLabel;
QLabel *m_interfaceLabel;
QCheckBox *m_pwdShowBox;
QFrame *switchAndApNameLine;
QFrame *apNameAndPwdLine;
QFrame *pwdAndfreqBandLine;
QFrame *freqBandAndInterfaceLine;
QVBoxLayout *mVlayout;
QLineEdit *m_apNameLine;
QLineEdit *m_pwdNameLine;
QComboBox *m_freqBandComboBox;
QComboBox *m_interfaceComboBox;
QDBusInterface *m_interface = nullptr;
QString m_interfaceName = "";
QGSettings *m_switchGsettings = nullptr;
QString m_uuid = "";
QString m_hostName = "";
void initUI();
void initDbusConnect();
void initInterfaceInfo();
void getApInfo();
bool getApInfoBySsid(QString devName, QString ssid, QStringList &info);
void setSwitchFrame();
void setApNameFrame();
void setPasswordFrame();
void setFreqBandFrame();
void setInterFaceFrame();
void setUiEnabled(bool enable);
void setWidgetHidden(bool isHidden);
void showDesktopNotify(const QString &message);
void updateBandCombox();
QString getHostName();
bool eventFilter(QObject *watched, QEvent *event);
void paintEvent(QPaintEvent *event);
QFrame* myLine();
signals:
private slots:
void onActivateFailed(QString errorMessage);
void onDeactivateFailed(QString errorMessage);
//设备插拔
void onDeviceStatusChanged();
void onDeviceNameChanged(QString oldName, QString newName, int type);
//热点断开
void onHotspotDeactivated(QString devName, QString ssid);
//热点连接
void onHotspotActivated(QString devName, QString ssid, QString uuid);
void onGsettingChanged(const QString &key);
void onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, int status);
void onApLineEditTextEdit(QString text);
};
#endif // MOBILEHOTSPOTWIDGET_H

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>MobileHotspot</name>
<message>
<location filename="../mobilehotspot.cpp" line="35"/>
<source>MobileHotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspot.cpp" line="101"/>
<source>mobilehotspot</source>
<translation type="unfinished"></translation>
<extra-contents_path>/mobilehotspot/mobilehotspot</extra-contents_path>
</message>
<message>
<location filename="../mobilehotspot.cpp" line="103"/>
<source>mobilehotspot open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/mobilehotspot/mobilehotspot open</extra-contents_path>
</message>
</context>
<context>
<name>MobileHotspotWidget</name>
<message>
<location filename="../mobilehotspotwidget.cpp" line="29"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="32"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="95"/>
<source>wirless switch is close or no wireless device</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="99"/>
<source>start to close hotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="108"/>
<source>hotpots name or device is invalid</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="112"/>
<source>can not create hotspot with password length less than eight!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="115"/>
<source>start to open hotspot </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="148"/>
<source>Hotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="220"/>
<location filename="../mobilehotspotwidget.cpp" line="526"/>
<source>hotspot already close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="360"/>
<source>Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="381"/>
<source>Wi-Fi Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="403"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="442"/>
<source>Frequency band</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="467"/>
<source>Net card</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="542"/>
<location filename="../mobilehotspotwidget.cpp" line="550"/>
<source>hotspot already open</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>MobileHotspot</name>
<message>
<location filename="../mobilehotspot.cpp" line="35"/>
<source>MobileHotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspot.cpp" line="101"/>
<source>mobilehotspot</source>
<translation type="unfinished"></translation>
<extra-contents_path>/mobilehotspot/mobilehotspot</extra-contents_path>
</message>
<message>
<location filename="../mobilehotspot.cpp" line="103"/>
<source>mobilehotspot open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/mobilehotspot/mobilehotspot open</extra-contents_path>
</message>
</context>
<context>
<name>MobileHotspotWidget</name>
<message>
<location filename="../mobilehotspotwidget.cpp" line="29"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="32"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="95"/>
<source>wirless switch is close or no wireless device</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="99"/>
<source>start to close hotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="108"/>
<source>hotpots name or device is invalid</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="112"/>
<source>can not create hotspot with password length less than eight!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="115"/>
<source>start to open hotspot </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="148"/>
<source>Hotspot</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="220"/>
<location filename="../mobilehotspotwidget.cpp" line="526"/>
<source>hotspot already close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="360"/>
<source>Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="381"/>
<source>Wi-Fi Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="403"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="442"/>
<source>Frequency band</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="467"/>
<source>Net card</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="542"/>
<location filename="../mobilehotspotwidget.cpp" line="550"/>
<source>hotspot already open</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

Binary file not shown.

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>MobileHotspot</name>
<message>
<location filename="../mobilehotspot.cpp" line="35"/>
<source>MobileHotspot</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspot.cpp" line="101"/>
<source>mobilehotspot</source>
<translation></translation>
<extra-contents_path>/mobilehotspot/mobilehotspot</extra-contents_path>
</message>
<message>
<location filename="../mobilehotspot.cpp" line="103"/>
<source>mobilehotspot open</source>
<translation> </translation>
<extra-contents_path>/mobilehotspot/mobilehotspot open</extra-contents_path>
</message>
</context>
<context>
<name>MobileHotspotWidget</name>
<message>
<location filename="../mobilehotspotwidget.cpp" line="29"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="32"/>
<source>ukui control center desktop message</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="95"/>
<source>wirless switch is close or no wireless device</source>
<translation>线线</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="99"/>
<source>start to close hotspot</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="108"/>
<source>hotpots name or device is invalid</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="112"/>
<source>can not create hotspot with password length less than eight!</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="115"/>
<source>start to open hotspot </source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="148"/>
<source>Hotspot</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="220"/>
<location filename="../mobilehotspotwidget.cpp" line="526"/>
<source>hotspot already close</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="360"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="381"/>
<source>Wi-Fi Name</source>
<translation>Wi-Fi名称</translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="403"/>
<source>Password</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="442"/>
<source>Frequency band</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="467"/>
<source>Net card</source>
<translation></translation>
</message>
<message>
<location filename="../mobilehotspotwidget.cpp" line="542"/>
<location filename="../mobilehotspotwidget.cpp" line="550"/>
<source>hotspot already open</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,31 @@
#include "itemframe.h"
#include <QPainter>
#include <QPalette>
#define LAYOUT_MARGINS 0,0,0,0
#define MAIN_LAYOUT_MARGINS 0,0,0,0
ItemFrame::ItemFrame(QString devName, QWidget *parent) : QFrame(parent)
{
deviceLanLayout = new QVBoxLayout(this);
deviceLanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
lanItemFrame = new QFrame(this);
lanItemFrame->setFrameShape(QFrame::Shape::NoFrame);
lanItemLayout = new QVBoxLayout(this);
lanItemLayout->setContentsMargins(LAYOUT_MARGINS);
lanItemLayout->setSpacing(0);
deviceLanLayout->setSpacing(0);
setLayout(deviceLanLayout);
lanItemFrame->setLayout(lanItemLayout);
deviceFrame = new DeviceFrame(devName, this);
m_divider = new Divider(this);
deviceLanLayout->addWidget(m_divider);
deviceLanLayout->addWidget(deviceFrame);
deviceLanLayout->addWidget(lanItemFrame);
}

View File

@ -0,0 +1,28 @@
#ifndef ITEMFRAME_H
#define ITEMFRAME_H
#include <QFrame>
#include <QVBoxLayout>
#include "../component/DeviceFrame/deviceframe.h"
#include "lanitem.h"
#include "../component/Divider/divider.h"
class ItemFrame : public QFrame
{
Q_OBJECT
public:
ItemFrame(QString devName, QWidget *parent = nullptr);
//单设备整体layout
QVBoxLayout * deviceLanLayout = nullptr;
Divider * m_divider;
//单设备名称 单设备开关
DeviceFrame * deviceFrame = nullptr;
//单设备列表Frame
QFrame * lanItemFrame = nullptr;
//单设备列表layout
QVBoxLayout * lanItemLayout = nullptr;
//单设备item列表 key:uuid
QMap<QString, LanItem *> itemMap;
};
#endif // ITEMFRAME_H

View File

@ -0,0 +1,99 @@
#include "lanitem.h"
#define FRAME_SPEED 150
#define LIMIT_TIME 60*1000
#define TOTAL_PAGE 8
LanItem::LanItem(bool isSimple, QWidget *parent)
: QFrame(parent),isSimple(isSimple)
{
this->setFixedSize(420, 48);
QHBoxLayout *mLanLyt = new QHBoxLayout(this);
mLanLyt->setContentsMargins(24,0,24,0);
mLanLyt->setSpacing(0);
iconLabel = new QLabel(this);
iconLabel->setProperty("useIconHighlightEffect", 0x2);
titileLabel = new QLabel(this);
mLanLyt->addWidget(iconLabel);
mLanLyt->addSpacing(10);
mLanLyt->addWidget(titileLabel,Qt::AlignLeft);
mLanLyt->addStretch();
if (!isSimple) {
infoLabel = new InfoButton(this);
mLanLyt->addSpacing(8);
mLanLyt->addWidget(infoLabel);
}
loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic"));
waitTimer = new QTimer(this);
connect(waitTimer, &QTimer::timeout, this, &LanItem::updateIcon);
m_menu = new QMenu(this);//右键菜单
connect(m_menu, &QMenu::triggered, this, &LanItem::itemClick);
}
void LanItem::updateIcon()
{
if (currentIconIndex > 6) {
currentIconIndex = 0;
}
iconLabel->setPixmap(loadIcons.at(currentIconIndex).pixmap(16,16));
currentIconIndex ++;
}
void LanItem::startLoading()
{
waitTimer->start(FRAME_SPEED);
loading = true;
}
void LanItem::stopLoading(){
waitTimer->stop();
loading = false;
}
void LanItem::mousePressEvent(QMouseEvent *event)
{
return QFrame::mousePressEvent(event);
}
void LanItem::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton) {
if (!m_menu) {
return QFrame::mouseReleaseEvent(event);
}
m_menu->clear();
if (isAcitve || loading) {
m_menu->addAction(new QAction(tr("Disconnect"), this));
} else if (!isAcitve && !loading) {
m_menu->addAction(new QAction(tr("Connect"), this));
}
m_menu->move(cursor().pos());
m_menu->show();
} else {
if (!isAcitve && !loading) {
Q_EMIT itemClick();
}
}
return QFrame::mouseReleaseEvent(event);
}
void LanItem::enterEvent(QEvent *event)
{
return QFrame::enterEvent(event);
}
void LanItem::leaveEvent(QEvent *event)
{
return QFrame::leaveEvent(event);
}
void LanItem::paintEvent(QPaintEvent *event)
{
return QFrame::paintEvent(event);
}

View File

@ -0,0 +1,56 @@
#ifndef LANITEM_H
#define LANITEM_H
#include <QObject>
#include <QHBoxLayout>
#include <QLabel>
#include <QTimer>
#include <QImage>
#include <QPainter>
#include <QMouseEvent>
#include <QMenu>
#include "../component/InfoButton/infobutton.h"
class LanItem : public QFrame
{
Q_OBJECT
public:
LanItem(bool isSimple, QWidget *parent = nullptr);
QLabel * iconLabel = nullptr;
InfoButton * infoLabel = nullptr;
QLabel * titileLabel = nullptr;
void startLoading();
void stopLoading();
bool loading = false;
bool isAcitve = false;
bool isSimple;
QString uuid;
QString dbusPath;
Q_SIGNALS:
void itemClick();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void paintEvent(QPaintEvent *event);
private:
QTimer *waitTimer = nullptr;
QList<QIcon> loadIcons;
int currentIconIndex=0;
QMenu *m_menu = nullptr;
private Q_SLOTS:
void updateIcon();
// void onMenuTriggered(QAction *action);
};
#endif // LANITEM_H

View File

@ -0,0 +1,863 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "netconnect.h"
#include <QGSettings>
#include <QProcess>
#include <QTimer>
#include <QtDBus>
#include <QDir>
#include <QDebug>
#include <QtAlgorithms>
const QString KLanSymbolic = "network-wired-connected-symbolic";
const QString NoNetSymbolic = "network-wired-disconnected-symbolic";
#define NO_MARGINS 0,0,0,0
#define TOP_MARGINS 0,8,0,0
#define MAIN_LAYOUT_MARGINS 0,0,0,0
#define MAIN_LAYOUT_SPACING 0
#define TITLE_FRAME_HEIGHT 50 //TabWidget的tab和widget有间隙和设计稿看起来一致就不能设为设计稿里的高度
#define TITLE_LAYOUT_MARGINS 24,0,24,0
#define SPACING 8
const QString KEY_WIRED_SWITCH = "wiredswitch";
const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf";
void NetConnect::showDesktopNotify(const QString &message)
{
QDBusInterface iface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
QDBusConnection::sessionBus());
QList<QVariant> args;
args<<(tr("ukui control center"))
<<((unsigned int) 0)
<<QString("/usr/share/icons/ukui-icon-theme-default/24x24/devices/gnome-dev-ethernet.png")
<<tr("ukui control center desktop message") //显示的是什么类型的信息
<<message //显示的具体信息
<<QStringList()
<<QVariantMap()
<<(int)-1;
iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args);
}
NetConnect::NetConnect() : mFirstLoad(true) {
QTranslator* translator = new QTranslator(this);
translator->load("/usr/share/kylin-nm/netconnect/" + QLocale::system().name());
QApplication::installTranslator(translator);
}
NetConnect::~NetConnect() {
if (!mFirstLoad) {
if (m_switchGsettings != nullptr) {
delete m_switchGsettings;
m_switchGsettings = nullptr;
}
}
}
QWidget *NetConnect::pluginUi() {
if (mFirstLoad) {
mFirstLoad = false;
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
pluginWidget->setFixedSize(420, 436);
initUi();
initComponent();
initConnect();
}
return pluginWidget;
}
void NetConnect::setPluginType(PluginType type)
{
if (type == SIMPLE) {
m_isSimpleMode = true;
} else {
m_isSimpleMode = false;
}
}
void NetConnect::initUi()
{
thread = new QThread;
manager = new KyNetworkManager();
manager->moveToThread(thread);
thread->start();
m_mainLayout = new QVBoxLayout(pluginWidget);
m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
pluginWidget->setLayout(m_mainLayout);
m_titleFrame = new QFrame(pluginWidget);
m_titleFrame->setFixedHeight(53);
m_titleLayout = new QHBoxLayout(m_titleFrame);
m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_titleLabel = new QLabel(m_titleFrame);
m_titleLabel->setText(tr("LAN"));
m_wiredSwitch = new KSwitchButton(pluginWidget);
m_wiredSwitch->installEventFilter(this);
m_titleLayout->addWidget(m_titleLabel);
m_titleLayout->addStretch();
m_titleLayout->addWidget(m_wiredSwitch);
m_titleDivider = new Divider(pluginWidget);
m_titleDivider->hide();
m_scrollFrame = new QFrame(pluginWidget);
if (!m_isSimpleMode) {
m_scrollFrame->setMinimumHeight(330);
} else {
m_scrollFrame->setMinimumHeight(383);
}
m_scrollLayout = new QVBoxLayout(m_scrollFrame);
m_scrollLayout->setContentsMargins(0,0,0,0);
m_scrollLayout->setSpacing(0);
m_scrollFrame->setLayout(m_scrollLayout);
m_scrollArea = new QScrollArea(m_scrollFrame);
m_scrollArea->setFrameShape(QFrame::Shape::NoFrame);
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setBackgroundRole(QPalette::Base);
m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_scrollLayout->addWidget(m_scrollArea);
m_listWidget = new QWidget(pluginWidget);
m_listWidget->setFixedWidth(420);
m_scrollAreaLayout = new QVBoxLayout(m_listWidget);
m_scrollAreaLayout->setSpacing(MAIN_LAYOUT_SPACING);
m_scrollAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_scrollAreaLayout->setAlignment(Qt::AlignTop);
m_listWidget->setLayout(m_scrollAreaLayout);
m_scrollArea->setWidget(m_listWidget);
m_settingsDivider = new Divider(pluginWidget);
m_settingsFrame = new QFrame(pluginWidget);
m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_settingsLayout = new QHBoxLayout(m_settingsFrame);
m_settingsLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_settingsLabel = new KBorderlessButton(m_settingsFrame);
m_settingsLabel->setCursor(Qt::PointingHandCursor);
m_settingsLabel->setText(tr("Settings"));
m_settingsLayout->addWidget(m_settingsLabel);
m_settingsLayout->addStretch();
m_settingsFrame->setLayout(m_settingsLayout);
m_mainLayout->addWidget(m_titleFrame);
m_mainLayout->addWidget(m_titleDivider);
m_mainLayout->addWidget(m_scrollFrame);
if (!m_isSimpleMode) {
m_mainLayout->addStretch();
m_mainLayout->addWidget(m_settingsDivider);
m_mainLayout->addWidget(m_settingsFrame);
} else {
m_settingsDivider->hide();
m_settingsFrame->hide();
}
QPalette pal = m_scrollArea->palette();
pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明
m_scrollArea->setPalette(pal);
}
bool NetConnect::eventFilter(QObject *w, QEvent *e) {
if (w == m_wiredSwitch && e->type() == QEvent::MouseButtonRelease) {
if (!m_wiredSwitch->isCheckable()) {
showDesktopNotify(tr("No ethernet device avaliable"));
qDebug() << "No ethernet device avaliable";
} else {
Q_EMIT setWiredEnabled(!m_wiredSwitch->isChecked());
qDebug() << "setWiredEnabled" << !m_wiredSwitch->isChecked();
}
return true;
}
return QObject::eventFilter(w,e);
}
void NetConnect::initComponent() {
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
setSwitchStatus();
connect(m_switchGsettings, &QGSettings::changed, this, [=] (const QString &key) {
if (key == KEY_WIRED_SWITCH) {
setSwitchStatus();
}
});
} else {
m_wiredSwitch->blockSignals(true);
m_wiredSwitch->setChecked(true);
qDebug() << "m_wiredSwitch setChecked" << true;
m_wiredSwitch->blockSignals(false);
m_wiredSwitch->hide();
qDebug()<<"[Netconnect] org.ukui.kylin-nm.switch is not installed!";
}
getDeviceStatusMap(deviceStatusMap);
if (deviceStatusMap.isEmpty()) {
qDebug() << "[Netconnect] no device exist when init, set switch disable";
m_wiredSwitch->setCheckable(false);
m_wiredSwitch->setChecked(false);
qDebug() << "m_wiredSwitch setCheckable setChecked" << false;
}
initNet();
if (!m_wiredSwitch->isChecked() || deviceStatusMap.isEmpty()) {
hideLayout(m_scrollAreaLayout);
m_titleDivider->show();
}
connect(m_settingsLabel, &KBorderlessButton::clicked, this, [=](bool checked) {
Q_UNUSED(checked)
runExternalApp();
});
}
void NetConnect::initConnect()
{
connect(manager, &KyNetworkManager::wiredStateChange, this, &NetConnect::onActiveConnectionChanged);
//connect(manager, &KyNetworkManager::deviceStateChange, this, &NetConnect::onDeviceStatusChanged);
connect(manager, &KyNetworkManager::carrierChange, this, &NetConnect::onDeviceCarrierChange);
connect(manager, &KyNetworkManager::wiredConnectionAdd, this, &NetConnect::onLanAdd);
connect(manager, &KyNetworkManager::wiredConnectionUpdate, this, &NetConnect::updateLanInfo);
connect(manager, &KyNetworkManager::connectionRemove, this, &NetConnect::onLanRemove);
connect(manager, &KyNetworkManager::wiredDeviceAdd, this, &NetConnect::onDeviceAdd);
connect(manager, &KyNetworkManager::wiredDeviceRemove, this, &NetConnect::onDeviceRemove);
connect(manager, &KyNetworkManager::wiredDeviceUpdate, this, &NetConnect::onDeviceNameChanged);
connect(this, &NetConnect::setWiredDeviceEnable, manager, &KyNetworkManager::onSetWiredDeviceEnable);
connect(this, &NetConnect::setWiredEnabled, manager, &KyNetworkManager::onSetWiredEnabled);
connect(this, &NetConnect::activateConnection, manager, &KyNetworkManager::onActivateConnection);
connect(this, &NetConnect::deactivateConnection, manager, &KyNetworkManager::onDeactivateConnection);
connect(this, &NetConnect::deleteConnect, manager, &KyNetworkManager::onDeleteConnect);
connect(this, &NetConnect::updateIpv4AndIpv6SettingInfo, manager, &KyNetworkManager::onUpdateIpv4AndIpv6SettingInfo);
connect(this, &NetConnect::createWiredConnect, manager, &KyNetworkManager::onCreateWiredConnect);
}
//获取网卡列表
void NetConnect::getDeviceStatusMap(QMap<QString, bool> &map)
{
map.clear();
if (!QFile::exists(CONFIG_FILE_PATH)) {
qDebug() << "CONFIG_FILE_PATH not exist";
return;
}
QStringList wiredDevList;
wiredDevList.clear();
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
m_settings->beginGroup("CARDEABLE");
manager->getNetworkDeviceList(DEVICE_TYPE_ETHERNET, wiredDevList);
if (!wiredDevList.isEmpty()) {
for (int i = 0; i < wiredDevList.size(); ++i) {
if (!m_settings->contains(wiredDevList.at(i))) {
map.insert(wiredDevList.at(i), true);
}
bool enable = m_settings->value(wiredDevList.at(i), true).toBool();
map.insert(wiredDevList.at(i), enable);
}
}
m_settings->endGroup();
delete m_settings;
m_settings = nullptr;
}
//lanUpdate
void NetConnect::updateLanInfo(QString deviceName, QString connectUuid, QString connectName, QString connectPath)
{
//设备归属变化 || 有线名称变化
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (deviceName.isEmpty()) {
//变为无指定网卡,所有列表都要添加
if (!iter.value()->itemMap.contains(connectUuid)) {
QStringList lanInfo;
lanInfo << connectName << connectUuid << connectPath;
addOneLanFrame(iter.value(), iter.key(), lanInfo);
} else {
if (iter.value()->itemMap[connectUuid]->titileLabel->text() != connectName) {
qDebug() << "[NetConnect]" << iter.key()
<< iter.value()->itemMap[connectUuid]->titileLabel->text() << "change to" << connectName;
iter.value()->itemMap[connectUuid]->titileLabel->setText(connectName);
deviceFrameMap[iter.key()]->lanItemLayout->removeWidget(iter.value()->itemMap[connectUuid]);
int index = getInsertPos(connectName, deviceFrameMap[iter.key()]->lanItemLayout);
deviceFrameMap[iter.key()]->lanItemLayout->insertWidget(index,iter.value()->itemMap[connectUuid]);
}
}
} else {
if (iter.key() != deviceName) {
qDebug() << "[NetConnect]" << connectUuid << " not belongs to " << iter.key();
removeOneLanFrame(iter.value(), deviceName, connectUuid);
} else {
if (!iter.value()->itemMap.contains(connectUuid)) {
qDebug() << "[NetConnect]" << connectUuid << " now belongs to " << deviceName;
QStringList lanInfo;
lanInfo << connectName << connectUuid << connectPath;
addOneLanFrame(iter.value(), deviceName, lanInfo);
} else {
qDebug() << "[NetConnect]" << deviceName
<< iter.value()->itemMap[connectUuid]->titileLabel->text() << "change to" << connectName;
if (iter.value()->itemMap[connectUuid]->titileLabel->text() != connectName) {
iter.value()->itemMap[connectUuid]->titileLabel->setText(connectName);
deviceFrameMap[iter.key()]->lanItemLayout->removeWidget(iter.value()->itemMap[connectUuid]);
int index = getInsertPos(connectName, deviceFrameMap[iter.key()]->lanItemLayout);
deviceFrameMap[iter.key()]->lanItemLayout->insertWidget(index,iter.value()->itemMap[connectUuid]);
}
}
}
}
}
}
//总开关
void NetConnect::setSwitchStatus()
{
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
bool status = m_switchGsettings->get(KEY_WIRED_SWITCH).toBool();
qDebug() << "setSwitchStatus" << status;
m_wiredSwitch->blockSignals(true);
m_wiredSwitch->setChecked(status);
qDebug() << "m_wiredSwitch setChecked" << status;
m_wiredSwitch->blockSignals(false);
if (!status) {
hideLayout(m_scrollAreaLayout);
m_titleDivider->show();
} else {
showLayout(m_scrollAreaLayout);
m_titleDivider->hide();
}
} else {
qDebug()<<"[netconnect] org.ukui.kylin-nm.switch is not installed!";
}
}
//总体隐藏
void NetConnect::hideLayout(QVBoxLayout * layout) {
for (int i = layout->layout()->count()-1; i >= 0; --i)
{
QLayoutItem *it = layout->layout()->itemAt(i);
ItemFrame *itemFrame = qobject_cast<ItemFrame *>(it->widget());
itemFrame->hide();
}
}
//总体显示
void NetConnect::showLayout(QVBoxLayout * layout) {
for (int i = layout->layout()->count()-1; i >= 0; --i)
{
QLayoutItem *it = layout->layout()->itemAt(i);
ItemFrame *itemFrame = qobject_cast<ItemFrame *>(it->widget());
itemFrame->show();
}
}
//初始化
void NetConnect::initNet()
{
//先构建每个设备的列表头
QStringList deviceList = deviceStatusMap.keys();
for (int i = 0; i < deviceList.size(); ++i) {
addDeviceFrame(deviceList.at(i), deviceStatusMap[deviceList.at(i)]);
}
//再填充每个设备的列表
for (int i = 0; i < deviceList.size(); ++i) {
initNetListFromDevice(deviceList.at(i));
}
}
void NetConnect::runExternalApp()
{
QProcess process;
process.startDetached("ukui-control-center -m netconnect");
}
//激活
void NetConnect::activeConnect(QString uuid, QString deviceName)
{
Q_EMIT activateConnection(uuid, deviceName);
}
//断开
void NetConnect::deActiveConnect(QString uuid)
{
Q_EMIT deactivateConnection(uuid);
}
//初始化设备列表
void NetConnect::initNetListFromDevice(QString deviceName)
{
qDebug() << "[NetConnect]initNetListFromDevice " << deviceName;
if (!deviceFrameMap.contains(deviceName)) {
qDebug() << "[NetConnect]initNetListFromDevice " << deviceName << " not exist";
return;
}
QMap<QString,QList<KyWiredItem>> wiredMap;
manager->getWiredList(wiredMap);
if (wiredMap.size() == 0) {
qDebug() << "[NetConnect]initNetListFromDevice " << deviceName << " list empty";
return;
}
QMap<QString,QList<KyWiredItem>>::iterator iter;
for (iter = wiredMap.begin(); iter != wiredMap.end(); iter++) {
if (deviceName == iter.key()) {
QList<KyWiredItem> lanListInfo = iter.value();
//处理列表
for (int i = 0; i < lanListInfo.length(); i++) {
addLanItem(deviceFrameMap[deviceName], deviceName, lanListInfo.at(i));
}
}
}
QList<KyActivateItem> activateList;
manager->getActiveConnectionList(deviceName, CONNECT_TYPE_WIRED, activateList);
if (activateList.size() != 0) {
onActiveConnectionChanged(deviceName, activateList.at(0).m_uuid, activateList.at(0).m_connStatus);
}
}
//初始化时添加一个项
void NetConnect::addLanItem(ItemFrame *frame, QString devName, KyWiredItem item)
{
if (frame == nullptr) {
return;
}
LanItem * lanItem = new LanItem(m_isSimpleMode, pluginWidget);
QIcon searchIcon = QIcon::fromTheme(NoNetSymbolic);
lanItem->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24))));
lanItem->titileLabel->setText(item.m_connectName);
lanItem->uuid = item.m_connectUuid;
lanItem->dbusPath = item.m_connectPath;
//todo show detail page
connect(lanItem->infoLabel, &InfoButton::clicked, this, [=]{
});
lanItem->isAcitve = false;
connect(lanItem, &LanItem::itemClick, this, [=] {
if (lanItem->isAcitve || lanItem->loading) {
deActiveConnect(lanItem->uuid);
} else {
activeConnect(lanItem->uuid, devName);
}
});
//记录到deviceFrame的itemMap中
deviceFrameMap[devName]->itemMap.insert(item.m_connectUuid, lanItem);
frame->lanItemLayout->addWidget(lanItem);
}
//增加设备
void NetConnect::addDeviceFrame(QString devName, bool isEnable)
{
ItemFrame *itemFrame = new ItemFrame(devName, pluginWidget);
m_scrollAreaLayout->addWidget(itemFrame);
itemFrame->deviceFrame->deviceLabel->setText(devName);
if (isEnable) {
itemFrame->lanItemFrame->show();
} else {
itemFrame->lanItemFrame->hide();
}
deviceFrameMap.insert(devName, itemFrame);
deviceStatusMap.insert(devName, true);
}
//减少设备
void NetConnect::removeDeviceFrame(QString devName)
{
if (deviceFrameMap.contains(devName)) {
ItemFrame *item = deviceFrameMap[devName];
if (item->lanItemFrame->layout() != NULL) {
QLayoutItem* layoutItem;
while ((layoutItem = item->lanItemFrame->layout()->takeAt(0)) != NULL) {
delete layoutItem->widget();
delete layoutItem;
layoutItem = nullptr;
}
item->itemMap.clear();
}
delete item;
item = nullptr;
deviceFrameMap.remove(devName);
}
}
//device add or remove=================================
#if 0
void NetConnect::onDeviceStatusChanged()
{
qDebug()<<"[NetConnect]onDeviceStatusChanged";
QEventLoop eventloop;
QTimer::singleShot(300, &eventloop, SLOT(quit()));
eventloop.exec();
QStringList list;
QMap<QString, bool> map;
getDeviceStatusMap(map);
list = map.keys();
QStringList removeList;
QMap<QString, bool> addMap;
//remove的设备
for (int i = 0; i< deviceStatusMap.keys().size(); ++i) {
if (!list.contains(deviceStatusMap.keys().at(i))) {
qDebug() << "[NetConnect]onDeviceStatusChanged " << deviceStatusMap.keys().at(i) << "was removed";
removeList << deviceStatusMap.keys().at(i);
}
}
//add的设备
for (int i = 0; i< list.size(); ++i) {
if (!deviceStatusMap.keys().contains(list.at(i))) {
qDebug() << "[NetConnect]onDeviceStatusChanged " << list.at(i) << "was add, init status" << map[list.at(i)];
addMap.insert(list.at(i),map[list.at(i)]);
}
}
for (int i = 0; i < removeList.size(); ++i) {
removeDeviceFrame(removeList.at(i));
}
QStringList addList = addMap.keys();
for (int i = 0; i < addList.size(); ++i) {
qDebug() << "add a device " << addList.at(i) << "status" << map[addList.at(i)];
addDeviceFrame(addList.at(i));
initNetListFromDevice(addList.at(i));
}
deviceStatusMap = map;
if (deviceStatusMap.isEmpty()) {
wiredSwitch->setDisabledFlag(true);
wiredSwitch->setChecked(false);
} else {
wiredSwitch->setDisabledFlag(false);
setSwitchStatus();
}
}
#endif
void NetConnect::onDeviceNameChanged(QString oldName, QString newName)
{
if (!deviceFrameMap.contains(oldName) || !deviceStatusMap.contains(oldName)) {
qDebug() << "[NetConnect]onDeviceNameChanged no such device " << oldName;
return;
}
if (deviceFrameMap.contains(newName) && deviceStatusMap.contains(newName)) {
qDebug() << "[NetConnect]onDeviceNameChanged already has device " << newName;
return;
}
qDebug() << "[NetConnect]onDeviceNameChanged " << oldName << "change to" << newName;
//shan chu chong jian
removeDeviceFrame(oldName);
removeDeviceFrame(newName);
getDeviceStatusMap(deviceStatusMap);
if (deviceStatusMap.contains(newName)) {
addDeviceFrame(newName, deviceStatusMap[newName]);
initNetListFromDevice(newName);
}
}
//lan add===============================================================
void NetConnect::onLanAdd(QString devName, QString connectUuid, QString connectName, QString connectPath)
{
qDebug() << "onLanAdd";
if (!devName.isEmpty() && !deviceStatusMap.contains(devName)) {
return;
}
QStringList lanInfo;
lanInfo << connectName << connectUuid << connectPath;
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (devName.isEmpty()) {
addOneLanFrame(iter.value(), iter.key(), lanInfo);
} else if (devName == iter.key()) {
addOneLanFrame(iter.value(), devName, lanInfo);
break;
}
}
}
//wifi remove =============================================================
void NetConnect::onLanRemove(QString lanPath)
{
qDebug() << "onLanRemove";
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
QMap<QString, LanItem *>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
if (itemIter.value()->dbusPath == lanPath) {
qDebug()<<"[NetConnect]lan remove " << lanPath << " find in " << itemIter.value()->titileLabel->text();
QString key = itemIter.key();
iter.value()->lanItemLayout->removeWidget(itemIter.value());
delete itemIter.value();
iter.value()->itemMap.remove(key);
break;
}
}
}
}
//增加一项
void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringList infoList)
{
if (nullptr == frame) {
return;
}
if (frame->itemMap.contains(infoList.at(1))) {
qDebug() << "[NetConnect]Already exist a lan " << infoList.at(1) << " in " << deviceName;
return;
}
qDebug() << "[NetConnect]addOneLanFrame" << deviceName << infoList.at(0);
QString connName = infoList.at(0);
QString connUuid = infoList.at(1);
QString connDbusPath = infoList.at(2);
LanItem * lanItem = new LanItem(m_isSimpleMode, pluginWidget);
QIcon searchIcon = QIcon::fromTheme(NoNetSymbolic);
lanItem->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24))));
lanItem->titileLabel->setText(connName);
lanItem->uuid = connUuid;
lanItem->dbusPath = connDbusPath;
// todo open landetail page
connect(lanItem->infoLabel, &InfoButton::clicked, this, [=]{
});
lanItem->isAcitve = false;
connect(lanItem, &LanItem::itemClick, this, [=] {
if (lanItem->isAcitve || lanItem->loading) {
deActiveConnect(lanItem->uuid);
} else {
activeConnect(lanItem->uuid, deviceName);
}
});
//记录到deviceFrame的itemMap中
deviceFrameMap[deviceName]->itemMap.insert(connUuid, lanItem);
int index = getInsertPos(connName, deviceFrameMap[deviceName]->lanItemLayout);
qDebug()<<"[NetConnect]addOneLanFrame " << connName << " to " << deviceName << " list at pos:" << index;
frame->lanItemLayout->insertWidget(index, lanItem);
}
void NetConnect::removeOneLanFrame(ItemFrame *frame, QString deviceName, QString uuid)
{
if (nullptr == frame) {
return;
}
if (!frame->itemMap.contains(uuid)) {
qDebug() << "[NetConnect]not exist a lan " << uuid << " in " << deviceName;
return;
}
qDebug()<<"[NetConnect]removeOneLanFrame " << uuid << " find in " << deviceName;
frame->lanItemLayout->removeWidget(frame->itemMap[uuid]);
delete frame->itemMap[uuid];
frame->itemMap.remove(uuid);
}
//activeconnect status change
void NetConnect::onActiveConnectionChanged(QString deviceName, QString uuid, KyConnectState status)
{
if (uuid.isEmpty()) {
qDebug() << "[NetConnect]onActiveConnectionChanged but uuid is empty";
return;
}
qDebug() << "[NetConnect]onActiveConnectionChanged " << deviceName << uuid << status;
LanItem * item= nullptr;
if (deviceName.isEmpty()) {
if (status != CONNECT_STATE_DEACTIVATED) {
return;
}
//断开时 设备为空 说明此有线未指定设备 添加到所有列表中
QStringList infoList;
QMap<QString, ItemFrame *>::iterator iters;
for (iters = deviceFrameMap.begin(); iters != deviceFrameMap.end(); iters++) {
if (iters.value()->itemMap.contains(uuid)) {
item = iters.value()->itemMap[uuid];
infoList << item->titileLabel->text() << item->uuid << item->dbusPath;
//为断开则重新插入
deviceFrameMap[iters.key()]->lanItemLayout->removeWidget(item);
int index = getInsertPos(item->titileLabel->text(), deviceFrameMap[iters.key()]->lanItemLayout);
qDebug() << "[NetConnect]reinsert" << item->titileLabel->text() << "pos" << index << "in" << iters.key() << "because status changes to deactive";
deviceFrameMap[iters.key()]->lanItemLayout->insertWidget(index,item);
itemActiveConnectionStatusChanged(item, status);
}
}
//添加到所有列表中
if (!infoList.isEmpty()) {
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (!iter.value()->itemMap.contains(uuid)) {
addOneLanFrame(iter.value(), iter.key(), infoList);
}
}
}
} else {
if (deviceFrameMap.contains(deviceName)) {
if (deviceFrameMap[deviceName]->itemMap.contains(uuid)) {
item = deviceFrameMap[deviceName]->itemMap[uuid];
if (status == CONNECT_STATE_ACTIVATED) {
//为已连接则放到第一个
deviceFrameMap[deviceName]->lanItemLayout->removeWidget(item);
deviceFrameMap[deviceName]->lanItemLayout->insertWidget(0,item);
} else if (status == CONNECT_STATE_DEACTIVATED) {
//为断开则重新插入
deviceFrameMap[deviceName]->lanItemLayout->removeWidget(item);
int index = getInsertPos(item->titileLabel->text(), deviceFrameMap[deviceName]->lanItemLayout);
qDebug() << "[NetConnect]reinsert" << item->titileLabel->text() << "pos" << index << "in" << deviceName << "because status changes to deactive";
deviceFrameMap[deviceName]->lanItemLayout->insertWidget(index,item);
}
itemActiveConnectionStatusChanged(item, status);
}
} else {
if (status == CONNECT_STATE_ACTIVATED || status == CONNECT_STATE_DEACTIVATED) {
//虚拟网卡处理
QMap<QString, ItemFrame *>::iterator iters;
for (iters = deviceFrameMap.begin(); iters != deviceFrameMap.end(); iters++) {
if (iters.value()->itemMap.contains(uuid)) {
removeOneLanFrame(iters.value(), iters.key(), uuid);
}
}
}
}
}
}
void NetConnect::itemActiveConnectionStatusChanged(LanItem *item, KyConnectState status)
{
if (status == CONNECT_STATE_ACTIVATING) {
item->startLoading();
} else if (status == CONNECT_STATE_ACTIVATED) {
item->stopLoading();
QIcon searchIcon = QIcon::fromTheme(KLanSymbolic);
item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24))));
item->isAcitve = true;
} else if (status == CONNECT_STATE_DEACTIVATING) {
item->startLoading();
} else {
item->stopLoading();
QIcon searchIcon = QIcon::fromTheme(NoNetSymbolic);
item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24))));
item->isAcitve = false;
}
}
int NetConnect::getInsertPos(QString connName, QVBoxLayout* layout)
{
// qDebug() << "[NetConnect]getInsertPos" << connName << deviceName;
// int index = 0;
// QMap<QString,QList<KyWiredItem>> wiredMap;
// manager->getWiredList(wiredMap);
// if (!wiredMap.contains(deviceName)) {
// return 0;
// }
// QList<KyActivateItem> activateList;
// QString name;
// manager->getActiveConnectionList(deviceName, CONNECT_TYPE_WIRED, activateList);
// if (activateList.size() != 0) {
// name = activateList.at(0).m_connName;
// }
// bool isFind = false;
// for (;index < wiredMap[deviceName].size(); ++index) {
// if (wiredMap[deviceName].at(index).m_connectName == connName) {
// break;
// } else if (wiredMap[deviceName].at(index).m_connectName == name) {
// isFind = true;
// }
// }
// if (!isFind) {
// index++;
// }
// return index;
int index = 0;
for (; index < layout->count(); ++index)
{
QLayoutItem *it = layout->layout()->itemAt(index);
LanItem *item = qobject_cast<LanItem *>(it->widget());
if (QString::compare(connName, item->titileLabel->text(), Qt::CaseInsensitive) > 0) {
qDebug() << "compare" << connName << item->titileLabel->text() << index;
continue;
} else {
if (item->isAcitve) {
continue;
}
break;
}
}
return index;
}
void NetConnect::onDeviceCarrierChange(QString deviceName, bool pluged)
{
}
void NetConnect::onDeviceAdd(QString deviceName)
{
addDeviceFrame(deviceName, true);
initNetListFromDevice(deviceName);
}
void NetConnect::onDeviceRemove(QString deviceName)
{
removeDeviceFrame(deviceName);
}

View File

@ -0,0 +1,178 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef NETCONNECT_H
#define NETCONNECT_H
#include "kswitchbutton.h"
#include "kborderlessbutton.h"
using namespace kdk;
#include <QObject>
#include <QtPlugin>
#include <QTranslator>
#include <QApplication>
#include <QTimer>
#include <QStringList>
#include <QString>
#include <QGSettings>
#include <QListWidget>
#include <QListWidgetItem>
#include <QMap>
#include <QPropertyAnimation>
#include <QPoint>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <kylin-nm/kylin-nm-interface.h>
#include <kylin-nm/kylinnetworkmanager.h>
#include "lanitem.h"
#include "../component/DeviceFrame/deviceframe.h"
#include "itemframe.h"
#include "../component/Divider/divider.h"
enum {
DISCONNECTED,
NOINTERNET,
CONNECTED
};
class NetConnect : public QObject, Interface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kylin.network")
Q_INTERFACES(Interface)
public:
NetConnect();
~NetConnect();
QWidget * pluginUi() Q_DECL_OVERRIDE; // 插件主界面---setPluginType后调用
void setPluginType(PluginType type) Q_DECL_OVERRIDE; // 设置插件类型
private:
bool m_isSimpleMode = true;
void initUi();
void initComponent();
void initConnect();
void runExternalApp();
void showDesktopNotify(const QString &message);
//开关相关
void setSwitchStatus();
void hideLayout(QVBoxLayout * layout);
void showLayout(QVBoxLayout * layout);
int getInsertPos(QString connName, QVBoxLayout* layout);
void activeConnect(QString uuid, QString deviceName);
void deActiveConnect(QString uuid);
//获取设备列表
void getDeviceStatusMap(QMap<QString, bool> &map);
void initNet();
void initNetListFromDevice(QString deviceName);
//处理列表增加
void addLanItem(ItemFrame *frame, QString devName, KyWiredItem item);
//增加设备
void addDeviceFrame(QString devName, bool isEnable);
//减少设备
void removeDeviceFrame(QString devName);
//增加一项
void addOneLanFrame(ItemFrame *frame, QString devName, QStringList infoList);
//减少一项
void removeOneLanFrame(ItemFrame *frame, QString deviceName, QString uuid);
//单个lan连接状态变化
void itemActiveConnectionStatusChanged(LanItem *item, KyConnectState status);
protected:
bool eventFilter(QObject *w,QEvent *e);
private:
KyNetworkManager* manager;
QThread* thread;
QWidget* pluginWidget = nullptr;
bool mFirstLoad = true;
QVBoxLayout* m_mainLayout = nullptr;
QFrame* m_titleFrame = nullptr;
QHBoxLayout* m_titleLayout = nullptr;
QLabel* m_titleLabel = nullptr;
KSwitchButton* m_wiredSwitch = nullptr;
Divider* m_titleDivider = nullptr;
QFrame* m_scrollFrame = nullptr;
QVBoxLayout* m_scrollLayout = nullptr;
QScrollArea* m_scrollArea = nullptr;
QWidget* m_listWidget = nullptr;
QVBoxLayout* m_scrollAreaLayout = nullptr;
Divider* m_settingsDivider = nullptr;
QFrame* m_settingsFrame = nullptr;
QHBoxLayout* m_settingsLayout = nullptr;
KBorderlessButton* m_settingsLabel = nullptr;
QGSettings *m_switchGsettings = nullptr;
QMap<QString, bool> deviceStatusMap;
QMap<QString, ItemFrame *> deviceFrameMap;
Q_SIGNALS:
//general
void setWiredEnabled(bool enabled);
//有线无线公用
void deleteConnect(const QString &connectUuid);
void activateConnection(const QString connectUuid, const QString deviceName);
void deactivateConnection(const QString &activeConnectUuid);
//wired 单设备启用禁用
void setWiredDeviceEnable(const QString &interface, bool enable);
void createWiredConnect(KyConnectSetting connectSettingsInfo);
void updateIpv4AndIpv6SettingInfo(const QString &uuid, const KyConnectSetting &connectSettingsInfo);
private Q_SLOTS:
void updateLanInfo(QString deviceName, QString connectUuid, QString connectName, QString connectPath);
void onLanAdd(QString devName, QString connectUuid, QString connectName, QString connectPath);
void onLanRemove(QString dbusPath);
void onActiveConnectionChanged(QString deviceName, QString uuid, KyConnectState status);
// void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString);
void onDeviceCarrierChange(QString deviceName, bool pluged);
void onDeviceAdd(QString deviceName);
void onDeviceRemove(QString deviceName);
};
#endif // NETCONNECT_H

View File

@ -0,0 +1,44 @@
QT += widgets network dbus gui core
TEMPLATE = lib
CONFIG += plugin
include(../component/infobutton.pri)
include(../component/divider.pri)
include(../component/deviceframe.pri)
TARGET = $$qtLibraryTarget(netconnect)
DESTDIR = ../..
target.path = /usr/lib/kylin-nm
INCLUDEPATH += \
$$PROJECT_COMPONENTSOURCE \
$$PROJECT_ROOTDIR \
LIBS += -L$$[QT_INSTALL_LIBS] -lkylin-nm-base
CONFIG += c++11 \
link_pkgconfig \
no_keywords
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
kylin-nm-base
#DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
itemframe.cpp \
lanitem.cpp \
netconnect.cpp
HEADERS += \
itemframe.h \
lanitem.h \
netconnect.h
INSTALLS += target \
TRANSLATIONS += \
translations/zh_CN.ts \
translations/tr.ts \
translations/bo.ts

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>AddNetBtn</name>
<message>
<location filename="../addnetbtn.cpp" line="22"/>
<source>Add WiredNetork</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="152"/>
<source>Wired Network</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="154"/>
<source>open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="151"/>
<source>Advanced settings</source>
<translation type="unfinished"></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="63"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="66"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="80"/>
<source>WiredConnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="177"/>
<source>No ethernet device avaliable</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="426"/>
<location filename="../netconnect.cpp" line="835"/>
<source>connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="490"/>
<source>card</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>AddNetBtn</name>
<message>
<location filename="../addnetbtn.cpp" line="22"/>
<source>Add WiredNetork</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="152"/>
<source>Wired Network</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="154"/>
<source>open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="151"/>
<source>Advanced settings</source>
<translation type="unfinished"></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="63"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="66"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="80"/>
<source>WiredConnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="177"/>
<source>No ethernet device avaliable</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="426"/>
<location filename="../netconnect.cpp" line="835"/>
<source>connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="490"/>
<source>card</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

Binary file not shown.

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>AddNetBtn</name>
<message>
<location filename="../addnetbtn.cpp" line="22"/>
<source>Add WiredNetork</source>
<translation>线</translation>
</message>
</context>
<context>
<name>NetConnect</name>
<message>
<location filename="../netconnect.ui" line="50"/>
<location filename="../netconnect.cpp" line="152"/>
<source>Wired Network</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.ui" line="112"/>
<location filename="../netconnect.cpp" line="154"/>
<source>open</source>
<translation></translation>
<extra-contents_path>/netconnect/open</extra-contents_path>
</message>
<message>
<location filename="../netconnect.ui" line="198"/>
<location filename="../netconnect.cpp" line="151"/>
<source>Advanced settings</source>
<translation></translation>
<extra-contents_path>/netconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../netconnect.cpp" line="63"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="66"/>
<source>ukui control center desktop message</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="80"/>
<source>WiredConnect</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="177"/>
<source>No ethernet device avaliable</source>
<translation>线</translation>
</message>
<message>
<location filename="../netconnect.cpp" line="426"/>
<location filename="../netconnect.cpp" line="835"/>
<source>connected</source>
<translation></translation>
</message>
<message>
<location filename="../netconnect.cpp" line="490"/>
<source>card</source>
<translation></translation>
</message>
</context>
</TS>

5
plugins/plugin.pro Normal file
View File

@ -0,0 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = \
netconnect \
wlanconnect \
# mobilehotspot

View File

@ -0,0 +1,48 @@
#include "deviceframe.h"
#include <QPainter>
#define LAYOUT_MARGINS 18,0,8,0
#define FRAME_HEIGHT 58
#define LAYOUT_SPACING 16
#define RADIUS 6.0
DeviceFrame::DeviceFrame(QString devName, QWidget *parent) : QFrame(parent)
{
this->setFrameShape(QFrame::Box);
this->setFixedHeight(FRAME_HEIGHT);
QHBoxLayout *deviceLayout = new QHBoxLayout(this);
deviceLayout->setContentsMargins(LAYOUT_MARGINS);
setLayout(deviceLayout);
deviceLayout->setSpacing(LAYOUT_SPACING);
deviceLabel = new QLabel(this);
dropDownLabel = new DrownLabel(devName, this);
deviceLayout->addWidget(deviceLabel);
deviceLayout->addStretch();
deviceLayout->addWidget(dropDownLabel);
}
DeviceFrame::~DeviceFrame()
{
}
void DeviceFrame::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
painter.setBrush(pal.color(QPalette::Base));
QRect rect = this->rect();
QPainterPath path;
path.addRoundedRect (rect, RADIUS, RADIUS);
QRect temp_rect(rect.left(), rect.top() + rect.height()/2, rect.width(), rect.height()/2);
path.addRect(temp_rect);
painter.drawPath(path);
QFrame::paintEvent(event);
}

View File

@ -0,0 +1,30 @@
#ifndef DEVICEFRAME_H
#define DEVICEFRAME_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>
#include "../component/DrownLabel/drownlabel.h"
class DeviceFrame : public QFrame
{
public:
DeviceFrame(QString devName, QWidget *parent = nullptr);
~DeviceFrame();
public:
//仅设备名称+下拉label
QLabel * deviceLabel = nullptr;
DrownLabel *dropDownLabel = nullptr;
protected:
void paintEvent(QPaintEvent *event);
private:
int frameSize;
};
#endif // DEVICEFRAME_H

View File

@ -0,0 +1,27 @@
#include "itemframe.h"
#include <QPainter>
#define LAYOUT_MARGINS 0,0,0,0
#define MAIN_LAYOUT_MARGINS 0,0,0,0
ItemFrame::ItemFrame(QString devName, QWidget *parent) : QFrame(parent)
{
deviceLanLayout = new QVBoxLayout(this);
deviceLanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
lanItemFrame = new QFrame(this);
lanItemFrame->setFrameShape(QFrame::Shape::NoFrame);
lanItemFrame->setContentsMargins(LAYOUT_MARGINS);
lanItemLayout = new QVBoxLayout(this);
lanItemLayout->setContentsMargins(LAYOUT_MARGINS);
lanItemLayout->setSpacing(0);
deviceLanLayout->setSpacing(0);
setLayout(deviceLanLayout);
lanItemFrame->setLayout(lanItemLayout);
deviceFrame = new DeviceFrame(devName, this);
m_divider = new Divider(this);
deviceLanLayout->addWidget(m_divider);
deviceLanLayout->addWidget(deviceFrame);
deviceLanLayout->addWidget(lanItemFrame);
}

View File

@ -0,0 +1,30 @@
#ifndef ITEMFRAME_H
#define ITEMFRAME_H
#include <QFrame>
#include <QVBoxLayout>
#include "../component/DeviceFrame/deviceframe.h"
#include "wlanitem.h"
#include "../component/Divider/divider.h"
class ItemFrame : public QFrame
{
Q_OBJECT
public:
ItemFrame(QString devName, QWidget *parent = nullptr);
//单设备整体layout
QVBoxLayout * deviceLanLayout = nullptr;
//单设备名称+下拉按钮Frame
Divider * m_divider;
DeviceFrame * deviceFrame = nullptr;
//单设备列表Frame
QFrame * lanItemFrame = nullptr;
//单设备列表layout
QVBoxLayout * lanItemLayout = nullptr;
//单设备item列表
QMap<QString, WlanItem *> itemMap;
//已激活uuid
QString uuid = "";
};
#endif // ITEMFRAME_H

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.ui" line="14"/>
<location filename="../wlanconnect.cpp" line="93"/>
<source>WlanConnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="35"/>
<location filename="../wlanconnect.cpp" line="164"/>
<source>WLAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="94"/>
<location filename="../wlanconnect.cpp" line="166"/>
<source>open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/wlanconnect/open</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.ui" line="147"/>
<location filename="../wlanconnect.cpp" line="163"/>
<source>Advanced settings</source>
<translation type="unfinished"></translation>
<extra-contents_path>/wlanconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.cpp" line="76"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="79"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="188"/>
<source>No wireless network card detected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="326"/>
<location filename="../wlanconnect.cpp" line="916"/>
<location filename="../wlanconnect.cpp" line="980"/>
<source>connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="869"/>
<source>card</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.ui" line="14"/>
<location filename="../wlanconnect.cpp" line="93"/>
<source>WlanConnect</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="35"/>
<location filename="../wlanconnect.cpp" line="164"/>
<source>WLAN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="94"/>
<location filename="../wlanconnect.cpp" line="166"/>
<source>open</source>
<translation type="unfinished"></translation>
<extra-contents_path>/wlanconnect/open</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.ui" line="147"/>
<location filename="../wlanconnect.cpp" line="163"/>
<source>Advanced settings</source>
<translation type="unfinished"></translation>
<extra-contents_path>/wlanconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.cpp" line="76"/>
<source>ukui control center</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="79"/>
<source>ukui control center desktop message</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="188"/>
<source>No wireless network card detected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="326"/>
<location filename="../wlanconnect.cpp" line="916"/>
<location filename="../wlanconnect.cpp" line="980"/>
<source>connected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="869"/>
<source>card</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

Binary file not shown.

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>WlanConnect</name>
<message>
<location filename="../wlanconnect.ui" line="14"/>
<location filename="../wlanconnect.cpp" line="93"/>
<source>WlanConnect</source>
<translation>线</translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="35"/>
<location filename="../wlanconnect.cpp" line="164"/>
<source>WLAN</source>
<translation>线</translation>
</message>
<message>
<location filename="../wlanconnect.ui" line="94"/>
<location filename="../wlanconnect.cpp" line="166"/>
<source>open</source>
<translation></translation>
<extra-contents_path>/wlanconnect/open</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.ui" line="147"/>
<location filename="../wlanconnect.cpp" line="163"/>
<source>Advanced settings</source>
<translation></translation>
<extra-contents_path>/wlanconnect/Advanced settings&quot;</extra-contents_path>
</message>
<message>
<location filename="../wlanconnect.cpp" line="76"/>
<source>ukui control center</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="79"/>
<source>ukui control center desktop message</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="188"/>
<source>No wireless network card detected</source>
<translation>线</translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="326"/>
<location filename="../wlanconnect.cpp" line="916"/>
<location filename="../wlanconnect.cpp" line="980"/>
<source>connected</source>
<translation></translation>
</message>
<message>
<location filename="../wlanconnect.cpp" line="869"/>
<source>card</source>
<translation></translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,944 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "wlanconnect.h"
#include <QGSettings>
#include <QProcess>
#include <QTimer>
#include <QtDBus>
#include <QDir>
#include <QDebug>
#include <QtAlgorithms>
#define SCANTIMER 20 * 1000
#define UPDATETIMER 10 * 1000
#define SPACING 8
const QString KWifiSymbolic = "network-wireless-signal-excellent";
const QString KWifiLockSymbolic = "network-wireless-secure-signal-excellent";
const QString KWifiGood = "network-wireless-signal-good";
const QString KWifiLockGood = "network-wireless-secure-signal-good";
const QString KWifiOK = "network-wireless-signal-ok";
const QString KWifiLockOK = "network-wireless-secure-signal-ok";
const QString KWifiLow = "network-wireless-signal-low";
const QString KWifiLockLow = "network-wireless-secure-signal-low";
const QString KWifiNone = "network-wireless-signal-none";
const QString KWifiLockNone = "network-wireless-secure-signal-none";
const QString KApSymbolic = "network-wireless-hotspot-symbolic";
const QString IsApConnection = "1";
#define NO_MARGINS 0,0,0,0
#define TOP_MARGINS 0,8,0,0
#define MAIN_LAYOUT_MARGINS 0,0,0,0
#define MAIN_LAYOUT_SPACING 0
#define TITLE_FRAME_HEIGHT 50 //TabWidget的tab和widget有间隙和设计稿看起来一致就不能设为设计稿里的高度
#define TITLE_LAYOUT_MARGINS 24,0,24,0
bool intThan(int sign1, int sign2)
{
return sign1 < sign2;
}
testWidget::testWidget(QWidget *parent) : QWidget(parent)
{
this->setFixedSize(400, 200);
layout = new QVBoxLayout(this);
button = new QPushButton(this);
layout->addWidget(button);
this->setLayout(layout);
}
void WlanConnect::showDesktopNotify(const QString &message)
{
QDBusInterface iface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
QDBusConnection::sessionBus());
QList<QVariant> args;
args<<(tr("ukui control center"))
<<((unsigned int) 0)
<<QString("/usr/share/icons/ukui-icon-theme-default/24x24/devices/gnome-dev-ethernet.png")
<<tr("ukui control center desktop message") //显示的是什么类型的信息
<<message //显示的具体信息
<<QStringList()
<<QVariantMap()
<<(int)-1;
iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args);
}
WlanConnect::WlanConnect() : m_firstLoad(true)
{
qRegisterMetaType<KyWirelessConnectSetting>("KyWirelessConnectSetting");
qRegisterMetaType<KySecuType>("KySecuType");
}
WlanConnect::~WlanConnect()
{
// if (!m_firstLoad) {
// delete m_switchGsettings;
// m_switchGsettings = nullptr;
// }
}
QWidget *WlanConnect::pluginUi() {
if (m_firstLoad) {
m_firstLoad = false;
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
pluginWidget->setFixedSize(420, 436);
initUi();
initComponent();
initConnect();
}
return pluginWidget;
}
//void WlanConnect::setParentWidget(QWidget* widget){
// parentWidget = widget;
// qDebug() << "setParentWidget!!!!";
//}
void WlanConnect::setPluginType(PluginType type)
{
if (type == SIMPLE) {
m_isSimpleMode = true;
} else {
m_isSimpleMode = false;
}
}
void WlanConnect::initUi()
{
pluginWidget->setFixedSize(420,436);
thread = new QThread;
manager = new KyNetworkManager();
manager->moveToThread(thread);
thread->start();
m_mainLayout = new QVBoxLayout(pluginWidget);
m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
pluginWidget->setLayout(m_mainLayout);
m_titleFrame = new QFrame(pluginWidget);
m_titleFrame->setFixedHeight(53);
m_titleLayout = new QHBoxLayout(m_titleFrame);
m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_titleLabel = new QLabel(m_titleFrame);
m_titleLabel->setText(tr("WLAN"));
m_wirelessSwitch = new KSwitchButton(pluginWidget);
m_wirelessSwitch->installEventFilter(this);
m_titleLayout->addWidget(m_titleLabel);
m_titleLayout->addStretch();
m_titleLayout->addWidget(m_wirelessSwitch);
m_titleDivider = new Divider(pluginWidget);
m_titleDivider->hide();
m_scrollFrame = new QFrame(pluginWidget);
if (m_isSimpleMode) {
m_scrollFrame->setFixedHeight(383);
} else {
m_scrollFrame->setFixedHeight(330);
}
m_scrollLayout = new QVBoxLayout(m_scrollFrame);
m_scrollLayout->setContentsMargins(0,0,0,0);
m_scrollLayout->setSpacing(0);
m_scrollFrame->setLayout(m_scrollLayout);
m_scrollArea = new QScrollArea(m_scrollFrame);
m_scrollArea->setFrameShape(QFrame::Shape::NoFrame);
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setBackgroundRole(QPalette::Base);
m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_scrollLayout->addWidget(m_scrollArea);
m_listWidget = new QWidget(pluginWidget);
m_listWidget->setFixedWidth(420);
m_scrollAreaLayout = new QVBoxLayout(m_listWidget);
m_scrollAreaLayout->setSpacing(MAIN_LAYOUT_SPACING);
m_scrollAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_scrollAreaLayout->setAlignment(Qt::AlignTop);
m_listWidget->setLayout(m_scrollAreaLayout);
m_scrollArea->setWidget(m_listWidget);
m_settingsDivider = new Divider(pluginWidget);
m_settingsFrame = new QFrame(pluginWidget);
m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_settingsLayout = new QHBoxLayout(m_settingsFrame);
m_settingsLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_settingsLabel = new KBorderlessButton(m_settingsFrame);
m_settingsLabel->setCursor(Qt::PointingHandCursor);
m_settingsLabel->setText(tr("Settings"));
m_settingsLayout->addWidget(m_settingsLabel);
m_settingsLayout->addStretch();
m_settingsFrame->setLayout(m_settingsLayout);
m_mainLayout->addWidget(m_titleFrame);
m_mainLayout->addWidget(m_titleDivider);
m_mainLayout->addWidget(m_scrollFrame);
if (!m_isSimpleMode) {
m_mainLayout->addStretch();
m_mainLayout->addWidget(m_settingsDivider);
m_mainLayout->addWidget(m_settingsFrame);
} else {
m_settingsDivider->hide();
m_settingsFrame->hide();
}
QPalette pal = m_scrollArea->palette();
pal.setBrush(QPalette::Base, QColor(0,0,0,0)); //背景透明
m_scrollArea->setPalette(pal);
}
bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
if (w == m_wirelessSwitch && e->type() == QEvent::MouseButtonRelease) {
// testWidget* cc = new testWidget(parentWidget);
// cc->move((parentWidget->width() - cc->width())/2,
// (parentWidget->height() - cc->height())/2);
// cc->show();
// cc->raise();
// qDebug() << "show testWidget!!!!!!!!" << (parentWidget->width() - cc->width())/2 << (parentWidget->height() - cc->height())/2;
if (!m_wirelessSwitch->isCheckable()) {
showDesktopNotify(tr("No wireless device avaliable"));
} else {
Q_EMIT setWirelessNetworkEnabled(!m_wirelessSwitch->isChecked());
}
return true;
}
return QObject::eventFilter(w,e);
}
void WlanConnect::initComponent() {
m_wirelessSwitch->blockSignals(true);
m_wirelessSwitch->setChecked(manager->getWirelessEnabled());
m_wirelessSwitch->blockSignals(false);
getDeviceList(deviceList);
if (deviceList.isEmpty()) {
qDebug() << "[WlanConnect]no device exist when init, set switch disable";
m_wirelessSwitch->setCheckable(false);
m_wirelessSwitch->setChecked(false);
qDebug() << "m_wirelessSwitch setCheckable setChecked" << false;
}
initNet();
if (!m_wirelessSwitch->isChecked() || deviceList.isEmpty()) {
hideLayout(m_scrollAreaLayout);
m_titleDivider->show();
}
connect(m_settingsLabel, &KBorderlessButton::clicked, this, [=]() {
runExternalApp();
});
//定时20s扫描
m_scanTimer = new QTimer(this);
m_scanTimer->start(SCANTIMER);
connect(m_scanTimer, &QTimer::timeout, this, &WlanConnect::reScan);
reScan();
//10s重新排序
m_updateTimer = new QTimer(this);
m_updateTimer->start(UPDATETIMER);
connect(m_updateTimer, &QTimer::timeout, this, &WlanConnect::updateList);
reScan();
}
void WlanConnect::initConnect()
{
connect(manager, &KyNetworkManager::wirelessStateChange, this, &WlanConnect::onActiveConnectionChanged);
connect(manager, &KyNetworkManager::deviceStateChange, this, &WlanConnect::onDeviceStatusChanged);
connect(manager, &KyNetworkManager::wifiEnabledChanged, this, &WlanConnect::onWifiEnabledChanged);
connect(manager, &KyNetworkManager::secuTypeChange, this, &WlanConnect::onNetworkSecuTypeChange);
connect(manager, &KyNetworkManager::wirelessConnectionRemove, this, &WlanConnect::onWirelessConnectionRemove);
connect(manager, &KyNetworkManager::wirelessConnectionAdd, this, &WlanConnect::onWirelessConnectionAdd);
connect(manager, &KyNetworkManager::wirelessConnectionUpdate, this, &WlanConnect::onWirelessConnectionUpdate);
connect(manager, &KyNetworkManager::wirelessDeviceAdd, this, &WlanConnect::onWirelessDeviceAdd);
connect(manager, &KyNetworkManager::wirelessDeviceRemove, this, &WlanConnect::onWirelessDeviceRemove);
connect(manager, &KyNetworkManager::wirelessDeviceNameUpdate, this, &WlanConnect::onDeviceNameChanged);
connect(manager, &KyNetworkManager::wifiNetworkAdd, this, &WlanConnect::onNetworkAdd);
connect(manager, &KyNetworkManager::wifiNetworkRemove, this, &WlanConnect::onNetworkRemove);
connect(manager, &KyNetworkManager::wifiNetworkUpdate, this, &WlanConnect::onNetworkUpdate);
connect(this, &WlanConnect::requestWirelessScan, manager, &KyNetworkManager::onRequestWirelessScan);
connect(this, &WlanConnect::activateConnection, manager, &KyNetworkManager::onActivateConnection);
connect(this, &WlanConnect::deactivateConnection, manager, &KyNetworkManager::onDeactivateConnection);
connect(this,&WlanConnect::addAndActivateNormalWifi, manager, &KyNetworkManager::onAddAndActivateNormalWifi);
connect(this, &WlanConnect::setWirelessNetworkEnabled, manager, &KyNetworkManager::onSetWirelessNetworkEnabled);
}
void WlanConnect::reScan()
{
Q_EMIT requestWirelessScan();
}
//更新列表顺序 ->从so中重新拿 然后插+更新icon
void WlanConnect::updateList()
{
if (!m_wirelessSwitch->isChecked()) {
return;
}
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
resortWifiList(deviceFrameMap[iter.key()], iter.key());
}
}
void WlanConnect::resortWifiList(ItemFrame *frame, QString devName)
{
qDebug() << "resortWifiList" << devName;
if(nullptr == frame || frame->lanItemLayout->count() <= 0) {
return;
}
int frameIndex = 0;
QString activateSsid = "";
QList<KyActivateItem> connectItemList;
qDebug() << "0";
manager->getActiveConnectionList(devName, CONNECT_TYPE_WIRELESS, connectItemList);
qDebug() << "1";
QList<KyWirelessNetItem> list;
manager->getWifiNetworkList(devName, list);
qDebug() << "2";
for (int i = 0; i < connectItemList.size(); ++i) {
if (connectItemList.at(i).m_connStatus == CONNECT_STATE_ACTIVATED) {
activateSsid = connectItemList.at(i).m_ssid;
for (int i = 0; i < list.size(); ++i) {
if (list.at(i).m_NetSsid == activateSsid) {
updateIcon(frame->itemMap[list.at(i).m_NetSsid],
list.at(i).m_signalStrength,
list.at(i).m_secuType,
list.at(i).m_isApConnection);
break;
}
}
frameIndex++;
qDebug() << "resortWifiList no" << frameIndex << activateSsid << list.at(i).m_signalStrength;
break;
}
}
for (int listIndex = 0; listIndex < list.size(); ++listIndex) {
if (frameIndex > frame->lanItemLayout->count() - 1) {
return;
}
if (frame->itemMap.contains(list.at(listIndex).m_NetSsid) && list.at(listIndex).m_NetSsid != activateSsid) {
frame->lanItemLayout->removeWidget(frame->itemMap[list.at(listIndex).m_NetSsid]);
frame->lanItemLayout->insertWidget(frameIndex, frame->itemMap[list.at(listIndex).m_NetSsid]);
if (!frame->itemMap[list.at(listIndex).m_NetSsid]->getIsLoading()) {
updateIcon(frame->itemMap[list.at(listIndex).m_NetSsid],
list.at(listIndex).m_signalStrength,
list.at(listIndex).m_secuType,
list.at(listIndex).m_isApConnection);
}
frameIndex++;
qDebug() << "resortWifiList no" << frameIndex << list.at(listIndex).m_NetSsid << list.at(listIndex).m_signalStrength;
} else {
qDebug() << "not find " << list.at(listIndex).m_NetSsid << " in current list, ignore";
}
}
qDebug() << "resort finish";
}
void WlanConnect::updateIcon(WlanItem *item, int signalStrength, QString security, bool isApConnection)
{
qDebug() << "updateIcon" << item->getName();
int sign = setSignal(signalStrength);
bool isLock = true;
if (security.isEmpty()) {
isLock = false;
} else {
isLock = true;
}
QString iconamePath;
if (isApConnection) {
iconamePath = KApSymbolic;
} else {
iconamePath = wifiIcon(isLock, sign);
}
QIcon searchIcon = QIcon::fromTheme(iconamePath);
item->setItemIcon(searchIcon.pixmap(searchIcon.actualSize(QSize(16,16))));
qDebug() << "updateIcon" << item->getName() << " finish";
}
//device status change
void WlanConnect::onDeviceStatusChanged()
{
}
void WlanConnect::onDeviceNameChanged(QString oldName, QString newName)
{
if (!deviceFrameMap.contains(oldName) || !deviceList.contains(oldName)) {
qWarning() << "[WlanConnect]onDeviceNameChanged no such device " << oldName;
return;
}
if (deviceFrameMap.contains(newName) && deviceList.contains(newName)) {
qWarning() << "[WlanConnect]onDeviceNameChanged already has device " << newName;
return;
}
removeDeviceFrame(oldName);
getDeviceList(deviceList);
if (deviceList.contains(newName)) {
addDeviceFrame(newName);
initNetListFromDevice(newName);
}
}
//activeconnect status change
void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, KyConnectState status)
{
qDebug() << "onActiveConnectionChanged" << ssid << status;
if (!m_wirelessSwitch->isChecked()) {
return;
}
if (uuid.isEmpty()) {
return;
}
WlanItem * item= nullptr;
//device ssid 有可能均为空
if (deviceName.isEmpty() || ssid.isEmpty()) {
if (status == CONNECT_STATE_ACTIVATING || status == CONNECT_STATE_ACTIVATED) {
return;
}
QMap<QString, ItemFrame*>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (uuid == iter.value()->uuid) {
QMap<QString, WlanItem*>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
if (itemIter.value()->getUuid() == uuid ) {
item = itemIter.value();
break;
}
}
break;
}
}
} else {
if (!deviceFrameMap.contains(deviceName)) {
return;
}
for (int i = 0; i < deviceFrameMap[deviceName]->itemMap.size(); ++i) {
if (deviceFrameMap[deviceName]->itemMap.contains(ssid)) {
item = deviceFrameMap[deviceName]->itemMap[ssid];
if (status == CONNECT_STATE_ACTIVATED || status == CONNECT_STATE_ACTIVATING) {
deviceFrameMap[deviceName]->itemMap[ssid]->setUuid(uuid);
deviceFrameMap[deviceName]->uuid = uuid;
if (status == CONNECT_STATE_ACTIVATED) {
deviceFrameMap[deviceName]->lanItemLayout->removeWidget(item);
deviceFrameMap[deviceName]->lanItemLayout->insertWidget(0,item);
}
} else if (status == CONNECT_STATE_DEACTIVATED) {
deviceFrameMap[deviceName]->uuid.clear();
}
break;
}
}
}
if (nullptr != item) {
qDebug() << "itemActiveConnectionStatusChanged" << ssid << status;
itemActiveConnectionStatusChanged(item, status);
QList<KyWirelessNetItem> list;
manager->getWifiNetworkList(deviceName, list);
for (int i = 0; i < list.size(); ++i) {
if (list.at(i).m_NetSsid == ssid) {
updateIcon(item,list.at(i).m_signalStrength,list.at(i).m_secuType,list.at(i).m_isApConnection);
break;
}
}
}
}
//wifi add==============================================================
void WlanConnect::onNetworkAdd(QString deviceName, KyWirelessNetItem wlanInfo)
{
qDebug()<<"[WlanConnect]onNetworkAdd "<< deviceName << " " << wlanInfo.m_NetSsid;
if(!m_wirelessSwitch->isChecked() || deviceName.isEmpty()) {
return;
}
if (!deviceList.contains(deviceName)) {
qDebug() << "[WlanConnect]onNetworkAdd not contain " << deviceName << "then add";
deviceList.append(deviceName);
addDeviceFrame(deviceName);
onNetworkAdd(deviceName, wlanInfo);
return;
}
// if (m_isSimpleMode && wlanInfo.m_secuType.indexOf("802.1X") != -1) {
// //锁屏 登录界面暂不实现企业网连接
// return;
// }
insertOneWlanFrame(deviceFrameMap[deviceName], deviceName, wlanInfo);
}
//wifi remove =============================================================
void WlanConnect::onNetworkRemove(QString deviceName, QString wlannName)
{
//当前无此设备 忽略
if (deviceName.isEmpty() || !deviceFrameMap.contains(deviceName)) {
qDebug() << "[WlanConnect]recieve network remove,but no such device:" << deviceName;
return;
}
qDebug()<<"[WlanConnect]Wifi remove device:" << deviceName << ",wlan name:" << wlannName;
removeOneWlanFrame(deviceFrameMap[deviceName], deviceName, wlannName);
}
//wifi secu Update =============================================================
void WlanConnect::onNetworkUpdate(QString deviceName, QString wlannName, KyWirelessNetItem item)
{
//当前无此设备 忽略
if (deviceName.isEmpty() || !deviceFrameMap.contains(deviceName)) {
qDebug() << "[WlanConnect]recieve network update,but no such device:" << deviceName;
return;
}
qDebug()<<"[WlanConnect]Wifi update device:" << deviceName << ",wlan name:" << wlannName;
// if (m_isSimpleMode && item.m_secuType.indexOf("802.1X") != -1) {
//锁屏 登录界面暂不实现企业网连接
// removeOneWlanFrame(deviceFrameMap[deviceName], deviceName, item.m_NetSsid);
// }
bool isFind = false;
QMap<QString, WlanItem*>::iterator itemIter;
for (itemIter = deviceFrameMap[deviceName]->itemMap.begin(); itemIter != deviceFrameMap[deviceName]->itemMap.end(); ++itemIter) {
if (itemIter.value()->getName() == wlannName) {
itemIter.value()->setSecuType(item.m_secuType);
isFind = true;
break;
}
}
if (!isFind) {
//由企业网变为非企业网,则重新添加
// if (m_isSimpleMode && item.m_secuType.indexOf("802.1X") == -1) {
insertOneWlanFrame(deviceFrameMap[deviceName], deviceName, item);
// }
}
}
//获取设备列表=======================================================
void WlanConnect::getDeviceList(QStringList &list)
{
manager->getNetworkDeviceList(DEVICE_TYPE_WIFI, list);
}
//设置开关
void WlanConnect::setSwitchStatus(bool status)
{
m_wirelessSwitch->blockSignals(true);
m_wirelessSwitch->setChecked(status);
m_wirelessSwitch->blockSignals(false);
if (!m_wirelessSwitch->isChecked()) {
hideLayout(m_scrollAreaLayout);
m_titleDivider->show();
} else {
showLayout(m_scrollAreaLayout);
m_titleDivider->hide();
}
}
//初始化整体列表和单设备列表
void WlanConnect::initNet() {
//先构建每个设备的列表头
qDebug() << deviceList <<deviceList.size();
for (int i = 0; i < deviceList.size(); ++i) {
addDeviceFrame(deviceList.at(i));
}
//再填充每个设备的列表
for (int i = 0; i < deviceList.size(); ++i) {
initNetListFromDevice(deviceList.at(i));
}
}
//初始化设备列表
void WlanConnect::initNetListFromDevice(QString deviceName)
{
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName;
if (!m_wirelessSwitch->isChecked()) {
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " switch off";
return;
}
if (!deviceFrameMap.contains(deviceName)) {
qDebug() << "[WlanConnect]initNetListFromDevice " << deviceName << " not exist";
return;
}
QList<KyWirelessNetItem> list;
manager->getWifiNetworkList(deviceName, list);
for (int i = 0; i < list.size(); ++i) {
// if (m_isSimpleMode && list.at(i).m_secuType.indexOf("802.1X") != -1) {
// //锁屏 登录界面暂不实现企业网连接
// continue;
// }
KyWirelessNetItem item = list.at(i);
addOneWlanFrame(deviceFrameMap[deviceName], deviceName, item);
}
QList<KyActivateItem> activateList;
manager->getActiveConnectionList(deviceName, CONNECT_TYPE_WIRELESS, activateList);
if (activateList.size() != 0) {
onActiveConnectionChanged(deviceName,activateList.at(0).m_ssid, activateList.at(0).m_uuid, activateList.at(0).m_connStatus);
}
}
//高级设置
void WlanConnect::runExternalApp() {
QProcess process;
process.startDetached("ukui-control-center -m wlanconnect");
}
//根据信号强度分级+安全性分图标
QString WlanConnect::wifiIcon(bool isLock, int strength) {
switch (strength) {
case 1:
return isLock ? KWifiLockSymbolic : KWifiSymbolic;
case 2:
return isLock ? KWifiLockGood : KWifiGood;
case 3:
return isLock ? KWifiLockOK : KWifiOK;
case 4:
return isLock ? KWifiLockLow : KWifiLow;
case 5:
return isLock ? KWifiLockNone : KWifiNone;
default:
return "";
}
}
//根据信号强度分级
int WlanConnect::setSignal(int signal) {
int signalLv = 0;
if (signal > 75) {
signalLv = 1;
} else if (signal > 55 && signal <= 75) {
signalLv = 2;
} else if (signal > 35 && signal <= 55) {
signalLv = 3;
} else if (signal > 15 && signal <= 35) {
signalLv = 4;
} else if (signal <= 15) {
signalLv = 5;
}
return signalLv;
}
//隐藏
void WlanConnect::hideLayout(QVBoxLayout * layout) {
for (int i = layout->layout()->count()-1; i >= 0; --i) {
QLayoutItem *it = layout->layout()->itemAt(i);
ItemFrame *itemFrame = qobject_cast<ItemFrame *>(it->widget());
itemFrame->hide();
}
}
//显示
void WlanConnect::showLayout(QVBoxLayout * layout) {
for (int i = layout->layout()->count()-1; i >= 0; --i) {
QLayoutItem *it = layout->layout()->itemAt(i);
ItemFrame *itemFrame = qobject_cast<ItemFrame *>(it->widget());
itemFrame->show();
}
}
//获取应该插入哪个位置
int WlanConnect::sortWlanNet(QString deviceName, QString name, QString signal)
{
return 0;
}
//增加设备
void WlanConnect::addDeviceFrame(QString devName)
{
qDebug() << "[WlanConnect]addDeviceFrame " << devName;
ItemFrame *itemFrame = new ItemFrame(devName, pluginWidget);
m_scrollAreaLayout->addWidget(itemFrame);
itemFrame->deviceFrame->deviceLabel->setText(devName);
deviceFrameMap.insert(devName, itemFrame);
}
//减少设备
void WlanConnect::removeDeviceFrame(QString devName)
{
qDebug() << "[WlanConnect]removeDeviceFrame " << devName;
if (deviceFrameMap.contains(devName)) {
ItemFrame *item = deviceFrameMap[devName];
if (item->lanItemFrame->layout() != NULL) {
QLayoutItem* layoutItem;
while ((layoutItem = item->lanItemFrame->layout()->takeAt(0)) != NULL) {
delete layoutItem->widget();
delete layoutItem;
item = nullptr;
}
item->itemMap.clear();
}
delete item;
item = nullptr;
deviceFrameMap.remove(devName);
}
getDeviceList(deviceList);
}
//增加ap
void WlanConnect::addOneWlanFrame(ItemFrame *frame, QString deviceName, KyWirelessNetItem &wlanInfo)
{
if (nullptr == frame) {
return;
}
if (frame->itemMap.contains(wlanInfo.m_NetSsid)) {
qDebug() << "[WlanConnect]Already exist a wifi " << wlanInfo.m_NetSsid << " in " << deviceName;
return;
}
//设置单项的信息
int sign = setSignal(wlanInfo.m_signalStrength);
WlanItem * wlanItem = new WlanItem(m_isSimpleMode, pluginWidget);
QString iconamePath;
if (wlanInfo.m_isApConnection) {
iconamePath = KApSymbolic;
} else {
iconamePath = wifiIcon(!wlanInfo.m_secuType.isEmpty(), sign);
}
QIcon searchIcon = QIcon::fromTheme(iconamePath);
wlanItem->setItemIcon(searchIcon.pixmap(searchIcon.actualSize(QSize(16,16))));
wlanItem->setName(wlanInfo.m_NetSsid);
wlanItem->setSecuType(wlanInfo.m_secuType);
wlanItem->setUuid(wlanInfo.m_connectUuid);
wlanItem->setPath(wlanInfo.m_dbusPath);
wlanItem->setInterface(deviceName);
connect(wlanItem, &WlanItem::infoButtonClick, this, [=]{
//todo 详情页
});
connect(wlanItem, &WlanItem::itemClick, this, [=] {
if (wlanItem->getStatus() || wlanItem->getIsLoading()) {
Q_EMIT deactivateConnection(wlanItem->getUuid());
} else {
if (wlanItem->getExpend()) {
wlanItem->setExpend(false);
} else {
//先看加密类型 再看是否已有配置
if (!wlanItem->getUuid().isEmpty()) {
activateConnection(wlanItem->getUuid(), wlanItem->getInterface());
} else {
if (wlanItem->getSecuType().isEmpty()) {
KyWirelessConnectSetting sett;
KySecuType secuType = KySecuType::NONE;
sett.m_ssid = wlanItem->getName();
sett.m_ifaceName = wlanItem->getInterface();
Q_EMIT addAndActivateNormalWifi(sett, secuType);
} else {
if (wlanItem->getSecuType().indexOf("802.1X") != -1) {
//todo 企业网页面
} else {
wlanItem->setExpend(true);
setOtherItemExpandedFalse(deviceName, wlanInfo.m_NetSsid);
}
}
}
}
}
});
connect(wlanItem, &WlanItem::connectButtonClick, this, [=](QString password, bool isAutoConnect) {
KySecuType secuType;
if (wlanItem->getSecuType().indexOf("WPA3")) {
secuType = KySecuType::WPA3_PERSONAL;
} else {
secuType = KySecuType::WPA_AND_WPA2_PERSONAL;
}
KyWirelessConnectSetting sett;
sett.m_ssid = wlanItem->getName();
sett.m_psk = password;
sett.m_isAutoConnect = isAutoConnect;
sett.m_ifaceName = wlanItem->getInterface();
Q_EMIT addAndActivateNormalWifi(sett, secuType);
wlanItem->setExpend(false);
});
//记录到deviceFrame的itemMap中
deviceFrameMap[deviceName]->itemMap.insert(wlanInfo.m_NetSsid, wlanItem);
qDebug()<<"add " << wlanInfo.m_NetSsid << " to " << deviceName << " list";
frame->lanItemLayout->addWidget(wlanItem);
}
//减少ap
void WlanConnect::removeOneWlanFrame(ItemFrame *frame, QString deviceName, QString ssid)
{
if (nullptr == frame) {
return;
}
if (frame->itemMap.contains(ssid)) {
qDebug() << "[WlanConnect]removeOneWlanFrame " << deviceName << ssid;
frame->lanItemLayout->removeWidget(frame->itemMap[ssid]);
delete frame->itemMap[ssid];
frame->itemMap.remove(ssid);
}
}
void WlanConnect::insertOneWlanFrame(ItemFrame *frame, QString devName, KyWirelessNetItem &wlanInfo)
{
addOneWlanFrame(frame, devName, wlanInfo);
}
void WlanConnect::itemActiveConnectionStatusChanged(WlanItem *item, int status)
{
if (status == CONNECT_STATE_ACTIVATING) {
item->startLoading();
} else if (status == CONNECT_STATE_ACTIVATED) {
item->stopLoading();
item->setStatus(true);
} else if (status == CONNECT_STATE_DEACTIVATING) {
item->startLoading();
} else if (status == CONNECT_STATE_DEACTIVATED) {
item->stopLoading();
item->setStatus(false);
}
}
void WlanConnect::onNetworkSecuTypeChange(QString deviceName, QString ssid, QString securityType)
{
Q_UNUSED(deviceName)
Q_UNUSED(ssid)
Q_UNUSED(securityType)
}
void WlanConnect::onWifiEnabledChanged(bool status)
{
// if (m_wirelessSwitch->isCheckable()) {
setSwitchStatus(status);
// }
}
void WlanConnect::onWirelessConnectionRemove(QString deviceName, QString ssid)
{
qDebug() << "onWirelessConnectionRemove" << deviceName << ssid;
WlanItem *item = findItem(deviceName,ssid);
if (nullptr == item) {
return;
}
if (item->getStatus()) {
onActiveConnectionChanged(deviceName, ssid, item->getUuid(), CONNECT_STATE_DEACTIVATED);
}
item->setUuid("");
item->setPath("");
}
void WlanConnect::onWirelessConnectionAdd(QString deviceName, QString ssid, QString uuid, QString dbusPath)
{
qDebug() << "onWirelessConnectionAdd" << deviceName << ssid;
WlanItem *item = findItem(deviceName,ssid);
if (nullptr == item) {
return;
}
if (!item->getUuid().isEmpty()
&& !item->getPath().isEmpty())
item->setUuid(uuid);
item->setPath(dbusPath);
}
void WlanConnect::onWirelessConnectionUpdate(QString deviceName, QString ssid, QString uuid, QString dbusPath, KySecuType connectSecuType)
{
}
void WlanConnect::onWirelessDeviceAdd(QString deviceName)
{
addDeviceFrame(deviceName);
if (manager->getWirelessEnabled()) {
setSwitchStatus(true);
m_wirelessSwitch->setCheckable(true);
}
}
void WlanConnect::onWirelessDeviceRemove(QString deviceName)
{
removeDeviceFrame(deviceName);
if (deviceList.isEmpty()) {
setSwitchStatus(false);
m_wirelessSwitch->setCheckable(false);
}
}
WlanItem* WlanConnect::findItem(QString devName, QString ssid)
{
if (!deviceFrameMap.contains(devName)) {
return nullptr;
}
if (!deviceFrameMap[devName]->itemMap.contains(ssid)) {
return nullptr;
}
return deviceFrameMap[devName]->itemMap[ssid];
}
void WlanConnect::setOtherItemExpandedFalse(QString devName, QString ssid)
{
QMap<QString, ItemFrame *>::iterator iter;
for (iter = deviceFrameMap.begin(); iter != deviceFrameMap.end(); iter++) {
if (iter.key() != devName) {
QMap<QString, WlanItem *>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
itemIter.value()->setExpend(false);
}
} else {
QMap<QString, WlanItem *>::iterator itemIter;
for (itemIter = iter.value()->itemMap.begin(); itemIter != iter.value()->itemMap.end(); itemIter++) {
if (itemIter.value()->getName() != ssid) {
itemIter.value()->setExpend(false);
}
}
}
}
}

View File

@ -0,0 +1,212 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef WLANCONNECT_H
#define WLANCONNECT_H
#include "kswitchbutton.h"
#include "kborderlessbutton.h"
using namespace kdk;
#include <QObject>
#include <QtPlugin>
#include <QNetworkInterface>
#include <QtNetwork/QNetworkConfigurationManager>
#include <QtNetwork/QtNetwork>
#include <QTimer>
#include <QStringList>
#include <QString>
#include <QGSettings>
#include <QListWidget>
#include <QListWidgetItem>
#include <QMap>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <kylin-nm/kylin-nm-interface.h>
#include <kylin-nm/kylinnetworkmanager.h>
#include "../component/DeviceFrame/deviceframe.h"
#include "itemframe.h"
#include "wlanitem.h"
namespace Ui {
class WlanConnect;
}
class testWidget : public QWidget
{
public:
testWidget(QWidget *parent = nullptr);
private:
QVBoxLayout* layout;
QPushButton* button;
};
class WlanConnect : public QObject, Interface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kylin.network")
Q_INTERFACES(Interface)
public:
WlanConnect();
~WlanConnect();
QWidget * pluginUi() Q_DECL_OVERRIDE; // 插件主界面---setPluginType后调用
void setPluginType(PluginType type) Q_DECL_OVERRIDE; // 设置插件类型
// void setParentWidget(QWidget*);
private:
bool m_isSimpleMode = true;
void initUi();
void initComponent();
void initConnect();
void runExternalApp();
void initSearchText();
void showDesktopNotify(const QString &message);
int sortWlanNet(QString deviceName, QString name, QString signal);
void updateIcon(WlanItem *item, int signalStrength, QString security, bool isApConnection);
void resortWifiList(ItemFrame *frame, QString devName);
//单wifi图标
int setSignal(int lv);
QString wifiIcon(bool isLock, int strength);
//开关相关
void setSwitchStatus(bool status);
void hideLayout(QVBoxLayout * layout);
void showLayout(QVBoxLayout * layout);
//获取设备列表
void getDeviceList(QStringList &list);
//初始化设备wifi列表
void initNet();
void initNetListFromDevice(QString deviceName);
//增加设备
void addDeviceFrame(QString devName);
//减少设备
void removeDeviceFrame(QString devName);
//无序增加ap
void addOneWlanFrame(ItemFrame *frame, QString deviceName, KyWirelessNetItem &wlanInfo);
//减少ap
void removeOneWlanFrame(ItemFrame *frame, QString deviceName, QString ssid);
//有序增加ap
void insertOneWlanFrame(ItemFrame *frame, QString devName, KyWirelessNetItem &wlanInfo);
//单个wifi连接状态变化
void itemActiveConnectionStatusChanged(WlanItem *item, int status);
void setOtherItemExpandedFalse(QString devName, QString ssid);
protected:
bool eventFilter(QObject *w,QEvent *e);
private:
KyNetworkManager* manager;
QThread* thread;
// QWidget* parentWidget = nullptr;
QWidget *pluginWidget;
// QGSettings *m_switchGsettings = nullptr;
//设备列表
QStringList deviceList;
//设备名 + 单设备frame
QMap<QString, ItemFrame *> deviceFrameMap;
QTimer * m_scanTimer = nullptr;
QTimer * m_updateTimer = nullptr;
bool m_firstLoad;
QVBoxLayout* m_mainLayout = nullptr;
QFrame* m_titleFrame = nullptr;
QHBoxLayout* m_titleLayout = nullptr;
QLabel* m_titleLabel = nullptr;
KSwitchButton* m_wirelessSwitch = nullptr;
Divider* m_titleDivider = nullptr;
QFrame* m_scrollFrame = nullptr;
QVBoxLayout* m_scrollLayout = nullptr;
QScrollArea* m_scrollArea = nullptr;
QWidget* m_listWidget = nullptr;
QVBoxLayout* m_scrollAreaLayout = nullptr;
Divider* m_settingsDivider = nullptr;
QFrame* m_settingsFrame = nullptr;
QHBoxLayout* m_settingsLayout = nullptr;
KBorderlessButton* m_settingsLabel = nullptr;
WlanItem* findItem(QString devName, QString ssid);
Q_SIGNALS:
void requestWirelessScan();
void setWirelessNetworkEnabled(bool enabled);
//=======================连接/断开操作====================
void activateConnection(const QString connectUuid, const QString deviceName);
void deactivateConnection(const QString &activeConnectUuid);
//连接无本地配置的非企业网热点
void addAndActivateNormalWifi(KyWirelessConnectSetting connSettingInfo, KySecuType type);
// //连接无本地配置的企业网热点
// void addAndActiveWirelessEnterPriseTlsConnect(KyEapMethodTlsInfo &info,
// KyWirelessConnectSetting &connSettingInfo);
// void addAndActiveWirelessEnterPrisePeapConnect(KyEapMethodPeapInfo &info,
// KyWirelessConnectSetting &connSettingInfo);
// void addAndActiveWirelessEnterPriseTtlsConnect(KyEapMethodTtlsInfo &info,
// KyWirelessConnectSetting &connSettingInfo);
private Q_SLOTS:
void onNetworkAdd(QString deviceName, KyWirelessNetItem wlanInfo);
void onNetworkRemove(QString deviceName, QString wlannName);
void onNetworkUpdate(QString deviceName, QString wlannName, KyWirelessNetItem secuType);
void onActiveConnectionChanged(QString deviceName, QString ssid, QString uuid, KyConnectState status);
void updateList();
void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString);
void reScan();
void onNetworkSecuTypeChange(QString deviceName, QString ssid, QString securityType);
void onWifiEnabledChanged(bool);
void onWirelessConnectionRemove(QString deviceName, QString ssid);
void onWirelessConnectionAdd(QString deviceName, QString ssid, QString uuid, QString dbusPath);
void onWirelessConnectionUpdate(QString deviceName, QString ssid, QString uuid, QString dbusPath, KySecuType connectSecuType);
void onWirelessDeviceAdd(QString deviceName);
void onWirelessDeviceRemove(QString deviceName);
};
#endif // WLANCONNECT_H

View File

@ -0,0 +1,44 @@
QT += widgets network dbus gui core
TEMPLATE = lib
CONFIG += plugin
include(../component/infobutton.pri)
include(../component/divider.pri)
include(../component/deviceframe.pri)
TARGET = $$qtLibraryTarget(wlanconnect)
DESTDIR = ../..
target.path = /usr/lib/kylin-nm
INCLUDEPATH += \
$$PROJECT_COMPONENTSOURCE \
$$PROJECT_ROOTDIR \
LIBS += -L$$[QT_INSTALL_LIBS] -lkylin-nm-base
CONFIG += c++11 \
link_pkgconfig \
no_keywords
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
kylin-nm-base
#DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
itemframe.cpp \
wlanconnect.cpp \
wlanitem.cpp
HEADERS += \
itemframe.h \
wlanconnect.h \
wlanitem.h
INSTALLS += target \
TRANSLATIONS += \
translations/zh_CN.ts \
translations/tr.ts \
translations/bo.ts

View File

@ -0,0 +1,210 @@
#include "wlanitem.h"
#include <QPainter>
#include <QRegExpValidator>
#define FRAME_SPEED 150
#define LIMIT_TIME 60*1000
#define TOTAL_PAGE 8
#define RADIUS 6.0
#define THEME_QT_SCHEMA "org.ukui.style"
#define MODE_QT_KEY "style-name"
#define UNEXPEND_HEIGHT 48
#define EXPEND_HEIGHT 120
WlanItem::WlanItem(bool isSimple, QWidget *parent)
: isSimple(isSimple), QFrame(parent)
{
this->setFixedSize(404, UNEXPEND_HEIGHT);
QVBoxLayout *m_mainLayout = new QVBoxLayout(this);
m_mainLayout->setContentsMargins(8,0,8,0);
m_mainLayout->setSpacing(0);
//icon + name
m_nameFrame = new QFrame(this);
QHBoxLayout *lanLyt = new QHBoxLayout(m_nameFrame);
lanLyt->setContentsMargins(16,8,16,4);
lanLyt->setSpacing(0);
iconLabel = new QLabel(this);
iconLabel->setProperty("useIconHighlightEffect", 0x10);
titileLabel = new QLabel(this);
lanLyt->addWidget(iconLabel);
lanLyt->addSpacing(10);
lanLyt->addWidget(titileLabel,Qt::AlignLeft);
lanLyt->addStretch();
if (!isSimple) {
infoLabel = new InfoButton(this);
lanLyt->addSpacing(8);
lanLyt->addWidget(infoLabel);
connect(infoLabel, &InfoButton::released, this, &WlanItem::infoButtonClick);
}
m_expendFrame = new QFrame(this);
QVBoxLayout *expendnLyt = new QVBoxLayout(m_expendFrame);
expendnLyt->setContentsMargins(40, 0, 16, 0);
expendnLyt->setSpacing(0);
//pwdline + connect Button
m_pwdFrame = new QFrame(m_expendFrame);
m_pwdFrameLyt = new QHBoxLayout(m_pwdFrame);
m_pwdFrameLyt->setContentsMargins(0,0,0,0);
m_pwdFrameLyt->setSpacing(0);
m_pwdFrame->setLayout(m_pwdFrameLyt);
m_pwdLineEdit = new KPasswordEdit(m_pwdFrame);
m_pwdLineEdit->setState(Ordinary);
m_pwdLineEdit->setEchoModeBtnVisible(true);
m_pwdLineEdit->setContextMenuPolicy(Qt::NoContextMenu);
QRegExp rx("^[A-Za-z0-9`~!@#$%^&*()_-+=<>,.\\\/]+$");
QRegExpValidator *latitude = new QRegExpValidator(rx, this);
m_pwdLineEdit->setValidator(latitude);
connect(m_pwdLineEdit, &KPasswordEdit::textChanged, this, &WlanItem::onPwdEditorTextChanged);
m_pwdLineEdit->setFixedSize(228, 36);
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password);
m_pwdFrameLyt->addWidget(m_pwdLineEdit);
m_pwdFrameLyt->addSpacing(8);
m_connectButton = new QPushButton(m_pwdFrame);
m_connectButton->setFixedSize(96, 36);
m_connectButton->setText(tr("Connect"));
m_connectButton->setEnabled(false);
connect(m_connectButton, &QPushButton::clicked, this, &WlanItem::onConnectButtonClicked);
m_pwdFrameLyt->addWidget(m_connectButton);
//自动连接选择区域UI
m_autoConnectFrame = new QFrame(m_expendFrame);
m_autoConnectFrameLyt = new QHBoxLayout(m_autoConnectFrame);
m_autoConnectFrameLyt->setContentsMargins(0,8,150,8);
m_autoConnectFrameLyt->setSpacing(0);
m_autoConnectFrame->setLayout(m_autoConnectFrameLyt);
m_autoConnectCheckBox = new QCheckBox(m_autoConnectFrame);
m_autoConnectCheckBox->setChecked(true);
m_autoConnectCheckBox->setFixedSize(16, 16);
m_autoConnectFrameLyt->addWidget(m_autoConnectCheckBox);
m_autoConnectFrameLyt->addSpacing(8);
m_autoConnectLabel = new QLabel(m_autoConnectFrame);
m_autoConnectLabel->setText(tr("Auto Connect"));
m_autoConnectFrameLyt->addWidget(m_autoConnectLabel);
expendnLyt->addWidget(m_pwdFrame);
expendnLyt->addWidget(m_autoConnectFrame);
m_mainLayout->addWidget(m_nameFrame);
m_mainLayout->addWidget(m_expendFrame);
m_expendFrame->hide();
loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-3-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-4-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-5-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-6-symbolic"));
loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic"));
waitTimer = new QTimer(this);
connect(waitTimer, &QTimer::timeout, this, &WlanItem::updateIcon);
m_menu = new QMenu(this);//右键菜单
connect(m_menu, &QMenu::triggered, this, &WlanItem::itemClick);
}
void WlanItem::updateIcon()
{
if (currentIconIndex > 6) {
currentIconIndex = 0;
}
iconLabel->setPixmap(loadIcons.at(currentIconIndex).pixmap(16,16));
currentIconIndex ++;
}
void WlanItem::startLoading()
{
waitTimer->start(FRAME_SPEED);
m_loading = true;
}
void WlanItem::stopLoading(){
waitTimer->stop();
m_loading = false;
}
void WlanItem::mousePressEvent(QMouseEvent *event)
{
return QFrame::mousePressEvent(event);
}
void WlanItem::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton) {
if (!m_menu) {
return QFrame::mouseReleaseEvent(event);
}
m_menu->clear();
if (m_isAcitve || m_loading) {
m_menu->addAction(new QAction(tr("Disconnect"), this));
} else if (!m_isAcitve && !m_loading) {
m_menu->addAction(new QAction(tr("Connect"), this));
}
m_menu->move(cursor().pos());
m_menu->show();
} else {
if (!m_isAcitve && !m_loading) {
Q_EMIT itemClick();
}
}
return QFrame::mouseReleaseEvent(event);
}
void WlanItem::enterEvent(QEvent *event)
{
return QFrame::enterEvent(event);
}
void WlanItem::leaveEvent(QEvent *event)
{
return QFrame::leaveEvent(event);
}
void WlanItem::paintEvent(QPaintEvent *event)
{
return QFrame::paintEvent(event);
}
void WlanItem::setExpend(bool enable)
{
if (enable) {
this->setFixedHeight(EXPEND_HEIGHT);
m_expendFrame->show();
} else {
m_expendFrame->hide();
this->setFixedHeight(UNEXPEND_HEIGHT);
m_pwdLineEdit->clear();
}
}
bool WlanItem::getExpend()
{
return !m_expendFrame->isHidden();
}
void WlanItem::onPwdEditorTextChanged()
{
if (m_pwdLineEdit->text().length() < 8) {
m_connectButton->setEnabled(false);
} else {
m_connectButton->setEnabled(true);
}
}
void WlanItem::onConnectButtonClicked()
{
connectButtonClick(m_pwdLineEdit->text(), m_autoConnectCheckBox->isChecked());
}

View File

@ -0,0 +1,139 @@
#ifndef WLANITEM_H
#define WLANITEM_H
#include <QObject>
#include <QHBoxLayout>
#include <QLabel>
#include <QTimer>
#include <QDebug>
#include <QImage>
#include <QMouseEvent>
#include <QMenu>
#include <QCheckBox>
#include "../component/InfoButton/infobutton.h"
#include "kpasswordedit.h"
using namespace kdk;
class WlanItem : public QFrame
{
Q_OBJECT
public:
WlanItem(bool isSimple, QWidget *parent = nullptr);
public:
void setName(QString name) {
titileLabel->setText(name);
}
QString getName() {
return titileLabel->text();
}
void setItemIcon(const QPixmap &pixmap) {
iconLabel->setPixmap(pixmap);
}
void setStatus(bool isAcitve){
m_isAcitve = isAcitve;
}
bool getStatus(){
return m_isAcitve;
}
bool getIsLoading() {
return m_loading;
}
QString getUuid(){
return m_uuid;
}
void setUuid(QString uuid){
m_uuid = uuid;
}
QString getPath(){
return m_dbusPath;
}
void setPath(QString dbusPath){
m_dbusPath = dbusPath;
}
QString getSecuType(){
return m_secutype;
}
void setSecuType(QString &secuType){
m_secutype = secuType;
}
QString getInterface(){
return m_interface;
}
void setInterface(QString &interface){
m_interface = interface;
}
void startLoading();
void stopLoading();
void setExpend(bool);
bool getExpend();
Q_SIGNALS:
void itemClick();
void infoButtonClick();
void connectButtonClick(QString , bool);
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void paintEvent(QPaintEvent *event);
private:
QTimer *waitTimer = nullptr;
QList<QIcon> loadIcons;
int currentIconIndex=0;
QMenu *m_menu = nullptr;
QLabel * iconLabel = nullptr;
InfoButton * infoLabel = nullptr;
QLabel * titileLabel = nullptr;
bool isSimple;
bool m_isAcitve = false;
bool m_loading = false;
bool m_isExpand = false;
QString m_uuid = "";
QString m_dbusPath ="";
//ap类型
QString m_secutype = "";
QString m_interface = "";
QFrame* m_nameFrame = nullptr;
QFrame* m_expendFrame = nullptr;
QFrame* m_pwdFrame = nullptr;
QFrame* m_autoConnectFrame = nullptr;
KPasswordEdit* m_pwdLineEdit = nullptr;
QPushButton* m_connectButton = nullptr;
QCheckBox* m_autoConnectCheckBox = nullptr;
QLabel* m_autoConnectLabel = nullptr;
QHBoxLayout* m_autoConnectFrameLyt = nullptr;
QHBoxLayout* m_pwdFrameLyt = nullptr;
private Q_SLOTS:
void updateIcon();
// void onMenuTriggered(QAction *action);
void onPwdEditorTextChanged();
void onConnectButtonClicked();
};
#endif // WLANITEM_H