From 98ae5de2bd40b6e67feec9d146c4a8eff0675e06 Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Mon, 25 Jan 2021 16:49:04 +0200 Subject: [PATCH 01/83] Initial commit to set up the repo. --- LICENSE | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 11 ++ 2 files changed, 350 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..23cb790 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE 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. + + 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 +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..be92e11 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# koto + +Koto is an in-development audiobook, music, and podcast manager that is designed *for* and caters *to* a modern desktop Linux experience. **Nothing to see here yet** but keep an eye on my [Patreon](https://patreon.com/joshuastrobl) or [personal site](https://joshuastrobl.com) for updates! + +## Blog + +- [Dev Diary 1: Koto - Foundations](https://joshuastrobl.com/2021/01/25/2021-01-25-dev-diary-1-koto-foundations) + +## License + +Koto is licensed under the Apache 2.0 license. \ No newline at end of file From c91b8a370939b73197c6a9ade565caf89e7508f7 Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Mon, 25 Jan 2021 17:01:17 +0200 Subject: [PATCH 02/83] Created our funding.yaml file --- .github/FUNDING.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..ac2385e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: JoshStrobl +patreon: joshuastrobl +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] From c30eb09c1250c3271669b5dfb583acf91b419a32 Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Mon, 25 Jan 2021 17:21:36 +0200 Subject: [PATCH 03/83] Fix dev diary 1 link. --- .gitignore | 2 ++ README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..032748e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +builddir +.buildconfig \ No newline at end of file diff --git a/README.md b/README.md index be92e11..fc3dbd2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Koto is an in-development audiobook, music, and podcast manager that is designed ## Blog -- [Dev Diary 1: Koto - Foundations](https://joshuastrobl.com/2021/01/25/2021-01-25-dev-diary-1-koto-foundations) +- [Dev Diary 1: Koto - Foundations](https://joshuastrobl.com/2021/01/25/dev-diary-1-koto-foundations/) ## License From 9aa493c51a1b2c786c171e14b81abc18d2daca9a Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Mon, 1 Feb 2021 07:02:28 +0200 Subject: [PATCH 04/83] Fix license file. Fixes #1. --- COPYING | 202 +++++++++++++++++++++++++++++++++ LICENSE | 339 -------------------------------------------------------- 2 files changed, 202 insertions(+), 339 deletions(-) create mode 100644 COPYING delete mode 100644 LICENSE diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/COPYING @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 23cb790..0000000 --- a/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) 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 -this service 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 make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. 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. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the 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 a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE 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. - - 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 -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - {description} - Copyright (C) {year} {fullname} - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision 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, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - {signature of Ty Coon}, 1 April 1989 - Ty Coon, President of Vice - -This 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. From 6fb3852f094f83987918bb6a14b9166b2695b9cf Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Tue, 9 Feb 2021 17:37:26 +0200 Subject: [PATCH 05/83] Work leading up to and including Day 4. - Initial window bits - Preliminary Nav sidebar - Expanders - Koto Button to reduce code duplication - Started work on indexer --- build-aux/meson/postinstall.py | 21 ++ com.github.joshstrobl.koto.json | 37 ++ .../com.github.joshstrobl.koto.appdata.xml.in | 8 + data/com.github.joshstrobl.koto.desktop.in | 7 + data/com.github.joshstrobl.koto.gschema.xml | 5 + data/meson.build | 41 +++ data/style.css | 20 ++ meson.build | 27 ++ po/LINGUAS | 0 po/POTFILES | 7 + po/meson.build | 1 + src/indexer/album.h | 33 ++ src/indexer/artist.h | 33 ++ src/indexer/file-indexer.c | 193 ++++++++++ src/indexer/file-indexer.h | 36 ++ src/indexer/meson.build | 8 + src/koto-button.c | 340 ++++++++++++++++++ src/koto-button.h | 57 +++ src/koto-expander.c | 245 +++++++++++++ src/koto-expander.h | 36 ++ src/koto-flipper-button.c | 129 +++++++ src/koto-flipper-button.h | 32 ++ src/koto-headerbar.c | 47 +++ src/koto-headerbar.h | 30 ++ src/koto-headerbar.ui | 40 +++ src/koto-nav.c | 155 ++++++++ src/koto-nav.h | 32 ++ src/koto-playerbar.c | 172 +++++++++ src/koto-playerbar.h | 32 ++ src/koto-utils.c | 28 ++ src/koto-utils.h | 24 ++ src/koto-window.c | 89 +++++ src/koto-window.h | 30 ++ src/koto-window.ui | 10 + src/koto.gresource.xml | 8 + src/main.c | 50 +++ src/meson.build | 31 ++ 37 files changed, 2094 insertions(+) create mode 100755 build-aux/meson/postinstall.py create mode 100644 com.github.joshstrobl.koto.json create mode 100644 data/com.github.joshstrobl.koto.appdata.xml.in create mode 100644 data/com.github.joshstrobl.koto.desktop.in create mode 100644 data/com.github.joshstrobl.koto.gschema.xml create mode 100644 data/meson.build create mode 100644 data/style.css create mode 100644 meson.build create mode 100644 po/LINGUAS create mode 100644 po/POTFILES create mode 100644 po/meson.build create mode 100644 src/indexer/album.h create mode 100644 src/indexer/artist.h create mode 100644 src/indexer/file-indexer.c create mode 100644 src/indexer/file-indexer.h create mode 100644 src/indexer/meson.build create mode 100644 src/koto-button.c create mode 100644 src/koto-button.h create mode 100644 src/koto-expander.c create mode 100644 src/koto-expander.h create mode 100644 src/koto-flipper-button.c create mode 100644 src/koto-flipper-button.h create mode 100644 src/koto-headerbar.c create mode 100644 src/koto-headerbar.h create mode 100644 src/koto-headerbar.ui create mode 100644 src/koto-nav.c create mode 100644 src/koto-nav.h create mode 100644 src/koto-playerbar.c create mode 100644 src/koto-playerbar.h create mode 100644 src/koto-utils.c create mode 100644 src/koto-utils.h create mode 100644 src/koto-window.c create mode 100644 src/koto-window.h create mode 100644 src/koto-window.ui create mode 100644 src/koto.gresource.xml create mode 100644 src/main.c create mode 100644 src/meson.build diff --git a/build-aux/meson/postinstall.py b/build-aux/meson/postinstall.py new file mode 100755 index 0000000..6a3ea97 --- /dev/null +++ b/build-aux/meson/postinstall.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +from os import environ, path +from subprocess import call + +prefix = environ.get('MESON_INSTALL_PREFIX', '/usr/local') +datadir = path.join(prefix, 'share') +destdir = environ.get('DESTDIR', '') + +# Package managers set this so we don't need to run +if not destdir: + print('Updating icon cache...') + call(['gtk-update-icon-cache', '-qtf', path.join(datadir, 'icons', 'hicolor')]) + + print('Updating desktop database...') + call(['update-desktop-database', '-q', path.join(datadir, 'applications')]) + + print('Compiling GSettings schemas...') + call(['glib-compile-schemas', path.join(datadir, 'glib-2.0', 'schemas')]) + + diff --git a/com.github.joshstrobl.koto.json b/com.github.joshstrobl.koto.json new file mode 100644 index 0000000..587014a --- /dev/null +++ b/com.github.joshstrobl.koto.json @@ -0,0 +1,37 @@ +{ + "app-id" : "com.github.joshstrobl.koto", + "runtime" : "org.gnome.Platform", + "runtime-version" : "3.38", + "sdk" : "org.gnome.Sdk", + "command" : "com.github.joshstrobl.koto", + "finish-args" : [ + "--share=network", + "--share=ipc", + "--socket=fallback-x11", + "--socket=wayland" + ], + "cleanup" : [ + "/include", + "/lib/pkgconfig", + "/man", + "/share/doc", + "/share/gtk-doc", + "/share/man", + "/share/pkgconfig", + "*.la", + "*.a" + ], + "modules" : [ + { + "name" : "koto", + "builddir" : true, + "buildsystem" : "meson", + "sources" : [ + { + "type" : "git", + "url" : "file:///home/joshua/Code/Personal/Koto" + } + ] + } + ] +} diff --git a/data/com.github.joshstrobl.koto.appdata.xml.in b/data/com.github.joshstrobl.koto.appdata.xml.in new file mode 100644 index 0000000..ce3a8a4 --- /dev/null +++ b/data/com.github.joshstrobl.koto.appdata.xml.in @@ -0,0 +1,8 @@ + + + com.github.joshstrobl.koto.desktop + CC0-1.0 + + + + diff --git a/data/com.github.joshstrobl.koto.desktop.in b/data/com.github.joshstrobl.koto.desktop.in new file mode 100644 index 0000000..fb87fd6 --- /dev/null +++ b/data/com.github.joshstrobl.koto.desktop.in @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=koto +Exec=koto +Terminal=false +Type=Application +Categories=GTK; +StartupNotify=true diff --git a/data/com.github.joshstrobl.koto.gschema.xml b/data/com.github.joshstrobl.koto.gschema.xml new file mode 100644 index 0000000..7ff368a --- /dev/null +++ b/data/com.github.joshstrobl.koto.gschema.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..3336028 --- /dev/null +++ b/data/meson.build @@ -0,0 +1,41 @@ +desktop_file = i18n.merge_file( + input: 'com.github.joshstrobl.koto.desktop.in', + output: 'com.github.joshstrobl.koto.desktop', + type: 'desktop', + po_dir: '../po', + install: true, + install_dir: join_paths(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.github.joshstrobl.koto.appdata.xml.in', + output: 'com.github.joshstrobl.koto.appdata.xml', + po_dir: '../po', + install: true, + install_dir: join_paths(get_option('datadir'), 'appdata') +) + +appstream_util = find_program('appstream-util', required: false) +if appstream_util.found() + test('Validate appstream file', appstream_util, + args: ['validate', appstream_file] + ) +endif + +install_data('com.github.joshstrobl.koto.gschema.xml', + install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas') +) + +compile_schemas = find_program('glib-compile-schemas', required: false) +if compile_schemas.found() + test('Validate schema file', compile_schemas, + args: ['--strict', '--dry-run', meson.current_source_dir()] + ) +endif diff --git a/data/style.css b/data/style.css new file mode 100644 index 0000000..5329f46 --- /dev/null +++ b/data/style.css @@ -0,0 +1,20 @@ +.primary-nav > .frame > box >.koto-button { + padding: 10px 0; +} + +.primary-nav .expander .expander-header { + padding-bottom: 10px; +} + +.expander > revealer > box > .koto-button { + min-height: 40px; +} + +.koto-button > image { + margin-right: 10px; +} + +.primary-nav label, +.expander-header label { + font-size: large; +} diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..5623ddf --- /dev/null +++ b/meson.build @@ -0,0 +1,27 @@ +project('koto', 'c', + version: '0.1.0', + meson_version: '>= 0.50.0', + default_options: [ 'warning_level=2', + 'c_std=gnu11', + ], +) + +i18n = import('i18n') + +config_h = configuration_data() +config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) +config_h.set_quoted('GETTEXT_PACKAGE', 'koto') +config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir'))) +configure_file( + output: 'koto-config.h', + configuration: config_h, +) +add_project_arguments([ + '-I' + meson.build_root(), +], language: 'c') + +subdir('data') +subdir('src') +subdir('po') + +meson.add_install_script('build-aux/meson/postinstall.py') diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000..e69de29 diff --git a/po/POTFILES b/po/POTFILES new file mode 100644 index 0000000..2839995 --- /dev/null +++ b/po/POTFILES @@ -0,0 +1,7 @@ +data/com.github.joshstrobl.koto.desktop.in +data/com.github.joshstrobl.koto.appdata.xml.in +data/com.github.joshstrobl.koto.gschema.xml +src/koto-window.ui +src/main.c +src/koto-window.c + diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 0000000..fe55b6a --- /dev/null +++ b/po/meson.build @@ -0,0 +1 @@ +i18n.gettext('koto', preset: 'glib') diff --git a/src/indexer/album.h b/src/indexer/album.h new file mode 100644 index 0000000..f9cc23b --- /dev/null +++ b/src/indexer/album.h @@ -0,0 +1,33 @@ +/* album.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +G_BEGIN_DECLS + +#define KOTO_INDEXED_ALBUM_TYPE koto_indexed_album_get_type() +G_DECLARE_FINAL_TYPE (KotoIndexedAlbum, koto_indexed_album, KOTO, INDEXED_ALBUM, GObject); + +KotoIndexedAlbum* koto_indexed_album_new(const gchar *path); + +void add_song(KotoIndexedAlbum *self, KotoIndexedFile *file); +KotoIndexedFile** get_songs(KotoIndexedAlbum *self); +void remove_song(KotoIndexedAlbum *self, KotoIndexedFile *file); +void remove_song_by_name(KotoIndexedAlbum *self, gchar *file_name); + +G_END_DECLS diff --git a/src/indexer/artist.h b/src/indexer/artist.h new file mode 100644 index 0000000..e87fa2f --- /dev/null +++ b/src/indexer/artist.h @@ -0,0 +1,33 @@ +/* artist.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +G_BEGIN_DECLS + +#define KOTO_INDEXED_ARTIST_TYPE koto_indexed_artist_get_type() +G_DECLARE_FINAL_TYPE (KotoIndexedArtist, koto_indexed_artist, KOTO, INDEXED_ARTIST, GObject); + +KotoIndexedArtist* koto_indexed_artist_new(const gchar *path); + +void add_album(KotoIndexedArtist *self, KotoIndexedAlbum *album); +KotoIndexedAlbum** get_albums(KotoIndexedArtist *self); +void remove_album(KotoIndexedArtist *self, KotoIndexedAlbum *album); +void remove_album_by_name(KotoIndexedArtist *self, gchar *album_name); + +G_END_DECLS diff --git a/src/indexer/file-indexer.c b/src/indexer/file-indexer.c new file mode 100644 index 0000000..a6588ab --- /dev/null +++ b/src/indexer/file-indexer.c @@ -0,0 +1,193 @@ +/* file-indexer.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "file-indexer.h" + +struct KotoIndexedFile { + GObject parent_instance; + gchar *file_name; + gchar *path; +}; + +struct KotoIndexedAlbum { + GObject parent_instance; + gboolean has_album_art; + gchar *album_name; + gchar *art_path; + gchar *path; + GHashTable *songs; +}; + +struct _KotoIndexedArtist { + GObject parent_instance; + gboolean has_artist_art; + gchar *artist_name; + GHashTable *albums; + gchar *path; +} + +struct _KotoIndexedLibrary { + GObject parent_instance; + gchar *path; + magic_t magic_cookie; + GHashTable *music_artists; +}; + +G_DEFINE_TYPE(KotoIndexedLibrary, koto_indexed_library, G_TYPE_OBJECT); + +enum { + PROP_0, + PROP_PATH, + N_PROPERTIES +}; + +static GParamSpec *props[N_PROPERTIES] = { NULL, }; + +static void koto_indexed_library_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec); +static void koto_indexed_library_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); + +static void koto_indexed_library_class_init(KotoIndexedLibraryClass *c) { + GObjectClass *gobject_class; + gobject_class = G_OBJECT_CLASS(c); + gobject_class->set_property = koto_indexed_library_set_property; + gobject_class->get_property = koto_indexed_library_get_property; + + props[PROP_PATH] = g_param_spec_string( + "path", + "Path", + "Path to Music", + NULL, + G_PARAM_CONSTRUCT_ONLY|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + g_object_class_install_properties(gobject_class, N_PROPERTIES, props); +} + +static void koto_indexed_library_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { + KotoIndexedLibrary *self = KOTO_INDEXED_LIBRARY(obj); + + switch (prop_id) { + case PROP_PATH: + g_value_set_string(val, self->path); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +static void koto_indexed_library_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec){ + KotoIndexedLibrary *self = KOTO_INDEXED_LIBRARY(obj); + + switch (prop_id) { + case PROP_PATH: + self->path = g_strdup(g_value_get_string(val)); + g_message("Set to %s", self->path); + start_indexing(self); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +void start_indexing(KotoIndexedLibrary *self) { + struct stat library_stat; + int success = stat(self->path, &library_stat); + + if (success != 0) { // Failed to read the library path + return; + } + + if (!S_ISDIR(library_stat.st_mode)) { // Is not a directory + g_warning("%s is not a directory", self->path); + return; + } + + self->magic_cookie = magic_open(MAGIC_MIME); + + if (self->magic_cookie == NULL) { + return; + } + + if (magic_load(self->magic_cookie, NULL) != 0) { + magic_close(self->magic_cookie); + return; + } + + index_folder(self, self->path); + magic_close(self->magic_cookie); +} + +void index_folder(KotoIndexedLibrary *self, gchar *path) { + DIR *dir = opendir(path); // Attempt to open our directory + + if (dir == NULL) { + return; + } + + struct dirent *entry; + + while ((entry = readdir(dir))) { + if (!g_str_has_prefix(entry->d_name, ".")) { // Not a reference to parent dir, self, or a hidden item + gchar *full_path = g_strdup_printf("%s%s%s", path, G_DIR_SEPARATOR_S, entry->d_name); + + if (entry->d_type == DT_DIR) { // Directory + index_folder(self, full_path); // Index this directory + } else if (entry->d_type == DT_REG) { // Regular file + index_file(self, full_path); // Index the file + } + + g_free(full_path); + } + } + + closedir(dir); // Close the directory +} + +void index_file(KotoIndexedLibrary *self, gchar *path) { + const char *mime_type = magic_file(self->magic_cookie, path); + + if (mime_type == NULL) { // Failed to get the mimetype + return; + } + + gchar** mime_info = g_strsplit(mime_type, ";", 2); // Only care about our first item + + if ( + g_str_has_prefix(mime_info[0], "audio/") || // Is audio + g_str_has_prefix(mime_info[0], "image/") // Is image + ) { + g_message("File Name: %s", path); + } + + g_strfreev(mime_info); // Free our mimeinfo +} + +static void koto_indexed_library_init(KotoIndexedLibrary *self) { + self->files = g_hash_table_new(g_str_hash, g_str_equal); +} + +KotoIndexedLibrary* koto_indexed_library_new(const gchar *path) { + return g_object_new(KOTO_INDEXED_TYPE_LIBRARY, + "path", path, + NULL + ); +} diff --git a/src/indexer/file-indexer.h b/src/indexer/file-indexer.h new file mode 100644 index 0000000..f5f61f2 --- /dev/null +++ b/src/indexer/file-indexer.h @@ -0,0 +1,36 @@ +/* file-indexer.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +G_BEGIN_DECLS + +#define KOTO_INDEXED_TYPE_FILE koto_indexed_file_get_type() +G_DECLARE_FINAL_TYPE(KotoIndexedFile, koto_indexed_file, KOTO, INDEXED_FILE, GObject); + +#define KOTO_INDEXED_TYPE_LIBRARY koto_indexed_library_get_type() +G_DECLARE_FINAL_TYPE(KotoIndexedLibrary, koto_indexed_library, KOTO, INDEXED_LIBRARY, GObject); + +KotoIndexedLibrary* koto_indexed_library_new(const gchar *path); +KotoIndexedFile* koto_indexed_file_new(gchar *path); + +void start_indexing(KotoIndexedLibrary *self); +void index_folder(KotoIndexedLibrary *self, gchar *path); +void index_file(KotoIndexedLibrary *self, gchar *path); + +G_END_DECLS diff --git a/src/indexer/meson.build b/src/indexer/meson.build new file mode 100644 index 0000000..df7c618 --- /dev/null +++ b/src/indexer/meson.build @@ -0,0 +1,8 @@ +indexer_sources = [ + 'file-indexer.c', +] + +indexer_deps = [ + dependency('glib-2.0', version: '>= 2.66'), + dependency('gio-2.0', version: '>= 2.66'), +] diff --git a/src/koto-button.c b/src/koto-button.c new file mode 100644 index 0000000..7857fd6 --- /dev/null +++ b/src/koto-button.c @@ -0,0 +1,340 @@ +/* koto-button.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "koto-button.h" +#include "koto-config.h" + +struct _PixbufSize { + guint size; +}; + +typedef struct _PixbufSize PixbufSize; + +static PixbufSize *pixbuf_sizes = NULL; +static guint pixbuf_sizes_allocated = 0; + +static void init_pixbuf_sizes() { + if (pixbuf_sizes == NULL) { + pixbuf_sizes = g_new(PixbufSize, NUM_BUILTIN_SIZES); + + pixbuf_sizes[KOTO_BUTTON_PIXBUF_SIZE_INVALID].size = 0; + pixbuf_sizes[KOTO_BUTTON_PIXBUF_SIZE_TINY].size = 16; + pixbuf_sizes[KOTO_BUTTON_PIXBUF_SIZE_SMALL].size = 24; + pixbuf_sizes[KOTO_BUTTON_PIXBUF_SIZE_NORMAL].size = 32; + pixbuf_sizes[KOTO_BUTTON_PIXBUF_SIZE_LARGE].size = 64; + pixbuf_sizes[KOTO_BUTTON_PIXBUF_SIZE_MASSIVE].size = 96; + pixbuf_sizes[KOTO_BUTTON_PIXBUF_SIZE_GODLIKE].size = 128; + pixbuf_sizes_allocated = NUM_BUILTIN_SIZES; + } +} + +guint koto_get_pixbuf_size(KotoButtonPixbufSize s) { + init_pixbuf_sizes(); + + return pixbuf_sizes[s].size; +} + +enum { + PROP_0, + PROP_PIX_SIZE, + PROP_TEXT, + PROP_BADGE_TEXT, + PROP_PIX, + PROP_ICON_NAME, + N_PROPERTIES +}; + +static GParamSpec *props[N_PROPERTIES] = { NULL, }; + +struct _KotoButton { + GtkBox parent_instance; + guint pix_size; + + GtkWidget *button_image; + GtkWidget *badge_label; + GtkWidget *button_label; + + gchar *badge_text; + gchar *icon_name; + gchar *text; + + GdkPixbuf *pix; +}; + +struct _KotoButtonClass { + GtkBoxClass parent_class; +}; + +G_DEFINE_TYPE(KotoButton, koto_button, GTK_TYPE_BOX); + +static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec); +static void koto_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); + +static void koto_button_class_init(KotoButtonClass *c) { + GObjectClass *gobject_class; + gobject_class = G_OBJECT_CLASS(c); + gobject_class->set_property = koto_button_set_property; + gobject_class->get_property = koto_button_get_property; + + props[PROP_PIX_SIZE] = g_param_spec_uint( + "pixbuf-size", + "Pixbuf Size", + "Size of the pixbuf", + koto_get_pixbuf_size(KOTO_BUTTON_PIXBUF_SIZE_TINY), + koto_get_pixbuf_size(KOTO_BUTTON_PIXBUF_SIZE_GODLIKE), + koto_get_pixbuf_size(KOTO_BUTTON_PIXBUF_SIZE_SMALL), + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_TEXT] = g_param_spec_string( + "button-text", + "Button Text", + "Text of Button", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_BADGE_TEXT] = g_param_spec_string( + "badge-text", + "Badge Text", + "Text of Badge", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_PIX] = g_param_spec_object( + "pixbuf", + "Pixbuf", + "Pixbuf", + GDK_TYPE_PIXBUF, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_ICON_NAME] = g_param_spec_string( + "icon-name", + "Icon Name", + "Name of Icon", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + g_object_class_install_properties(gobject_class, N_PROPERTIES, props); +} + +static void koto_button_init(KotoButton *self) { + GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(self)); + gtk_style_context_add_class(style, "koto-button"); +} + +static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { + KotoButton *self = KOTO_BUTTON(obj); + + switch (prop_id) { + case PROP_PIX_SIZE: + g_value_set_uint(val, self->pix_size); + break; + case PROP_TEXT: + g_value_set_string(val, self->text); + break; + case PROP_BADGE_TEXT: + g_value_set_string(val, self->badge_text); + break; + case PROP_ICON_NAME: + g_value_set_string(val, self->icon_name); + break; + case PROP_PIX: + g_value_set_object(val, self->pix); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +static void koto_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec) { + KotoButton *self = KOTO_BUTTON(obj); + + switch (prop_id) { + case PROP_PIX_SIZE: + koto_button_set_pixbuf_size(self, g_value_get_uint(val)); + break; + case PROP_TEXT: + koto_button_set_text(self, g_strdup(g_value_get_string(val))); + break; + case PROP_BADGE_TEXT: + koto_button_set_badge_text(self, g_strdup(g_value_get_string(val))); + break; + case PROP_PIX: + koto_button_set_pixbuf(self, (GdkPixbuf*) g_value_get_object(val)); + break; + case PROP_ICON_NAME: + koto_button_set_icon_name(self, g_strdup(g_value_get_string(val))); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +void koto_button_set_badge_text(KotoButton *self, gchar *text) { + if ((text == NULL) || (strcmp(text, "") == 0)) { // If the text is empty + self->badge_text = g_strdup(""); + } else { + g_free(self->badge_text); + self->badge_text = g_strdup(text); + } + + if (GTK_IS_LABEL(self->badge_label)) { // If badge label already exists + gtk_label_set_text(GTK_LABEL(self->badge_label), self->badge_text); + } else { + self->badge_label = gtk_label_new(self->badge_text); // Create our label + gtk_box_pack_end(GTK_BOX(self), self->badge_label, FALSE, FALSE, 0); // Add to the end of the box + } + + if (strcmp(self->badge_text, "") != 0) { // Empty badge + gtk_widget_hide(self->badge_label); // Hide our badge + } else { // Have some text + gtk_widget_show(self->badge_label); // Show our badge + } + + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_BADGE_TEXT]); +} + +void koto_button_set_icon_name(KotoButton *self, gchar *icon_name) { + gchar *copied_icon_name = g_strdup(icon_name); + g_message("icon name set in koto button: %s", icon_name); + g_free(self->icon_name); + self->icon_name = copied_icon_name; + + if ((self->icon_name == NULL) || (strcmp(self->icon_name,"") == 0)) { // Have no icon name now + g_message("Have no icon name now?"); + if (GTK_IS_IMAGE(self->button_image)) { // If we already have a button image + gtk_widget_hide(self->button_image); // Hide + } + + return; + } + + GtkIconTheme *theme = gtk_icon_theme_get_default(); // Get the default icon theme + GdkPixbuf* icon_pix = gtk_icon_theme_load_icon_for_scale(theme, self->icon_name, (gint) self->pix_size, 1, GTK_ICON_LOOKUP_USE_BUILTIN & GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); + g_return_if_fail(GDK_IS_PIXBUF(icon_pix)); // Return if not a pixbuf + koto_button_set_pixbuf(self, icon_pix); + + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_ICON_NAME]); +} + +void koto_button_set_pixbuf(KotoButton *self, GdkPixbuf *pix) { + g_return_if_fail(self->pix_size != 0); // Return if don't have a pixbuf size to indicate what to scale to + + if (!GDK_IS_PIXBUF(pix)) { + return; + } + + self->pix = pix; + + GdkPixbuf *use_pix = pix; // Default to using our provided pixbuf + if (gdk_pixbuf_get_height(pix) > (int) self->pix_size) { // If our height is greater than our desired pixel size + use_pix = gdk_pixbuf_scale_simple(pix, -1, self->pix_size, GDK_INTERP_BILINEAR); // Scale using bilnear + g_return_if_fail(use_pix != NULL); // Return if we could not allocate memory for the scaling + } + + if (GTK_IS_IMAGE(self->button_image)) { // If we already have a button image + gtk_image_set_from_pixbuf(GTK_IMAGE(self->button_image), use_pix); // Update our pixbuf + gtk_widget_show(self->button_image); // Ensure we show the image + } else { // No image set + GtkWidget *new_image = gtk_image_new_from_pixbuf(use_pix); // Create our new image + g_return_if_fail(GTK_IS_IMAGE(new_image)); // Return if we failed to create our image + self->button_image = new_image; + gtk_box_pack_start(GTK_BOX(self), self->button_image, FALSE, FALSE, 0); // Prepend the image + gtk_box_reorder_child(GTK_BOX(self), self->button_image, 0); + } + + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PIX]); +} + +void koto_button_set_pixbuf_size(KotoButton *self, guint size) { + g_return_if_fail(size != self->pix_size); // If the sizes aren't different, return + + self->pix_size = size; + + if (GDK_PIXBUF(self->pix)) { // If we already have a pixbuf set and we're changing the size + koto_button_set_pixbuf(self, self->pix); + } + + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PIX_SIZE]); +} + +void koto_button_set_text(KotoButton *self, gchar *text) { + gchar *copied_text = g_strdup(text); // Copy our text + + if (strcmp(copied_text, "") == 0) { // Clearing our text + g_free(self->text); // Free existing text + } + + self->text = copied_text; + + if (GTK_IS_LABEL(self->button_label)) { // If we have a button label + if (strcmp(self->text, "") != 0) { // Have text set + gtk_label_set_text(GTK_LABEL(self->button_label), self->text); + gtk_widget_show(self->button_label); // Show the label + } else { // Have a label but no longer text + gtk_container_remove(GTK_CONTAINER(self), self->button_label); // Remove the label + g_free(self->button_label); + } + } else { // If we do not have a button label + if (strcmp(self->text, "") != 0) { // If we have text + self->button_label = gtk_label_new(self->text); // Create our label + gtk_label_set_xalign(GTK_LABEL(self->button_label), 0); + gtk_box_pack_start(GTK_BOX(self), self->button_label, FALSE, FALSE, 0); // Add to the beginning of the box + + if (GTK_IS_IMAGE(self->button_image)) { // If we have an image + gtk_box_reorder_child(GTK_BOX(self), self->button_image, 0); // Move to the beginning + } + } + } + + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_TEXT]); +} + +KotoButton* koto_button_new_plain(gchar *label) { + return g_object_new(KOTO_TYPE_BUTTON, + "button-text", label, + "orientation", GTK_ORIENTATION_HORIZONTAL, + NULL + ); +} + +KotoButton* koto_button_new_with_icon(gchar *label, gchar *icon_name, KotoButtonPixbufSize size) { + return g_object_new(KOTO_TYPE_BUTTON, + "button-text", label, + "icon-name", icon_name, + "orientation", GTK_ORIENTATION_HORIZONTAL, + "pixbuf-size", koto_get_pixbuf_size(size), + NULL + ); +} + +KotoButton* koto_button_new_with_pixbuf(gchar *label, GdkPixbuf *pix, KotoButtonPixbufSize size) { + return g_object_new(KOTO_TYPE_BUTTON, + "button-text", label, + "pixbuf", pix, + "orientation", GTK_ORIENTATION_HORIZONTAL, + "pixbuf-size", koto_get_pixbuf_size(size), + NULL + ); +} diff --git a/src/koto-button.h b/src/koto-button.h new file mode 100644 index 0000000..4f99950 --- /dev/null +++ b/src/koto-button.h @@ -0,0 +1,57 @@ +/* koto-button.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#ifndef __GTK_ENUMS_H__ +#define __GTK_ENUMS_H__ +#endif + +#include +#include +#include + +G_BEGIN_DECLS + +typedef enum { + KOTO_BUTTON_PIXBUF_SIZE_INVALID, + KOTO_BUTTON_PIXBUF_SIZE_TINY, + KOTO_BUTTON_PIXBUF_SIZE_SMALL, + KOTO_BUTTON_PIXBUF_SIZE_NORMAL, + KOTO_BUTTON_PIXBUF_SIZE_LARGE, + KOTO_BUTTON_PIXBUF_SIZE_MASSIVE, + KOTO_BUTTON_PIXBUF_SIZE_GODLIKE +} KotoButtonPixbufSize; + +#define NUM_BUILTIN_SIZES 7 + +#define KOTO_TYPE_BUTTON (koto_button_get_type()) + +G_DECLARE_FINAL_TYPE (KotoButton, koto_button, KOTO, BUTTON, GtkBox) + +guint koto_get_pixbuf_size(KotoButtonPixbufSize size); + +KotoButton* koto_button_new_plain(gchar *label); +KotoButton* koto_button_new_with_icon(gchar *label, gchar *icon_name, KotoButtonPixbufSize size); +KotoButton* koto_button_new_with_pixbuf(gchar *label, GdkPixbuf *pix, KotoButtonPixbufSize size); + +void koto_button_set_badge_text(KotoButton *self, gchar *text); +void koto_button_set_icon_name(KotoButton *self, gchar *icon_name); +void koto_button_set_pixbuf(KotoButton *self, GdkPixbuf *pix); +void koto_button_set_pixbuf_size(KotoButton *self, guint size); +void koto_button_set_text(KotoButton *self, gchar *text); + +G_END_DECLS diff --git a/src/koto-expander.c b/src/koto-expander.c new file mode 100644 index 0000000..3ecae3d --- /dev/null +++ b/src/koto-expander.c @@ -0,0 +1,245 @@ +/* koto-expander.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "koto-config.h" +#include "koto-button.h" +#include "koto-flipper-button.h" +#include "koto-expander.h" +#include "koto-utils.h" + +enum { + PROP_0, + PROP_HEADER_ICON_NAME, + PROP_HEADER_LABEL, + PROP_HEADER_SECONDARY_BUTTON, + PROP_CONTENT, + N_PROPERTIES +}; + +static GParamSpec *props[N_PROPERTIES] = { NULL, }; + +struct _KotoExpander { + GtkBox parent_instance; + gboolean constructed; + GtkWidget *header; + KotoButton *header_button; + + gchar *icon_name; + gchar *label; + + GtkWidget *header_secondary_button; + KotoFlipperButton *header_expand_button; + + GtkWidget *revealer; + GtkWidget *content; +}; + +struct _KotoExpanderClass { + GtkBoxClass parent_class; +}; + +G_DEFINE_TYPE(KotoExpander, koto_expander, GTK_TYPE_BOX); + +static void koto_expander_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec); +static void koto_expander_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); + +static void koto_expander_class_init(KotoExpanderClass *c) { + GObjectClass *gobject_class; + gobject_class = G_OBJECT_CLASS(c); + gobject_class->set_property = koto_expander_set_property; + gobject_class->get_property = koto_expander_get_property; + + props[PROP_HEADER_ICON_NAME] = g_param_spec_string( + "icon-name", + "Icon Name", + "Name of the icon to use in the Expander", + "emblem-favorite-symbolic", + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_HEADER_LABEL] = g_param_spec_string( + "label", + "Label", + "Label for the Expander", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_HEADER_SECONDARY_BUTTON] = g_param_spec_object( + "secondary-button", + "Secondary Button", + "Secondary Button to be placed next to Expander button", + GTK_TYPE_WIDGET, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_CONTENT] = g_param_spec_object( + "content", + "Content", + "Content inside the Expander", + GTK_TYPE_WIDGET, + G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + g_object_class_install_properties(gobject_class, N_PROPERTIES, props); +} + +static void koto_expander_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { + KotoExpander *self = KOTO_EXPANDER(obj); + + switch (prop_id) { + case PROP_HEADER_ICON_NAME: + g_value_set_string(val, self->icon_name); + break; + case PROP_HEADER_LABEL: + g_value_set_string(val, self->label); + break; + case PROP_HEADER_SECONDARY_BUTTON: + g_value_set_object(val, (GObject *) self->header_secondary_button); + break; + case PROP_CONTENT: + g_value_set_object(val, (GObject *) self->content); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +static void koto_expander_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec) { + KotoExpander *self = KOTO_EXPANDER(obj); + + if (!GTK_IS_WIDGET(self->header_button)) { // Header Button is not a widget + KotoButton *new_button = koto_button_new_with_icon("Temporary Text", "emblem-favorite-symbolic", KOTO_BUTTON_PIXBUF_SIZE_SMALL); + + if (GTK_IS_WIDGET(new_button)) { // Created our widget successfully + self->header_button = new_button; + gtk_box_pack_start(GTK_BOX(self->header), GTK_WIDGET(self->header_button), TRUE, TRUE, 0); // Add it + } + } + + switch (prop_id) { + case PROP_HEADER_ICON_NAME: + g_return_if_fail(GTK_IS_WIDGET(self->header_button)); + koto_button_set_icon_name(self->header_button, g_strdup(g_value_get_string(val))); + break; + case PROP_HEADER_LABEL: + g_return_if_fail(GTK_IS_WIDGET(self->header_button)); + koto_button_set_text(self->header_button, g_strdup(g_value_get_string(val))); + break; + case PROP_HEADER_SECONDARY_BUTTON: + koto_expander_set_secondary_button(self, (GtkWidget*) g_value_get_object(val)); + break; + case PROP_CONTENT: + koto_expander_set_content(self, (GtkWidget*) g_value_get_object(val)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +static void koto_expander_init(KotoExpander *self) { + GtkSettings *settings = gtk_settings_get_default(); + g_object_set(settings, "gtk_application_prefer_dark_theme", TRUE, NULL); + + GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(self)); + gtk_style_context_add_class(style, "expander"); + + self->header = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); + + GtkStyleContext *header_style = gtk_widget_get_style_context(self->header); + gtk_style_context_add_class(header_style, "expander-header"); + + self->revealer = gtk_revealer_new(); + gtk_revealer_set_reveal_child(GTK_REVEALER(self->revealer), TRUE); // Set to be revealed by default + gtk_revealer_set_transition_type(GTK_REVEALER(self->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); + + self->header_expand_button = koto_flipper_button_new("pan-down-symbolic", "pan-up-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_box_pack_end(GTK_BOX(self->header), GTK_WIDGET(self->header_expand_button), FALSE, FALSE, 0); + + gtk_box_pack_start(GTK_BOX(self), self->header, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(self), self->revealer, TRUE, TRUE, 0); + + self->constructed = TRUE; + + g_signal_connect(self->header_expand_button, "clicked", G_CALLBACK(koto_expander_toggle_content), self); +} + +void koto_expander_set_secondary_button(KotoExpander *self, GtkWidget *new_button) { + if (!self->constructed) { + return; + } + + if (!GTK_IS_BUTTON(new_button)) { + return; + } + + if (GTK_IS_BUTTON(self->header_secondary_button)) { // Already have a button + gtk_container_remove(GTK_CONTAINER(self->header), self->header_secondary_button); + //g_free(self->header_secondary_button); + } + + self->header_secondary_button = new_button; + gtk_box_pack_end(GTK_BOX(self->header), self->header_secondary_button, FALSE, FALSE, 0); + + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_HEADER_SECONDARY_BUTTON]); +} + +void koto_expander_set_content(KotoExpander *self, GtkWidget *new_content) { + if (!self->constructed) { + return; + } + + if (self->content != NULL) { // Already have content + gtk_container_remove(GTK_CONTAINER(self->revealer), self->content); + g_free(self->content); + } + + self->content = new_content; + gtk_container_add(GTK_CONTAINER(self->revealer), self->content); + + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_CONTENT]); +} + +void koto_expander_toggle_content(GtkWidget *button, gpointer data) { + KotoExpander* self = data; + koto_flipper_button_flip(KOTO_FLIPPER_BUTTON(button)); + GtkRevealer* rev = GTK_REVEALER(self->revealer); + gtk_revealer_set_reveal_child(rev, !gtk_revealer_get_reveal_child(rev)); // Invert our values +} + +KotoExpander* koto_expander_new(gchar *primary_icon_name, gchar *primary_label_text) { + return g_object_new(KOTO_TYPE_EXPANDER, + "orientation", GTK_ORIENTATION_VERTICAL, + "icon-name", primary_icon_name, + "label", primary_label_text, + NULL + ); +} + +KotoExpander* koto_expander_new_with_button(gchar *primary_icon_name, gchar *primary_label_text, GtkWidget *secondary_button) { + return g_object_new(KOTO_TYPE_EXPANDER, + "orientation", GTK_ORIENTATION_VERTICAL, + "icon-name", primary_icon_name, + "label", primary_label_text, + "secondary-button", secondary_button, + NULL + ); +} diff --git a/src/koto-expander.h b/src/koto-expander.h new file mode 100644 index 0000000..c047ab7 --- /dev/null +++ b/src/koto-expander.h @@ -0,0 +1,36 @@ +/* koto-expander.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define KOTO_TYPE_EXPANDER (koto_expander_get_type()) + +G_DECLARE_FINAL_TYPE (KotoExpander, koto_expander, KOTO, EXPANDER, GtkBox) + +KotoExpander* koto_expander_new(gchar *primary_icon_name, gchar *primary_label_text); +KotoExpander* koto_expander_new_with_button(gchar *primary_icon_name, gchar *primary_label_text, GtkWidget *secondary_button); +void koto_expander_set_icon_name(KotoExpander *self, const gchar *in); +void koto_expander_set_label(KotoExpander *self, const gchar *label); +void koto_expander_set_secondary_button(KotoExpander *self, GtkWidget *new_button); +void koto_expander_set_content(KotoExpander *self, GtkWidget *new_content); +void koto_expander_toggle_content(GtkWidget *button, gpointer data); + +G_END_DECLS diff --git a/src/koto-flipper-button.c b/src/koto-flipper-button.c new file mode 100644 index 0000000..510bf0d --- /dev/null +++ b/src/koto-flipper-button.c @@ -0,0 +1,129 @@ +/* koto-flipper-button.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "koto-config.h" +#include "koto-flipper-button.h" + +enum { + PROP_0, + PROP_SIZE, + PROP_INITIAL_IMAGE, + PROP_FLIPPED_IMAGE, + N_PROPERTIES +}; + +static GParamSpec *props[N_PROPERTIES] = { NULL, }; + +struct _KotoFlipperButton { + GtkButton parent_instance; + GtkIconSize size; + gboolean flipped; + + gchar *initial_image; + gchar *flipped_image; +}; + +struct _KotoFlipperButtonClass { + GtkButtonClass parent_class; +}; + +G_DEFINE_TYPE(KotoFlipperButton, koto_flipper_button, GTK_TYPE_BUTTON); +static void koto_flipper_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); + +static void koto_flipper_button_class_init(KotoFlipperButtonClass *c) { + GObjectClass *gobject_class; + gobject_class = G_OBJECT_CLASS(c); + gobject_class->set_property = koto_flipper_button_set_property; + + props[PROP_SIZE] = g_param_spec_enum( + "size", + "Icon Size", + "Size of the icon", + GTK_TYPE_ICON_SIZE, + GTK_ICON_SIZE_MENU, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_WRITABLE + ); + + props[PROP_INITIAL_IMAGE] = g_param_spec_string( + "initial-image", + "Initial Image", + "Image to use initially for the button", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_WRITABLE + ); + + props[PROP_FLIPPED_IMAGE] = g_param_spec_string( + "flipped-image", + "Flipped Image", + "Image to use when the button is flipped", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_WRITABLE + ); + + g_object_class_install_properties(gobject_class, N_PROPERTIES, props); +} + +static void koto_flipper_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec) { + KotoFlipperButton *self = KOTO_FLIPPER_BUTTON(obj); + + if (prop_id == PROP_INITIAL_IMAGE) { + g_free(self->initial_image); + self->initial_image = g_strdup(g_value_get_string(val)); + koto_flipper_button_set_icon(self, self->initial_image); + } else if (prop_id == PROP_FLIPPED_IMAGE) { + g_free(self->flipped_image); + self->flipped_image = g_strdup(g_value_get_string(val)); + } else if (prop_id == PROP_SIZE) { + self->size = (GtkIconSize) g_value_get_enum(val); + + if (self->initial_image != NULL && !self->flipped) { + koto_flipper_button_set_icon(self, self->flipped ? self->initial_image : self->flipped_image); + } + } else { + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + return; + } + + g_object_notify_by_pspec(obj, props[prop_id]); +} + +static void koto_flipper_button_init(KotoFlipperButton *self) { + self->flipped = FALSE; + + GtkStyleContext *button_style = gtk_widget_get_style_context(GTK_WIDGET(self)); // Get the styling for the flipper button + gtk_style_context_add_class(button_style, "flat"); // Set it to flat +} + +void koto_flipper_button_flip(KotoFlipperButton *self) { + koto_flipper_button_set_icon(self, self->flipped ? self->initial_image : self->flipped_image); + self->flipped = !self->flipped; +} + +void koto_flipper_button_set_icon(KotoFlipperButton *self, gchar *name) { + GtkWidget *new_image = gtk_image_new_from_icon_name(name, self->size); + gtk_button_set_image(GTK_BUTTON(self), new_image); +} + +KotoFlipperButton* koto_flipper_button_new(gchar *initial_icon, gchar *flipped_icon, GtkIconSize size) { + return g_object_new(KOTO_TYPE_FLIPPER_BUTTON, + "initial-image", initial_icon, + "flipped-image", flipped_icon, + "size", size, + NULL + ); +} diff --git a/src/koto-flipper-button.h b/src/koto-flipper-button.h new file mode 100644 index 0000000..711e607 --- /dev/null +++ b/src/koto-flipper-button.h @@ -0,0 +1,32 @@ +/* koto-flipper-button.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define KOTO_TYPE_FLIPPER_BUTTON (koto_flipper_button_get_type()) + +G_DECLARE_FINAL_TYPE (KotoFlipperButton, koto_flipper_button, KOTO, FLIPPER_BUTTON, GtkButton) + +KotoFlipperButton* koto_flipper_button_new(gchar *initial_icon, gchar *flipped_icon, GtkIconSize size); +void koto_flipper_button_flip(KotoFlipperButton *self); +void koto_flipper_button_set_icon(KotoFlipperButton *self, gchar *name); + +G_END_DECLS diff --git a/src/koto-headerbar.c b/src/koto-headerbar.c new file mode 100644 index 0000000..e408891 --- /dev/null +++ b/src/koto-headerbar.c @@ -0,0 +1,47 @@ +/* koto-headerbar.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "koto-config.h" +#include "koto-headerbar.h" + +struct _KotoHeaderBar { + GtkHeaderBar parent_instance; + GtkButton *menu_button; + GtkWidget *search; +}; + +struct _KotoHeaderBarClass { + GtkHeaderBarClass parent_class; +}; + +G_DEFINE_TYPE(KotoHeaderBar, koto_headerbar, GTK_TYPE_HEADER_BAR) + +static void koto_headerbar_class_init(KotoHeaderBarClass *c) { + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(c); + gtk_widget_class_set_template_from_resource(widget_class, "/com/github/joshstrobl/koto/koto-headerbar.ui"); + //gtk_widget_class_bind_template_child(widget_class, KotoHeaderBar, menu_button); + //gtk_widget_class_bind_template_child(widget_class, KotoHeaderBar, search); +} + +static void koto_headerbar_init(KotoHeaderBar *self) { + gtk_widget_init_template(GTK_WIDGET(self)); + gtk_widget_show_all(GTK_WIDGET(self)); +} + +KotoHeaderBar* koto_headerbar_new(void) { + return g_object_new(KOTO_TYPE_HEADERBAR, NULL); +} diff --git a/src/koto-headerbar.h b/src/koto-headerbar.h new file mode 100644 index 0000000..43c4ffc --- /dev/null +++ b/src/koto-headerbar.h @@ -0,0 +1,30 @@ +/* koto-headerbar.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define KOTO_TYPE_HEADERBAR (koto_headerbar_get_type()) + +G_DECLARE_FINAL_TYPE (KotoHeaderBar, koto_headerbar, KOTO, HEADERBAR, GtkHeaderBar) + +KotoHeaderBar* koto_headerbar_new (void); + +G_END_DECLS diff --git a/src/koto-headerbar.ui b/src/koto-headerbar.ui new file mode 100644 index 0000000..03384fe --- /dev/null +++ b/src/koto-headerbar.ui @@ -0,0 +1,40 @@ + + + + + + False + audio-headphones + 3 + + + diff --git a/src/koto-nav.c b/src/koto-nav.c new file mode 100644 index 0000000..15ec21f --- /dev/null +++ b/src/koto-nav.c @@ -0,0 +1,155 @@ +/* koto-nav.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "koto-config.h" +#include "koto-button.h" +#include "koto-expander.h" +#include "koto-nav.h" +#include "koto-utils.h" + +struct _KotoNav { + GtkScrolledWindow parent_instance; + GtkWidget *content; + + KotoButton *home_button; + KotoExpander *audiobook_expander; + KotoExpander *music_expander; + KotoExpander *podcast_expander; + KotoExpander *playlists_expander; + + // Audiobooks + + KotoButton *audiobooks_local; + KotoButton *audiobooks_audible; + KotoButton *audiobooks_librivox; + + // Music + + KotoButton *music_local; + KotoButton *music_radio; + + // Podcasts + + KotoButton *podcasts_local; + KotoButton *podcasts_discover; +}; + +struct _KotoNavClass { + GtkScrolledWindowClass parent_class; +}; + +G_DEFINE_TYPE(KotoNav, koto_nav, GTK_TYPE_SCROLLED_WINDOW); + +static void koto_nav_class_init(KotoNavClass *c) { + +} + +static void koto_nav_init(KotoNav *self) { + gtk_widget_set_size_request(GTK_WIDGET(self), 300, -1); // Take up 300px width + self->content = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); + + GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(self)); + gtk_style_context_add_class(style, "primary-nav"); + + gtk_container_add(GTK_CONTAINER(self), self->content); + + KotoButton *h_button = koto_button_new_with_icon("Home", "user-home-symbolic", KOTO_BUTTON_PIXBUF_SIZE_SMALL); + + if (h_button != NULL) { + self->home_button = h_button; + gtk_box_pack_start(GTK_BOX(self->content), GTK_WIDGET(self->home_button), FALSE, FALSE, 0); + } + + koto_nav_create_audiobooks_section(self); + koto_nav_create_music_section(self); + koto_nav_create_podcasts_section(self); + + + + GtkWidget *playlist_add_button = koto_create_flat_icon_button("list-add-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); + KotoExpander *pl_expander = koto_expander_new_with_button("playlist-symbolic", "Playlists", playlist_add_button); + + if (pl_expander != NULL) { + self->playlists_expander = pl_expander; + gtk_box_pack_start(GTK_BOX(self->content), GTK_WIDGET(self->playlists_expander), FALSE, FALSE, 0); + } + + gtk_widget_show_all(GTK_WIDGET(self)); +} + +void koto_nav_create_audiobooks_section(KotoNav *self) { + KotoExpander *a_expander = koto_expander_new("ephy-bookmarks-symbolic", "Audiobooks"); + + self->audiobook_expander = a_expander; + gtk_box_pack_start(GTK_BOX(self->content), GTK_WIDGET(self->audiobook_expander), FALSE, FALSE, 0); + + GtkWidget *new_content = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + self->audiobooks_local = koto_button_new_plain("Local Library"); + self->audiobooks_audible = koto_button_new_plain("Audible"); + self->audiobooks_librivox = koto_button_new_plain("LibriVox"); + + gtk_box_pack_start(GTK_BOX(new_content), GTK_WIDGET(self->audiobooks_local), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(new_content), GTK_WIDGET(self->audiobooks_audible), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(new_content), GTK_WIDGET(self->audiobooks_librivox), FALSE, FALSE, 0); + + koto_expander_set_content(a_expander, new_content); +} + +void koto_nav_create_music_section(KotoNav *self) { + KotoExpander *m_expander = koto_expander_new("emblem-music-symbolic", "Music"); + self->music_expander = m_expander; + gtk_box_pack_start(GTK_BOX(self->content), GTK_WIDGET(self->music_expander), FALSE, FALSE, 0); + + GtkWidget *new_content = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + self->music_local = koto_button_new_plain("Local Library"); + self->music_radio = koto_button_new_plain("Radio"); + + gtk_box_pack_start(GTK_BOX(new_content), GTK_WIDGET(self->music_local), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(new_content), GTK_WIDGET(self->music_radio), FALSE, FALSE, 0); + + koto_expander_set_content(m_expander, new_content); +} + +void koto_nav_create_podcasts_section(KotoNav *self) { + KotoExpander *p_expander = koto_expander_new("microphone-sensitivity-high-symbolic", "Podcasts"); + self->podcast_expander = p_expander; + gtk_box_pack_start(GTK_BOX(self->content), GTK_WIDGET(self->podcast_expander), FALSE, FALSE, 0); + + GtkWidget *new_content = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + self->podcasts_local = koto_button_new_plain("Library"); + self->podcasts_discover = koto_button_new_plain("Find New Podcasts"); + + gtk_box_pack_start(GTK_BOX(new_content), GTK_WIDGET(self->podcasts_local), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(new_content), GTK_WIDGET(self->podcasts_discover), FALSE, FALSE, 0); + + koto_expander_set_content(p_expander, new_content); +} + +KotoNav* koto_nav_new(void) { + return g_object_new(KOTO_TYPE_NAV, + "hscrollbar-policy", GTK_POLICY_NEVER, + "min-content-width", 300, + "max-content-width", 300, + "propagate-natural-height", TRUE, + "propagate-natural-width", TRUE, + "shadow-type", GTK_SHADOW_NONE + ,NULL); +} diff --git a/src/koto-nav.h b/src/koto-nav.h new file mode 100644 index 0000000..58c395f --- /dev/null +++ b/src/koto-nav.h @@ -0,0 +1,32 @@ +/* koto-nav.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +G_BEGIN_DECLS + +#define KOTO_TYPE_NAV (koto_nav_get_type()) + +G_DECLARE_FINAL_TYPE (KotoNav, koto_nav, KOTO, NAV, GtkScrolledWindow) + +KotoNav* koto_nav_new (void); +void koto_nav_create_audiobooks_section(KotoNav *self); +void koto_nav_create_music_section(KotoNav *self); +void koto_nav_create_podcasts_section(KotoNav *self); + +G_END_DECLS diff --git a/src/koto-playerbar.c b/src/koto-playerbar.c new file mode 100644 index 0000000..307f0d7 --- /dev/null +++ b/src/koto-playerbar.c @@ -0,0 +1,172 @@ +/* koto-playerbar.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "koto-config.h" +#include "koto-playerbar.h" +#include "koto-utils.h" + +struct _KotoPlayerBar { + GtkBox parent_instance; + + /* Sections */ + GtkWidget *playback_section; + GtkWidget *primary_controls_section; + GtkWidget *secondary_controls_section; + + /* Primary Buttons */ + GtkWidget *back_button; + GtkWidget *play_pause_button; + GtkWidget *forward_button; + GtkWidget *repeat_button; + GtkWidget *shuffle_button; + GtkWidget *playlist_button; + GtkWidget *eq_button; + GtkWidget *volume_button; + + /* Selected Playback Section */ + + GtkWidget *playback_details_section; + GtkWidget *artwork; + GtkWidget *playback_title; + GtkWidget *playback_album; + GtkWidget *playback_artist; +}; + +struct _KotoPlayerBarClass { + GtkBoxClass parent_class; +}; + +G_DEFINE_TYPE(KotoPlayerBar, koto_playerbar, GTK_TYPE_BOX); + +static void koto_playerbar_constructed(GObject *obj); + +static void koto_playerbar_class_init(KotoPlayerBarClass *c) { + GObjectClass *gobject_class; + gobject_class = G_OBJECT_CLASS(c); + + gobject_class->constructed = koto_playerbar_constructed; +} + +static void koto_playerbar_constructed(GObject *obj) { + KotoPlayerBar *self = KOTO_PLAYERBAR(obj); + self->playback_section = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + self->primary_controls_section = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + self->secondary_controls_section = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + + gtk_box_pack_start(GTK_BOX(self), GTK_WIDGET(self->primary_controls_section), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(self), GTK_WIDGET(self->playback_section), TRUE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(self), GTK_WIDGET(self->secondary_controls_section), FALSE, FALSE, 0); + + koto_playerbar_create_playback_details(self); + koto_playerbar_create_primary_controls(self); + koto_playerbar_create_secondary_controls(self); + + gtk_widget_set_margin_top(GTK_WIDGET(self), 10); + gtk_widget_set_margin_bottom(GTK_WIDGET(self), 10); + gtk_widget_set_margin_start(GTK_WIDGET(self), 10); + gtk_widget_set_margin_end(GTK_WIDGET(self), 10); +} + +static void koto_playerbar_init(KotoPlayerBar *self) { + gtk_widget_show_all(GTK_WIDGET(self)); +} + +KotoPlayerBar* koto_playerbar_new(void) { + return g_object_new(KOTO_TYPE_PLAYERBAR, "orientation", GTK_ORIENTATION_HORIZONTAL, NULL); +} + +void koto_playerbar_create_playback_details(KotoPlayerBar* bar) { + bar->playback_details_section = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + GtkIconTheme* default_icon_theme = gtk_icon_theme_get_default(); + + if (default_icon_theme != NULL) { + gint scale_factor = gtk_widget_get_scale_factor(GTK_WIDGET(bar)); + GdkPixbuf* audio_pixbuf = gtk_icon_theme_load_icon_for_scale(default_icon_theme, "audio-x-generic-symbolic", 96, scale_factor, GTK_ICON_LOOKUP_USE_BUILTIN & GTK_ICON_LOOKUP_FORCE_SIZE, NULL); + + if (audio_pixbuf != NULL) { + bar->artwork = gtk_image_new_from_pixbuf(audio_pixbuf); + } + } + + if (bar->artwork == NULL) { + bar->artwork = gtk_image_new_from_icon_name("audio-x-generic-symbolic", GTK_ICON_SIZE_DIALOG); + } + + if (bar->artwork != NULL) { + gtk_widget_set_margin_end(bar->artwork, 10); + gtk_box_pack_start(GTK_BOX(bar->playback_section), bar->artwork, FALSE, FALSE, 0); + } + + bar->playback_title = gtk_label_new(_("Title")); + bar->playback_album = gtk_label_new(_("Album")); + bar->playback_artist = gtk_label_new(_("Artist")); + + gtk_box_pack_start(GTK_BOX(bar->playback_details_section), GTK_WIDGET(bar->playback_title), TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(bar->playback_details_section), GTK_WIDGET(bar->playback_album), TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(bar->playback_details_section), GTK_WIDGET(bar->playback_artist), TRUE, TRUE, 0); + + gtk_box_pack_end(GTK_BOX(bar->playback_section), GTK_WIDGET(bar->playback_details_section), FALSE, FALSE, 0); +} + +void koto_playerbar_create_primary_controls(KotoPlayerBar* bar) { + bar->back_button = koto_create_flat_icon_button("media-skip-backward-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + bar->play_pause_button = koto_create_flat_icon_button("media-playback-start-symbolic", GTK_ICON_SIZE_DND); // TODO: Have this take in a state and switch to a different icon if necessary + bar->forward_button = koto_create_flat_icon_button("media-skip-forward-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + + if (bar->back_button != NULL) { + gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), bar->back_button, FALSE, FALSE, 0); + } + + if (bar->play_pause_button != NULL) { + gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), bar->play_pause_button, FALSE, FALSE, 0); + } + + if (bar->forward_button != NULL) { + gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), bar->forward_button, FALSE, FALSE, 0); + } +} + +void koto_playerbar_create_secondary_controls(KotoPlayerBar* bar) { + bar->repeat_button = koto_create_flat_icon_button("media-playlist-repeat-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + bar->shuffle_button = koto_create_flat_icon_button("media-playlist-shuffle-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + bar->playlist_button = koto_create_flat_icon_button("playlist-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + bar->eq_button = koto_create_flat_icon_button("multimedia-equalizer-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + bar->volume_button = gtk_volume_button_new(); // Have this take in a state and switch to a different icon if necessary + gtk_scale_button_set_value(GTK_SCALE_BUTTON(bar->volume_button), 0.5); + + if (bar->repeat_button != NULL) { + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->repeat_button, FALSE, FALSE, 0); + } + + if (bar->shuffle_button != NULL) { + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->shuffle_button, FALSE, FALSE, 0); + } + + if (bar->playlist_button != NULL) { + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->playlist_button, FALSE, FALSE, 0); + } + + if (bar->eq_button != NULL) { + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->eq_button, FALSE, FALSE, 0); + } + + if (bar->volume_button != NULL) { + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->volume_button, FALSE, FALSE, 0); + } +} diff --git a/src/koto-playerbar.h b/src/koto-playerbar.h new file mode 100644 index 0000000..1b204f2 --- /dev/null +++ b/src/koto-playerbar.h @@ -0,0 +1,32 @@ +/* koto-playerbar.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +G_BEGIN_DECLS + +#define KOTO_TYPE_PLAYERBAR (koto_playerbar_get_type()) + +G_DECLARE_FINAL_TYPE (KotoPlayerBar, koto_playerbar, KOTO, PLAYERBAR, GtkBox) + +KotoPlayerBar* koto_playerbar_new (void); +void koto_playerbar_create_playback_details(KotoPlayerBar* bar); +void koto_playerbar_create_primary_controls(KotoPlayerBar* bar); +void koto_playerbar_create_secondary_controls(KotoPlayerBar* bar); + +G_END_DECLS diff --git a/src/koto-utils.c b/src/koto-utils.c new file mode 100644 index 0000000..985c787 --- /dev/null +++ b/src/koto-utils.c @@ -0,0 +1,28 @@ +/* koto-utils.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "koto-utils.h" + +GtkWidget* koto_create_flat_icon_button(gchar *icon_name, GtkIconSize size) { + GtkWidget* button; + button = gtk_button_new_from_icon_name(icon_name, size); + + GtkStyleContext *button_style = gtk_widget_get_style_context(button); + gtk_style_context_add_class(button_style, "flat"); + + return button; +} diff --git a/src/koto-utils.h b/src/koto-utils.h new file mode 100644 index 0000000..0a13d1c --- /dev/null +++ b/src/koto-utils.h @@ -0,0 +1,24 @@ +/* koto-utils.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +G_BEGIN_DECLS + +GtkWidget* koto_create_flat_icon_button(gchar *icon_name, GtkIconSize size); + +G_END_DECLS diff --git a/src/koto-window.c b/src/koto-window.c new file mode 100644 index 0000000..b86d565 --- /dev/null +++ b/src/koto-window.c @@ -0,0 +1,89 @@ +/* koto-window.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "indexer/file-indexer.h" +#include "koto-config.h" +#include "koto-headerbar.h" +#include "koto-nav.h" +#include "koto-playerbar.h" +#include "koto-window.h" + +struct _KotoWindow { + GtkApplicationWindow parent_instance; + KotoIndexedLibrary *library; + KotoHeaderBar *header_bar; + GtkWidget *primary_layout; + GtkWidget *content_layout; + + KotoNav *nav; + KotoPlayerBar *player_bar; +}; + +G_DEFINE_TYPE (KotoWindow, koto_window, GTK_TYPE_APPLICATION_WINDOW) + +static void koto_window_class_init (KotoWindowClass *klass) { + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/com/github/joshstrobl/koto/koto-window.ui"); +} + +static void koto_window_init (KotoWindow *self) { + gtk_widget_init_template (GTK_WIDGET (self)); + GtkCssProvider* provider = gtk_css_provider_new(); + gtk_css_provider_load_from_resource(provider, "/com/github/joshstrobl/koto/style.css"); + gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + //KotoHeaderBar *header = koto_headerbar_new(); + self->header_bar = koto_headerbar_new(); + + if (self->header_bar != NULL) { + gtk_window_set_titlebar(GTK_WINDOW(self), GTK_WIDGET(self->header_bar)); + } + + self->primary_layout = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + self->content_layout = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + + self->nav = koto_nav_new(); + + if (self->nav != NULL) { + gtk_box_pack_start(GTK_BOX(self->content_layout), GTK_WIDGET(self->nav), FALSE, TRUE, 10); + + GtkWidget *sep = gtk_separator_new(GTK_ORIENTATION_VERTICAL); + gtk_box_pack_end(GTK_BOX(self->content_layout), sep, FALSE, TRUE, 0); + } + + gtk_box_pack_start(GTK_BOX(self->primary_layout), self->content_layout, TRUE, TRUE, 0); + + self->player_bar = koto_playerbar_new(); + + if (self->player_bar != NULL) { + gtk_box_pack_start(GTK_BOX(self->primary_layout), GTK_WIDGET(self->player_bar), FALSE, FALSE, 0); + } + + gtk_container_add(GTK_CONTAINER(self), self->primary_layout); + gtk_widget_show_all(GTK_WIDGET(self)); + + g_thread_new("load-library", load_library, self); +} + +void load_library(KotoWindow *self) { + KotoIndexedLibrary *lib = koto_indexed_library_new(g_get_user_special_dir(G_USER_DIRECTORY_MUSIC)); + + if (lib != NULL) { + self->library = lib; + } +} diff --git a/src/koto-window.h b/src/koto-window.h new file mode 100644 index 0000000..bab11e8 --- /dev/null +++ b/src/koto-window.h @@ -0,0 +1,30 @@ +/* koto-window.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define KOTO_TYPE_WINDOW (koto_window_get_type()) + +G_DECLARE_FINAL_TYPE (KotoWindow, koto_window, KOTO, WINDOW, GtkApplicationWindow) + +G_END_DECLS + +void load_library(KotoWindow *self); diff --git a/src/koto-window.ui b/src/koto-window.ui new file mode 100644 index 0000000..a1da769 --- /dev/null +++ b/src/koto-window.ui @@ -0,0 +1,10 @@ + + + + + + diff --git a/src/koto.gresource.xml b/src/koto.gresource.xml new file mode 100644 index 0000000..5e969dc --- /dev/null +++ b/src/koto.gresource.xml @@ -0,0 +1,8 @@ + + + + koto-headerbar.ui + koto-window.ui + ../data/style.css + + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..4bf6957 --- /dev/null +++ b/src/main.c @@ -0,0 +1,50 @@ +/* main.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "koto-config.h" +#include "koto-window.h" + +static void on_activate (GtkApplication *app) { + g_assert(GTK_IS_APPLICATION (app)); + + GtkWindow *window; + + window = gtk_application_get_active_window (app); + if (window == NULL) { + window = g_object_new(KOTO_TYPE_WINDOW, "application", app, "default-width", 600, "default-height", 300, NULL); + } + + gtk_window_present(window); +} + +int main (int argc, char *argv[]) { + g_autoptr(GtkApplication) app = NULL; + int ret; + + /* Set up gettext translations */ + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + app = gtk_application_new ("com.github.joshstrobl.koto", G_APPLICATION_FLAGS_NONE); + g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL); + ret = g_application_run (G_APPLICATION (app), argc, argv); + + return ret; +} diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..ff11a8d --- /dev/null +++ b/src/meson.build @@ -0,0 +1,31 @@ +koto_sources = [ + 'indexer/file-indexer.c', + 'main.c', + 'koto-button.c', + 'koto-expander.c', + 'koto-flipper-button.c', + 'koto-headerbar.c', + 'koto-nav.c', + 'koto-playerbar.c', + 'koto-utils.c', + 'koto-window.c', +] + +koto_deps = [ + dependency('glib-2.0', version: '>= 2.66'), + dependency('gio-2.0', version: '>= 2.66'), + dependency('gtk+-3.0', version: '>= 3.24'), + dependency('libmagic', version: '>=5.39'), +] + +gnome = import('gnome') + +koto_sources += gnome.compile_resources('koto-resources', + 'koto.gresource.xml', + c_name: 'koto' +) + +executable('com.github.joshstrobl.koto', koto_sources, + dependencies: koto_deps, + install: true, +) From 625c1be645af745ca0602d3aa9463de22a3e28e2 Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Wed, 10 Feb 2021 19:13:43 +0200 Subject: [PATCH 06/83] Update funding to include liberapay. Remove some commented out code. --- .github/FUNDING.yml | 2 +- src/koto-headerbar.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index ac2385e..09d0c70 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -6,7 +6,7 @@ open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username +liberapay: joshuastrobl issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/src/koto-headerbar.c b/src/koto-headerbar.c index e408891..64dab78 100644 --- a/src/koto-headerbar.c +++ b/src/koto-headerbar.c @@ -33,8 +33,6 @@ G_DEFINE_TYPE(KotoHeaderBar, koto_headerbar, GTK_TYPE_HEADER_BAR) static void koto_headerbar_class_init(KotoHeaderBarClass *c) { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(c); gtk_widget_class_set_template_from_resource(widget_class, "/com/github/joshstrobl/koto/koto-headerbar.ui"); - //gtk_widget_class_bind_template_child(widget_class, KotoHeaderBar, menu_button); - //gtk_widget_class_bind_template_child(widget_class, KotoHeaderBar, search); } static void koto_headerbar_init(KotoHeaderBar *self) { From 9b6fa4593a4d2c26358ea2cd5713319ea541fd6f Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Fri, 12 Feb 2021 12:56:41 +0200 Subject: [PATCH 07/83] Deprecate KotoFlipperButton, integrate flip functionality with an alt image into KotoButton. We are now leveraging KotoButton in the KotoPlayerBar and KotoExpander. Dropped Glade UI templating from KotoWindow, set its default size using gtk_widget_set_size_request to force a minimum window size, set window title, WMClass, and icon name. Start implementing KotoIndexedFile class to handle our provided audio files, setting its file name and attempting to parse the file name when we are not using ID3 data. The parsing is as follows: - All `_` are replaced with whitespace - We will attempt to remove nested references to the artist and album name (we need to implemented the relevant classes to leverage that). - Remove any references to ` - ` followed by any stragglers `-` (without the whitespace around it). - Split based on `.` and remove the trailing file extension, preserving the rest (so something like `Ch. 01.ogg` would be considered just `Ch. 01`). --- data/style.css | 7 +- src/indexer/file-indexer.c | 38 ++- src/indexer/file-indexer.h | 6 +- src/indexer/file.c | 274 ++++++++++++++++++ src/{koto-flipper-button.h => indexer/file.h} | 16 +- src/indexer/meson.build | 1 + src/koto-button.c | 129 ++++++--- src/koto-button.h | 11 +- src/koto-expander.c | 55 ++-- src/koto-expander.h | 7 +- src/koto-flipper-button.c | 129 --------- src/koto-nav.c | 6 +- src/koto-playerbar.c | 51 ++-- src/koto-utils.c | 28 -- src/koto-utils.h | 24 -- src/koto-window.c | 9 +- src/koto-window.ui | 10 - src/koto.gresource.xml | 1 - src/meson.build | 3 +- 19 files changed, 472 insertions(+), 333 deletions(-) create mode 100644 src/indexer/file.c rename src/{koto-flipper-button.h => indexer/file.h} (57%) delete mode 100644 src/koto-flipper-button.c delete mode 100644 src/koto-utils.c delete mode 100644 src/koto-utils.h delete mode 100644 src/koto-window.ui diff --git a/data/style.css b/data/style.css index 5329f46..1e3d5d1 100644 --- a/data/style.css +++ b/data/style.css @@ -1,4 +1,4 @@ -.primary-nav > .frame > box >.koto-button { +.primary-nav > .frame > box >.koto-button > box { padding: 10px 0; } @@ -6,11 +6,12 @@ padding-bottom: 10px; } -.expander > revealer > box > .koto-button { +.expander > revealer > box > .koto-button, +.expander > revealer > box > .koto-button > box { min-height: 40px; } -.koto-button > image { +.koto-button > box > image { margin-right: 10px; } diff --git a/src/indexer/file-indexer.c b/src/indexer/file-indexer.c index a6588ab..5a9b55b 100644 --- a/src/indexer/file-indexer.c +++ b/src/indexer/file-indexer.c @@ -18,14 +18,9 @@ #include #include #include +#include "file.h" #include "file-indexer.h" -struct KotoIndexedFile { - GObject parent_instance; - gchar *file_name; - gchar *path; -}; - struct KotoIndexedAlbum { GObject parent_instance; gboolean has_album_art; @@ -41,7 +36,7 @@ struct _KotoIndexedArtist { gchar *artist_name; GHashTable *albums; gchar *path; -} +}; struct _KotoIndexedLibrary { GObject parent_instance; @@ -74,12 +69,16 @@ static void koto_indexed_library_class_init(KotoIndexedLibraryClass *c) { "Path", "Path to Music", NULL, - G_PARAM_CONSTRUCT_ONLY|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); g_object_class_install_properties(gobject_class, N_PROPERTIES, props); } +static void koto_indexed_library_init(KotoIndexedLibrary *self) { + self->music_artists = g_hash_table_new(g_str_hash, g_str_equal); +} + static void koto_indexed_library_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { KotoIndexedLibrary *self = KOTO_INDEXED_LIBRARY(obj); @@ -175,18 +174,29 @@ void index_file(KotoIndexedLibrary *self, gchar *path) { g_str_has_prefix(mime_info[0], "audio/") || // Is audio g_str_has_prefix(mime_info[0], "image/") // Is image ) { - g_message("File Name: %s", path); + //g_message("File Name: %s", path); + } + + if (g_str_has_prefix(mime_info[0], "audio/")) { // Is an audio file + KotoIndexedFile *file = koto_indexed_file_new(path); + gchar *filepath; + gchar *parsed_name; + + g_object_get(file, + "path", &filepath, + "parsed-name", &parsed_name, + NULL); + + g_free(filepath); + g_free(parsed_name); + g_object_unref(file); } g_strfreev(mime_info); // Free our mimeinfo } -static void koto_indexed_library_init(KotoIndexedLibrary *self) { - self->files = g_hash_table_new(g_str_hash, g_str_equal); -} - KotoIndexedLibrary* koto_indexed_library_new(const gchar *path) { - return g_object_new(KOTO_INDEXED_TYPE_LIBRARY, + return g_object_new(KOTO_TYPE_INDEXED_LIBRARY, "path", path, NULL ); diff --git a/src/indexer/file-indexer.h b/src/indexer/file-indexer.h index f5f61f2..f5a5155 100644 --- a/src/indexer/file-indexer.h +++ b/src/indexer/file-indexer.h @@ -20,14 +20,10 @@ G_BEGIN_DECLS -#define KOTO_INDEXED_TYPE_FILE koto_indexed_file_get_type() -G_DECLARE_FINAL_TYPE(KotoIndexedFile, koto_indexed_file, KOTO, INDEXED_FILE, GObject); - -#define KOTO_INDEXED_TYPE_LIBRARY koto_indexed_library_get_type() +#define KOTO_TYPE_INDEXED_LIBRARY koto_indexed_library_get_type() G_DECLARE_FINAL_TYPE(KotoIndexedLibrary, koto_indexed_library, KOTO, INDEXED_LIBRARY, GObject); KotoIndexedLibrary* koto_indexed_library_new(const gchar *path); -KotoIndexedFile* koto_indexed_file_new(gchar *path); void start_indexing(KotoIndexedLibrary *self); void index_folder(KotoIndexedLibrary *self, gchar *path); diff --git a/src/indexer/file.c b/src/indexer/file.c new file mode 100644 index 0000000..c9052b5 --- /dev/null +++ b/src/indexer/file.c @@ -0,0 +1,274 @@ +/* file.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "file.h" + +struct _KotoIndexedFile { + GObject parent_instance; + gchar *path; + gchar *file_name; + gchar *parsed_name; + gchar *artist; + gchar *album; + + guint position; + gboolean acquired_metadata_from_id3; +}; + +G_DEFINE_TYPE(KotoIndexedFile, koto_indexed_file, G_TYPE_OBJECT); + +enum { + PROP_0, + PROP_PATH, + PROP_ARTIST, + PROP_ALBUM, + PROP_FILE_NAME, + PROP_PARSED_NAME, + PROP_POSITION, + N_PROPERTIES +}; + +static GParamSpec *props[N_PROPERTIES] = { NULL }; + +static void koto_indexed_file_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec); +static void koto_indexed_file_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); + +static void koto_indexed_file_class_init(KotoIndexedFileClass *c) { + GObjectClass *gobject_class; + gobject_class = G_OBJECT_CLASS(c); + gobject_class->set_property = koto_indexed_file_set_property; + gobject_class->get_property = koto_indexed_file_get_property; + + props[PROP_PATH] = g_param_spec_string( + "path", + "Path", + "Path to File", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_ARTIST] = g_param_spec_string( + "artist", + "Name of Artist", + "Name of Artist", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_ALBUM] = g_param_spec_string( + "album", + "Name of Album", + "Name of Album", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_FILE_NAME] = g_param_spec_string( + "file-name", + "Name of File", + "Name of File", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_PARSED_NAME] = g_param_spec_string( + "parsed-name", + "Parsed Name of File", + "Parsed Name of File", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_POSITION] = g_param_spec_uint( + "position", + "Position in Audiobook, Album, etc.", + "Position in Audiobook, Album, etc.", + 0, + G_MAXUINT16, + 0, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + g_object_class_install_properties(gobject_class, N_PROPERTIES, props); +} + +static void koto_indexed_file_init(KotoIndexedFile *self) { + self->acquired_metadata_from_id3 = FALSE; +} + +static void koto_indexed_file_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { + KotoIndexedFile *self = KOTO_INDEXED_FILE(obj); + + switch (prop_id) { + case PROP_PATH: + g_value_set_string(val, self->path); + break; + case PROP_ARTIST: + g_value_set_string(val, self->artist); + break; + case PROP_ALBUM: + g_value_set_string(val, self->album); + break; + case PROP_FILE_NAME: + g_value_set_string(val, self->file_name); + break; + case PROP_PARSED_NAME: + g_value_set_string(val, self->parsed_name); + break; + case PROP_POSITION: + g_value_set_uint(val, self->position); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +static void koto_indexed_file_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec) { + KotoIndexedFile *self = KOTO_INDEXED_FILE(obj); + + switch (prop_id) { + case PROP_PATH: + self->path = g_strdup(g_value_get_string(val)); // Update our path + koto_indexed_file_set_file_name(self, g_path_get_basename(self->path)); // Update our file name + break; + case PROP_ARTIST: + self->artist = g_strdup(g_value_get_string(val)); + break; + case PROP_ALBUM: + self->album = g_strdup(g_value_get_string(val)); + break; + case PROP_FILE_NAME: + koto_indexed_file_set_file_name(self, g_strdup(g_value_get_string(val))); // Update the file name + break; + case PROP_PARSED_NAME: + koto_indexed_file_set_parsed_name(self, g_strdup(g_value_get_string(val))); + break; + case PROP_POSITION: + self->position = g_value_get_uint(val); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +void koto_indexed_file_set_file_name(KotoIndexedFile *self, gchar *new_file_name) { + if (new_file_name == NULL) { + return; + } + + if ((self->file_name != NULL) && (strcmp(self->file_name, new_file_name) == 0)) { // Not null and the same + return; // Don't do anything + } + + if (self->file_name != NULL) { // If it is defined + g_free(self->file_name); + } + + self->file_name = g_strdup(new_file_name); + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_FILE_NAME]); + + if (!self->acquired_metadata_from_id3) { // Haven't acquired our information from ID3 + koto_indexed_file_parse_name(self); // Update our parsed name + } +} + +void koto_indexed_file_set_parsed_name(KotoIndexedFile *self, gchar *new_parsed_name) { + if (new_parsed_name == NULL) { + return; + } + + if ((self->parsed_name != NULL) && (strcmp(self->parsed_name, new_parsed_name) == 0)) { // Not null and the same + return; // Don't do anything + } + + if (self->parsed_name != NULL) { + g_free(self->parsed_name); + } + + self->parsed_name = g_strdup(new_parsed_name); + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PARSED_NAME]); +} + +void koto_indexed_file_parse_name(KotoIndexedFile *self) { + gchar *copied_file_name = g_strdelimit(g_strdup(self->file_name), "_", ' '); // Replace _ with whitespace for starters + + if (self->artist != NULL && strcmp(self->artist, "") != 0) { // If we have artist set + gchar **split = g_strsplit(copied_file_name, self->artist, -1); // Split whenever we encounter the artist + copied_file_name = g_strjoinv("", split); // Remove the artist + g_strfreev(split); + } + + if (self->artist != NULL && strcmp(self->album, "") != 0) { // If we have album set + gchar **split = g_strsplit(copied_file_name, self->album, -1); // Split whenever we encounter the album + copied_file_name = g_strjoinv("", split); // Remove the album + g_strfreev(split); + + split = g_strsplit(copied_file_name, g_utf8_strdown(self->album, g_utf8_strlen(self->album, -1)), -1); // Split whenever we encounter the album lowercased + copied_file_name = g_strjoin("", split, NULL); // Remove the lowercased album + g_strfreev(split); + } + + if (g_str_match_string(copied_file_name, "-", FALSE)) { // Contains - like a heathen + gchar **split = g_strsplit(copied_file_name, " - ", -1); // Split whenever we encounter " - " + copied_file_name = g_strjoin("", split, NULL); // Remove entirely + g_strfreev(split); + + if (g_str_match_string(copied_file_name, "-", FALSE)) { // If we have any stragglers + split = g_strsplit(copied_file_name, "-", -1); // Split whenever we encounter - + copied_file_name = g_strjoin("", split, NULL); // Remove entirely + g_strfreev(split); + } + } + + gchar **split = g_strsplit(copied_file_name, ".", -1); // Split every time we see . + g_free(copied_file_name); + guint len_of_extension_split = g_strv_length(split); + + if (len_of_extension_split == 2) { // Only have two elements + copied_file_name = g_strdup(split[0]); // Get the first element + } else { + gchar *new_parsed_name = ""; + for (guint i = 0; i < len_of_extension_split - 1; i++) { // Iterate over everything except the last item + if (g_strcmp0(new_parsed_name, "") == 0) { // Currently empty + new_parsed_name = g_strdup(split[i]); // Just duplicate this string + } else { + gchar *tmp_copy = g_strdup(new_parsed_name); + g_free(new_parsed_name); // Free the old + new_parsed_name = g_strdup(g_strjoin(".", tmp_copy, split[i], NULL)); // Join the two strings with a . again and duplicate it, setting it to our new_parsed_name + g_free(tmp_copy); // Free our temporary copy + } + } + + copied_file_name = g_strdup(new_parsed_name); + g_free(new_parsed_name); + } + + g_strfreev(split); + + koto_indexed_file_set_parsed_name(self, copied_file_name); + g_free(copied_file_name); +} + +KotoIndexedFile* koto_indexed_file_new(const gchar *path) { + return g_object_new(KOTO_TYPE_INDEXED_FILE, + "path", path, + NULL + ); +} diff --git a/src/koto-flipper-button.h b/src/indexer/file.h similarity index 57% rename from src/koto-flipper-button.h rename to src/indexer/file.h index 711e607..669d9f4 100644 --- a/src/koto-flipper-button.h +++ b/src/indexer/file.h @@ -1,4 +1,4 @@ -/* koto-flipper-button.h +/* file.h * * Copyright 2021 Joshua Strobl * @@ -16,17 +16,17 @@ */ #pragma once - -#include +#include G_BEGIN_DECLS -#define KOTO_TYPE_FLIPPER_BUTTON (koto_flipper_button_get_type()) +#define KOTO_TYPE_INDEXED_FILE koto_indexed_file_get_type() +G_DECLARE_FINAL_TYPE(KotoIndexedFile, koto_indexed_file, KOTO, INDEXED_FILE, GObject); -G_DECLARE_FINAL_TYPE (KotoFlipperButton, koto_flipper_button, KOTO, FLIPPER_BUTTON, GtkButton) +KotoIndexedFile* koto_indexed_file_new(const gchar *path); -KotoFlipperButton* koto_flipper_button_new(gchar *initial_icon, gchar *flipped_icon, GtkIconSize size); -void koto_flipper_button_flip(KotoFlipperButton *self); -void koto_flipper_button_set_icon(KotoFlipperButton *self, gchar *name); +void koto_indexed_file_set_file_name(KotoIndexedFile *self, gchar *new_file_name); +void koto_indexed_file_set_parsed_name(KotoIndexedFile *self, gchar *new_parsed_name); +void koto_indexed_file_parse_name(KotoIndexedFile *self); G_END_DECLS diff --git a/src/indexer/meson.build b/src/indexer/meson.build index df7c618..e923e85 100644 --- a/src/indexer/meson.build +++ b/src/indexer/meson.build @@ -1,4 +1,5 @@ indexer_sources = [ + 'file.c', 'file-indexer.c', ] diff --git a/src/koto-button.c b/src/koto-button.c index 7857fd6..7067b9a 100644 --- a/src/koto-button.c +++ b/src/koto-button.c @@ -50,19 +50,21 @@ guint koto_get_pixbuf_size(KotoButtonPixbufSize s) { } enum { - PROP_0, + PROP_BTN_0, PROP_PIX_SIZE, PROP_TEXT, PROP_BADGE_TEXT, PROP_PIX, PROP_ICON_NAME, - N_PROPERTIES + PROP_ALT_ICON_NAME, + N_BTN_PROPERTIES }; -static GParamSpec *props[N_PROPERTIES] = { NULL, }; +static GParamSpec *btn_props[N_BTN_PROPERTIES] = { NULL, }; struct _KotoButton { - GtkBox parent_instance; + GtkEventBox parent_instance; + GtkBox *content; guint pix_size; GtkWidget *button_image; @@ -71,16 +73,18 @@ struct _KotoButton { gchar *badge_text; gchar *icon_name; + gchar *alt_icon_name; gchar *text; GdkPixbuf *pix; + gboolean currently_showing_alt; }; struct _KotoButtonClass { GtkBoxClass parent_class; }; -G_DEFINE_TYPE(KotoButton, koto_button, GTK_TYPE_BOX); +G_DEFINE_TYPE(KotoButton, koto_button, GTK_TYPE_EVENT_BOX); static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec); static void koto_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); @@ -91,7 +95,7 @@ static void koto_button_class_init(KotoButtonClass *c) { gobject_class->set_property = koto_button_set_property; gobject_class->get_property = koto_button_get_property; - props[PROP_PIX_SIZE] = g_param_spec_uint( + btn_props[PROP_PIX_SIZE] = g_param_spec_uint( "pixbuf-size", "Pixbuf Size", "Size of the pixbuf", @@ -101,7 +105,7 @@ static void koto_button_class_init(KotoButtonClass *c) { G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - props[PROP_TEXT] = g_param_spec_string( + btn_props[PROP_TEXT] = g_param_spec_string( "button-text", "Button Text", "Text of Button", @@ -109,7 +113,7 @@ static void koto_button_class_init(KotoButtonClass *c) { G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - props[PROP_BADGE_TEXT] = g_param_spec_string( + btn_props[PROP_BADGE_TEXT] = g_param_spec_string( "badge-text", "Badge Text", "Text of Badge", @@ -117,7 +121,7 @@ static void koto_button_class_init(KotoButtonClass *c) { G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - props[PROP_PIX] = g_param_spec_object( + btn_props[PROP_PIX] = g_param_spec_object( "pixbuf", "Pixbuf", "Pixbuf", @@ -125,7 +129,7 @@ static void koto_button_class_init(KotoButtonClass *c) { G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - props[PROP_ICON_NAME] = g_param_spec_string( + btn_props[PROP_ICON_NAME] = g_param_spec_string( "icon-name", "Icon Name", "Name of Icon", @@ -133,12 +137,23 @@ static void koto_button_class_init(KotoButtonClass *c) { G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - g_object_class_install_properties(gobject_class, N_PROPERTIES, props); + btn_props[PROP_ALT_ICON_NAME] = g_param_spec_string( + "alt-icon-name", + "Name of an Alternate Icon", + "Name of an Alternate Icon", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + g_object_class_install_properties(gobject_class, N_BTN_PROPERTIES, btn_props); } static void koto_button_init(KotoButton *self) { GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(self)); gtk_style_context_add_class(style, "koto-button"); + self->currently_showing_alt = FALSE; + self->content = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)); + gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(self->content)); } static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { @@ -157,6 +172,9 @@ static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, G case PROP_ICON_NAME: g_value_set_string(val, self->icon_name); break; + case PROP_ALT_ICON_NAME: + g_value_set_string(val, self->alt_icon_name); + break; case PROP_PIX: g_value_set_object(val, self->pix); break; @@ -183,7 +201,16 @@ static void koto_button_set_property(GObject *obj, guint prop_id, const GValue * koto_button_set_pixbuf(self, (GdkPixbuf*) g_value_get_object(val)); break; case PROP_ICON_NAME: - koto_button_set_icon_name(self, g_strdup(g_value_get_string(val))); + koto_button_set_icon_name(self, g_strdup(g_value_get_string(val)), FALSE); + if (!self->currently_showing_alt) { // Not showing alt + koto_button_show_image(self, FALSE); + } + break; + case PROP_ALT_ICON_NAME: + koto_button_set_icon_name(self, g_strdup(g_value_get_string(val)), TRUE); + if (self->currently_showing_alt) { // Currently showing the alt image + koto_button_show_image(self, TRUE); + } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); @@ -191,6 +218,10 @@ static void koto_button_set_property(GObject *obj, guint prop_id, const GValue * } } +void koto_button_flip(KotoButton *self) { + koto_button_show_image(self, !self->currently_showing_alt); +} + void koto_button_set_badge_text(KotoButton *self, gchar *text) { if ((text == NULL) || (strcmp(text, "") == 0)) { // If the text is empty self->badge_text = g_strdup(""); @@ -203,7 +234,7 @@ void koto_button_set_badge_text(KotoButton *self, gchar *text) { gtk_label_set_text(GTK_LABEL(self->badge_label), self->badge_text); } else { self->badge_label = gtk_label_new(self->badge_text); // Create our label - gtk_box_pack_end(GTK_BOX(self), self->badge_label, FALSE, FALSE, 0); // Add to the end of the box + gtk_box_pack_end(self->content, self->badge_label, FALSE, FALSE, 0); // Add to the end of the box } if (strcmp(self->badge_text, "") != 0) { // Empty badge @@ -212,17 +243,34 @@ void koto_button_set_badge_text(KotoButton *self, gchar *text) { gtk_widget_show(self->badge_label); // Show our badge } - g_object_notify_by_pspec(G_OBJECT(self), props[PROP_BADGE_TEXT]); + g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_BADGE_TEXT]); } -void koto_button_set_icon_name(KotoButton *self, gchar *icon_name) { +void koto_button_set_icon_name(KotoButton *self, gchar *icon_name, gboolean for_alt) { gchar *copied_icon_name = g_strdup(icon_name); - g_message("icon name set in koto button: %s", icon_name); - g_free(self->icon_name); - self->icon_name = copied_icon_name; - if ((self->icon_name == NULL) || (strcmp(self->icon_name,"") == 0)) { // Have no icon name now - g_message("Have no icon name now?"); + if (for_alt) { // Is for the alternate icon + if ((self->alt_icon_name != NULL) && strcmp(icon_name, self->alt_icon_name) != 0) { // If the icons are different + g_free(self->alt_icon_name); + } + + self->alt_icon_name = copied_icon_name; + } else { + if ((self->icon_name != NULL) && strcmp(icon_name, self->icon_name) != 0) { + g_free(self->icon_name); + } + + self->icon_name = copied_icon_name; + } + + gboolean hide_image = FALSE; + if (for_alt && self->currently_showing_alt && ((self->alt_icon_name == NULL) || strcmp(self->alt_icon_name, "") == 0)) { // For alt, alt is currently showing, and no longer have alt + hide_image = TRUE; + } else if (!for_alt && ((self->icon_name == NULL) || (strcmp(self->icon_name,"") == 0))) { // Not for alt, no icon + hide_image = TRUE; + } + + if (hide_image) { // Should hide the image if (GTK_IS_IMAGE(self->button_image)) { // If we already have a button image gtk_widget_hide(self->button_image); // Hide } @@ -230,12 +278,7 @@ void koto_button_set_icon_name(KotoButton *self, gchar *icon_name) { return; } - GtkIconTheme *theme = gtk_icon_theme_get_default(); // Get the default icon theme - GdkPixbuf* icon_pix = gtk_icon_theme_load_icon_for_scale(theme, self->icon_name, (gint) self->pix_size, 1, GTK_ICON_LOOKUP_USE_BUILTIN & GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); - g_return_if_fail(GDK_IS_PIXBUF(icon_pix)); // Return if not a pixbuf - koto_button_set_pixbuf(self, icon_pix); - - g_object_notify_by_pspec(G_OBJECT(self), props[PROP_ICON_NAME]); + g_object_notify_by_pspec(G_OBJECT(self), for_alt ? btn_props[PROP_ALT_ICON_NAME] : btn_props[PROP_ICON_NAME]); } void koto_button_set_pixbuf(KotoButton *self, GdkPixbuf *pix) { @@ -260,11 +303,11 @@ void koto_button_set_pixbuf(KotoButton *self, GdkPixbuf *pix) { GtkWidget *new_image = gtk_image_new_from_pixbuf(use_pix); // Create our new image g_return_if_fail(GTK_IS_IMAGE(new_image)); // Return if we failed to create our image self->button_image = new_image; - gtk_box_pack_start(GTK_BOX(self), self->button_image, FALSE, FALSE, 0); // Prepend the image - gtk_box_reorder_child(GTK_BOX(self), self->button_image, 0); + gtk_box_pack_start(self->content, self->button_image, FALSE, FALSE, 0); // Prepend the image + gtk_box_reorder_child(self->content, self->button_image, 0); } - g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PIX]); + g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_PIX]); } void koto_button_set_pixbuf_size(KotoButton *self, guint size) { @@ -276,7 +319,7 @@ void koto_button_set_pixbuf_size(KotoButton *self, guint size) { koto_button_set_pixbuf(self, self->pix); } - g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PIX_SIZE]); + g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_PIX_SIZE]); } void koto_button_set_text(KotoButton *self, gchar *text) { @@ -300,30 +343,43 @@ void koto_button_set_text(KotoButton *self, gchar *text) { if (strcmp(self->text, "") != 0) { // If we have text self->button_label = gtk_label_new(self->text); // Create our label gtk_label_set_xalign(GTK_LABEL(self->button_label), 0); - gtk_box_pack_start(GTK_BOX(self), self->button_label, FALSE, FALSE, 0); // Add to the beginning of the box + gtk_box_pack_start(self->content, self->button_label, FALSE, FALSE, 0); // Add to the beginning of the box if (GTK_IS_IMAGE(self->button_image)) { // If we have an image - gtk_box_reorder_child(GTK_BOX(self), self->button_image, 0); // Move to the beginning + gtk_box_reorder_child(self->content, self->button_image, 0); // Move to the beginning } } } - g_object_notify_by_pspec(G_OBJECT(self), props[PROP_TEXT]); + g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_TEXT]); +} + +void koto_button_show_image(KotoButton *self, gboolean use_alt) { + if (use_alt && ((self->alt_icon_name == NULL) || (strcmp(self->alt_icon_name, "") == 0))) { // Don't have an alt icon set + return; + } else if (!use_alt && ((self->icon_name == NULL) || (strcmp(self->icon_name, "") == 0))) { // Don't have icon set + return; + } + + GtkIconTheme *theme = gtk_icon_theme_get_default(); // Get the default icon theme + GdkPixbuf* icon_pix = gtk_icon_theme_load_icon_for_scale(theme, use_alt ? self->alt_icon_name : self->icon_name, (gint) self->pix_size, 1, GTK_ICON_LOOKUP_USE_BUILTIN & GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); + g_return_if_fail(GDK_IS_PIXBUF(icon_pix)); // Return if not a pixbuf + koto_button_set_pixbuf(self, icon_pix); + self->currently_showing_alt = use_alt; } KotoButton* koto_button_new_plain(gchar *label) { return g_object_new(KOTO_TYPE_BUTTON, "button-text", label, - "orientation", GTK_ORIENTATION_HORIZONTAL, NULL ); } -KotoButton* koto_button_new_with_icon(gchar *label, gchar *icon_name, KotoButtonPixbufSize size) { +KotoButton* koto_button_new_with_icon(gchar *label, gchar *icon_name, gchar *alt_icon_name, KotoButtonPixbufSize size) { return g_object_new(KOTO_TYPE_BUTTON, "button-text", label, "icon-name", icon_name, - "orientation", GTK_ORIENTATION_HORIZONTAL, + "alt-icon-name", alt_icon_name, "pixbuf-size", koto_get_pixbuf_size(size), NULL ); @@ -333,7 +389,6 @@ KotoButton* koto_button_new_with_pixbuf(gchar *label, GdkPixbuf *pix, KotoButton return g_object_new(KOTO_TYPE_BUTTON, "button-text", label, "pixbuf", pix, - "orientation", GTK_ORIENTATION_HORIZONTAL, "pixbuf-size", koto_get_pixbuf_size(size), NULL ); diff --git a/src/koto-button.h b/src/koto-button.h index 4f99950..c267247 100644 --- a/src/koto-button.h +++ b/src/koto-button.h @@ -16,9 +16,6 @@ */ #pragma once -#ifndef __GTK_ENUMS_H__ -#define __GTK_ENUMS_H__ -#endif #include #include @@ -40,18 +37,20 @@ typedef enum { #define KOTO_TYPE_BUTTON (koto_button_get_type()) -G_DECLARE_FINAL_TYPE (KotoButton, koto_button, KOTO, BUTTON, GtkBox) +G_DECLARE_FINAL_TYPE (KotoButton, koto_button, KOTO, BUTTON, GtkEventBox) guint koto_get_pixbuf_size(KotoButtonPixbufSize size); KotoButton* koto_button_new_plain(gchar *label); -KotoButton* koto_button_new_with_icon(gchar *label, gchar *icon_name, KotoButtonPixbufSize size); +KotoButton* koto_button_new_with_icon(gchar *label, gchar *icon_name, gchar *alt_icon_name, KotoButtonPixbufSize size); KotoButton* koto_button_new_with_pixbuf(gchar *label, GdkPixbuf *pix, KotoButtonPixbufSize size); +void koto_button_flip(KotoButton *self); void koto_button_set_badge_text(KotoButton *self, gchar *text); -void koto_button_set_icon_name(KotoButton *self, gchar *icon_name); +void koto_button_set_icon_name(KotoButton *self, gchar *icon_name, gboolean for_alt); void koto_button_set_pixbuf(KotoButton *self, GdkPixbuf *pix); void koto_button_set_pixbuf_size(KotoButton *self, guint size); void koto_button_set_text(KotoButton *self, gchar *text); +void koto_button_show_image(KotoButton *self, gboolean use_alt); G_END_DECLS diff --git a/src/koto-expander.c b/src/koto-expander.c index 3ecae3d..639da81 100644 --- a/src/koto-expander.c +++ b/src/koto-expander.c @@ -19,20 +19,18 @@ #include #include "koto-config.h" #include "koto-button.h" -#include "koto-flipper-button.h" #include "koto-expander.h" -#include "koto-utils.h" enum { - PROP_0, + PROP_EXP_0, PROP_HEADER_ICON_NAME, PROP_HEADER_LABEL, PROP_HEADER_SECONDARY_BUTTON, PROP_CONTENT, - N_PROPERTIES + N_EXP_PROPERTIES }; -static GParamSpec *props[N_PROPERTIES] = { NULL, }; +static GParamSpec *expander_props[N_EXP_PROPERTIES] = { NULL, }; struct _KotoExpander { GtkBox parent_instance; @@ -43,8 +41,8 @@ struct _KotoExpander { gchar *icon_name; gchar *label; - GtkWidget *header_secondary_button; - KotoFlipperButton *header_expand_button; + KotoButton *header_secondary_button; + KotoButton *header_expand_button; GtkWidget *revealer; GtkWidget *content; @@ -65,7 +63,7 @@ static void koto_expander_class_init(KotoExpanderClass *c) { gobject_class->set_property = koto_expander_set_property; gobject_class->get_property = koto_expander_get_property; - props[PROP_HEADER_ICON_NAME] = g_param_spec_string( + expander_props[PROP_HEADER_ICON_NAME] = g_param_spec_string( "icon-name", "Icon Name", "Name of the icon to use in the Expander", @@ -73,7 +71,7 @@ static void koto_expander_class_init(KotoExpanderClass *c) { G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - props[PROP_HEADER_LABEL] = g_param_spec_string( + expander_props[PROP_HEADER_LABEL] = g_param_spec_string( "label", "Label", "Label for the Expander", @@ -81,15 +79,15 @@ static void koto_expander_class_init(KotoExpanderClass *c) { G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - props[PROP_HEADER_SECONDARY_BUTTON] = g_param_spec_object( + expander_props[PROP_HEADER_SECONDARY_BUTTON] = g_param_spec_object( "secondary-button", "Secondary Button", "Secondary Button to be placed next to Expander button", - GTK_TYPE_WIDGET, + KOTO_TYPE_BUTTON, G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - props[PROP_CONTENT] = g_param_spec_object( + expander_props[PROP_CONTENT] = g_param_spec_object( "content", "Content", "Content inside the Expander", @@ -97,7 +95,7 @@ static void koto_expander_class_init(KotoExpanderClass *c) { G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - g_object_class_install_properties(gobject_class, N_PROPERTIES, props); + g_object_class_install_properties(gobject_class, N_EXP_PROPERTIES, expander_props); } static void koto_expander_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { @@ -126,7 +124,7 @@ static void koto_expander_set_property(GObject *obj, guint prop_id, const GValue KotoExpander *self = KOTO_EXPANDER(obj); if (!GTK_IS_WIDGET(self->header_button)) { // Header Button is not a widget - KotoButton *new_button = koto_button_new_with_icon("Temporary Text", "emblem-favorite-symbolic", KOTO_BUTTON_PIXBUF_SIZE_SMALL); + KotoButton *new_button = koto_button_new_with_icon("Temporary Text", "emblem-favorite-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_SMALL); if (GTK_IS_WIDGET(new_button)) { // Created our widget successfully self->header_button = new_button; @@ -137,14 +135,14 @@ static void koto_expander_set_property(GObject *obj, guint prop_id, const GValue switch (prop_id) { case PROP_HEADER_ICON_NAME: g_return_if_fail(GTK_IS_WIDGET(self->header_button)); - koto_button_set_icon_name(self->header_button, g_strdup(g_value_get_string(val))); + koto_button_set_icon_name(self->header_button, g_strdup(g_value_get_string(val)), FALSE); break; case PROP_HEADER_LABEL: g_return_if_fail(GTK_IS_WIDGET(self->header_button)); koto_button_set_text(self->header_button, g_strdup(g_value_get_string(val))); break; case PROP_HEADER_SECONDARY_BUTTON: - koto_expander_set_secondary_button(self, (GtkWidget*) g_value_get_object(val)); + koto_expander_set_secondary_button(self, (KotoButton*) g_value_get_object(val)); break; case PROP_CONTENT: koto_expander_set_content(self, (GtkWidget*) g_value_get_object(val)); @@ -171,7 +169,7 @@ static void koto_expander_init(KotoExpander *self) { gtk_revealer_set_reveal_child(GTK_REVEALER(self->revealer), TRUE); // Set to be revealed by default gtk_revealer_set_transition_type(GTK_REVEALER(self->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); - self->header_expand_button = koto_flipper_button_new("pan-down-symbolic", "pan-up-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); + self->header_expand_button = koto_button_new_with_icon("", "pan-down-symbolic", "pan-up-symbolic", KOTO_BUTTON_PIXBUF_SIZE_SMALL); gtk_box_pack_end(GTK_BOX(self->header), GTK_WIDGET(self->header_expand_button), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(self), self->header, FALSE, FALSE, 0); @@ -179,27 +177,26 @@ static void koto_expander_init(KotoExpander *self) { self->constructed = TRUE; - g_signal_connect(self->header_expand_button, "clicked", G_CALLBACK(koto_expander_toggle_content), self); + g_signal_connect(self->header_expand_button, "button-release-event", G_CALLBACK(koto_expander_toggle_content), self); } -void koto_expander_set_secondary_button(KotoExpander *self, GtkWidget *new_button) { +void koto_expander_set_secondary_button(KotoExpander *self, KotoButton *new_button) { if (!self->constructed) { return; } - if (!GTK_IS_BUTTON(new_button)) { + if (!GTK_IS_WIDGET(new_button)) { return; } - if (GTK_IS_BUTTON(self->header_secondary_button)) { // Already have a button - gtk_container_remove(GTK_CONTAINER(self->header), self->header_secondary_button); - //g_free(self->header_secondary_button); + if (GTK_IS_WIDGET(self->header_secondary_button)) { // Already have a button + gtk_container_remove(GTK_CONTAINER(self->header), GTK_WIDGET(self->header_secondary_button)); } self->header_secondary_button = new_button; - gtk_box_pack_end(GTK_BOX(self->header), self->header_secondary_button, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(self->header), GTK_WIDGET(self->header_secondary_button), FALSE, FALSE, 0); - g_object_notify_by_pspec(G_OBJECT(self), props[PROP_HEADER_SECONDARY_BUTTON]); + g_object_notify_by_pspec(G_OBJECT(self), expander_props[PROP_HEADER_SECONDARY_BUTTON]); } void koto_expander_set_content(KotoExpander *self, GtkWidget *new_content) { @@ -215,12 +212,12 @@ void koto_expander_set_content(KotoExpander *self, GtkWidget *new_content) { self->content = new_content; gtk_container_add(GTK_CONTAINER(self->revealer), self->content); - g_object_notify_by_pspec(G_OBJECT(self), props[PROP_CONTENT]); + g_object_notify_by_pspec(G_OBJECT(self), expander_props[PROP_CONTENT]); } -void koto_expander_toggle_content(GtkWidget *button, gpointer data) { +void koto_expander_toggle_content(GtkWidget *button, GdkEvent *event, gpointer data) { KotoExpander* self = data; - koto_flipper_button_flip(KOTO_FLIPPER_BUTTON(button)); + koto_button_flip(KOTO_BUTTON(button)); GtkRevealer* rev = GTK_REVEALER(self->revealer); gtk_revealer_set_reveal_child(rev, !gtk_revealer_get_reveal_child(rev)); // Invert our values } @@ -234,7 +231,7 @@ KotoExpander* koto_expander_new(gchar *primary_icon_name, gchar *primary_label_t ); } -KotoExpander* koto_expander_new_with_button(gchar *primary_icon_name, gchar *primary_label_text, GtkWidget *secondary_button) { +KotoExpander* koto_expander_new_with_button(gchar *primary_icon_name, gchar *primary_label_text, KotoButton *secondary_button) { return g_object_new(KOTO_TYPE_EXPANDER, "orientation", GTK_ORIENTATION_VERTICAL, "icon-name", primary_icon_name, diff --git a/src/koto-expander.h b/src/koto-expander.h index c047ab7..6d82a94 100644 --- a/src/koto-expander.h +++ b/src/koto-expander.h @@ -18,6 +18,7 @@ #pragma once #include +#include "koto-button.h" G_BEGIN_DECLS @@ -26,11 +27,11 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (KotoExpander, koto_expander, KOTO, EXPANDER, GtkBox) KotoExpander* koto_expander_new(gchar *primary_icon_name, gchar *primary_label_text); -KotoExpander* koto_expander_new_with_button(gchar *primary_icon_name, gchar *primary_label_text, GtkWidget *secondary_button); +KotoExpander* koto_expander_new_with_button(gchar *primary_icon_name, gchar *primary_label_text, KotoButton *secondary_button); void koto_expander_set_icon_name(KotoExpander *self, const gchar *in); void koto_expander_set_label(KotoExpander *self, const gchar *label); -void koto_expander_set_secondary_button(KotoExpander *self, GtkWidget *new_button); +void koto_expander_set_secondary_button(KotoExpander *self, KotoButton *new_button); void koto_expander_set_content(KotoExpander *self, GtkWidget *new_content); -void koto_expander_toggle_content(GtkWidget *button, gpointer data); +void koto_expander_toggle_content(GtkWidget *button, GdkEvent *event, gpointer data); G_END_DECLS diff --git a/src/koto-flipper-button.c b/src/koto-flipper-button.c deleted file mode 100644 index 510bf0d..0000000 --- a/src/koto-flipper-button.c +++ /dev/null @@ -1,129 +0,0 @@ -/* koto-flipper-button.c - * - * Copyright 2021 Joshua Strobl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "koto-config.h" -#include "koto-flipper-button.h" - -enum { - PROP_0, - PROP_SIZE, - PROP_INITIAL_IMAGE, - PROP_FLIPPED_IMAGE, - N_PROPERTIES -}; - -static GParamSpec *props[N_PROPERTIES] = { NULL, }; - -struct _KotoFlipperButton { - GtkButton parent_instance; - GtkIconSize size; - gboolean flipped; - - gchar *initial_image; - gchar *flipped_image; -}; - -struct _KotoFlipperButtonClass { - GtkButtonClass parent_class; -}; - -G_DEFINE_TYPE(KotoFlipperButton, koto_flipper_button, GTK_TYPE_BUTTON); -static void koto_flipper_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); - -static void koto_flipper_button_class_init(KotoFlipperButtonClass *c) { - GObjectClass *gobject_class; - gobject_class = G_OBJECT_CLASS(c); - gobject_class->set_property = koto_flipper_button_set_property; - - props[PROP_SIZE] = g_param_spec_enum( - "size", - "Icon Size", - "Size of the icon", - GTK_TYPE_ICON_SIZE, - GTK_ICON_SIZE_MENU, - G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_WRITABLE - ); - - props[PROP_INITIAL_IMAGE] = g_param_spec_string( - "initial-image", - "Initial Image", - "Image to use initially for the button", - NULL, - G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_WRITABLE - ); - - props[PROP_FLIPPED_IMAGE] = g_param_spec_string( - "flipped-image", - "Flipped Image", - "Image to use when the button is flipped", - NULL, - G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_WRITABLE - ); - - g_object_class_install_properties(gobject_class, N_PROPERTIES, props); -} - -static void koto_flipper_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec) { - KotoFlipperButton *self = KOTO_FLIPPER_BUTTON(obj); - - if (prop_id == PROP_INITIAL_IMAGE) { - g_free(self->initial_image); - self->initial_image = g_strdup(g_value_get_string(val)); - koto_flipper_button_set_icon(self, self->initial_image); - } else if (prop_id == PROP_FLIPPED_IMAGE) { - g_free(self->flipped_image); - self->flipped_image = g_strdup(g_value_get_string(val)); - } else if (prop_id == PROP_SIZE) { - self->size = (GtkIconSize) g_value_get_enum(val); - - if (self->initial_image != NULL && !self->flipped) { - koto_flipper_button_set_icon(self, self->flipped ? self->initial_image : self->flipped_image); - } - } else { - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); - return; - } - - g_object_notify_by_pspec(obj, props[prop_id]); -} - -static void koto_flipper_button_init(KotoFlipperButton *self) { - self->flipped = FALSE; - - GtkStyleContext *button_style = gtk_widget_get_style_context(GTK_WIDGET(self)); // Get the styling for the flipper button - gtk_style_context_add_class(button_style, "flat"); // Set it to flat -} - -void koto_flipper_button_flip(KotoFlipperButton *self) { - koto_flipper_button_set_icon(self, self->flipped ? self->initial_image : self->flipped_image); - self->flipped = !self->flipped; -} - -void koto_flipper_button_set_icon(KotoFlipperButton *self, gchar *name) { - GtkWidget *new_image = gtk_image_new_from_icon_name(name, self->size); - gtk_button_set_image(GTK_BUTTON(self), new_image); -} - -KotoFlipperButton* koto_flipper_button_new(gchar *initial_icon, gchar *flipped_icon, GtkIconSize size) { - return g_object_new(KOTO_TYPE_FLIPPER_BUTTON, - "initial-image", initial_icon, - "flipped-image", flipped_icon, - "size", size, - NULL - ); -} diff --git a/src/koto-nav.c b/src/koto-nav.c index 15ec21f..63b643c 100644 --- a/src/koto-nav.c +++ b/src/koto-nav.c @@ -20,7 +20,6 @@ #include "koto-button.h" #include "koto-expander.h" #include "koto-nav.h" -#include "koto-utils.h" struct _KotoNav { GtkScrolledWindow parent_instance; @@ -68,7 +67,7 @@ static void koto_nav_init(KotoNav *self) { gtk_container_add(GTK_CONTAINER(self), self->content); - KotoButton *h_button = koto_button_new_with_icon("Home", "user-home-symbolic", KOTO_BUTTON_PIXBUF_SIZE_SMALL); + KotoButton *h_button = koto_button_new_with_icon("Home", "user-home-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_SMALL); if (h_button != NULL) { self->home_button = h_button; @@ -80,8 +79,7 @@ static void koto_nav_init(KotoNav *self) { koto_nav_create_podcasts_section(self); - - GtkWidget *playlist_add_button = koto_create_flat_icon_button("list-add-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); + KotoButton *playlist_add_button = koto_button_new_with_icon("", "list-add-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_SMALL); KotoExpander *pl_expander = koto_expander_new_with_button("playlist-symbolic", "Playlists", playlist_add_button); if (pl_expander != NULL) { diff --git a/src/koto-playerbar.c b/src/koto-playerbar.c index 307f0d7..66abab8 100644 --- a/src/koto-playerbar.c +++ b/src/koto-playerbar.c @@ -15,10 +15,9 @@ * limitations under the License. */ -#include +#include "koto-button.h" #include "koto-config.h" #include "koto-playerbar.h" -#include "koto-utils.h" struct _KotoPlayerBar { GtkBox parent_instance; @@ -29,13 +28,13 @@ struct _KotoPlayerBar { GtkWidget *secondary_controls_section; /* Primary Buttons */ - GtkWidget *back_button; - GtkWidget *play_pause_button; - GtkWidget *forward_button; - GtkWidget *repeat_button; - GtkWidget *shuffle_button; - GtkWidget *playlist_button; - GtkWidget *eq_button; + KotoButton *back_button; + KotoButton *play_pause_button; + KotoButton *forward_button; + KotoButton *repeat_button; + KotoButton *shuffle_button; + KotoButton *playlist_button; + KotoButton *eq_button; GtkWidget *volume_button; /* Selected Playback Section */ @@ -113,9 +112,9 @@ void koto_playerbar_create_playback_details(KotoPlayerBar* bar) { gtk_box_pack_start(GTK_BOX(bar->playback_section), bar->artwork, FALSE, FALSE, 0); } - bar->playback_title = gtk_label_new(_("Title")); - bar->playback_album = gtk_label_new(_("Album")); - bar->playback_artist = gtk_label_new(_("Artist")); + bar->playback_title = gtk_label_new("Title"); + bar->playback_album = gtk_label_new("Album"); + bar->playback_artist = gtk_label_new("Artist"); gtk_box_pack_start(GTK_BOX(bar->playback_details_section), GTK_WIDGET(bar->playback_title), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(bar->playback_details_section), GTK_WIDGET(bar->playback_album), TRUE, TRUE, 0); @@ -125,45 +124,45 @@ void koto_playerbar_create_playback_details(KotoPlayerBar* bar) { } void koto_playerbar_create_primary_controls(KotoPlayerBar* bar) { - bar->back_button = koto_create_flat_icon_button("media-skip-backward-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); - bar->play_pause_button = koto_create_flat_icon_button("media-playback-start-symbolic", GTK_ICON_SIZE_DND); // TODO: Have this take in a state and switch to a different icon if necessary - bar->forward_button = koto_create_flat_icon_button("media-skip-forward-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + bar->back_button = koto_button_new_with_icon("", "media-skip-backward-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_NORMAL); + bar->play_pause_button = koto_button_new_with_icon("", "media-playback-start-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_LARGE); // TODO: Have this take in a state and switch to a different icon if necessary + bar->forward_button = koto_button_new_with_icon("", "media-skip-forward-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_NORMAL); if (bar->back_button != NULL) { - gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), bar->back_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), GTK_WIDGET(bar->back_button), FALSE, FALSE, 0); } if (bar->play_pause_button != NULL) { - gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), bar->play_pause_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), GTK_WIDGET(bar->play_pause_button), FALSE, FALSE, 0); } if (bar->forward_button != NULL) { - gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), bar->forward_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(bar->primary_controls_section), GTK_WIDGET(bar->forward_button), FALSE, FALSE, 0); } } void koto_playerbar_create_secondary_controls(KotoPlayerBar* bar) { - bar->repeat_button = koto_create_flat_icon_button("media-playlist-repeat-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); - bar->shuffle_button = koto_create_flat_icon_button("media-playlist-shuffle-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); - bar->playlist_button = koto_create_flat_icon_button("playlist-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); - bar->eq_button = koto_create_flat_icon_button("multimedia-equalizer-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + bar->repeat_button = koto_button_new_with_icon("", "media-playlist-repeat-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_NORMAL); + bar->shuffle_button = koto_button_new_with_icon("", "media-playlist-shuffle-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_NORMAL); + bar->playlist_button = koto_button_new_with_icon("", "playlist-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_NORMAL); + bar->eq_button = koto_button_new_with_icon("", "multimedia-equalizer-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_NORMAL); bar->volume_button = gtk_volume_button_new(); // Have this take in a state and switch to a different icon if necessary gtk_scale_button_set_value(GTK_SCALE_BUTTON(bar->volume_button), 0.5); if (bar->repeat_button != NULL) { - gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->repeat_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), GTK_WIDGET(bar->repeat_button), FALSE, FALSE, 0); } if (bar->shuffle_button != NULL) { - gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->shuffle_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), GTK_WIDGET(bar->shuffle_button), FALSE, FALSE, 0); } if (bar->playlist_button != NULL) { - gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->playlist_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), GTK_WIDGET(bar->playlist_button), FALSE, FALSE, 0); } if (bar->eq_button != NULL) { - gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), bar->eq_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(bar->secondary_controls_section), GTK_WIDGET(bar->eq_button), FALSE, FALSE, 0); } if (bar->volume_button != NULL) { diff --git a/src/koto-utils.c b/src/koto-utils.c deleted file mode 100644 index 985c787..0000000 --- a/src/koto-utils.c +++ /dev/null @@ -1,28 +0,0 @@ -/* koto-utils.c - * - * Copyright 2021 Joshua Strobl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "koto-utils.h" - -GtkWidget* koto_create_flat_icon_button(gchar *icon_name, GtkIconSize size) { - GtkWidget* button; - button = gtk_button_new_from_icon_name(icon_name, size); - - GtkStyleContext *button_style = gtk_widget_get_style_context(button); - gtk_style_context_add_class(button_style, "flat"); - - return button; -} diff --git a/src/koto-utils.h b/src/koto-utils.h deleted file mode 100644 index 0a13d1c..0000000 --- a/src/koto-utils.h +++ /dev/null @@ -1,24 +0,0 @@ -/* koto-utils.h - * - * Copyright 2021 Joshua Strobl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -G_BEGIN_DECLS - -GtkWidget* koto_create_flat_icon_button(gchar *icon_name, GtkIconSize size); - -G_END_DECLS diff --git a/src/koto-window.c b/src/koto-window.c index b86d565..53116dc 100644 --- a/src/koto-window.c +++ b/src/koto-window.c @@ -37,12 +37,9 @@ G_DEFINE_TYPE (KotoWindow, koto_window, GTK_TYPE_APPLICATION_WINDOW) static void koto_window_class_init (KotoWindowClass *klass) { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - gtk_widget_class_set_template_from_resource (widget_class, "/com/github/joshstrobl/koto/koto-window.ui"); } static void koto_window_init (KotoWindow *self) { - gtk_widget_init_template (GTK_WIDGET (self)); GtkCssProvider* provider = gtk_css_provider_new(); gtk_css_provider_load_from_resource(provider, "/com/github/joshstrobl/koto/style.css"); gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); @@ -75,8 +72,12 @@ static void koto_window_init (KotoWindow *self) { } gtk_container_add(GTK_CONTAINER(self), self->primary_layout); - gtk_widget_show_all(GTK_WIDGET(self)); + gtk_widget_set_size_request(GTK_WIDGET(self), 1200, 675); + gtk_window_set_title(GTK_WINDOW(self), "Koto"); + gtk_window_set_wmclass(GTK_WINDOW(self), "com.github.joshstrobl.koto", "com.github.joshstrobl.koto"); + gtk_window_set_icon_name(GTK_WINDOW(self), "audio-headphones"); + gtk_widget_show_all(GTK_WIDGET(self)); g_thread_new("load-library", load_library, self); } diff --git a/src/koto-window.ui b/src/koto-window.ui deleted file mode 100644 index a1da769..0000000 --- a/src/koto-window.ui +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/src/koto.gresource.xml b/src/koto.gresource.xml index 5e969dc..250bec4 100644 --- a/src/koto.gresource.xml +++ b/src/koto.gresource.xml @@ -2,7 +2,6 @@ koto-headerbar.ui - koto-window.ui ../data/style.css diff --git a/src/meson.build b/src/meson.build index ff11a8d..b0b252b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,13 +1,12 @@ koto_sources = [ + 'indexer/file.c', 'indexer/file-indexer.c', 'main.c', 'koto-button.c', 'koto-expander.c', - 'koto-flipper-button.c', 'koto-headerbar.c', 'koto-nav.c', 'koto-playerbar.c', - 'koto-utils.c', 'koto-window.c', ] From 304c7635da3be17200320ee550e296fcaaa9e08e Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Tue, 16 Feb 2021 17:15:10 +0200 Subject: [PATCH 08/83] Implemented ID3 tag parsing in our KotoIndexedFile leveraging taglib, refactored our mimetype code. Implemented KotoIndexedArtist as well as KotoIndexedAlbum, including moving the file indexing capabilities into the KotoIndexedAlbum (subject to change). Added g_debug messages instead of using g_message for debug purposes. Re-introduced Koto Utils with new koto_utils_get_filename_without_extension, since that is used to get the extensionless file name across both album fetching and base file name fetching. --- src/indexer/album.c | 289 +++++++++++++++++++++++++++++++++++++ src/indexer/album.h | 15 +- src/indexer/artist.c | 196 +++++++++++++++++++++++++ src/indexer/artist.h | 15 +- src/indexer/file-indexer.c | 185 ++++++++++++++++-------- src/indexer/file-indexer.h | 7 +- src/indexer/file.c | 151 ++++++++++++------- src/indexer/file.h | 5 +- src/koto-utils.c | 48 ++++++ src/koto-utils.h | 25 ++++ src/meson.build | 4 + 11 files changed, 815 insertions(+), 125 deletions(-) create mode 100644 src/indexer/album.c create mode 100644 src/indexer/artist.c create mode 100644 src/koto-utils.c create mode 100644 src/koto-utils.h diff --git a/src/indexer/album.c b/src/indexer/album.c new file mode 100644 index 0000000..589c7eb --- /dev/null +++ b/src/indexer/album.c @@ -0,0 +1,289 @@ +/* album.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "album.h" +#include "file.h" +#include "koto-utils.h" + +struct _KotoIndexedAlbum { + GObject parent_instance; + gchar *path; + + gchar *name; + gchar *art_path; + GHashTable *files; + + gboolean has_album_art; +}; + +G_DEFINE_TYPE(KotoIndexedAlbum, koto_indexed_album, G_TYPE_OBJECT); + +enum { + PROP_0, + PROP_PATH, + PROP_ALBUM_NAME, + PROP_ART_PATH, + N_PROPERTIES +}; + +static GParamSpec *props[N_PROPERTIES] = { NULL, }; + +static void koto_indexed_album_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec); +static void koto_indexed_album_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); + +static void koto_indexed_album_class_init(KotoIndexedAlbumClass *c) { + GObjectClass *gobject_class; + gobject_class = G_OBJECT_CLASS(c); + gobject_class->set_property = koto_indexed_album_set_property; + gobject_class->get_property = koto_indexed_album_get_property; + + props[PROP_PATH] = g_param_spec_string( + "path", + "Path", + "Path to Album", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_ALBUM_NAME] = g_param_spec_string( + "name", + "Name", + "Name of Album", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_ART_PATH] = g_param_spec_string( + "art-path", + "Path to Artwork", + "Path to Artwork", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + g_object_class_install_properties(gobject_class, N_PROPERTIES, props); +} + +static void koto_indexed_album_init(KotoIndexedAlbum *self) { + self->has_album_art = FALSE; +} + +void koto_indexed_album_add_file(KotoIndexedAlbum *self, KotoIndexedFile *file) { + if (file == NULL) { // Not a file + return; + } + + if (self->files == NULL) { // No HashTable yet + self->files = g_hash_table_new(g_str_hash, g_str_equal); // Create a new HashTable + } + + gchar *file_name; + g_object_get(file, "parsed-name", &file_name, NULL); + + if (g_hash_table_contains(self->files, file_name)) { // If we have this file already + g_free(file_name); + return; + } + + g_hash_table_insert(self->files, file_name, file); // Add the file +} + + + +static void koto_indexed_album_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { + KotoIndexedAlbum *self = KOTO_INDEXED_ALBUM(obj); + + switch (prop_id) { + case PROP_PATH: + g_value_set_string(val, self->path); + break; + case PROP_ALBUM_NAME: + g_value_set_string(val, self->name); + break; + case PROP_ART_PATH: + g_value_set_string(val, koto_indexed_album_get_album_art(self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +gchar* koto_indexed_album_get_album_art(KotoIndexedAlbum *self) { + return g_strdup((self->has_album_art) ? self->art_path : ""); +} + +GList* koto_indexed_album_get_files(KotoIndexedAlbum *self) { + if (self->files == NULL) { // No HashTable yet + self->files = g_hash_table_new(g_str_hash, g_str_equal); // Create a new HashTable + } + + return g_hash_table_get_values(self->files); +} + +void koto_indexed_album_set_album_art(KotoIndexedAlbum *self, const gchar *album_art) { + if (album_art == NULL) { // Not valid album art + return; + } + + if (self->art_path != NULL) { + g_free(self->art_path); + } + + self->art_path = g_strdup(album_art); + self->has_album_art = TRUE; +} + +void koto_indexed_album_remove_file(KotoIndexedAlbum *self, KotoIndexedFile *file) { + if (file == NULL) { // Not a file + return; + } + + if (self->files == NULL) { // No HashTable yet + self->files = g_hash_table_new(g_str_hash, g_str_equal); // Create a new HashTable + } + + gchar *file_name; + g_object_get(file, "parsed-name", &file_name, NULL); + g_hash_table_remove(self->files, file_name); +} + +void koto_indexed_album_remove_file_by_name(KotoIndexedAlbum *self, const gchar *file_name) { + if (file_name == NULL) { + return; + } + + KotoIndexedFile *file = g_hash_table_lookup(self->files, file_name); // Get the files + koto_indexed_album_remove_file(self, file); +} + +void koto_indexed_album_set_album_name(KotoIndexedAlbum *self, const gchar *album_name) { + if (album_name == NULL) { // Not valid album name + return; + } + + if (self->name != NULL) { + g_free(self->name); + } + + self->name = g_strdup(album_name); +} + +static void koto_indexed_album_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec){ + KotoIndexedAlbum *self = KOTO_INDEXED_ALBUM(obj); + + switch (prop_id) { + case PROP_PATH: // Path to the album + koto_indexed_album_update_path(self, g_value_get_string(val)); + break; + case PROP_ALBUM_NAME: // Name of album + koto_indexed_album_set_album_name(self, g_value_get_string(val)); + break; + case PROP_ART_PATH: // Path to art + koto_indexed_album_set_album_art(self, g_value_get_string(val)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +void koto_indexed_album_update_path(KotoIndexedAlbum *self, const gchar* new_path) { + if (new_path == NULL) { + return; + } + + DIR *dir = opendir(new_path); // Attempt to open our directory + + if (dir == NULL) { + return; + } + + if (self->path != NULL) { + g_free(self->path); + } + + self->path = g_strdup(new_path); + + koto_indexed_album_set_album_name(self, g_path_get_basename(self->path)); // Update our album name based on the base name + + magic_t magic_cookie = magic_open(MAGIC_MIME); + + if (magic_cookie == NULL) { + return; + } + + if (magic_load(magic_cookie, NULL) != 0) { + magic_close(magic_cookie); + return; + } + + struct dirent *entry; + + while ((entry = readdir(dir))) { + if (g_str_has_prefix(entry->d_name, ".")) { // Reference to parent dir, self, or a hidden item + continue; // Skip + } + + if (entry->d_type != DT_REG) { // If this is not a regular file + continue; // Skip + } + + gchar *full_path = g_strdup_printf("%s%s%s", self->path, G_DIR_SEPARATOR_S, entry->d_name); + const char *mime_type = magic_file(magic_cookie, full_path); + + if (mime_type == NULL) { // Failed to get the mimetype + g_free(full_path); + continue; // Skip + } + + if (g_str_has_prefix(mime_type, "image/") && !self->has_album_art) { // Is an image file and doesn't have album art yet + gchar *album_art_no_ext = g_strdup(koto_utils_get_filename_without_extension(entry->d_name)); // Get the name of the file without the extension + gchar *lower_art = g_strdup(g_utf8_strdown(album_art_no_ext, -1)); // Lowercase + + if ( + (g_strrstr(lower_art, "Small") == NULL) && // Not Small + (g_strrstr(lower_art, "back") == NULL) // Not back + ) { + koto_indexed_album_set_album_art(self, full_path); + } + + g_free(album_art_no_ext); + g_free(lower_art); + } else if (g_str_has_prefix(mime_type, "audio/")) { // Is an audio file + KotoIndexedFile *file = koto_indexed_file_new(full_path); + + if (file != NULL) { // Is a file + koto_indexed_album_add_file(self, file); // Add our file + } + } + + g_free(full_path); + } + + magic_close(magic_cookie); +} + +KotoIndexedAlbum* koto_indexed_album_new(const gchar *path) { + return g_object_new(KOTO_TYPE_INDEXED_ALBUM, + "path", path, + NULL + ); +} diff --git a/src/indexer/album.h b/src/indexer/album.h index f9cc23b..3ff9001 100644 --- a/src/indexer/album.h +++ b/src/indexer/album.h @@ -17,17 +17,22 @@ #pragma once #include +#include "file.h" G_BEGIN_DECLS -#define KOTO_INDEXED_ALBUM_TYPE koto_indexed_album_get_type() +#define KOTO_TYPE_INDEXED_ALBUM koto_indexed_album_get_type() G_DECLARE_FINAL_TYPE (KotoIndexedAlbum, koto_indexed_album, KOTO, INDEXED_ALBUM, GObject); KotoIndexedAlbum* koto_indexed_album_new(const gchar *path); -void add_song(KotoIndexedAlbum *self, KotoIndexedFile *file); -KotoIndexedFile** get_songs(KotoIndexedAlbum *self); -void remove_song(KotoIndexedAlbum *self, KotoIndexedFile *file); -void remove_song_by_name(KotoIndexedAlbum *self, gchar *file_name); +void koto_indexed_album_add_file(KotoIndexedAlbum *self, KotoIndexedFile *file); +gchar* koto_indexed_album_get_album_art(KotoIndexedAlbum *self); +GList* koto_indexed_album_get_files(KotoIndexedAlbum *self); +void koto_indexed_album_remove_file(KotoIndexedAlbum *self, KotoIndexedFile *file); +void koto_indexed_album_remove_file_by_name(KotoIndexedAlbum *self, const gchar *file_name); +void koto_indexed_album_set_album_art(KotoIndexedAlbum *self, const gchar *album_art); +void koto_indexed_album_set_album_name(KotoIndexedAlbum *self, const gchar *album_name); +void koto_indexed_album_update_path(KotoIndexedAlbum *self, const gchar *path); G_END_DECLS diff --git a/src/indexer/artist.c b/src/indexer/artist.c new file mode 100644 index 0000000..6985a31 --- /dev/null +++ b/src/indexer/artist.c @@ -0,0 +1,196 @@ +/* artist.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "album.h" +#include "artist.h" + +struct _KotoIndexedArtist { + GObject parent_instance; + gchar *path; + + gboolean has_artist_art; + gchar *artist_name; + GHashTable *albums; +}; + +G_DEFINE_TYPE(KotoIndexedArtist, koto_indexed_artist, G_TYPE_OBJECT); + +enum { + PROP_0, + PROP_PATH, + PROP_ARTIST_NAME, + N_PROPERTIES +}; + +static GParamSpec *props[N_PROPERTIES] = { NULL, }; + +static void koto_indexed_artist_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec); +static void koto_indexed_artist_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); + +static void koto_indexed_artist_class_init(KotoIndexedArtistClass *c) { + GObjectClass *gobject_class; + gobject_class = G_OBJECT_CLASS(c); + gobject_class->set_property = koto_indexed_artist_set_property; + gobject_class->get_property = koto_indexed_artist_get_property; + + props[PROP_PATH] = g_param_spec_string( + "path", + "Path", + "Path to Artist", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + props[PROP_ARTIST_NAME] = g_param_spec_string( + "name", + "Name", + "Name of Artist", + NULL, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + + g_object_class_install_properties(gobject_class, N_PROPERTIES, props); +} + +static void koto_indexed_artist_init(KotoIndexedArtist *self) { + self->has_artist_art = FALSE; + self->albums = NULL; // Set to null initially maybe +} + +static void koto_indexed_artist_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { + KotoIndexedArtist *self = KOTO_INDEXED_ARTIST(obj); + + switch (prop_id) { + case PROP_PATH: + g_value_set_string(val, self->path); + break; + case PROP_ARTIST_NAME: + g_value_set_string(val, self->artist_name); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +static void koto_indexed_artist_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec){ + KotoIndexedArtist *self = KOTO_INDEXED_ARTIST(obj); + + switch (prop_id) { + case PROP_PATH: + koto_indexed_artist_update_path(self, g_value_get_string(val)); + break; + case PROP_ARTIST_NAME: + koto_indexed_artist_set_artist_name(self, g_value_get_string(val)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); + break; + } +} + +void koto_indexed_artist_add_album(KotoIndexedArtist *self, KotoIndexedAlbum *album) { + if (album == NULL) { // No album really defined + return; + } + + if (self->albums == NULL) { // No HashTable yet + self->albums = g_hash_table_new(g_str_hash, g_str_equal); // Create a new HashTable + } + + gchar *album_name; + g_object_get(album, "name", &album_name, NULL); + + if (album_name == NULL) { + g_free(album_name); + return; + } + + if (g_hash_table_contains(self->albums, album_name)) { // If we have this album already + g_free(album_name); + return; + } + + g_hash_table_insert(self->albums, album_name, album); // Add the album +} + +GList* koto_indexed_artist_get_albums(KotoIndexedArtist *self) { + if (self->albums == NULL) { // No HashTable yet + self->albums = g_hash_table_new(g_str_hash, g_str_equal); // Create a new HashTable + } + + return g_hash_table_get_values(self->albums); +} + +void koto_indexed_artist_remove_album(KotoIndexedArtist *self, KotoIndexedAlbum *album) { + if (album == NULL) { // No album defined + return; + } + + if (self->albums == NULL) { // No HashTable yet + self->albums = g_hash_table_new(g_str_hash, g_str_equal); // Create a new HashTable + } + + gchar *album_name; + g_object_get(album, "name", &album_name, NULL); + + g_hash_table_remove(self->albums, album_name); +} + +void koto_indexed_artist_remove_album_by_name(KotoIndexedArtist *self, gchar *album_name) { + if (album_name == NULL) { + return; + } + + KotoIndexedAlbum *album = g_hash_table_lookup(self->albums, album_name); // Get the album + koto_indexed_artist_remove_album(self, album); +} + +void koto_indexed_artist_update_path(KotoIndexedArtist *self, const gchar *new_path) { + if (new_path == NULL) { // No path really + return; + } + + if (self->path != NULL) { // Already have a path set + g_free(self->path); // Free + } + + self->path = g_strdup(new_path); + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PATH]); +} + +void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, const gchar *artist_name) { + if (artist_name == NULL) { // No artist name + return; + } + + if (self->artist_name != NULL) { // Has artist name + g_free(self->artist_name); + } + + self->artist_name = g_strdup(artist_name); + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_ARTIST_NAME]); +} + +KotoIndexedArtist* koto_indexed_artist_new(const gchar *path) { + return g_object_new(KOTO_TYPE_INDEXED_ARTIST, + "path", path, + "name", g_path_get_basename(path), + NULL + ); +} diff --git a/src/indexer/artist.h b/src/indexer/artist.h index e87fa2f..df88435 100644 --- a/src/indexer/artist.h +++ b/src/indexer/artist.h @@ -17,17 +17,22 @@ #pragma once #include +#include "album.h" G_BEGIN_DECLS -#define KOTO_INDEXED_ARTIST_TYPE koto_indexed_artist_get_type() +#define KOTO_TYPE_INDEXED_ARTIST koto_indexed_artist_get_type() G_DECLARE_FINAL_TYPE (KotoIndexedArtist, koto_indexed_artist, KOTO, INDEXED_ARTIST, GObject); KotoIndexedArtist* koto_indexed_artist_new(const gchar *path); -void add_album(KotoIndexedArtist *self, KotoIndexedAlbum *album); -KotoIndexedAlbum** get_albums(KotoIndexedArtist *self); -void remove_album(KotoIndexedArtist *self, KotoIndexedAlbum *album); -void remove_album_by_name(KotoIndexedArtist *self, gchar *album_name); +void koto_indexed_artist_add_album(KotoIndexedArtist *self, KotoIndexedAlbum *album); +guint koto_indexed_artist_find_album_with_name(gconstpointer *album_data, gconstpointer *album_name_data); +GList* koto_indexed_artist_get_albums(KotoIndexedArtist *self); +void koto_indexed_artist_remove_album(KotoIndexedArtist *self, KotoIndexedAlbum *album); +void koto_indexed_artist_remove_album_by_name(KotoIndexedArtist *self, gchar *album_name); +void koto_indexed_artist_set_artist_name(KotoIndexedArtist *self, const gchar *artist_name); +void koto_indexed_artist_update_path(KotoIndexedArtist *self, const gchar *new_path); +void output_artists(gpointer artist_key, gpointer artist_ptr, gpointer data); G_END_DECLS diff --git a/src/indexer/file-indexer.c b/src/indexer/file-indexer.c index 5a9b55b..7609485 100644 --- a/src/indexer/file-indexer.c +++ b/src/indexer/file-indexer.c @@ -17,27 +17,14 @@ #include #include +#include #include +#include +#include "album.h" +#include "artist.h" #include "file.h" #include "file-indexer.h" -struct KotoIndexedAlbum { - GObject parent_instance; - gboolean has_album_art; - gchar *album_name; - gchar *art_path; - gchar *path; - GHashTable *songs; -}; - -struct _KotoIndexedArtist { - GObject parent_instance; - gboolean has_artist_art; - gchar *artist_name; - GHashTable *albums; - gchar *path; -}; - struct _KotoIndexedLibrary { GObject parent_instance; gchar *path; @@ -73,12 +60,60 @@ static void koto_indexed_library_class_init(KotoIndexedLibraryClass *c) { ); g_object_class_install_properties(gobject_class, N_PROPERTIES, props); + taglib_id3v2_set_default_text_encoding(TagLib_ID3v2_UTF8); // Ensure our id3v2 text encoding is UTF-8 } static void koto_indexed_library_init(KotoIndexedLibrary *self) { self->music_artists = g_hash_table_new(g_str_hash, g_str_equal); } +void koto_indexed_library_add_artist(KotoIndexedLibrary *self, KotoIndexedArtist *artist) { + if (artist == NULL) { // No artist + return; + } + + if (self->music_artists == NULL) { // Not a HashTable + self->music_artists = g_hash_table_new(g_str_hash, g_str_equal); + } + + gchar *artist_name; + g_object_get(artist, "name", &artist_name, NULL); + + if (g_hash_table_contains(self->music_artists, artist_name)) { // Already have the artist + g_free(artist_name); + return; + } + + g_hash_table_insert(self->music_artists, artist_name, artist); // Add the artist +} + +KotoIndexedArtist* koto_indexed_library_get_artist(KotoIndexedLibrary *self, gchar *artist_name) { + if (artist_name == NULL) { + return NULL; + } + + if (self->music_artists == NULL) { // Not a HashTable + return NULL; + } + + return g_hash_table_lookup(self->music_artists, (KotoIndexedArtist*) artist_name); +} + +void koto_indexed_library_remove_artist(KotoIndexedLibrary *self, KotoIndexedArtist *artist) { + if (artist == NULL) { + return; + } + + if (self->music_artists == NULL) { // Not a HashTable + return; + } + + gchar *artist_name; + g_object_get(artist, "name", &artist_name, NULL); + + g_hash_table_remove(self->music_artists, artist_name); // Remove the artist +} + static void koto_indexed_library_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { KotoIndexedLibrary *self = KOTO_INDEXED_LIBRARY(obj); @@ -98,7 +133,6 @@ static void koto_indexed_library_set_property(GObject *obj, guint prop_id, const switch (prop_id) { case PROP_PATH: self->path = g_strdup(g_value_get_string(val)); - g_message("Set to %s", self->path); start_indexing(self); break; default: @@ -131,11 +165,14 @@ void start_indexing(KotoIndexedLibrary *self) { return; } - index_folder(self, self->path); + index_folder(self, self->path, 0); magic_close(self->magic_cookie); + g_hash_table_foreach(self->music_artists, output_artists, NULL); } -void index_folder(KotoIndexedLibrary *self, gchar *path) { +void index_folder(KotoIndexedLibrary *self, gchar *path, guint depth) { + depth++; + DIR *dir = opendir(path); // Attempt to open our directory if (dir == NULL) { @@ -145,54 +182,88 @@ void index_folder(KotoIndexedLibrary *self, gchar *path) { struct dirent *entry; while ((entry = readdir(dir))) { - if (!g_str_has_prefix(entry->d_name, ".")) { // Not a reference to parent dir, self, or a hidden item - gchar *full_path = g_strdup_printf("%s%s%s", path, G_DIR_SEPARATOR_S, entry->d_name); - - if (entry->d_type == DT_DIR) { // Directory - index_folder(self, full_path); // Index this directory - } else if (entry->d_type == DT_REG) { // Regular file - index_file(self, full_path); // Index the file - } - - g_free(full_path); + if (g_str_has_prefix(entry->d_name, ".")) { // A reference to parent dir, self, or a hidden item + continue; } + + gchar *full_path = g_strdup_printf("%s%s%s", path, G_DIR_SEPARATOR_S, entry->d_name); + + if (entry->d_type == DT_DIR) { // Directory + if (depth == 1) { // If we are following FOLDER/ARTIST/ALBUM then this would be artist + KotoIndexedArtist *artist = koto_indexed_artist_new(full_path); // Attempt to get the artist + gchar *artist_name; + + g_object_get(artist, + "name", &artist_name, + NULL + ); + + koto_indexed_library_add_artist(self, artist); // Add the artist + index_folder(self, full_path, depth); // Index this directory + g_free(artist_name); + } else if (depth == 2) { // If we are following FOLDER/ARTIST/ALBUM then this would be album + gchar *artist_name = g_path_get_basename(path); // Get the last entry from our path which is probably the artist + KotoIndexedAlbum *album = koto_indexed_album_new(full_path); + + KotoIndexedArtist *artist = koto_indexed_library_get_artist(self, artist_name); // Get the artist + + if (artist == NULL) { + continue; + } + + koto_indexed_artist_add_album(artist, album); // Add the album + g_free(artist_name); + } + } + + g_free(full_path); } closedir(dir); // Close the directory } -void index_file(KotoIndexedLibrary *self, gchar *path) { - const char *mime_type = magic_file(self->magic_cookie, path); +void output_artists(gpointer artist_key, gpointer artist_ptr, gpointer data) { + KotoIndexedArtist *artist = (KotoIndexedArtist*) artist_ptr; + gchar *artist_name; + g_object_get(artist, "name", &artist_name, NULL); - if (mime_type == NULL) { // Failed to get the mimetype - return; + g_debug("Artist: %s", artist_name); + GList *albums = koto_indexed_artist_get_albums(artist); // Get the albums for this artist + + if (albums != NULL) { + g_debug("Length of Albums: %d", g_list_length(albums)); } - gchar** mime_info = g_strsplit(mime_type, ";", 2); // Only care about our first item + GList *a; + for (a = albums; a != NULL; a = a->next) { + KotoIndexedAlbum *album = (KotoIndexedAlbum*) a->data; + gchar *artwork = koto_indexed_album_get_album_art(album); + gchar *album_name; + g_object_get(album, "name", &album_name, NULL); + g_debug("Album Art: %s", artwork); + g_debug("Album Name: %s", album_name); - if ( - g_str_has_prefix(mime_info[0], "audio/") || // Is audio - g_str_has_prefix(mime_info[0], "image/") // Is image - ) { - //g_message("File Name: %s", path); + GList *files = koto_indexed_album_get_files(album); // Get the files for the album + GList *f; + + for (f = files; f != NULL; f = f->next) { + KotoIndexedFile *file = (KotoIndexedFile*) f->data; + gchar *filepath; + gchar *parsed_name; + guint *pos; + + g_object_get(file, + "path", &filepath, + "parsed-name", &parsed_name, + "position", &pos, + NULL); + g_debug("File Path: %s", filepath); + g_debug("Parsed Name: %s", parsed_name); + g_debug("Position: %d", GPOINTER_TO_INT(pos)); + g_free(filepath); + g_free(parsed_name); + } } - - if (g_str_has_prefix(mime_info[0], "audio/")) { // Is an audio file - KotoIndexedFile *file = koto_indexed_file_new(path); - gchar *filepath; - gchar *parsed_name; - - g_object_get(file, - "path", &filepath, - "parsed-name", &parsed_name, - NULL); - - g_free(filepath); - g_free(parsed_name); - g_object_unref(file); - } - - g_strfreev(mime_info); // Free our mimeinfo } KotoIndexedLibrary* koto_indexed_library_new(const gchar *path) { diff --git a/src/indexer/file-indexer.h b/src/indexer/file-indexer.h index f5a5155..97b25cc 100644 --- a/src/indexer/file-indexer.h +++ b/src/indexer/file-indexer.h @@ -17,6 +17,7 @@ #pragma once #include +#include "artist.h" G_BEGIN_DECLS @@ -25,8 +26,10 @@ G_DECLARE_FINAL_TYPE(KotoIndexedLibrary, koto_indexed_library, KOTO, INDEXED_LIB KotoIndexedLibrary* koto_indexed_library_new(const gchar *path); +void koto_indexed_library_add_artist(KotoIndexedLibrary *self, KotoIndexedArtist *artist); +KotoIndexedArtist* koto_indexed_library_get_artist(KotoIndexedLibrary *self, gchar* artist_name); +void koto_indexed_library_remove_artist(KotoIndexedLibrary *self, KotoIndexedArtist *artist); void start_indexing(KotoIndexedLibrary *self); -void index_folder(KotoIndexedLibrary *self, gchar *path); -void index_file(KotoIndexedLibrary *self, gchar *path); +void index_folder(KotoIndexedLibrary *self, gchar *path, guint depth); G_END_DECLS diff --git a/src/indexer/file.c b/src/indexer/file.c index c9052b5..043dd7a 100644 --- a/src/indexer/file.c +++ b/src/indexer/file.c @@ -16,17 +16,19 @@ */ #include +#include #include "file.h" +#include "koto-utils.h" struct _KotoIndexedFile { GObject parent_instance; gchar *path; + gchar *file_name; gchar *parsed_name; gchar *artist; gchar *album; - - guint position; + guint *position; gboolean acquired_metadata_from_id3; }; @@ -131,7 +133,7 @@ static void koto_indexed_file_get_property(GObject *obj, guint prop_id, GValue * g_value_set_string(val, self->parsed_name); break; case PROP_POSITION: - g_value_set_uint(val, self->position); + g_value_set_uint(val, GPOINTER_TO_UINT(self->position)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); @@ -144,8 +146,7 @@ static void koto_indexed_file_set_property(GObject *obj, guint prop_id, const GV switch (prop_id) { case PROP_PATH: - self->path = g_strdup(g_value_get_string(val)); // Update our path - koto_indexed_file_set_file_name(self, g_path_get_basename(self->path)); // Update our file name + koto_indexed_file_update_path(self, g_value_get_string(val)); // Update the path break; case PROP_ARTIST: self->artist = g_strdup(g_value_get_string(val)); @@ -160,7 +161,7 @@ static void koto_indexed_file_set_property(GObject *obj, guint prop_id, const GV koto_indexed_file_set_parsed_name(self, g_strdup(g_value_get_string(val))); break; case PROP_POSITION: - self->position = g_value_get_uint(val); + koto_indexed_file_set_position(self, g_value_get_uint(val)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); @@ -168,6 +169,65 @@ static void koto_indexed_file_set_property(GObject *obj, guint prop_id, const GV } } +void koto_indexed_file_parse_name(KotoIndexedFile *self) { + gchar *copied_file_name = g_strdelimit(g_strdup(self->file_name), "_", ' '); // Replace _ with whitespace for starters + + if (self->artist != NULL && strcmp(self->artist, "") != 0) { // If we have artist set + gchar **split = g_strsplit(copied_file_name, self->artist, -1); // Split whenever we encounter the artist + copied_file_name = g_strjoinv("", split); // Remove the artist + g_strfreev(split); + } + + if (self->artist != NULL && strcmp(self->album, "") != 0) { // If we have album set + gchar **split = g_strsplit(copied_file_name, self->album, -1); // Split whenever we encounter the album + copied_file_name = g_strjoinv("", split); // Remove the album + g_strfreev(split); + + split = g_strsplit(copied_file_name, g_utf8_strdown(self->album, g_utf8_strlen(self->album, -1)), -1); // Split whenever we encounter the album lowercased + copied_file_name = g_strjoin("", split, NULL); // Remove the lowercased album + g_strfreev(split); + } + + if (g_str_match_string(copied_file_name, "-", FALSE)) { // Contains - like a heathen + gchar **split = g_strsplit(copied_file_name, " - ", -1); // Split whenever we encounter " - " + copied_file_name = g_strjoin("", split, NULL); // Remove entirely + g_strfreev(split); + + if (g_str_match_string(copied_file_name, "-", FALSE)) { // If we have any stragglers + split = g_strsplit(copied_file_name, "-", -1); // Split whenever we encounter - + copied_file_name = g_strjoin("", split, NULL); // Remove entirely + g_strfreev(split); + } + } + + gchar *file_without_ext = koto_utils_get_filename_without_extension(copied_file_name); + g_free(copied_file_name); + + gchar **split = g_regex_split_simple("^([\\d]+)\\s", file_without_ext, G_REGEX_JAVASCRIPT_COMPAT, 0); + + if (g_strv_length(split) > 1) { // Has positional info at the beginning of the file + gchar *num = split[1]; + + g_free(file_without_ext); // Free the prior name + file_without_ext = g_strdup(split[2]); // Set to our second item which is the rest of the song name without the prefixed numbers + + if ((strcmp(num, "0") == 0) || (strcmp(num, "00") == 0)) { // Is exactly zero + koto_indexed_file_set_position(self, 0); // Set position to 0 + } else { // Either starts with 0 (like 09) or doesn't start with it at all + guint64 potential_pos = g_ascii_strtoull(num, NULL, 10); // Attempt to convert + + if (potential_pos != 0) { // Got a legitimate position + koto_indexed_file_set_position(self, potential_pos); + } + } + } + + g_strfreev(split); + + koto_indexed_file_set_parsed_name(self, file_without_ext); + g_free(file_without_ext); +} + void koto_indexed_file_set_file_name(KotoIndexedFile *self, gchar *new_file_name) { if (new_file_name == NULL) { return; @@ -206,64 +266,45 @@ void koto_indexed_file_set_parsed_name(KotoIndexedFile *self, gchar *new_parsed_ g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PARSED_NAME]); } -void koto_indexed_file_parse_name(KotoIndexedFile *self) { - gchar *copied_file_name = g_strdelimit(g_strdup(self->file_name), "_", ' '); // Replace _ with whitespace for starters - - if (self->artist != NULL && strcmp(self->artist, "") != 0) { // If we have artist set - gchar **split = g_strsplit(copied_file_name, self->artist, -1); // Split whenever we encounter the artist - copied_file_name = g_strjoinv("", split); // Remove the artist - g_strfreev(split); +void koto_indexed_file_set_position(KotoIndexedFile *self, guint pos) { + if (pos == 0) { // No position change really + return; } - if (self->artist != NULL && strcmp(self->album, "") != 0) { // If we have album set - gchar **split = g_strsplit(copied_file_name, self->album, -1); // Split whenever we encounter the album - copied_file_name = g_strjoinv("", split); // Remove the album - g_strfreev(split); + self->position = GUINT_TO_POINTER(pos); + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_POSITION]); +} - split = g_strsplit(copied_file_name, g_utf8_strdown(self->album, g_utf8_strlen(self->album, -1)), -1); // Split whenever we encounter the album lowercased - copied_file_name = g_strjoin("", split, NULL); // Remove the lowercased album - g_strfreev(split); - } +void koto_indexed_file_update_metadata(KotoIndexedFile *self) { + TagLib_File *t_file = taglib_file_new(self->path); // Get a taglib file for this file - if (g_str_match_string(copied_file_name, "-", FALSE)) { // Contains - like a heathen - gchar **split = g_strsplit(copied_file_name, " - ", -1); // Split whenever we encounter " - " - copied_file_name = g_strjoin("", split, NULL); // Remove entirely - g_strfreev(split); - - if (g_str_match_string(copied_file_name, "-", FALSE)) { // If we have any stragglers - split = g_strsplit(copied_file_name, "-", -1); // Split whenever we encounter - - copied_file_name = g_strjoin("", split, NULL); // Remove entirely - g_strfreev(split); - } - } - - gchar **split = g_strsplit(copied_file_name, ".", -1); // Split every time we see . - g_free(copied_file_name); - guint len_of_extension_split = g_strv_length(split); - - if (len_of_extension_split == 2) { // Only have two elements - copied_file_name = g_strdup(split[0]); // Get the first element - } else { - gchar *new_parsed_name = ""; - for (guint i = 0; i < len_of_extension_split - 1; i++) { // Iterate over everything except the last item - if (g_strcmp0(new_parsed_name, "") == 0) { // Currently empty - new_parsed_name = g_strdup(split[i]); // Just duplicate this string - } else { - gchar *tmp_copy = g_strdup(new_parsed_name); - g_free(new_parsed_name); // Free the old - new_parsed_name = g_strdup(g_strjoin(".", tmp_copy, split[i], NULL)); // Join the two strings with a . again and duplicate it, setting it to our new_parsed_name - g_free(tmp_copy); // Free our temporary copy - } + if ((t_file != NULL) && taglib_file_is_valid(t_file)) { // If we got the taglib file and it is valid + self->acquired_metadata_from_id3 = TRUE; + TagLib_Tag *tag = taglib_file_tag(t_file); // Get our tag + koto_indexed_file_set_parsed_name(self, taglib_tag_title(tag)); // Set the title of the file + self->artist = g_strdup(taglib_tag_artist((tag))); // Set the artist + self->album = g_strdup(taglib_tag_album(tag)); // Set the album + koto_indexed_file_set_position(self, (uint) taglib_tag_track(tag)); // Get the track, convert to uint and cast as a pointer } - copied_file_name = g_strdup(new_parsed_name); - g_free(new_parsed_name); + taglib_tag_free_strings(); // Free strings + taglib_file_free(t_file); // Free the file +} + +void koto_indexed_file_update_path(KotoIndexedFile *self, const gchar *new_path) { + if (new_path == NULL) { + return; } - g_strfreev(split); + if (self->path != NULL) { // Already have a path + g_free(self->path); // Free it + } - koto_indexed_file_set_parsed_name(self, copied_file_name); - g_free(copied_file_name); + self->path = g_strdup(new_path); // Duplicate the path and set it + koto_indexed_file_update_metadata(self); // Attempt to get ID3 info + koto_indexed_file_set_file_name(self, g_path_get_basename(self->path)); // Update our file name + + g_object_notify_by_pspec(G_OBJECT(self), props[PROP_PATH]); } KotoIndexedFile* koto_indexed_file_new(const gchar *path) { diff --git a/src/indexer/file.h b/src/indexer/file.h index 669d9f4..4913a68 100644 --- a/src/indexer/file.h +++ b/src/indexer/file.h @@ -25,8 +25,11 @@ G_DECLARE_FINAL_TYPE(KotoIndexedFile, koto_indexed_file, KOTO, INDEXED_FILE, GOb KotoIndexedFile* koto_indexed_file_new(const gchar *path); +void koto_indexed_file_parse_name(KotoIndexedFile *self); void koto_indexed_file_set_file_name(KotoIndexedFile *self, gchar *new_file_name); void koto_indexed_file_set_parsed_name(KotoIndexedFile *self, gchar *new_parsed_name); -void koto_indexed_file_parse_name(KotoIndexedFile *self); +void koto_indexed_file_set_position(KotoIndexedFile *self, guint pos); +void koto_indexed_file_update_metadata(KotoIndexedFile *self); +void koto_indexed_file_update_path(KotoIndexedFile *self, const gchar *new_path); G_END_DECLS diff --git a/src/koto-utils.c b/src/koto-utils.c new file mode 100644 index 0000000..b0239c7 --- /dev/null +++ b/src/koto-utils.c @@ -0,0 +1,48 @@ +/* koto-utils.c + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +gchar* koto_utils_get_filename_without_extension(gchar *filename) { + gchar *trimmed_file_name = g_strdup(filename); + gchar **split = g_strsplit(filename, ".", -1); // Split every time we see . + g_free(trimmed_file_name); + guint len_of_extension_split = g_strv_length(split); + + if (len_of_extension_split == 2) { // Only have two elements + trimmed_file_name = g_strdup(split[0]); // Get the first element + } else { + gchar *new_parsed_name = ""; + for (guint i = 0; i < len_of_extension_split - 1; i++) { // Iterate over everything except the last item + if (g_strcmp0(new_parsed_name, "") == 0) { // Currently empty + new_parsed_name = g_strdup(split[i]); // Just duplicate this string + } else { + gchar *tmp_copy = g_strdup(new_parsed_name); + g_free(new_parsed_name); // Free the old + new_parsed_name = g_strdup(g_strjoin(".", tmp_copy, split[i], NULL)); // Join the two strings with a . again and duplicate it, setting it to our new_parsed_name + g_free(tmp_copy); // Free our temporary copy + } + } + + trimmed_file_name = g_strdup(new_parsed_name); + g_free(new_parsed_name); + } + + gchar *stripped_file_name = g_strstrip(trimmed_file_name); // Strip leading and trailing whitespace + g_free(trimmed_file_name); + return stripped_file_name; +} diff --git a/src/koto-utils.h b/src/koto-utils.h new file mode 100644 index 0000000..5d25b30 --- /dev/null +++ b/src/koto-utils.h @@ -0,0 +1,25 @@ +/* koto-utils.h + * + * Copyright 2021 Joshua Strobl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +G_BEGIN_DECLS + +gchar* koto_utils_get_filename_without_extension(gchar *filename); + +G_END_DECLS diff --git a/src/meson.build b/src/meson.build index b0b252b..a85ee0e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,4 +1,6 @@ koto_sources = [ + 'indexer/album.c', + 'indexer/artist.c', 'indexer/file.c', 'indexer/file-indexer.c', 'main.c', @@ -7,6 +9,7 @@ koto_sources = [ 'koto-headerbar.c', 'koto-nav.c', 'koto-playerbar.c', + 'koto-utils.c', 'koto-window.c', ] @@ -15,6 +18,7 @@ koto_deps = [ dependency('gio-2.0', version: '>= 2.66'), dependency('gtk+-3.0', version: '>= 3.24'), dependency('libmagic', version: '>=5.39'), + dependency('taglib_c', version: '>=1.11'), ] gnome = import('gnome') From 8948a8ec9f81c018ed04bc4f7eab6e6d5942cc65 Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Tue, 16 Feb 2021 23:18:23 +0200 Subject: [PATCH 09/83] Bump meson requirement to 0.57, drop most of postinstall for new gnome module functions --- build-aux/meson/postinstall.py | 7 ------- meson.build | 9 +++++++-- src/koto-window.h | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/build-aux/meson/postinstall.py b/build-aux/meson/postinstall.py index 6a3ea97..cfa1e2d 100755 --- a/build-aux/meson/postinstall.py +++ b/build-aux/meson/postinstall.py @@ -9,13 +9,6 @@ destdir = environ.get('DESTDIR', '') # Package managers set this so we don't need to run if not destdir: - print('Updating icon cache...') - call(['gtk-update-icon-cache', '-qtf', path.join(datadir, 'icons', 'hicolor')]) - print('Updating desktop database...') call(['update-desktop-database', '-q', path.join(datadir, 'applications')]) - print('Compiling GSettings schemas...') - call(['glib-compile-schemas', path.join(datadir, 'glib-2.0', 'schemas')]) - - diff --git a/meson.build b/meson.build index 5623ddf..0b6195d 100644 --- a/meson.build +++ b/meson.build @@ -1,12 +1,13 @@ project('koto', 'c', version: '0.1.0', - meson_version: '>= 0.50.0', + meson_version: '>= 0.57.0', default_options: [ 'warning_level=2', 'c_std=gnu11', ], ) i18n = import('i18n') +gnome = import('gnome') config_h = configuration_data() config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) @@ -17,11 +18,15 @@ configure_file( configuration: config_h, ) add_project_arguments([ - '-I' + meson.build_root(), + '-I' + meson.current_build_dir(), ], language: 'c') subdir('data') subdir('src') subdir('po') +gnome.post_install( + glib_compile_schemas: true, + gtk_update_icon_cache: true +) meson.add_install_script('build-aux/meson/postinstall.py') diff --git a/src/koto-window.h b/src/koto-window.h index bab11e8..e6aa68c 100644 --- a/src/koto-window.h +++ b/src/koto-window.h @@ -17,7 +17,7 @@ #pragma once -#include +#include G_BEGIN_DECLS From 588a68b2cc99d3f06589aa88f577d491989efd23 Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Wed, 24 Feb 2021 20:17:18 +0200 Subject: [PATCH 10/83] Port to GTK4, start implementation of Local Music view, Artist and Album Views. --- data/style.css | 16 ++ meson.build | 2 +- src/indexer/album.c | 2 +- src/indexer/file-indexer.c | 22 +- src/indexer/file-indexer.h | 1 + src/koto-button.c | 143 ++++++------ src/koto-button.h | 6 +- src/koto-expander.c | 37 ++-- src/koto-expander.h | 4 +- src/koto-headerbar.c | 45 ---- src/koto-headerbar.ui | 2 +- src/koto-nav.c | 71 +++--- src/koto-nav.h | 5 +- src/koto-playerbar.c | 92 ++++---- src/koto-playerbar.h | 5 +- src/koto-track-item.c | 120 +++++++++++ src/{koto-headerbar.h => koto-track-item.h} | 13 +- src/koto-utils.c | 22 +- src/koto-utils.h | 2 + src/koto-window.c | 78 +++++-- src/koto-window.h | 3 +- src/meson.build | 9 +- src/pages/music/album-view.c | 169 +++++++++++++++ src/pages/music/album-view.h | 36 ++++ src/pages/music/artist-view.c | 167 ++++++++++++++ src/pages/music/artist-view.h | 36 ++++ src/pages/music/music-local.c | 227 ++++++++++++++++++++ src/pages/music/music-local.h | 38 ++++ 28 files changed, 1103 insertions(+), 270 deletions(-) delete mode 100644 src/koto-headerbar.c create mode 100644 src/koto-track-item.c rename src/{koto-headerbar.h => koto-track-item.h} (62%) create mode 100644 src/pages/music/album-view.c create mode 100644 src/pages/music/album-view.h create mode 100644 src/pages/music/artist-view.c create mode 100644 src/pages/music/artist-view.h create mode 100644 src/pages/music/music-local.c create mode 100644 src/pages/music/music-local.h diff --git a/data/style.css b/data/style.css index 1e3d5d1..24b0cba 100644 --- a/data/style.css +++ b/data/style.css @@ -1,3 +1,11 @@ +window { + background-color: #2e2e2e; +} + +headerbar, .player-bar { + background-color: #1d1d1d; +} + .primary-nav > .frame > box >.koto-button > box { padding: 10px 0; } @@ -19,3 +27,11 @@ .expander-header label { font-size: large; } + +.page-music-local .artist-list { + background-color: #1d1d1d; +} + +.page-music-local row { + padding: 10px; +} diff --git a/meson.build b/meson.build index 0b6195d..ca1ee90 100644 --- a/meson.build +++ b/meson.build @@ -27,6 +27,6 @@ subdir('po') gnome.post_install( glib_compile_schemas: true, - gtk_update_icon_cache: true + gtk_update_icon_cache: false ) meson.add_install_script('build-aux/meson/postinstall.py') diff --git a/src/indexer/album.c b/src/indexer/album.c index 589c7eb..ec4104a 100644 --- a/src/indexer/album.c +++ b/src/indexer/album.c @@ -267,7 +267,7 @@ void koto_indexed_album_update_path(KotoIndexedAlbum *self, const gchar* new_pat g_free(album_art_no_ext); g_free(lower_art); - } else if (g_str_has_prefix(mime_type, "audio/")) { // Is an audio file + } else if (g_str_has_prefix(mime_type, "audio/") || g_str_has_prefix(mime_type, "video/ogg")) { // Is an audio file or ogg because it is special KotoIndexedFile *file = koto_indexed_file_new(full_path); if (file != NULL) { // Is a file diff --git a/src/indexer/file-indexer.c b/src/indexer/file-indexer.c index 7609485..e8ea155 100644 --- a/src/indexer/file-indexer.c +++ b/src/indexer/file-indexer.c @@ -72,9 +72,7 @@ void koto_indexed_library_add_artist(KotoIndexedLibrary *self, KotoIndexedArtist return; } - if (self->music_artists == NULL) { // Not a HashTable - self->music_artists = g_hash_table_new(g_str_hash, g_str_equal); - } + koto_indexed_library_get_artists(self); // Call to generate if needed gchar *artist_name; g_object_get(artist, "name", &artist_name, NULL); @@ -92,21 +90,25 @@ KotoIndexedArtist* koto_indexed_library_get_artist(KotoIndexedLibrary *self, gch return NULL; } - if (self->music_artists == NULL) { // Not a HashTable - return NULL; - } + koto_indexed_library_get_artists(self); // Call to generate if needed return g_hash_table_lookup(self->music_artists, (KotoIndexedArtist*) artist_name); } +GHashTable* koto_indexed_library_get_artists(KotoIndexedLibrary *self) { + if (self->music_artists == NULL) { // Not a HashTable + self->music_artists = g_hash_table_new(g_str_hash, g_str_equal); + } + + return self->music_artists; +} + void koto_indexed_library_remove_artist(KotoIndexedLibrary *self, KotoIndexedArtist *artist) { if (artist == NULL) { return; } - if (self->music_artists == NULL) { // Not a HashTable - return; - } + koto_indexed_library_get_artists(self); // Call to generate if needed gchar *artist_name; g_object_get(artist, "name", &artist_name, NULL); @@ -223,6 +225,8 @@ void index_folder(KotoIndexedLibrary *self, gchar *path, guint depth) { } void output_artists(gpointer artist_key, gpointer artist_ptr, gpointer data) { + (void)artist_key; + (void)data; KotoIndexedArtist *artist = (KotoIndexedArtist*) artist_ptr; gchar *artist_name; g_object_get(artist, "name", &artist_name, NULL); diff --git a/src/indexer/file-indexer.h b/src/indexer/file-indexer.h index 97b25cc..59af814 100644 --- a/src/indexer/file-indexer.h +++ b/src/indexer/file-indexer.h @@ -28,6 +28,7 @@ KotoIndexedLibrary* koto_indexed_library_new(const gchar *path); void koto_indexed_library_add_artist(KotoIndexedLibrary *self, KotoIndexedArtist *artist); KotoIndexedArtist* koto_indexed_library_get_artist(KotoIndexedLibrary *self, gchar* artist_name); +GHashTable* koto_indexed_library_get_artists(KotoIndexedLibrary *self); void koto_indexed_library_remove_artist(KotoIndexedLibrary *self, KotoIndexedArtist *artist); void start_indexing(KotoIndexedLibrary *self); void index_folder(KotoIndexedLibrary *self, gchar *path, guint depth); diff --git a/src/koto-button.c b/src/koto-button.c index 7067b9a..7af5dc7 100644 --- a/src/koto-button.c +++ b/src/koto-button.c @@ -15,7 +15,7 @@ * limitations under the License. */ -#include +#include #include "koto-button.h" #include "koto-config.h" @@ -51,10 +51,10 @@ guint koto_get_pixbuf_size(KotoButtonPixbufSize s) { enum { PROP_BTN_0, + PROP_USE_FROM_FILE, PROP_PIX_SIZE, PROP_TEXT, PROP_BADGE_TEXT, - PROP_PIX, PROP_ICON_NAME, PROP_ALT_ICON_NAME, N_BTN_PROPERTIES @@ -63,11 +63,10 @@ enum { static GParamSpec *btn_props[N_BTN_PROPERTIES] = { NULL, }; struct _KotoButton { - GtkEventBox parent_instance; - GtkBox *content; + GtkBox parent_instance; guint pix_size; - GtkWidget *button_image; + GtkWidget *button_pic; GtkWidget *badge_label; GtkWidget *button_label; @@ -76,7 +75,7 @@ struct _KotoButton { gchar *alt_icon_name; gchar *text; - GdkPixbuf *pix; + gboolean use_from_file; gboolean currently_showing_alt; }; @@ -84,17 +83,27 @@ struct _KotoButtonClass { GtkBoxClass parent_class; }; -G_DEFINE_TYPE(KotoButton, koto_button, GTK_TYPE_EVENT_BOX); +G_DEFINE_TYPE(KotoButton, koto_button, GTK_TYPE_BOX); +static void koto_button_constructed(GObject *obj); static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec); static void koto_button_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *spec); static void koto_button_class_init(KotoButtonClass *c) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS(c); + gobject_class->constructed = koto_button_constructed; gobject_class->set_property = koto_button_set_property; gobject_class->get_property = koto_button_get_property; + btn_props[PROP_USE_FROM_FILE] = g_param_spec_boolean( + "use-from-file", + "Use from a file / file name", + "Use from a file / file name", + FALSE, + G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE + ); + btn_props[PROP_PIX_SIZE] = g_param_spec_uint( "pixbuf-size", "Pixbuf Size", @@ -121,14 +130,6 @@ static void koto_button_class_init(KotoButtonClass *c) { G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE ); - btn_props[PROP_PIX] = g_param_spec_object( - "pixbuf", - "Pixbuf", - "Pixbuf", - GDK_TYPE_PIXBUF, - G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY|G_PARAM_READWRITE - ); - btn_props[PROP_ICON_NAME] = g_param_spec_string( "icon-name", "Icon Name", @@ -149,17 +150,24 @@ static void koto_button_class_init(KotoButtonClass *c) { } static void koto_button_init(KotoButton *self) { + self->currently_showing_alt = FALSE; +} + +static void koto_button_constructed(GObject *obj) { + KotoButton *self = KOTO_BUTTON(obj); GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(self)); gtk_style_context_add_class(style, "koto-button"); - self->currently_showing_alt = FALSE; - self->content = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)); - gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(self->content)); + + G_OBJECT_CLASS (koto_button_parent_class)->constructed (obj); } static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *spec) { KotoButton *self = KOTO_BUTTON(obj); switch (prop_id) { + case PROP_USE_FROM_FILE: + g_value_set_boolean(val, self->use_from_file); + break; case PROP_PIX_SIZE: g_value_set_uint(val, self->pix_size); break; @@ -175,9 +183,6 @@ static void koto_button_get_property(GObject *obj, guint prop_id, GValue *val, G case PROP_ALT_ICON_NAME: g_value_set_string(val, self->alt_icon_name); break; - case PROP_PIX: - g_value_set_object(val, self->pix); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, spec); break; @@ -188,18 +193,23 @@ static void koto_button_set_property(GObject *obj, guint prop_id, const GValue * KotoButton *self = KOTO_BUTTON(obj); switch (prop_id) { + case PROP_USE_FROM_FILE: + self->use_from_file = g_value_get_boolean(val); + break; case PROP_PIX_SIZE: koto_button_set_pixbuf_size(self, g_value_get_uint(val)); break; case PROP_TEXT: - koto_button_set_text(self, g_strdup(g_value_get_string(val))); + if (val == NULL) { + koto_button_set_text(self, NULL); + } else { + koto_button_set_text(self, g_strdup(g_value_get_string(val))); + } + break; case PROP_BADGE_TEXT: koto_button_set_badge_text(self, g_strdup(g_value_get_string(val))); break; - case PROP_PIX: - koto_button_set_pixbuf(self, (GdkPixbuf*) g_value_get_object(val)); - break; case PROP_ICON_NAME: koto_button_set_icon_name(self, g_strdup(g_value_get_string(val)), FALSE); if (!self->currently_showing_alt) { // Not showing alt @@ -234,7 +244,7 @@ void koto_button_set_badge_text(KotoButton *self, gchar *text) { gtk_label_set_text(GTK_LABEL(self->badge_label), self->badge_text); } else { self->badge_label = gtk_label_new(self->badge_text); // Create our label - gtk_box_pack_end(self->content, self->badge_label, FALSE, FALSE, 0); // Add to the end of the box + gtk_box_append(GTK_BOX(self), self->badge_label); } if (strcmp(self->badge_text, "") != 0) { // Empty badge @@ -271,8 +281,8 @@ void koto_button_set_icon_name(KotoButton *self, gchar *icon_name, gboolean for_ } if (hide_image) { // Should hide the image - if (GTK_IS_IMAGE(self->button_image)) { // If we already have a button image - gtk_widget_hide(self->button_image); // Hide + if (GTK_IS_PICTURE(self->button_pic)) { // If we already have a button image + gtk_widget_hide(self->button_pic); // Hide } return; @@ -281,48 +291,20 @@ void koto_button_set_icon_name(KotoButton *self, gchar *icon_name, gboolean for_ g_object_notify_by_pspec(G_OBJECT(self), for_alt ? btn_props[PROP_ALT_ICON_NAME] : btn_props[PROP_ICON_NAME]); } -void koto_button_set_pixbuf(KotoButton *self, GdkPixbuf *pix) { - g_return_if_fail(self->pix_size != 0); // Return if don't have a pixbuf size to indicate what to scale to - - if (!GDK_IS_PIXBUF(pix)) { - return; - } - - self->pix = pix; - - GdkPixbuf *use_pix = pix; // Default to using our provided pixbuf - if (gdk_pixbuf_get_height(pix) > (int) self->pix_size) { // If our height is greater than our desired pixel size - use_pix = gdk_pixbuf_scale_simple(pix, -1, self->pix_size, GDK_INTERP_BILINEAR); // Scale using bilnear - g_return_if_fail(use_pix != NULL); // Return if we could not allocate memory for the scaling - } - - if (GTK_IS_IMAGE(self->button_image)) { // If we already have a button image - gtk_image_set_from_pixbuf(GTK_IMAGE(self->button_image), use_pix); // Update our pixbuf - gtk_widget_show(self->button_image); // Ensure we show the image - } else { // No image set - GtkWidget *new_image = gtk_image_new_from_pixbuf(use_pix); // Create our new image - g_return_if_fail(GTK_IS_IMAGE(new_image)); // Return if we failed to create our image - self->button_image = new_image; - gtk_box_pack_start(self->content, self->button_image, FALSE, FALSE, 0); // Prepend the image - gtk_box_reorder_child(self->content, self->button_image, 0); - } - - g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_PIX]); -} - void koto_button_set_pixbuf_size(KotoButton *self, guint size) { g_return_if_fail(size != self->pix_size); // If the sizes aren't different, return self->pix_size = size; - - if (GDK_PIXBUF(self->pix)) { // If we already have a pixbuf set and we're changing the size - koto_button_set_pixbuf(self, self->pix); - } + gtk_widget_set_size_request(GTK_WIDGET(self), self->pix_size, self->pix_size); g_object_notify_by_pspec(G_OBJECT(self), btn_props[PROP_PIX_SIZE]); } void koto_button_set_text(KotoButton *self, gchar *text) { + if (text == NULL) { + return; + } + gchar *copied_text = g_strdup(text); // Copy our text if (strcmp(copied_text, "") == 0) { // Clearing our text @@ -336,17 +318,18 @@ void koto_button_set_text(KotoButton *self, gchar *text) { gtk_label_set_text(GTK_LABEL(self->button_label), self->text); gtk_widget_show(self->button_label); // Show the label } else { // Have a label but no longer text - gtk_container_remove(GTK_CONTAINER(self), self->button_label); // Remove the label + gtk_box_remove(GTK_BOX(self), self->button_label); g_free(self->button_label); } } else { // If we do not have a button label if (strcmp(self->text, "") != 0) { // If we have text self->button_label = gtk_label_new(self->text); // Create our label gtk_label_set_xalign(GTK_LABEL(self->button_label), 0); - gtk_box_pack_start(self->content, self->button_label, FALSE, FALSE, 0); // Add to the beginning of the box - if (GTK_IS_IMAGE(self->button_image)) { // If we have an image - gtk_box_reorder_child(self->content, self->button_image, 0); // Move to the beginning + if (GTK_IS_IMAGE(self->button_pic)) { // If we have an image + gtk_box_insert_child_after(GTK_BOX(self), self->button_label, self->button_pic); + } else { + gtk_box_prepend(GTK_BOX(self), GTK_WIDGET(self->button_label)); } } } @@ -361,11 +344,22 @@ void koto_button_show_image(KotoButton *self, gboolean use_alt) { return; } - GtkIconTheme *theme = gtk_icon_theme_get_default(); // Get the default icon theme - GdkPixbuf* icon_pix = gtk_icon_theme_load_icon_for_scale(theme, use_alt ? self->alt_icon_name : self->icon_name, (gint) self->pix_size, 1, GTK_ICON_LOOKUP_USE_BUILTIN & GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); - g_return_if_fail(GDK_IS_PIXBUF(icon_pix)); // Return if not a pixbuf - koto_button_set_pixbuf(self, icon_pix); - self->currently_showing_alt = use_alt; + if (self->use_from_file) { // Use from a file instead of icon name + // TODO: Add + } else { // From icon name + self->currently_showing_alt = use_alt; + gchar *name = use_alt ? self->alt_icon_name : self->icon_name; + + if (GTK_IS_IMAGE(self->button_pic)) { + gtk_image_set_from_icon_name(GTK_IMAGE(self->button_pic), name); // Just update the existing iamge + } else { // Not an image + self->button_pic = gtk_image_new_from_icon_name(name); // Get our new image + gtk_image_set_pixel_size(GTK_IMAGE(self->button_pic), self->pix_size); + gtk_box_prepend(GTK_BOX(self), self->button_pic); // Prepend to the box + } + + gtk_image_set_icon_size(GTK_IMAGE(self->button_pic), GTK_ICON_SIZE_INHERIT); // Inherit height of parent widget + } } KotoButton* koto_button_new_plain(gchar *label) { @@ -384,12 +378,3 @@ KotoButton* koto_button_new_with_icon(gchar *label, gchar *icon_name, gchar *alt NULL ); } - -KotoButton* koto_button_new_with_pixbuf(gchar *label, GdkPixbuf *pix, KotoButtonPixbufSize size) { - return g_object_new(KOTO_TYPE_BUTTON, - "button-text", label, - "pixbuf", pix, - "pixbuf-size", koto_get_pixbuf_size(size), - NULL - ); -} diff --git a/src/koto-button.h b/src/koto-button.h index c267247..d839709 100644 --- a/src/koto-button.h +++ b/src/koto-button.h @@ -17,9 +17,9 @@ #pragma once -#include +#include #include -#include +#include G_BEGIN_DECLS @@ -37,7 +37,7 @@ typedef enum { #define KOTO_TYPE_BUTTON (koto_button_get_type()) -G_DECLARE_FINAL_TYPE (KotoButton, koto_button, KOTO, BUTTON, GtkEventBox) +G_DECLARE_FINAL_TYPE (KotoButton, koto_button, KOTO, BUTTON, GtkBox) guint koto_get_pixbuf_size(KotoButtonPixbufSize size); diff --git a/src/koto-expander.c b/src/koto-expander.c index 639da81..1201137 100644 --- a/src/koto-expander.c +++ b/src/koto-expander.c @@ -16,7 +16,7 @@ */ #include -#include +#include #include "koto-config.h" #include "koto-button.h" #include "koto-expander.h" @@ -128,7 +128,8 @@ static void koto_expander_set_property(GObject *obj, guint prop_id, const GValue if (GTK_IS_WIDGET(new_button)) { // Created our widget successfully self->header_button = new_button; - gtk_box_pack_start(GTK_BOX(self->header), GTK_WIDGET(self->header_button), TRUE, TRUE, 0); // Add it + gtk_widget_set_hexpand(GTK_WIDGET(self->header_button), TRUE); + gtk_box_prepend(GTK_BOX(self->header), GTK_WIDGET(self->header_button)); } } @@ -154,11 +155,9 @@ static void koto_expander_set_property(GObject *obj, guint prop_id, const GValue } static void koto_expander_init(KotoExpander *self) { - GtkSettings *settings = gtk_settings_get_default(); - g_object_set(settings, "gtk_application_prefer_dark_theme", TRUE, NULL); - GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(self)); gtk_style_context_add_class(style, "expander"); + gtk_widget_set_hexpand((GTK_WIDGET(self)), TRUE); self->header = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); @@ -170,14 +169,16 @@ static void koto_expander_init(KotoExpander *self) { gtk_revealer_set_transition_type(GTK_REVEALER(self->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); self->header_expand_button = koto_button_new_with_icon("", "pan-down-symbolic", "pan-up-symbolic", KOTO_BUTTON_PIXBUF_SIZE_SMALL); - gtk_box_pack_end(GTK_BOX(self->header), GTK_WIDGET(self->header_expand_button), FALSE, FALSE, 0); + gtk_box_append(GTK_BOX(self->header), GTK_WIDGET(self->header_expand_button)); - gtk_box_pack_start(GTK_BOX(self), self->header, FALSE, FALSE, 0); - gtk_box_pack_end(GTK_BOX(self), self->revealer, TRUE, TRUE, 0); + gtk_box_prepend(GTK_BOX(self), self->header); + gtk_box_append(GTK_BOX(self), self->revealer); self->constructed = TRUE; - g_signal_connect(self->header_expand_button, "button-release-event", G_CALLBACK(koto_expander_toggle_content), self); + GtkGesture *controller = gtk_gesture_click_new(); // Create a new GtkGestureClick + g_signal_connect(controller, "pressed", G_CALLBACK(koto_expander_toggle_content), self); + gtk_widget_add_controller(GTK_WIDGET(self->header_expand_button), GTK_EVENT_CONTROLLER(controller)); } void koto_expander_set_secondary_button(KotoExpander *self, KotoButton *new_button) { @@ -190,11 +191,11 @@ void koto_expander_set_secondary_button(KotoExpander *self, KotoButton *new_butt } if (GTK_IS_WIDGET(self->header_secondary_button)) { // Already have a button - gtk_container_remove(GTK_CONTAINER(self->header), GTK_WIDGET(self->header_secondary_button)); + gtk_box_remove(GTK_BOX(self->header), GTK_WIDGET(self->header_secondary_button)); } self->header_secondary_button = new_button; - gtk_box_pack_end(GTK_BOX(self->header), GTK_WIDGET(self->header_secondary_button), FALSE, FALSE, 0); + gtk_box_append(GTK_BOX(self->header), GTK_WIDGET(self->header_secondary_button)); g_object_notify_by_pspec(G_OBJECT(self), expander_props[PROP_HEADER_SECONDARY_BUTTON]); } @@ -204,20 +205,22 @@ void koto_expander_set_content(KotoExpander *self, GtkWidget *new_content) { return; } - if (self->content != NULL) { // Already have content - gtk_container_remove(GTK_CONTAINER(self->revealer), self->content); - g_free(self->content); + if (GTK_IS_WIDGET(self->content)) { // Already have content + gtk_revealer_set_child(GTK_REVEALER(self->revealer), NULL); + g_object_unref(self->content); } self->content = new_content; - gtk_container_add(GTK_CONTAINER(self->revealer), self->content); + gtk_revealer_set_child(GTK_REVEALER(self->revealer), self->content); g_object_notify_by_pspec(G_OBJECT(self), expander_props[PROP_CONTENT]); } -void koto_expander_toggle_content(GtkWidget *button, GdkEvent *event, gpointer data) { +void koto_expander_toggle_content(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data) { + (void) gesture; (void) n_press; (void) x; (void) y; KotoExpander* self = data; - koto_button_flip(KOTO_BUTTON(button)); + + koto_button_flip(KOTO_BUTTON(self->header_expand_button)); GtkRevealer* rev = GTK_REVEALER(self->revealer); gtk_revealer_set_reveal_child(rev, !gtk_revealer_get_reveal_child(rev)); // Invert our values } diff --git a/src/koto-expander.h b/src/koto-expander.h index 6d82a94..680c9f1 100644 --- a/src/koto-expander.h +++ b/src/koto-expander.h @@ -17,7 +17,7 @@ #pragma once -#include +#include #include "koto-button.h" G_BEGIN_DECLS @@ -32,6 +32,6 @@ void koto_expander_set_icon_name(KotoExpander *self, const gchar *in); void koto_expander_set_label(KotoExpander *self, const gchar *label); void koto_expander_set_secondary_button(KotoExpander *self, KotoButton *new_button); void koto_expander_set_content(KotoExpander *self, GtkWidget *new_content); -void koto_expander_toggle_content(GtkWidget *button, GdkEvent *event, gpointer data); +void koto_expander_toggle_content(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data); G_END_DECLS diff --git a/src/koto-headerbar.c b/src/koto-headerbar.c deleted file mode 100644 index 64dab78..0000000 --- a/src/koto-headerbar.c +++ /dev/null @@ -1,45 +0,0 @@ -/* koto-headerbar.c - * - * Copyright 2021 Joshua Strobl - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "koto-config.h" -#include "koto-headerbar.h" - -struct _KotoHeaderBar { - GtkHeaderBar parent_instance; - GtkButton *menu_button; - GtkWidget *search; -}; - -struct _KotoHeaderBarClass { - GtkHeaderBarClass parent_class; -}; - -G_DEFINE_TYPE(KotoHeaderBar, koto_headerbar, GTK_TYPE_HEADER_BAR) - -static void koto_headerbar_class_init(KotoHeaderBarClass *c) { - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(c); - gtk_widget_class_set_template_from_resource(widget_class, "/com/github/joshstrobl/koto/koto-headerbar.ui"); -} - -static void koto_headerbar_init(KotoHeaderBar *self) { - gtk_widget_init_template(GTK_WIDGET(self)); - gtk_widget_show_all(GTK_WIDGET(self)); -} - -KotoHeaderBar* koto_headerbar_new(void) { - return g_object_new(KOTO_TYPE_HEADERBAR, NULL); -} diff --git a/src/koto-headerbar.ui b/src/koto-headerbar.ui index 03384fe..43244f9 100644 --- a/src/koto-headerbar.ui +++ b/src/koto-headerbar.ui @@ -7,7 +7,7 @@ audio-headphones 3 -