diff options
author | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-10-04 20:53:17 +0100 |
---|---|---|
committer | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-10-04 20:53:17 +0100 |
commit | be71bf80d290c98c0f6a66d3dcab28515b4ea371 (patch) | |
tree | d936090c5b5c9435febfe220770ff7f25399a235 |
Initial commit
34 files changed, 3329 insertions, 0 deletions
@@ -0,0 +1,675 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://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 <https://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 +<https://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 +<https://www.gnu.org/philosophy/why-not-lgpl.html>. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d8ede1 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# weegtk + +A weechat relay using LibAdwita and Gtk4. Written in Python diff --git a/com.fryzekconcepts.weegtk.json b/com.fryzekconcepts.weegtk.json new file mode 100644 index 0000000..f057400 --- /dev/null +++ b/com.fryzekconcepts.weegtk.json @@ -0,0 +1,136 @@ +{ + "id" : "com.fryzekconcepts.weegtk", + "runtime" : "org.gnome.Platform", + "runtime-version" : "47", + "sdk" : "org.gnome.Sdk", + "command" : "weegtk", + "finish-args" : [ + "--share=network", + "--share=ipc", + "--socket=fallback-x11", + "--device=dri", + "--socket=wayland" + ], + "cleanup" : [ + "/include", + "/lib/pkgconfig", + "/man", + "/share/doc", + "/share/gtk-doc", + "/share/man", + "/share/pkgconfig", + "*.la", + "*.a" + ], + "modules" : [ + { + "name" : "python3-pycparser", + "buildsystem" : "simple", + "build-commands" : [ + "pip install --prefix=/app pycparser-2.22-py3-none-any.whl" + ], + "sources" : [ + { + "type" : "file", + "url" : "https://files.pythonhosted.org/packages/13/a3/a812df4e2dd5696d1f351d58b8fe16a405b234ad2886a0dab9183fb78109/pycparser-2.22-py3-none-any.whl", + "sha256" : "c3702b6d3dd8c7abc1afa565d7e63d53a1d0bd86cdc24edd75470f4de499cfcc" + } + ] + }, + { + "name" : "python3-cffi", + "buildsystem" : "simple", + "build-commands" : [ + "pip install --prefix=/app cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl" + ], + "sources" : [ + { + "type" : "file", + "url" : "https://files.pythonhosted.org/packages/b2/d5/da47df7004cb17e4955df6a43d14b3b4ae77737dff8bf7f8f333196717bf/cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", + "sha256" : "b62ce867176a75d03a665bad002af8e6d54644fad99a3c70905c543130e39d93" + } + ] + }, + { + "name" : "python3-cryptography", + "buildsystem" : "simple", + "build-commands" : [ + "pip install --prefix=/app cryptography-43.0.1-cp39-abi3-manylinux_2_28_x86_64.whl" + ], + "sources" : [ + { + "type" : "file", + "url" : "https://files.pythonhosted.org/packages/ac/7e/ebda4dd4ae098a0990753efbb4b50954f1d03003846b943ea85070782da7/cryptography-43.0.1-cp39-abi3-manylinux_2_28_x86_64.whl", + "sha256" : "511f4273808ab590912a93ddb4e3914dfd8a388fed883361b02dea3791f292e1" + } + ] + }, + { + "name" : "python3-bcrypt", + "buildsystem" : "simple", + "build-commands" : [ + "pip install --prefix=/app bcrypt-4.2.0-cp39-abi3-manylinux_2_28_x86_64.whl" + ], + "sources" : [ + { + "type" : "file", + "url" : "https://files.pythonhosted.org/packages/3e/d0/31938bb697600a04864246acde4918c4190a938f891fd11883eaaf41327a/bcrypt-4.2.0-cp39-abi3-manylinux_2_28_x86_64.whl", + "sha256" : "3d3a6d28cb2305b43feac298774b997e372e56c7c7afd90a12b3dc49b189151c" + } + ] + }, + { + "name" : "python3-pynacl", + "buildsystem" : "simple", + "build-commands" : [ + "pip install --prefix=/app PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl" + ], + "sources" : [ + { + "type" : "file", + "url" : "https://files.pythonhosted.org/packages/66/28/ca86676b69bf9f90e710571b67450508484388bfce09acf8a46f0b8c785f/PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", + "sha256" : "06b8f6fa7f5de8d5d2f7573fe8c863c051225a27b61e6860fd047b1775807858" + } + ] + }, + { + "name" : "python3-paramiko", + "buildsystem" : "simple", + "build-commands" : [ + "pip install --prefix=/app paramiko-3.5.0-py3-none-any.whl" + ], + "sources" : [ + { + "type" : "file", + "url" : "https://files.pythonhosted.org/packages/1f/66/14b2c030fcce69cba482d205c2d1462ca5c77303a263260dcb1192801c85/paramiko-3.5.0-py3-none-any.whl", + "sha256" : "1fedf06b085359051cd7d0d270cebe19e755a8a921cc2ddbfa647fb0cd7d68f9" + } + ] + }, + { + "name" : "python3-sshtunnel", + "buildsystem" : "simple", + "build-commands" : [ + "pip install --prefix=/app sshtunnel-0.4.0-py2.py3-none-any.whl" + ], + "sources" : [ + { + "type" : "file", + "url" : "https://files.pythonhosted.org/packages/58/13/8476c4328dcadfe26f8bd7f3a1a03bf9ddb890a7e7b692f54a179bc525bf/sshtunnel-0.4.0-py2.py3-none-any.whl", + "sha256" : "98e54c26f726ab8bd42b47a3a21fca5c3e60f58956f0f70de2fb8ab0046d0606" + } + ] + }, + { + "name" : "weegtk", + "builddir" : true, + "buildsystem" : "meson", + "sources" : [ + { + "type" : "git", + "url" : "file:///home/lfryzek/Documents/projects/gtk/weegtk" + } + ] + } + ] +} diff --git a/data/com.fryzekconcepts.weegtk.desktop.in b/data/com.fryzekconcepts.weegtk.desktop.in new file mode 100644 index 0000000..b2722e5 --- /dev/null +++ b/data/com.fryzekconcepts.weegtk.desktop.in @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=weegtk +Exec=weegtk +Icon=com.fryzekconcepts.weegtk +Terminal=false +Type=Application +Categories=Utility; +Keywords=GTK; +StartupNotify=true +DBusActivatable=true diff --git a/data/com.fryzekconcepts.weegtk.gschema.xml b/data/com.fryzekconcepts.weegtk.gschema.xml new file mode 100644 index 0000000..47529b2 --- /dev/null +++ b/data/com.fryzekconcepts.weegtk.gschema.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<schemalist gettext-domain="weegtk"> + <schema id="com.fryzekconcepts.weegtk" path="/com/fryzekconcepts/weegtk/"> + </schema> +</schemalist> diff --git a/data/com.fryzekconcepts.weegtk.metainfo.xml.in b/data/com.fryzekconcepts.weegtk.metainfo.xml.in new file mode 100644 index 0000000..cbab1f8 --- /dev/null +++ b/data/com.fryzekconcepts.weegtk.metainfo.xml.in @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<component type="desktop-application"> + <id>com.fryzekconcepts.weegtk</id> + <metadata_license>CC0-1.0</metadata_license> + <project_license>GPL-3.0-or-later</project_license> + + <name>Weegtk</name> + <summary>Keep the summary shorter, between 10 and 35 characters</summary> + <description> + <p>No description</p> + </description> + + <developer id="tld.vendor"> + <name>Developer name</name> + </developer> + + <!-- Requered: Should be a link to the upstream homepage for the component --> + <url type="homepage">https://example.org/</url> + <!-- Recommended: It is highly recommended for open-source projects to display the source code repository --> + <url type="vcs-browser">https://example.org/repository</url> + <!-- Should point to the software's bug tracking system, for users to report new bugs --> + <url type="bugtracker">https://example.org/issues</url> + <!-- Should link a FAQ page for this software, to answer some of the most-asked questions in detail --> + <!-- URLs of this type should point to a webpage where users can submit or modify translations of the upstream project --> + <url type="translate">https://example.org/translate</url> + <url type="faq">https://example.org/faq</url> + <!--Sould provide a web link to an online user's reference, a software manual or help page --> + <url type="help">https://example.org/help</url> + <!-- URLs of this type should point to a webpage showing information on how to donate to the described software project --> + <url type="donation">https://example.org/donate</url> + <!--This could for example be an HTTPS URL to an online form or a page describing how to contact the developer --> + <url type="contact">https://example.org/contact</url> + <!--URLs of this type should point to a webpage showing information on how to contribute to the described software project --> + <url type="contribute">https://example.org/contribute</url> + + <translation type="gettext">weegtk</translation> + <!-- All graphical applications having a desktop file must have this tag in the MetaInfo. + If this is present, appstreamcli compose will pull icons, keywords and categories from the desktop file. --> + <launchable type="desktop-id">com.fryzekconcepts.weegtk.desktop</launchable> + <!-- Use the OARS website (https://hughsie.github.io/oars/generate.html) to generate these and make sure to use oars-1.1 --> + <content_rating type="oars-1.1" /> + + <!-- Applications should set a brand color in both light and dark variants like so --> + <branding> + <color type="primary" scheme_preference="light">#ff00ff</color> + <color type="primary" scheme_preference="dark">#993d3d</color> + </branding> + + <screenshots> + <screenshot type="default"> + <image>https://example.org/example1.png</image> + <caption>A caption</caption> + </screenshot> + <screenshot> + <image>https://example.org/example2.png</image> + <caption>A caption</caption> + </screenshot> + </screenshots> + + <releases> + <release version="1.0.1" date="2024-01-18"> + <url type="details">https://example.org/changelog.html#version_1.0.1</url> + <description translate="no"> + <p>Release description</p> + <ul> + <li>List of changes</li> + <li>List of changes</li> + </ul> + </description> + </release> + </releases> + +</component> diff --git a/data/com.fryzekconcepts.weegtk.service.in b/data/com.fryzekconcepts.weegtk.service.in new file mode 100644 index 0000000..1ed30df --- /dev/null +++ b/data/com.fryzekconcepts.weegtk.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=com.fryzekconcepts.weegtk +Exec=@bindir@/weegtk --gapplication-service diff --git a/data/icons/hicolor/scalable/apps/com.fryzekconcepts.weegtk.svg b/data/icons/hicolor/scalable/apps/com.fryzekconcepts.weegtk.svg new file mode 100644 index 0000000..a74c4df --- /dev/null +++ b/data/icons/hicolor/scalable/apps/com.fryzekconcepts.weegtk.svg @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + width="33.750061mm" + height="33.750061mm" + viewBox="0 0 33.750061 33.750061" + version="1.1" + id="svg974"> + <defs + id="defs968"> + <clipPath + clipPathUnits="userSpaceOnUse" + id="clipPath18689"> + <rect + clip-path="none" + transform="rotate(45)" + ry="32.000008" + rx="32.000008" + y="123.9986" + x="486.03726" + height="362.94299" + width="362.94299" + id="rect18691" + style="display:inline;opacity:1;vector-effect:none;fill:#4a86cf;fill-opacity:1;stroke:none;stroke-width:26.0669;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;enable-background:new" /> + </clipPath> + <clipPath + clipPathUnits="userSpaceOnUse" + id="clipPath18689-3"> + <rect + clip-path="none" + transform="rotate(45)" + ry="32.000008" + rx="32.000008" + y="123.9986" + x="486.03726" + height="362.94299" + width="362.94299" + id="rect18691-6" + style="display:inline;opacity:1;vector-effect:none;fill:#4a86cf;fill-opacity:1;stroke:none;stroke-width:26.0669;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;enable-background:new" /> + </clipPath> + </defs> + <metadata + id="metadata971"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + id="layer1" + transform="translate(-61.819823,-103.94395)"> + <g + transform="matrix(0.26367235,0,0,0.26367235,61.819823,-529.39703)" + style="display:inline;stroke-width:0.25;enable-background:new" + id="g1836"> + <title + id="title1838">application-x-executable</title> + <g + transform="matrix(0.25,0,0,0.25,0,2295)" + id="g18818" + style="stroke-width:0.25"> + <g + style="stroke-width:0.269963" + transform="matrix(0.92605186,0,0,0.92605186,18.930729,50.876335)" + id="g18590"> + <g + style="stroke-width:0.269963" + id="g18681" + clip-path="url(#clipPath18689-3)"> + <rect + style="opacity:1;vector-effect:none;fill:#3584e4;fill-opacity:1;stroke:none;stroke-width:8.22095;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal" + id="rect18571" + width="424" + height="424" + x="458.33722" + y="90.641701" + rx="10.092117" + ry="10.092117" + transform="matrix(0.60528171,0.60528171,-0.60528171,0.60528171,33.440632,99.073632)" + clip-path="none" /> + <circle + style="opacity:1;vector-effect:none;fill:#f66151;fill-opacity:1;stroke:none;stroke-width:7.03712;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal" + id="path18706" + cx="0" + cy="0" + r="0" + transform="translate(0,-212)" /> + <circle + style="opacity:1;vector-effect:none;fill:#f66151;fill-opacity:1;stroke:none;stroke-width:7.03712;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal" + id="path18708" + cx="0" + cy="0" + r="0" + transform="translate(0,-212)" /> + <path + style="display:inline;opacity:1;vector-effect:none;fill:#98c1f1;fill-opacity:1;stroke:none;stroke-width:7.03712;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;enable-background:new" + d="m 408.91993,561.9183 -9.8861,29.82892 a 172.97099,172.97099 0 0 0 -1.42693,-0.0713 172.97099,172.97099 0 0 0 -23.92891,1.85189 l -13.80082,-28.50125 a 203.29325,203.29325 0 0 0 -29.40085,7.97217 l 2.28619,31.40474 a 172.97099,172.97099 0 0 0 -22.73152,11.31923 l -23.71796,-21.103 a 203.29325,203.29325 0 0 0 -24.05918,18.6741 l 14.09863,28.07319 a 172.97099,172.97099 0 0 0 -16.63608,19.21074 l -30.05845,-10.44758 a 203.29325,203.29325 0 0 0 -15.01683,26.48807 l 23.73035,20.50738 a 172.97099,172.97099 0 0 0 -7.98456,24.14293 l -31.73044,1.84879 a 203.29325,203.29325 0 0 0 -3.77825,30.21664 l 29.82892,9.8861 a 172.97099,172.97099 0 0 0 -0.0713,1.42693 172.97099,172.97099 0 0 0 1.85188,23.92889 l -28.50125,13.80084 a 203.29325,203.29325 0 0 0 7.97215,29.40084 l 31.40475,-2.28619 a 172.97099,172.97099 0 0 0 11.31922,22.73152 l -21.10296,23.71797 a 203.29325,203.29325 0 0 0 18.67409,24.05918 l 28.07319,-14.09863 a 172.97099,172.97099 0 0 0 19.21074,16.63606 l -10.44758,30.05847 a 203.29325,203.29325 0 0 0 26.48806,15.01683 l 20.50739,-23.73036 a 172.97099,172.97099 0 0 0 24.14293,7.98457 l 1.8488,31.73043 a 203.29325,203.29325 0 0 0 30.21666,3.77826 l 9.8861,-29.82892 a 172.97099,172.97099 0 0 0 1.42693,0.0713 172.97099,172.97099 0 0 0 23.9289,-1.85188 l 13.80084,28.50125 a 203.29325,203.29325 0 0 0 29.40084,-7.97217 l -2.2862,-31.40474 a 172.97099,172.97099 0 0 0 22.73153,-11.31922 l 23.71796,21.10297 A 203.29325,203.29325 0 0 0 532.96,916.00016 l -14.09864,-28.07319 a 172.97099,172.97099 0 0 0 16.63607,-19.21073 l 30.05846,10.44757 a 203.29325,203.29325 0 0 0 15.01683,-26.48807 l -23.73036,-20.50738 a 172.97099,172.97099 0 0 0 7.98457,-24.14293 l 31.73044,-1.84879 a 203.29325,203.29325 0 0 0 3.77825,-30.21667 l -29.82892,-9.8861 a 172.97099,172.97099 0 0 0 0.0713,-1.42692 172.97099,172.97099 0 0 0 -1.85189,-23.9289 l 28.50124,-13.80084 a 203.29325,203.29325 0 0 0 -7.97215,-29.40084 l -31.40474,2.2862 a 172.97099,172.97099 0 0 0 -11.31923,-22.73153 l 21.10297,-23.71797 a 203.29325,203.29325 0 0 0 -18.67409,-24.05918 l -28.07319,14.09863 a 172.97099,172.97099 0 0 0 -19.21074,-16.63606 l 10.44757,-30.05847 A 203.29325,203.29325 0 0 0 485.6357,581.68117 l -20.50738,23.73035 a 172.97099,172.97099 0 0 0 -24.14293,-7.98455 l -1.84879,-31.73044 a 203.29325,203.29325 0 0 0 -30.21667,-3.77826 z M 397.6069,637.72208 A 126.92605,126.92605 0 0 1 524.5318,764.64699 126.92605,126.92605 0 0 1 397.6069,891.57189 126.92605,126.92605 0 0 1 270.682,764.64699 126.92605,126.92605 0 0 1 397.6069,637.72208 Z" + id="path18717-4" /> + <path + id="path18758" + d="m 51.748325,401.28402 -9.8861,29.82892 c -0.475543,-0.0257 -0.951191,-0.0495 -1.42693,-0.0713 -8.00956,0.0625 -16.005106,0.6813 -23.92891,1.85189 L 2.7055639,404.39228 c -9.9858697,1.91835 -19.8137359,4.58322 -29.4008489,7.97217 l 2.28619,31.40474 c -7.844275,3.21103 -15.441918,6.9943 -22.73152,11.31923 l -23.71796,-21.103 c -8.475372,5.61437 -16.517661,11.85658 -24.05918,18.6741 l 14.09863,28.07319 c -6.008901,5.98701 -11.569263,12.40791 -16.636077,19.21074 l -30.058438,-10.44758 c -5.66072,8.44155 -10.68041,17.29574 -15.01683,26.48807 l 23.73035,20.50738 c -3.25027,7.84084 -5.919,15.91028 -7.98456,24.14293 l -31.73044,1.84879 c -2.01308,9.96359 -3.27604,20.06413 -3.77825,30.21664 l 29.82892,9.8861 c -0.0257,0.47554 -0.0495,0.95119 -0.0713,1.42693 0.0625,8.00955 0.68129,16.00509 1.85188,23.92889 l -28.50125,13.80084 c 1.91835,9.98587 4.58321,19.81373 7.97215,29.40084 l 31.40475,-2.28619 c 3.21102,7.84427 6.99429,15.44192 11.31922,22.73152 l -21.10296,23.71797 c 5.61437,8.47537 11.85658,16.51766 18.67409,24.05918 l 28.073175,-14.09863 c 5.987006,6.00889 12.407911,11.56925 19.21074,16.63606 l -10.44758,30.05847 c 8.441549,5.66072 17.295731,10.68041 26.48806,15.01683 l 20.50739,-23.73036 c 7.840839,3.25027 15.910282,5.91901 24.142929,7.98457 l 1.8488,31.73043 c 9.9635962,2.01309 20.064147,3.27605 30.216661,3.77826 l 9.8861,-29.82892 c 0.475543,0.0257 0.951191,0.0495 1.42693,0.0713 8.009557,-0.0625 16.005099,-0.68129 23.9289,-1.85188 l 13.80084,28.50125 c 9.985867,-1.91835 19.813731,-4.58322 29.400855,-7.97217 l -2.2862,-31.40474 c 7.84428,-3.21102 15.44192,-6.99429 22.73153,-11.31922 l 23.71796,21.10297 c 8.47538,-5.61437 16.51767,-11.85658 24.05919,-18.6741 l -14.09864,-28.07319 c 6.0089,-5.987 11.56926,-12.4079 16.63607,-19.21073 l 30.05846,10.44757 c 5.66072,-8.44155 10.68041,-17.29574 15.01683,-26.48807 l -23.73036,-20.50738 c 3.25027,-7.84084 5.91901,-15.91028 7.98457,-24.14293 l 31.73044,-1.84879 c 2.01308,-9.9636 3.27604,-20.06415 3.77825,-30.21667 l -29.82892,-9.8861 c 0.0257,-0.47554 0.0495,-0.95118 0.0713,-1.42692 -0.0625,-8.00956 -0.6813,-16.0051 -1.85189,-23.9289 l 28.50124,-13.80084 c -1.91835,-9.98587 -4.58321,-19.81373 -7.97215,-29.40084 l -31.40474,2.2862 c -3.21103,-7.84428 -6.9943,-15.44192 -11.31923,-22.73153 l 21.10297,-23.71797 c -5.61437,-8.47537 -11.85658,-16.51766 -18.67409,-24.05918 l -28.07319,14.09863 c -5.98701,-6.00889 -12.40791,-11.56925 -19.21074,-16.63606 l 10.44757,-30.05847 c -8.44155,-5.66072 -17.29572,-10.6804 -26.48805,-15.01682 l -20.50738,23.73035 c -7.84085,-3.25027 -15.910298,-5.91899 -24.142945,-7.98455 l -1.84879,-31.73044 c -9.9636,-2.01309 -20.064152,-3.27605 -30.21667,-3.77826 z" + style="display:inline;opacity:1;vector-effect:none;fill:#1a5fb4;fill-opacity:1;stroke:none;stroke-width:7.03712;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;enable-background:new" /> + </g> + </g> + <path + style="display:inline;opacity:0.534;vector-effect:none;fill:#1a5fb4;fill-opacity:1;stroke:none;stroke-width:1.62918;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;enable-background:new" + clip-path="none" + d="m 8.4765625,2676 c -1.1711695,2.8866 -0.5827763,6.3078 1.7656255,8.6562 l 48.101562,48.1016 c 3.133898,3.1339 8.178602,3.1339 11.3125,0 l 48.10156,-48.1016 c 2.3484,-2.3484 2.9368,-5.7696 1.76563,-8.6562 -0.39174,0.9655 -0.98013,1.8708 -1.76563,2.6562 l -48.10156,48.1016 c -3.133898,3.1339 -8.178602,3.1339 -11.3125,0 L 10.242188,2678.6562 C 9.4566904,2677.8708 8.8682972,2676.9655 8.4765625,2676 Z" + transform="matrix(4,0,0,4,0,-10028)" + id="rect18571-6" /> + </g> + <rect + y="2402" + x="-1.5000001e-06" + height="128" + width="128" + id="rect9125-7-2" + style="display:inline;opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:none;stroke-width:1.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;enable-background:new" /> + </g> + </g> +</svg> diff --git a/data/icons/hicolor/symbolic/apps/com.fryzekconcepts.weegtk-symbolic.svg b/data/icons/hicolor/symbolic/apps/com.fryzekconcepts.weegtk-symbolic.svg new file mode 100644 index 0000000..0444828 --- /dev/null +++ b/data/icons/hicolor/symbolic/apps/com.fryzekconcepts.weegtk-symbolic.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><g color="#000" fill="#2e3436"><path d="M7.188 2.281c-.094.056-.192.125-.29.19L5.566 3.803a1.684 1.684 0 11-2.17 2.17L2.332 7.037c.506-.069 1.017-.136 1.2.026.242.214.139 1.031.155 1.656.213.088.427.171.657.219.04.008.085-.007.125 0 .337-.525.683-1.288 1-1.344.322-.057.905.562 1.406.937a3.67 3.67 0 00.656-.468c-.195-.595-.594-1.369-.437-1.657.158-.29 1.019-.37 1.625-.531.028-.183.062-.371.062-.562 0-.075-.027-.146-.031-.22-.587-.217-1.435-.385-1.562-.687-.128-.302.34-1.021.593-1.593a3.722 3.722 0 00-.593-.532zm3.875 3.25c-.165.475-.305 1.086-.47 1.563-.43.047-.84.14-1.218.312-.38-.322-.787-.773-1.156-1.093a5.562 5.562 0 00-.688.468c.177.46.453 1.001.625 1.469-.298.309-.531.67-.719 1.063-.494 0-1.102-.084-1.593-.094a5.68 5.68 0 00-.219.812c.435.24 1.006.468 1.438.72-.006.093-.032.185-.032.28 0 .333.049.66.125.97-.382.304-.898.63-1.28.937.015.044.04.083.058.127l.613.613c.417-.1.868-.223 1.266-.303.248.343.532.626.875.875-.027.135-.068.283-.104.428.174-.063.34-.155.482-.297l1.432-1.432a1.994 1.994 0 01.533-3.918c.919 0 1.684.623 1.918 1.467l1.338-1.338c.06-.06.11-.124.156-.191-.035-.062-.06-.13-.1-.188.096-.152.205-.31.315-.47.017-.348-.1-.7-.37-.971l-.177-.176c-.28.192-.561.387-.83.555-.345-.233-.746-.383-1.156-.5-.077-.507-.107-1.132-.187-1.625a5.44 5.44 0 00-.875-.063zm-9.247.608c-.087.068-.173.138-.254.205l.014.035z" style="marker:none" overflow="visible"/><path d="M8.707.293a1 1 0 00-1.415 0l-6.999 7a1 1 0 000 1.413l7 7.001a1 1 0 001.415 0l7-7a1 1 0 000-1.413zm-.708 2.121l5.587 5.587L8 13.586 2.414 7.999z" style="line-height:normal;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000;text-transform:none;text-orientation:mixed;shape-padding:0;isolation:auto;mix-blend-mode:normal;marker:none" font-weight="400" font-family="sans-serif" overflow="visible"/></g></svg>
\ No newline at end of file diff --git a/data/icons/meson.build b/data/icons/meson.build new file mode 100644 index 0000000..d850b9c --- /dev/null +++ b/data/icons/meson.build @@ -0,0 +1,13 @@ +application_id = 'com.fryzekconcepts.weegtk' + +scalable_dir = 'hicolor' / 'scalable' / 'apps' +install_data( + scalable_dir / ('@0@.svg').format(application_id), + install_dir: get_option('datadir') / 'icons' / scalable_dir +) + +symbolic_dir = 'hicolor' / 'symbolic' / 'apps' +install_data( + symbolic_dir / ('@0@-symbolic.svg').format(application_id), + install_dir: get_option('datadir') / 'icons' / symbolic_dir +) diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..0196aa7 --- /dev/null +++ b/data/meson.build @@ -0,0 +1,46 @@ +desktop_file = i18n.merge_file( + input: 'com.fryzekconcepts.weegtk.desktop.in', + output: 'com.fryzekconcepts.weegtk.desktop', + type: 'desktop', + po_dir: '../po', + install: true, + install_dir: get_option('datadir') / 'applications' +) + +desktop_utils = find_program('desktop-file-validate', required: false) +if desktop_utils.found() + test('Validate desktop file', desktop_utils, args: [desktop_file]) +endif + +appstream_file = i18n.merge_file( + input: 'com.fryzekconcepts.weegtk.metainfo.xml.in', + output: 'com.fryzekconcepts.weegtk.metainfo.xml', + po_dir: '../po', + install: true, + install_dir: get_option('datadir') / 'metainfo' +) + +appstreamcli = find_program('appstreamcli', required: false, disabler: true) +test('Validate appstream file', appstreamcli, + args: ['validate', '--no-net', '--explain', appstream_file]) + +install_data('com.fryzekconcepts.weegtk.gschema.xml', + install_dir: get_option('datadir') / 'glib-2.0' / 'schemas' +) + +compile_schemas = find_program('glib-compile-schemas', required: false, disabler: true) +test('Validate schema file', + compile_schemas, + args: ['--strict', '--dry-run', meson.current_source_dir()]) + + +service_conf = configuration_data() +service_conf.set('bindir', get_option('prefix') / get_option('bindir')) +configure_file( + input: 'com.fryzekconcepts.weegtk.service.in', + output: 'com.fryzekconcepts.weegtk.service', + configuration: service_conf, + install_dir: get_option('datadir') / 'dbus-1' / 'services' +) + +subdir('icons') diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..bfefd93 --- /dev/null +++ b/meson.build @@ -0,0 +1,18 @@ +project('weegtk', + version: '0.1.0', + meson_version: '>= 1.0.0', + default_options: [ 'warning_level=2', 'werror=false', ], +) + +i18n = import('i18n') +gnome = import('gnome') + +subdir('data') +subdir('src') +subdir('po') + +gnome.post_install( + glib_compile_schemas: true, + gtk_update_icon_cache: true, + update_desktop_database: true, +) diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000..61b6fb7 --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1 @@ +# Please keep this file sorted alphabetically. diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..716f409 --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,8 @@ +# List of source files containing translatable strings. +# Please keep this file sorted alphabetically. +data/com.fryzekconcepts.weegtk.desktop.in +data/com.fryzekconcepts.weegtk.metainfo.xml.in +data/com.fryzekconcepts.weegtk.gschema.xml +src/main.py +src/window.py +src/window.ui diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 0000000..4315eb2 --- /dev/null +++ b/po/meson.build @@ -0,0 +1 @@ +i18n.gettext('weegtk', preset: 'glib') diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/__init__.py diff --git a/src/chat.py b/src/chat.py new file mode 100644 index 0000000..f876854 --- /dev/null +++ b/src/chat.py @@ -0,0 +1,120 @@ +# window.py +# +# Copyright 2024 Lucas Fryzek +# +# 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 <https://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: GPL-3.0-or-later +from gi.repository import Adw +from gi.repository import Gtk +from gi.repository import Gio +from gi.repository import GObject + +from .message import WeegtkMessage +from .color import Color +from weegtk import config + +import json + +@Gtk.Template(resource_path='/com/fryzekconcepts/weegtk/gtk/chat.ui') +class WeegtkChat(Adw.Bin): + __gtype_name__ = 'WeegtkChat' + + __gsignals__ = { + "buffer_input" : ( + GObject.SignalFlags.RUN_FIRST, + None, + (str, str) + ) + } + + window = Gtk.Template.Child() + messages = Gtk.Template.Child() + text_entry = Gtk.Template.Child() + + def __init__(self, data=None, **kwargs): + super().__init__(**kwargs) + + self.data = data or {} + + self.model = Gtk.StringList() + self.select = Gtk.NoSelection(model=self.model) + + self.factory = Gtk.SignalListItemFactory() + self.factory.connect("setup", self.setup_list_item) + self.factory.connect("bind", self.bind_list_item) + + self.messages.set_model(self.select) + self.messages.set_factory(self.factory) + + self.color = Color(config.color_options(), False) + + def scroll_bottom(self, *args): + n_items = self.model.get_n_items() + self.messages.scroll_to(n_items - 1, Gtk.ListScrollFlags.FOCUS) + + def setup_list_item(self, factory, list_item, *user_data): + message = WeegtkMessage() + list_item.set_child(message) + pass + + def bind_list_item(self, factory, list_item, *user_data): + text = list_item.get_item().get_string() + data = json.loads(text) + message = list_item.get_child() + message.set_contents(data["username"], data["text"]) + pass + + def is_chat(self): + buf_type = self.data['local_variables']['type'] if 'type' in self.data['local_variables'] else None + return buf_type is not None and (buf_type == "private" or buf_type == "channel") + + def pointer(self): + """Return pointer on buffer.""" + return self.data.get('__path', [''])[0] + + def parse_out_colors(self, text): + clean_text = self.color.convert(text) + return clean_text + + def display(self, time, prefix, text, forcecolor=None): + # TODO using JSON here seems a bit ineffcient + # See if its possible to make a model that uses + # our own custom struct + user = self.parse_out_colors(prefix) + msg = self.parse_out_colors(text) + count = self.model.get_n_items() + + if count != 0: + last = self.model.get_string(count - 1) + last_data = json.loads(last) + if last_data["username"] == user: + last_data["text"].append(msg) + self.model.splice(count - 1, 1, [json.dumps(last_data)]) + return + + data = { + "username": user, + "text": [msg] + } + self.model.append(json.dumps(data)) + self.scroll_bottom() + + @Gtk.Template.Callback() + def entry_activate(self, *args): + entry_buffer = self.text_entry.get_buffer() + text = entry_buffer.get_text() + entry_buffer.set_text("", 0) + self.emit("buffer_input", self.data['full_name'], text) + diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..ee9d611 --- /dev/null +++ b/src/config.py @@ -0,0 +1,140 @@ +# main.py +# +# Copyright 2024 Lucas Fryzek +# Based on code from QWeeChat +# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org> +# +# 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 <https://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: GPL-3.0-or-later +"""Configuration for Weegtk.""" + +import configparser +import os + +from gi.repository import GLib + +from pathlib import Path + +CONFIG_DIR = f"{GLib.get_user_config_dir()}/weegtk" +CONFIG_FILENAME = f"{CONFIG_DIR}/weegtk.conf" + +CONFIG_DEFAULT_RELAY_LINES = 50 + +CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color', 'ssh') +CONFIG_DEFAULT_OPTIONS = (('relay.hostname', ''), + ('relay.port', ''), + ('relay.ssl', 'off'), + ('relay.password', ''), + ('relay.autoconnect', 'off'), + ('relay.lines', str(CONFIG_DEFAULT_RELAY_LINES)), + ('ssh.host', ''), + ('ssh.port', ''), + ('ssh.username', ''), + ('ssh.key', ''), + ('look.debug', 'off'), + ('look.statusbar', 'off')) + +# Default colors for WeeChat color options (option name, #rgb value) +CONFIG_DEFAULT_COLOR_OPTIONS = ( + ('separator', '#000066'), # 0 + ('chat', '#000000'), # 1 + ('chat_time', '#999999'), # 2 + ('chat_time_delimiters', '#000000'), # 3 + ('chat_prefix_error', '#FF6633'), # 4 + ('chat_prefix_network', '#990099'), # 5 + ('chat_prefix_action', '#000000'), # 6 + ('chat_prefix_join', '#00CC00'), # 7 + ('chat_prefix_quit', '#CC0000'), # 8 + ('chat_prefix_more', '#CC00FF'), # 9 + ('chat_prefix_suffix', '#330099'), # 10 + ('chat_buffer', '#000000'), # 11 + ('chat_server', '#000000'), # 12 + ('chat_channel', '#000000'), # 13 + ('chat_nick', '#000000'), # 14 + ('chat_nick_self', '*#000000'), # 15 + ('chat_nick_other', '#000000'), # 16 + ('', '#000000'), # 17 (nick1 -- obsolete) + ('', '#000000'), # 18 (nick2 -- obsolete) + ('', '#000000'), # 19 (nick3 -- obsolete) + ('', '#000000'), # 20 (nick4 -- obsolete) + ('', '#000000'), # 21 (nick5 -- obsolete) + ('', '#000000'), # 22 (nick6 -- obsolete) + ('', '#000000'), # 23 (nick7 -- obsolete) + ('', '#000000'), # 24 (nick8 -- obsolete) + ('', '#000000'), # 25 (nick9 -- obsolete) + ('', '#000000'), # 26 (nick10 -- obsolete) + ('chat_host', '#666666'), # 27 + ('chat_delimiters', '#9999FF'), # 28 + ('chat_highlight', '#3399CC'), # 29 + ('chat_read_marker', '#000000'), # 30 + ('chat_text_found', '#000000'), # 31 + ('chat_value', '#000000'), # 32 + ('chat_prefix_buffer', '#000000'), # 33 + ('chat_tags', '#000000'), # 34 + ('chat_inactive_window', '#000000'), # 35 + ('chat_inactive_buffer', '#000000'), # 36 + ('chat_prefix_buffer_inactive_buffer', '#000000'), # 37 + ('chat_nick_offline', '#000000'), # 38 + ('chat_nick_offline_highlight', '#000000'), # 39 + ('chat_nick_prefix', '#000000'), # 40 + ('chat_nick_suffix', '#000000'), # 41 + ('emphasis', '#000000'), # 42 + ('chat_day_change', '#000000'), # 43 +) +config_options = {"color": []} + + +def read(): + """Read config file.""" + global config_options + config = configparser.RawConfigParser() + if os.path.isfile(CONFIG_FILENAME): + config.read(CONFIG_FILENAME) + + # add missing sections/options + for section in CONFIG_DEFAULT_SECTIONS: + if not config.has_section(section): + config.add_section(section) + for option in reversed(CONFIG_DEFAULT_OPTIONS): + section, name = option[0].split('.', 1) + if not config.has_option(section, name): + config.set(section, name, option[1]) + section = 'color' + for option in reversed(CONFIG_DEFAULT_COLOR_OPTIONS): + if option[0] and not config.has_option(section, option[0]): + config.set(section, option[0], option[1]) + + # build list of color options + config_options = {"color": []} + for option in CONFIG_DEFAULT_COLOR_OPTIONS: + if option[0]: + config_options["color"].append(config.get('color', option[0])) + else: + config_options["color"].append('#000000') + + return config + + +def write(config): + """Write config file.""" + Path(CONFIG_DIR).mkdir(mode=0o0700, parents=True, exist_ok=True) + with open(CONFIG_FILENAME, 'w') as cfg: + config.write(cfg) + + +def color_options(): + """Return color options.""" + global config_options + return config_options["color"] diff --git a/src/gtk/chat.ui b/src/gtk/chat.ui new file mode 100644 index 0000000..23477ad --- /dev/null +++ b/src/gtk/chat.ui @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk" version="4.0"/> + <requires lib="libadwaita" version="1.0"/> + <template class="WeegtkChat" parent="AdwBin"> + <style> + <class name="view"/> + </style> + <property name="child"> + <object class="AdwToolbarView"> + <child type="top"> + <object class="AdwHeaderBar"> + <property name="show-title">True</property> + </object> + </child> + <property name="content"> + <object class="GtkBox"> + <property name="orientation">vertical</property> + <child> + <object class="GtkScrolledWindow" id="window"> + <property name="vexpand">True</property> + <property name="hscrollbar_policy">3</property> + <child> + <object class="AdwClampScrollable"> + <property name="maximum-size">750</property> + <property name="tightening-threshold">550</property> + <property name="child"> + <object class="GtkListView" id="messages"> + <property name="orientation">1</property> + <style> + <class name="navigation-sidebar"/> + </style> + </object> + </property> + </object> + </child> + </object> + </child> + <child> + <object class="AdwClamp"> + <property name="maximum-size">750</property> + <property name="tightening-threshold">550</property> + <property name="child"> + <object class="GtkBox"> + <property name="margin-top">5</property> + <property name="margin-bottom">5</property> + <child> + <object class="GtkEntry" id="text_entry"> + <property name="halign">fill</property> + <property name="hexpand">True</property> + <property name="hexpand-set">True</property> + <property name="width-request">50</property> + <property name="margin-start">5</property> + <property name="margin-end">5</property> + <signal name="activate" handler="entry_activate"/> + </object> + </child> + </object> + </property> + </object> + </child> + </object> + </property> + </object> + </property> + </template> +</interface> diff --git a/src/gtk/help-overlay.ui b/src/gtk/help-overlay.ui new file mode 100644 index 0000000..ef12f02 --- /dev/null +++ b/src/gtk/help-overlay.ui @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <object class="GtkShortcutsWindow" id="help_overlay"> + <property name="modal">True</property> + <child> + <object class="GtkShortcutsSection"> + <property name="section-name">shortcuts</property> + <property name="max-height">10</property> + <child> + <object class="GtkShortcutsGroup"> + <property name="title" translatable="yes" context="shortcut window">General</property> + <child> + <object class="GtkShortcutsShortcut"> + <property name="title" translatable="yes" context="shortcut window">Show Shortcuts</property> + <property name="action-name">win.show-help-overlay</property> + </object> + </child> + <child> + <object class="GtkShortcutsShortcut"> + <property name="title" translatable="yes" context="shortcut window">Quit</property> + <property name="action-name">app.quit</property> + </object> + </child> + </object> + </child> + </object> + </child> + </object> +</interface> diff --git a/src/gtk/message.ui b/src/gtk/message.ui new file mode 100644 index 0000000..dca0237 --- /dev/null +++ b/src/gtk/message.ui @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk" version="4.0"/> + <template class="WeegtkMessage" parent="GtkBox"> + <property name="orientation">horizontal</property> + <property name="valign">start</property> + <property name="halign">start</property> + <!-- <property name="margin-top">2</property> --> + <!-- <property name="margin-bottom">2</property> --> + <style> + <class name="message"/> + </style> + <child> + <object class="AdwAvatar" id="avatar"> + <property name="size">32</property> + <property name="text" translatable="true">Username</property> + <property name="show-initials">true</property> + <property name="margin-start">10</property> + <property name="margin-end">10</property> + <property name="valign">start</property> + </object> + </child> + <child> + <object class="GtkBox" id="MessageText"> + <property name="orientation">1</property> + <property name="valign">1</property> + <property name="halign">1</property> + <child> + <object class="GtkLabel" id="username"> + <property name="label" translatable="true">Username</property> + <property name="halign">1</property> + <property name="selectable">true</property> + <style> + <class name="username"/> + </style> + </object> + </child> + <child> + <object class="GtkBox" id="message_list"> + <property name="orientation">1</property> + <property name="valign">1</property> + <property name="halign">1</property> + <!-- <child> --> + <!-- <object class="GtkLabel" id="message"> --> + <!-- <property name="label" translatable="true">This is the the message that some user sent</property> --> + <!-- <property name="halign">1</property> --> + <!-- <property name="selectable">true</property> --> + <!-- <property name="wrap">true</property> --> + <!-- <property name="halign">0</property> --> + <!-- <property name="hexpand">true</property> --> + <!-- <property name="hexpand-set">true</property> --> + <!-- <property name="xalign">0</property> --> + <!-- <style> --> + <!-- <class name="message"/> --> + <!-- </style> --> + <!-- </object> --> + <!-- </child> --> + </object> + </child> + </object> + </child> + </template> +</interface> diff --git a/src/gtk/preferences.ui b/src/gtk/preferences.ui new file mode 100644 index 0000000..5823d2f --- /dev/null +++ b/src/gtk/preferences.ui @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk" version="4.0"/> + <requires lib="libadwaita" version="1.0"/> + <template class="WeegtkPreferences" parent="AdwPreferencesDialog"> + <property name="content-height">1000</property> + <property name="search-enabled">True</property> + <signal name="closed" handler="preferences_closed"/> + <child> + <object class="AdwPreferencesPage"> + <property name="icon_name">preferences-window-layout-symbolic</property> + <property name="title">Settings</property> + <property name="use-underline">True</property> + <child> + <object class="AdwPreferencesGroup"> + <property name="title" translatable="yes">Connection</property> + <child> + <object class="AdwEntryRow" id="hostname"> + <property name="title" translatable="yes">Hostname</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="AdwEntryRow" id="port"> + <property name="title" translatable="yes">Port</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="AdwPasswordEntryRow" id="password"> + <property name="title" translatable="yes">Password</property> + </object> + </child> + <child> + <object class="AdwEntryRow" id="ssh_host"> + <property name="title" translatable="yes">SSH host</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="AdwEntryRow" id="ssh_port"> + <property name="title" translatable="yes">SSH port</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="AdwEntryRow" id="ssh_username"> + <property name="title" translatable="yes">SSH username</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="AdwActionRow"> + <property name="title" translatable="yes">SSH key</property> + <child> + <object class="GtkButton"> + <property name="valign">center</property> + <property name="action-name">ssh_key.open</property> + <child> + <object class="GtkBox"> + <property name="spacing">6</property> + <child> + <object class="GtkImage"> + <property name="icon-name">document-open-symbolic</property> + </object> + </child> + <child> + <object class="GtkLabel" id="ssh_key_label"> + <property name="ellipsize">middle</property> + </object> + </child> + </object> + </child> + </object> + </child> + </object> + </child> + </object> + </child> + </object> + </child> + </template> +</interface> diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..8997ab5 --- /dev/null +++ b/src/main.py @@ -0,0 +1,338 @@ +# main.py +# +# Copyright 2024 Lucas Fryzek +# +# 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 <https://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import sys +import os +import gi + +gi.require_version('Gtk', '4.0') +gi.require_version('Adw', '1') + +from gi.repository import Gtk, Gio, Adw +from .window import WeegtkWindow + +from .network import Network +from weegtk import protocol +from weegtk import config +from .chat import WeegtkChat +from .preferences import WeegtkPreferences + +class WeegtkApplication(Adw.Application): + """The main application singleton class.""" + + def __init__(self): + super().__init__(application_id='com.fryzekconcepts.weegtk', + flags=Gio.ApplicationFlags.DEFAULT_FLAGS) + self.create_action('quit', lambda *_: self.quit(), ['<primary>q']) + self.create_action('about', self.on_about_action) + self.create_action('preferences', self.on_preferences_action) + + self.network = Network() + self.network.connect("status_changed", self._network_status_changed) + self.network.connect("message_from_weechat", self._network_weechat_msg) + + conf = config.read() + #self.network.connect_weechat("localhost", "9001", False, relay_pw, None, "") + self.network.connect_weechat_ssh(conf["ssh"]["host"], + conf["ssh"]["port"], + conf["ssh"]["username"], + conf["ssh"]["key"], + conf["relay"]["hostname"], + conf["relay"]["port"], + conf["relay"]["password"]) + + self.buffers = [] + + def _network_status_changed(self, source_object, status, extra): + """Called when the network status has changed.""" + # TODO handle this + #if self.config.getboolean('look', 'statusbar'): + # self.statusBar().showMessage(status) + #self.network.debug_print(0, '', status, forcecolor='#0000AA') + #self.network_status_set(status) + print(f"Status is {status}") + + def _network_weechat_msg(self, source_object, message): + """Called when a message is received from WeeChat.""" + #print(f"Message {message}") + try: + proto = protocol.Protocol() + message = proto.decode(message.get_data()) + # TODO figure this out + #if message.uncompressed: + # self.network.debug_print( + # 0, '==>', + # 'message uncompressed (%d bytes):\n%s' + # % (message.size_uncompressed, + # protocol.hex_and_ascii(message.uncompressed, 20)), + # forcecolor='#008800') + #self.network.debug_print(0, '', 'Message: %s' % message) + #print(f"parsed message is f{message}") + self.parse_message(message) + except: + print('Error while decoding message from WeeChat:\n%s' + % traceback.format_exc()) + self.net.disconnect_weechat() + + def do_activate(self): + """Called when the application is activated. + + We raise the application's main window, creating it if + necessary. + """ + win = self.props.active_window + if not win: + win = WeegtkWindow(application=self) + win.present() + + def on_about_action(self, *args): + """Callback for the app.about action.""" + about = Adw.AboutDialog(application_name='weegtk', + application_icon='com.fryzekconcepts.weegtk', + developer_name='Lucas Fryzek', + version='0.1.0', + developers=['Lucas Fryzek <lucas.fryzek@fryzekconcepts.com>'], + copyright='© 2024 Lucas Fryzek') + # Translators: Replace "translator-credits" with your name/username, and optionally an email or URL. + about.set_translator_credits(_('translator-credits')) + about.add_credit_section("QWeechat", ["Sébastien Helleu <flashcode@flashtux.org>"]) + about.present(self.props.active_window) + + def on_preferences_action(self, widget, _): + """Callback for the app.preferences action.""" + pref = WeegtkPreferences() + pref.present(self.props.active_window) + + def create_action(self, name, callback, shortcuts=None): + """Add an application action. + + Args: + name: the name of the action + callback: the function to be called when the action is + activated + shortcuts: an optional list of accelerators + """ + action = Gio.SimpleAction.new(name, None) + action.connect("activate", callback) + self.add_action(action) + if shortcuts: + self.set_accels_for_action(f"app.{name}", shortcuts) + + def _parse_handshake(self, message): + """Parse a WeeChat message with handshake response.""" + for obj in message.objects: + if obj.objtype != 'htb': + continue + self.network.init_with_handshake(obj.value) + break + + def _parse_listbuffers(self, message): + """Parse a WeeChat message with list of buffers.""" + # TODO handle gui for this + for obj in message.objects: + if obj.objtype != 'hda' or obj.value['path'][-1] != 'buffer': + continue + #self.list_buffers.clear() + #while self.stacked_buffers.count() > 0: + # buf = self.stacked_buffers.widget(0) + # self.stacked_buffers.removeWidget(buf) + self.buffers = [] + for item in obj.value['items']: + buf = self.create_buffer(item) + self.insert_buffer(len(self.buffers), buf) + #self.list_buffers.setCurrentRow(0) + #self.buffers[0].widget.input.setFocus() + + def _parse_line(self, message): + """Parse a WeeChat message with a buffer line.""" + # TODO implement text for chats + for obj in message.objects: + lines = [] + if obj.objtype != 'hda' or obj.value['path'][-1] != 'line_data': + continue + for item in obj.value['items']: + if message.msgid == 'listlines': + ptrbuf = item['__path'][0] + else: + ptrbuf = item['buffer'] + index = [i for i, b in enumerate(self.buffers) + if b.pointer() == ptrbuf] + if index: + lines.append( + (index[0], + (item['date'], item['prefix'], + item['message'])) + ) + if message.msgid == 'listlines': + lines.reverse() + for line in lines: + #print(line) + self.buffers[line[0]].display(*line[1]) + + def _parse_nicklist(self, message): + """Parse a WeeChat message with a buffer nicklist.""" + # TODO implement nicklist for chat + # buffer_refresh = {} + # for obj in message.objects: + # if obj.objtype != 'hda' or \ + # obj.value['path'][-1] != 'nicklist_item': + # continue + # group = '__root' + # for item in obj.value['items']: + # index = [i for i, b in enumerate(self.buffers) + # if b.pointer() == item['__path'][0]] + # if index: + # if not index[0] in buffer_refresh: + # self.buffers[index[0]].nicklist = {} + # buffer_refresh[index[0]] = True + # if item['group']: + # group = item['name'] + # self.buffers[index[0]].nicklist_add_item( + # group, item['group'], item['prefix'], item['name'], + # item['visible']) + # for index in buffer_refresh: + # self.buffers[index].nicklist_refresh() + + def _parse_nicklist_diff(self, message): + """Parse a WeeChat message with a buffer nicklist diff.""" + buffer_refresh = {} + for obj in message.objects: + if obj.objtype != 'hda' or \ + obj.value['path'][-1] != 'nicklist_item': + continue + group = '__root' + for item in obj.value['items']: + index = [i for i, b in enumerate(self.buffers) + if b.pointer() == item['__path'][0]] + if not index: + continue + buffer_refresh[index[0]] = True + if item['_diff'] == ord('^'): + group = item['name'] + elif item['_diff'] == ord('+'): + self.buffers[index[0]].nicklist_add_item( + group, item['group'], item['prefix'], item['name'], + item['visible']) + elif item['_diff'] == ord('-'): + self.buffers[index[0]].nicklist_remove_item( + group, item['group'], item['name']) + elif item['_diff'] == ord('*'): + self.buffers[index[0]].nicklist_update_item( + group, item['group'], item['prefix'], item['name'], + item['visible']) + for index in buffer_refresh: + self.buffers[index].nicklist_refresh() + + def _parse_buffer_opened(self, message): + """Parse a WeeChat message with a new buffer (opened).""" + for obj in message.objects: + if obj.objtype != 'hda' or obj.value['path'][-1] != 'buffer': + continue + for item in obj.value['items']: + buf = self.create_buffer(item) + index = self.find_buffer_index_for_insert(item['next_buffer']) + self.insert_buffer(index, buf) + + def _parse_buffer(self, message): + """Parse a WeeChat message with a buffer event + (anything except a new buffer). + """ + for obj in message.objects: + if obj.objtype != 'hda' or obj.value['path'][-1] != 'buffer': + continue + for item in obj.value['items']: + index = [i for i, b in enumerate(self.buffers) + if b.pointer() == item['__path'][0]] + if not index: + continue + index = index[0] + if message.msgid == '_buffer_type_changed': + self.buffers[index].data['type'] = item['type'] + elif message.msgid in ('_buffer_moved', '_buffer_merged', + '_buffer_unmerged'): + buf = self.buffers[index] + buf.data['number'] = item['number'] + self.remove_buffer(index) + index2 = self.find_buffer_index_for_insert( + item['next_buffer']) + self.insert_buffer(index2, buf) + elif message.msgid == '_buffer_renamed': + self.buffers[index].data['full_name'] = item['full_name'] + self.buffers[index].data['short_name'] = item['short_name'] + elif message.msgid == '_buffer_title_changed': + self.buffers[index].data['title'] = item['title'] + self.buffers[index].update_title() + elif message.msgid == '_buffer_cleared': + self.buffers[index].widget.chat.clear() + elif message.msgid.startswith('_buffer_localvar_'): + self.buffers[index].data['local_variables'] = \ + item['local_variables'] + self.buffers[index].update_prompt() + elif message.msgid == '_buffer_closing': + self.remove_buffer(index) + + def parse_message(self, message): + """Parse a WeeChat message.""" + if message.msgid.startswith('debug'): + self.network.debug_print(0, '', '(debug message, ignored)') + elif message.msgid == 'handshake': + self._parse_handshake(message) + elif message.msgid == 'listbuffers': + self._parse_listbuffers(message) + elif message.msgid in ('listlines', '_buffer_line_added'): + self._parse_line(message) + elif message.msgid in ('_nicklist', 'nicklist'): + self._parse_nicklist(message) + elif message.msgid == '_nicklist_diff': + self._parse_nicklist_diff(message) + elif message.msgid == '_buffer_opened': + self._parse_buffer_opened(message) + elif message.msgid.startswith('_buffer_'): + self._parse_buffer(message) + elif message.msgid == '_upgrade': + self.network.desync_weechat() + elif message.msgid == '_upgrade_ended': + self.network.sync_weechat() + else: + print(f"Unknown message with id {message.msgid}") + + def create_buffer(self, item): + """Create a new buffer.""" + buf = WeegtkChat(data=item) + buf.connect("buffer_input", self.buffer_input) + return buf + + def insert_buffer(self, index, buf): + """Insert a buffer in list.""" + self.buffers.insert(index, buf) + buf_name = buf.data['short_name'] + + # Only make chats visible on main screen + if buf.is_chat(): + self.props.active_window.stack.add_titled(buf, name=buf_name, title=buf_name) + + def buffer_input(self, source_object, full_name, text): + if self.network.is_connected(): + message = f"input {full_name} {text}\n" + self.network.send_to_weechat(message) + +def main(version): + """The application's entry point.""" + app = WeegtkApplication() + return app.run(sys.argv) diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..3225adc --- /dev/null +++ b/src/meson.build @@ -0,0 +1,42 @@ +pkgdatadir = get_option('prefix') / get_option('datadir') / meson.project_name() +moduledir = pkgdatadir / 'weegtk' +gnome = import('gnome') + +gnome.compile_resources('weegtk', + 'weegtk.gresource.xml', + gresource_bundle: true, + install: true, + install_dir: pkgdatadir, +) + +python = import('python') + +conf = configuration_data() +conf.set('PYTHON', python.find_installation('python3').full_path()) +conf.set('VERSION', meson.project_version()) +conf.set('localedir', get_option('prefix') / get_option('localedir')) +conf.set('pkgdatadir', pkgdatadir) + +configure_file( + input: 'weegtk.in', + output: 'weegtk', + configuration: conf, + install: true, + install_dir: get_option('bindir'), + install_mode: 'r-xr-xr-x' +) + +weegtk_sources = [ + '__init__.py', + 'main.py', + 'window.py', + 'config.py', + 'chat.py', + 'message.py', + 'preferences.py', + 'relay/network.py', + 'relay/protocol.py', + 'relay/color.py' +] + +install_data(weegtk_sources, install_dir: moduledir) diff --git a/src/message.py b/src/message.py new file mode 100644 index 0000000..a6e69a4 --- /dev/null +++ b/src/message.py @@ -0,0 +1,48 @@ +# window.py +# +# Copyright 2024 Lucas Fryzek +# +# 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 <https://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: GPL-3.0-or-later +from gi.repository import Adw +from gi.repository import Gtk + +@Gtk.Template(resource_path='/com/fryzekconcepts/weegtk/gtk/message.ui') +class WeegtkMessage(Gtk.Box): + __gtype_name__ = 'WeegtkMessage' + + username = Gtk.Template.Child() + avatar = Gtk.Template.Child() + message_list = Gtk.Template.Child() + + def __init__(self, username="username", messages=[], **kwargs): + super().__init__(**kwargs) + + self.set_contents(username, messages) + + def set_contents(self, username, messages): + self.username.set_label(username) + self.avatar.set_text(username) + + first = True + for message in messages: + margin = 5 if not first else 0 + first = False + msg = Gtk.Label(label=message, selectable=True, + wrap=True, halign=0, hexpand=True, hexpand_set=True, + xalign=0, margin_top=margin) + self.message_list.append(msg) + + diff --git a/src/preferences.py b/src/preferences.py new file mode 100644 index 0000000..d864012 --- /dev/null +++ b/src/preferences.py @@ -0,0 +1,90 @@ +# window.py +# +# Copyright 2024 Lucas Fryzek +# +# 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 <https://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: GPL-3.0-or-later +from gi.repository import Adw +from gi.repository import Gtk +from gi.repository import GLib + +from weegtk import config + +import os + +@Gtk.Template(resource_path='/com/fryzekconcepts/weegtk/gtk/preferences.ui') +class WeegtkPreferences(Adw.PreferencesDialog): + __gtype_name__ = 'WeegtkPreferences' + + hostname = Gtk.Template.Child() + port = Gtk.Template.Child() + password = Gtk.Template.Child() + + ssh_host = Gtk.Template.Child() + ssh_port = Gtk.Template.Child() + ssh_username = Gtk.Template.Child() + ssh_key_label = Gtk.Template.Child() + + ssh_key_path = "" + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.config = config.read() + + self.hostname.set_text(self.config["relay"]["hostname"]) + self.port.set_text(self.config["relay"]["port"]) + self.password.set_text(self.config["relay"]["password"]) + + self.ssh_host.set_text(self.config["ssh"]["host"]) + self.ssh_port.set_text(self.config["ssh"]["port"]) + self.ssh_username.set_text(self.config["ssh"]["username"]) + self.set_ssh_key(self.config["ssh"]["key"]) + + self.install_action("ssh_key.open", None, self.ssh_key_open) + + def read_preferences(self): + self.config["relay"]["hostname"] = self.hostname.get_text() + self.config["relay"]["port"] = self.port.get_text() + self.config["relay"]["password"] = self.password.get_text() + + self.config["ssh"]["host"] = self.ssh_host.get_text() + self.config["ssh"]["port"] = self.ssh_port.get_text() + self.config["ssh"]["username"] = self.ssh_username.get_text() + self.config["ssh"]["key"] = self.ssh_key_path + + def set_ssh_key(self, key_path): + self.ssh_key_path = key_path + short_name = os.path.basename(key_path) + self.ssh_key_label.set_label(short_name) + + def ssh_key_open_dialog(self, dialog, result, caller): + try: + file = dialog.open_finish(result) + except GLib.GError: + # gtk-dialog-error-quark: Dismissed by user + pass + else: + self.set_ssh_key(file.get_path()) + + def ssh_key_open(self, *args): + dialog = Gtk.FileDialog() + dialog.set_title("Select SSH private key") + dialog.open(self.get_root(), None, self.ssh_key_open_dialog, self) + + @Gtk.Template.Callback() + def preferences_closed(self, *args): + self.read_preferences() + config.write(self.config) diff --git a/src/relay/color.py b/src/relay/color.py new file mode 100644 index 0000000..61b70ff --- /dev/null +++ b/src/relay/color.py @@ -0,0 +1,198 @@ +# -*- coding: utf-8 -*- +# +# color.py - remove/replace colors in WeeChat strings +# +# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org> +# +# This file is part of QWeeChat, a Qt remote GUI for WeeChat. +# +# QWeeChat 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. +# +# QWeeChat 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 QWeeChat. If not, see <http://www.gnu.org/licenses/>. +# + +"""Remove/replace colors in WeeChat strings.""" + +import re +import logging + +RE_COLOR_ATTRS = r'[*!/_|]*' +RE_COLOR_STD = r'(?:%s\d{2})' % RE_COLOR_ATTRS +RE_COLOR_EXT = r'(?:@%s\d{5})' % RE_COLOR_ATTRS +RE_COLOR_ANY = r'(?:%s|%s)' % (RE_COLOR_STD, RE_COLOR_EXT) +# \x19: color code, \x1A: set attribute, \x1B: remove attribute, \x1C: reset +RE_COLOR = re.compile( + r'(\x19(?:\d{2}|F%s|B\d{2}|B@\d{5}|E|\\*%s(~%s)?|@\d{5}|b.|\x1C))|\x1A.|' + r'\x1B.|\x1C' + % (RE_COLOR_ANY, RE_COLOR_ANY, RE_COLOR_ANY)) + +TERMINAL_COLORS = \ + '000000cd000000cd00cdcd000000cdcd00cd00cdcde5e5e5' \ + '4d4d4dff000000ff00ffff000000ffff00ff00ffffffffff' \ + '00000000002a0000550000800000aa0000d4002a00002a2a' \ + '002a55002a80002aaa002ad400550000552a005555005580' \ + '0055aa0055d400800000802a0080550080800080aa0080d4' \ + '00aa0000aa2a00aa5500aa8000aaaa00aad400d40000d42a' \ + '00d45500d48000d4aa00d4d42a00002a002a2a00552a0080' \ + '2a00aa2a00d42a2a002a2a2a2a2a552a2a802a2aaa2a2ad4' \ + '2a55002a552a2a55552a55802a55aa2a55d42a80002a802a' \ + '2a80552a80802a80aa2a80d42aaa002aaa2a2aaa552aaa80' \ + '2aaaaa2aaad42ad4002ad42a2ad4552ad4802ad4aa2ad4d4' \ + '55000055002a5500555500805500aa5500d4552a00552a2a' \ + '552a55552a80552aaa552ad455550055552a555555555580' \ + '5555aa5555d455800055802a5580555580805580aa5580d4' \ + '55aa0055aa2a55aa5555aa8055aaaa55aad455d40055d42a' \ + '55d45555d48055d4aa55d4d480000080002a800055800080' \ + '8000aa8000d4802a00802a2a802a55802a80802aaa802ad4' \ + '80550080552a8055558055808055aa8055d480800080802a' \ + '8080558080808080aa8080d480aa0080aa2a80aa5580aa80' \ + '80aaaa80aad480d40080d42a80d45580d48080d4aa80d4d4' \ + 'aa0000aa002aaa0055aa0080aa00aaaa00d4aa2a00aa2a2a' \ + 'aa2a55aa2a80aa2aaaaa2ad4aa5500aa552aaa5555aa5580' \ + 'aa55aaaa55d4aa8000aa802aaa8055aa8080aa80aaaa80d4' \ + 'aaaa00aaaa2aaaaa55aaaa80aaaaaaaaaad4aad400aad42a' \ + 'aad455aad480aad4aaaad4d4d40000d4002ad40055d40080' \ + 'd400aad400d4d42a00d42a2ad42a55d42a80d42aaad42ad4' \ + 'd45500d4552ad45555d45580d455aad455d4d48000d4802a' \ + 'd48055d48080d480aad480d4d4aa00d4aa2ad4aa55d4aa80' \ + 'd4aaaad4aad4d4d400d4d42ad4d455d4d480d4d4aad4d4d4' \ + '0808081212121c1c1c2626263030303a3a3a4444444e4e4e' \ + '5858586262626c6c6c7676768080808a8a8a9494949e9e9e' \ + 'a8a8a8b2b2b2bcbcbcc6c6c6d0d0d0dadadae4e4e4eeeeee' + +# WeeChat basic colors (color name, index in terminal colors) +WEECHAT_BASIC_COLORS = ( + ('default', 0), ('black', 0), ('darkgray', 8), ('red', 1), + ('lightred', 9), ('green', 2), ('lightgreen', 10), ('brown', 3), + ('yellow', 11), ('blue', 4), ('lightblue', 12), ('magenta', 5), + ('lightmagenta', 13), ('cyan', 6), ('lightcyan', 14), ('gray', 7), + ('white', 0)) + + +log = logging.getLogger(__name__) + + +class Color(): + def __init__(self, color_options, debug=False): + self.color_options = color_options + self.debug = debug + + def _rgb_color(self, index): + color = TERMINAL_COLORS[index*6:(index*6)+6] + col_r = int(color[0:2], 16) * 0.85 + col_g = int(color[2:4], 16) * 0.85 + col_b = int(color[4:6], 16) * 0.85 + return '%02x%02x%02x' % (col_r, col_g, col_b) + + def _convert_weechat_color(self, color): + # TODO figure out if I want to do something here + return '' + + def _convert_terminal_color(self, fg_bg, attrs, color): + try: + index = int(color) + return '\x01(%s%s#%s)' % (fg_bg, attrs, self._rgb_color(index)) + except Exception: # noqa: E722 + log.debug('Error decoding terminal color "%s"', color) + return '' + + def _convert_color_attr(self, fg_bg, color): + extended = False + if color[0].startswith('@'): + extended = True + color = color[1:] + attrs = '' + # keep_attrs = False + while color.startswith(('*', '!', '/', '_', '|')): + # TODO: manage the "keep attributes" flag + # if color[0] == '|': + # keep_attrs = True + attrs += color[0] + color = color[1:] + if extended: + return self._convert_terminal_color(fg_bg, attrs, color) + try: + index = int(color) + return self._convert_terminal_color(fg_bg, attrs, + WEECHAT_BASIC_COLORS[index][1]) + except Exception: # noqa: E722 + log.debug('Error decoding color "%s"', color) + return '' + + def _attrcode_to_char(self, code): + codes = { + '\x01': '*', + '\x02': '!', + '\x03': '/', + '\x04': '_', + } + return codes.get(code, '') + + def _convert_color(self, match): + # TODO figure out how to deal with color + color = match.group(0) + if color[0] == '\x19': + if color[1] == 'b': + # bar code, ignored + return '' + if color[1] == '\x1C': + # reset + return '' + if color[1] in ('F', 'B'): + # foreground or background + return self._convert_color_attr(color[1], color[2:]) + if color[1] == '*': + # foreground with optional background + items = color[2:].split(',') + str_col = self._convert_color_attr('F', items[0]) + if len(items) > 1: + str_col += self._convert_color_attr('B', items[1]) + return str_col + if color[1] == '@': + # direct ncurses pair number, ignored + return '' + if color[1] == 'E': + # text emphasis, ignored + return '' + if color[1:].isdigit(): + return self._convert_weechat_color(int(color[1:])) + elif color[0] == '\x1A': + # set attribute + return '\x01(+%s)' % self._attrcode_to_char(color[1]) + elif color[0] == '\x1B': + # remove attribute + return '\x01(-%s)' % self._attrcode_to_char(color[1]) + elif color[0] == '\x1C': + # reset + return '' + # should never be executed! + return match.group(0) + + def _convert_color_debug(self, match): + group = match.group(0) + for code in (0x01, 0x02, 0x03, 0x04, 0x19, 0x1A, 0x1B): + group = group.replace(chr(code), '<x%02X>' % code) + return group + + def convert(self, text): + if not text: + return '' + if self.debug: + return RE_COLOR.sub(self._convert_color_debug, text) + return RE_COLOR.sub(self._convert_color, text) + + +def remove(text): + """Remove colors in a WeeChat string.""" + if not text: + return '' + return re.sub(RE_COLOR, '', text) diff --git a/src/relay/network.py b/src/relay/network.py new file mode 100644 index 0000000..1071f1a --- /dev/null +++ b/src/relay/network.py @@ -0,0 +1,403 @@ +# -*- coding: utf-8 -*- +# +# network.py - I/O with WeeChat/relay +# +# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org> +# +# This file is part of QWeeChat, a Qt remote GUI for WeeChat. +# +# QWeeChat 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. +# +# QWeeChat 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 QWeeChat. If not, see <http://www.gnu.org/licenses/>. +# + +"""I/O with WeeChat/relay.""" + +import hashlib +import secrets +import struct + +from gi.repository import GObject, GLib, Gio + +from weegtk import config + +from sshtunnel import SSHTunnelForwarder + +# list of supported hash algorithms on our side +# (the hash algorithm will be negotiated with the remote WeeChat) +_HASH_ALGOS_LIST = [ + 'plain', + 'sha256', + 'sha512', + 'pbkdf2+sha256', + 'pbkdf2+sha512', +] +_HASH_ALGOS = ':'.join(_HASH_ALGOS_LIST) + +# handshake with remote WeeChat (before init) +_PROTO_HANDSHAKE = f'(handshake) handshake password_hash_algo={_HASH_ALGOS}\n' + +# initialize with the password (plain text) +_PROTO_INIT_PWD = 'init password=%(password)s%(totp)s\n' # nosec + +# initialize with the hashed password +_PROTO_INIT_HASH = ('init password_hash=' + '%(algo)s:%(salt)s%(iter)s:%(hash)s%(totp)s\n') + +_PROTO_SYNC_CMDS = [ + # get buffers + '(listbuffers) hdata buffer:gui_buffers(*) number,full_name,short_name,' + 'type,nicklist,title,local_variables', + # get lines + '(listlines) hdata buffer:gui_buffers(*)/own_lines/last_line(-%(lines)d)/' + 'data date,displayed,prefix,message', + # get nicklist for all buffers + '(nicklist) nicklist', + # enable synchronization + 'sync', +] + +STATUS_DISCONNECTED = 'disconnected' +STATUS_CONNECTING = 'connecting' +STATUS_AUTHENTICATING = 'authenticating' +STATUS_CONNECTED = 'connected' + +NETWORK_STATUS = { + STATUS_DISCONNECTED: { + 'label': 'Disconnected', + 'color': '#aa0000', + 'icon': 'dialog-close.png', + }, + STATUS_CONNECTING: { + 'label': 'Connecting…', + 'color': '#dd5f00', + 'icon': 'dialog-warning.png', + }, + STATUS_AUTHENTICATING: { + 'label': 'Authenticating…', + 'color': '#007fff', + 'icon': 'dialog-password.png', + }, + STATUS_CONNECTED: { + 'label': 'Connected', + 'color': 'green', + 'icon': 'dialog-ok-apply.png', + }, +} + + +class Network(GObject.GObject): + """I/O with WeeChat/relay.""" + __gsignals__ = { + "status_changed" : ( + GObject.SignalFlags.RUN_FIRST, + None, + (str, str) + ), + "message_from_weechat" : ( + GObject.SignalFlags.RUN_FIRST, + None, + (GLib.Bytes,) + ) + } + + def __init__(self, *args): + super().__init__(*args) + self._init_connection() + self.debug_lines = [] + self.debug_dialog = None + self._lines = config.CONFIG_DEFAULT_RELAY_LINES + self.cancel_network_reads = Gio.Cancellable() + self._buffer = bytearray() + self._socketclient = Gio.SocketClient.new() + self._socket = None + + # TODO figure out how to deal with these signals + #self._socket.connected.self._socket_connected) + #self._socket.readyRead.connect(self._socket_read) + #self._socket.disconnected.connect(self._socket_disconnected) + + def _init_connection(self): + self.status = STATUS_DISCONNECTED + self._hostname = None + self._port = None + self._ssl = None + self._password = None + self._totp = None + self._handshake_received = False + self._handshake_timer = None + self._pwd_hash_algo = None + self._pwd_hash_iter = 0 + self._server_nonce = None + + def set_status(self, status): + """Set current status.""" + self.status = status + self.emit("status_changed", status, None) + + def pbkdf2(self, hash_name, salt): + """Return hashed password with PBKDF2-HMAC.""" + return hashlib.pbkdf2_hmac( + hash_name, + password=self._password.encode('utf-8'), + salt=salt, + iterations=self._pwd_hash_iter, + ).hex() + + def _build_init_command(self): + """Build the init command to send to WeeChat.""" + totp = f',totp={self._totp}' if self._totp else '' + if self._pwd_hash_algo == 'plain': # nosec + cmd = _PROTO_INIT_PWD % { + 'password': self._password, + 'totp': totp, + } + else: + client_nonce = secrets.token_bytes(16) + salt = self._server_nonce + client_nonce + pwd_hash = None + iterations = '' + if self._pwd_hash_algo == 'pbkdf2+sha512': # nosec + pwd_hash = self.pbkdf2('sha512', salt) + iterations = f':{self._pwd_hash_iter}' + elif self._pwd_hash_algo == 'pbkdf2+sha256': # nosec + pwd_hash = self.pbkdf2('sha256', salt) + iterations = f':{self._pwd_hash_iter}' + elif self._pwd_hash_algo == 'sha512': # nosec + pwd = salt + self._password.encode('utf-8') + pwd_hash = hashlib.sha512(pwd).hexdigest() + elif self._pwd_hash_algo == 'sha256': # nosec + pwd = salt + self._password.encode('utf-8') + pwd_hash = hashlib.sha256(pwd).hexdigest() + if not pwd_hash: + return None + cmd = _PROTO_INIT_HASH % { + 'algo': self._pwd_hash_algo, + 'salt': bytearray(salt).hex(), + 'iter': iterations, + 'hash': pwd_hash, + 'totp': totp, + } + return cmd + + def _build_sync_command(self): + """Build the sync commands to send to WeeChat.""" + cmd = '\n'.join(_PROTO_SYNC_CMDS) + '\n' + return cmd % {'lines': self._lines} + + def handshake_timer_expired(self): + if self.status == STATUS_AUTHENTICATING: + self._pwd_hash_algo = 'plain' # nosec + self.send_to_weechat(self._build_init_command()) + self.sync_weechat() + self.set_status(STATUS_CONNECTED) + return False + + def _socket_connected(self): + """Slot: socket connected.""" + self.set_status(STATUS_AUTHENTICATING) + self.send_to_weechat(_PROTO_HANDSHAKE) + self._handshake_timer = GLib.timeout_add(2000, self.handshake_timer_expired) + + def _socket_read(self, source_object, res, *user_data): + """Slot: data available on socket.""" + try: + gbytes = self.input.read_bytes_finish(res) + except GLib.Error as err: + self.handle_network_error(err) + return + + self._buffer.extend(gbytes.get_data()) + while len(self._buffer) >= 4: + remainder = None + length = struct.unpack('>i', self._buffer[0:4])[0] + if len(self._buffer) < length: + # partial message, just wait for end of message + break + # more than one message? + if length < len(self._buffer): + # save beginning of another message + remainder = self._buffer[length:] + self._buffer = self._buffer[0:length] + self.emit("message_from_weechat", GLib.Bytes(self._buffer)) + if not self.is_connected(): + return + self._buffer.clear() + if remainder: + self._buffer.extend(remainder) + + self.input.read_bytes_async( + 4096, 0, self.cancel_network_reads, self._socket_read) + + def _socket_disconnected(self): + """Slot: socket disconnected.""" + if self._handshake_timer: + self._handshake_timer.stop() + self._init_connection() + self.set_status(STATUS_DISCONNECTED) + + def is_connected(self): + """Return True if the socket is connected, False otherwise.""" + return self._socket.is_connected() + + def is_ssl(self): + """Return True if SSL is used, False otherwise.""" + return self._ssl + + def connect_weechat_ssh(self, ssh_host, ssh_port, ssh_username, ssh_key, + relay_host, relay_port, relay_pw): + self.ssh_tunnel = SSHTunnelForwarder( + ssh_host, + ssh_username=ssh_username, + ssh_pkey=ssh_key, + remote_bind_address=(relay_host, int(relay_port))) + + self.ssh_tunnel.start() + + self.connect_weechat("localhost", self.ssh_tunnel.local_bind_port, + False, relay_pw, None, "") + + def connect_weechat(self, hostname, port, ssl, password, totp, lines): + """Connect to WeeChat.""" + self._hostname = hostname + try: + self._port = int(port) + except ValueError: + self._port = 0 + self._ssl = ssl + self._password = password + self._totp = totp + try: + self._lines = int(lines) + except ValueError: + self._lines = config.CONFIG_DEFAULT_RELAY_LINES + + # TODO handle SSL + self._socketclient.connect_async( + Gio.NetworkAddress.new(self._hostname, self._port), + None, + self._connected_func, None) + self.set_status(STATUS_CONNECTING) + + def _connected_func(self, source_object, res, *user_data): + """Callback function called after connection attempt.""" + try: + self._socket = self._socketclient.connect_finish(res) + except GLib.Error as err: + print("Connection failed:\n{}".format(err.message)) + self.set_status(STATUS_NOT_CONNECTED) + return + else: + print("Connected") + self.set_status(STATUS_CONNECTED) + self._socket_connected() + self.input = self._socket.get_input_stream() + self.input.read_bytes_async( + 4096, 0, self.cancel_network_reads, self._socket_read) + + def disconnect_weechat(self): + """Disconnect from WeeChat.""" + if self._socket.state() == QtNetwork.QAbstractSocket.UnconnectedState: + self.set_status(STATUS_DISCONNECTED) + return + if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState: + self.send_to_weechat('quit\n') + self._socket.waitForBytesWritten(1000) + else: + self.set_status(STATUS_DISCONNECTED) + self._socket.abort() + + def send_to_weechat(self, message): + """Send a message to WeeChat.""" + output = self._socket.get_output_stream() + try: + output.write(message.encode("utf-8")) + except GLib.Error as err: + self.handle_network_error(err) + + def init_with_handshake(self, response): + """Initialize with WeeChat using the handshake response.""" + self._pwd_hash_algo = response['password_hash_algo'] + self._pwd_hash_iter = int(response['password_hash_iterations']) + self._server_nonce = bytearray.fromhex(response['nonce']) + if self._pwd_hash_algo: + cmd = self._build_init_command() + if cmd: + self.send_to_weechat(cmd) + self.sync_weechat() + self.set_status(STATUS_CONNECTED) + return + # failed to initialize: disconnect + self.disconnect_weechat() + + def desync_weechat(self): + """Desynchronize from WeeChat.""" + self.send_to_weechat('desync\n') + + def sync_weechat(self): + """Synchronize with WeeChat.""" + self.send_to_weechat(self._build_sync_command()) + + def status_label(self, status): + """Return the label for a given status.""" + return NETWORK_STATUS.get(status, {}).get('label', '') + + def status_color(self, status): + """Return the color for a given status.""" + return NETWORK_STATUS.get(status, {}).get('color', 'black') + + def status_icon(self, status): + """Return the name of icon for a given status.""" + return NETWORK_STATUS.get(status, {}).get('icon', '') + + def get_options(self): + """Get connection options.""" + return { + 'hostname': self._hostname, + 'port': self._port, + 'ssl': 'on' if self._ssl else 'off', + 'password': self._password, + 'lines': str(self._lines), + } + + def debug_print(self, *args, **kwargs): + """Display a debug message.""" + self.debug_lines.append((args, kwargs)) + if self.debug_dialog: + self.debug_dialog.chat.display(*args, **kwargs) + + def _debug_dialog_closed(self, result): + """Called when debug dialog is closed.""" + self.debug_dialog = None + + def debug_input_text_sent(self, text): + """Send debug buffer input to WeeChat.""" + if self.network.is_connected(): + text = str(text) + pos = text.find(')') + if text.startswith('(') and pos >= 0: + text = '(debug_%s)%s' % (text[1:pos], text[pos+1:]) + else: + text = '(debug) %s' % text + self.network.debug_print(0, '<==', text, forcecolor='#AA0000') + self.network.send_to_weechat(text + '\n') + + def open_debug_dialog(self): + """Open a dialog with debug messages.""" + if not self.debug_dialog: + self.debug_dialog = DebugDialog() + self.debug_dialog.input.textSent.connect( + self.debug_input_text_sent) + self.debug_dialog.finished.connect(self._debug_dialog_closed) + self.debug_dialog.display_lines(self.debug_lines) + self.debug_dialog.chat.scroll_bottom() + diff --git a/src/relay/protocol.py b/src/relay/protocol.py new file mode 100644 index 0000000..6f70544 --- /dev/null +++ b/src/relay/protocol.py @@ -0,0 +1,362 @@ +# -*- coding: utf-8 -*- +# +# protocol.py - decode binary messages received from WeeChat/relay +# +# Copyright (C) 2011-2022 Sébastien Helleu <flashcode@flashtux.org> +# +# This file is part of QWeeChat, a Qt remote GUI for WeeChat. +# +# QWeeChat 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. +# +# QWeeChat 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 QWeeChat. If not, see <http://www.gnu.org/licenses/>. +# + +# +# For info about protocol and format of messages, please read document +# "WeeChat Relay Protocol", available at: https://weechat.org/doc/ +# +# History: +# +# 2011-11-23, Sébastien Helleu <flashcode@flashtux.org>: +# start dev +# + +"""Decode binary messages received from WeeChat/relay.""" + +import collections +import struct +import zlib + + +class WeechatDict(collections.OrderedDict): + def __str__(self): + return '{%s}' % ', '.join( + ['%s: %s' % (repr(key), repr(self[key])) for key in self]) + + +class WeechatObject: + def __init__(self, objtype, value, separator='\n'): + self.objtype = objtype + self.value = value + self.separator = separator + self.indent = ' ' if separator == '\n' else '' + self.separator1 = '\n%s' % self.indent if separator == '\n' else '' + + def _str_value(self, val): + if isinstance(val, str) and val is not None: + return '\'%s\'' % val + return str(val) + + def _str_value_hdata(self): + lines = ['%skeys: %s%s%spath: %s' % (self.separator1, + str(self.value['keys']), + self.separator, + self.indent, + str(self.value['path']))] + for i, item in enumerate(self.value['items']): + lines.append(' item %d:%s%s' % ( + (i + 1), self.separator, + self.separator.join( + ['%s%s: %s' % (self.indent * 2, key, + self._str_value(value)) + for key, value in item.items()]))) + return '\n'.join(lines) + + def _str_value_infolist(self): + lines = ['%sname: %s' % (self.separator1, self.value['name'])] + for i, item in enumerate(self.value['items']): + lines.append(' item %d:%s%s' % ( + (i + 1), self.separator, + self.separator.join( + ['%s%s: %s' % (self.indent * 2, key, + self._str_value(value)) + for key, value in item.items()]))) + return '\n'.join(lines) + + def _str_value_other(self): + return self._str_value(self.value) + + def __str__(self): + obj_cb = { + 'hda': self._str_value_hdata, + 'inl': self._str_value_infolist, + } + return '%s: %s' % (self.objtype, + obj_cb.get(self.objtype, self._str_value_other)()) + + +class WeechatObjects(list): + def __init__(self, separator='\n'): + super().__init__() + self.separator = separator + + def __str__(self): + return self.separator.join([str(obj) for obj in self]) + + +class WeechatMessage: + def __init__(self, size, size_uncompressed, compression, uncompressed, + msgid, objects): + self.size = size + self.size_uncompressed = size_uncompressed + self.compression = compression + self.uncompressed = uncompressed + self.msgid = msgid + self.objects = objects + + def __str__(self): + if self.compression != 0: + return 'size: %d/%d (%d%%), id=\'%s\', objects:\n%s' % ( + self.size, self.size_uncompressed, + 100 - ((self.size * 100) // self.size_uncompressed), + self.msgid, self.objects) + return 'size: %d, id=\'%s\', objects:\n%s' % (self.size, + self.msgid, + self.objects) + + +class Protocol: + """Decode binary message received from WeeChat/relay.""" + + def __init__(self): + self.data = '' + self._obj_cb = { + 'chr': self._obj_char, + 'int': self._obj_int, + 'lon': self._obj_long, + 'str': self._obj_str, + 'buf': self._obj_buffer, + 'ptr': self._obj_ptr, + 'tim': self._obj_time, + 'htb': self._obj_hashtable, + 'hda': self._obj_hdata, + 'inf': self._obj_info, + 'inl': self._obj_infolist, + 'arr': self._obj_array, + } + + def _obj_type(self): + """Read type in data (3 chars).""" + if len(self.data) < 3: + self.data = '' + return '' + objtype = self.data[0:3].decode() + self.data = self.data[3:] + return objtype + + def _obj_len_data(self, length_size): + """Read length (1 or 4 bytes), then value with this length.""" + if len(self.data) < length_size: + self.data = '' + return None + if length_size == 1: + length = struct.unpack('B', self.data[0:1])[0] + self.data = self.data[1:] + else: + length = self._obj_int() + if length < 0: + return None + if length > 0: + value = self.data[0:length] + self.data = self.data[length:] + else: + value = '' + return value + + def _obj_char(self): + """Read a char in data.""" + if len(self.data) < 1: + return 0 + value = struct.unpack('b', self.data[0:1])[0] + self.data = self.data[1:] + return value + + def _obj_int(self): + """Read an integer in data (4 bytes).""" + if len(self.data) < 4: + self.data = '' + return 0 + value = struct.unpack('>i', self.data[0:4])[0] + self.data = self.data[4:] + return value + + def _obj_long(self): + """Read a long integer in data (length on 1 byte + value as string).""" + value = self._obj_len_data(1) + if value is None: + return None + return int(value) + + def _obj_str(self): + """Read a string in data (length on 4 bytes + content).""" + value = self._obj_len_data(4) + if value in ("", None): + return "" + return value.decode() + + def _obj_buffer(self): + """Read a buffer in data (length on 4 bytes + data).""" + return self._obj_len_data(4) + + def _obj_ptr(self): + """Read a pointer in data (length on 1 byte + value as string).""" + value = self._obj_len_data(1) + if value is None: + return None + return '0x%s' % value + + def _obj_time(self): + """Read a time in data (length on 1 byte + value as string).""" + value = self._obj_len_data(1) + if value is None: + return None + return int(value) + + def _obj_hashtable(self): + """ + Read a hashtable in data + (type for keys + type for values + count + items). + """ + type_keys = self._obj_type() + type_values = self._obj_type() + count = self._obj_int() + hashtable = WeechatDict() + for _ in range(count): + key = self._obj_cb[type_keys]() + value = self._obj_cb[type_values]() + hashtable[key] = value + return hashtable + + def _obj_hdata(self): + """Read a hdata in data.""" + path = self._obj_str() + keys = self._obj_str() + count = self._obj_int() + list_path = path.split('/') if path else [] + list_keys = keys.split(',') if keys else [] + keys_types = [] + dict_keys = WeechatDict() + for key in list_keys: + items = key.split(':') + keys_types.append(items) + dict_keys[items[0]] = items[1] + items = [] + for _ in range(count): + item = WeechatDict() + item['__path'] = [] + pointers = [] + for _ in enumerate(list_path): + pointers.append(self._obj_ptr()) + for key, objtype in keys_types: + item[key] = self._obj_cb[objtype]() + item['__path'] = pointers + items.append(item) + return { + 'path': list_path, + 'keys': dict_keys, + 'count': count, + 'items': items, + } + + def _obj_info(self): + """Read an info in data.""" + name = self._obj_str() + value = self._obj_str() + return (name, value) + + def _obj_infolist(self): + """Read an infolist in data.""" + name = self._obj_str() + count_items = self._obj_int() + items = [] + for _ in range(count_items): + count_vars = self._obj_int() + variables = WeechatDict() + for _ in range(count_vars): + var_name = self._obj_str() + var_type = self._obj_type() + var_value = self._obj_cb[var_type]() + variables[var_name] = var_value + items.append(variables) + return { + 'name': name, + 'items': items + } + + def _obj_array(self): + """Read an array of values in data.""" + type_values = self._obj_type() + count_values = self._obj_int() + values = [] + for _ in range(count_values): + values.append(self._obj_cb[type_values]()) + return values + + def decode(self, data, separator='\n'): + """Decode binary data and return list of objects.""" + self.data = data + size = len(self.data) + size_uncompressed = size + uncompressed = None + # uncompress data (if it is compressed) + compression = struct.unpack('b', self.data[4:5])[0] + if compression: + uncompressed = zlib.decompress(self.data[5:]) + size_uncompressed = len(uncompressed) + 5 + uncompressed = b'%s%s%s' % (struct.pack('>i', size_uncompressed), + struct.pack('b', 0), uncompressed) + self.data = uncompressed + else: + uncompressed = self.data[:] + # skip length and compression flag + self.data = self.data[5:] + # read id + msgid = self._obj_str() + if msgid is None: + msgid = '' + # read objects + objects = WeechatObjects(separator=separator) + while len(self.data) > 0: + objtype = self._obj_type() + value = self._obj_cb[objtype]() + objects.append(WeechatObject(objtype, value, separator=separator)) + return WeechatMessage(size, size_uncompressed, compression, + uncompressed, msgid, objects) + + +def hex_and_ascii(data, bytes_per_line=10): + """Convert a QByteArray to hex + ascii output.""" + num_lines = ((len(data) - 1) // bytes_per_line) + 1 + if num_lines == 0: + return '' + lines = [] + for i in range(num_lines): + str_hex = [] + str_ascii = [] + for j in range(bytes_per_line): + # We can't easily iterate over individual bytes, so we are going to + # do it this way. + index = (i*bytes_per_line) + j + char = data[index:index+1] + if not char: + char = b'x' + byte = struct.unpack('B', char)[0] + str_hex.append(b'%02X' % int(byte)) + if 32 <= byte <= 127: + str_ascii.append(char) + else: + str_ascii.append(b'.') + fmt = b'%%-%ds %%s' % ((bytes_per_line * 3) - 1) + lines.append(fmt % (b' '.join(str_hex), + b''.join(str_ascii))) + return b'\n'.join(lines) + diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..ae7eab8 --- /dev/null +++ b/src/style.css @@ -0,0 +1,9 @@ +label.username { + color: rgb(4, 97, 190); + font-weight: 700; +} + +box.message { + padding-top: 2px; + padding-bottom: 2px; +} diff --git a/src/weegtk.gresource.xml b/src/weegtk.gresource.xml new file mode 100644 index 0000000..c54ffe8 --- /dev/null +++ b/src/weegtk.gresource.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/com/fryzekconcepts/weegtk"> + <file preprocess="xml-stripblanks">window.ui</file> + <file preprocess="xml-stripblanks">gtk/help-overlay.ui</file> + <file preprocess="xml-stripblanks">gtk/chat.ui</file> + <file preprocess="xml-stripblanks">gtk/message.ui</file> + <file preprocess="xml-stripblanks">gtk/preferences.ui</file> + <file compressed="true">style.css</file> + </gresource> +</gresources> diff --git a/src/weegtk.in b/src/weegtk.in new file mode 100755 index 0000000..123a529 --- /dev/null +++ b/src/weegtk.in @@ -0,0 +1,46 @@ +#!@PYTHON@ + +# weegtk.in +# +# Copyright 2024 Lucas Fryzek +# +# 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 <https://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import os +import sys +import signal +import locale +import gettext + +VERSION = '@VERSION@' +pkgdatadir = '@pkgdatadir@' +localedir = '@localedir@' + +sys.path.insert(1, pkgdatadir) +signal.signal(signal.SIGINT, signal.SIG_DFL) +locale.bindtextdomain('weegtk', localedir) +locale.textdomain('weegtk') +gettext.install('weegtk', localedir) + +if __name__ == '__main__': + import gi + + from gi.repository import Gio + resource = Gio.Resource.load(os.path.join(pkgdatadir, 'weegtk.gresource')) + resource._register() + + from weegtk import main + sys.exit(main.main(VERSION)) diff --git a/src/window.py b/src/window.py new file mode 100644 index 0000000..df63e36 --- /dev/null +++ b/src/window.py @@ -0,0 +1,70 @@ +# window.py +# +# Copyright 2024 Lucas Fryzek +# +# 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 <https://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from gi.repository import Adw +from gi.repository import Gtk + +@Gtk.Template(resource_path='/com/fryzekconcepts/weegtk/window.ui') +class WeegtkWindow(Adw.ApplicationWindow): + __gtype_name__ = 'WeegtkWindow' + + stack = Gtk.Template.Child() + content_page = Gtk.Template.Child() + color_scheme_button = Gtk.Template.Child() + split_view = Gtk.Template.Child() + + def __init__(self, **kwargs): + super().__init__(**kwargs) + manager = Adw.StyleManager.get_default() + + manager.connect("notify::system-supports-color-schemes", + self.notify_system_supports_color_schemes_cb, + self, + False) + + self.notify_system_supports_color_schemes_cb() + self.notify_visible_child_cb() + + def notify_system_supports_color_schemes_cb(self): + manager = Adw.StyleManager.get_default() + supports = manager.get_system_supports_color_schemes() + + self.color_scheme_button.set_visible(not supports) + + if supports: + manager.set_color_scheme(Adw.ColorScheme.DEFAULT) + + @Gtk.Template.Callback() + def notify_visible_child_cb(self, *args): + child = self.stack.get_visible_child() + # When application starts up there are no buffers + if child is None: + return + page = self.stack.get_page(child) + self.content_page.set_title(page.get_title()) + self.split_view.set_show_content(True) + + @Gtk.Template.Callback() + def get_color_scheme_icon_name(self, user_data, dark): + return "light-mode-symbolic" if dark else "dark-mode-symbolic" + + @Gtk.Template.Callback() + def color_scheme_button_clicked_cb(self, *args): + raise NotImplementedError + diff --git a/src/window.ui b/src/window.ui new file mode 100644 index 0000000..3072280 --- /dev/null +++ b/src/window.ui @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk" version="4.0"/> + <requires lib="libadwaita" version="1.0"/> + <menu id="primary_menu"> + <section> + <item> + <attribute name="label" translatable="yes">_Preferences</attribute> + <attribute name="action">app.preferences</attribute> + </item> + <item> + <attribute name="label" translatable="yes">_About</attribute> + <attribute name="action">app.about</attribute> + </item> + </section> + </menu> + <template class="WeegtkWindow" parent="AdwApplicationWindow"> + <property name="title" translatable="yes">Weegtk</property> + <property name="default_width">800</property> + <property name="default_height">576</property> + <child> + <object class="AdwBreakpoint"> + <condition>max-width: 500sp</condition> + <setter object="split_view" property="collapsed">True</setter> + </object> + </child> + <property name="content"> + <object class="AdwToastOverlay" id="toast_overlay"> + <property name="child"> + <object class="AdwNavigationSplitView" id="split_view"> + <property name="min-sidebar-width">200</property> + <property name="sidebar"> + <object class="AdwNavigationPage"> + <property name="title" bind-source="WeegtkWindow" bind-property="title" bind-flags="sync-create"/> + <property name="child"> + <object class="AdwToolbarView"> + <child type="top"> + <object class="AdwHeaderBar"> + <child type="start"> + <object class="GtkButton" id="color_scheme_button"> + <binding name="icon-name"> + <closure type="gchararray" function="get_color_scheme_icon_name"> + <lookup name="dark" type="AdwStyleManager"> + <lookup name="style-manager" type="AdwApplication"> + <lookup name="application">WeegtkWindow</lookup> + </lookup> + </lookup> + </closure> + </binding> + <signal name="clicked" handler="color_scheme_button_clicked_cb" swapped="no"/> + </object> + </child> + <child type="end"> + <object class="GtkMenuButton"> + <property name="tooltip-text" translatable="yes">Main Menu</property> + <property name="menu-model">primary_menu</property> + <property name="icon-name">open-menu-symbolic</property> + <property name="primary">True</property> + </object> + </child> + </object> + </child> + <property name="content"> + <object class="GtkStackSidebar"> + <property name="stack">stack</property> + </object> + </property> + </object> + </property> + </object> + </property> + <property name="content"> + <object class="AdwNavigationPage" id="content_page"> + <property name="child"> + <object class="GtkStack" id="stack"> + <property name="vhomogeneous">False</property> + <signal name="notify::visible-child" handler="notify_visible_child_cb" after="yes" swapped="no"/> + </object> + </property> + </object> + </property> + </object> + </property> + </object> + </property> + </template> +</interface> |