commit 3ed6d78f758318060759420b5465d707a69da124 Author: Luis Ãngel San Martín Date: Sat Jul 18 10:54:14 2015 +0200 fixed compilation for Qt5.5 in OSX diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 00000000..51e0b35c --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,149 @@ +8.0.0 +Reading lists +Tags +'Favorites' and 'being read' lists +New search engine, now you can filter folders and comics +New grid view +Add and delete folders +Update a single folder (no need for updating the whole library to rescan a single folder) +Drag and drop for adding new comics and folders +Customizable shorcuts +Manga mode (thank you Felix) +Spread page detection for double page mode (including manga mode)(thank you again Felix :) ) +New view for folders not containing comics (only subfolders) +Save selected covers to disk +Comics in Reading Lists and Tags can be sorted by drag&drop +Sublist in Reading Lists can by sorted by drag&drop +Added WebP image format support +The user has to provide its own Comic Vine API key to prevent usage limit errors from Comic Vine +New unarr decompression backend for Linux and Unix systems +Fixed memory and filedescriptor leaks in 7zip wrapper +Dropped support for Qt4 +Lots of smaller bugfixes + +7.2.0 +Added support for the new "remote read" feature in iOS devices. +Improved stability +Fixed broken compatibility with Windows XP +Improved Linux "packageability" (thanks to Felix, Alexander and Yoann)** +German translation (thanks to Gerhard Joeken) +Bug fixes. + +7.1.0 +Añadida opción para resetear el rating de un comics +Corregidos bugs que afectaban a la información de página. +Corregido error que marcaba un comic terminado como empezado si se volvía a leer. +Añadidos 2 estados para las carpetas (Completo/Terminado) +Corregido bug en la comunicación YACReaderLibrary <-> YACReader +Añadidas las acciones relativas a los comics al menú contextual de la tabla de cómics. +Corrgido bug que provocaba el crecimiento ilimatado del log del servidor +Corregidos bugs menores + +7.0.2 (Sólo MacOSX) +Eliminado el uso de Poppler en la versión de MacOSX +Trabajo en traducciones. +Corregidos bugs menores + +7.0.1 +Añadido QsLog a YACReader +Corregido bug en la comunicación YACReaderLibrary <-> YACReader + +7.0 (Final) +Corregidos eventos de teclado en algunos diálogos +Corregido soporte para archivos Rar en sistemas Unix +Corregidos problemas borrando cómics +Mejorada la gestión de errores +Corregida la comunicación entre YACReader y YACReaderLibrary +Corregida la toolBar en MacOSX +Mejorada la compatabilidad de OpenGL en tarjetas NVIDIA +Corregidos bugs menores + +6.9 (No pública) +Añadida la apertura automática del siguiente/anterior cómic al llegar al final/portada del cómic actual +Corregido el comportamiento del diálogo de nueva versión detectada. Ahora avisa una vez al día o si el usuario lo elige cada 14 días. +Corregido el ajuste a lo ancho del título de la toolbar en YACReaderLibrary. +Añadido log a YACReaderLibrary (permitirá a los usuarios ofrecer más información sobre sus bugs) +Corregido bug en el historial de navegación (y al editar comics) después de usar el motor de búsqueda. + +6.8 (No pública) +Corregido bug que causaba un cierre inesperado después de cambiar el modo de sincronización vertical (flow) +Corregido bug que causaba que la toolbar en el visor no se pudiese ocultar/mostrar sin un cómic abierto +Mejorada la gestión de errores al abrir cómics +Corregidos algunos bugs relacionados con la apertura de cómics +Añadida función de rating +El visor ahora puede abrir archivos de imagen directamente. Si se abre un archivo de imagen se abre el directorio que lo contiene con todas las imágenes. +Corregida la ordenación de carpetas y cómics usada en la navegación desde dispositivos iOS + +6.7 (No pública) +Añadidos nuevos campos en la base de datos para almacenar información adicional sobre cómics: rating, página actual, bookmarks y configuración de imagen +Añadida comunicación entre YACReaderLibrary y YACReader para poder almacenar el progreso de los cómics e información adicional + +6.6 (No pública) +Modificado YACReader para que abra los archivos comprimidos usando 7z.dll (.so, .dylib) +YACReader abre ahora los cómics por la última página leída. +Corregido bug que causaba que algunos cómics no se pudiesen abrir desde YACReaderLibrary en YACReader +Corregido el modo en el que se actualizaba la "information label" + +6.5 +Nueva interfaz principal de YACReaderLibrary y YACReader +Corregido bug que causaba que el servidor no se activase en el primer arranque en MacOSX +Corregido bug que causaba un fallo al cerrar YACReaderLibrary cada vez que se usaba el servidor +Nuevo diseño para el diálogo de propiedades de los cómics. +Añadida navegación alante y atrás de las carpetas visitadas. +La edición del nombre de una biblioteca no fuerza ahora que se recargue la biblioteca +Corregido el color de fondo en la lupa +Nuevo botón para ajustar a lo alto +Eliminada la opción always on top +Mostrar en carpeta contenedora arreglado en Windows y MacOSX + +6.4 (No pública) +Normalizado el renderizado de páginas en modo doble página +Añadida la función de borrar cómics desde el disco duro +Nuevos iconos de la barra de herramientas de cómics + +6.3 (No pública) +Mejorada la gestión de errores relacionada con las bibliotecas +Añadido botón que permite ocultar las portadas en la pantalla de importación +Añadidos títulos "Bibliotecas" y "Carpetas" a la barra de navegación +Nuevos iconos para seleccionar la carpeta raíz, expandir y contraer todos. +Botón para cambiar el puerto del servidor por el usuario. +Ahora las columnas de la lista de cómics pueden reordenarse +Ahora YACReaderLibrary sólo permite una instancia ejecutandose. +Columna leído añadida. +Cambiado estilo de la lista de cómics +Corregidos bugs relacionados con realizar operaciones sobre cómics cuando no había ninguno seleccionado en la lista de cómics + +6.2 +Nueva ventana de "bienvenida" +Nueva ventana de importar/actualizar +Nuevo control para la búsqueda +Nueva imagen para las marcas de cómics leídos (sólo en OpenGL) +Cambiada la distribución de algunos iconos +Cambiado el modo de eliminar la metainformación (borrar base de datos/portadas de disco) +Ocultadas las opciones avanzadas de configuración de YACReader Flow, accesibles ahora tras pulsar un botón (diálogos de configuración más simples) + +6.0.1 (No pública) +Corregido bug al usar las teclas Inicio/fin +Corregido bug que al arrancar YACReaderLibrary por primera vez causaba que no se mostrasen las portadas (sólo bajo ciertas circunstancias) +Añadidos algunos atajos de teclado a YACReaderLibrary a los ya existentes + +6.0 + +Mejorada la velocidad de inicio gracias al uso de /LTCG como opción de compilación +Corregido bug relacionado con OpenGL que causaba consumo excesivo de CPU en tarjetas NVidia +Añadidos iconos para cada tipo de archivo soportado en YACReaderLibrary +Cambiado el icono "folder" en YACReaderLibrary +Añadida barra para ajustar el ancho de página en la toolbar de YACReader +Añadido widget para la information label +Añadido nuevo estilo visual a goToFlow +Añadidos filtros para controlar el brillo, el contraste y el valor gamma +Añadidas notificaciones de portada y última página +InformationLabel se muestra ahora en la esquina superiror derecha. +InformationLabel se muestra en 3 tamaños diferentes en función de la resolución +Corregido bug que causaba que las marcas de cómic leído no se dibujasen adecuadamente. +Se recuerda si se debe mostrar o no la "label" información. +Corregido bug que provocaba el fallo de YACReader al pasar muy rápido las páginas. +Añadida columna "Tamaño" a la lista de cómics en YACReaderLibrary +Añadida la ordinación "natural" de los comics que hay en directorio del cómic actual. +Corregido bug que causaba que se abriese el cómic erroneo en YACReaderLibrary. +Cambiado el modo en el que se cargan los lenguages, ahora se pueden añadir traducciones sin necesidad de recompilar. \ No newline at end of file diff --git a/COPYING.txt b/COPYING.txt new file mode 100644 index 00000000..94a9ed02 --- /dev/null +++ b/COPYING.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/INSTALL.txt b/INSTALL.txt new file mode 100644 index 00000000..3863450e --- /dev/null +++ b/INSTALL.txt @@ -0,0 +1,75 @@ +COMPILATION GUIDE FOR LINUX/UNIX USERS +********************************** +YACReader and YACReaderLibrary are build using qmake. To build and install the program, run: + +qmake-qt5 CONFIG+=[Options] +make +make install + +from the source dir. For seperate builds of YACReader or YACReaderLibrary, enter their respective subfolders and run the commands from there. + +Dependencies: +----------------------- + +- Qt >= 5.3 with the following modules: + - declarative + - sql + - script + - multimedia + - imageformats + - opengl + - sql-sqlite + +- poppler-qt5 +- qrencode +- sqllite +- glu +- a decompression backend, either 7zip or unarr (see below) + + +Decompression backend: +--------------------------------------- + +YACReader supports two decompression backends: + +- unarr +- p7zip=9.20.1 + +These can be selected at build time by adding either CONFIG+=unarr or CONFIG+=7zip as an option when running qmake. +If none of these is provided, the build system will default to unarr on Linux/Unix and [p]7zip on Windows and OS X. + +The decompression backends have their own dependencies and require additional steps like downloading additional source code +for setup. Please consult the README files provided in the compressed_archive and compressed_archive/unarr folders for details. + +If you chose to build YACReader with p7zip as a backend on Linux/Unix, please take notice that this backend has some problems: + +- p7zip > 9.20.1 is not supported +- p7zip 9.20.1 has known bugs that are fixed only in the later versions +- a system update that replaces p7zip 9.20.1 with a later version will make YACReader unusable + +If your system already ships with p7zip > 9.20.1 you can place 7z.so and the Codecs folder with the Rar29.so from p7zip 9.20.1 in /usr/lib/yacreader +YACReader will check this folder first and can thus continue using 7zip as a backend with p7zip > 9.20.1 installed on your system. + +Other build options: +--------------------- + +You can adjust the installation prefix as well als the path make install uses to install the files. +Use "qmake PREFIX=DIR" to configure YACReader for your systems default prefix (for example "/", "/usr", "/usr/local"). + +For packaging purposes, you can use "make install INSTALL_ROOT=DIR" to install to a different location than the prefix. + +Default values: + +PREFIX=/usr +INSTALL_ROOT="" + +On embedded devices that don't support desktop OpenGL, it is recommended to use the no_opengl config option: + +qmake CONFIG+=no_opengl + +This will remove any dependency on desktop OpenGL and hardlock rendering to software. + + +DO YOU WANT TO HELP YACREADER? +****************************** +If you have experience creating packages, please help to create a package for your favourite Linux distro! Send me an e-mail to: info@yacreader.com diff --git a/QsLog/QsLog.cpp b/QsLog/QsLog.cpp new file mode 100644 index 00000000..7eafd151 --- /dev/null +++ b/QsLog/QsLog.cpp @@ -0,0 +1,249 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "QsLog.h" +#include "QsLogDest.h" +#ifdef QS_LOG_SEPARATE_THREAD +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include + +namespace QsLogging +{ +typedef QVector DestinationList; + +static const char TraceString[] = "TRACE"; +static const char DebugString[] = "DEBUG"; +static const char InfoString[] = "INFO "; +static const char WarnString[] = "WARN "; +static const char ErrorString[] = "ERROR"; +static const char FatalString[] = "FATAL"; + +// not using Qt::ISODate because we need the milliseconds too +static const QString fmtDateTime("yyyy-MM-ddThh:mm:ss.zzz"); + +static Logger* sInstance = 0; + +static const char* LevelToText(Level theLevel) +{ + switch (theLevel) { + case TraceLevel: + return TraceString; + case DebugLevel: + return DebugString; + case InfoLevel: + return InfoString; + case WarnLevel: + return WarnString; + case ErrorLevel: + return ErrorString; + case FatalLevel: + return FatalString; + case OffLevel: + return ""; + default: { + assert(!"bad log level"); + return InfoString; + } + } +} + +#ifdef QS_LOG_SEPARATE_THREAD +class LogWriterRunnable : public QRunnable +{ +public: + LogWriterRunnable(QString message, Level level); + virtual void run(); + +private: + QString mMessage; + Level mLevel; +}; +#endif + +class LoggerImpl +{ +public: + LoggerImpl(); + +#ifdef QS_LOG_SEPARATE_THREAD + QThreadPool threadPool; +#endif + QMutex logMutex; + Level level; + DestinationList destList; +}; + +#ifdef QS_LOG_SEPARATE_THREAD +LogWriterRunnable::LogWriterRunnable(QString message, Level level) + : QRunnable() + , mMessage(message) + , mLevel(level) +{ +} + +void LogWriterRunnable::run() +{ + Logger::instance().write(mMessage, mLevel); +} +#endif + + +LoggerImpl::LoggerImpl() + : level(InfoLevel) +{ + // assume at least file + console + destList.reserve(2); +#ifdef QS_LOG_SEPARATE_THREAD + threadPool.setMaxThreadCount(1); + threadPool.setExpiryTimeout(-1); +#endif +} + + +Logger::Logger() + : d(new LoggerImpl) +{ +} + +Logger& Logger::instance() +{ + if (!sInstance) + sInstance = new Logger; + + return *sInstance; +} + +void Logger::destroyInstance() +{ + delete sInstance; + sInstance = 0; +} + +// tries to extract the level from a string log message. If available, conversionSucceeded will +// contain the conversion result. +Level Logger::levelFromLogMessage(const QString& logMessage, bool* conversionSucceeded) +{ + if (conversionSucceeded) + *conversionSucceeded = true; + + if (logMessage.startsWith(QLatin1String(TraceString))) + return TraceLevel; + if (logMessage.startsWith(QLatin1String(DebugString))) + return DebugLevel; + if (logMessage.startsWith(QLatin1String(InfoString))) + return InfoLevel; + if (logMessage.startsWith(QLatin1String(WarnString))) + return WarnLevel; + if (logMessage.startsWith(QLatin1String(ErrorString))) + return ErrorLevel; + if (logMessage.startsWith(QLatin1String(FatalString))) + return FatalLevel; + + if (conversionSucceeded) + *conversionSucceeded = false; + return OffLevel; +} + +Logger::~Logger() +{ +#ifdef QS_LOG_SEPARATE_THREAD + d->threadPool.waitForDone(); +#endif + delete d; + d = 0; +} + +void Logger::addDestination(DestinationPtr destination) +{ + assert(destination.data()); + d->destList.push_back(destination); +} + +void Logger::setLoggingLevel(Level newLevel) +{ + d->level = newLevel; +} + +Level Logger::loggingLevel() const +{ + return d->level; +} + +//! creates the complete log message and passes it to the logger +void Logger::Helper::writeToLog() +{ + const char* const levelName = LevelToText(level); + const QString completeMessage(QString("%1 %2 %3") + .arg(levelName) + .arg(QDateTime::currentDateTime().toString(fmtDateTime)) + .arg(buffer) + ); + + Logger::instance().enqueueWrite(completeMessage, level); +} + +Logger::Helper::~Helper() +{ + try { + writeToLog(); + } + catch(std::exception&) { + // you shouldn't throw exceptions from a sink + assert(!"exception in logger helper destructor"); + throw; + } +} + +//! directs the message to the task queue or writes it directly +void Logger::enqueueWrite(const QString& message, Level level) +{ +#ifdef QS_LOG_SEPARATE_THREAD + LogWriterRunnable *r = new LogWriterRunnable(message, level); + d->threadPool.start(r); +#else + write(message, level); +#endif +} + +//! Sends the message to all the destinations. The level for this message is passed in case +//! it's useful for processing in the destination. +void Logger::write(const QString& message, Level level) +{ + QMutexLocker lock(&d->logMutex); + for (DestinationList::iterator it = d->destList.begin(), + endIt = d->destList.end();it != endIt;++it) { + (*it)->write(message, level); + } +} + +} // end namespace diff --git a/QsLog/QsLog.h b/QsLog/QsLog.h new file mode 100644 index 00000000..f72e827c --- /dev/null +++ b/QsLog/QsLog.h @@ -0,0 +1,137 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef QSLOG_H +#define QSLOG_H + +#include "QsLogLevel.h" +#include "QsLogDest.h" +#include +#include + +#define QS_LOG_VERSION "2.0b3" + +namespace QsLogging +{ +class Destination; +class LoggerImpl; // d pointer + +class QSLOG_SHARED_OBJECT Logger +{ +public: + static Logger& instance(); + static void destroyInstance(); + static Level levelFromLogMessage(const QString& logMessage, bool* conversionSucceeded = 0); + + ~Logger(); + + //! Adds a log message destination. Don't add null destinations. + void addDestination(DestinationPtr destination); + //! Logging at a level < 'newLevel' will be ignored + void setLoggingLevel(Level newLevel); + //! The default level is INFO + Level loggingLevel() const; + + //! The helper forwards the streaming to QDebug and builds the final + //! log message. + class QSLOG_SHARED_OBJECT Helper + { + public: + explicit Helper(Level logLevel) : + level(logLevel), + qtDebug(&buffer) {} + ~Helper(); + QDebug& stream(){ return qtDebug; } + + private: + void writeToLog(); + + Level level; + QString buffer; + QDebug qtDebug; + }; + +private: + Logger(); + Logger(const Logger&); // not available + Logger& operator=(const Logger&); // not available + + void enqueueWrite(const QString& message, Level level); + void write(const QString& message, Level level); + + LoggerImpl* d; + + friend class LogWriterRunnable; +}; + +} // end namespace + +//! Logging macros: define QS_LOG_LINE_NUMBERS to get the file and line number +//! in the log output. +#ifndef QS_LOG_LINE_NUMBERS +#define QLOG_TRACE() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() +#define QLOG_DEBUG() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() +#define QLOG_INFO() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() +#define QLOG_WARN() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() +#define QLOG_ERROR() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() +#define QLOG_FATAL() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() +#else +#define QLOG_TRACE() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_DEBUG() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_INFO() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_WARN() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_ERROR() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_FATAL() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << __FILE__ << '@' << __LINE__ +#endif + +#ifdef QS_LOG_DISABLE +#include "QsLogDisableForThisFile.h" +#endif + +#endif // QSLOG_H diff --git a/QsLog/QsLog.pri b/QsLog/QsLog.pri new file mode 100644 index 00000000..4afc6b47 --- /dev/null +++ b/QsLog/QsLog.pri @@ -0,0 +1,22 @@ +INCLUDEPATH += $$PWD +#DEFINES += QS_LOG_LINE_NUMBERS # automatically writes the file and line for each log message +#DEFINES += QS_LOG_DISABLE # logging code is replaced with a no-op +#DEFINES += QS_LOG_SEPARATE_THREAD # messages are queued and written from a separate thread +SOURCES += $$PWD/QsLogDest.cpp \ + $$PWD/QsLog.cpp \ + $$PWD/QsLogDestConsole.cpp \ + $$PWD/QsLogDestFile.cpp \ + $$PWD/QsLogDestFunctor.cpp + +HEADERS += $$PWD/QSLogDest.h \ + $$PWD/QsLog.h \ + $$PWD/QsLogDestConsole.h \ + $$PWD/QsLogLevel.h \ + $$PWD/QsLogDestFile.h \ + $$PWD/QsLogDisableForThisFile.h \ + $$PWD/QsLogDestFunctor.h + +OTHER_FILES += \ + $$PWD/QsLogChanges.txt \ + $$PWD/QsLogReadme.txt \ + $$PWD/LICENSE.txt diff --git a/QsLog/QsLogDest.cpp b/QsLog/QsLogDest.cpp new file mode 100644 index 00000000..ae9f44bc --- /dev/null +++ b/QsLog/QsLogDest.cpp @@ -0,0 +1,70 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "QsLogDest.h" +#include "QsLogDestConsole.h" +#include "QsLogDestFile.h" +#include "QsLogDestFunctor.h" +#include + +namespace QsLogging +{ + +Destination::~Destination() +{ +} + +//! destination factory +DestinationPtr DestinationFactory::MakeFileDestination(const QString& filePath, + LogRotationOption rotation, const MaxSizeBytes &sizeInBytesToRotateAfter, + const MaxOldLogCount &oldLogsToKeep) +{ + if (EnableLogRotation == rotation) { + QScopedPointer logRotation(new SizeRotationStrategy); + logRotation->setMaximumSizeInBytes(sizeInBytesToRotateAfter.size); + logRotation->setBackupCount(oldLogsToKeep.count); + + return DestinationPtr(new FileDestination(filePath, RotationStrategyPtr(logRotation.take()))); + } + + return DestinationPtr(new FileDestination(filePath, RotationStrategyPtr(new NullRotationStrategy))); +} + +DestinationPtr DestinationFactory::MakeDebugOutputDestination() +{ + return DestinationPtr(new DebugOutputDestination); +} + +DestinationPtr DestinationFactory::MakeFunctorDestination(QsLogging::Destination::LogFunction f) +{ + return DestinationPtr(new FunctorDestination(f)); +} + +DestinationPtr DestinationFactory::MakeFunctorDestination(QObject *receiver, const char *member) +{ + return DestinationPtr(new FunctorDestination(receiver, member)); +} + +} // end namespace diff --git a/QsLog/QsLogDest.h b/QsLog/QsLogDest.h new file mode 100644 index 00000000..a404487b --- /dev/null +++ b/QsLog/QsLogDest.h @@ -0,0 +1,99 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef QSLOGDEST_H +#define QSLOGDEST_H + +#include "QsLogLevel.h" +#include +#include +class QString; +class QObject; + +#ifdef QSLOG_IS_SHARED_LIBRARY +#define QSLOG_SHARED_OBJECT Q_DECL_EXPORT +#elif QSLOG_IS_SHARED_LIBRARY_IMPORT +#define QSLOG_SHARED_OBJECT Q_DECL_IMPORT +#else +#define QSLOG_SHARED_OBJECT +#endif + +namespace QsLogging +{ + +class QSLOG_SHARED_OBJECT Destination +{ +public: + typedef void (*LogFunction)(const QString &message, Level level); + +public: + virtual ~Destination(); + virtual void write(const QString& message, Level level) = 0; + virtual bool isValid() = 0; // returns whether the destination was created correctly +}; +typedef QSharedPointer DestinationPtr; + + +// a series of "named" paramaters, to make the file destination creation more readable +enum LogRotationOption +{ + DisableLogRotation = 0, + EnableLogRotation = 1 +}; + +struct QSLOG_SHARED_OBJECT MaxSizeBytes +{ + MaxSizeBytes() : size(0) {} + explicit MaxSizeBytes(qint64 size_) : size(size_) {} + qint64 size; +}; + +struct QSLOG_SHARED_OBJECT MaxOldLogCount +{ + MaxOldLogCount() : count(0) {} + explicit MaxOldLogCount(int count_) : count(count_) {} + int count; +}; + + +//! Creates logging destinations/sinks. The caller shares ownership of the destinations with the logger. +//! After being added to a logger, the caller can discard the pointers. +class QSLOG_SHARED_OBJECT DestinationFactory +{ +public: + static DestinationPtr MakeFileDestination(const QString& filePath, + LogRotationOption rotation = DisableLogRotation, + const MaxSizeBytes &sizeInBytesToRotateAfter = MaxSizeBytes(), + const MaxOldLogCount &oldLogsToKeep = MaxOldLogCount()); + static DestinationPtr MakeDebugOutputDestination(); + // takes a pointer to a function + static DestinationPtr MakeFunctorDestination(Destination::LogFunction f); + // takes a QObject + signal/slot + static DestinationPtr MakeFunctorDestination(QObject *receiver, const char *member); +}; + +} // end namespace + +#endif // QSLOGDEST_H diff --git a/QsLog/QsLogDestConsole.cpp b/QsLog/QsLogDestConsole.cpp new file mode 100644 index 00000000..ed7fc53b --- /dev/null +++ b/QsLog/QsLogDestConsole.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "QsLogDestConsole.h" +#include +#include + +#if defined(Q_OS_WIN) +#define WIN32_LEAN_AND_MEAN +#include +void QsDebugOutput::output( const QString& message ) +{ + OutputDebugStringW(reinterpret_cast(message.utf16())); + OutputDebugStringW(L"\n"); +} +#elif defined(Q_OS_UNIX) +#include +void QsDebugOutput::output( const QString& message ) +{ + fprintf(stderr, "%s\n", qPrintable(message)); + fflush(stderr); +} +#endif + +void QsLogging::DebugOutputDestination::write(const QString& message, Level) +{ + QsDebugOutput::output(message); +} + +bool QsLogging::DebugOutputDestination::isValid() +{ + return true; +} diff --git a/QsLog/QsLogDestConsole.h b/QsLog/QsLogDestConsole.h new file mode 100644 index 00000000..f80f490e --- /dev/null +++ b/QsLog/QsLogDestConsole.h @@ -0,0 +1,52 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef QSLOGDESTCONSOLE_H +#define QSLOGDESTCONSOLE_H + +#include "QsLogDest.h" + +class QString; + +class QsDebugOutput +{ +public: + static void output(const QString& a_message); +}; + +namespace QsLogging +{ + +// debugger sink +class DebugOutputDestination : public Destination +{ +public: + virtual void write(const QString& message, Level level); + virtual bool isValid(); +}; + +} + +#endif // QSLOGDESTCONSOLE_H diff --git a/QsLog/QsLogDestFile.cpp b/QsLog/QsLogDestFile.cpp new file mode 100644 index 00000000..0f8f8048 --- /dev/null +++ b/QsLog/QsLogDestFile.cpp @@ -0,0 +1,155 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "QsLogDestFile.h" +#include +#include +#include +#include + +const int QsLogging::SizeRotationStrategy::MaxBackupCount = 10; + +QsLogging::RotationStrategy::~RotationStrategy() +{ +} + +QsLogging::SizeRotationStrategy::SizeRotationStrategy() + : mCurrentSizeInBytes(0) + , mMaxSizeInBytes(0) + , mBackupsCount(0) +{ +} + +void QsLogging::SizeRotationStrategy::setInitialInfo(const QFile &file) +{ + mFileName = file.fileName(); + mCurrentSizeInBytes = file.size(); +} + +void QsLogging::SizeRotationStrategy::includeMessageInCalculation(const QString &message) +{ + mCurrentSizeInBytes += message.toUtf8().size(); +} + +bool QsLogging::SizeRotationStrategy::shouldRotate() +{ + return mCurrentSizeInBytes > mMaxSizeInBytes; +} + +// Algorithm assumes backups will be named filename.X, where 1 <= X <= mBackupsCount. +// All X's will be shifted up. +void QsLogging::SizeRotationStrategy::rotate() +{ + if (!mBackupsCount) { + if (!QFile::remove(mFileName)) + std::cerr << "QsLog: backup delete failed " << qPrintable(mFileName); + return; + } + + // 1. find the last existing backup than can be shifted up + const QString logNamePattern = mFileName + QString::fromUtf8(".%1"); + int lastExistingBackupIndex = 0; + for (int i = 1;i <= mBackupsCount;++i) { + const QString backupFileName = logNamePattern.arg(i); + if (QFile::exists(backupFileName)) + lastExistingBackupIndex = qMin(i, mBackupsCount - 1); + else + break; + } + + // 2. shift up + for (int i = lastExistingBackupIndex;i >= 1;--i) { + const QString oldName = logNamePattern.arg(i); + const QString newName = logNamePattern.arg(i + 1); + QFile::remove(newName); + const bool renamed = QFile::rename(oldName, newName); + if (!renamed) { + std::cerr << "QsLog: could not rename backup " << qPrintable(oldName) + << " to " << qPrintable(newName); + } + } + + // 3. rename current log file + const QString newName = logNamePattern.arg(1); + if (QFile::exists(newName)) + QFile::remove(newName); + if (!QFile::rename(mFileName, newName)) { + std::cerr << "QsLog: could not rename log " << qPrintable(mFileName) + << " to " << qPrintable(newName); + } +} + +QIODevice::OpenMode QsLogging::SizeRotationStrategy::recommendedOpenModeFlag() +{ + return QIODevice::Append; +} + +void QsLogging::SizeRotationStrategy::setMaximumSizeInBytes(qint64 size) +{ + Q_ASSERT(size >= 0); + mMaxSizeInBytes = size; +} + +void QsLogging::SizeRotationStrategy::setBackupCount(int backups) +{ + Q_ASSERT(backups >= 0); + mBackupsCount = qMin(backups, SizeRotationStrategy::MaxBackupCount); +} + + +QsLogging::FileDestination::FileDestination(const QString& filePath, RotationStrategyPtr rotationStrategy) + : mRotationStrategy(rotationStrategy) +{ + mFile.setFileName(filePath); + if (!mFile.open(QFile::WriteOnly | QFile::Text | mRotationStrategy->recommendedOpenModeFlag())) + std::cerr << "QsLog: could not open log file " << qPrintable(filePath); + mOutputStream.setDevice(&mFile); + mOutputStream.setCodec(QTextCodec::codecForName("UTF-8")); + + mRotationStrategy->setInitialInfo(mFile); +} + +void QsLogging::FileDestination::write(const QString& message, Level) +{ + mRotationStrategy->includeMessageInCalculation(message); + if (mRotationStrategy->shouldRotate()) { + mOutputStream.setDevice(NULL); + mFile.close(); + mRotationStrategy->rotate(); + if (!mFile.open(QFile::WriteOnly | QFile::Text | mRotationStrategy->recommendedOpenModeFlag())) + std::cerr << "QsLog: could not reopen log file " << qPrintable(mFile.fileName()); + mRotationStrategy->setInitialInfo(mFile); + mOutputStream.setDevice(&mFile); + } + + mOutputStream << message << endl; + mOutputStream.flush(); +} + +bool QsLogging::FileDestination::isValid() +{ + return mFile.isOpen(); +} + diff --git a/QsLog/QsLogDestFile.h b/QsLog/QsLogDestFile.h new file mode 100644 index 00000000..ee7b5232 --- /dev/null +++ b/QsLog/QsLogDestFile.h @@ -0,0 +1,101 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef QSLOGDESTFILE_H +#define QSLOGDESTFILE_H + +#include "QsLogDest.h" +#include +#include +#include +#include + +namespace QsLogging +{ +class RotationStrategy +{ +public: + virtual ~RotationStrategy(); + + virtual void setInitialInfo(const QFile &file) = 0; + virtual void includeMessageInCalculation(const QString &message) = 0; + virtual bool shouldRotate() = 0; + virtual void rotate() = 0; + virtual QIODevice::OpenMode recommendedOpenModeFlag() = 0; +}; + +// Never rotates file, overwrites existing file. +class NullRotationStrategy : public RotationStrategy +{ +public: + virtual void setInitialInfo(const QFile &) {} + virtual void includeMessageInCalculation(const QString &) {} + virtual bool shouldRotate() { return false; } + virtual void rotate() {} + virtual QIODevice::OpenMode recommendedOpenModeFlag() { return QIODevice::Truncate; } +}; + +// Rotates after a size is reached, keeps a number of <= 10 backups, appends to existing file. +class SizeRotationStrategy : public RotationStrategy +{ +public: + SizeRotationStrategy(); + static const int MaxBackupCount; + + virtual void setInitialInfo(const QFile &file); + virtual void includeMessageInCalculation(const QString &message); + virtual bool shouldRotate(); + virtual void rotate(); + virtual QIODevice::OpenMode recommendedOpenModeFlag(); + + void setMaximumSizeInBytes(qint64 size); + void setBackupCount(int backups); + +private: + QString mFileName; + qint64 mCurrentSizeInBytes; + qint64 mMaxSizeInBytes; + int mBackupsCount; +}; + +typedef QSharedPointer RotationStrategyPtr; + +// file message sink +class FileDestination : public Destination +{ +public: + FileDestination(const QString& filePath, RotationStrategyPtr rotationStrategy); + virtual void write(const QString& message, Level level); + virtual bool isValid(); + +private: + QFile mFile; + QTextStream mOutputStream; + QSharedPointer mRotationStrategy; +}; + +} + +#endif // QSLOGDESTFILE_H diff --git a/QsLog/QsLogDestFunctor.cpp b/QsLog/QsLogDestFunctor.cpp new file mode 100644 index 00000000..601139d9 --- /dev/null +++ b/QsLog/QsLogDestFunctor.cpp @@ -0,0 +1,57 @@ +// Copyright (c) 2014, Razvan Petru +// Copyright (c) 2014, Omar Carey +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "QsLogDestFunctor.h" +#include +#include + +QsLogging::FunctorDestination::FunctorDestination(LogFunction f) + : QObject(NULL) + , mLogFunction(f) +{ +} + +QsLogging::FunctorDestination::FunctorDestination(QObject *receiver, const char *member) + : QObject(NULL) + , mLogFunction(NULL) +{ + connect(this, SIGNAL(logMessageReady(QString,int)), receiver, member, Qt::QueuedConnection); +} + + +void QsLogging::FunctorDestination::write(const QString &message, QsLogging::Level level) +{ + if (mLogFunction) + mLogFunction(message, level); + + if (level > QsLogging::TraceLevel) + emit logMessageReady(message, static_cast(level)); +} + +bool QsLogging::FunctorDestination::isValid() +{ + return true; +} diff --git a/QsLog/QsLogDestFunctor.h b/QsLog/QsLogDestFunctor.h new file mode 100644 index 00000000..e34631f0 --- /dev/null +++ b/QsLog/QsLogDestFunctor.h @@ -0,0 +1,59 @@ +// Copyright (c) 2014, Razvan Petru +// Copyright (c) 2014, Omar Carey +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef QSLOGDESTFUNCTOR_H +#define QSLOGDESTFUNCTOR_H + +#include "QsLogDest.h" +#include + +namespace QsLogging +{ +// Offers various types of function-like sinks. +// This is an advanced destination type. Depending on your configuration, LogFunction might be +// called from a different thread or even a different binary. You should not access QsLog from +// inside LogFunction and should not perform any time-consuming operations. +// logMessageReady is connected through a queued connection and trace messages are not included +class FunctorDestination : public QObject, public Destination +{ + Q_OBJECT +public: + explicit FunctorDestination(LogFunction f); + FunctorDestination(QObject *receiver, const char *member); + + virtual void write(const QString &message, Level level); + virtual bool isValid(); + +protected: + // int used to avoid registering a new enum type + Q_SIGNAL void logMessageReady(const QString &message, int level); + +private: + LogFunction mLogFunction; +}; +} + +#endif // QSLOGDESTFUNCTOR_H diff --git a/QsLog/QsLogDisableForThisFile.h b/QsLog/QsLogDisableForThisFile.h new file mode 100644 index 00000000..c70af103 --- /dev/null +++ b/QsLog/QsLogDisableForThisFile.h @@ -0,0 +1,22 @@ +#ifndef QSLOGDISABLEFORTHISFILE_H +#define QSLOGDISABLEFORTHISFILE_H + +#include +// When included AFTER QsLog.h, this file will disable logging in that C++ file. When included +// before, it will lead to compiler warnings or errors about macro redefinitions. + +#undef QLOG_TRACE +#undef QLOG_DEBUG +#undef QLOG_INFO +#undef QLOG_WARN +#undef QLOG_ERROR +#undef QLOG_FATAL + +#define QLOG_TRACE() if (1) {} else qDebug() +#define QLOG_DEBUG() if (1) {} else qDebug() +#define QLOG_INFO() if (1) {} else qDebug() +#define QLOG_WARN() if (1) {} else qDebug() +#define QLOG_ERROR() if (1) {} else qDebug() +#define QLOG_FATAL() if (1) {} else qDebug() + +#endif // QSLOGDISABLEFORTHISFILE_H diff --git a/QsLog/QsLogLevel.h b/QsLog/QsLogLevel.h new file mode 100644 index 00000000..62984732 --- /dev/null +++ b/QsLog/QsLogLevel.h @@ -0,0 +1,45 @@ +// Copyright (c) 2013, Razvan Petru +// All rights reserved. + +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: + +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, this +// list of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// * The name of the contributors may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef QSLOGLEVEL_H +#define QSLOGLEVEL_H + +namespace QsLogging +{ + +enum Level +{ + TraceLevel = 0, + DebugLevel, + InfoLevel, + WarnLevel, + ErrorLevel, + FatalLevel, + OffLevel +}; + +} + +#endif // QSLOGLEVEL_H diff --git a/QsLog/QsLogSharedLibrary.pro b/QsLog/QsLogSharedLibrary.pro new file mode 100644 index 00000000..51320684 --- /dev/null +++ b/QsLog/QsLogSharedLibrary.pro @@ -0,0 +1,35 @@ +# This pro file will build QsLog as a shared library +include(QsLog.pri) + +TARGET = QsLog +VERSION = "2.0.0" +QT -= gui +CONFIG -= console +CONFIG -= app_bundle +CONFIG += shared +TEMPLATE = lib + +DESTDIR = $$PWD/build-QsLogShared +OBJECTS_DIR = $$DESTDIR/obj +MOC_DIR = $$DESTDIR/moc + +win32 { + DEFINES += QSLOG_IS_SHARED_LIBRARY +} + +unix:!macx { + # make install will install the shared object in the appropriate folders + headers.files = QsLog.h QsLogDest.h QsLogLevel.h + headers.path = /usr/include/$(QMAKE_TARGET) + + other_files.files = *.txt + other_files.path = /usr/local/share/$(QMAKE_TARGET) + + contains(QT_ARCH, x86_64) { + target.path = /usr/lib64 + } else { + target.path = /usr/lib + } + + INSTALLS += headers target other_files +} diff --git a/README.txt b/README.txt new file mode 100644 index 00000000..b9d66e4a --- /dev/null +++ b/README.txt @@ -0,0 +1,22 @@ +LICENSE +******* +This software has been developed by Luis Ángel San Martín Rodríguez (luisangelsm@gmail.com) under GPL v3 license +(for more details read COPYING.txt). + +CONTACT +******* +Project home page : www.yacreader.com +e-mail: + info@yacreader.com + support@yacreader.com +Social: + Facebook - http://www.facebook.com/YACReader + Twitter - https://twitter.com/yacreader + YouTube - https://www.youtube.com/user/yacreader + +If you need help or have any suggestion, please, send me an e-mail. + +DONATIONS +********* +YACReader is free but it needs money to still be alive, so please, +if you like YACReader, visit the home page and make a donation. \ No newline at end of file diff --git a/YACReader.1 b/YACReader.1 new file mode 100644 index 00000000..9777636f --- /dev/null +++ b/YACReader.1 @@ -0,0 +1,50 @@ +.\" Manpage for YACReader. +.\" Contact yoann.gauthier9@gmail.com to correct errors or typos. +.TH man 1 "28 September 2014" "2.0" "YACReader man page" +.SH NAME +YACReader \- launch YACReader application. +.SH SYNOPSIS +YACReader [\fBFile\fR | \fBDirectory\fR] +.br +YACReader [\fB\-h\fR | \fB\-\-help\fR] +.br +YACReader [\fB\-v\fR | \fB\-\-version\fR] +.SH DESCRIPTION +YACReader is a free cross-platform comic reader with support for multiple comic files and image formats. +.SH OPTIONS +.TP +.BR File +Open comic file. +.TP +.BR Directory +Open comic directory. +.TP +.BR \-h, \-\- help +Display this text and exit. +.TP +.BR \-v, \-\- version +Display version information and exit. +.SH FEATURES +- rar, zip, cbr, cbz, tar, pdf, 7z and cb7 comics support with compatibility for jpeg, gif, png, tiff and bmp images. +.TP +- Fast and easy to use. +.TP +- Use your keyboard or mouse for easy navigation. +.TP +- Fully customizable magnifying glass. +.TP +- Image rotation, double page mode, full size view, fullscreen mode, customizable background color and more. +.TP +- Bookmarks and resume reading. +.TP +- Find any page easily and quickly with "go to flow", a customizable eye candy effect for browsing comic pages. +.SH CONTACTS +To report bug or contact developpers, send a mail to : +.RS 3 +.TP +\fBinfo@yacreader.com\fR : for general information or suggestions about YACReader. +.TP +\fBsupport@yacreader.com\fR : for problems with YACReader or bugs detected. +.RE +.SH AUTHOR +Luis Ãngel San Martín Rodríguez (luisangelsm@gmail.com) \ No newline at end of file diff --git a/YACReader.desktop b/YACReader.desktop new file mode 100644 index 00000000..32d5caf3 --- /dev/null +++ b/YACReader.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Name=YACReader +GenericName=Yet Another Comic Reader +Comment=A comic reader with support for .cb*, .pdf and whole directories. +Exec=YACReader %f +Icon=/usr/share/yacreader/icon.png +Terminal=false +Type=Application +StartupNotify=true +Categories=Graphics;Viewer; +MimeType=application/x-cbz;application/x-cbr;application/x-cbt;application/x-cb7;application/x-pdf;application/x-zip;application/x-rar;application/x-7z;inode/directory; +Keywords=comic;viewer;pdf;reader; +X-Desktop-File-Install-Version=0.22 diff --git a/YACReader.pro b/YACReader.pro new file mode 100644 index 00000000..528d3c41 --- /dev/null +++ b/YACReader.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = YACReader YACReaderLibrary +YACReaderLibrary.depends = YACReader \ No newline at end of file diff --git a/YACReader/YACReader.icns b/YACReader/YACReader.icns new file mode 100644 index 00000000..9943539f Binary files /dev/null and b/YACReader/YACReader.icns differ diff --git a/YACReader/YACReader.pro b/YACReader/YACReader.pro new file mode 100644 index 00000000..6c0b418e --- /dev/null +++ b/YACReader/YACReader.pro @@ -0,0 +1,269 @@ +# ##################################################################### +# Automatically generated by qmake (2.01a) mié 8. oct 20:54:05 2008 +# ##################################################################### +TEMPLATE = app +TARGET = YACReader +DEPENDPATH += . \ + release + +DEFINES += NOMINMAX YACREADER + +#load default build flags +include (../config.pri) + +unix:!macx{ + QMAKE_CXXFLAGS += -std=c++11 +} + +CONFIG(force_angle) { + Release:DESTDIR = ../release_angle + Debug:DESTDIR = ../debug_angle +} else { + Release:DESTDIR = ../release + Debug:DESTDIR = ../debug +} + +SOURCES += main.cpp + +INCLUDEPATH += ../common \ + ../custom_widgets + +!CONFIG(no_opengl):CONFIG(legacy_gl_widget) { + INCLUDEPATH += ../common/gl_legacy \ +} else { + INCLUDEPATH += ../common/gl \ +} + +#there are going to be two builds for windows, OpenGL based and ANGLE based +win32 { + CONFIG(force_angle) { + message("using ANGLE") + LIBS += -L../dependencies/poppler/lib -loleaut32 -lole32 -lshell32 -lopengl32 -lglu32 -luser32 + #linking extra libs are necesary for a successful compilation, a better approach should be + #to remove any OpenGL (desktop) dependencies + #the OpenGL stuff should be migrated to OpenGL ES + DEFINES += FORCE_ANGLE + } else { + LIBS += -L../dependencies/poppler/lib -loleaut32 -lole32 -lshell32 -lopengl32 -lglu32 -luser32 + } + + LIBS += -lpoppler-qt5 + INCLUDEPATH += ../dependencies/poppler/include/qt5 + + QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL + QMAKE_LFLAGS_RELEASE += /LTCG + CONFIG -= embed_manifest_exe +} + +unix:!macx{ + +INCLUDEPATH += /usr/include/poppler/qt5 +LIBS += -L/usr/lib -lpoppler-qt5 + +!CONFIG(no_opengl) { + LIBS += -lGLU +} + +} + +macx{ +#INCLUDEPATH += "/Volumes/Mac OS X Lion/usr/X11/include" +#isEqual(QT_MAJOR_VERSION, 5) { +#INCLUDEPATH += /usr/local/include/poppler/qt5 +#LIBS += -L/usr/local/lib -lpoppler-qt5 +#} +#else { +#INCLUDEPATH += /usr/local/include/poppler/qt4 +#LIBS += -L/usr/local/lib -lpoppler-qt4 +#} +CONFIG += objective_c +QT += macextras gui-private + + +LIBS += -framework Foundation -framework ApplicationServices -framework AppKit + +OBJECTIVE_SOURCES += ../common/pdf_comic.mm +HEADERS += ../common/pdf_comic.h +} + +QT += network widgets core +!CONFIG(no_opengl) { + QT += opengl +} + +#CONFIG += release +CONFIG -= flat + +QT += multimedia + +# Input +HEADERS += ../common/comic.h \ + configuration.h \ + goto_dialog.h \ + magnifying_glass.h \ + main_window_viewer.h \ + viewer.h \ + goto_flow.h \ + options_dialog.h \ + ../common/bookmarks.h \ + bookmarks_dialog.h \ + render.h \ + shortcuts_dialog.h \ + translator.h \ + goto_flow_widget.h \ + page_label_widget.h \ + goto_flow_toolbar.h \ + goto_flow_decorationbar.h \ + width_slider.h \ + notifications_label_widget.h \ + ../common/pictureflow.h \ + ../common/custom_widgets.h \ + ../common/check_new_version.h \ + ../common/qnaturalsorting.h \ + ../common/yacreader_global.h \ + ../common/onstart_flow_selection_dialog.h \ + ../common/comic_db.h \ + ../common/folder.h \ + ../common/library_item.h \ + yacreader_local_client.h \ + ../common/http_worker.h \ + ../common/exit_check.h \ + ../common/scroll_management.h \ + ../common/opengl_checker.h + +!CONFIG(no_opengl) { + CONFIG(legacy_gl_widget) { + message("using legacy YACReaderFlowGL (QGLWidget) header") + HEADERS += ../common/gl_legacy/yacreader_flow_gl.h + } else { + HEADERS += ../common/gl/yacreader_flow_gl.h + } + HEADERS += goto_flow_gl.h +} + +SOURCES += ../common/comic.cpp \ + configuration.cpp \ + goto_dialog.cpp \ + magnifying_glass.cpp \ + main_window_viewer.cpp \ + viewer.cpp \ + goto_flow.cpp \ + options_dialog.cpp \ + ../common/bookmarks.cpp \ + bookmarks_dialog.cpp \ + render.cpp \ + shortcuts_dialog.cpp \ + translator.cpp \ + goto_flow_widget.cpp \ + page_label_widget.cpp \ + goto_flow_toolbar.cpp \ + goto_flow_decorationbar.cpp \ + width_slider.cpp \ + notifications_label_widget.cpp \ + ../common/pictureflow.cpp \ + ../common/custom_widgets.cpp \ + ../common/check_new_version.cpp \ + ../common/qnaturalsorting.cpp \ + ../common/onstart_flow_selection_dialog.cpp \ + ../common/comic_db.cpp \ + ../common/folder.cpp \ + ../common/library_item.cpp \ + yacreader_local_client.cpp \ + ../common/http_worker.cpp \ + ../common/yacreader_global.cpp \ + ../common/exit_check.cpp \ + ../common/scroll_management.cpp \ + ../common/opengl_checker.cpp + +!CONFIG(no_opengl) { + CONFIG(legacy_gl_widget) { + message("using legacy YACReaderFlowGL (QGLWidget) source code") + SOURCES += ../common/gl_legacy/yacreader_flow_gl.cpp + } else { + SOURCES += ../common/gl/yacreader_flow_gl.cpp + } + SOURCES += goto_flow_gl.cpp +} + +include(../custom_widgets/custom_widgets_yacreader.pri) +CONFIG(7zip){ +include(../compressed_archive/wrapper.pri) +} else:CONFIG(unarr){ +include(../compressed_archive/unarr/unarr-wrapper.pri) +} else { + error(No compression backend specified. Did you mess with the build system?) + } +include(../shortcuts_management/shortcuts_management.pri) + +RESOURCES += yacreader_images.qrc \ + yacreader_files.qrc + +win32:RESOURCES += yacreader_images_win.qrc +unix:!macx:RESOURCES += yacreader_images_win.qrc +macx:RESOURCES += yacreader_images_osx.qrc + + +include(../QsLog/QsLog.pri) + +RC_FILE = icon.rc + +macx { + ICON = YACReader.icns +} + +TRANSLATIONS = yacreader_es.ts \ + yacreader_fr.ts \ + yacreader_ru.ts \ + yacreader_pt.ts \ + yacreader_nl.ts \ + yacreader_tr.ts \ + yacreader_de.ts \ + yacreader_source.ts + +unix:!macx { +#set install prefix if it's empty +isEmpty(PREFIX) { + PREFIX = /usr +} + +BINDIR = $$PREFIX/bin +LIBDIR = $$PREFIX/lib +DATADIR = $$PREFIX/share + +DEFINES += "LIBDIR=\\\"$$LIBDIR\\\"" "DATADIR=\\\"$$DATADIR\\\"" + +#MAKE INSTALL + +INSTALLS += bin docs icon desktop translation manpage + +bin.path = $$BINDIR +isEmpty(DESTDIR) { + bin.files = YACReader +} else { + bin.files = $$DESTDIR/YACReader +} + +docs.path = $$DATADIR/doc/yacreader + +#rename docs for better packageability +docs.extra = cp ../CHANGELOG.txt ../changelog; cp ../README.txt ../README +docs.files = ../README ../changelog + +icon.path = $$DATADIR/yacreader +icon.files = ../images/icon.png + +desktop.path = $$DATADIR/applications +desktop.extra = desktop-file-edit --set-icon=$$DATADIR/yacreader/icon.png ../YACReader.desktop +desktop.files = ../YACReader.desktop + +#TODO: icons should be located at /usr/share/icons and have the same basename as their application + +translation.path = $$DATADIR/yacreader/languages +translation.files = ../release/languages/yacreader_* + +manpage.path = $$DATADIR/man/man1 +manpage.files = ../YACReader.1 + +#remove leftover doc files when 'make clean' is invoked +QMAKE_CLEAN += "../changelog" "../README" +} diff --git a/YACReader/bookmarks_dialog.cpp b/YACReader/bookmarks_dialog.cpp new file mode 100644 index 00000000..07df7222 --- /dev/null +++ b/YACReader/bookmarks_dialog.cpp @@ -0,0 +1,197 @@ +#include "bookmarks_dialog.h" + +#include +#include +#include +#include +#include +#include + +#include "bookmarks.h" + +BookmarksDialog::BookmarksDialog(QWidget * parent) + :QDialog(parent) +{ + setModal(true); + + //animation = new QPropertyAnimation(this,"windowOpacity"); + //animation->setDuration(150); + + QHBoxLayout * layout = new QHBoxLayout(); + + //bookmarks + QGridLayout * bookmarksL = new QGridLayout(); + + pages.push_back(new QLabel(tr("Lastest Page"))); + for(int i=0;i<3;i++) + pages.push_back(new QLabel("-")); + + QString labelsStyle = "QLabel {color:white;}"; + + foreach(QLabel * label,pages) + { + label->setStyleSheet(labelsStyle); + } + + int heightDesktopResolution = QApplication::desktop()->screenGeometry().height(); + int height,width; + height = heightDesktopResolution*0.50; + width = height*0.65; + + coverSize = QSize(width,height); + + for(int i=0;i<4;i++) + { + QLabel * l = new QLabel(); + l->setFixedSize(coverSize); + l->setScaledContents(false); + //l->setPixmap(QPixmap(":/images/notCover.png")); + l->installEventFilter(this); + images.push_back(l); + } + + for(int i=0;i<3;i++) + bookmarksL->addWidget(pages.at(i+1),0,i,Qt::AlignCenter); + + for(int i=0;i<3;i++) + bookmarksL->addWidget(images.at(i+1),1,i,Qt::AlignCenter); + + + //last page + QGridLayout * lp = new QGridLayout(); + lp->addWidget(pages.at(0),0,0,Qt::AlignCenter); + lp->addWidget(images.at(0),1,0,Qt::AlignCenter); + + layout->addLayout(bookmarksL); + QFrame *f = new QFrame( this ); + f->setFrameStyle( QFrame::VLine | QFrame::Sunken ); + layout->addWidget(f); + layout->addLayout(lp); + + QHBoxLayout * buttons = new QHBoxLayout(); + + cancel = new QPushButton(tr("Close")); + cancel->setFlat(true); + connect(cancel,SIGNAL(clicked()),this,SLOT(hide())); + buttons->addStretch(); + buttons->addWidget(cancel); + + cancel->setStyleSheet("QPushButton {border: 1px solid #242424; background: #2e2e2e; color:white; padding: 5px 26px 5px 26px; font-size:12px;font-family:Arial; font-weight:bold;}"); + + QVBoxLayout * l = new QVBoxLayout(); + + l->addWidget(new QLabel(""+tr("Click on any image to go to the bookmark")+""),0,Qt::AlignCenter); + l->addLayout(layout); +#ifdef Q_OS_MAC + l->addLayout(buttons); +#endif + + QPalette Pal(palette()); + // set black background + Pal.setColor(QPalette::Background, QColor("#454545")); + this->setAutoFillBackground(true); + this->setPalette(Pal); + + setLayout(l); +} + +void BookmarksDialog::setBookmarks(const Bookmarks & bm) +{ + lastPage = bm.getLastPage(); + if (lastPage > 0) + { + QPixmap p = QPixmap::fromImage(bm.getLastPagePixmap()); + if(p.isNull()) + { + images.at(0)->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + images.at(0)->setText(tr("Loading...")); + } + else + { + images.at(0)->setAlignment(Qt::AlignHCenter|Qt::AlignBottom); + images.at(0)->setPixmap(p.scaled(coverSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)); + } + } + else + { + images.at(0)->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + images.at(0)->setPixmap(QPixmap(":/images/notCover.png").scaled(coverSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)); + + } + + QList l = bm.getBookmarkPages(); + int s = l.count(); + for(int i=0;isetText(QString::number(l.at(i)+1)); + QPixmap p = QPixmap::fromImage(bm.getBookmarkPixmap(l.at(i))); + if(p.isNull()) + { + images.at(i+1)->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + images.at(i+1)->setText(tr("Loading...")); + } + else + { + images.at(i+1)->setAlignment(Qt::AlignHCenter|Qt::AlignBottom); + images.at(i+1)->setPixmap(p.scaled(coverSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)); + } + } + for(int i=s;i<3;i++) + { + pages.at(i+1)->setText("-"); + images.at(i+1)->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + images.at(i+1)->setPixmap(QPixmap(":/images/notCover.png").scaled(coverSize,Qt::KeepAspectRatio,Qt::SmoothTransformation)); + } +} + +bool BookmarksDialog::eventFilter(QObject *obj, QEvent *event) +{ + if(event->type() == QEvent::MouseButtonPress) + { + if (obj == images.at(0)) + { + emit(goToPage(lastPage)); + close(); + event->accept(); + } + for(int i=1;i<=3;i++) + { + if(obj == images.at(i)) + { + bool b; + int page = pages.at(i)->text().toInt(&b)-1; + if(b) + { + emit(goToPage(page)); + close(); + } + event->accept(); + } + } + } + // pass the event on to the parent class + return QDialog::eventFilter(obj, event); +} + +void BookmarksDialog::keyPressEvent(QKeyEvent * event) +{ + if(event->key() == Qt::Key_M) + hide(); +} +/* +void BookmarksDialog::show() +{ + QDialog::show(); + disconnect(animation,SIGNAL(finished()),this,SLOT(close())); + animation->setStartValue(0); + animation->setEndValue(1); + animation->start(); +} + +void BookmarksDialog::hide() +{ + connect(animation,SIGNAL(finished()),this,SLOT(close())); + animation->setStartValue(1); + animation->setEndValue(0); + animation->start(); +}*/ diff --git a/YACReader/bookmarks_dialog.h b/YACReader/bookmarks_dialog.h new file mode 100644 index 00000000..c83a2c7e --- /dev/null +++ b/YACReader/bookmarks_dialog.h @@ -0,0 +1,45 @@ +#ifndef __BOOKMARKS_DIALOG_H +#define __BOOKMARKS_DIALOG_H + +#include +#include +#include +#include +#include +#include +#include + +#include "bookmarks.h" + + class BookmarksDialog : public QDialog + { + Q_OBJECT + + protected: + QList pages; + QList images; + + int lastPage; + + QPushButton * accept; + QPushButton * cancel; + + QSize coverSize; + + bool eventFilter(QObject *obj, QEvent *event); + void keyPressEvent(QKeyEvent * event); + //QPropertyAnimation * animation; + + public: + BookmarksDialog(QWidget * parent = 0); + + public slots: + void setBookmarks(const Bookmarks & bookmarks); + //void show(); + //void hide(); + + signals: + void goToPage(unsigned int page); + }; + +#endif // BOOKMARKS_DIALOG_H diff --git a/YACReader/configuration.cpp b/YACReader/configuration.cpp new file mode 100644 index 00000000..13e7a9b2 --- /dev/null +++ b/YACReader/configuration.cpp @@ -0,0 +1,58 @@ +#include "configuration.h" + +#include +#include +#include +#include +#include +#include + +#include "yacreader_global.h" + +Configuration::Configuration() +{ + //read configuration + //load("/YACReader.conf"); +} + +/*Configuration::Configuration(const Configuration & conf) +{ + //nothing +}*/ + +void Configuration::load(QSettings * settings) +{ + this->settings = settings; + + //TODO set defaults + if(!settings->contains(PATH)) + settings->setValue(PATH,"."); + if(!settings->contains(GO_TO_FLOW_SIZE)) + settings->setValue(GO_TO_FLOW_SIZE,QSize(126,200)); + if(!settings->contains(MAG_GLASS_SIZE)) + settings->setValue(MAG_GLASS_SIZE,QSize(350,175)); + if(!settings->contains(ZOOM_LEVEL)) + settings->setValue(MAG_GLASS_SIZE,QSize(350,175)); + if(!settings->contains(FIT)) + settings->setValue(FIT,false); + if(!settings->contains(FLOW_TYPE)) + settings->setValue(FLOW_TYPE,0); + if(!settings->contains(FULLSCREEN)) + settings->setValue(FULLSCREEN,false); + if(!settings->contains(FIT_TO_WIDTH_RATIO)) + settings->setValue(FIT_TO_WIDTH_RATIO,1); + if(!settings->contains(Y_WINDOW_SIZE)) + settings->setValue(Y_WINDOW_SIZE,QSize(0,0)); + if(!settings->contains(MAXIMIZED)) + settings->setValue(MAXIMIZED,false); + if(!settings->contains(DOUBLE_PAGE)) + settings->setValue(DOUBLE_PAGE,false); + if(!settings->contains(ADJUST_TO_FULL_SIZE)) + settings->setValue(ADJUST_TO_FULL_SIZE,false); + if(!settings->contains(BACKGROUND_COLOR)) + settings->setValue(BACKGROUND_COLOR,QColor(40,40,40)); + if(!settings->contains(ALWAYS_ON_TOP)) + settings->setValue(ALWAYS_ON_TOP,false); + if(!settings->contains(SHOW_TOOLBARS)) + settings->setValue(SHOW_TOOLBARS, true); +} \ No newline at end of file diff --git a/YACReader/configuration.h b/YACReader/configuration.h new file mode 100644 index 00000000..ba9e1531 --- /dev/null +++ b/YACReader/configuration.h @@ -0,0 +1,97 @@ +#ifndef __CONFIGURATION_H +#define __CONFIGURATION_H +#include +#include +#include +#include +#include +#include +#include + +#include "yacreader_global.h" + +#define CONF_FILE_PATH "." +#define SLIDE_ASPECT_RATIO 1.585 + +using namespace YACReader; + + class Configuration : public QObject + { + Q_OBJECT + + private: + QSettings * settings; + + QString defaultPath; + //configuration properties + QSize magnifyingGlassSize; + QSize gotoSlideSize; + float zoomLevel; + bool adjustToWidth; + bool fullScreen; + FlowType flowType; + float fitToWidthRatio; + QPoint windowPos; + QSize windowSize; + bool maximized; + bool doublePage; + bool doubleMangaPage; + bool alwaysOnTop; + bool adjustToFullSize; + QColor backgroundColor; + + Configuration(); + //Configuration(const Configuration & conf); + void load(const QString & path = CONF_FILE_PATH); + + + public: + static Configuration & getConfiguration() + { + static Configuration configuration; + return configuration; + }; + void load(QSettings * settings); + QString getDefaultPath() { return settings->value(PATH).toString(); } + void setDefaultPath(QString defaultPath){settings->setValue(PATH,defaultPath);} + QSize getMagnifyingGlassSize() { return settings->value(MAG_GLASS_SIZE).toSize();} + void setMagnifyingGlassSize(const QSize & mgs) { settings->setValue(MAG_GLASS_SIZE,mgs);} + QSize getGotoSlideSize() { return settings->value(GO_TO_FLOW_SIZE).toSize();} + void setGotoSlideSize(const QSize & gss) { settings->setValue(GO_TO_FLOW_SIZE,gss);} + float getZoomLevel() { return settings->value(ZOOM_LEVEL).toFloat();} + void setZoomLevel(float zl) { settings->setValue(ZOOM_LEVEL,zl);} + bool getAdjustToWidth() {return settings->value(FIT).toBool();} + void setAdjustToWidth(bool atw=true) {settings->setValue(FIT,atw);} + FlowType getFlowType(){return (FlowType)settings->value(FLOW_TYPE_SW).toInt();} + void setFlowType(FlowType type){settings->setValue(FLOW_TYPE_SW,type);} + bool getFullScreen(){return settings->value(FULLSCREEN).toBool();} + void setFullScreen(bool f){settings->setValue(FULLSCREEN,f);} + float getFitToWidthRatio(){return settings->value(FIT_TO_WIDTH_RATIO).toFloat();} + void setFitToWidthRatio(float r){settings->setValue(FIT_TO_WIDTH_RATIO,r);} + QPoint getPos(){return settings->value(Y_WINDOW_POS).toPoint();} + void setPos(QPoint p){settings->setValue(Y_WINDOW_POS,p);} + QSize getSize(){return settings->value(Y_WINDOW_SIZE).toSize();} + void setSize(QSize s){settings->setValue(Y_WINDOW_SIZE,s);} + bool getMaximized(){return settings->value(MAXIMIZED).toBool();} + void setMaximized(bool b){settings->setValue(MAXIMIZED,b);} + bool getDoublePage(){return settings->value(DOUBLE_PAGE).toBool();} + void setDoublePage(bool b){settings->setValue(DOUBLE_PAGE,b);} + bool getDoubleMangaPage(){return settings->value(DOUBLE_MANGA_PAGE).toBool();} + void setDoubleMangaPage(bool b){settings->setValue(DOUBLE_MANGA_PAGE,b);} + bool getAdjustToFullSize(){return settings->value(ADJUST_TO_FULL_SIZE).toBool();} + void setAdjustToFullSize(bool b){settings->setValue(ADJUST_TO_FULL_SIZE,b);} + QColor getBackgroundColor(){return settings->value(BACKGROUND_COLOR).value();} + void setBackgroundColor(const QColor& color){settings->value(BACKGROUND_COLOR,color);} + bool getAlwaysOnTop(){return settings->value(ALWAYS_ON_TOP).toBool();} + void setAlwaysOnTop(bool b){ settings->setValue(ALWAYS_ON_TOP,b);} + bool getShowToolbars(){return settings->value(SHOW_TOOLBARS).toBool();} + void setShowToolbars(bool b){settings->setValue(SHOW_TOOLBARS,b);} + bool getShowInformation(){return settings->value(SHOW_INFO,false).toBool();} + void setShowInformation(bool b){settings->setValue(SHOW_INFO,b);} + QDate getLastVersionCheck(){return settings->value(LAST_VERSION_CHECK).toDate();} + void setLastVersionCheck(const QDate & date){ settings->setValue(LAST_VERSION_CHECK,date);} + int getNumDaysBetweenVersionChecks() {return settings->value(NUM_DAYS_BETWEEN_VERSION_CHECKS,1).toInt();} + void setNumDaysBetweenVersionChecks(int days) {return settings->setValue(NUM_DAYS_BETWEEN_VERSION_CHECKS,days);} + }; + +#endif diff --git a/YACReader/goto_dialog.cpp b/YACReader/goto_dialog.cpp new file mode 100644 index 00000000..ed774432 --- /dev/null +++ b/YACReader/goto_dialog.cpp @@ -0,0 +1,84 @@ +#include "goto_dialog.h" + +#include +#include +#include + + + +GoToDialog::GoToDialog(QWidget * parent) +:QDialog(parent) +{ + setupUI(); +} + +void GoToDialog::setupUI() +{ + textLabel = new QLabel(tr("Page : ")); + pageNumber = new QLineEdit; + v = new QIntValidator(this); + v->setBottom(1); + pageNumber->setValidator(v); + textLabel->setBuddy(pageNumber); + textLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + + accept = new QPushButton(tr("Go To")); + connect(accept,SIGNAL(clicked()),this,SLOT(goTo())); + cancel = new QPushButton(tr("Cancel")); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + + QHBoxLayout *topLayout = new QHBoxLayout; + + topLayout->addWidget(textLabel); + topLayout->addWidget(pageNumber); + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(accept); + bottomLayout->addWidget(cancel); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(numPagesLabel = new QLabel(tr("Total pages : "))); + mainLayout->addLayout(topLayout); + mainLayout->addStretch(); + mainLayout->addLayout(bottomLayout); + + QHBoxLayout *imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(); + QPixmap p(":/images/goto.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setWindowTitle(tr("Go to...")); + setModal (true); + + pageNumber->setFocusPolicy(Qt::StrongFocus); + pageNumber->setFocus(); +} + +void GoToDialog::goTo() +{ + unsigned int page = pageNumber->text().toInt(); + pageNumber->clear(); + + if(page >= 1) + emit(goToPage(page-1)); + + close(); + +} + +void GoToDialog::setNumPages(unsigned int numPages) +{ + numPagesLabel->setText(tr("Total pages : ")+QString::number(numPages)); + v->setTop(numPages); +} + +void GoToDialog::open() +{ + pageNumber->setFocus(); + QDialog::open(); +} diff --git a/YACReader/goto_dialog.h b/YACReader/goto_dialog.h new file mode 100644 index 00000000..54253605 --- /dev/null +++ b/YACReader/goto_dialog.h @@ -0,0 +1,32 @@ +#ifndef __GOTODIALOG_H +#define __GOTODIALOG_H + +#include +#include +#include +#include +#include + + class GoToDialog : public QDialog + { + Q_OBJECT + public: + GoToDialog(QWidget * parent = 0); + private: + QLabel * numPagesLabel; + QLabel * textLabel; + QLineEdit * pageNumber; + QIntValidator * v; + QPushButton * accept; + QPushButton * cancel; + void setupUI(); + public slots: + void goTo(); + void setNumPages(unsigned int numPages); + void open(); + signals: + void goToPage(unsigned int page); + }; + +#endif + diff --git a/YACReader/goto_flow.cpp b/YACReader/goto_flow.cpp new file mode 100644 index 00000000..f6325b0f --- /dev/null +++ b/YACReader/goto_flow.cpp @@ -0,0 +1,320 @@ +#include "goto_flow.h" +#include "configuration.h" +#include "comic.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "yacreader_flow.h" + +#include "goto_flow_toolbar.h" +#include "goto_flow_decorationbar.h" + + +GoToFlow::GoToFlow(QWidget *parent,FlowType flowType) +:GoToFlowWidget(parent),ready(false) +{ + updateTimer = new QTimer; + connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateImageData())); + + worker = new PageLoader(&mutexGoToFlow); + + + flow = new YACReaderFlow(this,flowType); + flow->setReflectionEffect(PictureFlow::PlainReflection); + imageSize = Configuration::getConfiguration().getGotoSlideSize(); + + flow->setSlideSize(imageSize); + connect(flow,SIGNAL(centerIndexChanged(int)),this,SLOT(setPageNumber(int))); + connect(flow,SIGNAL(selected(unsigned int)),this,SIGNAL(goToPage(unsigned int))); + + connect(toolBar,SIGNAL(goTo(unsigned int)),this,SIGNAL(goToPage(unsigned int))); + connect(toolBar,SIGNAL(setCenter(unsigned int)),flow,SLOT(showSlide(unsigned int))); + + mainLayout->insertWidget(1,flow); + mainLayout->setStretchFactor(flow,1); + + resize(static_cast(5*imageSize.width()),static_cast(imageSize.height()*1.7)); + + //install eventFilter + //flow->installEventFilter(this); + /*edit->installEventFilter(this); + centerButton->installEventFilter(this); + goToButton->installEventFilter(this); + + connect(edit,SIGNAL(returnPressed()),goToButton,SIGNAL(clicked()));*/ + + this->setCursor(QCursor(Qt::ArrowCursor)); + + +} +GoToFlow::~GoToFlow() +{ + delete flow; + delete updateTimer; + worker->deleteLater(); +} + +void GoToFlow::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) + { + case Qt::Key_Left: case Qt::Key_Right: case Qt::Key_Up: + QApplication::sendEvent(flow,event); + return; + default: + break; + } + + GoToFlowWidget::keyPressEvent(event); +} + +void GoToFlow::centerSlide(int slide) +{ + if(flow->centerIndex()!=slide) + { + flow->setCenterIndex(slide); + if(ready)// load images if pages are loaded. + { + //worker->reset(); //BUG FIXED : image didn't load if worker was working + preload(); + } + } +} + +void GoToFlow::setNumSlides(unsigned int slides) +{ + // numPagesLabel->setText(tr("Total pages : ")+QString::number(slides)); + // numPagesLabel->adjustSize(); + imagesReady.clear(); + imagesReady.fill(false,slides); + + rawImages.clear(); + rawImages.resize(slides); + + toolBar->setTop(slides); + + SlideInitializer * si = new SlideInitializer(&mutexGoToFlow,flow,slides); + + imagesLoaded.clear(); + imagesLoaded.fill(false,slides); + + imagesSetted.clear(); + imagesSetted.fill(false,slides); + + numImagesLoaded = 0; + + connect(flow, SIGNAL(centerIndexChanged(int)), this, SLOT(preload())); + connect(flow, SIGNAL(centerIndexChangedSilent(int)), this, SLOT(preload())); + + ready = true; + worker->reset(); + + si->start(); +} + +void GoToFlow::reset() +{ + updateTimer->stop(); + /*imagesLoaded.clear(); + numImagesLoaded = 0; + imagesReady.clear(); + rawImages.clear();*/ + ready = false; +} + +void GoToFlow::setImageReady(int index,const QByteArray & image) +{ + rawImages[index]=image; + imagesReady[index]=true; + preload(); +} + +void GoToFlow::preload() +{ + if(numImagesLoaded < imagesLoaded.size()) + updateTimer->start(30); //TODO comprobar rendimiento, antes era 70 +} + +void GoToFlow::updateImageData() +{ + // can't do anything, wait for the next possibility + if(worker->busy()) + return; + + // set image of last one + int idx = worker->index(); + if( idx >= 0 && !worker->result().isNull()) + { + if(!imagesSetted[idx]) + { + flow->setSlide(idx, worker->result()); + imagesSetted[idx] = true; + numImagesLoaded++; + rawImages[idx].clear();; //release memory + imagesLoaded[idx]=true; + } + + } + + // try to load only few images on the left and right side + // i.e. all visible ones plus some extra +#define COUNT 8 + int indexes[2*COUNT+1]; + int center = flow->centerIndex(); + indexes[0] = center; + for(int j = 0; j < COUNT; j++) + { + indexes[j*2+1] = center+j+1; + indexes[j*2+2] = center-j-1; + } + for(int c = 0; c < 2*COUNT+1; c++) + { + int i = indexes[c]; + if((i >= 0) && (i < flow->slideCount())) + if(!imagesLoaded[i]&&imagesReady[i])//slide(i).isNull()) + { + // schedule thumbnail generation + + worker->generate(i, flow->slideSize(),rawImages[i]); + return; + } + + } + + // no need to generate anything? stop polling... + updateTimer->stop(); +} + +void GoToFlow::wheelEvent(QWheelEvent * event) +{ + if(event->delta()<0) + flow->showNext(); + else + flow->showPrevious(); + event->accept(); +} + +void GoToFlow::setFlowType(FlowType flowType) +{ + flow->setFlowType(flowType); +} + +void GoToFlow::updateSize() //TODO : fix. it doesn't work. +{ + imageSize = Configuration::getConfiguration().getGotoSlideSize(); + flow->setSlideSize(imageSize); + resize(static_cast(5*imageSize.width()),static_cast(imageSize.height()*1.7)); +} + +void GoToFlow::updateConfig(QSettings * settings) +{ + Q_UNUSED(settings) +} +//----------------------------------------------------------------------------- +//SlideInitializer +//----------------------------------------------------------------------------- +SlideInitializer::SlideInitializer(QMutex * m,PictureFlow * flow,int slides) +:QThread(),mutex(m),_flow(flow),_slides(slides) +{ + +} +void SlideInitializer::run() +{ + mutex->lock(); + + _flow->clear(); + for(int i=0;i<_slides;i++) + _flow->addSlide(QImage()); + _flow->setCenterIndex(0); + + mutex->unlock(); +} +//----------------------------------------------------------------------------- +//PageLoader +//----------------------------------------------------------------------------- + + +PageLoader::PageLoader(QMutex * m): +QThread(),mutex(m), restart(false), working(false), idx(-1) +{ +} + +PageLoader::~PageLoader() +{ + mutex->lock(); + condition.wakeOne(); + mutex->unlock(); + wait(); +} + +bool PageLoader::busy() const +{ + return isRunning() ? working : false; +} + +void PageLoader::generate(int index, QSize size,const QByteArray & rImage) +{ + mutex->lock(); + this->idx = index; + //this->img = QImage(); + this->size = size; + this->rawImage = rImage; + mutex->unlock(); + + if (!isRunning()) + start(); + else + { + // already running, wake up whenever ready + restart = true; + condition.wakeOne(); + } +} + +void PageLoader::run() +{ + for(;;) + { + // copy necessary data + mutex->lock(); + this->working = true; + //int idx = this->idx; + + + QImage image; + image.loadFromData(this->rawImage); + // let everyone knows it is ready + image = image.scaled(this->size,Qt::KeepAspectRatio,Qt::SmoothTransformation); + + mutex->unlock(); + + mutex->lock(); + this->working = false; + this->img = image; + mutex->unlock(); + + // put to sleep + mutex->lock(); + if (!this->restart) + condition.wait(mutex); + restart = false; + mutex->unlock(); + } +} diff --git a/YACReader/goto_flow.h b/YACReader/goto_flow.h new file mode 100644 index 00000000..eb2c2112 --- /dev/null +++ b/YACReader/goto_flow.h @@ -0,0 +1,110 @@ +#ifndef __GOTO_FLOW_H +#define __GOTO_FLOW_H + +#include "goto_flow_widget.h" +#include + +#include +#include + +class QLineEdit; +class QPushButton; +class QPixmap; +class QThread; +class QSize; +class QIntValidator; +class QWaitCondition; +class QEvent; +class QLabel; + + +class Comic; +class SlideInitializer; +class PageLoader; +class YACReaderFlow; +class PictureFlow; +class QKeyEvent; + +class GoToFlow : public GoToFlowWidget +{ + Q_OBJECT +public: + GoToFlow(QWidget* parent = 0,FlowType flowType = CoverFlowLike); + ~GoToFlow(); + bool ready; //comic is ready for read. +private: + YACReaderFlow * flow; + void keyPressEvent(QKeyEvent* event); + //Comic * comic; + QSize imageSize; + + QVector imagesLoaded; + QVector imagesSetted; + int numImagesLoaded; + QVector imagesReady; + QVector rawImages; + QTimer* updateTimer; + PageLoader* worker; + virtual void wheelEvent(QWheelEvent * event); + QMutex mutexGoToFlow; + + private slots: + void preload(); + void updateImageData(); + + public slots: + void centerSlide(int slide); + void reset(); + void setNumSlides(unsigned int slides); + void setImageReady(int index,const QByteArray & image); + void setFlowType(FlowType flowType); + void updateSize(); + void updateConfig(QSettings * settings); +signals: + void goToPage(unsigned int page); + +}; +//----------------------------------------------------------------------------- +//SlideInitializer +//----------------------------------------------------------------------------- +class SlideInitializer : public QThread +{ +public: + SlideInitializer(QMutex * m,PictureFlow * flow,int slides); +private: + QMutex * mutex; + PictureFlow * _flow; + int _slides; + void run(); +}; +//----------------------------------------------------------------------------- +//PageLoader +//----------------------------------------------------------------------------- + +class PageLoader : public QThread +{ +public: + PageLoader(QMutex * m); + ~PageLoader(); + // returns FALSE if worker is still busy and can't take the task + bool busy() const; + void generate(int index, QSize size,const QByteArray & rImage); + void reset(){idx = -1;}; + int index() const { return idx; } + QImage result() const { return img; } +protected: + void run(); +private: + QMutex * mutex; + QWaitCondition condition; + + bool restart; + bool working; + int idx; + + QSize size; + QImage img; + QByteArray rawImage; +}; + +#endif diff --git a/YACReader/goto_flow_decorationbar.cpp b/YACReader/goto_flow_decorationbar.cpp new file mode 100644 index 00000000..c9ef2fbb --- /dev/null +++ b/YACReader/goto_flow_decorationbar.cpp @@ -0,0 +1,33 @@ +#include "goto_flow_decorationbar.h" + +#include +#include + +GoToFlowDecorationBar::GoToFlowDecorationBar(QWidget * parent) +:QWidget(parent) +{ + QHBoxLayout * topBar = new QHBoxLayout(); + + QLabel * imgTopLeft = new QLabel(); + QLabel * imgTopRight = new QLabel(); + QLabel * imgTopMiddle = new QLabel(); + QPixmap pL(":/images/imgTopLeft.png"); + QPixmap pM(":/images/imgTopMiddle.png"); + QPixmap pR(":/images/imgTopRight.png"); + imgTopLeft->setPixmap(pL); + imgTopRight->setPixmap(pR); + imgTopMiddle->setPixmap(pM); + imgTopMiddle->setScaledContents(true); + + topBar->addWidget(imgTopLeft); + topBar->addWidget(imgTopMiddle); + topBar->addWidget(imgTopRight); + topBar->setStretchFactor(imgTopLeft,0); + topBar->setStretchFactor(imgTopMiddle,1); + topBar->setStretchFactor(imgTopRight,0); + + topBar->setMargin(0); + topBar->setSpacing(0); + + setLayout(topBar); +} \ No newline at end of file diff --git a/YACReader/goto_flow_decorationbar.h b/YACReader/goto_flow_decorationbar.h new file mode 100644 index 00000000..10397124 --- /dev/null +++ b/YACReader/goto_flow_decorationbar.h @@ -0,0 +1,13 @@ +#ifndef GOTO_FLOW_DECORATIONBAR_H +#define GOTO_FLOW_DECORATIONBAR_H + +#include + +class GoToFlowDecorationBar : public QWidget +{ + Q_OBJECT + public: + GoToFlowDecorationBar(QWidget * parent = 0); +}; + +#endif \ No newline at end of file diff --git a/YACReader/goto_flow_gl.cpp b/YACReader/goto_flow_gl.cpp new file mode 100644 index 00000000..8f315c7d --- /dev/null +++ b/YACReader/goto_flow_gl.cpp @@ -0,0 +1,158 @@ +#include "goto_flow_gl.h" + +#include +#include +#include +#include +#include +#include + +#include "configuration.h" + +#include "goto_flow_toolbar.h" +#include "goto_flow_decorationbar.h" + +GoToFlowGL::GoToFlowGL(QWidget* parent, FlowType flowType) + :GoToFlowWidget(parent) +{ + Q_UNUSED(flowType) + flow = new YACReaderPageFlowGL(this); + flow->setShowMarks(false); + + imageSize = Configuration::getConfiguration().getGotoSlideSize(); + + flow->setSlideSize(imageSize); + connect(flow,SIGNAL(centerIndexChanged(int)),this,SLOT(setPageNumber(int))); + connect(flow,SIGNAL(selected(unsigned int)),this,SIGNAL(goToPage(unsigned int))); + + connect(toolBar,SIGNAL(goTo(unsigned int)),this,SIGNAL(goToPage(unsigned int))); + connect(toolBar,SIGNAL(setCenter(unsigned int)),flow,SLOT(setCenterIndex(unsigned int))); + + mainLayout->insertWidget(1,flow); + mainLayout->setStretchFactor(flow,1); + + resize(static_cast(5*imageSize.width()),static_cast(imageSize.height()*1.7)); + + this->setCursor(QCursor(Qt::ArrowCursor)); +} + +GoToFlowGL::~GoToFlowGL() +{ + delete flow; +} + +void GoToFlowGL::reset() +{ + flow->reset(); +} + +void GoToFlowGL::centerSlide(int slide) +{ + if(flow->centerIndex()!=slide) + { + flow->setCenterIndex(slide); + } +} + +void GoToFlowGL::setFlowType(FlowType flowType) +{ + if(flowType == CoverFlowLike) + flow->setPreset(presetYACReaderFlowClassicConfig); + else if(flowType == Strip) + flow->setPreset(presetYACReaderFlowStripeConfig); + else if(flowType == StripOverlapped) + flow->setPreset(presetYACReaderFlowOverlappedStripeConfig); + else + flow->setPreset(defaultYACReaderFlowConfig); +} + +void GoToFlowGL::setNumSlides(unsigned int slides) +{ + flow->populate(slides); + toolBar->setTop(slides); +} +void GoToFlowGL::setImageReady(int index,const QByteArray & imageData) +{ + flow->rawImages[index] = imageData; + flow->imagesReady[index] = true; +} + +void GoToFlowGL::updateSize() +{ + +} + +void GoToFlowGL::updateConfig(QSettings * settings) +{ + Performance performance = medium; + + switch (settings->value(PERFORMANCE).toInt()) + { + case 0: + performance = low; + break; + case 1: + performance = medium; + break; + case 2: + performance = high; + break; + case 3: + performance = ultraHigh; + break; + } + + flow->setPerformance(performance); + + switch (settings->value(FLOW_TYPE_GL).toInt()) + { + case 0: + flow->setPreset(presetYACReaderFlowClassicConfig); + return; + case 1: + flow->setPreset(presetYACReaderFlowStripeConfig); + return; + case 2: + flow->setPreset(presetYACReaderFlowOverlappedStripeConfig); + return; + case 3: + flow->setPreset(defaultYACReaderFlowConfig); + return; + case 4: + flow->setPreset(pressetYACReaderFlowDownConfig); + return; + } + + + //custom config + + flow->setCF_RX(settings->value(X_ROTATION).toInt()); + flow->setCF_Y(settings->value(Y_POSITION).toInt()); + flow->setX_Distance(settings->value(COVER_DISTANCE).toInt()); + flow->setCenter_Distance(settings->value(CENTRAL_DISTANCE).toInt()); + flow->setCF_Z(settings->value(ZOOM_LEVEL).toInt()); + flow->setY_Distance(settings->value(Y_COVER_OFFSET).toInt()); + flow->setZ_Distance(settings->value(Z_COVER_OFFSET).toInt()); + flow->setRotation(settings->value(COVER_ROTATION).toInt()); + flow->setFadeOutDist(settings->value(FADE_OUT_DIST).toInt()); + flow->setLightStrenght(settings->value(LIGHT_STRENGTH).toInt()); + flow->setMaxAngle(settings->value(MAX_ANGLE).toInt()); + +/* flow->setVisibility(settings->value("visibilityDistance").toInt()); + flow->setLightStrenght(settings->value("lightStrength").toInt())*/; + +} + +void GoToFlowGL::keyPressEvent(QKeyEvent* event) +{ + switch (event->key()) + { + case Qt::Key_Left: case Qt::Key_Right: case Qt::Key_Up: + QApplication::sendEvent(flow,event); + return; + default: + break; + } + + GoToFlowWidget::keyPressEvent(event); +} diff --git a/YACReader/goto_flow_gl.h b/YACReader/goto_flow_gl.h new file mode 100644 index 00000000..5b6ed1b5 --- /dev/null +++ b/YACReader/goto_flow_gl.h @@ -0,0 +1,39 @@ +#ifndef __GOTO_FLOW_GL_H +#define __GOTO_FLOW_GL_H + +#include "yacreader_global.h" +#include "goto_flow_widget.h" +#include "yacreader_flow_gl.h" + +class QLineEdit; +class QIntValidator; +class QPushButton; +class QPushButton; +class QSize; +class QKeyEvent; + +class GoToFlowGL : public GoToFlowWidget +{ + Q_OBJECT +public: + GoToFlowGL(QWidget* parent = 0,FlowType flowType = CoverFlowLike); + ~GoToFlowGL(); + void reset(); + void centerSlide(int slide); + void setFlowType(FlowType flowType); + void setNumSlides(unsigned int slides); + void setImageReady(int index,const QByteArray & image); + void updateSize(); + + void updateConfig(QSettings * settings); + +signals: + void goToPage(unsigned int page); +private: + YACReaderPageFlowGL * flow; + void keyPressEvent(QKeyEvent* event); + //Comic * comic; + QSize imageSize; +}; + +#endif diff --git a/YACReader/goto_flow_toolbar.cpp b/YACReader/goto_flow_toolbar.cpp new file mode 100644 index 00000000..d1e4fe62 --- /dev/null +++ b/YACReader/goto_flow_toolbar.cpp @@ -0,0 +1,122 @@ +#include "goto_flow_toolbar.h" + +#include +#include +#include +#include +#include +#include +#include + +GoToFlowToolBar::GoToFlowToolBar(QWidget * parent) + :QWidget(parent) +{ + //fondo + QBoxLayout * background = new QHBoxLayout(this); + + QLabel * imgBottomLeft = new QLabel(this); + QLabel * imgBottomRight = new QLabel(this); + QLabel * imgBottomMiddle = new QLabel(this); + QPixmap pBL(":/images/imgBottomLeft.png"); + QPixmap pBM(":/images/imgBottomMiddle.png"); + QPixmap pBR(":/images/imgBottomRight.png"); + imgBottomLeft->setPixmap(pBL); + imgBottomRight->setPixmap(pBR); + imgBottomMiddle->setPixmap(pBM); + imgBottomMiddle->setScaledContents(true); + //imgTop->setStyleSheet("background-image: url(:/images/numPagesLabel.png); width: 100%; height:100%; background-repeat: none; border: none"); + + background->addWidget(imgBottomLeft); + background->addWidget(imgBottomMiddle); + background->addWidget(imgBottomRight); + background->setStretchFactor(imgBottomLeft,0); + background->setStretchFactor(imgBottomMiddle,1); + background->setStretchFactor(imgBottomRight,0); + + background->setMargin(0); + background->setSpacing(0); + + //elementos interactivos + //QVBoxLayout * mainLayout = new QVBoxLayout; + bar = new QWidget(this); + QHBoxLayout * bottom = new QHBoxLayout(bar); + bottom->addStretch(); + bottom->addWidget(new QLabel(tr("Page : "),bar)); + bottom->addWidget(edit = new QLineEdit(bar)); + v = new QIntValidator(bar); + v->setBottom(1); + edit->setValidator(v); + edit->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit->setStyleSheet("background-image: url(:/images/imgEdit.png); width: 100%; height:100%; background-repeat: none; border: none; padding: 3px; color: white;"); + QPixmap p(":/images/imgEdit.png"); + edit->setFixedSize(54,50); + edit->setAttribute(Qt::WA_MacShowFocusRect,false); + edit->setAttribute(Qt::WA_LayoutUsesWidgetRect,true); + //edit->resize(QSize(54,50)); + edit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed)); + edit->setAutoFillBackground(false); + connect(edit,SIGNAL(returnPressed()),this,SLOT(goTo())); + + QString centerButtonCSS = "QPushButton {background-image: url(:/images/imgCenterSlide.png); width: 100%; height:100%; background-repeat: none; border: none;} " + "QPushButton:focus { border: none; outline: none;}" + "QPushButton:pressed {background-image: url(:/images/imgCenterSlidePressed.png); width: 100%; height:100%; background-repeat: none; border: none;} "; + centerButton = new QPushButton(bar); + //centerButton->setIcon(QIcon(":/images/center.png")); + centerButton->setStyleSheet(centerButtonCSS); + centerButton->setFixedSize(26,50); + centerButton->setAttribute(Qt::WA_LayoutUsesWidgetRect,true); + connect(centerButton,SIGNAL(clicked()),this,SLOT(centerSlide())); + bottom->addWidget(centerButton); + + QString goToButtonCSS = "QPushButton {background-image: url(:/images/imgGoToSlide.png); width: 100%; height:100%; background-repeat: none; border: none;} " + "QPushButton:focus { border: none; outline: none;}" + "QPushButton:pressed {background-image: url(:/images/imgGoToSlidePressed.png); width: 100%; height:100%; background-repeat: none; border: none;} "; + goToButton = new QPushButton(bar); + //goToButton->setIcon(QIcon(":/images/goto.png")); + goToButton->setStyleSheet(goToButtonCSS); + goToButton->setFixedSize(32,50); + goToButton->setAttribute(Qt::WA_LayoutUsesWidgetRect,true); + + connect(goToButton,SIGNAL(clicked()),this,SLOT(goTo())); + bottom->addWidget(goToButton); + + bottom->addStretch(); + bottom->setMargin(0); + bottom->setSpacing(0); + + bar->setLayout(bottom); + //mainLayout->addWidget(bar); + setLayout(background); + bar->setGeometry(QRect(0,0,400,50)); + +} + +void GoToFlowToolBar::setPage(int pageNumber) +{ + edit->setText(QString::number(pageNumber+1)); +} + +void GoToFlowToolBar::setTop(int numPages) +{ + v->setTop(numPages); +} + +void GoToFlowToolBar::resizeEvent(QResizeEvent * event) +{ + + bar->setGeometry(QRect(0,(event->size().height()-50)+((50-bar->height())/2),event->size().width(),50)); + + QWidget::resizeEvent(event); +} + +void GoToFlowToolBar::goTo() +{ + if(edit->text().toInt()!=0) + emit(goTo(edit->text().toInt()-1)); +} + +void GoToFlowToolBar::centerSlide() +{ + if(edit->text().toInt()!=0) + emit(setCenter(edit->text().toInt()-1)); +} \ No newline at end of file diff --git a/YACReader/goto_flow_toolbar.h b/YACReader/goto_flow_toolbar.h new file mode 100644 index 00000000..0fe6694d --- /dev/null +++ b/YACReader/goto_flow_toolbar.h @@ -0,0 +1,33 @@ +#ifndef GOTO_FLOW_TOOLBAR_H +#define GOTO_FLOW_TOOLBAR_H + +#include + +class QLineEdit; +class QIntValidator; +class QPushButton; + +class GoToFlowToolBar : public QWidget +{ + Q_OBJECT + private: + QLineEdit * edit; + QIntValidator * v; + QPushButton * centerButton; + QPushButton * goToButton; + QWidget * bar; + void resizeEvent(QResizeEvent * event); + + public: + GoToFlowToolBar(QWidget * parent = 0); + public slots: + void setPage(int pageNumber); + void setTop(int numPages); + void goTo(); + void centerSlide(); + signals: + void setCenter(unsigned int); + void goTo(unsigned int); +}; + +#endif \ No newline at end of file diff --git a/YACReader/goto_flow_widget.cpp b/YACReader/goto_flow_widget.cpp new file mode 100644 index 00000000..1f0c98c8 --- /dev/null +++ b/YACReader/goto_flow_widget.cpp @@ -0,0 +1,75 @@ +#include "goto_flow_widget.h" + +#include +#include +#include +#include + +#include "goto_flow_toolbar.h" +#include "goto_flow_decorationbar.h" + +GoToFlowWidget::GoToFlowWidget(QWidget * parent) + :QWidget(parent) +{ + mainLayout = new QVBoxLayout; + + mainLayout->setMargin(0); + mainLayout->setSpacing(0); + + topBar = new GoToFlowDecorationBar(this); + toolBar = new GoToFlowToolBar(this); + + mainLayout->addWidget(topBar); + mainLayout->addWidget(toolBar); + + mainLayout->setMargin(0); + mainLayout->setSpacing(0); + + setLayout(mainLayout); + + //toolBar->installEventFilter(this); +} + +GoToFlowWidget::~GoToFlowWidget() { + delete topBar; + delete toolBar; + delete mainLayout; +} + +void GoToFlowWidget::setPageNumber(int page) +{ + toolBar->setPage(page); +} + +void GoToFlowWidget::keyPressEvent(QKeyEvent* event) +{ + switch (event->key()) + { + case Qt::Key_Return: case Qt::Key_Enter: + toolBar->goTo(); + toolBar->centerSlide(); + break; + case Qt::Key_Space: + toolBar->centerSlide(); + break; + case Qt::Key_S: + QCoreApplication::sendEvent(this->parent(),event); + break; + } + + event->accept(); +} + +/*bool GoToFlowWidget::eventFilter(QObject * target, QEvent * event) +{ + if(event->type() == QEvent::KeyPress) + { + QKeyEvent * e = static_cast(event); + if(e->key()==Qt::Key_S || e->key() == Qt::Key_Space) + { + this->keyPressEvent(e); + return true; + } + } + return QWidget::eventFilter(target,event); +}*/ diff --git a/YACReader/goto_flow_widget.h b/YACReader/goto_flow_widget.h new file mode 100644 index 00000000..e4f42b2c --- /dev/null +++ b/YACReader/goto_flow_widget.h @@ -0,0 +1,41 @@ +#ifndef __GOTO_FLOW_WIDGET_H +#define __GOTO_FLOW_WIDGET_H + +#include +#include +#include "yacreader_global.h" + +using namespace YACReader; + +class QSettings; +class GoToFlowDecorationBar; +class GoToFlowToolBar; +class QVBoxLayout; + +class GoToFlowWidget : public QWidget +{ + Q_OBJECT +protected: + QVBoxLayout * mainLayout; + GoToFlowDecorationBar * topBar; + GoToFlowToolBar * toolBar; +public: + GoToFlowWidget(QWidget * paret = 0); + virtual ~GoToFlowWidget() = 0; +public slots: + virtual void reset() = 0; + virtual void centerSlide(int slide) = 0; + virtual void setPageNumber(int page); + virtual void setFlowType(FlowType flowType) = 0; + virtual void setNumSlides(unsigned int slides) = 0; + virtual void setImageReady(int index,const QByteArray & image) = 0; + virtual void updateSize() = 0; + virtual void updateConfig(QSettings * settings) = 0; + +protected: + void keyPressEvent(QKeyEvent* event); + //bool eventFilter(QObject *, QEvent *); + +}; + +#endif diff --git a/YACReader/icon.ico b/YACReader/icon.ico new file mode 100644 index 00000000..6c31de5a Binary files /dev/null and b/YACReader/icon.ico differ diff --git a/YACReader/icon.rc b/YACReader/icon.rc new file mode 100644 index 00000000..86e8e9b3 --- /dev/null +++ b/YACReader/icon.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "icon.ico" diff --git a/YACReader/magnifying_glass.cpp b/YACReader/magnifying_glass.cpp new file mode 100644 index 00000000..c86f202e --- /dev/null +++ b/YACReader/magnifying_glass.cpp @@ -0,0 +1,292 @@ +#include "magnifying_glass.h" +#include "viewer.h" +#include "configuration.h" +#include "shortcuts_manager.h" + +#include + +MagnifyingGlass::MagnifyingGlass(int w, int h, QWidget * parent) +:QLabel(parent),zoomLevel(0.5) +{ + setup(QSize(w,h)); +} + +MagnifyingGlass::MagnifyingGlass(const QSize & size, QWidget * parent) +:QLabel(parent),zoomLevel(0.5) +{ + setup(size); +} + +void MagnifyingGlass::setup(const QSize & size) +{ + resize(size); + setScaledContents(true); + setMouseTracking(true); + setCursor(QCursor(QBitmap(1,1),QBitmap(1,1))); +} + +void MagnifyingGlass::mouseMoveEvent(QMouseEvent * event) +{ + updateImage(); + event->accept(); +} + +void MagnifyingGlass::updateImage(int x, int y) +{ + //image section augmented + int zoomWidth = static_cast(width() * zoomLevel); + int zoomHeight = static_cast(height() * zoomLevel); + Viewer * p = (Viewer *)parent(); + int currentPos = p->verticalScrollBar()->sliderPosition(); + const QPixmap * image = p->pixmap(); + int iWidth = image->width(); + int iHeight = image->height(); + float wFactor = static_cast(iWidth) / p->widget()->width(); + float hFactor = static_cast(iHeight) / p->widget()->height(); + zoomWidth *= wFactor; + zoomHeight *= hFactor; + if(p->verticalScrollBar()->minimum()==p->verticalScrollBar()->maximum()) + { + int xp = static_cast(((x-p->widget()->pos().x())*wFactor)-zoomWidth/2); + int yp = static_cast((y-p->widget()->pos().y()+currentPos)*hFactor-zoomHeight/2); + int xOffset=0; + int yOffset=0; + int zw=zoomWidth; + int zh=zoomHeight; + //int wOffset,hOffset=0; + bool outImage = false; + if(xp<0) + { + xOffset = -xp; + xp=0; + zw = zw - xOffset; + outImage = true; + } + if(yp<0) + { + yOffset = -yp; + yp=0; + zh = zh - yOffset; + outImage = true; + } + + if(xp+zoomWidth >= image->width()) + { + zw -= xp+zw - image->width(); + outImage = true; + } + if(yp+zoomHeight >= image->height()) + { + zh -= yp+zh - image->height(); + outImage = true; + } + if(outImage) + { + QImage img(zoomWidth,zoomHeight,QImage::Format_RGB32); + img.fill(Configuration::getConfiguration().getBackgroundColor()); + if(zw>0&&zh>0) + { + QPainter painter(&img); + painter.drawPixmap(xOffset,yOffset,p->pixmap()->copy(xp,yp,zw,zh)); + } + setPixmap(QPixmap().fromImage(img)); + } + else + setPixmap(p->pixmap()->copy(xp,yp,zoomWidth,zoomHeight)); + } + else + { + int xp = static_cast(((x-p->widget()->pos().x())*wFactor)-zoomWidth/2); + int yp = static_cast((y+currentPos)*hFactor-zoomHeight/2); + int xOffset=0; + int yOffset=0; + int zw=zoomWidth; + int zh=zoomHeight; + //int wOffset,hOffset=0; + bool outImage = false; + if(xp<0) + { + xOffset = -xp; + xp=0; + zw = zw - xOffset; + outImage = true; + } + if(yp<0) + { + yOffset = -yp; + yp=0; + zh = zh - yOffset; + outImage = true; + } + + if(xp+zoomWidth >= image->width()) + { + zw -= xp+zw - image->width(); + outImage = true; + } + if(yp+zoomHeight >= image->height()) + { + zh -= yp+zh - image->height(); + outImage = true; + } + if(outImage) + { + QImage img(zoomWidth,zoomHeight,QImage::Format_RGB32); + img.fill(Configuration::getConfiguration().getBackgroundColor()); + if(zw>0&&zh>0) + { + QPainter painter(&img); + painter.drawPixmap(xOffset,yOffset,p->pixmap()->copy(xp,yp,zw,zh)); + } + setPixmap(QPixmap().fromImage(img)); + } + else + setPixmap(p->pixmap()->copy(xp,yp,zoomWidth,zoomHeight)); + } + move(static_cast(x-float(width())/2),static_cast(y-float(height())/2)); +} + +void MagnifyingGlass::updateImage() +{ + if(isVisible()) + { + QPoint p = QPoint(cursor().pos().x(),cursor().pos().y()); + p = this->parentWidget()->mapFromGlobal(p); + updateImage(p.x(),p.y()); + } +} +void MagnifyingGlass::wheelEvent(QWheelEvent * event) +{ + switch(event->modifiers()) + { + //size + case Qt::NoModifier: + if(event->delta()<0) + sizeUp(); + else + sizeDown(); + break; + //size height + case Qt::ControlModifier: + if(event->delta()<0) + heightUp(); + else + heightDown(); + break; + //size width + case Qt::AltModifier: + if(event->delta()<0) + widthUp(); + else + widthDown(); + break; + //zoom level + case Qt::ShiftModifier: + if(event->delta()<0) + zoomIn(); + else + zoomOut(); + break; + } + updateImage(); + event->setAccepted(true); +} +void MagnifyingGlass::zoomIn() +{ + if(zoomLevel>0.2f) + zoomLevel -= 0.025f; +} + +void MagnifyingGlass::zoomOut() +{ + if(zoomLevel<0.9f) + zoomLevel += 0.025f; +} + +void MagnifyingGlass::sizeUp() +{ + Viewer * p = (Viewer *)parent(); + if(width()<(p->width()*0.90f)) + resize(width()+30,height()+15); +} + +void MagnifyingGlass::sizeDown() +{ + if(width()>175) + resize(width()-30,height()-15); +} + +void MagnifyingGlass::heightUp() +{ + Viewer * p = (Viewer *)parent(); + if(height()<(p->height()*0.90f)) + resize(width(),height()+15); +} + +void MagnifyingGlass::heightDown() +{ + if(height()>80) + resize(width(),height()-15); +} + +void MagnifyingGlass::widthUp() +{ + Viewer * p = (Viewer *)parent(); + if(width()<(p->width()*0.90f)) + resize(width()+30,height()); +} + +void MagnifyingGlass::widthDown() +{ + if(width()>175) + resize(width()-30,height()); +} + +void MagnifyingGlass::keyPressEvent(QKeyEvent *event) +{ + bool validKey = false; + + int _key = event->key(); + Qt::KeyboardModifiers modifiers = event->modifiers(); + + if(modifiers & Qt::ShiftModifier) + _key |= Qt::SHIFT; + if (modifiers & Qt::ControlModifier) + _key |= Qt::CTRL; + if (modifiers & Qt::MetaModifier) + _key |= Qt::META; + if (modifiers & Qt::AltModifier) + _key |= Qt::ALT; + + QKeySequence key(_key); + + if (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y)) + { + sizeUp(); + validKey = true; + } + + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y)) + { + sizeDown(); + validKey = true; + } + + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y)) + { + zoomIn(); + validKey = true; + } + + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y)) + { + zoomOut(); + validKey = true; + } + + if(validKey) + { + updateImage(); + event->setAccepted(true); + } +} diff --git a/YACReader/magnifying_glass.h b/YACReader/magnifying_glass.h new file mode 100644 index 00000000..519e3404 --- /dev/null +++ b/YACReader/magnifying_glass.h @@ -0,0 +1,34 @@ +#ifndef __MAGNIFYING_GLASS +#define __MAGNIFYING_GLASS + +#include +#include +#include +#include + + class MagnifyingGlass : public QLabel + { + Q_OBJECT + private: + float zoomLevel; + void setup(const QSize & size); + void keyPressEvent(QKeyEvent * event); + public: + MagnifyingGlass(int width,int height,QWidget * parent); + MagnifyingGlass(const QSize & size, QWidget * parent); + void mouseMoveEvent(QMouseEvent * event); + public slots: + void updateImage(int x, int y); + void updateImage(); + void wheelEvent(QWheelEvent * event); + void zoomIn(); + void zoomOut(); + void sizeUp(); + void sizeDown(); + void heightUp(); + void heightDown(); + void widthUp(); + void widthDown(); + }; + +#endif diff --git a/YACReader/main.cpp b/YACReader/main.cpp new file mode 100644 index 00000000..fd01d04e --- /dev/null +++ b/YACReader/main.cpp @@ -0,0 +1,172 @@ +#include +#include +#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "main_window_viewer.h" +#include "configuration.h" +#include "exit_check.h" + +#include "QsLog.h" +#include "QsLogDest.h" + +using namespace QsLogging; + + #if defined(WIN32) && defined(_DEBUG) + #define _CRTDBG_MAP_ALLOC + #include + #include + #define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ ) + #define new DEBUG_NEW + #endif + +#ifdef Q_OS_MAC +#include +class YACReaderApplication: public QApplication +{ + public: + YACReaderApplication(int & argc, char ** argv) : QApplication(argc,argv) + {} + + void setWindow(MainWindowViewer * w) + { + window = w; + } + + protected: + bool event(QEvent * event) + { + switch(event->type()) + { + case QEvent::FileOpen: + window->openComicFromPath(static_cast(event)->file()); + return true; + default: + return QApplication::event(event); + } + } + private: + MainWindowViewer * window; +}; +#endif + +int main(int argc, char * argv[]) +{ + + #if defined(_MSC_VER) && defined(_DEBUG) + _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); +#endif + +//fix for misplaced text in Qt4.8 and Mavericks +#ifdef Q_OS_MAC + #if QT_VERSION < 0x050000 + if(QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) + QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); + #endif +#endif + + +#ifdef Q_OS_MAC + YACReaderApplication app(argc,argv); +#else + QApplication app(argc, argv); +#endif + +#ifdef FORCE_ANGLE + app.setAttribute(Qt::AA_UseOpenGLES); +#endif + + app.setApplicationName("YACReader"); + app.setOrganizationName("YACReader"); + app.setAttribute(Qt::AA_UseHighDpiPixmaps); + //simple command line parser + //will be replaced by QCommandLineParser in the future + QStringList optlist; + QStringList arglist; + + if (argc > 1) + { + //extract options and arguments + optlist = QCoreApplication::arguments().filter(QRegExp ("^-{1,2}")); //options starting with "-" + arglist = QCoreApplication::arguments().filter(QRegExp ("^(?!-{1,2})")); //positional arguments + //deal with standard options + if (!optlist.isEmpty()) + { + QTextStream parser(stdout); + if (optlist.contains("--version") || optlist.contains("-v")) + { + parser << app.applicationName() << " " << QString(VERSION) << endl << "Copyright 2014 by Luis Angel San Martin Rodriguez" << endl; + return 0; + } + if (optlist.contains("--help") || optlist.contains("-h")) + { + parser << endl << "Usage: YACReader [File|Directory|Option]" << endl << endl; + parser << "Options:" << endl; + parser << " -h, --help\t\tDisplay this text and exit." << endl; + parser << " -v, --version\t\tDisplay version information and exit." << endl << endl; + parser << "Arguments:" << endl; + parser << " file\t\t\tOpen comic file." < 1) + { + if (!optlist.filter("--comicId=").isEmpty() && !optlist.filter("--libraryId=").isEmpty()) + { + if (arglist.count()>1) + { + mwv->open(arglist.at(1), optlist.filter("--comicId=").at(0).split("=").at(1).toULongLong(), optlist.filter("--libraryId=").at(0).split("=").at(1).toULongLong()); + } + } + else if ((arglist.count()>1)) + { + //open first positional argument, silently ignore all following positional arguments + mwv->openComicFromPath(arglist.at(1)); + } + } +#ifdef Q_OS_MAC + app.setWindow(mwv); +#endif + mwv->show(); + + int ret = app.exec(); + + //Configuration::getConfiguration().save(); + + YACReader::exitCheck(ret); + + return ret; +} diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp new file mode 100644 index 00000000..06b0269b --- /dev/null +++ b/YACReader/main_window_viewer.cpp @@ -0,0 +1,1400 @@ +#include "main_window_viewer.h" +#include "configuration.h" +#include "viewer.h" +#include "goto_dialog.h" +#include "custom_widgets.h" +#include "options_dialog.h" +#include "check_new_version.h" +#include "comic.h" +#include "bookmarks_dialog.h" +#include "shortcuts_dialog.h" +#include "width_slider.h" +#include "qnaturalsorting.h" +#include "help_about_dialog.h" +#include "yacreader_tool_bar_stretch.h" + +#include "comic_db.h" +#include "yacreader_local_client.h" + +#include "yacreader_global.h" +#include "edit_shortcuts_dialog.h" +#include "shortcuts_manager.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* TODO remove, no longer used +#ifdef Q_OS_MAC +class MacToolBarSeparator : public QWidget +{ +public: + MacToolBarSeparator(QWidget * parent =0) + :QWidget(parent) + { + setFixedWidth(2); + } + + void paintEvent(QPaintEvent *event) + { + Q_UNUSED(event); + QPainter painter(this); + + QLinearGradient lG(0,0,0,height()); + + lG.setColorAt(0,QColor(128,128,128,0)); + lG.setColorAt(0.5,QColor(128,128,128,255)); + lG.setColorAt(1,QColor(128,128,128,0)); + + painter.fillRect(0,0,1,height(),lG); + + QLinearGradient lG2(1,0,1,height()); + + lG2.setColorAt(0,QColor(220,220,220,0)); + lG2.setColorAt(0.5,QColor(220,220,220,255)); + lG2.setColorAt(1,QColor(220,220,220,0)); + + painter.fillRect(1,0,1,height(),lG2); + } +}; +#endif*/ + +MainWindowViewer::MainWindowViewer() +:QMainWindow(),fullscreen(false),toolbars(true),alwaysOnTop(false),currentDirectory("."),currentDirectoryImgDest("."),isClient(false) +{ + loadConfiguration(); + setupUI(); +} + +MainWindowViewer::~MainWindowViewer() +{ + delete settings; + delete viewer; + delete had; + + delete sliderAction; + delete openAction; + delete openFolderAction; + delete saveImageAction; + delete openPreviousComicAction; + delete openNextComicAction; + delete prevAction; + delete nextAction; + delete adjustHeightAction; + delete adjustWidthAction; + delete leftRotationAction; + delete rightRotationAction; + delete doublePageAction; + delete doubleMangaPageAction; + delete goToPageAction; + delete optionsAction; + delete helpAboutAction; + delete showMagnifyingGlassAction; + delete setBookmarkAction; + delete showBookmarksAction; + delete showShorcutsAction; + delete showInfoAction; + delete closeAction; + delete showDictionaryAction; + delete alwaysOnTopAction; + delete adjustToFullSizeAction; + delete showFlowAction; + +} +void MainWindowViewer::loadConfiguration() +{ + settings = new QSettings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat); + + Configuration & config = Configuration::getConfiguration(); + config.load(settings); + currentDirectory = config.getDefaultPath(); + fullscreen = config.getFullScreen(); +} + +void MainWindowViewer::setupUI() +{ + setWindowIcon(QIcon(":/images/icon.png")); + + //setUnifiedTitleAndToolBarOnMac(true); + + viewer = new Viewer(this); + connect(viewer,SIGNAL(reset()),this,SLOT(processReset())); + //detected end of comic + connect(viewer,SIGNAL(openNextComic()),this,SLOT(openNextComic())); + //detected start of comic + connect(viewer,SIGNAL(openPreviousComic()),this,SLOT(openPreviousComic())); + + setCentralWidget(viewer); + int heightDesktopResolution = QApplication::desktop()->screenGeometry().height(); + int widthDesktopResolution = QApplication::desktop()->screenGeometry().width(); + int height,width; + height = static_cast(heightDesktopResolution*0.84); + width = static_cast(height*0.70); + Configuration & conf = Configuration::getConfiguration(); + QPoint p = conf.getPos(); + QSize s = conf.getSize(); + if(s.width()!=0) + { + move(p); + resize(s); + } + else + { + move(QPoint((widthDesktopResolution-width)/2,((heightDesktopResolution-height)-40)/2)); + resize(QSize(width,height)); + } + + had = new HelpAboutDialog(this); //TODO load data + + had->loadAboutInformation(":/files/about.html"); + had->loadHelp(":/files/helpYACReader.html"); + + optionsDialog = new OptionsDialog(this); + connect(optionsDialog,SIGNAL(accepted()),viewer,SLOT(updateOptions())); + connect(optionsDialog,SIGNAL(fitToWidthRatioChanged(float)),viewer,SLOT(updateFitToWidthRatio(float))); + connect(optionsDialog, SIGNAL(optionsChanged()),this,SLOT(reloadOptions())); + connect(optionsDialog,SIGNAL(changedFilters(int,int,int)),viewer,SLOT(updateFilters(int,int,int))); + + optionsDialog->restoreOptions(settings); + //shortcutsDialog = new ShortcutsDialog(this); + editShortcutsDialog = new EditShortcutsDialog(this); + connect(optionsDialog,SIGNAL(editShortcuts()),editShortcutsDialog,SLOT(show())); + + createActions(); + setUpShortcutsManagement(); + + createToolBars(); + + setWindowTitle("YACReader"); + + checkNewVersion(); + + viewer->setFocusPolicy(Qt::StrongFocus); + + + //if(Configuration::getConfiguration().getAlwaysOnTop()) + //{ + // setWindowFlags(this->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); + //} + + if(fullscreen) + toFullScreen(); + if(conf.getMaximized()) + showMaximized(); + + setAcceptDrops(true); + + if(Configuration::getConfiguration().getShowToolbars() && !Configuration::getConfiguration().getFullScreen()) + showToolBars(); + else + hideToolBars(); +} + +void MainWindowViewer::createActions() +{ + openAction = new QAction(tr("&Open"),this); + openAction->setIcon(QIcon(":/images/viewer_toolbar/open.png")); + openAction->setToolTip(tr("Open a comic")); + openAction->setData(OPEN_ACTION_Y); + openAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_ACTION_Y)); + connect(openAction, SIGNAL(triggered()), this, SLOT(open())); + + openFolderAction = new QAction(tr("Open Folder"),this); + openFolderAction->setIcon(QIcon(":/images/viewer_toolbar/openFolder.png")); + openFolderAction->setToolTip(tr("Open image folder")); + openFolderAction->setData(OPEN_FOLDER_ACTION_Y); + openFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_FOLDER_ACTION_Y)); + connect(openFolderAction, SIGNAL(triggered()), this, SLOT(openFolder())); + + saveImageAction = new QAction(tr("Save"),this); + saveImageAction->setIcon(QIcon(":/images/viewer_toolbar/save.png")); + saveImageAction->setToolTip(tr("Save current page")); + saveImageAction->setDisabled(true); + saveImageAction->setData(SAVE_IMAGE_ACTION_Y); + saveImageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SAVE_IMAGE_ACTION_Y)); + connect(saveImageAction,SIGNAL(triggered()),this,SLOT(saveImage())); + + openPreviousComicAction = new QAction(tr("Previous Comic"),this); + openPreviousComicAction->setIcon(QIcon(":/images/viewer_toolbar/openPrevious.png")); + openPreviousComicAction->setToolTip(tr("Open previous comic")); + openPreviousComicAction->setDisabled(true); + openPreviousComicAction->setData(OPEN_PREVIOUS_COMIC_ACTION_Y); + openPreviousComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_PREVIOUS_COMIC_ACTION_Y)); + connect(openPreviousComicAction,SIGNAL(triggered()),this,SLOT(openPreviousComic())); + + openNextComicAction = new QAction(tr("Next Comic"),this); + openNextComicAction->setIcon(QIcon(":/images/viewer_toolbar/openNext.png")); + openNextComicAction->setToolTip(tr("Open next comic")); + openNextComicAction->setDisabled(true); + openNextComicAction->setData(OPEN_NEXT_COMIC_ACTION_Y); + openNextComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_NEXT_COMIC_ACTION_Y)); + connect(openNextComicAction,SIGNAL(triggered()),this,SLOT(openNextComic())); + + prevAction = new QAction(tr("&Previous"),this); + prevAction->setIcon(QIcon(":/images/viewer_toolbar/previous.png")); + prevAction->setShortcutContext(Qt::WidgetShortcut); + prevAction->setToolTip(tr("Go to previous page")); + prevAction->setDisabled(true); + prevAction->setData(PREV_ACTION_Y); + prevAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(PREV_ACTION_Y)); + connect(prevAction, SIGNAL(triggered()),viewer,SLOT(prev())); + + nextAction = new QAction(tr("&Next"),this); + nextAction->setIcon(QIcon(":/images/viewer_toolbar/next.png")); + nextAction->setShortcutContext(Qt::WidgetShortcut); + nextAction->setToolTip(tr("Go to next page")); + nextAction->setDisabled(true); + nextAction->setData(NEXT_ACTION_Y); + nextAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(NEXT_ACTION_Y)); + connect(nextAction, SIGNAL(triggered()),viewer,SLOT(next())); + + adjustHeightAction = new QAction(tr("Fit Height"),this); + adjustHeightAction->setIcon(QIcon(":/images/viewer_toolbar/toHeight.png")); + //adjustWidth->setCheckable(true); + adjustHeightAction->setDisabled(true); + adjustHeightAction->setChecked(Configuration::getConfiguration().getAdjustToWidth()); + adjustHeightAction->setToolTip(tr("Fit image to height")); + //adjustWidth->setIcon(QIcon(":/images/fitWidth.png")); + adjustHeightAction->setData(ADJUST_HEIGHT_ACTION_Y); + adjustHeightAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADJUST_HEIGHT_ACTION_Y)); + connect(adjustHeightAction, SIGNAL(triggered()),this,SLOT(fitToHeight())); + + adjustWidthAction = new QAction(tr("Fit Width"),this); + adjustWidthAction->setIcon(QIcon(":/images/viewer_toolbar/toWidth.png")); + //adjustWidth->setCheckable(true); + adjustWidthAction->setDisabled(true); + adjustWidthAction->setChecked(Configuration::getConfiguration().getAdjustToWidth()); + adjustWidthAction->setToolTip(tr("Fit image to width")); + //adjustWidth->setIcon(QIcon(":/images/fitWidth.png")); + adjustWidthAction->setData(ADJUST_WIDTH_ACTION_Y); + adjustWidthAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADJUST_WIDTH_ACTION_Y)); + connect(adjustWidthAction, SIGNAL(triggered()),this,SLOT(fitToWidth())); + + leftRotationAction = new QAction(tr("Rotate image to the left"),this); + leftRotationAction->setIcon(QIcon(":/images/viewer_toolbar/rotateL.png")); + leftRotationAction->setDisabled(true); + leftRotationAction->setData(LEFT_ROTATION_ACTION_Y); + leftRotationAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(LEFT_ROTATION_ACTION_Y)); + connect(leftRotationAction, SIGNAL(triggered()),viewer,SLOT(rotateLeft())); + + rightRotationAction = new QAction(tr("Rotate image to the right"),this); + rightRotationAction->setIcon(QIcon(":/images/viewer_toolbar/rotateR.png")); + rightRotationAction->setDisabled(true); + rightRotationAction->setData(RIGHT_ROTATION_ACTION_Y); + rightRotationAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RIGHT_ROTATION_ACTION_Y)); + connect(rightRotationAction, SIGNAL(triggered()),viewer,SLOT(rotateRight())); + + doublePageAction = new QAction(tr("Double page mode"),this); + doublePageAction->setToolTip(tr("Switch to double page mode")); + doublePageAction->setIcon(QIcon(":/images/viewer_toolbar/doublePage.png")); + doublePageAction->setDisabled(true); + doublePageAction->setCheckable(true); + doublePageAction->setChecked(Configuration::getConfiguration().getDoublePage()); + doublePageAction->setData(DOUBLE_PAGE_ACTION_Y); + doublePageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(DOUBLE_PAGE_ACTION_Y)); + connect(doublePageAction, SIGNAL(triggered()),viewer,SLOT(doublePageSwitch())); + + //inversed pictures mode + doubleMangaPageAction = new QAction(tr("Double page manga mode"),this); + doubleMangaPageAction->setToolTip(tr("Reverse reading order in double page mode")); + doubleMangaPageAction->setIcon(QIcon(":/images/viewer_toolbar/doubleMangaPage.png")); + doubleMangaPageAction->setDisabled(true); + doubleMangaPageAction->setCheckable(true); + doubleMangaPageAction->setChecked(Configuration::getConfiguration().getDoubleMangaPage()); + doubleMangaPageAction->setData(DOUBLE_MANGA_PAGE_ACTION_Y); + doubleMangaPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(DOUBLE_MANGA_PAGE_ACTION_Y)); + connect(doubleMangaPageAction, SIGNAL(triggered()),viewer,SLOT(doubleMangaPageSwitch())); + + goToPageAction = new QAction(tr("Go To"),this); + goToPageAction->setIcon(QIcon(":/images/viewer_toolbar/goto.png")); + goToPageAction->setDisabled(true); + goToPageAction->setToolTip(tr("Go to page ...")); + goToPageAction->setData(GO_TO_PAGE_ACTION_Y); + goToPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_PAGE_ACTION_Y)); + connect(goToPageAction, SIGNAL(triggered()),viewer,SLOT(showGoToDialog())); + + optionsAction = new QAction(tr("Options"),this); + optionsAction->setToolTip(tr("YACReader options")); + optionsAction->setData(OPTIONS_ACTION_Y); + optionsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPTIONS_ACTION_Y)); + optionsAction->setIcon(QIcon(":/images/viewer_toolbar/options.png")); + + connect(optionsAction, SIGNAL(triggered()),optionsDialog,SLOT(show())); + + helpAboutAction = new QAction(tr("Help"),this); + helpAboutAction->setToolTip(tr("Help, About YACReader")); + helpAboutAction->setIcon(QIcon(":/images/viewer_toolbar/help.png")); + helpAboutAction->setData(HELP_ABOUT_ACTION_Y); + helpAboutAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(HELP_ABOUT_ACTION_Y)); + connect(helpAboutAction, SIGNAL(triggered()),had,SLOT(show())); + + showMagnifyingGlassAction = new QAction(tr("Magnifying glass"),this); + showMagnifyingGlassAction->setToolTip(tr("Switch Magnifying glass")); + showMagnifyingGlassAction->setIcon(QIcon(":/images/viewer_toolbar/magnifyingGlass.png")); + showMagnifyingGlassAction->setDisabled(true); + showMagnifyingGlassAction->setCheckable(true); + showMagnifyingGlassAction->setData(SHOW_MAGNIFYING_GLASS_ACTION_Y); + showMagnifyingGlassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_MAGNIFYING_GLASS_ACTION_Y)); + connect(showMagnifyingGlassAction, SIGNAL(triggered()),viewer,SLOT(magnifyingGlassSwitch())); + + setBookmarkAction = new QAction(tr("Set bookmark"),this); + setBookmarkAction->setToolTip(tr("Set a bookmark on the current page")); + setBookmarkAction->setIcon(QIcon(":/images/viewer_toolbar/bookmark.png")); + setBookmarkAction->setDisabled(true); + setBookmarkAction->setCheckable(true); + setBookmarkAction->setData(SET_BOOKMARK_ACTION_Y); + setBookmarkAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_BOOKMARK_ACTION_Y)); + connect(setBookmarkAction,SIGNAL(triggered (bool)),viewer,SLOT(setBookmarkAction(bool))); + connect(viewer,SIGNAL(pageAvailable(bool)),setBookmarkAction,SLOT(setEnabled(bool))); + connect(viewer,SIGNAL(pageIsBookmark(bool)),setBookmarkAction,SLOT(setChecked(bool))); + + showBookmarksAction = new QAction(tr("Show bookmarks"),this); + showBookmarksAction->setToolTip(tr("Show the bookmarks of the current comic")); + showBookmarksAction->setIcon(QIcon(":/images/viewer_toolbar/showBookmarks.png")); + showBookmarksAction->setDisabled(true); + showBookmarksAction->setData(SHOW_BOOKMARKS_ACTION_Y); + showBookmarksAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_BOOKMARKS_ACTION_Y)); + connect(showBookmarksAction, SIGNAL(triggered()),viewer->getBookmarksDialog(),SLOT(show())); + + showShorcutsAction = new QAction(tr("Show keyboard shortcuts"), this ); + showShorcutsAction->setIcon(QIcon(":/images/viewer_toolbar/shortcuts.png")); + showShorcutsAction->setData(SHOW_SHORCUTS_ACTION_Y); + showShorcutsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_SHORCUTS_ACTION_Y)); + //connect(showShorcutsAction, SIGNAL(triggered()),shortcutsDialog,SLOT(show())); + connect(showShorcutsAction, SIGNAL(triggered()), editShortcutsDialog, SLOT(show())); + + showInfoAction = new QAction(tr("Show Info"),this); + showInfoAction->setIcon(QIcon(":/images/viewer_toolbar/info.png")); + showInfoAction->setDisabled(true); + showInfoAction->setData(SHOW_INFO_ACTION_Y); + showInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_INFO_ACTION_Y)); + connect(showInfoAction, SIGNAL(triggered()),viewer,SLOT(informationSwitch())); + + closeAction = new QAction(tr("Close"),this); + closeAction->setIcon(QIcon(":/images/viewer_toolbar/close.png")); + closeAction->setData(CLOSE_ACTION_Y); + closeAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CLOSE_ACTION_Y)); + connect(closeAction,SIGNAL(triggered()),this,SLOT(close())); + + showDictionaryAction = new QAction(tr("Show Dictionary"),this); + showDictionaryAction->setIcon(QIcon(":/images/viewer_toolbar/translator.png")); + //showDictionaryAction->setCheckable(true); + showDictionaryAction->setDisabled(true); + showDictionaryAction->setData(SHOW_DICTIONARY_ACTION_Y); + showDictionaryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_DICTIONARY_ACTION_Y)); + connect(showDictionaryAction,SIGNAL(triggered()),viewer,SLOT(translatorSwitch())); + + //deprecated + alwaysOnTopAction = new QAction(tr("Always on top"),this); + alwaysOnTopAction->setIcon(QIcon(":/images/alwaysOnTop.png")); + alwaysOnTopAction->setCheckable(true); + alwaysOnTopAction->setDisabled(true); + alwaysOnTopAction->setChecked(Configuration::getConfiguration().getAlwaysOnTop()); + alwaysOnTopAction->setData(ALWAYS_ON_TOP_ACTION_Y); + alwaysOnTopAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ALWAYS_ON_TOP_ACTION_Y)); + connect(alwaysOnTopAction,SIGNAL(triggered()),this,SLOT(alwaysOnTopSwitch())); + + adjustToFullSizeAction = new QAction(tr("Show full size"),this); + adjustToFullSizeAction->setIcon(QIcon(":/images/viewer_toolbar/full.png")); + adjustToFullSizeAction->setCheckable(true); + adjustToFullSizeAction->setDisabled(true); + adjustToFullSizeAction->setChecked(Configuration::getConfiguration().getAdjustToFullSize()); + adjustToFullSizeAction->setData(ADJUST_TO_FULL_SIZE_ACTION_Y); + adjustToFullSizeAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADJUST_TO_FULL_SIZE_ACTION_Y)); + connect(adjustToFullSizeAction,SIGNAL(triggered()),this,SLOT(adjustToFullSizeSwitch())); + + showFlowAction = new QAction(tr("Show go to flow"),this); + showFlowAction->setIcon(QIcon(":/images/viewer_toolbar/flow.png")); + showFlowAction->setDisabled(true); + showFlowAction->setData(SHOW_FLOW_ACTION_Y); + showFlowAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_FLOW_ACTION_Y)); + connect(showFlowAction,SIGNAL(triggered()),viewer,SLOT(goToFlowSwitch())); + + showEditShortcutsAction = new QAction(tr("Edit shortcuts"),this); + showEditShortcutsAction->setData(SHOW_EDIT_SHORTCUTS_ACTION_Y); + showEditShortcutsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_EDIT_SHORTCUTS_ACTION_Y)); + connect(showEditShortcutsAction,SIGNAL(triggered()),editShortcutsDialog,SLOT(show())); +} + +void MainWindowViewer::createToolBars() +{ +#ifdef Q_OS_MAC + comicToolBar = new YACReaderMacOSXToolbar(this); +#else + comicToolBar = addToolBar(tr("&File")); +#endif + +#ifdef Q_OS_MAC + //comicToolBar->setIconSize(QSize(16,16)); +#else + comicToolBar->setIconSize(QSize(18,18)); + comicToolBar->setStyleSheet("QToolBar{border:none;}"); +#endif + +#ifdef Q_OS_MAC + comicToolBar->addAction(openAction); + comicToolBar->addAction(openFolderAction); +#else + QToolButton * tb = new QToolButton(); + tb->addAction(openAction); + tb->addAction(openFolderAction); + tb->setPopupMode(QToolButton::MenuButtonPopup); + tb->setDefaultAction(openAction); + + comicToolBar->addWidget(tb); +#endif + comicToolBar->addAction(saveImageAction); + comicToolBar->addAction(openPreviousComicAction); + comicToolBar->addAction(openNextComicAction); + + comicToolBar->addSeparator(); + + comicToolBar->addAction(prevAction); + comicToolBar->addAction(nextAction); + comicToolBar->addAction(goToPageAction); + +//#ifndef Q_OS_MAC +// comicToolBar->addSeparator(); +// comicToolBar->addAction(alwaysOnTopAction); +//#else +// alwaysOnTopAction->setEnabled(false); +//#endif + + + comicToolBar->addSeparator(); + + //QWidget * widget = new QWidget(); + + //QToolButton * tbW = new QToolButton(widget); + //tbW->addAction(adjustWidth); + //tbW->setPopupMode(QToolButton::MenuButtonPopup); + //tbW->setDefaultAction(adjustWidth); + + //QHBoxLayout *layout = new QHBoxLayout; + //layout->addWidget(tbW); + //layout->setContentsMargins(0,0,0,0); + //widget->setLayout(layout); + //widget->setContentsMargins(0,0,0,0); + + //comicToolBar->addWidget(widget); + + //comicToolBar->addAction(adjustWidth); + + +#ifdef Q_OS_MAC + + sliderAction = new YACReaderSlider(this); + sliderAction->hide(); + + comicToolBar->addAction(adjustWidthAction); + + QAction * action = comicToolBar->addFitToWidthSlider(adjustWidthAction); + + connect(action,SIGNAL(triggered()),this,SLOT(toggleFitToWidthSlider())); + +#else + QMenu * menu = new QMenu(); + + sliderAction = new YACReaderSliderAction(this); + + menu->setAutoFillBackground(false); + menu->setStyleSheet(" QMenu {background:transparent; border: 0px;padding: 0px; }" + ); + menu->addAction(sliderAction); + QToolButton * tb2 = new QToolButton(); + tb2->addAction(adjustWidthAction); + tb2->setMenu(menu); + + //tb2->addAction(); + tb2->setPopupMode(QToolButton::MenuButtonPopup); + tb2->setDefaultAction(adjustWidthAction); + comicToolBar->addWidget(tb2); +#endif + + connect(sliderAction,SIGNAL(fitToWidthRatioChanged(float)),viewer,SLOT(updateFitToWidthRatio(float))); + connect(optionsDialog,SIGNAL(fitToWidthRatioChanged(float)),sliderAction,SLOT(updateFitToWidthRatio(float))); + + comicToolBar->addAction(adjustHeightAction); + comicToolBar->addAction(adjustToFullSizeAction); + comicToolBar->addAction(leftRotationAction); + comicToolBar->addAction(rightRotationAction); + comicToolBar->addAction(doublePageAction); + comicToolBar->addAction(doubleMangaPageAction); + + comicToolBar->addSeparator(); + + comicToolBar->addAction(showMagnifyingGlassAction); + + + comicToolBar->addSeparator(); + + comicToolBar->addAction(setBookmarkAction); + comicToolBar->addAction(showBookmarksAction); + + comicToolBar->addSeparator(); + + comicToolBar->addAction(showDictionaryAction); + comicToolBar->addAction(showFlowAction); + comicToolBar->addAction(showInfoAction); + +#ifdef Q_OS_MAC + comicToolBar->addStretch(); +#else + comicToolBar->addWidget(new QToolBarStretch()); +#endif + + + comicToolBar->addAction(showShorcutsAction); + comicToolBar->addAction(optionsAction); + comicToolBar->addAction(helpAboutAction); + //comicToolBar->addAction(closeAction); + +#ifndef Q_OS_MAC + comicToolBar->setMovable(false); +#endif + + viewer->addAction(openAction); + viewer->addAction(openFolderAction); + viewer->addAction(saveImageAction); + viewer->addAction(openPreviousComicAction); + viewer->addAction(openNextComicAction); + YACReader::addSperator(viewer); + + viewer->addAction(prevAction); + viewer->addAction(nextAction); + viewer->addAction(goToPageAction); + viewer->addAction(adjustHeightAction); + viewer->addAction(adjustWidthAction); + viewer->addAction(adjustToFullSizeAction); + viewer->addAction(leftRotationAction); + viewer->addAction(rightRotationAction); + viewer->addAction(doublePageAction); + viewer->addAction(doubleMangaPageAction); + YACReader::addSperator(viewer); + + viewer->addAction(showMagnifyingGlassAction); + YACReader::addSperator(viewer); + + viewer->addAction(setBookmarkAction); + viewer->addAction(showBookmarksAction); + YACReader::addSperator(viewer); + + viewer->addAction(showDictionaryAction); + viewer->addAction(showFlowAction); + viewer->addAction(showInfoAction); + YACReader::addSperator(viewer); + + viewer->addAction(showShorcutsAction); + viewer->addAction(showEditShortcutsAction); + viewer->addAction(optionsAction); + viewer->addAction(helpAboutAction); + YACReader::addSperator(viewer); + + viewer->addAction(closeAction); + + viewer->setContextMenuPolicy(Qt::ActionsContextMenu); + + //MacOSX app menus +#ifdef Q_OS_MAC + QMenuBar * menuBar = this->menuBar(); + //about / preferences + //TODO + + //file + QMenu * fileMenu = new QMenu(tr("File")); + + fileMenu->addAction(openAction); + fileMenu->addAction(openFolderAction); + fileMenu->addSeparator(); + fileMenu->addAction(saveImageAction); + + //tool bar + //QMenu * toolbarMenu = new QMenu(tr("Toolbar")); + //toolbarMenu->addAction(); + //TODO + + menuBar->addMenu(fileMenu); + //menu->addMenu(toolbarMenu); + + //attach toolbar + + comicToolBar->attachToWindow(this->windowHandle()); + +#endif + +} + +void MainWindowViewer::reloadOptions() +{ + viewer->updateConfig(settings); +} + +void MainWindowViewer::open() +{ + QFileDialog openDialog; +#ifndef use_unarr + QString pathFile = openDialog.getOpenFileName(this,tr("Open Comic"),currentDirectory,tr("Comic files") + "(*.cbr *.cbz *.rar *.zip *.tar *.pdf *.7z *.cb7 *.arj *.cbt)"); +#else + QString pathFile = openDialog.getOpenFileName(this,tr("Open Comic"),currentDirectory,tr("Comic files") + "(*.cbr *.cbz *.rar *.zip *.tar *.pdf *.cbt)"); +#endif + if (!pathFile.isEmpty()) + { + openComicFromPath(pathFile); + } +} + +void MainWindowViewer::open(QString path, ComicDB & comic, QList & siblings) +{ + //currentComicDB = comic; + //siblingComics = siblings; + + QFileInfo fi(path); + + if(!comic.info.title.isNull() && !comic.info.title.toString().isEmpty()) + setWindowTitle("YACReader - " + comic.info.title.toString()); + else + setWindowTitle("YACReader - " + fi.fileName()); + + viewer->open(path,comic); + enableActions(); + int index = siblings.indexOf(comic); + + optionsDialog->setFilters(currentComicDB.info.brightness, currentComicDB.info.contrast, currentComicDB.info.gamma); + + if(index>0) + openPreviousComicAction->setDisabled(false); + else + openPreviousComicAction->setDisabled(true); + + if(index+1setDisabled(false); + else + openNextComicAction->setDisabled(true); +} + +void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId) +{ + //QString pathFile = QCoreApplication::arguments().at(1); + currentDirectory = path; + //quint64 comicId = QCoreApplication::arguments().at(2).split("=").at(1).toULongLong(); + //libraryId = QCoreApplication::arguments().at(3).split("=").at(1).toULongLong(); + this->libraryId=libraryId; +// this->path=path; + + enableActions(); + + currentComicDB.id = comicId; + YACReaderLocalClient client; + int tries = 1; + bool success = false; + while(!(success = client.requestComicInfo(libraryId,currentComicDB,siblingComics)) && tries != 0) + tries--; + + if(success) + { + isClient = true; + open(path+currentComicDB.path,currentComicDB,siblingComics); + } + else + { + isClient = false; + QMessageBox::information(this,"Connection Error", "Unable to connect to YACReaderLibrary"); + //error + } + + optionsDialog->setFilters(currentComicDB.info.brightness, currentComicDB.info.contrast, currentComicDB.info.gamma); +} + +void MainWindowViewer::openComicFromPath(QString pathFile) +{ + openComic(pathFile); + isClient = false; //this method is used for direct openings +} + +//isClient shouldn't be modified when a siblinig comic is opened +void MainWindowViewer::openSiblingComic(QString pathFile) +{ + openComic(pathFile); +} + +void MainWindowViewer::openComic(QString pathFile) +{ + QFileInfo fi(pathFile); + currentDirectory = fi.dir().absolutePath(); + getSiblingComics(fi.absolutePath(),fi.fileName()); + + setWindowTitle("YACReader - " + fi.fileName()); + + enableActions(); + + viewer->open(pathFile); + } + +void MainWindowViewer::openFolder() +{ + QFileDialog openDialog; + QString pathDir = openDialog.getExistingDirectory(this,tr("Open folder"),currentDirectory); + if (!pathDir.isEmpty()) + { + openFolderFromPath(pathDir); + isClient = false; + } +} + +void MainWindowViewer::openFolderFromPath(QString pathDir) +{ + currentDirectory = pathDir; //TODO ?? + QFileInfo fi(pathDir); + getSiblingComics(fi.absolutePath(),fi.fileName()); + + setWindowTitle("YACReader - " + fi.fileName()); + + enableActions(); + + viewer->open(pathDir); +} + +void MainWindowViewer::openFolderFromPath(QString pathDir, QString atFileName) +{ + currentDirectory = pathDir; //TODO ?? + QFileInfo fi(pathDir); + getSiblingComics(fi.absolutePath(),fi.fileName()); + + setWindowTitle("YACReader - " + fi.fileName()); + + enableActions(); + + QDir d(pathDir); + d.setFilter(QDir::Files|QDir::NoDotAndDotDot); + d.setNameFilters(Comic::getSupportedImageFormats()); + d.setSorting(QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); + QStringList list = d.entryList(); + + qSort(list.begin(),list.end(),naturalSortLessThanCI); + int i = 0; + foreach(QString path,list) + { + if(path.endsWith(atFileName)) + break; + i++; + } + + int index = 0; + if(i < list.count()) + index = i; + + viewer->open(pathDir,i); +} + +void MainWindowViewer::saveImage() +{ + QFileDialog saveDialog; + QString pathFile = saveDialog.getSaveFileName(this,tr("Save current page"),currentDirectoryImgDest+"/"+tr("page_%1.jpg").arg(viewer->getIndex()),tr("Image files (*.jpg)")); + if (!pathFile.isEmpty()) + { + QFileInfo fi(pathFile); + currentDirectoryImgDest = fi.absolutePath(); + const QPixmap * p = viewer->pixmap(); + if(p!=NULL) + p->save(pathFile); + } +} + +void MainWindowViewer::enableActions() +{ + saveImageAction->setDisabled(false); + prevAction->setDisabled(false); + nextAction->setDisabled(false); + adjustHeightAction->setDisabled(false); + adjustWidthAction->setDisabled(false); + goToPageAction->setDisabled(false); + //alwaysOnTopAction->setDisabled(false); + leftRotationAction->setDisabled(false); + rightRotationAction->setDisabled(false); + showMagnifyingGlassAction->setDisabled(false); + doublePageAction->setDisabled(false); + doubleMangaPageAction->setDisabled(false); + adjustToFullSizeAction->setDisabled(false); + //setBookmark->setDisabled(false); + showBookmarksAction->setDisabled(false); + showInfoAction->setDisabled(false); //TODO enable goTo and showInfo (or update) when numPages emited + showDictionaryAction->setDisabled(false); + showFlowAction->setDisabled(false); +} +void MainWindowViewer::disableActions() +{ + saveImageAction->setDisabled(true); + prevAction->setDisabled(true); + nextAction->setDisabled(true); + adjustHeightAction->setDisabled(true); + adjustWidthAction->setDisabled(true); + goToPageAction->setDisabled(true); + //alwaysOnTopAction->setDisabled(true); + leftRotationAction->setDisabled(true); + rightRotationAction->setDisabled(true); + showMagnifyingGlassAction->setDisabled(true); + doublePageAction->setDisabled(true); + doubleMangaPageAction->setDisabled(true); + adjustToFullSizeAction->setDisabled(true); + setBookmarkAction->setDisabled(true); + showBookmarksAction->setDisabled(true); + showInfoAction->setDisabled(true); //TODO enable goTo and showInfo (or update) when numPages emited + openPreviousComicAction->setDisabled(true); + openNextComicAction->setDisabled(true); + showDictionaryAction->setDisabled(true); + showFlowAction->setDisabled(true); +} + +void MainWindowViewer::keyPressEvent(QKeyEvent *event) +{ + //TODO remove unused keys + int _key = event->key(); + Qt::KeyboardModifiers modifiers = event->modifiers(); + + if(modifiers & Qt::ShiftModifier) + _key |= Qt::SHIFT; + if (modifiers & Qt::ControlModifier) + _key |= Qt::CTRL; + if (modifiers & Qt::MetaModifier) + _key |= Qt::META; + if (modifiers & Qt::AltModifier) + _key |= Qt::ALT; + + QKeySequence key(_key); + + if (key == ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_Y)) + { + toggleFullScreen(); + event->accept(); + } + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y)) + { + toggleToolBars(); + event->accept(); + } + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y)) + { + changeFit(); + event->accept(); + } + else + QWidget::keyPressEvent(event); +} + +void MainWindowViewer::mouseDoubleClickEvent ( QMouseEvent * event ) +{ + toggleFullScreen(); + event->accept(); +} + +void MainWindowViewer::toggleFullScreen() +{ + fullscreen?toNormal():toFullScreen(); + Configuration::getConfiguration().setFullScreen(fullscreen = !fullscreen); +} + +void MainWindowViewer::toFullScreen() +{ + fromMaximized = this->isMaximized(); + + hideToolBars(); + viewer->hide(); + viewer->fullscreen = true;//TODO, change by the right use of windowState(); + showFullScreen(); + viewer->show(); + if(viewer->magnifyingGlassIsVisible()) + viewer->showMagnifyingGlass(); +} + +void MainWindowViewer::toNormal() +{ + //show all + viewer->hide(); + viewer->fullscreen = false;//TODO, change by the right use of windowState(); + //viewer->hideMagnifyingGlass(); + if(fromMaximized) + showMaximized(); + else + showNormal(); + + if(Configuration::getConfiguration().getShowToolbars()) + showToolBars(); + viewer->show(); + if(viewer->magnifyingGlassIsVisible()) + viewer->showMagnifyingGlass(); +} + +void MainWindowViewer::toggleToolBars() +{ + toolbars?hideToolBars():showToolBars(); + + Configuration::getConfiguration().setShowToolbars(toolbars); +#ifndef Q_OS_MAC + comicToolBar->setMovable(false); +#endif +} +void MainWindowViewer::hideToolBars() +{ + //hide all + this->comicToolBar->hide(); + toolbars = false; +} + +void MainWindowViewer::showToolBars() +{ + this->comicToolBar->show(); + toolbars = true; +} +void MainWindowViewer::fitToWidth() +{ + Configuration & conf = Configuration::getConfiguration(); + if(!conf.getAdjustToWidth()) + { + conf.setAdjustToWidth(true); + viewer->updatePage(); + } +} +void MainWindowViewer::fitToHeight() +{ + Configuration & conf = Configuration::getConfiguration(); + if(conf.getAdjustToWidth()) + { + conf.setAdjustToWidth(false); + viewer->updatePage(); + } +} + +void MainWindowViewer::checkNewVersion() +{ + Configuration & conf = Configuration::getConfiguration(); + QDate lastCheck = conf.getLastVersionCheck(); + QDate current = QDate::currentDate(); + if(lastCheck.isNull() || lastCheck.daysTo(current) >= conf.getNumDaysBetweenVersionChecks()) + { + versionChecker = new HttpVersionChecker(); + + connect(versionChecker,SIGNAL(newVersionDetected()), + this,SLOT(newVersion())); + + QTimer * tT = new QTimer; + tT->setSingleShot(true); + connect(tT, SIGNAL(timeout()), versionChecker, SLOT(get())); + //versionChecker->get(); //TOD� + tT->start(100); + + conf.setLastVersionCheck(current); + } +} + +void MainWindowViewer::processReset() +{ + if(isClient) + { + if(siblingComics.count()>1) + { + bool openNextB = openNextComicAction->isEnabled(); + bool openPrevB = openPreviousComicAction->isEnabled(); + disableActions(); + openNextComicAction->setEnabled(openNextB); + openPreviousComicAction->setEnabled(openPrevB); + } + else + disableActions(); + } + else + disableActions(); +} + +void MainWindowViewer::setUpShortcutsManagement() +{ + //actions holder + QObject * orphanActions = new QObject; + + QList allActions; + QList tmpList; + + + editShortcutsDialog->addActionsGroup(tr("Comics"),QIcon(":/images/shortcuts_group_comics.png"), + tmpList = QList() + << openAction + << openFolderAction + << saveImageAction + << openPreviousComicAction + << openNextComicAction); + + allActions << tmpList; + + //keys without actions (General) + QAction * toggleFullScreenAction = new QAction(tr("Toggle fullscreen mode"),orphanActions); + toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_Y); + toggleFullScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_Y)); + + QAction * toggleToolbarsAction = new QAction(tr("Hide/show toolbar"),orphanActions); + toggleToolbarsAction->setData(TOGGLE_TOOL_BARS_ACTION_Y); + toggleToolbarsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y)); + + editShortcutsDialog->addActionsGroup(tr("General"),QIcon(":/images/shortcuts_group_general.png"), + tmpList = QList() + << optionsAction + << helpAboutAction + << showShorcutsAction + << showInfoAction + << closeAction + << showDictionaryAction + << showFlowAction + << toggleFullScreenAction + << toggleToolbarsAction + << showEditShortcutsAction); + + allActions << tmpList; + + //keys without actions (MGlass) + QAction * sizeUpMglassAction = new QAction(tr("Size up magnifying glass"),orphanActions); + sizeUpMglassAction->setData(SIZE_UP_MGLASS_ACTION_Y); + sizeUpMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y)); + + QAction * sizeDownMglassAction = new QAction(tr("Size down magnifying glass"),orphanActions); + sizeDownMglassAction->setData(SIZE_DOWN_MGLASS_ACTION_Y); + sizeDownMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y)); + + QAction * zoomInMglassAction = new QAction(tr("Zoom in magnifying glass"),orphanActions); + zoomInMglassAction->setData(ZOOM_IN_MGLASS_ACTION_Y); + zoomInMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y)); + + QAction * zoomOutMglassAction = new QAction(tr("Zoom out magnifying glass"),orphanActions); + zoomOutMglassAction->setData(ZOOM_OUT_MGLASS_ACTION_Y); + zoomOutMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y)); + + editShortcutsDialog->addActionsGroup(tr("Magnifiying glass"),QIcon(":/images/shortcuts_group_mglass.png"), + tmpList = QList() + << showMagnifyingGlassAction + << sizeUpMglassAction + << sizeDownMglassAction + << zoomInMglassAction + << zoomOutMglassAction); + + allActions << tmpList; + + //keys without actions + QAction * toggleFitToScreenAction = new QAction(tr("Toggle between fit to width and fit to height"),orphanActions); + toggleFitToScreenAction->setData(CHANGE_FIT_ACTION_Y); + toggleFitToScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y)); + + editShortcutsDialog->addActionsGroup(tr("Page adjustement"),QIcon(":/images/shortcuts_group_page.png"), + tmpList = QList() + << adjustHeightAction + << adjustWidthAction + << toggleFitToScreenAction + << leftRotationAction + << rightRotationAction + << doublePageAction + << doubleMangaPageAction + << adjustToFullSizeAction); + + allActions << tmpList; + + QAction * autoScrollForwardAction = new QAction(tr("Autoscroll down"),orphanActions); + autoScrollForwardAction->setData(AUTO_SCROLL_FORWARD_ACTION_Y); + autoScrollForwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)); + + QAction * autoScrollBackwardAction = new QAction(tr("Autoscroll up"),orphanActions); + autoScrollBackwardAction->setData(AUTO_SCROLL_BACKWARD_ACTION_Y); + autoScrollBackwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)); + + QAction * moveDownAction = new QAction(tr("Move down"),orphanActions); + moveDownAction->setData(MOVE_DOWN_ACTION_Y); + moveDownAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_DOWN_ACTION_Y)); + + QAction * moveUpAction = new QAction(tr("Move up"),orphanActions); + moveUpAction->setData(MOVE_UP_ACTION_Y); + moveUpAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_UP_ACTION_Y)); + + QAction * moveLeftAction = new QAction(tr("Move left"),orphanActions); + moveLeftAction->setData(MOVE_LEFT_ACTION_Y); + moveLeftAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_LEFT_ACTION_Y)); + + QAction * moveRightAction = new QAction(tr("Move right"),orphanActions); + moveRightAction->setData(MOVE_RIGHT_ACTION_Y); + moveRightAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_RIGHT_ACTION_Y)); + + QAction * goToFirstPageAction = new QAction(tr("Go to the first page"),orphanActions); + goToFirstPageAction->setData(GO_TO_FIRST_PAGE_ACTION_Y); + goToFirstPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_FIRST_PAGE_ACTION_Y)); + + QAction * goToLastPageAction = new QAction(tr("Go to the last page"),orphanActions); + goToLastPageAction->setData(GO_TO_LAST_PAGE_ACTION_Y); + goToLastPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_LAST_PAGE_ACTION_Y)); + + editShortcutsDialog->addActionsGroup(tr("Reading"),QIcon(":/images/shortcuts_group_reading.png"), + tmpList = QList() + << nextAction + << prevAction + << setBookmarkAction + << showBookmarksAction + << autoScrollForwardAction + << autoScrollBackwardAction + << moveDownAction + << moveUpAction + << moveLeftAction + << moveRightAction + << goToFirstPageAction + << goToLastPageAction + << goToPageAction); + + allActions << tmpList; + + ShortcutsManager::getShortcutsManager().registerActions(allActions); + +} + +#ifdef Q_OS_MAC +void MainWindowViewer::toggleFitToWidthSlider() +{ + if(sliderAction->isVisible()) + { + sliderAction->hide(); + } + else + { + sliderAction->move(250,0); + sliderAction->show(); + } +} +#endif + +void MainWindowViewer::changeFit() +{ + Configuration & conf = Configuration::getConfiguration(); + conf.setAdjustToWidth(!conf.getAdjustToWidth()); + viewer->updatePage(); +} + +void MainWindowViewer::newVersion() +{ + QMessageBox msgBox; + msgBox.setText(tr("There is a new version available")); + msgBox.setInformativeText(tr("Do you want to download the new version?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Ignore | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + msgBox.button(QMessageBox::Ignore)->setText(tr("Remind me in 14 days")); + msgBox.button(QMessageBox::No)->setText(tr("Not now")); + msgBox.setWindowFlags(Qt::WindowStaysOnTopHint); + msgBox.setModal(true); + int ret = msgBox.exec(); + + switch(ret) + { + case QMessageBox::Yes: + QDesktopServices::openUrl(QUrl("http://www.yacreader.com")); + break; + case QMessageBox::No: + Configuration::getConfiguration().setNumDaysBetweenVersionChecks(1); + break; + case QMessageBox::Ignore: + Configuration::getConfiguration().setNumDaysBetweenVersionChecks(14); + break; + } +} + +void MainWindowViewer::closeEvent ( QCloseEvent * event ) +{ + Q_UNUSED(event) + + if(isClient) + sendComic(); + + viewer->save(); + Configuration & conf = Configuration::getConfiguration(); + if(!fullscreen && !isMaximized()) + { + conf.setPos(pos()); + conf.setSize(size()); + } + conf.setMaximized(isMaximized()); + + emit (closed()); +} + +void MainWindowViewer::openPreviousComic() +{ + if(!siblingComics.isEmpty() && isClient) + { + sendComic(); + + int currentIndex = siblingComics.indexOf(currentComicDB); + if (currentIndex == -1) + return; + if(currentIndex-1 >= 0 && currentIndex-1 < siblingComics.count()) + { + siblingComics[currentIndex] = currentComicDB; //updated + currentComicDB = siblingComics.at(currentIndex-1); + open(currentDirectory+currentComicDB.path,currentComicDB,siblingComics); + } + return; + } + if(!previousComicPath.isEmpty()) + { + openSiblingComic(previousComicPath); + } +} + +void MainWindowViewer::openNextComic() +{ + if(!siblingComics.isEmpty() && isClient) + { + sendComic(); + + int currentIndex = siblingComics.indexOf(currentComicDB); + if (currentIndex == -1) + return; + if(currentIndex+1 > 0 && currentIndex+1 < siblingComics.count()) + { + siblingComics[currentIndex] = currentComicDB; //updated + currentComicDB = siblingComics.at(currentIndex+1); + open(currentDirectory+currentComicDB.path,currentComicDB,siblingComics); + } + return; + } + if(!nextComicPath.isEmpty()) + { + openSiblingComic(nextComicPath); + } +} + +void MainWindowViewer::getSiblingComics(QString path,QString currentComic) +{ + QDir d(path); + d.setFilter(QDir::Files|QDir::NoDotAndDotDot); +#ifndef use_unarr + d.setNameFilters(QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.7z" << "*.cb7" << "*.arj" << "*.cbt"); +#else + d.setNameFilters(QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.cbt"); +#endif + d.setSorting(QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); + QStringList list = d.entryList(); + qSort(list.begin(),list.end(),naturalSortLessThanCI); + //std::sort(list.begin(),list.end(),naturalSortLessThanCI); + int index = list.indexOf(currentComic); + if(index == -1) //comic not found + { + /*QFile f(QCoreApplication::applicationDirPath()+"/errorLog.txt"); + if(!f.open(QIODevice::WriteOnly)) + { + QMessageBox::critical(NULL,tr("Saving error log file...."),tr("There was a problem saving YACReader error log file. Please, check if you have enough permissions in the YACReader root folder.")); + } + else + { + QTextStream txtS(&f); + txtS << "METHOD : MainWindowViewer::getSiblingComics" << '\n'; + txtS << "ERROR : current comic not found in its own path" << '\n'; + txtS << path << '\n'; + txtS << currentComic << '\n'; + txtS << "Comic list count : " + list.count() << '\n'; + foreach(QString s, list){ + txtS << s << '\n'; + } + f.close(); + }*/ + } + + previousComicPath = nextComicPath = ""; + if(index>0) + { + previousComicPath = path+"/"+list.at(index-1); + openPreviousComicAction->setDisabled(false); + } + else + openPreviousComicAction->setDisabled(true); + + if(index+1setDisabled(false); + } + else + openNextComicAction->setDisabled(true); +} + +void MainWindowViewer::dropEvent(QDropEvent *event) +{ + QList urlList; + QString fName; + QFileInfo info; + + if (event->mimeData()->hasUrls()) + { + urlList = event->mimeData()->urls(); + + if ( urlList.size() > 0 ) + { + fName = urlList[0].toLocalFile(); // convert first QUrl to local path + info.setFile( fName ); // information about file + if (info.isFile()) + { + QStringList imageSuffixs = Comic::getSupportedImageLiteralFormats(); + if(imageSuffixs.contains(info.suffix())) //image dropped + openFolderFromPath(info.absoluteDir().absolutePath(),info.fileName()); + else + openComicFromPath(fName); // if is file, setText + } + else + if(info.isDir()) + openFolderFromPath(fName); + + isClient = false; + } + } + + event->acceptProposedAction(); +} +void MainWindowViewer::dragEnterEvent(QDragEnterEvent *event) +{ + // accept just text/uri-list mime format + if (event->mimeData()->hasFormat("text/uri-list")) + { + event->acceptProposedAction(); + isClient = false; + } +} + +void MainWindowViewer::alwaysOnTopSwitch() +{ + if(!Configuration::getConfiguration().getAlwaysOnTop()) + { + setWindowFlags(this->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); //always on top + show(); + } + else + { + setWindowFlags(this->windowFlags() ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)); + show(); + } + Configuration::getConfiguration().setAlwaysOnTop(!Configuration::getConfiguration().getAlwaysOnTop()); +} + +void MainWindowViewer::adjustToFullSizeSwitch() +{ + Configuration::getConfiguration().setAdjustToFullSize(!Configuration::getConfiguration().getAdjustToFullSize()); + viewer->updatePage(); +} + +void MainWindowViewer::sendComic() +{ + YACReaderLocalClient * client = new YACReaderLocalClient; + currentComicDB.info.hasBeenOpened = true; + viewer->updateComic(currentComicDB); + int retries = 1; + while(!client->sendComicInfo(libraryId,currentComicDB) && retries!=0) + retries--; + connect(client,SIGNAL(finished()),client,SLOT(deleteLater())); + //delete client; +} diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h new file mode 100644 index 00000000..6f27c75b --- /dev/null +++ b/YACReader/main_window_viewer.h @@ -0,0 +1,169 @@ +#ifndef __MAIN_WINDOW_VIEWER_H +#define __MAIN_WINDOW_VIEWER_H +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_OS_MAC + #include "yacreader_macosx_toolbar.h" +#endif + +#include "comic_db.h" + +class Comic; +class Viewer; +class OptionsDialog; +class HelpAboutDialog; +class HttpVersionChecker; +class ShortcutsDialog; +class YACReaderSliderAction; +class YACReaderSlider; +class EditShortcutsDialog; + + class MainWindowViewer : public QMainWindow + { + Q_OBJECT + + public slots: + void open(); + void open(QString path, ComicDB & comic, QList & siblings); + void open(QString path, qint64 comicId, qint64 libraryId); + void openFolder(); + void saveImage(); + void toggleToolBars(); + void hideToolBars(); + void showToolBars(); + void changeFit(); + void enableActions(); + void disableActions(); + void toggleFullScreen(); + void toFullScreen(); + void toNormal(); + void loadConfiguration(); + void newVersion(); + void openPreviousComic(); + void openNextComic(); + void openComicFromPath(QString pathFile); + void openSiblingComic(QString pathFile); + void openComic(QString pathFile); + void openFolderFromPath(QString pathDir); + void openFolderFromPath(QString pathFile, QString atFileName); + void alwaysOnTopSwitch(); + void adjustToFullSizeSwitch(); + void reloadOptions(); + void fitToWidth(); + void fitToHeight(); + void checkNewVersion(); + void processReset(); + void setUpShortcutsManagement(); + +#ifdef Q_OS_MAC + void toggleFitToWidthSlider(); +#endif + /*void viewComic(); + void prev(); + void next(); + void updatePage();*/ + + + private: + //!State + bool fullscreen; + bool toolbars; + bool alwaysOnTop; + bool fromMaximized; + + //QTBUG-41883 + QSize _size; + QPoint _pos; + + QString currentDirectory; + QString currentDirectoryImgDest; + //!Widgets + Viewer * viewer; + //GoToDialog * goToDialog; + OptionsDialog * optionsDialog; + HelpAboutDialog * had; + //ShortcutsDialog * shortcutsDialog; + EditShortcutsDialog * editShortcutsDialog; + + //! ToolBars + #ifdef Q_OS_MAC + YACReaderMacOSXToolbar * comicToolBar; +#else + QToolBar * comicToolBar; +#endif + + //! Actions + QAction *openAction; + QAction *openFolderAction; + QAction *saveImageAction; + QAction *openPreviousComicAction; + QAction *openNextComicAction; + QAction *nextAction; + QAction *prevAction; + QAction *adjustWidthAction; + QAction *adjustHeightAction; + QAction *goToPageAction; + QAction *optionsAction; + QAction *helpAboutAction; + QAction *showMagnifyingGlassAction; + QAction *setBookmarkAction; + QAction *showBookmarksAction; + QAction *leftRotationAction; + QAction *rightRotationAction; + QAction *showInfoAction; + QAction *closeAction; + QAction *doublePageAction; + QAction *doubleMangaPageAction; + QAction *showShorcutsAction; + QAction *showDictionaryAction; + QAction *alwaysOnTopAction; + QAction *adjustToFullSizeAction; + QAction *showFlowAction; + + QAction *showEditShortcutsAction; +#ifdef Q_OS_MAC + YACReaderSlider * sliderAction; +#else + YACReaderSliderAction * sliderAction; +#endif + + HttpVersionChecker * versionChecker; + QString previousComicPath; + QString nextComicPath; + //! Método que inicializa el interfaz. + void setupUI(); + void createActions(); + void createToolBars(); + void getSiblingComics(QString path,QString currentComic); + + //! Manejadores de evento: + void keyPressEvent(QKeyEvent *event); + //void resizeEvent(QResizeEvent * event); + void mouseDoubleClickEvent ( QMouseEvent * event ); + void dropEvent(QDropEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + + QSettings * settings; + + ComicDB currentComicDB; + QList siblingComics; + bool isClient; + QString startComicPath; + quint64 libraryId; +signals: + void closed(); + protected: + virtual void closeEvent ( QCloseEvent * event ); + void sendComic(); + public: + MainWindowViewer(); + ~MainWindowViewer(); + }; +#endif diff --git a/YACReader/notifications_label_widget.cpp b/YACReader/notifications_label_widget.cpp new file mode 100644 index 00000000..33810644 --- /dev/null +++ b/YACReader/notifications_label_widget.cpp @@ -0,0 +1,83 @@ +#include "notifications_label_widget.h" + +#include +#include +#include +#include + +NotificationsLabelWidget::NotificationsLabelWidget(QWidget * parent) + :QWidget(parent) +{ + setAttribute(Qt::WA_LayoutUsesWidgetRect,true); + effect = new QGraphicsOpacityEffect(this); + effect->setOpacity(1.0); + + effect2= new QGraphicsOpacityEffect(this); + effect->setOpacity(1.0); + + anim = new QPropertyAnimation(effect,"opacity"); + anim->setDuration(500); + anim->setStartValue(1.0); + anim->setEndValue(0.0); + anim->setEasingCurve(QEasingCurve::InExpo); + + anim2 = new QPropertyAnimation(effect2,"opacity"); + anim2->setDuration(500); + anim2->setStartValue(1.0); + anim2->setEndValue(0.0); + anim2->setEasingCurve(QEasingCurve::InExpo); + anim2->start(); + + connect(anim,SIGNAL(finished()),this,SLOT(hide())); + + imgLabel = new QLabel(this); + QPixmap p(":/images/notificationsLabel.png"); + imgLabel->resize(p.size()); + imgLabel->setPixmap(p); + imgLabel->setAttribute(Qt::WA_LayoutUsesWidgetRect,true); + + textLabel = new QLabel(this); + textLabel->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter); + textLabel->setStyleSheet("QLabel { color : white; font-size:24px; }"); + textLabel->setAttribute(Qt::WA_LayoutUsesWidgetRect,true); + + textLabel->setGeometry(imgLabel->geometry()); +#ifndef Q_OS_MAC + imgLabel->setGraphicsEffect(effect); + textLabel->setGraphicsEffect(effect2); +#endif + resize(p.size()); + updatePosition(); + +} + +void NotificationsLabelWidget::flash() +{ + updatePosition(); + anim->stop(); + anim2->stop(); + anim->start(); + anim2->start(); + + setVisible(true); +} + +void NotificationsLabelWidget::setText(const QString & text) +{ + textLabel->setText(text); + QRect geom = imgLabel->geometry(); + QSize size = geom.size(); + size.setHeight(size.height() - 10); //TODO remove this amazing magic number + geom.setSize(size); + textLabel->setGeometry(geom); +} + +void NotificationsLabelWidget::updatePosition() +{ + QWidget * parent = dynamic_cast(this->parent()); + if(parent == 0) + { + return; + } + move(QPoint((parent->geometry().size().width()-this->width())/2,(parent->geometry().size().height()-this->height())/2)); +} \ No newline at end of file diff --git a/YACReader/notifications_label_widget.h b/YACReader/notifications_label_widget.h new file mode 100644 index 00000000..08265d4a --- /dev/null +++ b/YACReader/notifications_label_widget.h @@ -0,0 +1,29 @@ +#ifndef NOTIFICATIONS_LABEL_WIDGET_H +#define NOTIFICATIONS_LABEL_WIDGET_H + +#include + +class QLabel; +class QPropertyAnimation; +class QGraphicsOpacityEffect; + +class NotificationsLabelWidget : public QWidget +{ +Q_OBJECT +private: + QLabel * imgLabel; + QLabel * textLabel; + QPropertyAnimation * anim; + QPropertyAnimation * anim2; + QGraphicsOpacityEffect * effect; + QGraphicsOpacityEffect * effect2; +public: + NotificationsLabelWidget(QWidget * parent); + +public slots: + void flash(); + void setText(const QString & text); + void updatePosition(); +}; + +#endif \ No newline at end of file diff --git a/YACReader/options_dialog.cpp b/YACReader/options_dialog.cpp new file mode 100644 index 00000000..2ed4eee2 --- /dev/null +++ b/YACReader/options_dialog.cpp @@ -0,0 +1,312 @@ +#include "options_dialog.h" +#include "configuration.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "yacreader_spin_slider_widget.h" +#include "yacreader_flow_config_widget.h" +#ifndef NO_OPENGL +#include "yacreader_gl_flow_config_widget.h" +#endif + +OptionsDialog::OptionsDialog(QWidget * parent) +:YACReaderOptionsDialog(parent) +{ + + QTabWidget * tabWidget = new QTabWidget(); + + QVBoxLayout * layout = new QVBoxLayout(this); + + QWidget * pageGeneral = new QWidget(); + QWidget * pageFlow = new QWidget(); + QWidget * pageImage = new QWidget(); + QVBoxLayout * layoutGeneral = new QVBoxLayout(); + QVBoxLayout * layoutFlow = new QVBoxLayout(); + QVBoxLayout * layoutImageV = new QVBoxLayout(); + QGridLayout * layoutImage = new QGridLayout(); + + QGroupBox *slideSizeBox = new QGroupBox(tr("\"Go to flow\" size")); + //slideSizeLabel = new QLabel(,this); + slideSize = new QSlider(this); + slideSize->setMinimum(125); + slideSize->setMaximum(350); + slideSize->setPageStep(5); + slideSize->setOrientation(Qt::Horizontal); + QHBoxLayout * slideLayout = new QHBoxLayout(); + slideLayout->addWidget(slideSize); + slideSizeBox->setLayout(slideLayout); + + QGroupBox *pathBox = new QGroupBox(tr("My comics path")); + + QHBoxLayout * path = new QHBoxLayout(); + path->addWidget(pathEdit = new QLineEdit()); + path->addWidget(pathFindButton = new QPushButton(QIcon(":/images/find_folder.png"),"")); + pathBox->setLayout(path); + + connect(pathFindButton,SIGNAL(clicked()),this,SLOT(findFolder())); + + //fitToWidthRatioLabel = new QLabel(tr("Page width stretch"),this); + QGroupBox *fitBox = new QGroupBox(tr("Page width stretch")); + fitToWidthRatioS = new QSlider(this); + fitToWidthRatioS->setMinimum(50); + fitToWidthRatioS->setMaximum(100); + fitToWidthRatioS->setPageStep(5); + fitToWidthRatioS->setOrientation(Qt::Horizontal); + //connect(fitToWidthRatioS,SIGNAL(valueChanged(int)),this,SLOT(fitToWidthRatio(int))); + QHBoxLayout * fitLayout = new QHBoxLayout; + fitLayout->addWidget(fitToWidthRatioS); + fitBox->setLayout(fitLayout); + + QHBoxLayout * colorSelection = new QHBoxLayout; + backgroundColor = new QLabel(); + QPalette pal = backgroundColor->palette(); + pal.setColor(backgroundColor->backgroundRole(), Qt::black); + backgroundColor->setPalette(pal); + backgroundColor->setAutoFillBackground(true); + + colorDialog = new QColorDialog(Qt::red,this); + connect(colorDialog,SIGNAL(colorSelected(QColor)),this,SLOT(updateColor(QColor))); + + QGroupBox *colorBox = new QGroupBox(tr("Background color")); + //backgroundColor->setMinimumWidth(100); + colorSelection->addWidget(backgroundColor); + colorSelection->addWidget(selectBackgroundColorButton = new QPushButton(tr("Choose"))); + colorSelection->setStretchFactor(backgroundColor,1); + colorSelection->setStretchFactor(selectBackgroundColorButton,0); + //colorSelection->addStretch(); + connect(selectBackgroundColorButton, SIGNAL(clicked()), colorDialog, SLOT(show())); + colorBox->setLayout(colorSelection); + + brightnessS = new YACReaderSpinSliderWidget(this,true); + brightnessS->setRange(0,100); + //brightnessS->setText(tr("Brightness")); + brightnessS->setTracking(false); + connect(brightnessS,SIGNAL(valueChanged(int)),this,SLOT(brightnessChanged(int))); + + contrastS = new YACReaderSpinSliderWidget(this,true); + contrastS->setRange(0,250); + //contrastS->setText(tr("Contrast")); + contrastS->setTracking(false); + connect(contrastS,SIGNAL(valueChanged(int)),this,SLOT(contrastChanged(int))); + + gammaS = new YACReaderSpinSliderWidget(this,true); + gammaS->setRange(0,250); + //gammaS->setText(tr("Gamma")); + gammaS->setTracking(false); + connect(gammaS,SIGNAL(valueChanged(int)),this,SLOT(gammaChanged(int))); + //connect(brightnessS,SIGNAL(valueChanged(int)),this,SIGNAL(changedOptions())); + + QHBoxLayout * buttons = new QHBoxLayout(); + buttons->addStretch(); + buttons->addWidget(new QLabel(tr("Restart is needed"))); + buttons->addWidget(accept); + buttons->addWidget(cancel); + + layoutGeneral->addWidget(pathBox); + layoutGeneral->addWidget(slideSizeBox); + layoutGeneral->addWidget(fitBox); + layoutGeneral->addWidget(colorBox); + layoutGeneral->addWidget(shortcutsBox); + layoutGeneral->addStretch(); + layoutFlow->addWidget(sw); +#ifndef NO_OPENGL + layoutFlow->addWidget(gl); + layoutFlow->addWidget(useGL); +#endif + layoutFlow->addStretch(); + layoutImage->addWidget(new QLabel(tr("Brightness")),0,0); + layoutImage->addWidget(new QLabel(tr("Contrast")),1,0); + layoutImage->addWidget(new QLabel(tr("Gamma")),2,0); + layoutImage->addWidget(brightnessS,0,1); + layoutImage->addWidget(contrastS,1,1); + layoutImage->addWidget(gammaS,2,1); + QPushButton * pushButton = new QPushButton(tr("Reset")); + connect(pushButton,SIGNAL(pressed()),this,SLOT(resetImageConfig())); + layoutImage->addWidget(pushButton,3,0); + layoutImage->setColumnStretch(1,1); + + + QGroupBox *imageBox = new QGroupBox(tr("Image options")); + imageBox->setLayout(layoutImage); + layoutImageV->addWidget(imageBox); + layoutImageV->addStretch(); + + + pageGeneral->setLayout(layoutGeneral); + pageFlow->setLayout(layoutFlow); + pageImage->setLayout(layoutImageV); + + tabWidget->addTab(pageGeneral,tr("General")); + tabWidget->addTab(pageFlow,tr("Page Flow")); + tabWidget->addTab(pageImage,tr("Image adjustment")); + + layout->addWidget(tabWidget); + layout->addLayout(buttons); + + setLayout(layout); + + //disable vSyncCheck +#ifndef NO_OPENGL + gl->vSyncCheck->hide(); +#endif + //restoreOptions(); //load options + //resize(400,0); + setModal (true); + setWindowTitle(tr("Options")); + + this->layout()->setSizeConstraint(QLayout::SetFixedSize); +} + +void OptionsDialog::findFolder() +{ + QString s = QFileDialog::getExistingDirectory(0,tr("Comics directory"),"."); + if(!s.isEmpty()) + { + pathEdit->setText(s); + } +} + +void OptionsDialog::saveOptions() +{ + + settings->setValue(GO_TO_FLOW_SIZE,QSize(static_cast(slideSize->sliderPosition()/SLIDE_ASPECT_RATIO),slideSize->sliderPosition())); + + if(sw->radio1->isChecked()) + settings->setValue(FLOW_TYPE_SW,0); + if(sw->radio2->isChecked()) + settings->setValue(FLOW_TYPE_SW,1); + if(sw->radio3->isChecked()) + settings->setValue(FLOW_TYPE_SW,2); + + settings->setValue(PATH,pathEdit->text()); + + settings->setValue(BACKGROUND_COLOR,colorDialog->currentColor()); + settings->setValue(FIT_TO_WIDTH_RATIO,fitToWidthRatioS->sliderPosition()/100.0); + + YACReaderOptionsDialog::saveOptions(); +} + +void OptionsDialog::restoreOptions(QSettings * settings) +{ + YACReaderOptionsDialog::restoreOptions(settings); + + slideSize->setSliderPosition(settings->value(GO_TO_FLOW_SIZE).toSize().height()); + switch(settings->value(FLOW_TYPE_SW).toInt()) + { + case 0: + sw->radio1->setChecked(true); + break; + case 1: + sw->radio2->setChecked(true); + break; + case 2: + sw->radio3->setChecked(true); + break; + default: + sw->radio1->setChecked(true); + break; + } + + pathEdit->setText(settings->value(PATH).toString()); + + updateColor(settings->value(BACKGROUND_COLOR).value()); + fitToWidthRatioS->setSliderPosition(settings->value(FIT_TO_WIDTH_RATIO).toFloat()*100); + + brightnessS->setValue(settings->value(BRIGHTNESS,0).toInt()); + contrastS->setValue(settings->value(CONTRAST,100).toInt()); + gammaS->setValue(settings->value(GAMMA,100).toInt()); +} + + +void OptionsDialog::updateColor(const QColor & color) +{ + QPalette pal = backgroundColor->palette(); + pal.setColor(backgroundColor->backgroundRole(), color); + backgroundColor->setPalette(pal); + backgroundColor->setAutoFillBackground(true); + colorDialog->setCurrentColor(color); + + settings->setValue(BACKGROUND_COLOR,color); + + emit(changedOptions()); +} + +void OptionsDialog::fitToWidthRatio(int value) +{ + Configuration::getConfiguration().setFitToWidthRatio(value/100.0); + emit(fitToWidthRatioChanged(value/100.0)); +} + +void OptionsDialog::brightnessChanged(int value) +{ + QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat); + settings.setValue(BRIGHTNESS,value); + emit changedFilters(brightnessS->getValue(), contrastS->getValue(), gammaS->getValue()); + //emit(changedImageOptions()); +} + +void OptionsDialog::contrastChanged(int value) +{ + QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat); + settings.setValue(CONTRAST,value); + emit changedFilters(brightnessS->getValue(), contrastS->getValue(), gammaS->getValue()); + ///emit(changedImageOptions()); +} + +void OptionsDialog::gammaChanged(int value) +{ + QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat); + settings.setValue(GAMMA,value); + emit changedFilters(brightnessS->getValue(), contrastS->getValue(), gammaS->getValue()); + //emit(changedImageOptions()); +} + +void OptionsDialog::resetImageConfig() +{ + brightnessS->setValue(0); + contrastS->setValue(100); + gammaS->setValue(100); + QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat); + settings.setValue(BRIGHTNESS,0); + settings.setValue(CONTRAST,100); + settings.setValue(GAMMA,100); + emit changedFilters(brightnessS->getValue(), contrastS->getValue(), gammaS->getValue()); + //emit(changedImageOptions()); +} + +void OptionsDialog::show() +{ + //TODO solucionar el tema de las settings, esto sólo debería aparecer en una única línea de código + QSettings *s = new QSettings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat); + fitToWidthRatioS->disconnect(); + fitToWidthRatioS->setSliderPosition(settings->value(FIT_TO_WIDTH_RATIO).toFloat()*100); + connect(fitToWidthRatioS,SIGNAL(valueChanged(int)),this,SLOT(fitToWidthRatio(int))); + QDialog::show(); + delete s; +} + +void OptionsDialog::setFilters(int brightness, int contrast, int gamma) +{ + if(brightness != -1) + brightnessS->setValue(brightness); + else + brightnessS->setValue(0); + if(contrast != -1) + contrastS->setValue(contrast); + else + contrastS->setValue(100); + if(gamma != -1) + gammaS->setValue(gamma); + else + gammaS->setValue(100); + +} diff --git a/YACReader/options_dialog.h b/YACReader/options_dialog.h new file mode 100644 index 00000000..3bf0c5ec --- /dev/null +++ b/YACReader/options_dialog.h @@ -0,0 +1,70 @@ +#ifndef __OPTIONS_DIALOG_H +#define __OPTIONS_DIALOG_H + +#include "yacreader_options_dialog.h" + +class QDialog; +class QLabel; +class QLineEdit; +class QPushButton; +class QSlider; +class QPushButton; +class QRadioButton; +class QColorDialog; +class YACReaderSpinSliderWidget; + + +class OptionsDialog : public YACReaderOptionsDialog +{ +Q_OBJECT + public: + OptionsDialog(QWidget * parent = 0); + private: + //QLabel * pathLabel; + QLineEdit * pathEdit; + QPushButton * pathFindButton; + + QLabel * magGlassSizeLabel; + + QLabel * zoomLevel; + + //QLabel * slideSizeLabel; + QSlider * slideSize; + + //QLabel * fitToWidthRatioLabel; + QSlider * fitToWidthRatioS; + + QLabel * backgroundColor; + QPushButton * selectBackgroundColorButton; + + QColorDialog * colorDialog; + + YACReaderSpinSliderWidget * brightnessS; + + YACReaderSpinSliderWidget * contrastS; + + YACReaderSpinSliderWidget * gammaS; + + public slots: + void saveOptions(); + void restoreOptions(QSettings * settings); + void findFolder(); + void updateColor(const QColor & color); + void fitToWidthRatio(int value); + void brightnessChanged(int value); + void contrastChanged(int value); + void gammaChanged(int value); + void resetImageConfig(); + void show(); + void setFilters(int brightness, int contrast, int gamma); + +signals: + void changedOptions(); + void changedImageOptions(); + void changedFilters(int brightness, int contrast, int gamma); + void fitToWidthRatioChanged(float ratio); + +}; + + +#endif diff --git a/YACReader/page_label_widget.cpp b/YACReader/page_label_widget.cpp new file mode 100644 index 00000000..e7ec979c --- /dev/null +++ b/YACReader/page_label_widget.cpp @@ -0,0 +1,122 @@ +#include "page_label_widget.h" + +#include +#include +#include +#include +#include + +PageLabelWidget::PageLabelWidget(QWidget * parent) + :QWidget(parent) + { + animation = new QPropertyAnimation(this,"pos"); + animation->setDuration(150); + animation->setEndValue(QPoint((parent->geometry().size().width()-this->width()),-this->height())); + + int verticalRes = QApplication::desktop()->screenGeometry().height(); + + imgLabel = new QLabel(this); + QPixmap p; + if (verticalRes <= 1024) + p.load(":/images/numPagesLabel.png"); + else if (verticalRes <= 1200) + p.load(":/images/numPagesLabelMedium.png"); + else + p.load(":/images/numPagesLabelBig.png"); + imgLabel->resize(p.size()); + imgLabel->setPixmap(p); + + textLabel = new QLabel(this); + textLabel->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter); + if(verticalRes <= 1024) + textLabel->setStyleSheet("QLabel { color : white; font-size:12px; padding-left:8px; }"); + else if (verticalRes <= 1200) + textLabel->setStyleSheet("QLabel { color : white; font-size:16px; padding-left:8px;}"); + else + textLabel->setStyleSheet("QLabel { color : white; font-size:20px; padding-left:8px; }"); + + //informationLabel->setAutoFillBackground(true); + //textLabel->setFont(QFont("courier new bold", 12)); + //textLabel->resize(100,25); + + resize(p.size()); + //por defecto aparece oculto + if(parent != 0) + move(QPoint((parent->geometry().size().width()-this->width()),-this->height())); + /*QSize size = textLabel->sizeHint(); + + int w = width(); // returns screen width + int h = height(); // returns screen height + int mw = size.width(); + int mh = size.height(); + int cw = (w-mw)/2; + int ch = 0; + textLabel->move(cw,ch);*/ + } + +void PageLabelWidget::show() +{ + if(this->pos().y() <= 0 && animation->state()!=QPropertyAnimation::Running) + { + QWidget * parent = dynamic_cast(this->parent()); + if(parent == 0) + { + return; + } + + QWidget::show(); + //connect(animation,SIGNAL(finished()),this,SLOT(QWidget::hide())); + animation->disconnect(); + + animation->setStartValue(QPoint((parent->geometry().size().width()-this->width()),-this->height())); + animation->setEndValue(QPoint((parent->geometry().size().width()-this->width()),0)); + animation->start(); + } +} + +void PageLabelWidget::hide() +{ + + if(this->pos().y() >= 0 && animation->state()!=QPropertyAnimation::Running) + { + QWidget * parent = dynamic_cast(this->parent()); + if(parent == 0) + { + return; + } + //connect(animation,SIGNAL(finished()),this,SLOT(setHidden())); + animation->setStartValue(QPoint((parent->geometry().size().width()-this->width()),0)); + animation->setEndValue(QPoint((parent->geometry().size().width()-this->width()),-this->height())); + animation->start(); + } +} + +void PageLabelWidget::setText(const QString & text) +{ + textLabel->setText(text); + QRect geom = imgLabel->geometry(); + QSize size = geom.size(); + size.setHeight(size.height() - 10);//TODO remove this amazing magic number + geom.setSize(size); + textLabel->setGeometry(geom); +} + +/*void PageLabelWidget::resizeEvent(QResizeEvent * event) +{ + move(QPoint((((QWidget *) parent())->geometry().size().width()-this->width())/2,0)); +}*/ + +void PageLabelWidget::updatePosition() +{ + QWidget * parent = dynamic_cast(this->parent()); + if(parent == 0) + { + return; + } + + animation->stop(); + if (animation->endValue().toPoint().y() == 0) + move(QPoint((parent->geometry().size().width()-this->width()),0)); + else + move(QPoint((parent->geometry().size().width()-this->width()),-this->height())); +} diff --git a/YACReader/page_label_widget.h b/YACReader/page_label_widget.h new file mode 100644 index 00000000..315a1e4c --- /dev/null +++ b/YACReader/page_label_widget.h @@ -0,0 +1,29 @@ +#ifndef PAGE_LABEL_WIDGET_H +#define PAGE_LABEL_WIDGET_H + +#include + +class QLabel; +class QPropertyAnimation; + +class PageLabelWidget : public QWidget +{ +Q_OBJECT +private: + QLabel * imgLabel; + QLabel * textLabel; + QPropertyAnimation * animation; + + //void resizeEvent(QResizeEvent * event); + +public: + PageLabelWidget(QWidget * parent); + +public slots: + void show(); + void hide(); + void setText(const QString & text); + void updatePosition(); +}; + +#endif \ No newline at end of file diff --git a/YACReader/render.cpp b/YACReader/render.cpp new file mode 100644 index 00000000..cc53b8c5 --- /dev/null +++ b/YACReader/render.cpp @@ -0,0 +1,1187 @@ +#include "render.h" +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "comic_db.h" +#include "yacreader_global.h" + +template +inline const T& kClamp( const T& x, const T& low, const T& high ) +{ + if ( x < low ) return low; + else if ( high < x ) return high; + else return x; +} + +inline +int changeBrightness( int value, int brightness ) + { + return kClamp( value + brightness * 255 / 100, 0, 255 ); + } + +inline +int changeContrast( int value, int contrast ) + { + return kClamp((( value - 127 ) * contrast / 100 ) + 127, 0, 255 ); + } + +inline +int changeGamma( int value, int gamma ) + { + return kClamp( int( pow( value / 255.0, 100.0 / gamma ) * 255 ), 0, 255 ); + } + +inline +int changeUsingTable( int value, const int table[] ) + { + return table[ value ]; + } + +template< int operation( int, int ) > +static +QImage changeImage( const QImage& image, int value ) + { + QImage im = image; + im.detach(); + if( im.colorCount() == 0 ) /* truecolor */ + { + if( im.format() != QImage::Format_RGB32 ) /* just in case */ + im = im.convertToFormat( QImage::Format_RGB32 ); + int table[ 256 ]; + for( int i = 0; + i < 256; + ++i ) + table[ i ] = operation( i, value ); + if( im.hasAlphaChannel() ) + { + for( int y = 0; + y < im.height(); + ++y ) + { + QRgb* line = reinterpret_cast< QRgb* >( im.scanLine( y )); + for( int x = 0; + x < im.width(); + ++x ) + line[ x ] = qRgba( changeUsingTable( qRed( line[ x ] ), table ), + changeUsingTable( qGreen( line[ x ] ), table ), + changeUsingTable( qBlue( line[ x ] ), table ), + changeUsingTable( qAlpha( line[ x ] ), table )); + } + } + else + { + for( int y = 0; + y < im.height(); + ++y ) + { + QRgb* line = reinterpret_cast< QRgb* >( im.scanLine( y )); + for( int x = 0; + x < im.width(); + ++x ) + line[ x ] = qRgb( changeUsingTable( qRed( line[ x ] ), table ), + changeUsingTable( qGreen( line[ x ] ), table ), + changeUsingTable( qBlue( line[ x ] ), table )); + } + } + } + else + { + QVector colors = im.colorTable(); + for( int i = 0; + i < im.colorCount(); + ++i ) + colors[ i ] = qRgb( operation( qRed( colors[ i ] ), value ), + operation( qGreen( colors[ i ] ), value ), + operation( qBlue( colors[ i ] ), value )); + im.setColorTable(colors); + } + return im; + } + + +// brightness is multiplied by 100 in order to avoid floating point numbers +QImage changeBrightness( const QImage& image, int brightness ) + { + if( brightness == 0 ) // no change + return image; + return changeImage< changeBrightness >( image, brightness ); + } + + +// contrast is multiplied by 100 in order to avoid floating point numbers +QImage changeContrast( const QImage& image, int contrast ) + { + if( contrast == 100 ) // no change + return image; + return changeImage< changeContrast >( image, contrast ); + } + +// gamma is multiplied by 100 in order to avoid floating point numbers +QImage changeGamma( const QImage& image, int gamma ) + { + if( gamma == 100 ) // no change + return image; + return changeImage< changeGamma >( image, gamma ); + } + + + +//----------------------------------------------------------------------------- +// MeanNoiseReductionFilter +//----------------------------------------------------------------------------- + +MeanNoiseReductionFilter::MeanNoiseReductionFilter(enum NeighborghoodSize ns) +:neighborghoodSize(ns) +{ + +} + +QImage MeanNoiseReductionFilter::setFilter(const QImage & image) +{ + int width = image.width(); + int height = image.height(); + QImage result(width,height,image.format()); + int filterSize = sqrt((float)neighborghoodSize); + int bound = filterSize/2; + QRgb pix; + int r,g,b; + for(int j=bound;j redChannel; + QList greenChannel; + QList blueChannel; + for(int j=bound;j hist(256,0); + + for(int j=0;j 1; i--) + { + new_count += hist[i]; + percentage = new_count/count; + next_percentage = (new_count+hist[i-1])/count; + if(fabs (percentage - 0.006) < fabs (next_percentage - 0.006)) + { + max = i-1; + break; + } + } + QColor c; + int range = max - min; + for(int j=0;j f) +:QThread(), +render(r), +numPage(np), +data(rd), +page(p), +degrees(d), +filters(f) +{ +} + +void PageRender::run() +{ + QMutexLocker locker(&(render->mutex)); + + QImage img; + img.loadFromData(data); + if(degrees > 0) + { + QMatrix m; + m.rotate(degrees); + img = img.transformed(m,Qt::SmoothTransformation); + } + for(int i=0;isetFilter(img); + } + + + *page = img; + + emit pageReady(numPage); +} + +//----------------------------------------------------------------------------- +// Render +//----------------------------------------------------------------------------- + +Render::Render() +:currentIndex(0),doublePage(false),doubleMangaPage(false),comic(0),loadedComic(false),imageRotation(0),numLeftPages(4),numRightPages(4) +{ + int size = numLeftPages+numRightPages+1; + currentPageBufferedIndex = numLeftPages; + for(int i = 0; imoveToThread(QApplication::instance()->thread()); + comic->deleteLater(); + } + + foreach(ImageFilter * filter, filters) + delete filter; + + foreach(PageRender * pr,pageRenders) + if(pr !=0) + { + if(pr->wait()) + delete pr; + } +} +//Este método se encarga de forzar el renderizado de las páginas. +//Actualiza el buffer según es necesario. +//si la pagina actual no está renderizada, se lanza un hilo que la renderize (double or single page mode) y se emite una señal que indica que se está renderizando. +void Render::render() +{ + updateBuffer(); + if(buffer[currentPageBufferedIndex]->isNull()) + { + if(pagesReady.size()>0) + { + if(pagesReady[currentIndex]) + { + pageRenders[currentPageBufferedIndex] = new PageRender(this,currentIndex,comic->getRawData()->at(currentIndex),buffer[currentPageBufferedIndex],imageRotation,filters); + } + else + //las páginas no están listas, y se están cargando en el cómic + emit processingPage(); //para evitar confusiones esta señal debería llamarse de otra forma + + //si se ha creado un hilo para renderizar la página actual, se arranca + if(pageRenders[currentPageBufferedIndex]!=0) + { + //se conecta la señal pageReady del hilo, con el SLOT prepareAvailablePage + connect(pageRenders[currentPageBufferedIndex],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); + //se emite la señal de procesando, debido a que los hilos se arrancan aquí + if(filters.size()>0) + emit processingPage(); + pageRenders[currentPageBufferedIndex]->start(); + pageRenders[currentPageBufferedIndex]->setPriority(QThread::TimeCriticalPriority); + } + else + //en qué caso sería necesario hacer esto??? //TODO: IMPORTANTE, puede que no sea necesario. + emit processingPage(); + } + else + //no hay ninguna página lista para ser renderizada, es necesario esperar. + emit processingPage(); + } + else + // la página actual está lista + { + //emit currentPageReady(); + //make prepareAvailablePage the only function that emits currentPageReady() + prepareAvailablePage(currentIndex); + } + fillBuffer(); +} + +QPixmap * Render::getCurrentPage() +{ + QPixmap * page = new QPixmap(); + *page = page->fromImage(*buffer[currentPageBufferedIndex]); + return page; +} + +QPixmap * Render::getCurrentDoublePage() +{ + if (currentPageIsDoublePage()) + { + QPoint leftpage(0,0); + QPoint rightpage(0,0); + QSize leftsize = buffer[currentPageBufferedIndex]->size(); + QSize rightsize = buffer[currentPageBufferedIndex+1]->size(); + int totalWidth,totalHeight; + switch (imageRotation) + { + case 0: + totalHeight = qMax(leftsize.rheight(),rightsize.rheight()); + leftsize.scale(leftsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + rightsize.scale(rightsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + totalWidth = leftsize.rwidth() + rightsize.rwidth(); + rightpage.setX(leftsize.rwidth()); + break; + case 90: + totalWidth = qMax(leftsize.rwidth(), rightsize.rwidth()); + leftsize.scale(totalWidth, leftsize.rheight(), Qt::KeepAspectRatioByExpanding); + rightsize.scale(totalWidth, rightsize.rheight(), Qt::KeepAspectRatioByExpanding); + totalHeight = leftsize.rheight() + rightsize.rheight(); + rightpage.setY(leftsize.rheight()); + break; + case 180: + totalHeight = qMax(leftsize.rheight(),rightsize.rheight()); + leftsize.scale(leftsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + rightsize.scale(rightsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + totalWidth = leftsize.rwidth() + rightsize.rwidth(); + leftpage.setX(rightsize.rwidth()); + break; + case 270: + totalWidth = qMax(leftsize.rwidth(), rightsize.rwidth()); + leftsize.scale(totalWidth, leftsize.rheight(), Qt::KeepAspectRatioByExpanding); + rightsize.scale(totalWidth, rightsize.rheight(), Qt::KeepAspectRatioByExpanding); + totalHeight = leftsize.rheight() + rightsize.rheight(); + leftpage.setY(rightsize.rheight()); + break; + default: + return NULL; + } + QPixmap * page = new QPixmap(totalWidth, totalHeight); + QPainter painter(page); + painter.drawImage(QRect(leftpage,leftsize), *buffer[currentPageBufferedIndex]); + painter.drawImage(QRect(rightpage,rightsize), *buffer[currentPageBufferedIndex+1]); + return page; + } + else + { + return NULL; + } +} + +QPixmap * Render::getCurrentDoubleMangaPage() +{ + if (currentPageIsDoublePage()) + { + QPoint leftpage(0,0); + QPoint rightpage(0,0); + QSize leftsize = buffer[currentPageBufferedIndex+1]->size(); + QSize rightsize = buffer[currentPageBufferedIndex]->size(); + int totalWidth,totalHeight; + switch (imageRotation) + { + case 0: + totalHeight = qMax(leftsize.rheight(),rightsize.rheight()); + leftsize.scale(leftsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + rightsize.scale(rightsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + totalWidth = leftsize.rwidth() + rightsize.rwidth(); + rightpage.setX(leftsize.rwidth()); + break; + case 90: + totalWidth = qMax(leftsize.rwidth(), rightsize.rwidth()); + leftsize.scale(totalWidth, leftsize.rheight(), Qt::KeepAspectRatioByExpanding); + rightsize.scale(totalWidth, rightsize.rheight(), Qt::KeepAspectRatioByExpanding); + totalHeight = leftsize.rheight() + rightsize.rheight(); + rightpage.setY(leftsize.rheight()); + break; + case 180: + totalHeight = qMax(leftsize.rheight(),rightsize.rheight()); + leftsize.scale(leftsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + rightsize.scale(rightsize.rwidth(), totalHeight, Qt::KeepAspectRatioByExpanding); + totalWidth = leftsize.rwidth() + rightsize.rwidth(); + leftpage.setX(rightsize.rwidth()); + break; + case 270: + totalWidth = qMax(leftsize.rwidth(), rightsize.rwidth()); + leftsize.scale(totalWidth, leftsize.rheight(), Qt::KeepAspectRatioByExpanding); + rightsize.scale(totalWidth, rightsize.rheight(), Qt::KeepAspectRatioByExpanding); + totalHeight = leftsize.rheight() + rightsize.rheight(); + leftpage.setY(rightsize.rheight()); + break; + default: + return NULL; + } + QPixmap * page = new QPixmap(totalWidth, totalHeight); + QPainter painter(page); + painter.drawImage(QRect(rightpage, rightsize), *buffer[currentPageBufferedIndex]); + painter.drawImage(QRect(leftpage, leftsize), *buffer[currentPageBufferedIndex+1]); + return page; + } + else + { + return NULL; + } +} + +bool Render::currentPageIsDoublePage() +{ + if (buffer[currentPageBufferedIndex]->isNull() || buffer[currentPageBufferedIndex+1]->isNull()) + { + return false; + } + if (imageRotation == 0 || imageRotation == 180) + { + if (buffer[currentPageBufferedIndex]->height() > buffer[currentPageBufferedIndex]->width() && + buffer[currentPageBufferedIndex+1]->height() > buffer[currentPageBufferedIndex+1]->width()) + { + return true; + } + } + else if (imageRotation == 90 || imageRotation == 270) + { + if (buffer[currentPageBufferedIndex]->width() > buffer[currentPageBufferedIndex]->height() && + buffer[currentPageBufferedIndex+1]->width() > buffer[currentPageBufferedIndex+1]->height()) + { + return true; + } + } + return false; +} + +bool Render::nextPageIsDoublePage() +{ + //this function is not used right now + if (buffer[currentPageBufferedIndex+2]->isNull() || buffer[currentPageBufferedIndex+3]->isNull()) + { + return false; + } + if (imageRotation == 0 || imageRotation == 180) + { + if (buffer[currentPageBufferedIndex+2]->height() > buffer[currentPageBufferedIndex+2]->width() && + buffer[currentPageBufferedIndex+3]->height() > buffer[currentPageBufferedIndex+3]->width()) + { + return true; + } + } + else if (imageRotation == 90 || imageRotation == 270) + { + if (buffer[currentPageBufferedIndex]->width() > buffer[currentPageBufferedIndex]->height() && + buffer[currentPageBufferedIndex+1]->width() > buffer[currentPageBufferedIndex+1]->height()) + { + return true; + } + } + return false; +} + +bool Render::previousPageIsDoublePage() +{ + if (buffer[currentPageBufferedIndex-1]->isNull() || buffer[currentPageBufferedIndex-2]->isNull()) + { + return false; + } + if (imageRotation == 0 || imageRotation == 180) + { + if (buffer[currentPageBufferedIndex-1]->height() > buffer[currentPageBufferedIndex-1]->width() && + buffer[currentPageBufferedIndex-2]->height() > buffer[currentPageBufferedIndex-2]->width()) + { + return true; + } + } + else if (imageRotation == 90 || imageRotation == 270) + { + if (buffer[currentPageBufferedIndex-1]->width() > buffer[currentPageBufferedIndex-1]->height() && + buffer[currentPageBufferedIndex-2]->width() > buffer[currentPageBufferedIndex-2]->height()) + { + return true; + } + } + return false; +} + +void Render::setRotation(int degrees) +{ + Q_UNUSED(degrees) +} + +void Render::setComic(Comic * c) +{ + if(comic !=0) + { + comic->moveToThread(QApplication::instance()->thread()); + comic->disconnect(); + comic->deleteLater(); + } + comic = c; +} + +void Render::prepareAvailablePage(int page) +{ + if(!doublePage) + { + if (currentIndex == page) + { + emit currentPageReady(); + } + } + else + { + //check for last page in double page mode + if ((currentIndex == page) && (currentIndex + 1) >= (int)comic->numPages()) + { + emit currentPageReady(); + } + else if ((currentIndex == page && !buffer[currentPageBufferedIndex+1]->isNull()) || + (currentIndex+1 == page && !buffer[currentPageBufferedIndex]->isNull())) + { + emit currentPageReady(); + } + } +} + +void Render::update() +{ + render(); +} +//----------------------------------------------------------------------------- +// Comic interface +//----------------------------------------------------------------------------- +void Render::load(const QString & path, int atPage) +{ + createComic(path); + if (comic !=0) + { + loadComic(path,atPage); + startLoad(); + } +} + +//----------------------------------------------------------------------------- +void Render::load(const QString & path, const ComicDB & comicDB) +{ + //TODO prepare filters + for(int i = 0; i < filters.count(); i++) + { + if(typeid(*filters[i]) == typeid(BrightnessFilter)) + if(comicDB.info.brightness == -1) + filters[i]->setLevel(0); + else + filters[i]->setLevel(comicDB.info.brightness); + if(typeid(*filters[i]) == typeid(ContrastFilter)) + if(comicDB.info.contrast == -1) + filters[i]->setLevel(100); + else + filters[i]->setLevel(comicDB.info.contrast); + if(typeid(*filters[i]) == typeid(GammaFilter)) + if(comicDB.info.gamma == -1) + filters[i]->setLevel(100); + else + filters[i]->setLevel(comicDB.info.gamma); + } + createComic(path); + if (comic!=0) + { + loadComic(path,comicDB); + startLoad(); + } +} + +void Render::createComic(const QString & path) +{ + if(comic!=0) + { + //comic->moveToThread(QApplication::instance()->thread()); + comic->disconnect(); + comic->deleteLater(); + } + //comic->moveToThread(QApplication::instance()->thread()); + comic = FactoryComic::newComic(path); + + + if(comic == NULL)//archivo no encontrado o no válido + { + emit errorOpening(); + reset(); + return; + } + + previousIndex = currentIndex = 0; + + connect(comic,SIGNAL(errorOpening()),this,SIGNAL(errorOpening())); + connect(comic,SIGNAL(errorOpening(QString)),this,SIGNAL(errorOpening(QString))); + connect(comic,SIGNAL(crcErrorFound(QString)),this,SIGNAL(crcError(QString))); + connect(comic,SIGNAL(errorOpening()),this,SLOT(reset())); + connect(comic,SIGNAL(imageLoaded(int)),this,SIGNAL(imageLoaded(int))); + connect(comic,SIGNAL(imageLoaded(int)),this,SLOT(pageRawDataReady(int))); + connect(comic,SIGNAL(openAt(int)),this,SLOT(renderAt(int))); + connect(comic,SIGNAL(numPages(unsigned int)),this,SIGNAL(numPages(unsigned int))); + connect(comic,SIGNAL(numPages(unsigned int)),this,SLOT(setNumPages(unsigned int))); + connect(comic,SIGNAL(imageLoaded(int,QByteArray)),this,SIGNAL(imageLoaded(int,QByteArray))); + connect(comic,SIGNAL(isBookmark(bool)),this,SIGNAL(currentPageIsBookmark(bool))); + connect(comic,SIGNAL(isBookmark(bool)),this,SLOT(pageIsBookmark(bool))); + + connect(comic,SIGNAL(bookmarksUpdated()),this,SIGNAL(bookmarksUpdated())); + + //connect(comic,SIGNAL(isLast()),this,SIGNAL(isLast())); + //connect(comic,SIGNAL(isCover()),this,SIGNAL(isCover())); + + pagesReady.clear(); +} +void Render::loadComic(const QString & path,const ComicDB & comicDB) +{ + comic->load(path,comicDB); +} +void Render::loadComic(const QString & path, int atPage) +{ + comic->load(path,atPage); +} + +void Render::startLoad() +{ + QThread * thread = NULL; + + thread = new QThread(); + + comic->moveToThread(thread); + + connect(comic, SIGNAL(errorOpening()), thread, SLOT(quit())); + connect(comic, SIGNAL(errorOpening(QString)), thread, SLOT(quit())); + connect(comic, SIGNAL(imagesLoaded()), thread, SLOT(quit())); + connect(thread, SIGNAL(started()), comic, SLOT(process())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + if(thread != NULL) + thread->start(); + + invalidate(); + loadedComic = true; + update(); +} + +void Render::renderAt(int page) +{ + previousIndex = currentIndex = page; + emit pageChanged(page); +} + +void Render::reset() +{ + loadedComic = false; + invalidate(); +} +//si se solicita la siguiente página, se calcula cuál debe ser en función de si se lee en modo a doble página o no. +//la página sólo se renderiza, si realmente ha cambiado. +void Render::nextPage() +{ + int nextPage; //indica cuál será la próxima página + nextPage = comic->nextPage(); + //se fuerza renderizado si la página ha cambiado + if(currentIndex != nextPage) + { + previousIndex = currentIndex; + currentIndex = nextPage; + update(); + emit pageChanged(currentIndex); + } + else if (hasLoadedComic() && (currentIndex == numPages()-1)) + { + emit isLast(); + } +} +void Render::nextDoublePage() +{ + int nextPage; + if (currentIndex +2 < (int)comic->numPages()) + { + nextPage = currentIndex+2; + } + else + { + nextPage = currentIndex; + } + if(currentIndex != nextPage) + { + comic->setIndex(nextPage); + previousIndex = currentIndex; + currentIndex = nextPage; + update(); + emit pageChanged(currentIndex); + } + else if (hasLoadedComic() && (currentIndex >= numPages()-2)) + { + emit isLast(); + } +} + +//si se solicita la página anterior, se calcula cuál debe ser en función de si se lee en modo a doble página o no. +//la página sólo se renderiza, si realmente ha cambiado. +void Render::previousPage() +{ + int previousPage; //indica cuál será la próxima página + previousPage = comic->previousPage(); + + //se fuerza renderizado si la página ha cambiado + if(currentIndex != previousPage) + { + previousIndex = currentIndex; + currentIndex = previousPage; + update(); + emit pageChanged(currentIndex); + } + else if (hasLoadedComic() && (currentIndex == 0)) + { + emit isCover(); + } +} + +void Render::previousDoublePage() +{ + int previousPage; //indica cuál será la próxima página + previousPage = qMax(currentIndex-2,0); + if(currentIndex != previousPage) + { + comic->setIndex(previousPage); + previousIndex = currentIndex; + currentIndex = previousPage; + update(); + emit pageChanged(currentIndex); + } +} + +unsigned int Render::getIndex() +{ + return comic->getIndex(); +} +unsigned int Render::numPages() +{ + return comic->numPages(); +} + +bool Render::hasLoadedComic() +{ + if(comic!=0) + return comic->loaded(); + return false; +} + +void Render::setNumPages(unsigned int numPages) +{ + pagesReady.fill(false,numPages); +} + +void Render::pageRawDataReady(int page) +{ + if (!hasLoadedComic()) + return; + + pagesEmited.push_back(page); + if(pageRenders.size()>0) + { + for(int i=0;i= pagesReady.size()) + return; //Oooops, something went wrong + + pagesReady[pagesEmited.at(i)] = true; + if(pagesEmited.at(i) == currentIndex) + update(); + else + { + if ( ((pagesEmited.at(i) < currentIndex) && (pagesEmited.at(i) > currentIndex-numLeftPages)) || + ((pagesEmited.at(i) > currentIndex) && (pagesEmited.at(i) < currentIndex+numRightPages)) ) + { + fillBuffer(); + } + } + } + pagesEmited.clear(); + } +} + +//sólo se renderiza la página, si ha habido un cambio de página +void Render::goTo(int index) +{ + + if(currentIndex != index) + { + comic->setIndex(index); + previousIndex = currentIndex; + currentIndex = index; + update(); + emit pageChanged(currentIndex); + } +} + +void Render::rotateRight() +{ + imageRotation = (imageRotation+90) % 360; + reload(); +} +void Render::rotateLeft() +{ + if(imageRotation == 0) + imageRotation = 270; + else + imageRotation = imageRotation - 90; + reload(); +} + +//Actualiza el buffer, añadiendo las imágenes (vacías) necesarias para su posterior renderizado y +//eliminado aquellas que ya no sean necesarias. También libera los hilos (no estoy seguro de que sea responsabilidad suya) +//Calcula el número de nuevas páginas que hay que buferear y si debe hacerlo por la izquierda o la derecha (según sea el sentido de la lectura) +void Render::updateBuffer() +{ + QMutexLocker locker(&mutex); + int windowSize = currentIndex - previousIndex; + + if(windowSize > 0)//add pages to right pages and remove on the left + { + windowSize = qMin(windowSize,buffer.size()); + for(int i = 0; i < windowSize; i++) + { + //renders + PageRender * pr = pageRenders.front(); + pageRenders.pop_front(); + if(pr !=0) + { + if(pr->wait()) + delete pr; + } + pageRenders.push_back(0); + + //images + + if(buffer.front()!=0) + delete buffer.front(); + buffer.pop_front(); + buffer.push_back(new QImage()); + } + } + else //add pages to left pages and remove on the right + if(windowSize<0) + { + windowSize = -windowSize; + windowSize = qMin(windowSize,buffer.size()); + for(int i = 0; i < windowSize; i++) + { + //renders + PageRender * pr = pageRenders.back(); + pageRenders.pop_back(); + if(pr !=0) + { + if(pr->wait()) + delete pr; + } + pageRenders.push_front(0); + + //images + buffer.push_front(new QImage()); + QImage * p = buffer.back(); + if(p!=0) + delete p; + buffer.pop_back(); + } + } + previousIndex = currentIndex; +} + +void Render::fillBuffer() +{ + for(int i = 1; i <= qMax(numLeftPages,numRightPages); i++) + { + if ((currentIndex+i < (int)comic->numPages()) && + buffer[currentPageBufferedIndex+i]->isNull() && + i <= numRightPages && + pageRenders[currentPageBufferedIndex+i]==0 && + pagesReady[currentIndex+i]) //preload next pages + { + pageRenders[currentPageBufferedIndex+i] = new PageRender(this,currentIndex+i,comic->getRawData()->at(currentIndex+i),buffer[currentPageBufferedIndex+i],imageRotation,filters); + connect(pageRenders[currentPageBufferedIndex+i],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); + pageRenders[currentPageBufferedIndex+i]->start(); + } + + if ((currentIndex-i > 0) && + buffer[currentPageBufferedIndex-i]->isNull() && + i <= numLeftPages && + pageRenders[currentPageBufferedIndex-i]==0 && + pagesReady[currentIndex-i]) //preload previous pages + { + pageRenders[currentPageBufferedIndex-i] = new PageRender(this,currentIndex-i,comic->getRawData()->at(currentIndex-i),buffer[currentPageBufferedIndex-i],imageRotation,filters); + connect(pageRenders[currentPageBufferedIndex-i],SIGNAL(pageReady(int)),this,SLOT(prepareAvailablePage(int))); + pageRenders[currentPageBufferedIndex-i]->start(); + } + } +} + + +//Método que debe ser llamado cada vez que la estructura del buffer se vuelve inconsistente con el modo de lectura actual. +//se terminan todos los hilos en ejecución y se libera la memoria (de hilos e imágenes) +void Render::invalidate() +{ + for(int i=0;iwait(); + delete pageRenders[i]; + pageRenders[i] = 0; + } + } + + for(int i=0;inumPages())) + { + if (currentPageIsDoublePage()) + { + if (doubleMangaPage) + s = QString::number(currentIndex+2) + "-" + s; + else + s += "-"+QString::number(currentIndex+2); + } + } + s += "/"+QString::number(comic->numPages()); + return s; +} + +void Render::setBookmark() +{ + comic->setBookmark(); +} + +void Render::removeBookmark() +{ + comic->removeBookmark(); +} + +void Render::save() +{ + comic->saveBookmarks(); +} + +Bookmarks * Render::getBookmarks() +{ + return comic->bm; +} + +void Render::reload() +{ + if(comic) + { + invalidate(); + update(); + } +} + +void Render::updateFilters(int brightness, int contrast, int gamma) +{ + for(int i = 0; i < filters.count(); i++) + { + if(typeid(*filters[i]) == typeid(BrightnessFilter)) + filters[i]->setLevel(brightness); + if(typeid(*filters[i]) == typeid(ContrastFilter)) + filters[i]->setLevel(contrast); + if(typeid(*filters[i]) == typeid(GammaFilter)) + filters[i]->setLevel(gamma); + } + + reload(); +} diff --git a/YACReader/render.h b/YACReader/render.h new file mode 100644 index 00000000..9c525c55 --- /dev/null +++ b/YACReader/render.h @@ -0,0 +1,215 @@ + #ifndef RENDER_H +#define RENDER_H + +#include +#include +#include +#include +#include +#include +#include "comic.h" +//----------------------------------------------------------------------------- +// FILTERS +//----------------------------------------------------------------------------- + +#include + +class Comic; +class ComicDB; +class Render; + +class ImageFilter { +public: + ImageFilter(){}; + virtual QImage setFilter(const QImage & image) = 0; + inline int getLevel() {return level;}; + inline void setLevel(int l) {level = l;}; +protected: + int level; +}; + +class MeanNoiseReductionFilter : public ImageFilter { +public: + enum NeighborghoodSize{SMALL=9, LARGE=25 }; + MeanNoiseReductionFilter(enum NeighborghoodSize ns = SMALL); + virtual QImage setFilter(const QImage & image); +private: + enum NeighborghoodSize neighborghoodSize; +}; + +class MedianNoiseReductionFilter : public ImageFilter { +public: + enum NeighborghoodSize{SMALL=9, LARGE=25 }; + MedianNoiseReductionFilter(enum NeighborghoodSize ns = SMALL); + virtual QImage setFilter(const QImage & image); +private: + enum NeighborghoodSize neighborghoodSize; +}; + +class BrightnessFilter : public ImageFilter { +public: + BrightnessFilter(int l=-1); + virtual QImage setFilter(const QImage & image); +}; + +class ContrastFilter : public ImageFilter { +public: + ContrastFilter(int l=-1); + virtual QImage setFilter(const QImage & image); +}; + +class GammaFilter : public ImageFilter { +public: + GammaFilter(int l=-1); + virtual QImage setFilter(const QImage & image); +}; + +//----------------------------------------------------------------------------- +// RENDER +//----------------------------------------------------------------------------- + +class PageRender : public QThread +{ + Q_OBJECT +public: + PageRender(); + PageRender(Render * render,int numPage, const QByteArray & rawData, QImage * page,unsigned int degrees=0, QVector filters = QVector()); + int getNumPage(){return numPage;}; + void setData(const QByteArray & rawData){data = rawData;}; + void setPage(QImage * p){page = p;}; + void setRotation(unsigned int d){degrees = d;}; + void setFilters(QVector f){filters = f;}; +private: + int numPage; + QByteArray data; + QImage * page; + unsigned int degrees; + QVector filters; + void run(); + Render * render; +signals: + void pageReady(int); + +}; +//----------------------------------------------------------------------------- +// RENDER +//----------------------------------------------------------------------------- + +/*class DoublePageRender : public PageRender +{ + Q_OBJECT +public: + DoublePageRender(Render * render, int firstPage, const QByteArray & firstPageData,const QByteArray & secondPageData, QImage * page,unsigned int degrees=0, QVector filters = QVector()); +private: + int numPage; + QByteArray data; + QByteArray data2; + QImage * page; + unsigned int degrees; + QVector filters; + void run(); + Render * render; +signals: + void pageReady(int); + +}; +*/ + +class Render : public QObject { +Q_OBJECT +public: + Render(); + ~Render(); + +public slots: + void render(); + QPixmap * getCurrentPage(); + QPixmap * getCurrentDoublePage(); + QPixmap * getCurrentDoubleMangaPage(); + bool currentPageIsDoublePage(); + bool nextPageIsDoublePage(); + bool previousPageIsDoublePage(); + void goTo(int index); + void doublePageSwitch(); + void doubleMangaPageSwitch(); + void setRotation(int degrees); + void setComic(Comic * c); + void prepareAvailablePage(int page); + void update(); + void setNumPages(unsigned int numPages); + void pageRawDataReady(int page); + //--comic interface + void nextPage(); + void previousPage(); + void nextDoublePage(); + void previousDoublePage(); + void load(const QString & path, const ComicDB & comic); + void load(const QString & path, int atPage); + void createComic(const QString & path); + void loadComic(const QString & path,const ComicDB & comic); + void loadComic(const QString & path, int atPage); + void startLoad(); + void rotateRight(); + void rotateLeft(); + unsigned int getIndex(); + unsigned int numPages(); + bool hasLoadedComic(); + void updateBuffer(); + void fillBuffer(); + void invalidate(); + QString getCurrentPagesInformation(); + void setBookmark(); + void removeBookmark(); + void save(); + void reset(); + void reload(); + void updateFilters(int brightness, int contrast, int gamma); + Bookmarks * getBookmarks(); + //sets the firt page to render + void renderAt(int page); + +signals: + void currentPageReady(); + void processingPage(); + void imagesLoaded(); + void imageLoaded(int index); + void imageLoaded(int index,const QByteArray & image); + void pageChanged(int index); + void numPages(unsigned int numPages); + void errorOpening(); + void errorOpening(QString); + void crcError(QString); + void currentPageIsBookmark(bool); + void isLast(); + void isCover(); + + void bookmarksUpdated(); + + +private: + Comic * comic; + bool doublePage; + bool doubleMangaPage; + int previousIndex; + int currentIndex; + //QPixmap * currentPage; + int currentPageBufferedIndex; + int numLeftPages; + int numRightPages; + QList pageRenders; + QList buffer; + void loadAll(); + void updateRightPages(); + void updateLeftPages(); + bool loadedComic; + QList pagesEmited; + QVector pagesReady; + int imageRotation; + QVector filters; + QMutex mutex; + + friend class PageRender; +}; + + +#endif // RENDER_H diff --git a/YACReader/shortcuts_dialog.cpp b/YACReader/shortcuts_dialog.cpp new file mode 100644 index 00000000..e88c91a0 --- /dev/null +++ b/YACReader/shortcuts_dialog.cpp @@ -0,0 +1,55 @@ +#include "shortcuts_dialog.h" +#include +#include +#include +#include +#include +#include +#include +#include + +ShortcutsDialog::ShortcutsDialog(QWidget * parent) + :QDialog(parent)//,Qt::FramelessWindowHint) +{ + setModal(true); + setWindowIcon(QIcon(":/images/shortcuts.png")); + setWindowTitle(tr("YACReader keyboard shortcuts")); + + QVBoxLayout * mainLayout = new QVBoxLayout; + + close = new QPushButton(tr("Close")); + connect(close,SIGNAL(clicked()),this,SLOT(close())); + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(close); + + QHBoxLayout * shortcutsLayout = new QHBoxLayout; + + shortcuts = new QTextEdit(); + shortcuts->setFrameStyle(QFrame::NoFrame); + + //"

General functions:


O : Open comic
Esc : Exit

" + shortcuts->setReadOnly(true); + shortcutsLayout->addWidget(shortcuts); + //shortcutsLayout->addWidget(shortcuts2); + shortcutsLayout->setSpacing(0); + mainLayout->addLayout(shortcutsLayout); + mainLayout->addLayout(bottomLayout); + + setLayout(mainLayout); + + setFixedSize(QSize(700,500)); + + QFile f(":/files/shortcuts.html"); + f.open(QIODevice::ReadOnly); + QTextStream txtS(&f); + txtS.setCodec(QTextCodec::codecForName("UTF-8")); + QString content = txtS.readAll(); + + f.close(); + + shortcuts->setHtml(content); + + setWindowTitle(tr("Keyboard Shortcuts")); +} diff --git a/YACReader/shortcuts_dialog.h b/YACReader/shortcuts_dialog.h new file mode 100644 index 00000000..8f1b66b6 --- /dev/null +++ b/YACReader/shortcuts_dialog.h @@ -0,0 +1,19 @@ +#ifndef SHORTCUTS_DIALOG_H +#define SHORTCUTS_DIALOG_H + +#include +#include +#include + +class ShortcutsDialog : public QDialog +{ +Q_OBJECT + public: + ShortcutsDialog(QWidget * parent = 0); + private: + QTextEdit * shortcuts; + QPushButton * close; + public slots: +}; + +#endif // SHORTCUTS_DIALOG_H diff --git a/YACReader/translator.cpp b/YACReader/translator.cpp new file mode 100644 index 00000000..bff51e85 --- /dev/null +++ b/YACReader/translator.cpp @@ -0,0 +1,429 @@ +#include + +#if QT_VERSION >= 0x050000 +#include +#else +#include +#include +#endif + +#include +#include +#include +#include +#include +#include "translator.h" + +#include "yacreader_busy_widget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define APPID "417CEAD93449502CC3C9B69FED26C54118E62BCC" + +YACReaderTranslator::YACReaderTranslator(QWidget * parent) +:QWidget(parent),drag(false) +{ + QString scrollBarStyle = "QScrollBar:vertical { border: none; background: #404040; width: 7px; margin: 0 3px 0 0; }" + "QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }" + "QScrollBar::add-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}" + + "QScrollBar::sub-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}" + "QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}" + + "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background: none; }"; + + this->setCursor(QCursor(Qt::ArrowCursor)); + this->setAutoFillBackground(true); + this->setBackgroundRole(QPalette::Window); + QPalette p(this->palette()); + p.setColor(QPalette::Window, QColor("#404040")); + this->setPalette(p); + + QVBoxLayout *layout = new QVBoxLayout(this); + + //TITLE BAR + QHBoxLayout * titleBar = new QHBoxLayout(); + QPushButton * close = new QPushButton(QIcon(QPixmap(":/images/close.png")),""); + close->setFlat(true); + QLabel * title = new QLabel(tr("YACReader translator")); + title->setStyleSheet("QLabel {font-size:18px; font-family:Arial; color:white;}"); + titleBar->addWidget(title); + titleBar->addStretch(); + close->resize(14,14); + close->setStyleSheet("QPushButton {margin:0;padding:0;border:none;}"); + titleBar->addWidget(close); + titleBar->setContentsMargins(0,0,0,0); + titleBar->setSpacing(0); + connect(close,SIGNAL(clicked()),this->parent(),SLOT(animateHideTranslator())); + + layout->addLayout(titleBar); + + //INPUT TEXT + text = new QTextEdit(this); + text->setMinimumHeight(110); + text->setMaximumHeight(110); + layout->addSpacing(12); + layout->addWidget(text); + text->setStyleSheet("QTextEdit{border:none;background:#2a2a2a;color:white; font-size:12px; padding:6px;}"+scrollBarStyle); + + //COMBOBOXES + QHBoxLayout * combos = new QHBoxLayout(); + from = new QComboBox(this); + to = new QComboBox(this); + QString comboBoxStyle = "QComboBox {border:none;background:#2a2a2a;color:white;font-size:12px;font-family:Arial;padding-left:8px;}" + "QComboBox::down-arrow {image: url(:/images/dropDownArrow.png);}" + "QComboBox::drop-down {border:none; padding-right:10px;}" + "QComboBox QAbstractItemView {border: none; background:#272727; color:white; selection-background-color: #202020; outline:none;}" + "QComboBox QAbstractItemView::item {padding-left:8px;}" + scrollBarStyle + ; + from->setStyleSheet(comboBoxStyle); + to->setStyleSheet(comboBoxStyle); + from->setFixedHeight(22); + to->setFixedHeight(22); + QLabel * arrow = new QLabel(this); + QPixmap arrowPixmap(":/images/fromTo.png"); + arrow->setPixmap(arrowPixmap); + QPushButton * searchButton = new QPushButton(this); + searchButton->setIcon(QIcon(":/images/translatorSearch.png")); + searchButton->setStyleSheet("QPushButton {border:none; background:#2a2a2a;}"); + searchButton->setFixedSize(22,22); + combos->addWidget(from,1); + combos->addSpacing(9); + combos->addWidget(arrow,0); + combos->addSpacing(9); + combos->addWidget(to,1); + combos->addSpacing(9); + combos->addWidget(searchButton,0); + layout->addSpacing(12); + layout->addLayout(combos); + + + //RESULTS + QHBoxLayout * resultsTitleLayout = new QHBoxLayout(); + resultsTitle = new QLabel(tr("Translation")); + resultsTitle->setStyleSheet("QLabel {font-family:Arial;font-size:14px;color:#e3e3e3;}"); + speakButton = new QPushButton(this); + speakButton->setStyleSheet("QPushButton {border:none;}"); + speakButton->setIcon(QIcon(":/images/speaker.png")); + resultsTitleLayout->addWidget(resultsTitle,0,Qt::AlignVCenter); + resultsTitleLayout->addSpacing(10); + resultsTitleLayout->addWidget(speakButton,0,Qt::AlignVCenter); + resultsTitleLayout->addStretch(); + + layout->addSpacing(15); + layout->addLayout(resultsTitleLayout); + layout->addSpacing(12); + + resultText = new QLabel(); + resultText->setWordWrap(true); + resultText->setStyleSheet("QLabel {color:white;font-size:12px;}"); + resultText->setText("ñlkas lakj dflkaj lasd jflie lkajd fie kljads ijef lasei afsliej ljse f"); + layout->addWidget(resultText); + + layout->addStretch(); + + //CLEAR BUTTON + clearButton = new QPushButton(tr("clear")); + layout->addWidget(clearButton,0,Qt::AlignRight); + clearButton->setMinimumWidth(95); + clearButton->setStyleSheet("QPushButton {border:1px solid #212121; background:#2a2a2a; color:white; font-family:Arial; font-size:12px; padding-top:5px; padding-bottom:5px;}"); + + resize(400,479); + + layout->setMargin(0); + layout->setContentsMargins(18,12,18,12); + setContentsMargins(0,0,0,0); + layout->setSpacing(0); + + hideResults(); + populateCombos(); + + busyIndicator = new YACReaderBusyWidget(this); + busyIndicator->move((this->width()-busyIndicator->width())/2,(this->height()-busyIndicator->height())*2/3); + busyIndicator->hide(); + + show(); + + connect(searchButton,SIGNAL(pressed()),this,SLOT(translate())); + connect(speakButton,SIGNAL(pressed()),this,SLOT(play())); + connect(clearButton,SIGNAL(pressed()),this,SLOT(clear())); + + //multimedia/phonon +#if QT_VERSION >= 0x050000 + player = new QMediaPlayer; +#else + music = createPlayer(MusicCategory); +#endif + +} + +void YACReaderTranslator::hideResults() +{ + resultsTitle->setHidden(true); + speakButton->setHidden(true); + resultText->setHidden(true); +} + +void YACReaderTranslator::clear() +{ + hideResults(); + text->clear(); +} + +void YACReaderTranslator::translate() +{ + QString text = this->text->toPlainText(); + if(text.isEmpty()) + return; + QString from = this->from->itemData(this->from->currentIndex()).toString(); + QString to = this->to->itemData(this->to->currentIndex()).toString(); + + TranslationLoader * translationLoader = new TranslationLoader(text,from,to); + connect(translationLoader,SIGNAL(requestFinished(QString)),this,SLOT(setTranslation(QString))); + connect(translationLoader,SIGNAL(error()),this,SLOT(error())); + connect(translationLoader,SIGNAL(timeOut()),this,SLOT(error())); + connect(translationLoader,SIGNAL(finished()),translationLoader,SLOT(deleteLater())); + + TextToSpeachLoader * tts = new TextToSpeachLoader(text,from); + connect(tts,SIGNAL(requestFinished(QUrl)),this,SLOT(setSpeak(QUrl))); + connect(tts,SIGNAL(error()),this,SLOT(error())); + connect(tts,SIGNAL(timeOut()),this,SLOT(error())); + connect(tts,SIGNAL(finished()),tts,SLOT(deleteLater())); + + translationLoader->start(); + tts->start(); + + resultsTitle->setText(tr("Translation")); + + hideResults(); + + busyIndicator->show(); +} + +void YACReaderTranslator::error() +{ + resultsTitle->setText(tr("Service not available")); + resultsTitle->setHidden(false); + busyIndicator->hide(); +} + +void YACReaderTranslator::setSpeak(const QUrl & url) +{ + resultsTitle->setHidden(false); + speakButton->setHidden(false); + + ttsSource = url; +} + +void YACReaderTranslator::setTranslation(const QString & string) +{ + resultText->setText(string); + + resultsTitle->setHidden(false); + resultText->setHidden(false); + busyIndicator->hide(); +} + +void YACReaderTranslator::populateCombos() +{ + QList combos; + combos.append(from); + combos.append(to); + + for(int i=0;iaddItem("Arabic","ar"); + combo->addItem("Bulgarian","bg"); + combo->addItem("Catalan","ca"); + combo->addItem("Chinese Simplified","zh-CHS"); + combo->addItem("Chinese Traditional","zh-CHT"); + combo->addItem("Czech","cs"); + combo->addItem("Danish","da"); + combo->addItem("Dutch","nl"); + combo->addItem("English","en"); + combo->addItem("Estonian","et"); + combo->addItem("Finnish","fi"); + combo->addItem("French","fr"); + combo->addItem("German","de"); + combo->addItem("Greek","el"); + combo->addItem("Haitian Creole","ht"); + combo->addItem("Hebrew","he"); + combo->addItem("Hindi","hi"); + combo->addItem("Hungarian","hu"); + combo->addItem("Indonesian","id"); + combo->addItem("Italian","it"); + combo->addItem("Japanese","ja"); + combo->addItem("Korean","ko"); + combo->addItem("Latvian","lv"); + combo->addItem("Lithuanian","lt"); + combo->addItem("Norwegian","no"); + combo->addItem("Polish","pl"); + combo->addItem("Portuguese","pt"); + combo->addItem("Romanian","ro"); + combo->addItem("Russian","ru"); + combo->addItem("Slovak","sk"); + combo->addItem("Slovenian","sl"); + combo->addItem("Spanish","es"); + combo->addItem("Swedish","sv"); + combo->addItem("Thai","th"); + combo->addItem("Turkish","tr"); + combo->addItem("Ukrainian","uk"); + combo->addItem("Vietnamese","vi"); + } + from->setCurrentIndex(from->findText("English")); + to->setCurrentIndex(from->findText("Spanish")); +} + +void YACReaderTranslator::play() +{ + //QMessageBox::question(this,"xxx",ttsSource.toString()); +#if QT_VERSION >= 0x050000 + + player->setMedia(ttsSource); + player->play(); + +#else + MediaSource src(ttsSource); + src.setAutoDelete(true); + music->setCurrentSource(src); + music->play(); +#endif +} + +YACReaderTranslator::~YACReaderTranslator() +{ +#if QT_VERSION >= 0x050000 +#else + delete music; +#endif +} + +void YACReaderTranslator::mousePressEvent(QMouseEvent *event) +{ + QPoint p = mapTo(this,event->pos()); + if(p.y() < 40) + { + drag = true; + click = event->pos(); + } +} + +void YACReaderTranslator::mouseReleaseEvent(QMouseEvent *event) +{ + drag = false; + event->accept(); +} + +void YACReaderTranslator::mouseMoveEvent(QMouseEvent * event) +{ + if(drag) + this->move(QPoint(mapToParent(event->pos())-click)); + event->accept(); +} + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + +TranslationLoader::TranslationLoader(QString text, QString from, QString to) + :QThread(),text(text),from(from),to(to) +{ +} + +void TranslationLoader::run() +{ + QNetworkAccessManager manager; + QEventLoop q; + QTimer tT; + + tT.setSingleShot(true); + connect(&tT, SIGNAL(timeout()), &q, SLOT(quit())); + connect(&manager, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit())); + + QString url = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appid=%1&from=%2&to=%3&text=%4&contentType=text/plain"; + url = url.arg(APPID).arg(from).arg(to).arg(text); + + QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url))); + + tT.start(5000); // 5s timeout + q.exec(); + + if(tT.isActive()){ + // download complete + if(reply->error() == QNetworkReply::NoError) + { + QString utf8 = QString::fromUtf8(reply->readAll()); + utf8 = utf8.remove(0,1); + utf8 = utf8.remove(utf8.count()-1,1); + + QString translated(utf8); + emit(requestFinished(translated)); + } + else + emit(error()); + } else { + emit(timeOut()); + } +} + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- + + +TextToSpeachLoader::TextToSpeachLoader(QString text, QString language) + :QThread(),text(text),language(language) +{ +} + + +void TextToSpeachLoader::run() +{ + QNetworkAccessManager manager; + QEventLoop q; + QTimer tT; + + tT.setSingleShot(true); + connect(&tT, SIGNAL(timeout()), &q, SLOT(quit())); + connect(&manager, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit())); + + QString url = "http://api.microsofttranslator.com/V2/Ajax.svc/Speak?appid=%1&language=%2&text=%3&contentType=text/plain"; + url = url.arg(APPID).arg(language).arg(text); + + QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url))); + + tT.start(5000); // 5s timeout + q.exec(); + + if(tT.isActive()){ + // download complete + if(reply->error() == QNetworkReply::NoError) + { + QString utf8 = QString::fromUtf8(reply->readAll()); + utf8 = utf8.remove(0,1); + utf8 = utf8.remove(utf8.count()-1,1); + utf8 = utf8.replace("\\",""); + + emit(requestFinished(QUrl(utf8))); + } + else + emit(error()); + } else { + emit(timeOut()); + } +} diff --git a/YACReader/translator.h b/YACReader/translator.h new file mode 100644 index 00000000..1ce1bee0 --- /dev/null +++ b/YACReader/translator.h @@ -0,0 +1,102 @@ +#ifndef __TRANSLATOR_H +#define __TRANSLATOR_H + +class QUrl; +class QMouseEvent; +class QPoint; +class QTextEdit; +class QComboBox; +class QLabel; +class QPushButton; +class YACReaderBusyWidget; + +#include +#include +#include + +#if QT_VERSION >= 0x050000 + class QMediaPlayer; +#else + #include + using namespace Phonon; +#endif + + + +class YACReaderTranslator : public QWidget +{ + Q_OBJECT + public: + YACReaderTranslator(QWidget * parent = 0); + ~YACReaderTranslator(); + + public slots: + void play(); + + protected slots: + void translate(); + void setSpeak(const QUrl & url); + void setTranslation(const QString & string); + void error(); + void clear(); + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent ( QMouseEvent * event ); + void hideResults(); + + void populateCombos(); + bool drag; + QPoint click; +private: + +#if QT_VERSION >= 0x050000 + QMediaPlayer *player; +#else + MediaObject * music; +#endif + + QTextEdit * text; + QComboBox * from; + QComboBox * to; + QLabel * resultsTitle; + QPushButton * speakButton; + QLabel * resultText; + YACReaderBusyWidget * busyIndicator; + QUrl ttsSource; + QPushButton * clearButton; + +}; + +class TranslationLoader : public QThread +{ + Q_OBJECT +public: + TranslationLoader(QString text, QString from, QString to); +signals: + void requestFinished(QString); + void timeOut(); + void error(); +private: + QString text; + QString from; + QString to; + void run(); +}; + +class TextToSpeachLoader : public QThread +{ + Q_OBJECT +public: + TextToSpeachLoader(QString text, QString language); +signals: + void requestFinished(QUrl); + void timeOut(); + void error(); +private: + QString text; + QString language; + void run(); +}; +#endif diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp new file mode 100644 index 00000000..d0389a0a --- /dev/null +++ b/YACReader/viewer.cpp @@ -0,0 +1,999 @@ +#include "viewer.h" +#include "magnifying_glass.h" +#include "configuration.h" +#include "magnifying_glass.h" +#include "goto_flow.h" +#ifndef NO_OPENGL +#include "goto_flow_gl.h" +#else +#include +#endif +#include "bookmarks_dialog.h" +#include "render.h" +#include "goto_dialog.h" +#include "translator.h" +#include "onstart_flow_selection_dialog.h" +#include "page_label_widget.h" +#include "notifications_label_widget.h" +#include "comic_db.h" +#include "shortcuts_manager.h" + +#include "opengl_checker.h" + +#include + + +Viewer::Viewer(QWidget * parent) +:QScrollArea(parent), +currentPage(0), +magnifyingGlassShowed(false), +fullscreen(false), +information(false), +adjustToWidthRatio(1), +doublePage(false), +doubleMangaPage(false), +wheelStop(false), +direction(1), +restoreMagnifyingGlass(false), +drag(false), +numScrollSteps(22), +shouldOpenNext(false), +shouldOpenPrevious(false) +{ + translator = new YACReaderTranslator(this); + translator->hide(); + translatorAnimation = new QPropertyAnimation(translator,"pos"); + translatorAnimation->setDuration(150); + translatorXPos = -10000; + translator->move(-translator->width(),10); + //current comic page + content = new QLabel(this); + configureContent(tr("Press 'O' to open comic.")); + //scroll area configuration + setBackgroundRole(QPalette::Dark); + setWidget(content); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setFrameStyle(QFrame::NoFrame); + setAlignment(Qt::AlignCenter); + + QPalette palette; + palette.setColor(backgroundRole(), Configuration::getConfiguration().getBackgroundColor()); + setPalette(palette); + //--------------------------------------- + mglass = new MagnifyingGlass(Configuration::getConfiguration().getMagnifyingGlassSize(),this); + mglass->hide(); + content->setMouseTracking(true); + setMouseTracking(true); + + showCursor(); + + goToDialog = new GoToDialog(this); + + QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat); + + //CONFIG GOTO_FLOW-------------------------------------------------------- +#ifndef NO_OPENGL + + OpenGLChecker openGLChecker; + bool openGLAvailable = openGLChecker.hasCompatibleOpenGLVersion(); + + if(openGLAvailable && !settings->contains(USE_OPEN_GL)) + settings->setValue(USE_OPEN_GL,2); + else + if(!openGLAvailable) + settings->setValue(USE_OPEN_GL,0); + + if((settings->value(USE_OPEN_GL).toBool() == true)) + goToFlow = new GoToFlowGL(this,Configuration::getConfiguration().getFlowType()); + else + goToFlow = new GoToFlow(this,Configuration::getConfiguration().getFlowType()); +#else + goToFlow = new GoToFlow(this,Configuration::getConfiguration().getFlowType()); +#endif + goToFlow->setFocusPolicy(Qt::StrongFocus); + goToFlow->hide(); + showGoToFlowAnimation = new QPropertyAnimation(goToFlow,"pos"); + showGoToFlowAnimation->setDuration(150); + + bd = new BookmarksDialog(this->parentWidget()); + + render = new Render(); + + hideCursorTimer = new QTimer(); + hideCursorTimer->setSingleShot(true); + + if(Configuration::getConfiguration().getDoublePage()) + doublePageSwitch(); + + if(Configuration::getConfiguration().getDoubleMangaPage()) + doubleMangaPageSwitch(); + + createConnections(); + + hideCursorTimer->start(2500); + + setMouseTracking(true); + + //animations + verticalScroller = new QPropertyAnimation(verticalScrollBar(), "sliderPosition"); + connect(verticalScroller,SIGNAL(valueChanged (const QVariant &)),this,SIGNAL(backgroundChanges())); + + notificationsLabel = new NotificationsLabelWidget(this); + notificationsLabel->hide(); + + informationLabel = new PageLabelWidget(this); + + setAcceptDrops(true); + +} + +Viewer::~Viewer() +{ + delete render; + delete goToFlow; + delete translator; + delete translatorAnimation; + delete content; + delete hideCursorTimer; + delete informationLabel; + delete verticalScroller; + delete bd; + delete notificationsLabel; + delete mglass; + if(currentPage != 0) + delete currentPage; +} + +void Viewer::createConnections() +{ + //magnifyingGlass (update mg after a background change + connect(this,SIGNAL(backgroundChanges()),mglass,SLOT(updateImage())); + + //goToDialog + connect(goToDialog,SIGNAL(goToPage(unsigned int)),this,SLOT(goTo(unsigned int))); + + //goToFlow goTo + connect(goToFlow,SIGNAL(goToPage(unsigned int)),this,SLOT(goTo(unsigned int))); + + //current time + QTimer * t = new QTimer(); + connect(t,SIGNAL(timeout()),this,SLOT(updateInformation())); + t->start(1000); + + //hide cursor + connect(hideCursorTimer,SIGNAL(timeout()),this,SLOT(hideCursor())); + + //bookmarks + connect(bd,SIGNAL(goToPage(unsigned int)),this,SLOT(goTo(unsigned int))); + + //render + connect(render,SIGNAL(errorOpening()),this,SLOT(resetContent())); + connect(render,SIGNAL(errorOpening()),this,SLOT(showMessageErrorOpening())); + connect(render,SIGNAL(errorOpening(QString)),this,SLOT(showMessageErrorOpening(QString))); + connect(render,SIGNAL(crcError(QString)),this,SLOT(processCRCError(QString))); + connect(render,SIGNAL(numPages(unsigned int)),goToFlow,SLOT(setNumSlides(unsigned int))); + connect(render,SIGNAL(numPages(unsigned int)),goToDialog,SLOT(setNumPages(unsigned int))); + //connect(render,SIGNAL(numPages(unsigned int)),this,SLOT(updateInformation())); + connect(render,SIGNAL(imageLoaded(int,QByteArray)),goToFlow,SLOT(setImageReady(int,QByteArray))); + connect(render,SIGNAL(currentPageReady()),this,SLOT(updatePage())); + connect(render,SIGNAL(processingPage()),this,SLOT(setLoadingMessage())); + connect(render,SIGNAL(currentPageIsBookmark(bool)),this,SIGNAL(pageIsBookmark(bool))); + connect(render,SIGNAL(pageChanged(int)),this,SLOT(updateInformation())); + //connect(render,SIGNAL(bookmarksLoaded(Bookmarks)),this,SLOT(setBookmarks(Bookmarks))); + + connect(render,SIGNAL(isLast()),this,SLOT(showIsLastMessage())); + connect(render,SIGNAL(isCover()),this,SLOT(showIsCoverMessage())); + + connect(render,SIGNAL(bookmarksUpdated()),this,SLOT(setBookmarks())); +} + +//Deprecated +void Viewer::prepareForOpening() +{ + if(render->hasLoadedComic()) + save(); + //bd->setBookmarks(*bm); + + goToFlow->reset(); + + //render->update(); + + verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum()); + + if(Configuration::getConfiguration().getShowInformation() && !information) + { + QTimer * timer = new QTimer(); + connect(timer,SIGNAL(timeout()),this,SLOT(informationSwitch())); + connect(timer,SIGNAL(timeout()),timer,SLOT(deleteLater())); + timer->start(); + } + + informationLabel->setText("..."); +} + +void Viewer::open(QString pathFile, int atPage) +{ + prepareForOpening(); + render->load(pathFile, atPage); +} + +void Viewer::open(QString pathFile, const ComicDB & comic) +{ + prepareForOpening(); + render->load(pathFile, comic); +} + +void Viewer::showMessageErrorOpening() +{ + QMessageBox::critical(this,tr("Not found"),tr("Comic not found")); + //resetContent(); --> not needed +} + +void Viewer::showMessageErrorOpening(QString message) +{ + QMessageBox::critical(this,tr("Error opening comic"),message); + resetContent(); +} + +void Viewer::processCRCError(QString message) +{ + QMessageBox::critical(this,tr("CRC Error"),message); +} + +void Viewer::next() +{ + direction = 1; + if (doublePage && render->currentPageIsDoublePage()) + { + render->nextDoublePage(); + } + else + { + render->nextPage(); + } + updateInformation(); + shouldOpenPrevious = false; +} + +void Viewer::prev() +{ + direction = -1; + if (doublePage && render->previousPageIsDoublePage()) + { + render->previousDoublePage(); + } + else + { + render->previousPage(); + } + updateInformation(); + shouldOpenNext = false; +} +void Viewer::showGoToDialog() +{ + goToDialog->open(); +} +void Viewer::goTo(unsigned int page) +{ + direction = 1; //in "go to" direction is always fordward + render->goTo(page); +} + +void Viewer::updatePage() +{ + QPixmap * previousPage = currentPage; + if (doublePage) + { + if (!doubleMangaPage) + currentPage = render->getCurrentDoublePage(); + else + { + currentPage = render->getCurrentDoubleMangaPage(); + } + if (currentPage == NULL) + { + currentPage = render->getCurrentPage(); + } + } + else + { + currentPage = render->getCurrentPage(); + } + content->setPixmap(*currentPage); + updateContentSize(); + updateVerticalScrollBar(); + emit backgroundChanges(); + emit(pageAvailable(true)); + + if(goToFlow->isHidden()) + setFocus(Qt::ShortcutFocusReason); + else + goToFlow->setFocus(Qt::OtherFocusReason); + delete previousPage; + + if(currentPage->isNull()) + setPageUnavailableMessage(); + + if(restoreMagnifyingGlass) + { + restoreMagnifyingGlass = false; + showMagnifyingGlass(); + } + +} + +void Viewer::updateContentSize() +{ + //there is an image to resize + if(currentPage !=0 && !currentPage->isNull()) + { + if(Configuration::getConfiguration().getAdjustToFullSize()) + { + content->resize(currentPage->width(),currentPage->height()); + } + else + { + float aspectRatio = (float)currentPage->width()/currentPage->height(); + //Fit to width + if(Configuration::getConfiguration().getAdjustToWidth()) + { + adjustToWidthRatio = Configuration::getConfiguration().getFitToWidthRatio(); + if(static_cast(width()*adjustToWidthRatio/aspectRatio)(height()*aspectRatio)>width()) + content->resize(width(),static_cast(width()/aspectRatio)); + else + content->resize(static_cast(height()*aspectRatio),height()); + else + content->resize(width()*adjustToWidthRatio,static_cast(width()*adjustToWidthRatio/aspectRatio)); + } + //Fit to height or fullsize/custom size + else + { + if(static_cast(height()*aspectRatio)>width()) //page width exceeds window width + content->resize(width(),static_cast(width()/aspectRatio)); + else + content->resize(static_cast(height()*aspectRatio),height()); + } + } + + if(devicePixelRatio()>1)//only in retina display + { + QPixmap page = currentPage->scaled(content->width()*devicePixelRatio(), content->height()*devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + page.setDevicePixelRatio(devicePixelRatio()); + content->setPixmap(page); + } + + emit backgroundChanges(); + } + content->update(); //TODO, it shouldn't be neccesary +} + +void Viewer::updateVerticalScrollBar() +{ + if(direction > 0) + verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum()); + else + verticalScrollBar()->setSliderPosition(verticalScrollBar()->maximum()); +} + +void Viewer::scrollDown() +{ + if(verticalScrollBar()->sliderPosition()==verticalScrollBar()->maximum()) + { + next(); + } + else + { + int currentPos = verticalScrollBar()->sliderPosition(); + verticalScroller->setDuration(250); + verticalScroller->setStartValue(currentPos); + verticalScroller->setEndValue(nextPos); + + verticalScroller->start(); + + emit backgroundChanges(); + } +} + +void Viewer::scrollUp() +{ + if(verticalScrollBar()->sliderPosition()==verticalScrollBar()->minimum()) + { + prev(); + } + else + { + int currentPos = verticalScrollBar()->sliderPosition(); + verticalScroller->setDuration(250); + verticalScroller->setStartValue(currentPos); + verticalScroller->setEndValue(nextPos); + + verticalScroller->start(); + + emit backgroundChanges(); + } +} + +void Viewer::keyPressEvent(QKeyEvent *event) +{ + if(render->hasLoadedComic()) + { + int _key = event->key(); + Qt::KeyboardModifiers modifiers = event->modifiers(); + + if(modifiers & Qt::ShiftModifier) + _key |= Qt::SHIFT; + if (modifiers & Qt::ControlModifier) + _key |= Qt::CTRL; + if (modifiers & Qt::MetaModifier) + _key |= Qt::META; + if (modifiers & Qt::AltModifier) + _key |= Qt::ALT; + + QKeySequence key(_key); + /*if(goToFlow->isVisible() && event->key()!=Qt::Key_S) + QCoreApplication::sendEvent(goToFlow,event); + else*/ + + if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)) + { + posByStep = height()/numScrollSteps; + nextPos=verticalScrollBar()->sliderPosition()+static_cast((height()*0.80)); + scrollDown(); + } + + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)) + { + posByStep = height()/numScrollSteps; + nextPos=verticalScrollBar()->sliderPosition()-static_cast((height()*0.80)); + scrollUp(); + } + + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_DOWN_ACTION_Y) || + key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_UP_ACTION_Y) || + key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_LEFT_ACTION_Y) || + key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_RIGHT_ACTION_Y)) + { + QAbstractScrollArea::keyPressEvent(event); + emit backgroundChanges(); + } + + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_FIRST_PAGE_ACTION_Y)) + { + goTo(0); + } + + else if (key == ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_LAST_PAGE_ACTION_Y)) + { + goTo(this->render->numPages()-1); + } + + else + QAbstractScrollArea::keyPressEvent(event); + + if(mglass->isVisible() && (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y) || + key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y) || + key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y) || + key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y))) + { + QCoreApplication::sendEvent(mglass,event); + } + + } + else + QAbstractScrollArea::keyPressEvent(event); +} + +void Viewer::wheelEvent(QWheelEvent * event) +{ + if(render->hasLoadedComic()) + { + if((event->delta()<0)&&(verticalScrollBar()->sliderPosition()==verticalScrollBar()->maximum())) + { + if(wheelStop) + { + if(getMovement(event) == Forward) + { + next(); + verticalScroller->stop(); + event->accept(); + wheelStop = false; + } + return; + } + else + wheelStop = true; + } + else + { + if((event->delta()>0)&&(verticalScrollBar()->sliderPosition()==verticalScrollBar()->minimum())) + { + if(wheelStop) + { + if(getMovement(event) == Backward) + { + prev(); + verticalScroller->stop(); + event->accept(); + wheelStop = false; + } + return; + } + else + wheelStop = true; + } + } + + int deltaNotFinished = 0; + if(verticalScroller->state() == QAbstractAnimation::Running) + { + deltaNotFinished = verticalScroller->startValue().toInt() - verticalScroller->endValue().toInt(); + verticalScroller->stop(); + } + + + int currentPos = verticalScrollBar()->sliderPosition(); + verticalScroller->setDuration(250); + verticalScroller->setStartValue(currentPos); + verticalScroller->setEndValue(currentPos - event->delta() - deltaNotFinished); + + verticalScroller->start(); + + //QAbstractScrollArea::wheelEvent(event); + } +} + +void Viewer::resizeEvent(QResizeEvent * event) +{ + updateContentSize(); + goToFlow->move(QPoint((width()-goToFlow->width())/2,height()-goToFlow->height())); + informationLabel->updatePosition(); + QScrollArea::resizeEvent(event); +} + +void Viewer::mouseMoveEvent(QMouseEvent * event) +{ + showCursor(); + hideCursorTimer->start(2500); + + if(magnifyingGlassShowed) + mglass->move(static_cast(event->x()-float(mglass->width())/2),static_cast(event->y()-float(mglass->height())/2)); + + if(render->hasLoadedComic()) + { + if(showGoToFlowAnimation->state()!=QPropertyAnimation::Running) + { + if(goToFlow->isVisible()) + { + QPoint gtfPos = goToFlow->mapFrom(this,event->pos()); + if(gtfPos.y() < 0 || gtfPos.x()<0 || gtfPos.x()>goToFlow->width())//TODO this extra check is for Mavericks (mouseMove over goToFlowGL seems to be broken) + animateHideGoToFlow(); + //goToFlow->hide(); + } + else + { + int umbral = (width()-goToFlow->width())/2; + if((event->y()>height()-15)&&(event->x()>umbral)&&(event->x()stop(); + } + } + } + + if(drag) + { + int currentPosY = verticalScrollBar()->sliderPosition(); + int currentPosX = horizontalScrollBar()->sliderPosition(); + verticalScrollBar()->setSliderPosition(currentPosY=currentPosY+(yDragOrigin-event->y())); + horizontalScrollBar()->setSliderPosition(currentPosX=currentPosX+(xDragOrigin-event->x())); + yDragOrigin = event->y(); + xDragOrigin = event->x(); + } + } + + +} + +const QPixmap * Viewer::pixmap() +{ + return content->pixmap(); +} + +void Viewer::magnifyingGlassSwitch() +{ + magnifyingGlassShowed?hideMagnifyingGlass():showMagnifyingGlass(); +} + +void Viewer::showMagnifyingGlass() +{ + if(render->hasLoadedComic()) + { + QPoint p = QPoint(cursor().pos().x(),cursor().pos().y()); + p = this->parentWidget()->mapFromGlobal(p); + mglass->move(static_cast(p.x()-float(mglass->width())/2) + ,static_cast(p.y()-float(mglass->height())/2)); + mglass->show(); + mglass->updateImage(mglass->x()+mglass->width()/2,mglass->y()+mglass->height()/2); + magnifyingGlassShowed = true; + } +} + +void Viewer::hideMagnifyingGlass() +{ + mglass->hide(); + magnifyingGlassShowed = false; +} + +void Viewer::informationSwitch() +{ + information?informationLabel->hide():informationLabel->show(); + //informationLabel->move(QPoint((width()-informationLabel->width())/2,0)); + information=!information; + Configuration::getConfiguration().setShowInformation(information); + //TODO it shouldn't be neccesary + informationLabel->adjustSize(); + informationLabel->update(); +} + +void Viewer::updateInformation() +{ + if(render->hasLoadedComic()) + { + informationLabel->setText(render->getCurrentPagesInformation()+" - "+QTime::currentTime().toString("HH:mm")); + informationLabel->adjustSize(); + informationLabel->update(); //TODO it shouldn't be neccesary + } +} + +void Viewer::goToFlowSwitch() +{ + goToFlow->isVisible()?animateHideGoToFlow():showGoToFlow(); +} + +void Viewer::translatorSwitch() +{ + translator->isVisible()?animateHideTranslator():animateShowTranslator(); +} + +void Viewer::showGoToFlow() +{ + if(render->hasLoadedComic()) + { + animateShowGoToFlow(); + } +} + +void Viewer::animateShowGoToFlow() +{ + if(goToFlow->isHidden() && showGoToFlowAnimation->state()!=QPropertyAnimation::Running) + { + disconnect(showGoToFlowAnimation,SIGNAL(finished()),goToFlow,SLOT(hide())); + connect(showGoToFlowAnimation,SIGNAL(finished()),this,SLOT(moveCursoToGoToFlow())); + showGoToFlowAnimation->setStartValue(QPoint((width()-goToFlow->width())/2,height()-10)); + showGoToFlowAnimation->setEndValue(QPoint((width()-goToFlow->width())/2,height()-goToFlow->height())); + showGoToFlowAnimation->start(); + goToFlow->centerSlide(render->getIndex()); + goToFlow->setPageNumber(render->getIndex()); + goToFlow->show(); + goToFlow->setFocus(Qt::OtherFocusReason); + } +} + +void Viewer::animateHideGoToFlow() +{ + if(goToFlow->isVisible() && showGoToFlowAnimation->state()!=QPropertyAnimation::Running) + { + connect(showGoToFlowAnimation,SIGNAL(finished()),goToFlow,SLOT(hide())); + disconnect(showGoToFlowAnimation,SIGNAL(finished()),this,SLOT(moveCursoToGoToFlow())); + showGoToFlowAnimation->setStartValue(QPoint((width()-goToFlow->width())/2,height()-goToFlow->height())); + showGoToFlowAnimation->setEndValue(QPoint((width()-goToFlow->width())/2,height())); + showGoToFlowAnimation->start(); + goToFlow->centerSlide(render->getIndex()); + goToFlow->setPageNumber(render->getIndex()); + this->setFocus(Qt::OtherFocusReason); + } +} + +void Viewer::moveCursoToGoToFlow() +{ + //Move cursor to goToFlow widget on show (this avoid hide when mouse is moved) + int y = goToFlow->pos().y(); + int x1 = goToFlow->pos().x(); + int x2 = x1 + goToFlow->width(); + QPoint cursorPos = mapFromGlobal(cursor().pos()); + int cursorX = cursorPos.x(); + int cursorY = cursorPos.y(); + + if(cursorY <= y) + cursorY = y + 10; + if(cursorX <= x1) + cursorX = x1 + 10; + if(cursorX >= x2) + cursorX = x2 - 10; + cursor().setPos(mapToGlobal(QPoint(cursorX,cursorY))); + hideCursorTimer->stop(); + showCursor(); +} + +void Viewer::rotateLeft() +{ + render->rotateLeft(); +} +void Viewer::rotateRight() +{ + render->rotateRight(); +} + +//TODO +void Viewer::setBookmark(bool set) +{ + render->setBookmark(); + if(set) //add bookmark + { + render->setBookmark(); + } + else //remove bookmark + { + render->removeBookmark(); + } +} + +void Viewer::save () +{ + if(render->hasLoadedComic()) + render->save(); +} + +void Viewer::doublePageSwitch() +{ + doublePage = !doublePage; + render->doublePageSwitch(); + Configuration::getConfiguration().setDoublePage(doublePage); +} + +void Viewer::doubleMangaPageSwitch() +{ + doubleMangaPage = !doubleMangaPage; + render->doubleMangaPageSwitch(); + Configuration::getConfiguration().setDoubleMangaPage(doubleMangaPage); +} + +void Viewer::resetContent() +{ + configureContent(tr("Press 'O' to open comic.")); + goToFlow->reset(); + emit reset(); +} + +void Viewer::setLoadingMessage() +{ + if(magnifyingGlassShowed) + { + hideMagnifyingGlass(); + restoreMagnifyingGlass = true; + } + emit(pageAvailable(false)); + configureContent(tr("Loading...please wait!")); +} + +void Viewer::setPageUnavailableMessage() +{ + if(magnifyingGlassShowed) + { + hideMagnifyingGlass(); + restoreMagnifyingGlass = true; + } + emit(pageAvailable(false)); + configureContent(tr("Page not available!")); +} + +void Viewer::configureContent(QString msg) +{ + content->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + if(!(devicePixelRatio()>1)) + content->setScaledContents(true); + content->setAlignment(Qt::AlignTop|Qt::AlignHCenter); + content->setText(msg); + content->setFont(QFont("courier new", 12)); + content->adjustSize(); + setFocus(Qt::ShortcutFocusReason); + //emit showingText(); +} + +void Viewer::hideCursor() +{ +#ifdef Q_OS_MAC + setCursor(QCursor(QBitmap(1,1),QBitmap(1,1))); +#else + setCursor(Qt::BlankCursor); +#endif +} +void Viewer::showCursor() +{ + if(drag) + setCursor(Qt::ClosedHandCursor); + else + setCursor(Qt::OpenHandCursor); +} + +void Viewer::updateOptions() +{ + + goToFlow->setFlowType(Configuration::getConfiguration().getFlowType()); + updateBackgroundColor(Configuration::getConfiguration().getBackgroundColor()); + updateContentSize(); + //goToFlow->updateSize(); +} + +void Viewer::updateBackgroundColor(const QColor & color) +{ + QPalette palette; + palette.setColor(backgroundRole(), color); + setPalette(palette); +} + +void Viewer::animateShowTranslator() +{ + if(translator->isHidden() && translatorAnimation->state()!=QPropertyAnimation::Running) + { + disconnect(translatorAnimation,SIGNAL(finished()),translator,SLOT(hide())); + if(translatorXPos == -10000) + translatorXPos = (width()-translator->width())/2; + int x = qMax(0,qMin(translatorXPos,width()-translator->width())); + if(translator->pos().x()<0) + { + translatorAnimation->setStartValue(QPoint(-translator->width(),translator->pos().y())); + } + else + { + translatorAnimation->setStartValue(QPoint(width()+translator->width(),translator->pos().y())); + } + translatorAnimation->setEndValue(QPoint(x,translator->pos().y())); + translatorAnimation->start(); + translator->show(); + translator->setFocus(Qt::OtherFocusReason); + } +} +void Viewer::animateHideTranslator() +{ + if(translator->isVisible() && translatorAnimation->state()!=QPropertyAnimation::Running) + { + connect(translatorAnimation,SIGNAL(finished()),translator,SLOT(hide())); + translatorAnimation->setStartValue(QPoint(translatorXPos = translator->pos().x(),translator->pos().y())); + if((translator->width()/2)+translator->pos().x() <= width()/2) + translatorAnimation->setEndValue(QPoint(-translator->width(),translator->pos().y())); + else + translatorAnimation->setEndValue(QPoint(width()+translator->width(),translator->pos().y())); + translatorAnimation->start(); + this->setFocus(Qt::OtherFocusReason); + } +} + +void Viewer::mousePressEvent ( QMouseEvent * event ) +{ + drag = true; + yDragOrigin = event->y(); + xDragOrigin = event->x(); + setCursor(Qt::ClosedHandCursor); + event->accept(); +} + +void Viewer::mouseReleaseEvent ( QMouseEvent * event ) +{ + drag = false; + setCursor(Qt::OpenHandCursor); + event->accept(); +} + +void Viewer::updateFitToWidthRatio(float ratio) +{ + Configuration::getConfiguration().setAdjustToWidth(true); + adjustToWidthRatio = ratio; + updateContentSize(); +} + +void Viewer::updateConfig(QSettings * settings) +{ + goToFlow->updateConfig(settings); + + QPalette palette; + palette.setColor(backgroundRole(), Configuration::getConfiguration().getBackgroundColor()); + setPalette(palette); +} + +//deprecated +void Viewer::updateImageOptions() +{ + render->reload(); +} + +void Viewer::updateFilters(int brightness, int contrast,int gamma) +{ + render->updateFilters(brightness,contrast,gamma); +} + +void Viewer::setBookmarks() +{ + bd->setBookmarks(*render->getBookmarks()); +} + +void Viewer::showIsCoverMessage() +{ + if(!shouldOpenPrevious) + { + notificationsLabel->setText(tr("Cover!")); + notificationsLabel->flash(); + shouldOpenPrevious = true; + } + else + { + shouldOpenPrevious = false; + emit (openPreviousComic()); + } + + shouldOpenNext = false; //single page comic +} + +void Viewer::showIsLastMessage() +{ + if(!shouldOpenNext) + { + notificationsLabel->setText(tr("Last page!")); + notificationsLabel->flash(); + shouldOpenNext = true; + } + else + { + shouldOpenNext = false; + emit (openNextComic()); + } + + shouldOpenPrevious = false; //single page comic +} + +unsigned int Viewer::getIndex() +{ + return render->getIndex()+1; +} + +int Viewer::getCurrentPageNumber() +{ + return render->getIndex(); +} + +void Viewer::updateComic(ComicDB & comic) +{ + if(render->hasLoadedComic()) + { + //set currentPage + comic.info.currentPage = render->getIndex()+1; + //set bookmarks + Bookmarks * boomarks = render->getBookmarks(); + QList boomarksList = boomarks->getBookmarkPages(); + int numBookmarks = boomarksList.size(); + if(numBookmarks > 0) + comic.info.bookmark1 = boomarksList[0]; + if(numBookmarks > 1) + comic.info.bookmark2 = boomarksList[1]; + if(numBookmarks > 2) + comic.info.bookmark3 = boomarksList[2]; + //set filters + //TODO: avoid use settings for this... + QSettings settings(YACReader::getSettingsPath()+"/YACReader.ini",QSettings::IniFormat); + int brightness = settings.value(BRIGHTNESS,0).toInt(); + int contrast = settings.value(CONTRAST,100).toInt(); + int gamma = settings.value(GAMMA,100).toInt(); + + if(brightness != 0 || comic.info.brightness!=-1) + comic.info.brightness = brightness; + if(contrast != 100 || comic.info.contrast!=-1) + comic.info.contrast = contrast; + if(gamma != 100 || comic.info.gamma!=-1) + comic.info.gamma = gamma; + } + + +} diff --git a/YACReader/viewer.h b/YACReader/viewer.h new file mode 100644 index 00000000..b1eceb64 --- /dev/null +++ b/YACReader/viewer.h @@ -0,0 +1,168 @@ +#ifndef __VIEWER_H +#define __VIEWER_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "scroll_management.h" + +class ComicDB; +class Comic; +class MagnifyingGlass; +class GoToFlow; +class BookmarksDialog; +class Render; +class GoToDialog; +class YACReaderTranslator; +class GoToFlowWidget; +class Bookmarks; +class PageLabelWidget; +class NotificationsLabelWidget; + + class Viewer : public QScrollArea, public ScrollManagement + { + Q_OBJECT + public: + bool fullscreen; //TODO, change by the right use of windowState(); + public slots: + void prepareForOpening(); + void open(QString pathFile, int atPage = -1); + void open(QString pathFile, const ComicDB & comic); + void prev(); + void next(); + void showGoToDialog(); + void goTo(unsigned int page); + void updatePage(); + void updateContentSize(); + void updateVerticalScrollBar(); + void updateOptions(); + void scrollDown(); + void scrollUp(); + void magnifyingGlassSwitch(); + void showMagnifyingGlass(); + void hideMagnifyingGlass(); + void informationSwitch(); + void updateInformation(); + void goToFlowSwitch(); + void showGoToFlow(); + void moveCursoToGoToFlow(); + void animateShowGoToFlow(); + void animateHideGoToFlow(); + void rotateLeft(); + void rotateRight(); + bool magnifyingGlassIsVisible() {return magnifyingGlassShowed;} + void setBookmark(bool); + void save(); + void doublePageSwitch(); + void doubleMangaPageSwitch(); + void resetContent(); + void setLoadingMessage(); + void setPageUnavailableMessage(); + void configureContent(QString msg); + void hideCursor(); + void showCursor(); + void createConnections(); + void translatorSwitch(); + void animateShowTranslator(); + void animateHideTranslator(); +virtual void mousePressEvent ( QMouseEvent * event ); +virtual void mouseReleaseEvent ( QMouseEvent * event ); + void updateBackgroundColor(const QColor & color); + void updateFitToWidthRatio(float ratio); + void updateConfig(QSettings * settings); + void showMessageErrorOpening(); + void showMessageErrorOpening(QString); + void processCRCError(QString message); + void setBookmarks(); + //deprecated + void updateImageOptions(); + void updateFilters(int brightness, int contrast,int gamma); + void showIsCoverMessage(); + void showIsLastMessage(); + int getCurrentPageNumber(); + + private: + bool information; + bool doublePage; + bool doubleMangaPage; + PageLabelWidget * informationLabel; + //QTimer * scroller; + QPropertyAnimation * verticalScroller; + int posByStep; + int nextPos; + GoToFlowWidget * goToFlow; + QPropertyAnimation * showGoToFlowAnimation; + GoToDialog * goToDialog; + //!Image properties + float adjustToWidthRatio; + //! Comic + //Comic * comic; + int index; + QPixmap *currentPage; + BookmarksDialog * bd; + bool wheelStop; + Render * render; + QTimer * hideCursorTimer; + int direction; + bool drag; + int numScrollSteps; + + //!Widgets + QLabel *content; + + YACReaderTranslator * translator; + int translatorXPos; + QPropertyAnimation * translatorAnimation; + + int yDragOrigin; + int xDragOrigin; + + NotificationsLabelWidget * notificationsLabel; + + bool shouldOpenNext; + bool shouldOpenPrevious; + + private: + //!Magnifying glass + MagnifyingGlass *mglass; + bool magnifyingGlassShowed; + bool restoreMagnifyingGlass; + + //! Manejadores de evento: + void keyPressEvent(QKeyEvent * event); + void resizeEvent(QResizeEvent * event); + void wheelEvent(QWheelEvent * event); + void mouseMoveEvent(QMouseEvent * event); + + public: + Viewer(QWidget * parent = 0); + ~Viewer(); + void toggleFullScreen(); + const QPixmap * pixmap(); + //Comic * getComic(){return comic;} + const BookmarksDialog * getBookmarksDialog(){return bd;} + //returns the current index starting in 1 [1,nPages] + unsigned int getIndex(); + void updateComic(ComicDB & comic); + signals: + void backgroundChanges(); + void pageAvailable(bool); + void pageIsBookmark(bool); + void reset(); + void openNextComic(); + void openPreviousComic(); + }; + +#endif diff --git a/YACReader/width_slider.cpp b/YACReader/width_slider.cpp new file mode 100644 index 00000000..845823c6 --- /dev/null +++ b/YACReader/width_slider.cpp @@ -0,0 +1,94 @@ +#include "width_slider.h" + +#include +#include +#include +#include +#include "configuration.h" + +YACReaderSliderAction::YACReaderSliderAction (QWidget * parent) + :QWidgetAction (parent) { + + widget = new YACReaderSlider(); + setDefaultWidget(widget); + + connect(widget,SIGNAL(fitToWidthRatioChanged(float)),this,SIGNAL(fitToWidthRatioChanged(float))); + + +} + +void YACReaderSliderAction::updateText(int value) +{ + widget->updateText(value); +} + +void YACReaderSliderAction::updateFitToWidthRatio(float v) +{ + widget->updateFitToWidthRatio(v); +} + +YACReaderSlider::YACReaderSlider(QWidget *parent) + :QWidget(parent) +{ + QHBoxLayout* pLayout = new QHBoxLayout(); + + pLayout->addStretch(); + + percentageLabel = new QLabel ("100%"); + percentageLabel->setStyleSheet("QLabel { color : white; }"); + percentageLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + pLayout->addWidget (percentageLabel); + slider = new QSlider(NULL); + slider->setOrientation(Qt::Horizontal); + pLayout->addWidget (slider); + + QString sliderCSS = + + "QSlider::sub-page:horizontal {background-image: url(:/images/sliderSubPage.png); border: 0px; margin-left: 18px;}" + "QSlider::add-page:horizontal {background-image: url(:/images/sliderAddPage.png); border: 0px; margin-right: 25px;}" + "QSlider::handle:horizontal {image: url(:/images/sliderHandle.png); width: 31px;height:45px; }" + "QSlider::groove:horizontal {border-image:url(:/images/sliderGround.png); border-left:-2px; border-right:0;}" + ; + slider->setStyleSheet(sliderCSS); + slider->setFixedSize(218,45); + + QLabel* imgLabel = new QLabel(this); + QPixmap p(":/images/sliderBackground.png"); + imgLabel->resize(p.size()); + imgLabel->setPixmap(p); + + pLayout->setMargin(0); + pLayout->setSpacing(0); + + pLayout->setStretchFactor(percentageLabel,1); + pLayout->setStretchFactor(slider,0); + + + setLayout (pLayout); + setAutoFillBackground(false); + + setMinimumSize(276,45); + + slider->setMinimum(50); + slider->setMaximum(100); + slider->setPageStep(5); + + int value = Configuration::getConfiguration().getFitToWidthRatio()*100; + slider->setValue(value); + percentageLabel->setText(QString("%1 %").arg(value)); + connect(slider,SIGNAL(valueChanged(int)),this,SLOT(updateText(int))); +} + +void YACReaderSlider::updateText(int value) +{ + percentageLabel->setText(QString("%1 %").arg(value)); + Configuration::getConfiguration().setFitToWidthRatio(value/100.0); + emit(fitToWidthRatioChanged(value / 100.0f)); +} + +void YACReaderSlider::updateFitToWidthRatio(float v) +{ + int value = v*100; + slider->setValue(value); + percentageLabel->setText(QString("%1 %").arg(value)); +} diff --git a/YACReader/width_slider.h b/YACReader/width_slider.h new file mode 100644 index 00000000..aecedb95 --- /dev/null +++ b/YACReader/width_slider.h @@ -0,0 +1,48 @@ +#ifndef WIDTH_SLIDER_H +#define WIDTH_SLIDER_H + +#include + +class QLabel; +class QSlider; + +class YACReaderSlider : public QWidget +{ + Q_OBJECT +private: + QLabel * percentageLabel; + QSlider * slider; + +public: + + YACReaderSlider (QWidget * parent = 0); + +public slots: + void updateText(int value); + void updateFitToWidthRatio(float v); + + +signals: + void fitToWidthRatioChanged(float value); +}; + +class YACReaderSliderAction : public QWidgetAction +{ + Q_OBJECT +private: + YACReaderSlider * widget; + +public: + + YACReaderSliderAction (QWidget * parent = 0); + +public slots: + void updateText(int value); + void updateFitToWidthRatio(float v); + + +signals: + void fitToWidthRatioChanged(float value); +}; + +#endif diff --git a/YACReader/yacreader_de.ts b/YACReader/yacreader_de.ts new file mode 100644 index 00000000..16d8d4b0 --- /dev/null +++ b/YACReader/yacreader_de.ts @@ -0,0 +1,791 @@ + + + + + BookmarksDialog + + + Lastest Page + Vorherige Seite + + + + Close + Schliessen + + + + Click on any image to go to the bookmark + Click auf beliebiges Bild um zum Lesezeichen zu gehen + + + + + Loading... + Laden... + + + + FileComic + + + CRC error on page (%1): some of the pages will not be displayed correctly + CRC Error auf Seite (%1): einige Seiten werden nicht korrekt dargestellt + + + + Unknown error opening the file + Unbekannter Fehler beim öffnen des Files + + + + 7z not found + 7z nicht gefunden + + + + Format not supported + Format wird nicht unterstützt + + + + GoToDialog + + + Page : + Seite : + + + + Go To + Gehe nach + + + + Cancel + Abbrechen + + + + + Total pages : + Seiten total : + + + + Go to... + Gehe nach... + + + + GoToFlowToolBar + + + Page : + Seite : + + + + HelpAboutDialog + + + About + Über + + + + Help + + + + + MainWindowViewer + + + &Open + &Öffnen + + + + O + O + + + + Open a comic + Comic öffnen + + + + Open Folder + Ordner Öffnen + + + + Ctrl+O + Crtl+ O + + + + Open image folder + Bilder Ordner öffnen + + + + Save + Speichern + + + + + Save current page + Diese Seite speichern + + + + Previous Comic + Voheriger Comic + + + + Open previous comic + Vorherigen Comic öffnen + + + + Next Comic + Nächster Comic + + + + Open next comic + Nächsten Comic öffnen + + + + &Previous + &Vorherige + + + + Go to previous page + Zur vorherigen Seite gehen + + + + &Next + &Nächste + + + + Go to next page + Zur nächsten Seite gehen + + + + Fit Width + Breite anpassen + + + + Fit image to height + Bild auf Höhe anpassen + + + + Fit Height + Höhe anpassen + + + + Fit image to width + Bildbreite anpassen + + + + Rotate image to the left + Bild nach links drehen + + + + L + L + + + + Rotate image to the right + Bild nach rechts drehen + + + + R + R + + + + Double page mode + Doppelseiten Modus + + + + Switch to double page mode + Zum Doppelseiten Modus wechseln + + + + D + D + + + + Go To + Gehe zu + + + + G + G + + + + Go to page ... + Gehe nach Seite ... + + + + Options + Optionen + + + + C + C + + + + YACReader options + YACReader Optionen + + + + Help + Hilfe + + + + Help, About YACReader + Hilfe, über YACReader + + + + Magnifying glass + Vergößerungsglas + + + + Switch Magnifying glass + Vergrößerungsglas wechseln + + + + Z + Z + + + + Set bookmark + Lesezeichen setzen + + + + Set a bookmark on the current page + Lesezeichen auf dieser Seite setzen + + + + Show bookmarks + Lesezeichen anzeigen + + + + Show the bookmarks of the current comic + Lesezeichen für diesen Comic anzeigen + + + + M + M + + + + Show keyboard shortcuts + Tastaturkürzel anzeigen + + + + Show Info + Info anzeigen + + + + I + I + + + + Close + Schliessen + + + + Show Dictionary + Wörterbuch anzeigen + + + + Always on top + Immer Oberste Ansicht + + + + Show full size + Vollansicht anzeigen + + + + Show go to flow + "Go to Flow" anzeigen + + + + &File + &File + + + + File + File + + + + Open Comic + Comic öffnen + + + + Comic files + Comic Files + + + + Open folder + Ordner öffnen + + + + Image files (*.jpg) + Bilder Files (*.jpg) + + + + page_%1.jpg + Seite_%1.jpg + + + + There is a new version available + Neue Version verfügbar + + + + Do you want to download the new version? + Möchten Sie die neue Version herunterladen? + + + + Remind me in 14 days + In 14 Tagen erneut erinnern + + + + Not now + Nicht jetzt + + + + OptionsDialog + + + "Go to flow" size + "Go to flow" Größe + + + + My comics path + Pfad zu Meine Comics + + + + Page width stretch + Seitenbreite strecken + + + + Background color + Hintergrund Farbe + + + + Choose + Auswählen + + + + Restart is needed + Neustart erforderlich + + + + Brightness + Helligkeit + + + + Contrast + Kontrast + + + + Gamma + Gamma + + + + Reset + Zurücksetzen + + + + Image options + Bilderoptionen + + + + General + Allgemein + + + + Page Flow + Page Flow + + + + Image adjustment + Bildanpassung + + + + Options + Optionen + + + + Comics directory + Comics Verzeichnis + + + + QObject + + + 7z lib not found + 7z Verzeichnis nicht gefunden + + + + unable to load 7z lib from ./utils + 7z Verzeichnis kann von ./utils nicht geladen werden + + + + ShortcutsDialog + + + YACReader keyboard shortcuts + YACReader Tastaturkürzel + + + + Close + schliessen + + + + Keyboard Shortcuts + Tastaturkürzel + + + + Viewer + + + + Press 'O' to open comic. + 'O' drücken um Comic zu öffnen. + + + + Not found + Nicht gefunden + + + + Comic not found + Comic nicht gefunden + + + + Error opening comic + Fehler beim Öffnen des Comics + + + + CRC Error + CRC Fehler + + + + Loading...please wait! + Ladevorgang... Bitte warten! + + + + Page not available! + Seite nicht verfügbar! + + + + Cover! + Titelseite! + + + + Last page! + Letzte Seite! + + + + YACReaderFieldEdit + + + + Click to overwrite + Zum Überschreiben drücken + + + + Restore to default + Ursprungszustand wiederherstellen + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + zum Überschreiben drücken + + + + Restore to default + Urpsrungszustannd wiederherstellen + + + + YACReaderFlowConfigWidget + + + How to show covers: + Wie zeige ich die Titelseite an: + + + + CoverFlow look + Tielseiten Ansicht + + + + Stripe look + Streifen Ansicht + + + + Overlapped Stripe look + Überlappende Streifen Ansicht + + + + YACReaderGLFlowConfigWidget + + + Presets: + Voreinstellungen: + + + + Classic look + Klassische Ansicht + + + + Stripe look + Streifen Ansicht + + + + Overlapped Stripe look + Überlappende Streifenansicht + + + + Modern look + Moderne Ansicht + + + + Roulette look + Zufalls Ansicht + + + + Show advanced settings + Zeige fortgeschrittene Einstellungen + + + + Custom: + Custom: + + + + View angle + Anzeige Winkel + + + + Position + Position + + + + Cover gap + Titelbild Abstand + + + + Central gap + Mittel Abstand + + + + Zoom + Vergrößern + + + + Y offset + Y Anpassung + + + + Z offset + Z Anpassung + + + + Cover Angle + Titelbild Ansichtswinkel + + + + Visibility + Anzeigeintensität + + + + Light + Licht + + + + Max angle + Max Winkel + + + + Low Performance + Niedrige Leistung + + + + High Performance + Hohe Leistung + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + Benutz VSync (verbessert die Bildqualität im Vollanzeigemodus, schlechtere Leistung) + + + + Performance: + Leistung: + + + + YACReaderOptionsDialog + + + Save + Speichern + + + + Cancel + Abbrechen + + + + Use hardware acceleration (restart needed) + Benutze Hardware Beschleunigung (Neustart erforderlich) + + + + YACReaderTranslator + + + YACReader translator + YACReader Übersetzer + + + + + Translation + Übersetzung + + + + clear + löschen + + + + Service not available + Service nicht verfügbar + + + diff --git a/YACReader/yacreader_es.qm b/YACReader/yacreader_es.qm new file mode 100644 index 00000000..b2cee2ed Binary files /dev/null and b/YACReader/yacreader_es.qm differ diff --git a/YACReader/yacreader_es.ts b/YACReader/yacreader_es.ts new file mode 100644 index 00000000..6036ddeb --- /dev/null +++ b/YACReader/yacreader_es.ts @@ -0,0 +1,792 @@ + + + + + BookmarksDialog + + + Lastest Page + Última página + + + + Close + Cerrar + + + + Click on any image to go to the bookmark + Pulsa en cualquier imagen para ir al marcador + + + + + Loading... + Cargando... + + + + FileComic + + + Unknown error opening the file + Error desconocido abriendo el archivo + + + + 7z not found + 7z no encontrado + + + + Format not supported + Formato no soportado + + + + CRC error on page (%1): some of the pages will not be displayed correctly + Error CRC en la página (%1): algunas de las páginas no se mostrarán correctamente + + + + GoToDialog + + + Page : + Página : + + + + Go To + Ir a + + + + Cancel + Cancelar + + + + + Total pages : + Páginas totales: + + + + Go to... + Ir a... + + + + GoToFlowToolBar + + + Page : + Página : + + + + HelpAboutDialog + + + About + Acerca de + + + + Help + Ayuda + + + + MainWindowViewer + + + &Open + &Abrir + + + + O + O + + + + Open a comic + Abrir cómic + + + + Open Folder + Abrir carpeta + + + + Ctrl+O + Ctrl+O + + + + Open image folder + Open images in a folder + Abrir carpeta de imágenes + + + + Save + Guardar + + + + + Save current page + Guardar la página actual + + + + Previous Comic + Cómic anterior + + + + Open previous comic + Abrir cómic anterior + + + + Next Comic + Siguiente Cómic + + + + Open next comic + Abrir siguiente cómic + + + + &Previous + A&nterior + + + + Go to previous page + Ir a la página anterior + + + + &Next + Siguie&nte + + + + Go to next page + Ir a la página siguiente + + + + Fit Width + Ajustar anchura + + + + Fit image to height + Ajustar página a lo alto + + + + Fit Height + Ajustar altura + + + + Fit image to width + Ajustar página a lo ancho + + + + Rotate image to the left + Rotar imagen a la izquierda + + + + L + L + + + + Rotate image to the right + Rotar imagen a la derecha + + + + R + R + + + + Double page mode + Modo a doble página + + + + Switch to double page mode + Cambiar a modo de doble página + + + + D + D + + + + Go To + Ir a + + + + G + G + + + + Go to page ... + Ir a página... + + + + Options + Opciones + + + + C + C + + + + YACReader options + Opciones de YACReader + + + + Help + Ayuda + + + + Help, About YACReader + Ayuda, Sobre YACReader + + + + Magnifying glass + Lupa + + + + Switch Magnifying glass + Lupa On/Off + + + + Z + Z + + + + Set bookmark + Añadir marcador + + + + Set a bookmark on the current page + Añadir un marcador en la página actual + + + + Show bookmarks + Mostrar marcadores + + + + Show the bookmarks of the current comic + Mostrar los marcadores del cómic actual + + + + M + M + + + + Show keyboard shortcuts + Mostrar atajos de teclado + + + + Show Info + Mostrar información + + + + I + I + + + + Close + Cerrar + + + + Show Dictionary + Mostrar diccionario + + + + Always on top + Siempre visible + + + + Show full size + Mostrar a tamaño original + + + + Show go to flow + Mostrar flow ir a + + + + &File + &Archivo + + + + File + Archivo + + + + Open Comic + Abrir cómic + + + + Comic files + Archivos de cómic + + + + Remind me in 14 days + Recordar en 14 días + + + + Not now + Ahora no + + + + Open folder + Abrir carpeta + + + + Image files (*.jpg) + Archivos de imagen (*.jpg) + + + + page_%1.jpg + página_%1.jpg + + + + There is a new version available + Hay una nueva versión disponible + + + + Do you want to download the new version? + ¿Desea descargar la nueva versión? + + + + OptionsDialog + + + "Go to flow" size + Tamaño de "Go to flow" + + + + My comics path + Ruta a mis cómics + + + + Page width stretch + Ajuste en anchura de la página + + + + Background color + Color de fondo + + + + Choose + Elegir + + + + Restart is needed + Es necesario reiniciar + + + + Brightness + Brillo + + + + Contrast + Contraste + + + + Gamma + Gamma + + + + Reset + Reset + + + + Image options + Opciones de imagen + + + + General + General + + + + Page Flow + Page Flow + + + + Image adjustment + Ajustes de imagen + + + + Options + Opciones + + + + Comics directory + Directorio de cómics + + + + QObject + + + 7z lib not found + 7z lib no encontrado + + + + unable to load 7z lib from ./utils + imposible cargar 7z lib de ./utils + + + + ShortcutsDialog + + + YACReader keyboard shortcuts + Atajos de teclado de YACReader + + + + Close + Cerrar + + + + Keyboard Shortcuts + Atajos de teclado + + + + Viewer + + + + Press 'O' to open comic. + Pulsa 'O' para abrir un fichero. + + + + Not found + No encontrado + + + + Comic not found + Cómic no encontrado + + + + Error opening comic + Error abriendo cómic + + + + CRC Error + Error CRC + + + + Page not available! + ¡Página no disponible! + + + + Cover! + ¡Portada! + + + + Last page! + ¡Última página! + + + + Loading...please wait! + Cargando...espere, por favor! + + + + YACReaderFieldEdit + + + + Click to overwrite + Click para sobreescribir + + + + Restore to default + Restaurar valor por defecto + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Click para sobreescribir + + + + Restore to default + Restaurar valor por defecto + + + + YACReaderFlowConfigWidget + + + How to show covers: + Cómo mostrar las portadas: + + + + CoverFlow look + Tipo CoverFlow + + + + Stripe look + Tipo tira + + + + Overlapped Stripe look + Tipo tira solapada + + + + YACReaderGLFlowConfigWidget + + + Presets: + Predefinidos: + + + + Classic look + Tipo clásico + + + + Stripe look + Tipo tira + + + + Overlapped Stripe look + Tipo tira solapada + + + + Modern look + Tipo moderno + + + + Roulette look + Tipo ruleta + + + + Show advanced settings + Opciones avanzadas + + + + Custom: + Personalizado: + + + + View angle + Ãngulo de vista + + + + Position + Posición + + + + Cover gap + Hueco entre portadas + + + + Central gap + Hueco central + + + + Zoom + Zoom + + + + Y offset + Desplazamiento en Y + + + + Z offset + Desplazamiento en Z + + + + Cover Angle + Ãngulo de las portadas + + + + Visibility + Visibilidad + + + + Light + Luz + + + + Max angle + Ãngulo máximo + + + + Low Performance + Rendimiento bajo + + + + High Performance + Alto rendimiento + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + Utilizar VSync (mejora la calidad de imagen en pantalla completa, peor rendimiento) + + + + Performance: + Rendimiento: + + + + YACReaderOptionsDialog + + + Save + Guardar + + + + Cancel + Cancelar + + + + Use hardware acceleration (restart needed) + Utilizar aceleración por hardware (necesario reiniciar) + + + + YACReaderTranslator + + + YACReader translator + Traductor YACReader + + + + + Translation + Traducción + + + + clear + limpiar + + + + Service not available + Servicio no disponible + + + diff --git a/YACReader/yacreader_files.qrc b/YACReader/yacreader_files.qrc new file mode 100644 index 00000000..68d07c60 --- /dev/null +++ b/YACReader/yacreader_files.qrc @@ -0,0 +1,12 @@ + + + ../files/about.html + ../files/helpYACReader.html + ../files/shortcuts.html + + + + ../files/about_es_ES.html + ../files/helpYACReader_es_ES.html + + diff --git a/YACReader/yacreader_fr.ts b/YACReader/yacreader_fr.ts new file mode 100644 index 00000000..6d9646dc --- /dev/null +++ b/YACReader/yacreader_fr.ts @@ -0,0 +1,791 @@ + + + + + BookmarksDialog + + + Lastest Page + Aller à la dernière page + + + + Close + Fermer + + + + Click on any image to go to the bookmark + Cliquez sur une image pour aller au marque-page + + + + + Loading... + Chargement... + + + + FileComic + + + Unknown error opening the file + + + + + 7z not found + 7z introuvable + + + + Format not supported + + + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + GoToDialog + + + Page : + Page : + + + + Go To + Aller à + + + + Cancel + Annuler + + + + + Total pages : + Nombre de pages : + + + + Go to... + Aller à... + + + + GoToFlowToolBar + + + Page : + Page : + + + + HelpAboutDialog + + + About + A propos + + + + Help + Aide + + + + MainWindowViewer + + + &Open + &Ouvrir + + + + O + O + + + + Open a comic + Ouvrir un comic + + + + Open Folder + Ouvrir un dossier + + + + Ctrl+O + Ctrl+O + + + + Open image folder + Ouvrir un dossier d'images + + + + Save + Sauvegarder + + + + + Save current page + Sauvegarder la page actuelle + + + + Previous Comic + Comic précédent + + + + Open previous comic + Ouvrir le comic précédent + + + + Next Comic + Comic suivant + + + + Open next comic + Ouvrir le livre suivant + + + + &Previous + &Précédent + + + + Go to previous page + Aller à la page précédente + + + + &Next + &Suivant + + + + Go to next page + Aller à la page suivante + + + + Fit Width + Ajuster la largeur + + + + Fit image to height + Ajuster l'image à la hauteur + + + + Fit Height + + + + + Fit image to width + Ajuster l'image à la largeur + + + + Rotate image to the left + Rotation sur la gauche + + + + L + L + + + + Rotate image to the right + Rotation sur la droite + + + + R + R + + + + Double page mode + Mode double page + + + + Switch to double page mode + Passer en mode double page + + + + D + D + + + + Go To + Aller à + + + + G + G + + + + Go to page ... + Aller à la page ... + + + + Options + Options + + + + C + C + + + + YACReader options + Options de YACReader + + + + Help + Aide + + + + Help, About YACReader + Aide, à propos de YACReader + + + + Magnifying glass + Loupe + + + + Switch Magnifying glass + Utiliser la loupe + + + + Z + Z + + + + Set bookmark + Placer un marque-page + + + + Set a bookmark on the current page + Placer un marque-page à la page actuelle + + + + Show bookmarks + Voir les marque-pages + + + + Show the bookmarks of the current comic + Voir les marque-pages de ce comic + + + + M + M + + + + Show keyboard shortcuts + Voir les raccourcis + + + + Show Info + Voir les infos + + + + I + I + + + + Close + Fermer + + + + Show Dictionary + Dictionnaire + + + + Always on top + Toujours au dessus + + + + Show full size + Plein écran + + + + Show go to flow + Afficher le go to flow + + + + &File + &Fichier + + + + File + + + + + Open Comic + Ouvrir le comic + + + + Comic files + Comic files + + + + Open folder + Ouvirir le dossier + + + + Image files (*.jpg) + Image files (*.jpg) + + + + page_%1.jpg + page_%1.jpg + + + + There is a new version available + Une nouvelle version est disponible + + + + Do you want to download the new version? + Voulez-vous télécharger la nouvelle version? + + + + Remind me in 14 days + + + + + Not now + + + + + OptionsDialog + + + "Go to flow" size + Taille du "Go to flow" + + + + My comics path + Chemin de mes comics + + + + Page width stretch + Etirer la page + + + + Background color + Couleur d'arrière plan + + + + Choose + Choisir + + + + Restart is needed + Redémarrage nécessaire + + + + Brightness + Luminosité + + + + Contrast + Contraste + + + + Gamma + Gamma + + + + Reset + Reset + + + + Image options + Option de l'image + + + + General + Général + + + + Page Flow + Page Flow + + + + Image adjustment + Ajustement de l'image + + + + Options + Options + + + + Comics directory + Répertoire des comics + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + ShortcutsDialog + + + YACReader keyboard shortcuts + Raccourcis clavier de YACReader + + + + Close + Fermer + + + + Keyboard Shortcuts + Raccourcis clavier + + + + Viewer + + + + Press 'O' to open comic. + Appuyez sur "O" pour ouvrir un comic. + + + + Not found + Introuvable + + + + Comic not found + Comic introuvable + + + + Error opening comic + + + + + CRC Error + + + + + Loading...please wait! + Chargement...Patientez! + + + + Page not available! + + + + + Cover! + Couverture! + + + + Last page! + Dernière page! + + + + YACReaderFieldEdit + + + + Click to overwrite + Cliquez pour écraser + + + + Restore to default + Rétablir les paramètres par défaut + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Cliquez pour écraser + + + + Restore to default + Rétablir les paramètres par défaut + + + + YACReaderFlowConfigWidget + + + How to show covers: + Comment voir les couvertures: + + + + CoverFlow look + Vue CoverFlow + + + + Stripe look + Vue alignée + + + + Overlapped Stripe look + Vue superposée + + + + YACReaderGLFlowConfigWidget + + + Presets: + Réglages: + + + + Classic look + Vue classique + + + + Stripe look + Vue alignée + + + + Overlapped Stripe look + Vue superposée + + + + Modern look + Vue moderne + + + + Roulette look + Vue roulette + + + + Show advanced settings + Voir les paramètres avancés + + + + Custom: + Personnalisation: + + + + View angle + Angle de vue + + + + Position + Position + + + + Cover gap + Espace entre les couvertures + + + + Central gap + Espace couverture centrale + + + + Zoom + Zoom + + + + Y offset + Axe Y + + + + Z offset + Axe Z + + + + Cover Angle + Angle des couvertures + + + + Visibility + Visibilité + + + + Light + Lumière + + + + Max angle + Angle Maximum + + + + Low Performance + Faible performance + + + + High Performance + Haute performance + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + Utiliser VSync (Améliore la qualité d'image en mode plein écran, ralentit la performance) + + + + Performance: + Performance: + + + + YACReaderOptionsDialog + + + Save + Sauvegarder + + + + Cancel + Annuler + + + + Use hardware acceleration (restart needed) + Utiliser accélération hardware (nécessite le redémarrage) + + + + YACReaderTranslator + + + YACReader translator + + + + + + Translation + + + + + clear + + + + + Service not available + + + + diff --git a/YACReader/yacreader_images.qrc b/YACReader/yacreader_images.qrc new file mode 100644 index 00000000..d712c04e --- /dev/null +++ b/YACReader/yacreader_images.qrc @@ -0,0 +1,86 @@ + + + ../images/icon.png + ../images/goto.png + ../images/find_folder.png + ../images/flow1.png + ../images/flow2.png + ../images/flow3.png + ../images/flow4.png + ../images/flow5.png + ../images/notCover.png + ../images/shortcuts.png + ../images/close.png + ../images/up.png + ../images/down.png + ../images/numPagesLabel.png + ../images/numPagesLabelMedium.png + ../images/numPagesLabelBig.png + ../images/imgTopLeft.png + ../images/imgTopMiddle.png + ../images/imgTopRight.png + ../images/imgBottomLeft.png + ../images/imgBottomMiddle.png + ../images/imgBottomRight.png + ../images/imgEdit.png + ../images/imgCenterSlide.png + ../images/imgGoToSlide.png + ../images/imgCenterSlidePressed.png + ../images/imgGoToSlidePressed.png + ../images/sliderBackground.png + ../images/sliderGround.png + ../images/sliderSubPage.png + ../images/sliderAddPage.png + ../images/sliderHandle.png + + ../images/helpImages/open.png + ../images/helpImages/openFolder.png + ../images/helpImages/next.png + ../images/helpImages/prev.png + ../images/helpImages/icon.png + ../images/helpImages/zoom.png + ../images/helpImages/fit.png + ../images/helpImages/goto.png + ../images/helpImages/help.png + ../images/helpImages/center.png + ../images/helpImages/options.png + ../images/helpImages/comicFolder.png + ../images/helpImages/save.png + ../images/helpImages/rotateL.png + ../images/helpImages/rotateR.png + ../images/helpImages/flow1.png + ../images/helpImages/flow2.png + ../images/helpImages/flow3.png + ../images/helpImages/bookmark.png + ../images/helpImages/setBookmark.png + ../images/helpImages/notCover.png + ../images/helpImages/previousComic.png + ../images/helpImages/nextComic.png + ../images/helpImages/deleteLibrary.png + ../images/helpImages/properties.png + ../images/helpImages/doublePage.png + ../images/helpImages/keyboard.png + ../images/helpImages/mouse.png + ../images/helpImages/speaker.png + ../images/defaultCover.png + ../images/onStartFlowSelection.png + ../images/onStartFlowSelection_es.png + ../images/useNewFlowButton.png + ../images/useOldFlowButton.png + ../images/notificationsLabel.png + ../images/fromTo.png + ../images/dropDownArrow.png + ../images/translatorSearch.png + ../images/speaker.png + ../images/clear_shortcut.png + ../images/accept_shortcut.png + ../images/shortcuts_group_comics.png + ../images/shortcuts_group_folders.png + ../images/shortcuts_group_general.png + ../images/shortcuts_group_libraries.png + ../images/shortcuts_group_mglass.png + ../images/shortcuts_group_page.png + ../images/shortcuts_group_reading.png + ../images/shortcuts_group_visualization.png + + diff --git a/YACReader/yacreader_images_osx.qrc b/YACReader/yacreader_images_osx.qrc new file mode 100644 index 00000000..f11dee29 --- /dev/null +++ b/YACReader/yacreader_images_osx.qrc @@ -0,0 +1,57 @@ + + +../images/viewer_toolbar/bookmark_osx.png +../images/viewer_toolbar/bookmark_osx@2x.png +../images/viewer_toolbar/close_osx.png +../images/viewer_toolbar/close_osx@2x.png +../images/viewer_toolbar/doubleMangaPage_osx.png +../images/viewer_toolbar/doubleMangaPage_osx@2x.png +../images/viewer_toolbar/doublePage_osx.png +../images/viewer_toolbar/doublePage_osx@2x.png +../images/viewer_toolbar/flow_osx.png +../images/viewer_toolbar/flow_osx@2x.png +../images/viewer_toolbar/full_osx.png +../images/viewer_toolbar/full_osx@2x.png +../images/viewer_toolbar/goto_osx.png +../images/viewer_toolbar/goto_osx@2x.png +../images/viewer_toolbar/help_osx.png +../images/viewer_toolbar/help_osx@2x.png +../images/viewer_toolbar/info_osx.png +../images/viewer_toolbar/info_osx@2x.png +../images/viewer_toolbar/magnifyingGlass_osx.png +../images/viewer_toolbar/magnifyingGlass_osx@2x.png +../images/viewer_toolbar/next_osx.png +../images/viewer_toolbar/next_osx@2x.png +../images/viewer_toolbar/open_osx.png +../images/viewer_toolbar/open_osx@2x.png +../images/viewer_toolbar/openFolder_osx.png +../images/viewer_toolbar/openFolder_osx@2x.png +../images/viewer_toolbar/openNext_osx.png +../images/viewer_toolbar/openNext_osx@2x.png +../images/viewer_toolbar/openPrevious_osx.png +../images/viewer_toolbar/openPrevious_osx@2x.png +../images/viewer_toolbar/options_osx.png +../images/viewer_toolbar/options_osx@2x.png +../images/viewer_toolbar/previous_osx.png +../images/viewer_toolbar/previous_osx@2x.png +../images/viewer_toolbar/rotateL_osx.png +../images/viewer_toolbar/rotateL_osx@2x.png +../images/viewer_toolbar/rotateR_osx.png +../images/viewer_toolbar/rotateR_osx@2x.png +../images/viewer_toolbar/save_osx.png +../images/viewer_toolbar/save_osx@2x.png +../images/viewer_toolbar/shortcuts_osx.png +../images/viewer_toolbar/shortcuts_osx@2x.png +../images/viewer_toolbar/showBookmarks_osx.png +../images/viewer_toolbar/showBookmarks_osx@2x.png +../images/viewer_toolbar/toHeight_osx.png +../images/viewer_toolbar/toHeight_osx@2x.png +../images/viewer_toolbar/toWidth_osx.png +../images/viewer_toolbar/toWidth_osx@2x.png +../images/viewer_toolbar/toWidthSlider_osx.png +../images/viewer_toolbar/toWidthSlider_osx@2x.png +../images/viewer_toolbar/translator_osx.png +../images/viewer_toolbar/translator_osx@2x.png + + + diff --git a/YACReader/yacreader_images_win.qrc b/YACReader/yacreader_images_win.qrc new file mode 100644 index 00000000..e7251da4 --- /dev/null +++ b/YACReader/yacreader_images_win.qrc @@ -0,0 +1,29 @@ + + + ../images/viewer_toolbar/bookmark.png + ../images/viewer_toolbar/close.png + ../images/viewer_toolbar/doublePage.png + ../images/viewer_toolbar/doubleMangaPage.png + ../images/viewer_toolbar/flow.png + ../images/viewer_toolbar/full.png + ../images/viewer_toolbar/goto.png + ../images/viewer_toolbar/help.png + ../images/viewer_toolbar/info.png + ../images/viewer_toolbar/magnifyingGlass.png + ../images/viewer_toolbar/next.png + ../images/viewer_toolbar/open.png + ../images/viewer_toolbar/openFolder.png + ../images/viewer_toolbar/openNext.png + ../images/viewer_toolbar/openPrevious.png + ../images/viewer_toolbar/options.png + ../images/viewer_toolbar/previous.png + ../images/viewer_toolbar/rotateL.png + ../images/viewer_toolbar/rotateR.png + ../images/viewer_toolbar/save.png + ../images/viewer_toolbar/shortcuts.png + ../images/viewer_toolbar/showBookmarks.png + ../images/viewer_toolbar/toHeight.png + ../images/viewer_toolbar/toWidth.png + ../images/viewer_toolbar/translator.png + + diff --git a/YACReader/yacreader_local_client.cpp b/YACReader/yacreader_local_client.cpp new file mode 100644 index 00000000..a6175b99 --- /dev/null +++ b/YACReader/yacreader_local_client.cpp @@ -0,0 +1,171 @@ +#include "yacreader_local_client.h" +#include "comic_db.h" +#include "yacreader_global.h" + +#include + +#include "QsLog.h" + +using namespace YACReader; + +YACReaderLocalClient::YACReaderLocalClient(QObject *parent) : + QObject(parent) +{ + localSocket = new QLocalSocket(this); + + //connect(localSocket, SIGNAL(readyRead()), this, SLOT(readMessage())); + + /*connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)), + this, SLOT(displayError(QLocalSocket::LocalSocketError)));*/ +} +YACReaderLocalClient::~YACReaderLocalClient() +{ + delete localSocket; +} +//información de comic recibida... +void YACReaderLocalClient::readMessage() +{ + +} +#include + +bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic, QList & siblings) +{ + localSocket->connectToServer(YACREADERLIBRARY_GUID); + if(localSocket->isOpen()) + { + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_4_8); + out << (quint32)0; + out << (quint8)YACReader::RequestComicInfo; + out << libraryId; + out << comic; + out.device()->seek(0); + out << (quint32)(block.size() - sizeof(quint32)); + + int written = 0; + int previousWritten = 0; + quint16 tries = 0; + while(written != block.size() && tries < 200) + { + written += localSocket->write(block); + localSocket->flush(); + if(written == previousWritten) //no bytes were written + tries++; + previousWritten = written; + } + if(tries == 200) + { + localSocket->close(); + QLOG_ERROR() << "Requesting Comic Info : unable to send request"; + return false; + } + + localSocket->waitForBytesWritten(2000); + + //QByteArray data; + tries = 0; + int dataAvailable = 0; + QByteArray packageSize; + localSocket->waitForReadyRead(1000); + while(packageSize.size() < sizeof(quint32) && tries < 20) + { + packageSize.append(localSocket->read(sizeof(quint32) - packageSize.size())); + localSocket->waitForReadyRead(100); + if(dataAvailable == packageSize.size()) + { + tries++; //TODO apply 'tries' fix + } + dataAvailable = packageSize.size(); + } + if(tries == 20) + { + localSocket->close(); + QLOG_ERROR() << "Requesting Comic Info : unable to read package size"; + return false; + } + QDataStream sizeStream(packageSize);//localSocket->read(sizeof(quint32))); + sizeStream.setVersion(QDataStream::Qt_4_8); + quint32 totalSize = 0; + sizeStream >> totalSize; + + QByteArray data; + + tries = 0; + int dataRead = 0; + localSocket->waitForReadyRead(1000); + while(data.length() < totalSize && tries < 20 ) + { + data.append(localSocket->readAll()); + if(data.length() < totalSize) + localSocket->waitForReadyRead(100); + if(data.length() == dataRead) + tries++; + dataRead = data.length(); + } + + if(tries == 20) + { + localSocket->close(); + QLOG_ERROR() << "Requesting Comic Info : unable to read data (" << data.length() << "," << totalSize << ")"; + return false; + } + + QDataStream dataStream(data); + dataStream >> comic; + dataStream >> siblings; + localSocket->close(); + return true; + } + else + { + QLOG_ERROR() << "Requesting Comic Info : unable to connect to the server"; + return false; + } +} + +bool YACReaderLocalClient::sendComicInfo(quint64 libraryId, ComicDB & comic) +{ + localSocket->connectToServer(YACREADERLIBRARY_GUID); + if(localSocket->isOpen()) + { + //QLOG_INFO() << "Connection opened for sending ComicInfo"; + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_4_8); + out << (quint32)0; + out << (quint8)YACReader::SendComicInfo; + out << libraryId; + out << comic; + out.device()->seek(0); + out << (quint32)(block.size() - sizeof(quint32)); + + int written, previousWritten; + written = previousWritten = 0; + int tries = 0; + while(written != block.size() && tries < 100) + { + written += localSocket->write(block); + if(written == previousWritten) + tries++; + previousWritten = written; + } + localSocket->waitForBytesWritten(2000); + localSocket->close(); + //QLOG_INFO() << QString("Sending Comic Info : writen data (%1,%2)").arg(written).arg(block.size()); + if(tries == 100 && written != block.size()) + { + emit finished(); + QLOG_ERROR() << QString("Sending Comic Info : unable to write data (%1,%2)").arg(written).arg(block.size()); + return false; + } + emit finished(); + return true; + } + + emit finished(); + QLOG_ERROR() << "Sending Comic Info : unable to connect to the server"; + return false; + +} diff --git a/YACReader/yacreader_local_client.h b/YACReader/yacreader_local_client.h new file mode 100644 index 00000000..001cb1e7 --- /dev/null +++ b/YACReader/yacreader_local_client.h @@ -0,0 +1,27 @@ +#ifndef YACREADER_LOCAL_CLIENT_H +#define YACREADER_LOCAL_CLIENT_H + +#include + +class QLocalSocket; +class ComicDB; + +class YACReaderLocalClient : public QObject +{ + Q_OBJECT +public: + explicit YACReaderLocalClient(QObject *parent = 0); + ~YACReaderLocalClient(); +signals: + void finished(); +public slots: + void readMessage(); + bool requestComicInfo(quint64 libraryId, ComicDB & comic,QList & siblings); + bool sendComicInfo(quint64 libraryId, ComicDB & comic); + +private: + QLocalSocket * localSocket; + +}; + +#endif // YACREADER_LOCAL_CLIENT_H diff --git a/YACReader/yacreader_nl.ts b/YACReader/yacreader_nl.ts new file mode 100644 index 00000000..246fbe31 --- /dev/null +++ b/YACReader/yacreader_nl.ts @@ -0,0 +1,791 @@ + + + + + BookmarksDialog + + + Lastest Page + Laatste Pagina + + + + Close + Sluiten + + + + Click on any image to go to the bookmark + Klik op een afbeelding om naar de bladwijzer te gaan + + + + + Loading... + Inladen... + + + + FileComic + + + Unknown error opening the file + + + + + 7z not found + 7Z Archiefbestand niet gevonden + + + + Format not supported + + + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + GoToDialog + + + Page : + Pagina : + + + + Go To + Ga Naar + + + + Cancel + Annuleren + + + + + Total pages : + Totaal aantal pagina's : + + + + Go to... + Ga naar... + + + + GoToFlowToolBar + + + Page : + Pagina : + + + + HelpAboutDialog + + + About + Over + + + + Help + Help + + + + MainWindowViewer + + + &Open + &Open + + + + O + O + + + + Open a comic + Open een strip + + + + Open Folder + Map Openen + + + + Ctrl+O + Ctrl+O + + + + Open image folder + Open afbeeldings map + + + + Save + Bewaar + + + + + Save current page + Bewaren huidige pagina + + + + Previous Comic + Vorige Strip + + + + Open previous comic + Open de vorige strip + + + + Next Comic + Volgende Strip + + + + Open next comic + Open volgende strip + + + + &Previous + &Vorige + + + + Go to previous page + Ga naar de vorige pagina + + + + &Next + &Volgende + + + + Go to next page + Ga naar de volgende pagina + + + + Fit Width + Vensterbreedte aanpassen + + + + Fit image to height + Afbeelding aanpassen aan hoogte + + + + Fit Height + + + + + Fit image to width + Afbeelding aanpassen aan breedte + + + + Rotate image to the left + Links omdraaien + + + + L + L + + + + Rotate image to the right + Rechts omdraaien + + + + R + R + + + + Double page mode + Dubbele bladzijde modus + + + + Switch to double page mode + Naar dubbele bladzijde modus + + + + D + D + + + + Go To + Ga Naar + + + + G + G + + + + Go to page ... + Ga naar bladzijde ... + + + + Options + Opties + + + + C + C + + + + YACReader options + YACReader opties + + + + Help + Help + + + + Help, About YACReader + Help, Over YACReader + + + + Magnifying glass + Vergrootglas + + + + Switch Magnifying glass + Overschakelen naar Vergrootglas + + + + Z + Z + + + + Set bookmark + Bladwijzer instellen + + + + Set a bookmark on the current page + Een bladwijzer toevoegen aan de huidige pagina + + + + Show bookmarks + Bladwijzers weergeven + + + + Show the bookmarks of the current comic + Toon de bladwijzers van de huidige strip + + + + M + M + + + + Show keyboard shortcuts + Toon de sneltoetsen + + + + Show Info + Info tonen + + + + I + I + + + + Close + Sluiten + + + + Show Dictionary + Woordenlijst weergeven + + + + Always on top + Altijd op voorgrond + + + + Show full size + Volledig Scherm + + + + Show go to flow + Toon ga naar de Omslagbrowser + + + + &File + &Bestand + + + + File + + + + + Open Comic + Open een Strip + + + + Comic files + Strip bestanden + + + + Open folder + Open een Map + + + + Image files (*.jpg) + Afbeelding bestanden (*.jpg) + + + + page_%1.jpg + pagina_%1.jpg + + + + There is a new version available + Er is een nieuwe versie beschikbaar + + + + Do you want to download the new version? + Wilt u de nieuwe versie downloaden? + + + + Remind me in 14 days + + + + + Not now + + + + + OptionsDialog + + + "Go to flow" size + "Naar Omslagbrowser" afmetingen + + + + My comics path + Pad naar mijn strips + + + + Page width stretch + Pagina breedte + + + + Background color + Achtergrondkleur + + + + Choose + Kies + + + + Restart is needed + Herstart is nodig + + + + Brightness + Helderheid + + + + Contrast + Contrast + + + + Gamma + Gamma + + + + Reset + Standaardwaarden terugzetten + + + + Image options + Afbeelding opties + + + + General + Algemeen + + + + Page Flow + Omslagbrowser + + + + Image adjustment + Beeldaanpassing + + + + Options + Opties + + + + Comics directory + Strips map + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + ShortcutsDialog + + + YACReader keyboard shortcuts + YACReader sneltoetsen + + + + Close + Sluiten + + + + Keyboard Shortcuts + Sneltoetsen + + + + Viewer + + + + Press 'O' to open comic. + Druk 'O' om een strip te openen. + + + + Not found + Niet gevonden + + + + Comic not found + Strip niet gevonden + + + + Error opening comic + + + + + CRC Error + + + + + Loading...please wait! + Inladen...even wachten! + + + + Page not available! + + + + + Cover! + Omslag! + + + + Last page! + Laatste pagina! + + + + YACReaderFieldEdit + + + + Click to overwrite + Klik hier om te overschrijven + + + + Restore to default + Standaardwaarden herstellen + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Klik hier om te overschrijven + + + + Restore to default + Standaardwaarden herstellen + + + + YACReaderFlowConfigWidget + + + How to show covers: + Omslagbladen bekijken: + + + + CoverFlow look + Omslagbrowser uiterlijk + + + + Stripe look + Brede band + + + + Overlapped Stripe look + Overlappende band + + + + YACReaderGLFlowConfigWidget + + + Presets: + Voorinstellingen: + + + + Classic look + Klassiek + + + + Stripe look + Brede band + + + + Overlapped Stripe look + Overlappende band + + + + Modern look + Modern + + + + Roulette look + Roulette + + + + Show advanced settings + Toon geavanceerde instellingen + + + + Custom: + Aangepast: + + + + View angle + Kijkhoek + + + + Position + Positie + + + + Cover gap + Ruimte tss Omslag + + + + Central gap + Centrale ruimte + + + + Zoom + Zoom + + + + Y offset + Y-positie + + + + Z offset + Z- positie + + + + Cover Angle + Omslag hoek + + + + Visibility + Zichtbaarheid + + + + Light + Licht + + + + Max angle + Maximale hoek + + + + Low Performance + Lage Prestaties + + + + High Performance + Hoge Prestaties + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + Gebruik VSync (verbetering van de beeldkwaliteit in de modus volledig scherm, slechtere prestatie) + + + + Performance: + Prestatie: + + + + YACReaderOptionsDialog + + + Save + Bewaar + + + + Cancel + Annuleren + + + + Use hardware acceleration (restart needed) + Gebruik hardware versnelling (opnieuw opstarten vereist) + + + + YACReaderTranslator + + + YACReader translator + + + + + + Translation + + + + + clear + + + + + Service not available + + + + diff --git a/YACReader/yacreader_pt.ts b/YACReader/yacreader_pt.ts new file mode 100644 index 00000000..d2543af9 --- /dev/null +++ b/YACReader/yacreader_pt.ts @@ -0,0 +1,791 @@ + + + + + BookmarksDialog + + + Lastest Page + Última Página + + + + Close + Fechar + + + + Click on any image to go to the bookmark + Clique em qualquer imagem para ir para o marcador + + + + + Loading... + Carregando... + + + + FileComic + + + Unknown error opening the file + + + + + 7z not found + 7z não encontrado + + + + Format not supported + + + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + GoToDialog + + + Page : + Página : + + + + Go To + Ir Para + + + + Cancel + Cancelar + + + + + Total pages : + Total de páginas : + + + + Go to... + Ir para... + + + + GoToFlowToolBar + + + Page : + Página : + + + + HelpAboutDialog + + + About + + + + + Help + Ajuda + + + + MainWindowViewer + + + &Open + &Abrir + + + + O + O + + + + Open a comic + Abrir um quadrinho + + + + Open Folder + Abrir Pasta + + + + Ctrl+O + Ctrl+O + + + + Open image folder + + + + + Save + Salvar + + + + + Save current page + Salvar página atual + + + + Previous Comic + Quadrinho Anterior + + + + Open previous comic + Abrir quadrinho anterior + + + + Next Comic + Próximo Quadrinho + + + + Open next comic + Abrir próximo quadrinho + + + + &Previous + A&nterior + + + + Go to previous page + Ir para a página anterior + + + + &Next + &Próxima + + + + Go to next page + Ir para a próxima página + + + + Fit Width + Ajustar à Largura + + + + Fit image to height + + + + + Fit Height + + + + + Fit image to width + + + + + Rotate image to the left + Girar imagem à esquerda + + + + L + L + + + + Rotate image to the right + Girar imagem à direita + + + + R + R + + + + Double page mode + Modo dupla página + + + + Switch to double page mode + Alternar para o modo dupla página + + + + D + D + + + + Go To + Ir Para + + + + G + G + + + + Go to page ... + Ir para a página... + + + + Options + Opções + + + + C + C + + + + YACReader options + Opções do YACReader + + + + Help + Ajuda + + + + Help, About YACReader + Ajuda, Sobre o YACReader + + + + Magnifying glass + Lupa + + + + Switch Magnifying glass + Alternar Lupa + + + + Z + Z + + + + Set bookmark + Definir marcador + + + + Set a bookmark on the current page + Definir um marcador na página atual + + + + Show bookmarks + Mostrar marcadores + + + + Show the bookmarks of the current comic + Mostrar os marcadores do quadrinho atual + + + + M + M + + + + Show keyboard shortcuts + Mostrar teclas de atalhos + + + + Show Info + Mostrar Informações + + + + I + I + + + + Close + Fechar + + + + Show Dictionary + + + + + Always on top + + + + + Show full size + + + + + Show go to flow + + + + + &File + &Arquivo + + + + File + + + + + Open Comic + Abrir Quadrinho + + + + Comic files + + + + + Remind me in 14 days + + + + + Not now + + + + + Open folder + Abrir pasta + + + + Image files (*.jpg) + Arquivos de imagem (*.jpg) + + + + page_%1.jpg + + + + + There is a new version available + Há uma nova versão disponível + + + + Do you want to download the new version? + Você deseja baixar a nova versão? + + + + OptionsDialog + + + "Go to flow" size + Tamanho do "Ir para cheia" + + + + My comics path + Meu caminho de quadrinhos + + + + Page width stretch + Trecho da largura da página + + + + Background color + + + + + Choose + + + + + Restart is needed + Reiniciar é necessário + + + + Brightness + + + + + Contrast + + + + + Gamma + + + + + Reset + + + + + Image options + + + + + General + + + + + Page Flow + + + + + Image adjustment + + + + + Options + Opções + + + + Comics directory + Diretório de quadrinhos + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + ShortcutsDialog + + + YACReader keyboard shortcuts + Teclas de atalhos do YACReader + + + + Close + Fechar + + + + Keyboard Shortcuts + + + + + Viewer + + + + Press 'O' to open comic. + Pressione 'O' para abrir um quadrinho. + + + + Not found + + + + + Comic not found + + + + + Error opening comic + + + + + CRC Error + + + + + Loading...please wait! + Carregando... por favor, aguarde! + + + + Page not available! + + + + + Cover! + + + + + Last page! + + + + + YACReaderFieldEdit + + + + Click to overwrite + + + + + Restore to default + + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + + + + + Restore to default + + + + + YACReaderFlowConfigWidget + + + How to show covers: + + + + + CoverFlow look + Olhar capa cheia + + + + Stripe look + Olhar lista + + + + Overlapped Stripe look + Olhar lista sobreposta + + + + YACReaderGLFlowConfigWidget + + + Presets: + + + + + Classic look + + + + + Stripe look + Olhar lista + + + + Overlapped Stripe look + Olhar lista sobreposta + + + + Modern look + + + + + Roulette look + + + + + Show advanced settings + + + + + Custom: + + + + + View angle + + + + + Position + + + + + Cover gap + + + + + Central gap + + + + + Zoom + + + + + Y offset + + + + + Z offset + + + + + Cover Angle + + + + + Visibility + + + + + Light + + + + + Max angle + + + + + Low Performance + + + + + High Performance + + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + + + + + Performance: + + + + + YACReaderOptionsDialog + + + Save + Salvar + + + + Cancel + Cancelar + + + + Use hardware acceleration (restart needed) + + + + + YACReaderTranslator + + + YACReader translator + + + + + + Translation + + + + + clear + + + + + Service not available + + + + diff --git a/YACReader/yacreader_ru.ts b/YACReader/yacreader_ru.ts new file mode 100644 index 00000000..67e44ab4 --- /dev/null +++ b/YACReader/yacreader_ru.ts @@ -0,0 +1,791 @@ + + + + + BookmarksDialog + + + Lastest Page + ПоÑледнÑÑ Ð¡Ñ‚Ñ€Ð°Ð½Ð¸Ñ†Ð° + + + + Close + Закрыть + + + + Click on any image to go to the bookmark + Ðажмите на любое изображение, чтобы перейти к закладке + + + + + Loading... + Загрузка... + + + + FileComic + + + Unknown error opening the file + + + + + 7z not found + 7z не найден + + + + Format not supported + + + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + GoToDialog + + + Page : + Страница: + + + + Go To + Перейти к + + + + Cancel + Отмена + + + + + Total pages : + Общее количеÑтв Ñтраниц: + + + + Go to... + Перейти к... + + + + GoToFlowToolBar + + + Page : + Страница: + + + + HelpAboutDialog + + + About + О программе + + + + Help + Справка + + + + MainWindowViewer + + + &Open + &Открыть + + + + O + О + + + + Open a comic + Открыть ÐºÐ¾Ð¼Ð¸ÐºÑ + + + + Open Folder + Открыть папку + + + + Ctrl+O + Ctrl+О + + + + Open image folder + Открыть папку Ñ Ð¸Ð·Ð¾Ð±Ñ€Ð°Ð¶ÐµÐ½Ð¸Ñми + + + + Save + Сохранить + + + + + Save current page + Сохранить нынешнюю Ñтраницу + + + + Previous Comic + Предыдущий ÐºÐ¾Ð¼Ð¸ÐºÑ + + + + Open previous comic + Открыть предыдуший ÐºÐ¾Ð¼Ð¸ÐºÑ + + + + Next Comic + Следующий ÐºÐ¾Ð¼Ð¸ÐºÑ + + + + Open next comic + Открыть Ñледующий ÐºÐ¾Ð¼Ð¸ÐºÑ + + + + &Previous + &Предыдущий + + + + Go to previous page + Перейти к предыдущей Ñтранице + + + + &Next + &Следующий + + + + Go to next page + Перейти к Ñледующей Ñтранице + + + + Fit Width + Подогнать ширину + + + + Fit image to height + + + + + Fit Height + + + + + Fit image to width + + + + + Rotate image to the left + Повернуть изображение против чаÑовой Ñтрелки + + + + L + L + + + + Rotate image to the right + Повернуть изображение по чаÑовой Ñтрелке + + + + R + R + + + + Double page mode + Двойной режим Ñтраницы + + + + Switch to double page mode + Переключить на двойной режим Ñтраницы + + + + D + D + + + + Go To + Перейти к + + + + G + G + + + + Go to page ... + Перейти к Ñтранице ... + + + + Options + ÐаÑтройки + + + + C + С + + + + YACReader options + ÐаÑтройки YACReader + + + + Help + Справка + + + + Help, About YACReader + Справка по YACReader + + + + Magnifying glass + Увеличительное Ñтекло + + + + Switch Magnifying glass + ПереключитьÑÑ Ð½Ð° увеличительное Ñтекло + + + + Z + Z + + + + Set bookmark + УÑтановить закладку + + + + Set a bookmark on the current page + УÑтановить закладку на текущей Ñтранице + + + + Show bookmarks + Показать закладки + + + + Show the bookmarks of the current comic + Показать закладки текущего комикÑа + + + + M + M + + + + Show keyboard shortcuts + Показать горÑчие клавиши + + + + Show Info + Показать информацию + + + + I + I + + + + Close + Закрыть + + + + Show Dictionary + Показать Ñловарь + + + + Always on top + Ð’Ñегда Ñверху + + + + Show full size + ПолноÑкранный режим + + + + Show go to flow + + + + + &File + &Файл + + + + File + + + + + Open Comic + Открыть ÐºÐ¾Ð¼Ð¸ÐºÑ + + + + Comic files + Файлы комикÑа + + + + Open folder + Открыть папку + + + + Image files (*.jpg) + Файлы изображений + + + + page_%1.jpg + + + + + There is a new version available + ДоÑтупно новое обновление + + + + Do you want to download the new version? + Хотите загрузить новую верÑию ? + + + + Remind me in 14 days + + + + + Not now + + + + + OptionsDialog + + + "Go to flow" size + Перейти к иÑходному размеру + + + + My comics path + Путь комикÑа + + + + Page width stretch + РаÑÑ‚Ñнуть Ñтраницу в ширину + + + + Background color + Фоновый цвет + + + + Choose + Выбрать + + + + Restart is needed + Ðеобходима перезагрузка + + + + Brightness + ЯркоÑть + + + + Contrast + КонтраÑÑ‚ + + + + Gamma + Гамма + + + + Reset + ПерезапуÑк + + + + Image options + ÐаÑтройки Ð¸Ð·Ð¾Ð±Ñ€Ð°Ð¶ÐµÐ½Ð¸Ñ + + + + General + Общее + + + + Page Flow + Страница потока + + + + Image adjustment + Регулировки Ð¸Ð·Ð¾Ð±Ñ€Ð°Ð¶ÐµÐ½Ð¸Ñ + + + + Options + ÐаÑтройки + + + + Comics directory + Каталог комикÑов + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + ShortcutsDialog + + + YACReader keyboard shortcuts + Клавиатурные комбинации YACReader + + + + Close + Закрыть + + + + Keyboard Shortcuts + Клавиатурные комбинации + + + + Viewer + + + + Press 'O' to open comic. + Ðажмите "O" , чтобы открыть комикÑ. + + + + Not found + Ðе найдено + + + + Comic not found + ÐšÐ¾Ð¼Ð¸ÐºÑ Ð½Ðµ найден + + + + Error opening comic + + + + + CRC Error + + + + + Loading...please wait! + Загрузка ... ПожалуйÑта подождите! + + + + Page not available! + + + + + Cover! + + + + + Last page! + + + + + YACReaderFieldEdit + + + + Click to overwrite + Ðажмите, чтобы перепиÑать + + + + Restore to default + Вернуть начальные уÑтановки + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Ðажмите, чтобы перепиÑать + + + + Restore to default + Вернуть начальные уÑтановки + + + + YACReaderFlowConfigWidget + + + How to show covers: + Как показать обложки: + + + + CoverFlow look + ПредоÑмотр обложки + + + + Stripe look + Вид полоÑами + + + + Overlapped Stripe look + Вид перекрывающимиÑÑ Ð¿Ð¾Ð»Ð¾Ñами + + + + YACReaderGLFlowConfigWidget + + + Presets: + ПредуÑтановки: + + + + Classic look + КлаÑÑичеÑкий вид + + + + Stripe look + Вид полоÑами + + + + Overlapped Stripe look + Вид перекрывающимиÑÑ Ð¿Ð¾Ð»Ð¾Ñами + + + + Modern look + Современный вид + + + + Roulette look + Вид рулеткой + + + + Show advanced settings + + + + + Custom: + ПользовательÑкий: + + + + View angle + Угол Ð·Ñ€ÐµÐ½Ð¸Ñ + + + + Position + ÐŸÐ¾Ð·Ð¸Ñ†Ð¸Ñ + + + + Cover gap + ОÑветить разрыв + + + + Central gap + СфокуÑировать разрыв + + + + Zoom + МаÑштабировать + + + + Y offset + Смещение по Y + + + + Z offset + Смещение по Z + + + + Cover Angle + Охватить угол + + + + Visibility + ПрозрачноÑть + + + + Light + ОÑветить + + + + Max angle + МакÑимальный угол + + + + Low Performance + ÐœÐ¸Ð½Ð¸Ð¼Ð°Ð»ÑŒÐ½Ð°Ñ Ð¿Ñ€Ð¾Ð¸Ð·Ð²Ð¾Ð´Ð¸Ñ‚ÐµÐ»ÑŒÐ½Ð¾Ñть + + + + High Performance + МакÑÐ¸Ð¼Ð°Ð»ÑŒÐ½Ð°Ñ Ð¿Ñ€Ð¾Ð¸Ð·Ð²Ð¾Ð´Ð¸Ñ‚ÐµÐ»ÑŒÐ½Ð¾Ñть + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + ИÑпользовать VSync (повыÑить формат Ð¸Ð·Ð¾Ð±Ñ€Ð°Ð¶ÐµÐ½Ð¸Ñ Ð² полноÑкранном режиме , хуже производительноÑть) + + + + Performance: + ПроизводительноÑть: + + + + YACReaderOptionsDialog + + + Save + Сохранить + + + + Cancel + Отмена + + + + Use hardware acceleration (restart needed) + ИÑпользовать аппаратное уÑкорение (ТребуетÑÑ Ð¿ÐµÑ€ÐµÐ·Ð°Ð³Ñ€ÑƒÐ·ÐºÐ°) + + + + YACReaderTranslator + + + YACReader translator + + + + + + Translation + + + + + clear + + + + + Service not available + + + + diff --git a/YACReader/yacreader_source.ts b/YACReader/yacreader_source.ts new file mode 100644 index 00000000..87f1ba74 --- /dev/null +++ b/YACReader/yacreader_source.ts @@ -0,0 +1,791 @@ + + + + + BookmarksDialog + + + Lastest Page + + + + + Close + + + + + Click on any image to go to the bookmark + + + + + + Loading... + + + + + FileComic + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + Unknown error opening the file + + + + + 7z not found + + + + + Format not supported + + + + + GoToDialog + + + Page : + + + + + Go To + + + + + Cancel + + + + + + Total pages : + + + + + Go to... + + + + + GoToFlowToolBar + + + Page : + + + + + HelpAboutDialog + + + About + + + + + Help + + + + + MainWindowViewer + + + &Open + + + + + O + + + + + Open a comic + + + + + Open Folder + + + + + Ctrl+O + + + + + Open image folder + + + + + Save + + + + + + Save current page + + + + + Previous Comic + + + + + Open previous comic + + + + + Next Comic + + + + + Open next comic + + + + + &Previous + + + + + Go to previous page + + + + + &Next + + + + + Go to next page + + + + + Fit Width + + + + + Fit image to height + + + + + Fit Height + + + + + Fit image to width + + + + + Rotate image to the left + + + + + L + + + + + Rotate image to the right + + + + + R + + + + + Double page mode + + + + + Switch to double page mode + + + + + D + + + + + Go To + + + + + G + + + + + Go to page ... + + + + + Options + + + + + C + + + + + YACReader options + + + + + Help + + + + + Help, About YACReader + + + + + Magnifying glass + + + + + Switch Magnifying glass + + + + + Z + + + + + Set bookmark + + + + + Set a bookmark on the current page + + + + + Show bookmarks + + + + + Show the bookmarks of the current comic + + + + + M + + + + + Show keyboard shortcuts + + + + + Show Info + + + + + I + + + + + Close + + + + + Show Dictionary + + + + + Always on top + + + + + Show full size + + + + + Show go to flow + + + + + &File + + + + + File + + + + + Open Comic + + + + + Comic files + + + + + Open folder + + + + + Image files (*.jpg) + + + + + page_%1.jpg + + + + + There is a new version available + + + + + Do you want to download the new version? + + + + + Remind me in 14 days + + + + + Not now + + + + + OptionsDialog + + + "Go to flow" size + + + + + My comics path + + + + + Page width stretch + + + + + Background color + + + + + Choose + + + + + Restart is needed + + + + + Brightness + + + + + Contrast + + + + + Gamma + + + + + Reset + + + + + Image options + + + + + General + + + + + Page Flow + + + + + Image adjustment + + + + + Options + + + + + Comics directory + + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + ShortcutsDialog + + + YACReader keyboard shortcuts + + + + + Close + + + + + Keyboard Shortcuts + + + + + Viewer + + + + Press 'O' to open comic. + + + + + Not found + + + + + Comic not found + + + + + Error opening comic + + + + + CRC Error + + + + + Loading...please wait! + + + + + Page not available! + + + + + Cover! + + + + + Last page! + + + + + YACReaderFieldEdit + + + + Click to overwrite + + + + + Restore to default + + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + + + + + Restore to default + + + + + YACReaderFlowConfigWidget + + + How to show covers: + + + + + CoverFlow look + + + + + Stripe look + + + + + Overlapped Stripe look + + + + + YACReaderGLFlowConfigWidget + + + Presets: + + + + + Classic look + + + + + Stripe look + + + + + Overlapped Stripe look + + + + + Modern look + + + + + Roulette look + + + + + Show advanced settings + + + + + Custom: + + + + + View angle + + + + + Position + + + + + Cover gap + + + + + Central gap + + + + + Zoom + + + + + Y offset + + + + + Z offset + + + + + Cover Angle + + + + + Visibility + + + + + Light + + + + + Max angle + + + + + Low Performance + + + + + High Performance + + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + + + + + Performance: + + + + + YACReaderOptionsDialog + + + Save + + + + + Cancel + + + + + Use hardware acceleration (restart needed) + + + + + YACReaderTranslator + + + YACReader translator + + + + + + Translation + + + + + clear + + + + + Service not available + + + + diff --git a/YACReader/yacreader_tr.ts b/YACReader/yacreader_tr.ts new file mode 100644 index 00000000..8e7a0412 --- /dev/null +++ b/YACReader/yacreader_tr.ts @@ -0,0 +1,725 @@ + + + + + BookmarksDialog + + Close + Kapat + + + Loading... + Yükleniyor... + + + Click on any image to go to the bookmark + Yer imine git + + + Lastest Page + Son Sayfa + + + + Configuration + + There was a problem saving YACReader configuration. Please, check if you have enough permissions in the YACReader root folder. + Yeni ayarlar kaydedilirken bir problem çıktı. Lütfen YACReader dosyasını açın. + + + Saving config file.... + Config dosyası kaydediliyor... + + + + FileComic + + File not found or not images in file + Dosya bulunamadı yada dosyada resim yok + + + 7z not found + 7z bulunamadı + + + Comic not found + Çizgi roman bulunamadı + + + Not found + Bulunamadı + + + File error + Dosya hatası + + + 7z problem + 7z Problemli + + + 7z reading + 7z Okunuyor + + + 7z crashed. + 7z BozulmuÅŸ. + + + problem reading from 7z + 7z Okunurken Problem OluÅŸtu + + + 7z crashed + 7z Bozulması + + + Unknown error 7z + Bilinmeyen 7z hatası + + + 7z wasn't found in your PATH. + 7z Yolu Bulunamadı. + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + Unknown error opening the file + + + + Format not supported + + + + + GoToDialog + + Go To + Git + + + Go to... + Git... + + + Total pages : + Toplam sayfa: + + + Cancel + Vazgeç + + + Page : + Sayfa : + + + + GoToFlowToolBar + + Page : + Sayfa : + + + + HelpAboutDialog + + Help + Yardım + + + About + Hakkında + + + + MainWindowViewer + + C + C + + + D + D + + + G + G + + + I + I + + + L + L + + + M + M + + + O + O + + + R + R + + + Z + Z + + + Help + Yardım + + + Save + Kaydet + + + &File + &Dosya + + + &Next + &İleri + + + &Open + &Aç + + + Close + Kapat + + + Open Comic + Çizgi Romanı Aç + + + Go To + Git + + + Open image folder + Resim dosyasınıaç + + + Set bookmark + Yer imi yap + + + page_%1.jpg + sayfa_%1.jpg + + + Switch to double page mode + Çift sayfa moduna geç + + + Save current page + Geçerli sayfayı kaydet + + + Double page mode + Çift sayfa modu + + + Switch Magnifying glass + Büyüteç + + + Open Folder + Dosyayı Aç + + + Ctrl+O + Ctrl+O + + + Comic files + Çizgi Roman Dosyaları + + + Go to previous page + Önceki sayfaya dön + + + Open a comic + Çizgi romanı aç + + + Image files (*.jpg) + Resim dosyaları (*.jpg) + + + Next Comic + Sırada ki çizgi roman + + + Saving error log file.... + Hata dosyasını kaydet... + + + Fit Width + Uygun GeniÅŸlik + + + Options + Ayarlar + + + Show Info + Bilgiyi göster + + + Open folder + Dosyayı aç + + + Go to page ... + Sayfata git... + + + Fit image to width + Görüntüyü sığdır + + + &Previous + &Geri + + + Go to next page + Sonra ki sayfaya geç + + + Show keyboard shortcuts + Kılavye kısayollarını göster + + + Open next comic + Sıradaki çizgi romanı aç + + + There is a new version available + Yeni versiyon mevcut + + + Show bookmarks + Yer imlerini göster + + + Open previous comic + Önceki çizgi romanı aç + + + Rotate image to the left + Sayfayı sola yatır + + + Fit image to height + Uygun yüksekliÄŸe getir + + + Show the bookmarks of the current comic + Bu çizgi romanın yer imlerini göster + + + Show Dictionary + Sözlüğü göster + + + YACReader options + YACReader ayarları + + + Help, About YACReader + YACReader hakkında yardım ve bilgi + + + Show go to flow + Akışı göster + + + Previous Comic + Önce ki çizgi roman + + + Show full size + Tam erken + + + Magnifying glass + Büyüteç + + + Set a bookmark on the current page + Sayfayı yer imi olarak ayarla + + + Do you want to download the new version? + Yeni versiyonu indirmek ister misin ? + + + There was a problem saving YACReader error log file. Please, check if you have enough permissions in the YACReader root folder. + Kaydederken bir problem çıktı YACReader hata kayıt dosyası. Lütfen YACReader root dosyasını ziyaret edin. + + + Rotate image to the right + Sayfayı saÄŸa yator + + + Always on top + Her zaman üstte + + + Remind me in 14 days + + + + Not now + + + + Fit Height + + + + File + + + + + OptionsDialog + + Gamma + Gama + + + Reset + Yeniden baÅŸlat + + + My comics path + Çizgi Romanlarım + + + Image adjustment + Resim ayarları + + + Page width stretch + Sayfayı uzat + + + "Go to flow" size + Akış görünümüne git + + + Choose + Seç + + + Image options + Sayfa ayarları + + + Contrast + Kontrast + + + Options + Ayarlar + + + Comics directory + Çizgi roman konumu + + + Background color + Arka plan rengi + + + Page Flow + Sayfa akışı + + + General + Genel + + + Brightness + Parlaklık + + + Restart is needed + Yeniden baÅŸlatılmalı + + + + QObject + + 7z lib not found + + + + unable to load 7z lib from ./utils + + + + + ShortcutsDialog + + Close + Kapat + + + YACReader keyboard shortcuts + YACReader klavye kısayolları + + + Keyboard Shortcuts + Kılavye Kısayolları + + + + Viewer + + Press 'O' to open comic. + 'O'ya basarak aç. + + + Cover! + Kapak! + + + Comic not found + Çizgi roman bulunamadı + + + Not found + Bulunamadı + + + Last page! + Son sayfa! + + + Loading...please wait! + Yükleniyor... lütfen bekleyin! + + + Error opening comic + + + + CRC Error + + + + Page not available! + + + + + YACReaderDeletingProgress + + cancel + vazgeç + + + Please wait, deleting in progress... + Lütfen bekle silme iÅŸlemi gerçekleÅŸtiriliyor... + + + + YACReaderFieldEdit + + Restore to default + Varsayılana ayarla + + + Click to overwrite + Üzerine yazmak için tıkla + + + + YACReaderFieldPlainTextEdit + + Restore to default + Varsayılana ayarla + + + Click to overwrite + Üstüne yazmak için tıkla + + + + YACReaderFlowConfigWidget + + CoverFlow look + Kapak akışı görünümü + + + How to show covers: + Kapaklar nasıl gözüksün: + + + Stripe look + Åžerit görünüm + + + Overlapped Stripe look + Çakışan ÅŸerit görünüm + + + + YACReaderGLFlowConfigWidget + + Zoom + YakınlaÅŸ + + + Light + Işık + + + Show advanced settings + Daha fazla ayar göster + + + Roulette look + Rulet görünüm + + + Cover Angle + Kapak Açısı + + + Stripe look + Strip görünüm + + + Position + Pozisyon + + + Z offset + Z dengesi + + + Y offset + Y dengesi + + + Central gap + BoÅŸ merkaz + + + Presets: + Hazırlayan: + + + Overlapped Stripe look + Çakışan ÅŸerit görünüm + + + Modern look + Modern görünüm + + + View angle + Bakış açısı + + + Max angle + Maksimum açı + + + Custom: + KiÅŸisel: + + + Classic look + Klasik görünüm + + + Cover gap + Kapak + + + High Performance + Yüksek performans + + + Performance: + Performans: + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + VSync kullan + + + Visibility + Görünülebilirlik + + + Low Performance + Düşük Performans + + + + YACReaderOptionsDialog + + Save + Kaydet + + + Use hardware acceleration (restart needed) + Yüksek donanımlı kullan (yeniden baÅŸlatmak gerekli) + + + Cancel + Vazgeç + + + + YACReaderSideBar + + Search folders and comics + Dosyaları ve çizgi romanları ara + + + LIBRARIES + KÜTÜPHANELER + + + FOLDERS + DOSYALAR + + + + YACReaderTranslator + + YACReader translator + + + + Translation + + + + clear + + + + Service not available + + + + diff --git a/YACReaderLibrary.1 b/YACReaderLibrary.1 new file mode 100644 index 00000000..45a6737e --- /dev/null +++ b/YACReaderLibrary.1 @@ -0,0 +1,48 @@ +.\" Manpage for YACReaderLibrary. +.\" Contact yoann.gauthier9@gmail.com to correct errors or typos. +.TH man 1 "28 September 2014" "2.0" "YACReaderLibrary man page" +.SH NAME +YACReaderLibrary \- launch YACReaderLibrary application. +.SH SYNOPSIS +YACReaderLibrary +.br +YACReaderLibrary [\fB\-h\fR | \fB\-\-help\fR] +.br +YACReaderLibrary [\fB\-v\fR | \fB\-\-version\fR] + +.SH DESCRIPTION +YACReaderLibrary an application for browsing and managing your comic collections with various smooth transition effects. +.SH OPTIONS +.TP +Without options +Start YACReaderLibrary. +.TP +.BR \-h, \-\- help +Display help text and exit. +.TP +.BR \-v, \-\- version +Display version information and exit. +.SH FEATURES +- Create, manage and browse your comics collections using beautiful, customizable and smooth "comic flow" transitions. +.TP +- Comic Vine support. +.TP +- Easily organization of your comics in libraries. +.TP +- Find your comics quickly using the built-in search engine. +.TP +- Open your comics with YACReader from YACReaderLibrary. +.TP +- Enjoy your comics covers with the fullscreen mode. +.TP +- Mark your comics as read/unread and track your reading progress. +.SH CONTACTS +To report bug or contact developpers, send a mail to : +.RS 3 +.TP +\fBinfo@yacreader.com\fR : for general information or suggestions about YACReader. +.TP +\fBsupport@yacreader.com\fR : for problems with YACReader or bugs detected. +.RE +.SH AUTHOR +Luis Ãngel San Martín Rodríguez (luisangelsm@gmail.com) \ No newline at end of file diff --git a/YACReaderLibrary.desktop b/YACReaderLibrary.desktop new file mode 100644 index 00000000..75f7a4a3 --- /dev/null +++ b/YACReaderLibrary.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Name=YACReader Library +GenericName=Yet Another Comic Reader - Library +Comment=A comic library management application with server mode. +Exec=YACReaderLibrary %f +Icon=/usr/share/yacreader/iconLibrary.png +Terminal=false +Type=Application +StartupNotify=true +Categories=Graphics;Viewer; +MimeType= +Keywords=comic;library;server; +X-Desktop-File-Install-Version=0.22 diff --git a/YACReaderLibrary/YACReaderLibrary.icns b/YACReaderLibrary/YACReaderLibrary.icns new file mode 100644 index 00000000..30bb0b0d Binary files /dev/null and b/YACReaderLibrary/YACReaderLibrary.icns differ diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro new file mode 100644 index 00000000..2b707b90 --- /dev/null +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -0,0 +1,322 @@ +###################################################################### +# Automatically generated by qmake (2.01a) dom 12. oct 20:47:48 2008 +###################################################################### + +TEMPLATE = app +TARGET = YACReaderLibrary +DEPENDPATH += . +INCLUDEPATH += . +INCLUDEPATH += ../common \ + ./server \ + ./db \ + ../custom_widgets \ + ./comic_vine \ + ./comic_vine/model + +DEFINES += SERVER_RELEASE NOMINMAX YACREADER_LIBRARY + +#load default build flags +include (../config.pri) + +CONFIG(legacy_gl_widget) { + INCLUDEPATH += ../common/gl_legacy \ +} else { + INCLUDEPATH += ../common/gl \ +} + +#there are going to be two builds for windows, OpenGL based and ANGLE based +win32 { + CONFIG(force_angle) { + message("using ANGLE") + LIBS += -L../dependencies/poppler/lib -loleaut32 -lole32 -lshell32 -lopengl32 -lglu32 -luser32 + #linking extra libs are necesary for a successful compilation, a better approach should be + #to remove any OpenGL (desktop) dependencies + #the OpenGL stuff should be migrated to OpenGL ES + DEFINES += FORCE_ANGLE + } else { + LIBS += -L../dependencies/poppler/lib -loleaut32 -lole32 -lshell32 -lopengl32 -lglu32 -luser32 + } + + LIBS += -lpoppler-qt5 + INCLUDEPATH += ../dependencies/poppler/include/qt5 + + QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL + QMAKE_LFLAGS_RELEASE += /LTCG + CONFIG -= embed_manifest_exe +} + +unix:!macx{ + +INCLUDEPATH += /usr/include/poppler/qt5 +LIBS += -L/usr/lib -lpoppler-qt5 + +!CONFIG(no_opengl) { + LIBS += -lGLU + } +} + +macx{ +#INCLUDEPATH += "/Volumes/Mac OS X Lion/usr/X11/include" +#isEqual(QT_MAJOR_VERSION, 5) { +#INCLUDEPATH += /usr/local/include/poppler/qt5 +#LIBS += -L/usr/local/lib -lpoppler-qt5 +#} +#else { +#INCLUDEPATH += /usr/local/include/poppler/qt4 +#LIBS += -L/usr/local/lib -lpoppler-qt4 +#} +#QT += macextras + +LIBS += -framework Foundation -framework ApplicationServices -framework AppKit + +OBJECTIVE_SOURCES += $$PWD/../common/pdf_comic.mm +HEADERS += $$PWD/../common/pdf_comic.h +CONFIG += objective_c +QT += macextras gui-private +} + +unix{ +CONFIG += c++11 +} + +#CONFIG += release +CONFIG -= flat +QT += sql network widgets script +!CONFIG(no_opengl) { + QT += opengl +} + +# Input +HEADERS += comic_flow.h \ + create_library_dialog.h \ + library_creator.h \ + library_window.h \ + add_library_dialog.h \ + rename_library_dialog.h \ + properties_dialog.h \ + options_dialog.h \ + export_library_dialog.h \ + import_library_dialog.h \ + package_manager.h \ + bundle_creator.h \ + export_comics_info_dialog.h \ + import_comics_info_dialog.h \ + server_config_dialog.h \ + comic_flow_widget.h \ + db_helper.h \ + ./db/data_base_management.h \ + ./db/folder_item.h \ + ./db/folder_model.h \ + ./db/comic_model.h \ + ./db/comic_item.h \ + ../common/comic_db.h \ + ../common/folder.h \ + ../common/library_item.h \ + ../common/comic.h \ + ../common/bookmarks.h \ + ../common/pictureflow.h \ + ../common/custom_widgets.h \ + ../common/qnaturalsorting.h \ + ../common/yacreader_global.h \ + ../common/onstart_flow_selection_dialog.h \ + no_libraries_widget.h \ + import_widget.h \ + yacreader_local_server.h \ + yacreader_main_toolbar.h \ + comics_remover.h \ + ../common/http_worker.h \ + yacreader_libraries.h \ + ../common/exit_check.h \ + comics_view.h \ + classic_comics_view.h \ + empty_folder_widget.h \ + no_search_results_widget.h \ + comic_files_manager.h \ + db/reading_list_model.h \ + db/reading_list_item.h \ + yacreader_folders_view.h \ + yacreader_reading_lists_view.h \ + add_label_dialog.h \ + yacreader_history_controller.h \ + yacreader_navigation_controller.h \ + empty_label_widget.h \ + empty_container_info.h \ + empty_special_list.h \ + empty_reading_list_widget.h \ + ../common/scroll_management.h \ + ../common/opengl_checker.h + +!CONFIG(no_opengl) { + CONFIG(legacy_gl_widget) { + message("using legacy YACReaderFlowGL (QGLWidget) header") + HEADERS += ../common/gl_legacy/yacreader_flow_gl.h + } else { + HEADERS += ../common/gl/yacreader_flow_gl.h + } +} + +SOURCES += comic_flow.cpp \ + create_library_dialog.cpp \ + library_creator.cpp \ + library_window.cpp \ + main.cpp \ + add_library_dialog.cpp \ + rename_library_dialog.cpp \ + properties_dialog.cpp \ + options_dialog.cpp \ + export_library_dialog.cpp \ + import_library_dialog.cpp \ + package_manager.cpp \ + bundle_creator.cpp \ + export_comics_info_dialog.cpp \ + import_comics_info_dialog.cpp \ + server_config_dialog.cpp \ + comic_flow_widget.cpp \ + db_helper.cpp \ + ./db/data_base_management.cpp \ + ./db/folder_item.cpp \ + ./db/folder_model.cpp \ + ./db/comic_model.cpp \ + ./db/comic_item.cpp \ + ../common/comic_db.cpp \ + ../common/folder.cpp \ + ../common/library_item.cpp \ + ../common/comic.cpp \ + ../common/bookmarks.cpp \ + ../common/pictureflow.cpp \ + ../common/custom_widgets.cpp \ + ../common/qnaturalsorting.cpp \ + ../common/onstart_flow_selection_dialog.cpp \ + no_libraries_widget.cpp \ + import_widget.cpp \ + yacreader_local_server.cpp \ + yacreader_main_toolbar.cpp \ + comics_remover.cpp \ + ../common/http_worker.cpp \ + ../common/yacreader_global.cpp \ + yacreader_libraries.cpp \ + ../common/exit_check.cpp \ + comics_view.cpp \ + classic_comics_view.cpp \ + empty_folder_widget.cpp \ + no_search_results_widget.cpp \ + comic_files_manager.cpp \ + db/reading_list_model.cpp \ + db/reading_list_item.cpp \ + yacreader_folders_view.cpp \ + yacreader_reading_lists_view.cpp \ + add_label_dialog.cpp \ + yacreader_history_controller.cpp \ + yacreader_navigation_controller.cpp \ + empty_label_widget.cpp \ + empty_container_info.cpp \ + empty_special_list.cpp \ + empty_reading_list_widget.cpp \ + ../common/scroll_management.cpp \ + ../common/opengl_checker.cpp + +!CONFIG(no_opengl) { + CONFIG(legacy_gl_widget) { + message("using legacy YACReaderFlowGL (QGLWidget) source code") + SOURCES += ../common/gl_legacy/yacreader_flow_gl.cpp + } else { + SOURCES += ../common/gl/yacreader_flow_gl.cpp + } +} + + +include(./server/server.pri) +include(../custom_widgets/custom_widgets_yacreaderlibrary.pri) +CONFIG(7zip){ +include(../compressed_archive/wrapper.pri) +} else:CONFIG(unarr) { +include(../compressed_archive/unarr/unarr-wrapper.pri) +} else { + error(No compression backend specified. Did you mess with the build system?) +} + +include(./comic_vine/comic_vine.pri) +include(../QsLog/QsLog.pri) +include(../shortcuts_management/shortcuts_management.pri) + +RESOURCES += images.qrc files.qrc +win32:RESOURCES += images_win.qrc +unix:!macx:RESOURCES += images_win.qrc +macx:RESOURCES += images_osx.qrc + +RC_FILE = icon.rc + +macx { + ICON = YACReaderLibrary.icns +} + +TRANSLATIONS = yacreaderlibrary_es.ts \ + yacreaderlibrary_ru.ts \ + yacreaderlibrary_pt.ts \ + yacreaderlibrary_fr.ts \ + yacreaderlibrary_nl.ts \ + yacreaderlibrary_tr.ts \ + yacreaderlibrary_de.ts \ + yacreaderlibrary_source.ts + +CONFIG(force_angle) { + Release:DESTDIR = ../release_angle + Debug:DESTDIR = ../debug_angle +} else { + Release:DESTDIR = ../release + Debug:DESTDIR = ../debug +} + +#QML/GridView +QT += quick qml + +HEADERS += grid_comics_view.h \ + comics_view_transition.h + +SOURCES += grid_comics_view.cpp \ + comics_view_transition.cpp + +RESOURCES += qml.qrc +win32:RESOURCES += qml_win.qrc +unix:!macx:RESOURCES += qml_win.qrc +macx:RESOURCES += qml_osx.qrc + +unix:!macx { +#set install prefix if it's empty +isEmpty(PREFIX) { + PREFIX = /usr +} + +BINDIR = $$PREFIX/bin +LIBDIR = $$PREFIX/lib +DATADIR = $$PREFIX/share + +DEFINES += "LIBDIR=\\\"$$LIBDIR\\\"" "DATADIR=\\\"$$DATADIR\\\"" "BINDIR=\\\"$$BINDIR\\\"" + +#MAKE INSTALL +INSTALLS += bin icon desktop server translation manpage + +bin.path = $$BINDIR +isEmpty(DESTDIR) { + bin.files = YACReaderLibrary +} else { + bin.files = $$DESTDIR/YACReaderLibrary +} + +server.path = $$DATADIR/yacreader +server.files = ../release/server + +icon.path = $$DATADIR/yacreader +icon.files = ../images/iconLibrary.png ../images/db.png ../images/coversPackage.png + +desktop.path = $$DATADIR/applications +desktop.extra = desktop-file-edit --set-icon=$$DATADIR/yacreader/iconLibrary.png $$PWD/../YACReaderLibrary.desktop +desktop.files = ../YACReaderLibrary.desktop +#TODO: icons should be located at /usr/share/icons and have the same basename as their application + +translation.path = $$DATADIR/yacreader/languages +translation.files = ../release/languages/yacreaderlibrary_* + +manpage.path = $$DATADIR/man/man1 +manpage.files = ../YACReaderLibrary.1 +} diff --git a/YACReaderLibrary/add_label_dialog.cpp b/YACReaderLibrary/add_label_dialog.cpp new file mode 100644 index 00000000..6d9d73b7 --- /dev/null +++ b/YACReaderLibrary/add_label_dialog.cpp @@ -0,0 +1,84 @@ +#include "add_label_dialog.h" + +AddLabelDialog::AddLabelDialog(QWidget *parent) : + QDialog(parent) +{ + QVBoxLayout * layout = new QVBoxLayout; + + layout->addWidget(new QLabel(tr("Label name:"))); + layout->addWidget(edit = new QLineEdit()); + + layout->addWidget(new QLabel(tr("Choose a color:"))); + layout->addWidget(list = new QListWidget() ); + + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_red.png"), tr("red"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_orange.png"), tr("orange"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_yellow.png"), tr("yellow"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_green.png"), tr("green"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_cyan.png"), tr("cyan"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_blue.png"), tr("blue"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_violet.png"), tr("violet"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_purple.png"), tr("purple"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_pink.png"), tr("pink"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_white.png"), tr("white"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_light.png"), tr("light"))); + list->addItem(new QListWidgetItem(QIcon(":/images/lists/label_dark.png"), tr("dark"))); + + QColor backgroundColor = this->palette().background().color(); + list->setStyleSheet(QString("QListWidget {border : none; background-color: rgb(%1,%2,%3);}").arg(backgroundColor.red()).arg(backgroundColor.green()).arg(backgroundColor.blue())); + list->setMinimumHeight(225); + + setModal(true); + + setMinimumHeight(340); + + //buttons + acceptButton = new QPushButton(tr("accept"),this); + cancelButton = new QPushButton(tr("cancel"),this); + + QHBoxLayout * buttons = new QHBoxLayout; + buttons->addStretch(); + buttons->addWidget(acceptButton); + buttons->addWidget(cancelButton); + + layout->addStretch(); + layout->addLayout(buttons); + + setLayout(layout); + + //connections + connect(edit,SIGNAL(textChanged(QString)),this,SLOT(validateName(QString))); + connect(cancelButton,SIGNAL(clicked()),this,SLOT(close())); + connect(acceptButton,SIGNAL(clicked()),this,SLOT(accept())); + +} + +YACReader::LabelColors AddLabelDialog::selectedColor() +{ + return YACReader::LabelColors(list->currentRow()+1); +} + +QString AddLabelDialog::name() +{ + return edit->text(); +} + +int AddLabelDialog::exec() +{ + edit->clear(); + list->clearSelection(); + + acceptButton->setDisabled(true); + + list->setCurrentRow(0); + + return QDialog::exec(); +} + +void AddLabelDialog::validateName(const QString &name) +{ + if(name.isEmpty()) + acceptButton->setDisabled(true); + else + acceptButton->setEnabled(true); +} diff --git a/YACReaderLibrary/add_label_dialog.h b/YACReaderLibrary/add_label_dialog.h new file mode 100644 index 00000000..1f5de48b --- /dev/null +++ b/YACReaderLibrary/add_label_dialog.h @@ -0,0 +1,31 @@ +#ifndef ADD_LABEL_DIALOG_H +#define ADD_LABEL_DIALOG_H + +#include + +#include "yacreader_global.h" + +class AddLabelDialog : public QDialog +{ + Q_OBJECT +public: + explicit AddLabelDialog(QWidget *parent = 0); + YACReader::LabelColors selectedColor(); + QString name(); +signals: + +public slots: + int exec(); + +protected slots: + void validateName(const QString & name); + +protected: + QLineEdit * edit; + QListWidget * list; + + QPushButton * acceptButton; + QPushButton * cancelButton; +}; + +#endif // ADD_LABEL_DIALOG_H diff --git a/YACReaderLibrary/add_library_dialog.cpp b/YACReaderLibrary/add_library_dialog.cpp new file mode 100644 index 00000000..2b7f666b --- /dev/null +++ b/YACReaderLibrary/add_library_dialog.cpp @@ -0,0 +1,124 @@ +#include "add_library_dialog.h" + +#include +#include +#include +#include + + +AddLibraryDialog::AddLibraryDialog(QWidget * parent) +:QDialog(parent) +{ + setupUI(); +} + +void AddLibraryDialog::setupUI() +{ + textLabel = new QLabel(tr("Comics folder : ")); + path = new QLineEdit; + textLabel->setBuddy(path); + connect(path,SIGNAL(textChanged(QString)),this,SLOT(pathSetted(QString))); + + nameLabel = new QLabel(tr("Library Name : ")); + nameEdit = new QLineEdit; + nameLabel->setBuddy(nameEdit); + connect(nameEdit,SIGNAL(textChanged(QString)),this,SLOT(nameSetted(QString))); + + accept = new QPushButton(tr("Add")); + accept->setDisabled(true); + connect(accept,SIGNAL(clicked()),this,SLOT(add())); + + cancel = new QPushButton(tr("Cancel")); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + + find = new QPushButton(QIcon(":/images/find_folder.png"),""); + connect(find,SIGNAL(clicked()),this,SLOT(findPath())); + + QGridLayout * content = new QGridLayout; + + content->addWidget(nameLabel,0,0); + content->addWidget(nameEdit,0,1); + + content->addWidget(textLabel,1,0); + content->addWidget(path,1,1); + content->addWidget(find,1,2); + content->setColumnStretch(2,0); + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(accept); + bottomLayout->addWidget(cancel); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(content); + mainLayout->addStretch(); + mainLayout->addLayout(bottomLayout); + + QHBoxLayout * imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(this); + QPixmap p(":/images/openLibrary.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel);//,0,Qt::AlignTop); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setModal(true); + setWindowTitle(tr("Add an existing library")); +} + +void AddLibraryDialog::add() +{ + //accept->setEnabled(false); + emit(addLibrary(QDir::cleanPath(path->text()),nameEdit->text())); +} + +void AddLibraryDialog::nameSetted(const QString & text) +{ + if(!text.isEmpty()) + { + if(!path->text().isEmpty()) + { + QFileInfo fi(path->text()); + if(fi.isDir()) + accept->setEnabled(true); + else + accept->setEnabled(false); + } + } + else + accept->setEnabled(false); +} + +void AddLibraryDialog::pathSetted(const QString & text) +{ + QFileInfo fi(text); + if(fi.isDir()) + { + if(!nameEdit->text().isEmpty()) + accept->setEnabled(true); + } + else + accept->setEnabled(false); +} + +void AddLibraryDialog::findPath() +{ + QString s = QFileDialog::getExistingDirectory(0,"Comics directory","."); + if(!s.isEmpty()) + { + path->setText(s); + if(!nameEdit->text().isEmpty()) + accept->setEnabled(true); + } + else + accept->setEnabled(false); +} + +void AddLibraryDialog::close() +{ + path->clear(); + nameEdit->clear(); + accept->setEnabled(false); + QDialog::close(); +} diff --git a/YACReaderLibrary/add_library_dialog.h b/YACReaderLibrary/add_library_dialog.h new file mode 100644 index 00000000..4cbdd42b --- /dev/null +++ b/YACReaderLibrary/add_library_dialog.h @@ -0,0 +1,35 @@ +#ifndef __ADD_LIBRARY_DIALOG_H +#define __ADD_LIBRARY_DIALOG_H + +#include +#include +#include +#include +#include + + class AddLibraryDialog : public QDialog + { + Q_OBJECT + public: + AddLibraryDialog(QWidget * parent = 0); + private: + QLabel * nameLabel; + QLabel * textLabel; + QLineEdit * path; + QLineEdit * nameEdit; + QPushButton * find; + QPushButton * accept; + QPushButton * cancel; + void setupUI(); + public slots: + void add(); + void findPath(); + void close(); + void nameSetted(const QString & text); + void pathSetted(const QString & text); + signals: + void addLibrary(QString target, QString name); + }; + +#endif + diff --git a/YACReaderLibrary/bundle_creator.cpp b/YACReaderLibrary/bundle_creator.cpp new file mode 100644 index 00000000..8ea6eef2 --- /dev/null +++ b/YACReaderLibrary/bundle_creator.cpp @@ -0,0 +1,13 @@ +#include "bundle_creator.h" + + +BundleCreator::BundleCreator(void) + :QObject() +{ + +} + + +BundleCreator::~BundleCreator(void) +{ +} diff --git a/YACReaderLibrary/bundle_creator.h b/YACReaderLibrary/bundle_creator.h new file mode 100644 index 00000000..ff4dbd08 --- /dev/null +++ b/YACReaderLibrary/bundle_creator.h @@ -0,0 +1,14 @@ +#ifndef __BUNDLE_CREATOR_H +#define __BUNDLE_CREATOR_H + +#include + +class BundleCreator : public QObject +{ +Q_OBJECT +public: + BundleCreator(void); + ~BundleCreator(void); +}; + +#endif \ No newline at end of file diff --git a/YACReaderLibrary/classic_comics_view.cpp b/YACReaderLibrary/classic_comics_view.cpp new file mode 100644 index 00000000..4d2f5db6 --- /dev/null +++ b/YACReaderLibrary/classic_comics_view.cpp @@ -0,0 +1,337 @@ +#include "classic_comics_view.h" + +#include "yacreader_table_view.h" + +#include "comic_flow_widget.h" +#include "QsLog.h" + +#include "QStackedWidget" + +ClassicComicsView::ClassicComicsView(QWidget *parent) + :ComicsView(parent),searching(false) +{ + QHBoxLayout * layout = new QHBoxLayout; + + settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + settings->beginGroup("libraryConfig"); + //FLOW----------------------------------------------------------------------- + //--------------------------------------------------------------------------- +//FORCE_ANGLE is not used here, because ComicFlowWidgetGL will use OpenGL ES in the future +#ifndef NO_OPENGL + if((settings->value(USE_OPEN_GL).toBool() == true)) + comicFlow = new ComicFlowWidgetGL(0); + else + comicFlow = new ComicFlowWidgetSW(0); +#else + comicFlow = new ComicFlowWidgetSW(0); +#endif + comicFlow->updateConfig(settings); + comicFlow->setFocusPolicy(Qt::StrongFocus); + comicFlow->setShowMarks(true); + setFocusProxy(comicFlow); + + comicFlow->setFocus(Qt::OtherFocusReason); + + comicFlow->setContextMenuPolicy(Qt::CustomContextMenu); + + + //layout----------------------------------------------- + sVertical = new QSplitter(Qt::Vertical); //spliter derecha + + stack = new QStackedWidget; + stack->addWidget(comicFlow); + setupSearchingIcon(); + stack->addWidget(searchingIcon); + + + sVertical->addWidget(stack); + comics = new QWidget; + QVBoxLayout * comicsLayout = new QVBoxLayout; + comicsLayout->setSpacing(0); + comicsLayout->setContentsMargins(0,0,0,0); + //TODO ComicsView:(set toolbar) comicsLayout->addWidget(editInfoToolBar); + + tableView = new YACReaderTableView; + tableView->verticalHeader()->hide(); + tableView->setFocusPolicy(Qt::StrongFocus); + comicsLayout->addWidget(tableView); + comics->setLayout(comicsLayout); + sVertical->addWidget(comics); + + tableView->setContextMenuPolicy(Qt::CustomContextMenu); + + //config-------------------------------------------------- + if(settings->contains(COMICS_VIEW_HEADERS)) + tableView->horizontalHeader()->restoreState(settings->value(COMICS_VIEW_HEADERS).toByteArray()); + + //connections--------------------------------------------- + connect(tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(centerComicFlow(QModelIndex))); + connect(tableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectedComicForOpening(QModelIndex))); + connect(comicFlow, SIGNAL(centerIndexChanged(int)), this, SLOT(updateTableView(int))); + connect(tableView, SIGNAL(comicRated(int,QModelIndex)), this, SIGNAL(comicRated(int,QModelIndex))); + connect(comicFlow, SIGNAL(selected(uint)), this, SIGNAL(selected(uint))); + connect(tableView->horizontalHeader(), SIGNAL(sectionMoved(int,int,int)), this, SLOT(saveTableHeadersStatus())); + connect(tableView->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(saveTableHeadersStatus())); + connect(comicFlow, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(requestedViewContextMenu(QPoint))); + connect(tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(requestedItemContextMenu(QPoint))); + layout->addWidget(sVertical); + setLayout(layout); + + layout->setMargin(0); + +#ifdef Q_OS_MAC + sVertical->setCollapsible(1,false); +#endif + + if(settings->contains(COMICS_VIEW_FLOW_SPLITTER_STATUS)) + sVertical->restoreState(settings->value(COMICS_VIEW_FLOW_SPLITTER_STATUS).toByteArray()); + +} + +void ClassicComicsView::setToolBar(QToolBar *toolBar) +{ + static_cast(comics->layout())->insertWidget(0,toolBar); +} + +void ClassicComicsView::setModel(ComicModel *model) +{ + QLOG_DEBUG() << "Setting model"; + + ComicsView::setModel(model); + + if(model == NULL) + { + comicFlow->clear(); + } + else + { + connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), this, SLOT(applyModelChanges(QModelIndex,QModelIndex,QVector)),Qt::UniqueConnection); + connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(removeItemsFromFlow(QModelIndex,int,int)),Qt::UniqueConnection); + connect(model, SIGNAL(resortedIndexes(QList)),comicFlow,SLOT(resortCovers(QList)),Qt::UniqueConnection); + connect(model, SIGNAL(newSelectedIndex(QModelIndex)),this,SLOT(setCurrentIndex(QModelIndex)),Qt::UniqueConnection); + + tableView->setModel(model); + if(model->rowCount()>0) + tableView->setCurrentIndex(model->index(0,0)); + + tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + #if QT_VERSION >= 0x050000 + tableView->horizontalHeader()->setSectionsMovable(true); + #else + tableView->horizontalHeader()->setMovable(true); + #endif + //TODO parametrizar la configuración de las columnas + /*if(!settings->contains(COMICS_VIEW_HEADERS)) + {*/ + for(int i = 0;ihorizontalHeader()->count();i++) + tableView->horizontalHeader()->hideSection(i); + + tableView->horizontalHeader()->showSection(ComicModel::Number); + tableView->horizontalHeader()->showSection(ComicModel::Title); + tableView->horizontalHeader()->showSection(ComicModel::FileName); + tableView->horizontalHeader()->showSection(ComicModel::NumPages); + tableView->horizontalHeader()->showSection(ComicModel::Hash); //Size is part of the Hash...TODO add Columns::Size to Columns + tableView->horizontalHeader()->showSection(ComicModel::ReadColumn); + tableView->horizontalHeader()->showSection(ComicModel::CurrentPage); + tableView->horizontalHeader()->showSection(ComicModel::Rating); + //} + + //debido a un bug, qt4 no es capaz de ajustar el ancho teniendo en cuenta todas la filas (no sólo las visibles) + //así que se ecala la primera vez y después se deja el control al usuario. + //if(!settings->contains(COMICS_VIEW_HEADERS)) + + + QStringList paths = model->getPaths(model->getCurrentPath());//TODO ComicsView: get currentpath from somewhere currentPath()); + comicFlow->setImagePaths(paths); + comicFlow->setMarks(model->getReadList()); + //comicFlow->setFocus(Qt::OtherFocusReason); + + if(settings->contains(COMICS_VIEW_HEADERS)) + tableView->horizontalHeader()->restoreState(settings->value(COMICS_VIEW_HEADERS).toByteArray()); + + tableView->resizeColumnsToContents(); + + tableView->horizontalHeader()->setStretchLastSection(true); + } +} + +void ClassicComicsView::setCurrentIndex(const QModelIndex &index) +{ + QLOG_INFO() << "*******************************************************ClassicComicsView::setCurrentIndex"; + tableView->setCurrentIndex(index); + centerComicFlow(index); +} + +QModelIndex ClassicComicsView::currentIndex() +{ + return tableView->currentIndex(); +} + +QItemSelectionModel *ClassicComicsView::selectionModel() +{ + return tableView->selectionModel(); +} + +void ClassicComicsView::scrollTo(const QModelIndex & mi, QAbstractItemView::ScrollHint hint) +{ + comicFlow->setCenterIndex(mi.row()); +} + +void ClassicComicsView::toFullScreen() +{ + comicFlow->hide(); + comicFlow->setCenterIndex(comicFlow->centerIndex()); + comics->hide(); + + //showFullScreen() //parent windows + + comicFlow->show(); + comicFlow->setFocus(Qt::OtherFocusReason); +} + +void ClassicComicsView::toNormal() +{ + comicFlow->hide(); + comicFlow->setCenterIndex(comicFlow->centerIndex()); + comicFlow->render(); + comics->show(); + comicFlow->show(); +} + +void ClassicComicsView::updateConfig(QSettings *settings) +{ + comicFlow->updateConfig(settings); +} + +void ClassicComicsView::enableFilterMode(bool enabled) +{ + if(enabled) + { + comicFlow->clear(); + if(previousSplitterStatus.isEmpty()) + previousSplitterStatus = sVertical->saveState(); + sVertical->setSizes(QList () << 100 << 10000000); + showSearchingIcon(); + }else + { + hideSearchingIcon(); + sVertical->restoreState(previousSplitterStatus); + previousSplitterStatus.clear(); + } + + //sVertical->setCollapsible(0,!enabled); + searching = enabled; +} + +void ClassicComicsView::selectIndex(int index) +{ + tableView->selectRow(index); +} + +void ClassicComicsView::selectAll() +{ + tableView->selectAll(); +} + +void ClassicComicsView::selectedComicForOpening(const QModelIndex &mi) +{ + emit selected(mi.row()); +} + +void ClassicComicsView::requestedViewContextMenu(const QPoint &point) +{ + emit customContextMenuViewRequested(comicFlow->mapTo(this, point)); +} + +void ClassicComicsView::requestedItemContextMenu(const QPoint &point) +{ + emit customContextMenuItemRequested(tableView->mapTo(this, point)); +} + +void ClassicComicsView::setShowMarks(bool show) +{ + comicFlow->setShowMarks(show); +} + +void ClassicComicsView::centerComicFlow(const QModelIndex & mi) +{ + comicFlow->showSlide(mi.row()); + comicFlow->setFocus(Qt::OtherFocusReason); +} + +void ClassicComicsView::updateTableView(int i) +{ + QModelIndex mi = model->index(i,2); + tableView->setCurrentIndex(mi); + tableView->scrollTo(mi,QAbstractItemView::EnsureVisible); +} + +void ClassicComicsView::saveTableHeadersStatus() +{ + settings->setValue(COMICS_VIEW_HEADERS,tableView->horizontalHeader()->saveState()); +} + +void ClassicComicsView::saveSplitterStatus() +{ + settingsMutex.lock(); + if(!searching) + settings->setValue(COMICS_VIEW_FLOW_SPLITTER_STATUS, sVertical->saveState()); + settingsMutex.unlock(); +} + +void ClassicComicsView::applyModelChanges(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) +{ + Q_UNUSED(topLeft); + Q_UNUSED(bottomRight); + if(roles.contains(ComicModel::ReadColumnRole)) + { + comicFlow->setMarks(model->getReadList()); + comicFlow->updateMarks(); + } +} + +void ClassicComicsView::removeItemsFromFlow(const QModelIndex &parent, int from, int to) +{ + Q_UNUSED(parent); + for(int i = from; i<=to; i++) + comicFlow->remove(i); +} + +void ClassicComicsView::closeEvent(QCloseEvent *event) +{ + saveTableHeadersStatus(); + saveSplitterStatus(); + ComicsView::closeEvent(event); +} + +void ClassicComicsView::setupSearchingIcon() +{ + searchingIcon = new QWidget(comicFlow); + + QHBoxLayout * h = new QHBoxLayout; + + QPixmap p(":/images/searching_icon.png"); + QLabel * l = new QLabel(searchingIcon); + l->setPixmap(p); + l->setFixedSize(p.size()); + h->addWidget(l,0,Qt::AlignCenter); + searchingIcon->setLayout(h); + + QPalette pal(searchingIcon->palette()); + pal.setColor(QPalette::Background, Qt::black); + searchingIcon->setAutoFillBackground(true); + searchingIcon->setPalette(pal); + + hideSearchingIcon(); +} + +void ClassicComicsView::showSearchingIcon() +{ + stack->setCurrentWidget(searchingIcon); +} + +void ClassicComicsView::hideSearchingIcon() +{ + stack->setCurrentWidget(comicFlow); +} + diff --git a/YACReaderLibrary/classic_comics_view.h b/YACReaderLibrary/classic_comics_view.h new file mode 100644 index 00000000..16c5a59b --- /dev/null +++ b/YACReaderLibrary/classic_comics_view.h @@ -0,0 +1,71 @@ +#ifndef CLASSIC_COMICS_VIEW_H +#define CLASSIC_COMICS_VIEW_H + +#include "comics_view.h" + +#include +#include + +class YACReaderTableView; +class QSplitter; +class ComicFlowWidget; +class QToolBar; +class ComicModel; +class QStackedWidget; + +class ClassicComicsView : public ComicsView +{ + Q_OBJECT +public: + ClassicComicsView(QWidget *parent = 0); + void setToolBar(QToolBar * toolBar); + void setModel(ComicModel *model); + + QModelIndex currentIndex(); + QItemSelectionModel * selectionModel(); + void scrollTo(const QModelIndex & mi, QAbstractItemView::ScrollHint hint ); + void toFullScreen(); + void toNormal(); + void updateConfig(QSettings * settings); + void enableFilterMode(bool enabled); + void selectIndex(int index); + +public slots: + void setCurrentIndex(const QModelIndex &index); + void centerComicFlow(const QModelIndex & mi); + void updateTableView(int i); + void saveTableHeadersStatus(); + void saveSplitterStatus(); + void applyModelChanges(const QModelIndex & topLeft,const QModelIndex & bottomRight,const QVector & roles); + void removeItemsFromFlow(const QModelIndex & parent, int from, int to); + //ComicsView + void setShowMarks(bool show); + void selectAll(); + void selectedComicForOpening(const QModelIndex & mi); + +protected slots: + void requestedViewContextMenu(const QPoint & point); + void requestedItemContextMenu(const QPoint & point); + +private: + YACReaderTableView * tableView; + QWidget *comics; + QSplitter * sVertical; + ComicFlowWidget * comicFlow; + QSettings * settings; + void closeEvent ( QCloseEvent * event ); + + QStackedWidget * stack; + + QByteArray previousSplitterStatus; + QWidget * searchingIcon; + bool searching; + void setupSearchingIcon(); + void showSearchingIcon(); + void hideSearchingIcon(); + void updateSearchingIconPosition(); + + QMutex settingsMutex; +}; + +#endif // CLASSIC_COMICS_VIEW_H diff --git a/YACReaderLibrary/comic_files_manager.cpp b/YACReaderLibrary/comic_files_manager.cpp new file mode 100644 index 00000000..50f2b81d --- /dev/null +++ b/YACReaderLibrary/comic_files_manager.cpp @@ -0,0 +1,108 @@ +#include "comic_files_manager.h" +#include +#include +#include + +#include + +#include "comic.h" + +ComicFilesManager::ComicFilesManager(QObject *parent) : + QObject(parent), canceled(false) +{ +} + +void ComicFilesManager::copyComicsTo(const QList > &sourceComics, const QString &folderDest, const QModelIndex & dest) +{ + comics = sourceComics; + folder = folderDest; + folderDestinationModelIndex = dest; + move = false; +} + +void ComicFilesManager::moveComicsTo(const QList > &sourceComics, const QString &folderDest, const QModelIndex &dest) +{ + comics = sourceComics; + folder = folderDest; + folderDestinationModelIndex = dest; + move = true; +} + +QList > ComicFilesManager::getDroppedFiles(const QList &urls) +{ + QList > dropedFiles; + + QString currentPath; + foreach(QUrl url, urls) + { + currentPath = url.toLocalFile(); + if(currentPath.endsWith('/')) + currentPath = currentPath.remove(currentPath.length()-1,1); //QTBUG-35896 QUrl.toLocalFile inconsistency. + if(Comic::fileIsComic(currentPath)) + dropedFiles << QPair(currentPath,"/"); + else + { + QLOG_DEBUG() << "XXXXXXXXXXXX :" << currentPath; + QFileInfo info(currentPath); + if(info.isDir()) + { + QLOG_DEBUG() << "origin path prior to absoluteFilePath : " << info.absolutePath(); + foreach(QString comicPath, Comic::findValidComicFilesInFolder(info.absoluteFilePath())) + { + QFileInfo comicInfo(comicPath); + QString path = comicInfo.absolutePath(); + QLOG_DEBUG() << "comic path : " << comicPath; + QLOG_DEBUG() << "full comic path : " << path; + QLOG_DEBUG() << "origin path : " << info.absolutePath(); + dropedFiles << QPair(comicPath, path.remove(info.absolutePath())); + } + } + } + } + + return dropedFiles; +} + +void ComicFilesManager::process() +{ + int i=0; + bool successProcesingFiles = false; + QPair source; + foreach (source, comics) { + + if(canceled) + { + if(successProcesingFiles) + emit success(folderDestinationModelIndex); + emit finished(); + + return; //TODO rollback? + } + + QFileInfo info(source.first); + QString destPath = QDir::cleanPath(folder+'/'+source.second); + QLOG_DEBUG() << "crear : " << destPath; + QDir().mkpath(destPath); + if(QFile::copy(source.first, QDir::cleanPath(destPath+'/'+info.fileName()))) + { + successProcesingFiles = true; + if(move) + { + QFile::remove(source.first); //TODO: remove the whole path.... + } + } + + i++; + emit progress(i); + } + + if(successProcesingFiles) + emit success(folderDestinationModelIndex); + emit finished(); +} + +void ComicFilesManager::cancel() +{ + QLOG_DEBUG() << "Operation canceled"; + canceled = true; +} diff --git a/YACReaderLibrary/comic_files_manager.h b/YACReaderLibrary/comic_files_manager.h new file mode 100644 index 00000000..a6b54060 --- /dev/null +++ b/YACReaderLibrary/comic_files_manager.h @@ -0,0 +1,37 @@ +#ifndef COMIC_FILES_MANAGER_H +#define COMIC_FILES_MANAGER_H + +#include +#include +#include +#include + + +//this class is intended to work in background, just use moveToThread and process to start working +class ComicFilesManager : public QObject +{ + Q_OBJECT +public: + explicit ComicFilesManager(QObject *parent = 0); + void copyComicsTo(const QList > & sourceComics, const QString & folderDest, const QModelIndex &dest); + void moveComicsTo(const QList > & comics, const QString & folderDest, const QModelIndex &dest); + static QList > getDroppedFiles(const QList & urls); +signals: + void currentComic(QString); + void progress(int); + void finished(); + void success(QModelIndex); //at least one comics has been copied or moved +public slots: + void process(); + void cancel(); + +protected: + bool move; + bool canceled; + QList > comics; + QString folder; + QModelIndex folderDestinationModelIndex; + +}; + +#endif // COMIC_FILES_MANAGER_H diff --git a/YACReaderLibrary/comic_flow.cpp b/YACReaderLibrary/comic_flow.cpp new file mode 100644 index 00000000..730687b4 --- /dev/null +++ b/YACReaderLibrary/comic_flow.cpp @@ -0,0 +1,265 @@ +#include "comic_flow.h" +#include "qnaturalsorting.h" + +#include "yacreader_global.h" + +#include + +#include +#include +#include + +ComicFlow::ComicFlow(QWidget* parent,FlowType flowType) +:YACReaderFlow(parent,flowType) +{ + updateTimer = new QTimer; + connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateImageData())); + + worker = new ImageLoader; + connect(this, SIGNAL(centerIndexChanged(int)), this, SLOT(preload())); + connect(this, SIGNAL(centerIndexChangedSilent(int)), this, SLOT(preload())); + + setReflectionEffect(PlainReflection); +} + +ComicFlow::~ComicFlow() +{ + worker->terminate(); + delete worker; + delete updateTimer; +} + +void ComicFlow::setImagePaths(const QStringList& paths) +{ + clear(); + + //imagePath = path; + imageFiles = paths; + imagesLoaded.clear(); + imagesLoaded.fill(false,imageFiles.size()); + numImagesLoaded = 0; + + imagesSetted.clear(); + imagesSetted.fill(false,imageFiles.size()); + + // populate with empty images + QImage img; //TODO remove + QString s; + for(int i = 0; i < (int)imageFiles.size(); i++) + { + addSlide(img); + s = imageFiles.at(i); + s.remove(s.size()-4,4); + if(QFileInfo(s+".r").exists()) + markSlide(i); + } + + setCenterIndex(0); + worker->reset(); + preload(); +} + +void ComicFlow::preload() +{ + if(numImagesLoaded < imagesLoaded.size()) + updateTimer->start(30); //TODO comprobar rendimiento, originalmente era 70 +} + +void ComicFlow::updateImageData() +{ + // can't do anything, wait for the next possibility + if(worker->busy()) + return; + + // set image of last one + int idx = worker->index(); + if( idx >= 0 && !worker->result().isNull()) + { + if(!imagesSetted[idx]) + { + setSlide(idx, worker->result()); + imagesSetted[idx] = true; + numImagesLoaded++; + imagesLoaded[idx]=true; + } + } + + // try to load only few images on the left and right side + // i.e. all visible ones plus some extra +#define COUNT 8 + int indexes[2*COUNT+1]; + int center = centerIndex(); + indexes[0] = center; + for(int j = 0; j < COUNT; j++) + { + indexes[j*2+1] = center+j+1; + indexes[j*2+2] = center-j-1; + } + for(int c = 0; c < 2*COUNT+1; c++) + { + int i = indexes[c]; + if((i >= 0) && (i < slideCount())) + if(!imagesLoaded[i])//slide(i).isNull()) + { + // schedule thumbnail generation + QString fname = imageFiles[i]; + + + worker->generate(i, fname, slideSize()); + return; + } + } + + // no need to generate anything? stop polling... + updateTimer->stop(); +} + +void ComicFlow::keyPressEvent(QKeyEvent* event) +{ + PictureFlow::keyPressEvent(event); +} + +void ComicFlow::wheelEvent(QWheelEvent * event) +{ + if(event->delta()<0) + showNext(); + else + showPrevious(); + event->accept(); +} + +void ComicFlow::removeSlide(int cover) +{ + worker->lock(); + + worker->reset(); + + imageFiles.removeAt(cover); + if(imagesLoaded[cover]) + numImagesLoaded--; + imagesLoaded.remove(cover); + imagesSetted.remove(cover); + + YACReaderFlow::removeSlide(cover); + worker->unlock(); + + preload(); +} + +void ComicFlow::resortCovers(QList newOrder) +{ + worker->lock(); + worker->reset(); + + YACReaderFlow::resortCovers(newOrder); + + QStringList imageFilesNew; + QVector imagesLoadedNew; + QVector imagesSettedNew; + foreach(int index, newOrder) + { + imageFilesNew << imageFiles.at(index); + imagesLoadedNew << imagesLoaded.at(index); + imagesSettedNew << imagesSetted.at(index); + } + + + + imageFiles = imageFilesNew; + imagesLoaded = imagesLoadedNew; + imagesSetted = imagesSettedNew; + + worker->unlock(); +} +//----------------------------------------------------------------------------- +//ImageLoader +//----------------------------------------------------------------------------- +static QImage loadImage(const QString& fileName) +{ + QImage image; + bool result = image.load(fileName); + + if(!result) + return QImage(); + + return image; +} + +ImageLoader::ImageLoader(): +QThread(), restart(false), working(false), idx(-1) +{ +} + +ImageLoader::~ImageLoader() +{ + mutex.lock(); + condition.wakeOne(); + mutex.unlock(); + wait(); +} + +bool ImageLoader::busy() const +{ + return isRunning() ? working : false; +} + +void ImageLoader::generate(int index, const QString& fileName, QSize size) +{ + mutex.lock(); + this->idx = index; + this->fileName = fileName; + this->size = size; + this->img = QImage(); + mutex.unlock(); + + if (!isRunning()) + start(); + else + { + // already running, wake up whenever ready + restart = true; + condition.wakeOne(); + } +} + +void ImageLoader::lock() +{ + mutex.lock(); +} + +void ImageLoader::unlock() +{ + mutex.unlock(); +} + +void ImageLoader::run() +{ + for(;;) + { + // copy necessary data + mutex.lock(); + this->working = true; + QString fileName = this->fileName; + mutex.unlock(); + + QImage image = loadImage(fileName); + + // let everyone knows it is ready + mutex.lock(); + this->working = false; + this->img = image; + mutex.unlock(); + + // put to sleep + mutex.lock(); + if (!this->restart) + condition.wait(&mutex); + restart = false; + mutex.unlock(); + } +} + +QImage ImageLoader::result() +{ + return img; +} diff --git a/YACReaderLibrary/comic_flow.h b/YACReaderLibrary/comic_flow.h new file mode 100644 index 00000000..c49543b3 --- /dev/null +++ b/YACReaderLibrary/comic_flow.h @@ -0,0 +1,78 @@ +#ifndef __COMICFLOW_H +#define __COMICFLOW_H + +#include "yacreader_flow.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +class ImageLoader; +class ComicFlow : public YACReaderFlow +{ + Q_OBJECT +public: + ComicFlow(QWidget* parent = 0,FlowType flowType = CoverFlowLike); + virtual ~ComicFlow(); + + void setImagePaths(const QStringList& paths); + //bool eventFilter(QObject *target, QEvent *event); + void keyPressEvent(QKeyEvent* event); + void removeSlide(int cover); + void resortCovers(QList newOrder); + +private slots: + void preload(); + void updateImageData(); + +private: + //QString imagePath; + QStringList imageFiles; + QVector imagesLoaded; + QVector imagesSetted; + int numImagesLoaded; + QTimer* updateTimer; + ImageLoader* worker; + virtual void wheelEvent(QWheelEvent * event); +}; + + +//----------------------------------------------------------------------------- +// Source code of ImageLoader class was modified from http://code.google.com/p/photoflow/ +//------------------------------------------------------------------------------ +class ImageLoader : public QThread +{ +public: + ImageLoader(); + ~ImageLoader(); + // returns FALSE if worker is still busy and can't take the task + bool busy() const; + void generate(int index, const QString& fileName, QSize size); + void reset(){idx = -1;}; + int index() const { return idx; }; + void lock(); + void unlock(); + QImage result(); + +protected: + void run(); + +private: + QMutex mutex; + QWaitCondition condition; + + bool restart; + bool working; + int idx; + QString fileName; + QSize size; + QImage img; +}; + + +#endif diff --git a/YACReaderLibrary/comic_flow_widget.cpp b/YACReaderLibrary/comic_flow_widget.cpp new file mode 100644 index 00000000..e4326abc --- /dev/null +++ b/YACReaderLibrary/comic_flow_widget.cpp @@ -0,0 +1,355 @@ +#include "comic_flow_widget.h" +#include +ComicFlowWidget::ComicFlowWidget(QWidget * parent) + :QWidget(parent) +{ + +} + +ComicFlowWidgetSW::ComicFlowWidgetSW(QWidget * parent) + :ComicFlowWidget(parent) +{ + flow = new ComicFlow(parent); + + connect(flow,SIGNAL(centerIndexChanged(int)),this,SIGNAL(centerIndexChanged(int))); + connect(flow,SIGNAL(selected(unsigned int)),this,SIGNAL(selected(unsigned int))); + + QVBoxLayout * l = new QVBoxLayout; + l->addWidget(flow); + setLayout(l); + + //TODO eleminar "padding" + QPalette Pal(palette()); + // set black background + Pal.setColor(QPalette::Background, Qt::black); + setAutoFillBackground(true); + setPalette(Pal); + + //config + QMatrix m; + m.rotate(-90); + m.scale(-1,1); + QImage image(":/images/setRead.png"); + QImage imageTransformed = image.transformed(m,Qt::SmoothTransformation); + setMarkImage(imageTransformed); +} + +QSize ComicFlowWidgetSW::minimumSizeHint() const +{ + return flow->minimumSizeHint(); +} +QSize ComicFlowWidgetSW::sizeHint() const +{ + return flow->sizeHint(); +} + +void ComicFlowWidgetSW::setShowMarks(bool value) +{ + flow->setShowMarks(value); +} +void ComicFlowWidgetSW::setMarks(QVector marks) +{ + flow->setMarks(marks); +} +void ComicFlowWidgetSW::setMarkImage(QImage & image) +{ + flow->setMarkImage(image); +} +void ComicFlowWidgetSW::markSlide(int index, YACReaderComicReadStatus status) +{ + flow->markSlide(index,status); +} +void ComicFlowWidgetSW::unmarkSlide(int index) +{ + flow->unmarkSlide(index); +} +void ComicFlowWidgetSW::setSlideSize(QSize size) +{ + flow->setSlideSize(size); +} +void ComicFlowWidgetSW::clear() +{ + flow->clear(); +} +void ComicFlowWidgetSW::setImagePaths(QStringList paths) +{ + flow->setImagePaths(paths); +} +void ComicFlowWidgetSW::setCenterIndex(int index) +{ + flow->setCenterIndex(index); +} +void ComicFlowWidgetSW::showSlide(int index) +{ + flow->showSlide(index); +} +int ComicFlowWidgetSW::centerIndex() +{ + return flow->centerIndex(); +} +void ComicFlowWidgetSW::updateMarks() +{ + flow->updateMarks(); +} +void ComicFlowWidgetSW::setFlowType(FlowType flowType) +{ + flow->setFlowType(flowType); +} +void ComicFlowWidgetSW::render() +{ + flow->render(); +} +void ComicFlowWidgetSW::keyPressEvent(QKeyEvent* event) +{ + flow->keyPressEvent(event); +} +void ComicFlowWidgetSW::paintEvent(QPaintEvent *event) +{ + flow->paintEvent(event); +} +void ComicFlowWidgetSW::mousePressEvent(QMouseEvent* event) +{ + flow->mousePressEvent(event); +} +void ComicFlowWidgetSW::resizeEvent(QResizeEvent* event) +{ + flow->resizeEvent(event); +} +void ComicFlowWidgetSW::mouseDoubleClickEvent(QMouseEvent* event) +{ + flow->mouseDoubleClickEvent(event); +} +void ComicFlowWidgetSW::updateConfig(QSettings * settings) +{ + switch (settings->value(FLOW_TYPE_SW).toInt()) + { + case CoverFlowLike: + flow->setFlowType(CoverFlowLike); + return; + case Strip: + flow->setFlowType(Strip); + return; + case StripOverlapped: + flow->setFlowType(StripOverlapped); + return; + } +} + +void ComicFlowWidgetSW::remove(int cover) +{ + flow->removeSlide(cover); +} + +void ComicFlowWidgetSW::resortCovers(QList newOrder) +{ + flow->resortCovers(newOrder); +} + +#ifndef NO_OPENGL +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +///OpenGL ComicFlow +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +ComicFlowWidgetGL::ComicFlowWidgetGL(QWidget * parent) + :ComicFlowWidget(parent) +{ + flow = new YACReaderComicFlowGL(parent); + + connect(flow,SIGNAL(centerIndexChanged(int)),this,SIGNAL(centerIndexChanged(int))); + connect(flow,SIGNAL(selected(unsigned int)),this,SIGNAL(selected(unsigned int))); + + QVBoxLayout * l = new QVBoxLayout; + l->addWidget(flow); + l->setContentsMargins(0,0,0,0); + setLayout(l); + + //TODO eleminar "padding" + QPalette Pal(palette()); + // set black background + Pal.setColor(QPalette::Background, Qt::black); + setAutoFillBackground(true); + setPalette(Pal); +} + +QSize ComicFlowWidgetGL::minimumSizeHint() const +{ + return flow->minimumSizeHint(); +} +QSize ComicFlowWidgetGL::sizeHint() const +{ + return flow->sizeHint(); +} + +void ComicFlowWidgetGL::setShowMarks(bool value) +{ + flow->setShowMarks(value); +} +void ComicFlowWidgetGL::setMarks(QVector marks) +{ + flow->setMarks(marks); +} +void ComicFlowWidgetGL::setMarkImage(QImage & image) +{ + flow->setMarkImage(image); +} +void ComicFlowWidgetGL::markSlide(int index, YACReaderComicReadStatus status) +{ + flow->markSlide(index,status); +} +void ComicFlowWidgetGL::unmarkSlide(int index) +{ + flow->unmarkSlide(index); +} +void ComicFlowWidgetGL::setSlideSize(QSize size) +{ + flow->setSlideSize(size); +} +void ComicFlowWidgetGL::clear() +{ + flow->clear(); +} +void ComicFlowWidgetGL::setImagePaths(QStringList paths) +{ + flow->setImagePaths(paths); +} +void ComicFlowWidgetGL::setCenterIndex(int index) +{ + flow->setCenterIndex(index); +} +void ComicFlowWidgetGL::showSlide(int index) +{ + flow->showSlide(index); +} +int ComicFlowWidgetGL::centerIndex() +{ + return flow->centerIndex(); +} +void ComicFlowWidgetGL::updateMarks() +{ + flow->updateMarks(); +} +void ComicFlowWidgetGL::setFlowType(FlowType flowType) +{ + if(flowType == CoverFlowLike) + flow->setPreset(presetYACReaderFlowClassicConfig); + else if(flowType == Strip) + flow->setPreset(presetYACReaderFlowStripeConfig); + else if(flowType == StripOverlapped) + flow->setPreset(presetYACReaderFlowOverlappedStripeConfig); + else + flow->setPreset(defaultYACReaderFlowConfig); +} +void ComicFlowWidgetGL::render() +{ + flow->render(); +} +void ComicFlowWidgetGL::keyPressEvent(QKeyEvent* event) +{ + flow->keyPressEvent(event); +} +void ComicFlowWidgetGL::paintEvent(QPaintEvent *event) +{ + //flow->paintEvent(event); + ComicFlowWidget::paintEvent(event); +} +void ComicFlowWidgetGL::mousePressEvent(QMouseEvent* event) +{ + flow->mousePressEvent(event); +} +void ComicFlowWidgetGL::resizeEvent(QResizeEvent* event) +{ + flow->resizeGL(event->size().width(),event->size().height()); +} +void ComicFlowWidgetGL::mouseDoubleClickEvent(QMouseEvent* event) +{ + flow->mouseDoubleClickEvent(event); +} + +void ComicFlowWidgetGL::updateConfig(QSettings * settings) +{ + Performance performance = medium; + + switch (settings->value(PERFORMANCE).toInt()) + { + case 0: + performance = low; + break; + case 1: + performance = medium; + break; + case 2: + performance = high; + break; + case 3: + performance = ultraHigh; + break; + } + + flow->setPerformance(performance); + if(!settings->contains(V_SYNC)) + flow->useVSync(false); + else + flow->useVSync(settings->value(V_SYNC).toBool()); + + switch (settings->value(FLOW_TYPE_GL).toInt()) + { + case 0: + flow->setPreset(presetYACReaderFlowClassicConfig); + return; + case 1: + flow->setPreset(presetYACReaderFlowStripeConfig); + return; + case 2: + flow->setPreset(presetYACReaderFlowOverlappedStripeConfig); + return; + case 3: + flow->setPreset(defaultYACReaderFlowConfig); + return; + case 4: + flow->setPreset(pressetYACReaderFlowDownConfig); + return; + } + + + //custom config + + flow->setCF_RX(settings->value(X_ROTATION).toInt()); + flow->setCF_Y(settings->value(Y_POSITION).toInt()); + flow->setX_Distance(settings->value(COVER_DISTANCE).toInt()); + flow->setCenter_Distance(settings->value(CENTRAL_DISTANCE).toInt()); + flow->setCF_Z(settings->value(ZOOM_LEVEL).toInt()); + flow->setY_Distance(settings->value(Y_COVER_OFFSET).toInt()); + flow->setZ_Distance(settings->value(Z_COVER_OFFSET).toInt()); + flow->setRotation(settings->value(COVER_ROTATION).toInt()); + flow->setFadeOutDist(settings->value(FADE_OUT_DIST).toInt()); + flow->setLightStrenght(settings->value(LIGHT_STRENGTH).toInt()); + flow->setMaxAngle(settings->value(MAX_ANGLE).toInt()); + +/* flow->setVisibility(settings->value("visibilityDistance").toInt()); + flow->setLightStrenght(settings->value("lightStrength").toInt())*/; + +} + +void ComicFlowWidgetGL::remove(int cover) +{ + flow->remove(cover); +} + +void ComicFlowWidgetGL::resortCovers(QList newOrder) +{ + flow->resortCovers(newOrder); +} +#endif +//void ComicFlowWidgetGL::setCF_RX(int value){ flow->setCF_RX(value);} +//void ComicFlowWidgetGL::setCF_RY(int value){ flow->setCF_RY(value);} +//void ComicFlowWidgetGL::setCF_RZ(int value){ flow->setCF_RZ(value);} +//void ComicFlowWidgetGL::setZoom(int zoom){ flow->setZoom(zoom);} +//void ComicFlowWidgetGL::setRotation(int angle){ flow->setRotation(angle);} +//void ComicFlowWidgetGL::setX_Distance(int distance){ flow->setX_Distance(distance);} +//void ComicFlowWidgetGL::setCenter_Distance(int distance){ flow->setCenter_Distance(distance);} +//void ComicFlowWidgetGL::setZ_Distance(int distance){ flow->setZ_Distance(distance);} +//void ComicFlowWidgetGL::setCF_Y(int value){ flow->setCF_Y(value);} +//void ComicFlowWidgetGL::setY_Distance(int value){ flow->setY_Distance(value);} +//void ComicFlowWidgetGL::setPreset(const Preset & p){ flow->setPreset(p);} diff --git a/YACReaderLibrary/comic_flow_widget.h b/YACReaderLibrary/comic_flow_widget.h new file mode 100644 index 00000000..10f68486 --- /dev/null +++ b/YACReaderLibrary/comic_flow_widget.h @@ -0,0 +1,133 @@ +#ifndef __COMIC_FLOW_WIDGET_H +#define __COMIC_FLOW_WIDGET_H + + +#include + +#include "pictureflow.h" +#include "comic_flow.h" +#ifndef NO_OPENGL +#include "yacreader_flow_gl.h" +#endif +class ComicFlowWidget : public QWidget +{ + Q_OBJECT +public: + ComicFlowWidget(QWidget * paret = 0); + +public slots: + virtual void setShowMarks(bool value) = 0; + virtual void setMarks(QVector marks) = 0; + virtual void setMarkImage(QImage & image) = 0; + virtual void markSlide(int index, YACReaderComicReadStatus status) = 0; + virtual void unmarkSlide(int index) = 0; + virtual void setSlideSize(QSize size) = 0; + virtual void clear() = 0; + virtual void setImagePaths(QStringList paths) = 0; + virtual void setCenterIndex(int index) = 0; + virtual void showSlide(int index) = 0; + virtual int centerIndex() = 0; + virtual void updateMarks() = 0; + virtual void setFlowType(FlowType flowType) = 0; + virtual void render() = 0; + virtual void updateConfig(QSettings * settings) = 0; + virtual void remove(int cover) = 0; + virtual void resortCovers(QList newOrder) = 0; +signals: + void centerIndexChanged(int); + void selected(unsigned int); +}; + + +class ComicFlowWidgetSW : public ComicFlowWidget +{ + Q_OBJECT +private: + ComicFlow * flow; +public: + ComicFlowWidgetSW(QWidget * parent = 0); + + void setShowMarks(bool value); + void setMarks(QVector marks); + void setMarkImage(QImage & image); + void markSlide(int index, YACReaderComicReadStatus status); + void unmarkSlide(int index); + void setSlideSize(QSize size); + void clear(); + void setImagePaths(QStringList paths); + void setCenterIndex(int index); + void showSlide(int index); + int centerIndex(); + void updateMarks(); + void setFlowType(FlowType flowType); + void render(); + void updateConfig(QSettings * settings); + void remove(int cover); + void resortCovers(QList newOrder); +protected: + void keyPressEvent(QKeyEvent* event); + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent* event); + void resizeEvent(QResizeEvent* event); + void mouseDoubleClickEvent(QMouseEvent* event); + QSize minimumSizeHint() const; + QSize sizeHint() const; + QSize slideSizeW; + QSize slideSizeF; +}; + +#ifndef NO_OPENGL +class ComicFlowWidgetGL : public ComicFlowWidget +{ + Q_OBJECT +private: + YACReaderComicFlowGL * flow; +public: + ComicFlowWidgetGL(QWidget * parent = 0); + + void setShowMarks(bool value); + void setMarks(QVector marks); + void setMarkImage(QImage & image); + void markSlide(int index, YACReaderComicReadStatus status); + void unmarkSlide(int index); + void setSlideSize(QSize size); + void clear(); + void setImagePaths(QStringList paths); + void setCenterIndex(int index); + void showSlide(int index); + int centerIndex(); + void updateMarks(); + void setFlowType(FlowType flowType); + void render(); + void updateConfig(QSettings * settings); + void remove(int cover); + void resortCovers(QList newOrder); +//public slots: +// void setCF_RX(int value); +// //the Y Rotation of the Coverflow +// void setCF_RY(int value); +// //the Z Rotation of the Coverflow +// void setCF_RZ(int value); +// //perspective +// void setZoom(int zoom); +// void setRotation(int angle); +// //sets the distance between the covers +// void setX_Distance(int distance); +// //sets the distance between the centered and the non centered covers +// void setCenter_Distance(int distance); +// //sets the pushback amount +// void setZ_Distance(int distance); +// void setCF_Y(int value); +// void setY_Distance(int value); +// void setPreset(const Preset & p); +protected: + void keyPressEvent(QKeyEvent* event); + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent* event); + void resizeEvent(QResizeEvent* event); + void mouseDoubleClickEvent(QMouseEvent* event); + QSize minimumSizeHint() const; + QSize sizeHint() const; +}; +#endif +#endif diff --git a/YACReaderLibrary/comic_vine/api_key_dialog.cpp b/YACReaderLibrary/comic_vine/api_key_dialog.cpp new file mode 100644 index 00000000..355ecd0e --- /dev/null +++ b/YACReaderLibrary/comic_vine/api_key_dialog.cpp @@ -0,0 +1,68 @@ +#include "api_key_dialog.h" + +#include +#include +#include +#include +#include +#include + +#include "yacreader_global.h" + +ApiKeyDialog::ApiKeyDialog(QWidget *parent) : + QDialog(parent) +{ + QVBoxLayout * layout = new QVBoxLayout; + QHBoxLayout * buttonsLayout = new QHBoxLayout; + + settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + settings->beginGroup("ComicVine"); + + QLabel * info = new QLabel(tr("Before you can connect to Comic Vine, you need your own API key. Please, get one free here")); + info->setWordWrap(true); + info->setOpenExternalLinks(true); + edit = new QLineEdit(); + edit->setPlaceholderText(tr("Paste here your Comic Vine API key")); + connect(edit,SIGNAL(textChanged(QString)),this,SLOT(enableAccept(QString))); + + acceptButton = new QPushButton(tr("Accept")); + acceptButton->setDisabled(true); + connect(acceptButton,SIGNAL(clicked()),this,SLOT(saveApiKey())); + + cancelButton = new QPushButton(tr("Cancel")); + connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject())); + + layout->addWidget(info); + layout->addWidget(edit); + layout->addStretch(); + + buttonsLayout->addStretch(); + buttonsLayout->addWidget(acceptButton); + buttonsLayout->addWidget(cancelButton); + + layout->addLayout(buttonsLayout); + + setLayout(layout); + + resize(400,150); + + if(settings->contains(COMIC_VINE_API_KEY)) + edit->setText(settings->value(COMIC_VINE_API_KEY).toString()); +} + +ApiKeyDialog::~ApiKeyDialog() +{ + delete settings; +} + +void ApiKeyDialog::enableAccept(const QString &text) +{ + //TODO key validation + acceptButton->setEnabled(!text.isEmpty()); +} + +void ApiKeyDialog::saveApiKey() +{ + settings->setValue(COMIC_VINE_API_KEY,edit->text()); + accept(); +} diff --git a/YACReaderLibrary/comic_vine/api_key_dialog.h b/YACReaderLibrary/comic_vine/api_key_dialog.h new file mode 100644 index 00000000..13ff5750 --- /dev/null +++ b/YACReaderLibrary/comic_vine/api_key_dialog.h @@ -0,0 +1,31 @@ +#ifndef API_KEY_DIALOG_H +#define API_KEY_DIALOG_H + +#include + +class QPushButton; +class QLineEdit; +class QSettings; + +class ApiKeyDialog : public QDialog +{ + Q_OBJECT +public: + explicit ApiKeyDialog(QWidget *parent = 0); + ~ApiKeyDialog(); +signals: + +public slots: + +protected slots: + void enableAccept(const QString & text); + void saveApiKey(); + +protected: + QPushButton * acceptButton; + QPushButton * cancelButton; + QLineEdit * edit; + QSettings * settings; +}; + +#endif // API_KEY_DIALOG_H diff --git a/YACReaderLibrary/comic_vine/comic_vine.pri b/YACReaderLibrary/comic_vine/comic_vine.pri new file mode 100644 index 00000000..c76c0acc --- /dev/null +++ b/YACReaderLibrary/comic_vine/comic_vine.pri @@ -0,0 +1,46 @@ + +HEADERS += \ + comic_vine/comic_vine_dialog.h \ + comic_vine/comic_vine_client.h \ + comic_vine/scraper_lineedit.h \ + comic_vine/title_header.h \ + comic_vine/series_question.h \ + comic_vine/search_single_comic.h \ + comic_vine/search_volume.h \ + comic_vine/select_comic.h \ + comic_vine/select_volume.h \ + comic_vine/model/volumes_model.h \ + comic_vine/model/comics_model.h \ + comic_vine/model/json_model.h \ + comic_vine/model/response_parser.h \ + comic_vine/scraper_tableview.h \ + comic_vine/sort_volume_comics.h \ + comic_vine/model/local_comic_list_model.h \ + comic_vine/model/volume_comics_model.h \ + comic_vine/scraper_scroll_label.h \ + comic_vine/scraper_results_paginator.h \ + comic_vine/scraper_selector.h \ + comic_vine/api_key_dialog.h + +SOURCES += \ + comic_vine/comic_vine_dialog.cpp \ + comic_vine/comic_vine_client.cpp \ + comic_vine/scraper_lineedit.cpp \ + comic_vine/title_header.cpp \ + comic_vine/series_question.cpp \ + comic_vine/search_single_comic.cpp \ + comic_vine/search_volume.cpp \ + comic_vine/select_comic.cpp \ + comic_vine/select_volume.cpp \ + comic_vine/model/volumes_model.cpp \ + comic_vine/model/comics_model.cpp \ + comic_vine/model/json_model.cpp \ + comic_vine/model/response_parser.cpp \ + comic_vine/scraper_tableview.cpp \ + comic_vine/sort_volume_comics.cpp \ + comic_vine/model/local_comic_list_model.cpp \ + comic_vine/model/volume_comics_model.cpp \ + comic_vine/scraper_scroll_label.cpp \ + comic_vine/scraper_results_paginator.cpp \ + comic_vine/scraper_selector.cpp \ + comic_vine/api_key_dialog.cpp diff --git a/YACReaderLibrary/comic_vine/comic_vine_client.cpp b/YACReaderLibrary/comic_vine/comic_vine_client.cpp new file mode 100644 index 00000000..cb36d3ca --- /dev/null +++ b/YACReaderLibrary/comic_vine/comic_vine_client.cpp @@ -0,0 +1,171 @@ +#include "comic_vine_client.h" + +//this is the API key used by YACReader to access Comic Vine +//please, do not use it in your own software, get one for free at Comic Vine +static const QString CV_API_KEY = "%CV_API_KEY%"; //get from settings +static const QString CV_API_KEY_DEFAULT = "46680bebb358f1de690a5a365e15d325f9649f91"; + +static const QString CV_WEB_ADDRESS = "http://www.comicvine.com/api"; + +//gets any volumen containing any comic matching 'query' +static const QString CV_SEARCH = CV_WEB_ADDRESS + "/search/?api_key=" + CV_API_KEY + + "&format=json&limit=100&resources=volume" + "&field_list=name,start_year,publisher,id,image,count_of_issues,deck" + "&sort=name:asc" + "&query=%1&page=%2"; +//http://www.comicvine.com/api/search/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=json&limit=100&resources=volume&field_list=name,start_year,publisher,id,image,count_of_issues,deck&query=superman + +//gets the detail for a volume %1 +static const QString CV_SERIES_DETAIL = CV_WEB_ADDRESS + "/volume/4050-%1/?api_key=" + CV_API_KEY + + "&format=json&field_list=name,start_year,publisher,image,count_of_issues,id,description"; + +//gets info for comics in a volume id %1 +static const QString CV_COMICS_INFO = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API_KEY + + "&format=json&field_list=name,issue_number,id,image&filter=volume:%1" + "&sort=cover_date:asc" //sorting by cover_date, because comic vine doesn't use natural sorting (issue_number -> 1 10 11 ... 100 2 20 21....) + "&offset=%2"; + +//"http://www.comicvine.com/api/issues/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=json&field_list=name,issue_number,id,image&filter=volume:%1&page=%2 + +//gets id for comic number %2 in a volume id %1 +static const QString CV_COMIC_ID = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API_KEY + + "&format=json&field_list=name,issue_number,id,image" + "&filter=volume:%1,issue_number:%2"; +//gets comic detail +static const QString CV_COMIC_DETAIL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=json"; +//http://www.comicvine.com/api/issue/4000-%1/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=json + +//gets comic cover URL +static const QString CV_COVER_URL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=json&field_list=image"; + +//gets comics matching name %1 and number %2 +//http://comicvine.com/api/issues/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&limit=20&filter=name:super,issue_number:15 + +ComicVineClient::ComicVineClient(QObject *parent) : + QObject(parent) +{ + settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + settings->beginGroup("ComicVine"); +} + +ComicVineClient::~ComicVineClient() +{ + delete settings; +} + +//CV_SEARCH +void ComicVineClient::search(const QString & query, int page) +{ + HttpWorker * search = new HttpWorker(QString(CV_SEARCH).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(query).arg(page)); + connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessVolumesSearchData(const QByteArray &))); + connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); + connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); + search->get(); +} +//CV_SEARCH result +void ComicVineClient::proccessVolumesSearchData(const QByteArray & data) +{ + QString json(data); + emit searchResult(json); + emit finished(); +} + +void ComicVineClient::proccessSeriesDetailData(const QByteArray &data) +{ + QString json(data); + emit seriesDetail(json); + emit finished(); +} + +void ComicVineClient::processVolumeComicsInfo(const QByteArray &data) +{ + QString json(data); + emit volumeComicsInfo(json); + emit finished(); +} + +void ComicVineClient::proccessComicDetailData(const QByteArray &data) +{ + QString json(data); + emit comicDetail(json); + emit finished(); +} + +//CV_SERIES_DETAIL +void ComicVineClient::getSeriesDetail(const QString & id) +{ + HttpWorker * search = new HttpWorker(QString(CV_SERIES_DETAIL).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(id)); + connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessSeriesDetailData(const QByteArray &))); + connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); + connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); + search->get(); +} + +void ComicVineClient::getSeriesCover(const QString & url) +{ + HttpWorker * search = new HttpWorker(url); + connect(search,SIGNAL(dataReady(const QByteArray &)),this,SIGNAL(seriesCover(const QByteArray &))); + connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); //TODO + connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); + search->get(); +} + +//CV_COMIC_IDS +void ComicVineClient::getVolumeComicsInfo(const QString & idVolume, int page) +{ + HttpWorker * search = new HttpWorker(QString(CV_COMICS_INFO).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(idVolume).arg((page-1)*100)); //page on works for search, using offset instead + connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(processVolumeComicsInfo(const QByteArray &))); + connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); //TODO + connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); + search->get(); +} + +//CV_COMIC_ID +void ComicVineClient::getComicId(const QString & id, int comicNumber) +{ + +} + +//CV_COMIC_DETAIL +QByteArray ComicVineClient::getComicDetail(const QString & id, bool & outError, bool & outTimeout) +{ + HttpWorker * search = new HttpWorker(QString(CV_COMIC_DETAIL).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(id)); + + //connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessComicDetailData(const QByteArray &))); + //connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); + //connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); + search->get(); + search->wait(); + outError = !(search->wasValid()); + outTimeout = search->wasTimeout(); + QByteArray result = search->getResult(); + delete search; + + return result; +} + +//CV_COMIC_DETAIL +void ComicVineClient::getComicDetailAsync(const QString & id) +{ + HttpWorker * search = new HttpWorker(QString(CV_COMIC_DETAIL).replace(CV_API_KEY,settings->value(COMIC_VINE_API_KEY,CV_API_KEY_DEFAULT).toString()).arg(id)); + + connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessComicDetailData(const QByteArray &))); + connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); + connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); + search->get(); +} + +void ComicVineClient::getComicCover(const QString &url) +{ + HttpWorker * search = new HttpWorker(url); + connect(search,SIGNAL(dataReady(const QByteArray &)),this,SIGNAL(comicCover(QByteArray))); + connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut())); //TODO + connect(search,SIGNAL(finished()),search,SLOT(deleteLater())); + search->get(); +} + +//CV_COVER_DETAIL +void ComicVineClient::getCoverURL(const QString & id) +{ + +} diff --git a/YACReaderLibrary/comic_vine/comic_vine_client.h b/YACReaderLibrary/comic_vine/comic_vine_client.h new file mode 100644 index 00000000..f5fbc44c --- /dev/null +++ b/YACReaderLibrary/comic_vine/comic_vine_client.h @@ -0,0 +1,46 @@ +#ifndef COMIC_VINE_CLIENT_H +#define COMIC_VINE_CLIENT_H + +#include "http_worker.h" + +#include +#include + +class ComicVineClient : public QObject +{ + Q_OBJECT +public: + explicit ComicVineClient(QObject *parent = 0); + ~ComicVineClient(); + +signals: + void searchResult(QString); + void seriesDetail(QString);//JSON + void comicDetail(QString);//JSON + void seriesCover(const QByteArray &); + void comicCover(const QByteArray &); + void volumeComicsInfo(QString); + void timeOut(); + void finished(); +public slots: + void search(const QString & query, int page = 1); + void getSeriesDetail(const QString & id); + void getSeriesCover(const QString & url); + void getVolumeComicsInfo(const QString & idVolume, int page=1); + QByteArray getComicDetail(const QString & id, bool &outError, bool &outTimeout); + void getComicCover(const QString & url); + + void getComicId(const QString & id, int comicNumber); + void getCoverURL(const QString & id); + void getComicDetailAsync(const QString &id); +protected slots: + void proccessVolumesSearchData(const QByteArray & data); + void proccessSeriesDetailData(const QByteArray & data); + void processVolumeComicsInfo(const QByteArray & data); + void proccessComicDetailData(const QByteArray & data); + +protected: + QSettings * settings; + +}; +#endif // COMIC_VINE_CLIENT_H diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp new file mode 100644 index 00000000..fcfea60b --- /dev/null +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.cpp @@ -0,0 +1,722 @@ +#include "comic_vine_dialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#if QT_VERSION >= 0x050000 + #include +#else + #include +#endif +#include +#include +#include "data_base_management.h" + +#include "yacreader_busy_widget.h" +#include "comic_vine_client.h" +#include "scraper_lineedit.h" +#include "title_header.h" +#include "series_question.h" +#include "search_single_comic.h" +#include "search_volume.h" +#include "select_comic.h" +#include "select_volume.h" +#include "sort_volume_comics.h" +#include "db_helper.h" +#include "response_parser.h" + +#include "QsLog.h" + + + +ComicVineDialog::ComicVineDialog(QWidget *parent) : + QDialog(parent) +{ + doLayout(); + doStackedWidgets(); + doConnections(); +} + +void ComicVineDialog::doLayout() +{ + setStyleSheet("" + "QDialog {background-color: #404040; }" + ""); + + QString dialogButtonsStyleSheet = "QPushButton {border: 1px solid #242424; background: #2e2e2e; color:white; padding: 5px 26px 5px 26px; font-size:12px;font-family:Arial; font-weight:bold;}"; + + skipButton = new QPushButton(tr("skip")); + backButton = new QPushButton(tr("back")); + nextButton = new QPushButton(tr("next")); + searchButton = new QPushButton(tr("search")); + closeButton = new QPushButton(tr("close")); + + skipButton->setStyleSheet(dialogButtonsStyleSheet); + backButton->setStyleSheet(dialogButtonsStyleSheet); + nextButton->setStyleSheet(dialogButtonsStyleSheet); + searchButton->setStyleSheet(dialogButtonsStyleSheet); + closeButton->setStyleSheet(dialogButtonsStyleSheet); + + content = new QStackedWidget(this); + + QVBoxLayout * mainLayout = new QVBoxLayout; + + QHBoxLayout * buttonLayout = new QHBoxLayout; + + buttonLayout->addStretch(); + buttonLayout->addWidget(skipButton); + buttonLayout->addWidget(backButton); + buttonLayout->addWidget(nextButton); + buttonLayout->addWidget(searchButton); + buttonLayout->addWidget(closeButton); + buttonLayout->setContentsMargins(0,0,0,0); + + mainLayout->addWidget(titleHeader = new TitleHeader); + mainLayout->addWidget(content); + mainLayout->addStretch(); + mainLayout->addLayout(buttonLayout); + + mainLayout->setContentsMargins(26,16,26,11); + + setLayout(mainLayout); + setFixedSize(872,529); + + setWindowTitle("Comic Vine Scraper (beta)"); +} + +void ComicVineDialog::doStackedWidgets() +{ + doLoading(); + content->addWidget(seriesQuestionWidget = new SeriesQuestion); + content->addWidget(searchSingleComicWidget = new SearchSingleComic); + content->addWidget(searchVolumeWidget = new SearchVolume); + content->addWidget(selectVolumeWidget = new SelectVolume); + content->addWidget(selectComicWidget = new SelectComic); + content->addWidget(sortVolumeComicsWidget = new SortVolumeComics); +} + +void ComicVineDialog::doConnections() +{ + connect(closeButton,SIGNAL(clicked()),this,SLOT(close())); + connect(nextButton,SIGNAL(clicked()),this,SLOT(goNext())); + connect(backButton,SIGNAL(clicked()),this,SLOT(goBack())); + connect(searchButton,SIGNAL(clicked()),this,SLOT(search())); + connect(skipButton,SIGNAL(clicked()),this,SLOT(goToNextComic())); + + connect(selectVolumeWidget,SIGNAL(loadPage(QString,int)),this,SLOT(searchVolume(QString,int))); + connect(selectComicWidget,SIGNAL(loadPage(QString,int)),this,SLOT(getVolumeComicsInfo(QString,int))); + connect(sortVolumeComicsWidget,SIGNAL(loadPage(QString,int)),this,SLOT(getVolumeComicsInfo(QString,int))); +} + +void ComicVineDialog::goNext() +{ + // + if(content->currentWidget() == seriesQuestionWidget) + { + if(seriesQuestionWidget->getYes()) + { + QString volumeSearchString = comics[0].getParentFolderName(); + mode = Volume; + + if(volumeSearchString.isEmpty()) + showSearchVolume(); + else + { + status = AutoSearching; + showLoading(tr("Looking for volume...")); + searchVolume(volumeSearchString); + } + } + else + { + status = AutoSearching; + mode = SingleComicInList; + ComicDB comic = comics[currentIndex]; + QString title = comic.getTitleOrFileName(); + titleHeader->setSubTitle(tr("comic %1 of %2 - %3").arg(currentIndex+1).arg(comics.length()).arg(title)); + + showLoading(tr("Looking for volume...")); + searchVolume(title); + } + } + else if (content->currentWidget() == selectVolumeWidget) { + currentVolumeId = selectVolumeWidget->getSelectedVolumeId(); + getVolumeComicsInfo(currentVolumeId); + + } else if (content->currentWidget() == sortVolumeComicsWidget) { + showLoading(); + + //ComicDB-ComicVineID + QList > matchingInfo = sortVolumeComicsWidget->getMatchingInfo(); + int count = selectVolumeWidget->getSelectedVolumeNumIssues(); + QString publisher = selectVolumeWidget->getSelectedVolumePublisher(); + QtConcurrent::run(this, &ComicVineDialog::getComicsInfo,matchingInfo,count,publisher); + } else if (content->currentWidget() == selectComicWidget) + { + showLoading(); + QString comicId = selectComicWidget->getSelectedComicId(); + int count = selectVolumeWidget->getSelectedVolumeNumIssues(); + QString publisher = selectVolumeWidget->getSelectedVolumePublisher(); + QtConcurrent::run(this, &ComicVineDialog::getComicInfo,comicId,count,publisher); + } +} + +void ComicVineDialog::goBack() +{ + switch (status) { + case SelectingSeries: + if(mode == Volume) + showSearchVolume(); + else + showSearchSingleComic(); + break; + case SortingComics: + showSelectVolume(); + break; + case SelectingComic: + if(mode == SingleComic) + showSelectVolume(); + break; + case AutoSearching: + if(mode == Volume) + showSearchVolume(); + else + showSearchSingleComic(); + default: + if(mode == Volume) + showSearchVolume(); + else + showSearchSingleComic(); + break; + } +} + +void ComicVineDialog::setComics(const QList & comics) +{ + this->comics = comics; +} + +void ComicVineDialog::show() +{ + QDialog::show(); + + currentIndex = 0; + + seriesQuestionWidget->setYes(true); + searchSingleComicWidget->clean(); + searchVolumeWidget->clean(); + + if(comics.length() == 1) + { + status = AutoSearching; + mode = SingleComic; + + ComicDB singleComic = comics[0]; + QString title = singleComic.getTitleOrFileName(); + titleHeader->setSubTitle(title); + showLoading(tr("Looking for volume...")); + + searchVolume(singleComic.getParentFolderName()); + QLOG_TRACE() << singleComic.getParentFolderName(); + }else if(comics.length()>1) + { + titleHeader->setSubTitle(tr("%1 comics selected").arg(comics.length())); + showSeriesQuestion(); + } +} + +void ComicVineDialog::doLoading() +{ + QWidget * w = new QWidget; + QVBoxLayout * l = new QVBoxLayout; + + YACReaderBusyWidget * bw = new YACReaderBusyWidget; + loadingMessage = new QLabel; + + loadingMessage->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + + l->addStretch(); + l->addWidget(bw,0,Qt::AlignHCenter); + l->addStretch(); + l->addWidget(loadingMessage); + + + l->setContentsMargins(0,0,0,0); + w->setLayout(l); + w->setContentsMargins(0,0,0,0); + + content->addWidget(w); +} + +void ComicVineDialog::debugClientResults(const QString & string) +{ + ResponseParser p; + p.loadJSONResponse(string); + //QMessageBox::information(0,"Result", QString("Number of results : %1").arg(p.getNumResults())); + if(p.responseError()) + { + QMessageBox::critical(0,tr("Error connecting to ComicVine"), p.errorDescription()); + goBack(); + } + else + { + switch(mode) + { + case SingleComic: case SingleComicInList: + if(p.getNumResults() == 0) + showSearchSingleComic(); + else + if(status == SearchingVolume) + showSelectVolume(string); + else + showSelectComic(string); + break; + case Volume: + if(p.getNumResults() == 0) + showSearchVolume(); + else + showSelectVolume(string); + break; + } + } +} + +void ComicVineDialog::showSeriesQuestion() +{ + status = AskingForInfo; + content->setCurrentWidget(seriesQuestionWidget); + backButton->setHidden(true); + skipButton->setHidden(true); + nextButton->setVisible(true); + searchButton->setHidden(true); + closeButton->setVisible(true); + + if(mode == SingleComicInList) + skipButton->setVisible(true); + else + skipButton->setHidden(true); +} + +void ComicVineDialog::showSearchSingleComic() +{ + status = AskingForInfo; + content->setCurrentWidget(searchSingleComicWidget); + backButton->setHidden(true); + skipButton->setHidden(true); + nextButton->setHidden(true); + searchButton->setVisible(true); + closeButton->setVisible(true); + + if(mode == SingleComicInList) + skipButton->setVisible(true); + else + skipButton->setHidden(true); +} + +void ComicVineDialog::showSearchVolume() +{ + status = AskingForInfo; + content->setCurrentWidget(searchVolumeWidget); + backButton->setHidden(true); + nextButton->setHidden(true); + searchButton->setVisible(true); + closeButton->setVisible(true); + toggleSkipButton(); +} + +void ComicVineDialog::showSelectVolume(const QString & json) +{ + showSelectVolume(); + selectVolumeWidget->load(json,currentVolumeSearchString); +} + +void ComicVineDialog::showSelectVolume() +{ + status = SelectingSeries; + + content->setCurrentWidget(selectVolumeWidget); + + backButton->setVisible(true); + nextButton->setVisible(true); + searchButton->setHidden(true); + closeButton->setVisible(true); + toggleSkipButton(); +} + +void ComicVineDialog::showSelectComic(const QString &json) +{ + status = SelectingComic; + + content->setCurrentWidget(selectComicWidget); + selectComicWidget->load(json,currentVolumeId); + + backButton->setVisible(true); + nextButton->setVisible(true); + searchButton->setHidden(true); + closeButton->setVisible(true); + toggleSkipButton(); +} + +void ComicVineDialog::showSortVolumeComics(const QString &json) +{ + status = SortingComics; + + content->setCurrentWidget(sortVolumeComicsWidget); + + sortVolumeComicsWidget->setData(comics, json, currentVolumeId); + + backButton->setVisible(true); + nextButton->setVisible(true); + searchButton->setHidden(true); + closeButton->setVisible(true); + toggleSkipButton(); +} + +void ComicVineDialog::queryTimeOut() +{ + QMessageBox::warning(this,"Comic Vine error", "Time out connecting to Comic Vine"); + + switch (status) { + case AutoSearching: + if(mode == Volume) + showSearchVolume(); + else + showSearchSingleComic(); + break; + case SearchingVolume: + if(mode == Volume) + showSearchVolume(); + else + showSearchSingleComic(); + break; + case SearchingSingleComic: + showSearchSingleComic(); + break; + case GettingVolumeComics: + showSelectVolume(); + break; + default: + break; + } +} + +void ComicVineDialog::getComicsInfo(QList > & matchingInfo, int count,const QString & publisher) +{ + QPair p; + QList comics; + foreach (p, matchingInfo) { + ComicVineClient * comicVineClient = new ComicVineClient; + //connect(comicVineClient,SIGNAL(searchResult(QString)),this,SLOT(debugClientResults(QString))); + //connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut())); + //connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater())); + bool error; + bool timeout; + QByteArray result = comicVineClient->getComicDetail(p.second,error,timeout); //TODO check timeOut or Connection error + if(error || timeout) + continue; //TODO + ComicDB comic = parseComicInfo(p.first,result,count,publisher);//TODO check result error + comic.info.comicVineID = p.second; + comics.push_back(comic); + + setLoadingMessage(tr("Retrieving tags for : %1").arg(p.first.getFileName())); + } + + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + db.open(); + db.transaction(); + foreach(ComicDB comic, comics) + { + DBHelper::update(&(comic.info),db); + } + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(databasePath); + + close(); + emit accepted(); +} + +void ComicVineDialog::getComicInfo(const QString &comicId, int count, const QString &publisher) +{ + + ComicVineClient * comicVineClient = new ComicVineClient; + bool error; + bool timeout; + QByteArray result = comicVineClient->getComicDetail(comicId,error,timeout); //TODO check timeOut or Connection error + if(error || timeout) + { + //TODO + if(mode == SingleComic || currentIndex == (comics.count()-1)) + { + close(); + emit accepted(); + } else + { + goToNextComic(); + } + } + + ComicDB comic = parseComicInfo(comics[currentIndex],result,count,publisher); //TODO check result error + comic.info.comicVineID = comicId; + setLoadingMessage(tr("Retrieving tags for : %1").arg(comics[currentIndex].getFileName())); + + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + db.open(); + db.transaction(); + + DBHelper::update(&(comic.info),db); + + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(databasePath); + + if(mode == SingleComic || currentIndex == (comics.count()-1)) + { + close(); + emit accepted(); + } else + { + goToNextComic(); + } +} + +ComicDB ComicVineDialog::parseComicInfo(ComicDB & comic, const QString & json, int count, const QString & publisher) +{ + QScriptEngine engine; + QScriptValue sc; + sc = engine.evaluate("(" + json + ")"); + + if (!sc.property("error").isValid() && sc.property("error").toString() != "OK") + { + qDebug("Error detected"); + } + else + { + int numResults = sc.property("number_of_total_results").toString().toInt(); //fix to weird behaviour using hasNext + + if(numResults > 0) + { + QScriptValue result = sc.property("results"); + + QString title = result.property("name").toString(); + + QString number = result.property("issue_number").toString(); + //QString count; //get from select volume + + + QString volume = result.property("volume").property("name").toString(); + QString storyArc; //story_arc + QString arcNumber; //?? + QString arcCount; //count_of_issue_appearances -> NO + + QString genere; //no + + QMap authors = getAuthors(result.property("person_credits")); + + QString writer = QStringList(authors.values("writer")).join("\n"); + QString penciller = QStringList(authors.values("penciller")).join("\n"); + QString inker = QStringList(authors.values("inker")).join("\n"); + QString colorist = QStringList(authors.values("colorist")).join("\n"); + QString letterer = QStringList(authors.values("letterer")).join("\n"); + QString coverArtist = QStringList(authors.values("cover")).join("\n"); + + QString date = result.property("cover_date").toString(); + + //QString publisher; //get from select volume + QString format; //no + bool color; //no + QString ageRating; //no + + QString synopsis = result.property("description").toString().remove(QRegExp("<[^>]*>")); //description + QString characters = getCharacters(result.property("character_credits")); + + comic.info.title = title; + + comic.info.number = number; + comic.info.count = count; + + comic.info.writer = writer; + comic.info.penciller = penciller; + comic.info.inker = inker; + comic.info.colorist = colorist; + comic.info.letterer = letterer; + comic.info.coverArtist = coverArtist; + + QStringList tempList = date.split("-"); + std::reverse(tempList.begin(),tempList.end()); + comic.info.date = tempList.join("/"); + comic.info.volume = volume; + + comic.info.publisher = publisher; + + comic.info.synopsis = synopsis; + comic.info.characters = characters; + } + } + return comic; +} + +QString ComicVineDialog::getCharacters(const QScriptValue &json_characters) +{ + QString characters; + + QScriptValueIterator it(json_characters); + QScriptValue resultsValue; + while (it.hasNext()) { + it.next(); + if(it.flags() & QScriptValue::SkipInEnumeration) + continue; + resultsValue = it.value(); + + characters += resultsValue.property("name").toString() + "\n"; + } + + return characters; +} + +QMap ComicVineDialog::getAuthors(const QScriptValue &json_authors) +{ + QMap authors; + + QScriptValueIterator it(json_authors); + QScriptValue resultsValue; + while (it.hasNext()) { + it.next(); + if(it.flags() & QScriptValue::SkipInEnumeration) + continue; + resultsValue = it.value(); + + QString authorName = resultsValue.property("name").toString(); + + QStringList roles = resultsValue.property("role").toString().split(","); + foreach(QString role, roles) + { + if(role.trimmed() == "writer") + authors.insertMulti("writer",authorName); + else if(role.trimmed() == "inker") + authors.insertMulti("inker",authorName); + else if(role.trimmed() == "penciler" || role.trimmed() == "penciller") + authors.insertMulti("penciller",authorName); + else if(role.trimmed() == "colorist") + authors.insertMulti("colorist",authorName); + else if(role.trimmed() == "letterer") + authors.insertMulti("letterer",authorName); + else if(role.trimmed() == "cover") + authors.insertMulti("cover",authorName); + } + } + + return authors; +} + +void ComicVineDialog::toggleSkipButton() +{ + if (mode == SingleComicInList) + skipButton->setVisible(true); + else + skipButton->setHidden(true); +} + +void ComicVineDialog::goToNextComic() +{ + if(mode == SingleComic || currentIndex == (comics.count()-1)) + { + close(); + emit accepted(); + return; + } + + currentIndex++; + + showSearchSingleComic(); + + ComicDB comic = comics[currentIndex]; + QString title = comic.getTitleOrFileName(); + titleHeader->setSubTitle(tr("comic %1 of %2 - %3").arg(currentIndex+1).arg(comics.length()).arg(title)); +} + +void ComicVineDialog::showLoading(const QString &message) +{ + content->setCurrentIndex(0); + loadingMessage->setText(message); + backButton->setHidden(true); + skipButton->setHidden(true); + nextButton->setHidden(true); + searchButton->setHidden(true); + closeButton->setVisible(true); +} + +void ComicVineDialog::setLoadingMessage(const QString &message) +{ + loadingMessage->setText(message); +} + +void ComicVineDialog::search() +{ + switch (mode) { + case Volume: + launchSearchVolume(); + break; + default: + launchSearchComic(); + break; + } +} + +void ComicVineDialog::searchVolume(const QString &v, int page) +{ + showLoading(tr("Looking for volume...")); + + currentVolumeSearchString = v; + + ComicVineClient * comicVineClient = new ComicVineClient; + connect(comicVineClient,SIGNAL(searchResult(QString)),this,SLOT(debugClientResults(QString))); + connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut())); + connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater())); + comicVineClient->search(v,page); + + status = SearchingVolume; +} + +void ComicVineDialog::getVolumeComicsInfo(const QString &vID, int page) +{ + showLoading(tr("Retrieving volume info...")); + + status = GettingVolumeComics; + + ComicVineClient * comicVineClient = new ComicVineClient; + if(mode == Volume) + connect(comicVineClient,SIGNAL(volumeComicsInfo(QString)),this,SLOT(showSortVolumeComics(QString))); + else + connect(comicVineClient,SIGNAL(volumeComicsInfo(QString)),this,SLOT(showSelectComic(QString))); + connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut())); + connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater())); + + QLOG_TRACE() << vID; + + comicVineClient->getVolumeComicsInfo(vID,page); +} + +void ComicVineDialog::launchSearchVolume() +{ + showLoading(tr("Looking for volume...")); + //TODO: check if volume info is empty. + searchVolume(searchVolumeWidget->getVolumeInfo()); +} + +void ComicVineDialog::launchSearchComic() +{ + showLoading(tr("Looking for comic...")); + + QString volumeInfo = searchSingleComicWidget->getVolumeInfo(); + //QString comicInfo = searchSingleComicWidget->getComicInfo(); + //int comicNumber = searchSingleComicWidget->getComicNumber(); + + //if(comicInfo.isEmpty() && comicNumber == -1) + searchVolume(volumeInfo); +} + diff --git a/YACReaderLibrary/comic_vine/comic_vine_dialog.h b/YACReaderLibrary/comic_vine/comic_vine_dialog.h new file mode 100644 index 00000000..6474afa1 --- /dev/null +++ b/YACReaderLibrary/comic_vine/comic_vine_dialog.h @@ -0,0 +1,130 @@ +#ifndef COMIC_VINE_DIALOG_H +#define COMIC_VINE_DIALOG_H + +#include + +#include "comic_db.h" + +class QPushButton; +class QStackedWidget; +class QLabel; +class QRadioButton; +class ComicVineClient; +class QTableView; +class TitleHeader; +class SeriesQuestion; +class SearchSingleComic; +class SearchVolume; +class SelectComic; +class SelectVolume; +class SortVolumeComics; +class QScriptValue; + +//TODO this should use a QStateMachine +//---------------------------------------- +class ComicVineDialog : public QDialog +{ + Q_OBJECT +public: + explicit ComicVineDialog(QWidget *parent = 0); + QString databasePath; + QString basePath; + void setComics(const QList & comics); + + +signals: + +public slots: + void show(); + +protected slots: + void goNext(); + void goBack(); + void debugClientResults(const QString & string); + //show widget methods + void showSeriesQuestion(); + void showSearchSingleComic(); + void showSearchVolume(); + void showLoading(const QString & message = ""); + void search(); + void searchVolume(const QString & v, int page = 1); + void getVolumeComicsInfo(const QString &vID, int page = 1); + void launchSearchVolume(); + void launchSearchComic(); + void showSelectVolume(const QString & json); + void showSelectVolume(); + void showSelectComic(const QString & json); + void showSortVolumeComics(const QString & json); + void queryTimeOut(); + void getComicsInfo(QList > & matchingInfo, int count, const QString & publisher); + void getComicInfo(const QString & comicId, int count, const QString & publisher); + ComicDB parseComicInfo(ComicDB &comic, const QString & json, int count, const QString &publisher); + void setLoadingMessage(const QString &message); + void goToNextComic(); + +private: + + QString getCharacters(const QScriptValue & json_characters); + QMap getAuthors(const QScriptValue & json_authors); + + void toggleSkipButton(); + + enum ScraperMode + { + SingleComic, //the scraper has been opened for a single comic + Volume, //the scraper is trying to get comics info for a whole volume + SingleComicInList //the scraper has been opened for a list of unrelated comics + }; + + enum ScraperStatus + { + AutoSearching, + AskingForInfo, + SelectingComic, + SelectingSeries, + SearchingSingleComic, + SearchingVolume, + SortingComics, + GettingVolumeComics + }; + + ScraperMode mode; + ScraperStatus status; + + int currentIndex; + + TitleHeader * titleHeader; + + QPushButton * skipButton; + QPushButton * backButton; + QPushButton * nextButton; + QPushButton * searchButton; + QPushButton * closeButton; + + //stacked widgets + QStackedWidget * content; + + QWidget * infoNotFound; + QWidget * singleComicBrowser; + + QLabel * loadingMessage; + + void doLayout(); + void doStackedWidgets(); + void doLoading(); + void doConnections(); + + QList comics; + + SeriesQuestion * seriesQuestionWidget; + SearchSingleComic * searchSingleComicWidget; + SearchVolume * searchVolumeWidget; + SelectVolume * selectVolumeWidget; + SelectComic * selectComicWidget; + SortVolumeComics * sortVolumeComicsWidget; + + QString currentVolumeSearchString; + QString currentVolumeId; +}; + +#endif // COMIC_VINE_DIALOG_H diff --git a/YACReaderLibrary/comic_vine/model/comics_model.cpp b/YACReaderLibrary/comic_vine/model/comics_model.cpp new file mode 100644 index 00000000..5b194f24 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/comics_model.cpp @@ -0,0 +1,6 @@ +#include "comics_model.h" + +ComicsModel::ComicsModel(QObject *parent) : + JSONModel(parent) +{ +} diff --git a/YACReaderLibrary/comic_vine/model/comics_model.h b/YACReaderLibrary/comic_vine/model/comics_model.h new file mode 100644 index 00000000..86bfb2e5 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/comics_model.h @@ -0,0 +1,18 @@ +#ifndef COMICS_MODEL_H +#define COMICS_MODEL_H + +#include "json_model.h" + +class ComicsModel : public JSONModel +{ + Q_OBJECT +public: + explicit ComicsModel(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // COMICS_MODEL_H diff --git a/YACReaderLibrary/comic_vine/model/json_model.cpp b/YACReaderLibrary/comic_vine/model/json_model.cpp new file mode 100644 index 00000000..d0c4ce41 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/json_model.cpp @@ -0,0 +1,6 @@ +#include "json_model.h" + +JSONModel::JSONModel(QObject *parent) : + QAbstractItemModel(parent) +{ +} diff --git a/YACReaderLibrary/comic_vine/model/json_model.h b/YACReaderLibrary/comic_vine/model/json_model.h new file mode 100644 index 00000000..443e9a20 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/json_model.h @@ -0,0 +1,19 @@ +#ifndef JSON_MODEL_H +#define JSON_MODEL_H + +#include + +class JSONModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit JSONModel(QObject *parent = 0); + virtual void load(const QString & json) = 0 ; + +signals: + +public slots: + +}; + +#endif // JSON_MODEL_H diff --git a/YACReaderLibrary/comic_vine/model/local_comic_list_model.cpp b/YACReaderLibrary/comic_vine/model/local_comic_list_model.cpp new file mode 100644 index 00000000..861e61f1 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/local_comic_list_model.cpp @@ -0,0 +1,183 @@ +#include "local_comic_list_model.h" + +LocalComicListModel::LocalComicListModel(QObject *parent) : + QAbstractItemModel(parent),numExtraRows(0) +{ +} + +void LocalComicListModel::load(QList &comics) +{ + _data = comics; +} + + +QModelIndex LocalComicListModel::parent(const QModelIndex &index) const +{ + Q_UNUSED(index) + return QModelIndex(); //no parent +} + +int LocalComicListModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return _data.count(); +} + +int LocalComicListModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + if(_data.isEmpty()) + return 0; + else + return 1;//_data.at(0)->count(); +} + +QVariant LocalComicListModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DecorationRole) + { + return QVariant(); + } + if (role == Qt::TextAlignmentRole) + { + //TODO + } + + if(role != Qt::DisplayRole) + return QVariant(); + + int row = index.row(); + + //if(row < _data.count()) + return _data[row].getFileName(); + //else + //return QVariant(); +} + +Qt::ItemFlags LocalComicListModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant LocalComicListModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + + if ( role == Qt::TextAlignmentRole) + return QVariant(Qt::AlignLeft | Qt::AlignVCenter); + + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + return QVariant(QString(tr("file name"))); + } + + return QVariant(); +} + +QModelIndex LocalComicListModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + return createIndex(row, column); +} + +QList LocalComicListModel::getData() +{ + return _data; +} + +void LocalComicListModel::removeComics(const QList &selectedIndexes) +{ + QModelIndex mi = selectedIndexes.first(); + QModelIndex lastMi = selectedIndexes.last(); + int sourceRow = mi.row(); + int sourceLastRow = lastMi.row(); + + beginRemoveRows(QModelIndex(),selectedIndexes.first().row(),selectedIndexes.last().row()); + + for(int i = sourceLastRow;i>=sourceRow;i--) + { + _removed.push_front(_data.at(i)); + _data.removeAt(i); + } + + endRemoveRows(); + + beginInsertRows(QModelIndex(),_data.count()-_removed.count(),_data.count()-1); + for(int i = 0; i<_removed.count(); i++) + _data.append(ComicDB()); + endInsertRows(); +} + +void LocalComicListModel::restoreAll() +{ + int numItemsToRemove = 0; + for(int i = 0;numItemsToRemove<_removed.count();i++) + { + if(_data.at(i).getFileName().isEmpty()) + { + beginRemoveRows(QModelIndex(),i,i); + _data.removeAt(i); + endRemoveRows(); + + beginInsertRows(QModelIndex(),i,i); + _data.insert(i,_removed.at(numItemsToRemove)); + endInsertRows(); + + numItemsToRemove++; + } + } + + _removed.clear(); +} + +void LocalComicListModel::moveSelectionUp(const QList &selectedIndexes) +{ + QModelIndex mi = selectedIndexes.first(); + QModelIndex lastMi = selectedIndexes.last(); + int sourceRow = mi.row(); + int sourceLastRow = lastMi.row(); + int destRow = sourceRow - 1; + + if(destRow < 0) + return; + + beginMoveRows(mi.parent(),sourceRow,sourceLastRow,mi.parent(),destRow); + + for(int i = sourceRow; i <= sourceLastRow; i++) + _data.swap(i, i-1); + + endMoveRows(); +} + +void LocalComicListModel::moveSelectionDown(const QList &selectedIndexes) +{ + QModelIndex mi = selectedIndexes.first(); + QModelIndex lastMi = selectedIndexes.last(); + int sourceRow = mi.row(); + int sourceLastRow = lastMi.row(); + int destRow = sourceLastRow + 1; + + if(destRow >= _data.count()) + return; + + beginMoveRows(mi.parent(),sourceRow,sourceLastRow,mi.parent(),destRow+1); + + for(int i = sourceLastRow; i >= sourceRow; i--) + _data.swap(i, i+1); + + endMoveRows(); +} + +void LocalComicListModel::addExtraRows(int numRows) +{ + numExtraRows = numRows; + for(int i = 0; i + +#include "comic_db.h" + +class LocalComicListModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit LocalComicListModel(QObject *parent = 0); + + void load(QList & comics); + + //QAbstractItemModel methods + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QList getData(); + + void removeComics(const QList & selectedIndexes); + void restoreAll(); +signals: + +public slots: + void moveSelectionUp(const QList & selectedIndexes); + void moveSelectionDown(const QList & selectedIndexes); + void addExtraRows(int numRows); + +private: + int numExtraRows; + QList _data; + QList _removed; +}; + +#endif // LOCAL_COMIC_LIST_MODEL_H diff --git a/YACReaderLibrary/comic_vine/model/response_parser.cpp b/YACReaderLibrary/comic_vine/model/response_parser.cpp new file mode 100644 index 00000000..eb212107 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/response_parser.cpp @@ -0,0 +1,83 @@ +#include "response_parser.h" + +#include +#include + +ResponseParser::ResponseParser(QObject *parent) : + QObject(parent),error(false),numResults(-1),currentPage(-1),totalPages(-1),errorTxt("None") +{ +} + +bool ResponseParser::responseError() +{ + return error; +} + +QString ResponseParser::errorDescription() +{ + return errorTxt; +} + +qint32 ResponseParser::getNumResults() +{ + return numResults; +} + +qint32 ResponseParser::getCurrentPage() +{ + return currentPage; +} + +qint32 ResponseParser::getTotalPages() +{ + return totalPages; +} + +bool ResponseParser::isError(qint32 error) +{ + switch(error) + { + case 100: + return true; + + default: + return false; + } +} + +void ResponseParser::loadJSONResponse(const QString &response) +{ + QScriptEngine engine; + QScriptValue sc; + sc = engine.evaluate("(" + response + ")"); + + errorTxt = "None"; + + if (!sc.property("status_code").isValid() || isError(sc.property("status_code").toInt32())) + { + error = true; + if(sc.property("error").isValid()) + errorTxt = sc.property("error").toString(); + else + errorTxt = "Unknown error"; + } + else + { + error = false; + if(sc.property("number_of_total_results").isValid()) + numResults = sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32(); + else + qDebug() << sc.property("oops").toString(); + + int limit = sc.property("limit").toInt32(); + int offset = sc.property("offset").toInt32(); + int total = sc.property("number_of_total_results").toInt32(); + if(limit > 0) + { + totalPages = (total / limit) + (total%limit>0?1:0); + currentPage = (offset / limit) + 1; + } + else + totalPages = currentPage = 1; + } +} diff --git a/YACReaderLibrary/comic_vine/model/response_parser.h b/YACReaderLibrary/comic_vine/model/response_parser.h new file mode 100644 index 00000000..10014ecb --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/response_parser.h @@ -0,0 +1,30 @@ +#ifndef RESPONSE_PARSER_H +#define RESPONSE_PARSER_H + +#include + +class ResponseParser : public QObject +{ + Q_OBJECT +public: + explicit ResponseParser(QObject *parent = 0); + bool responseError(); + QString errorDescription(); + qint32 getNumResults(); + qint32 getCurrentPage(); + qint32 getTotalPages(); + bool isError(qint32 error); +signals: + +public slots: + void loadJSONResponse(const QString & response); + +protected: + bool error; + QString errorTxt; + qint32 numResults; + qint32 currentPage; + qint32 totalPages; +}; + +#endif // RESPONSE_PARSER_H diff --git a/YACReaderLibrary/comic_vine/model/volume_comics_model.cpp b/YACReaderLibrary/comic_vine/model/volume_comics_model.cpp new file mode 100644 index 00000000..0a7a7e1c --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/volume_comics_model.cpp @@ -0,0 +1,172 @@ +#include "volume_comics_model.h" +#include "qnaturalsorting.h" + + +#include + +bool lessThan(const QList & left, const QList & right) +{ + if ((left.count() > 0) && (right.count() > 0)) + return naturalSortLessThanCI(left.at(0),right.at(0)); + else + return true; +} + +VolumeComicsModel::VolumeComicsModel(QObject * parent) : + JSONModel(parent),numExtraRows(0) +{ +} + +void VolumeComicsModel::load(const QString & json) +{ + QScriptEngine engine; + QScriptValue sc; + sc = engine.evaluate("(" + json + ")"); + + if (!sc.property("error").isValid() && sc.property("error").toString() != "OK") + { + qDebug("Error detected"); + } + else + { + QScriptValueIterator it(sc.property("results")); + //bool test; + QScriptValue resultsValue; + while (it.hasNext()) { + it.next(); + if(it.flags() & QScriptValue::SkipInEnumeration) + continue; + resultsValue = it.value(); + QString issueNumber = resultsValue.property("issue_number").toString(); + QString name = resultsValue.property("name").toString(); + QString coverURL = resultsValue.property("image").property("medium_url").toString(); + QString id = resultsValue.property("id").toString(); + QStringList l; + l << issueNumber << name << coverURL << id; + _data.push_back(l); + } + + qSort(_data.begin(),_data.end(),lessThan); + } +} + +QModelIndex VolumeComicsModel::parent(const QModelIndex &index) const +{ + Q_UNUSED(index) + return QModelIndex(); //no parent +} + +int VolumeComicsModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return _data.count() + numExtraRows; +} + +int VolumeComicsModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + if(_data.isEmpty()) + return 0; + else + return 2; +} + +QVariant VolumeComicsModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + int row = index.row(); + int column = index.column(); + + if (role == Qt::DecorationRole) + { + return QVariant(); + } + if (role == Qt::TextAlignmentRole) + { + switch(column)//TODO obtener esto de la query + { + case ISSUE: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case TITLE: + return QVariant(Qt::AlignLeft | Qt::AlignVCenter); + } + } + + if(role != Qt::DisplayRole) + return QVariant(); + + if(row<_data.count()) + return _data[row][column]; + else + return QVariant(); +} + +Qt::ItemFlags VolumeComicsModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant VolumeComicsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch(section)//TODO obtener esto de la query + { + case ISSUE: + return QVariant(QString("issue")); + case TITLE: + return QVariant(QString(tr("title"))); + } + } + + if (orientation == Qt::Horizontal && role == Qt::TextAlignmentRole) + { + switch(section)//TODO obtener esto de la query + { + case ISSUE: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case TITLE: + return QVariant(Qt::AlignLeft | Qt::AlignVCenter); + } + } + + return QVariant(); +} + +QModelIndex VolumeComicsModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + return createIndex(row, column); +} + +QString VolumeComicsModel::getComicId(const QModelIndex &index) const +{ + int row = index.row(); + if(row >= _data.count()) + return ""; + return _data[row][ID]; +} + +QString VolumeComicsModel::getComicId(int row) const +{ + if(row >= _data.count()) + return ""; + return _data[row][ID]; +} + +QString VolumeComicsModel::getCoverURL(const QModelIndex &index) const +{ + return _data[index.row()][COVER_URL]; +} + +void VolumeComicsModel::addExtraRows(int numRows) +{ + numExtraRows = numRows; +} + diff --git a/YACReaderLibrary/comic_vine/model/volume_comics_model.h b/YACReaderLibrary/comic_vine/model/volume_comics_model.h new file mode 100644 index 00000000..d9007891 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/volume_comics_model.h @@ -0,0 +1,41 @@ +#ifndef VOLUME_COMICS_MODEL_H +#define VOLUME_COMICS_MODEL_H + +#include "json_model.h" + +class VolumeComicsModel : public JSONModel +{ + Q_OBJECT +public: + explicit VolumeComicsModel(QObject *parent = 0); + void load(const QString & json); + + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; +signals: + +public slots: + QString getComicId(const QModelIndex &index) const; + QString getComicId(int row) const; + QString getCoverURL(const QModelIndex &index) const; + void addExtraRows(int numRows); + +private: + int numExtraRows; + QList > _data; + + enum Column { + ISSUE = 0, + TITLE, + COVER_URL, + ID + }; +}; + +#endif // VOLUME_COMICS_MODEL_H diff --git a/YACReaderLibrary/comic_vine/model/volumes_model.cpp b/YACReaderLibrary/comic_vine/model/volumes_model.cpp new file mode 100644 index 00000000..e3bfff12 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/volumes_model.cpp @@ -0,0 +1,161 @@ +#include "volumes_model.h" + +#include + + +VolumesModel::VolumesModel(QObject *parent) : + JSONModel(parent) +{ +} + +VolumesModel::~VolumesModel() +{ + //std::for_each(_data.begin(), _data.end(), [](QList * ptr) { delete ptr; }); +} + +void VolumesModel::load(const QString &json) +{ + QScriptEngine engine; + QScriptValue sc; + sc = engine.evaluate("(" + json + ")"); + + if (!sc.property("error").isValid() && sc.property("error").toString() != "OK") + { + qDebug("Error detected"); + } + else + { + int numResults = sc.property("number_of_total_results").toString().toInt(); //fix to weird behaviour using hasNext + QScriptValueIterator it(sc.property("results")); + bool test; + QScriptValue resultsValue; + while (it.hasNext()) { + it.next(); + resultsValue = it.value(); + QString numIssues = resultsValue.property("count_of_issues").toString(); + QString year = resultsValue.property("start_year").toString(); + QString name = resultsValue.property("name").toString(); + QString publisher = resultsValue.property("publisher").property("name").toString(); + QString url = resultsValue.property("image").property("medium_url").toString(); + QString deck = resultsValue.property("deck").toString(); + QString id = resultsValue.property("id").toString(); + QStringList l; + l << name << year << numIssues << publisher << url << deck << id; + test = name.isEmpty() && year.isEmpty() && numIssues.isEmpty() && url.isEmpty(); + if(numResults>0 && !test) + _data.push_back(l); + numResults--; + } + } +} + +QModelIndex VolumesModel::parent(const QModelIndex &index) const +{ + Q_UNUSED(index) + return QModelIndex(); //no parent +} + +int VolumesModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return _data.count(); +} + +int VolumesModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + if(_data.isEmpty()) + return 0; + else + return 4;//_data.at(0)->count(); +} + +QVariant VolumesModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DecorationRole) + { + return QVariant(); + } + if (role == Qt::TextAlignmentRole) + { + //TODO + } + + if(role != Qt::DisplayRole) + return QVariant(); + + int row = index.row(); + int column = index.column(); + return _data[row][column]; +} + +Qt::ItemFlags VolumesModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant VolumesModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch(section)//TODO obtener esto de la query + { + case SERIES: + return QVariant(QString("series")); + case YEAR: + return QVariant(QString(tr("year"))); + case ISSUES: + return QVariant(QString(tr("issues"))); + case PUBLISHER: + return QVariant(QString(tr("publisher"))); + } + } + + if (orientation == Qt::Horizontal && role == Qt::TextAlignmentRole) + { + switch(section)//TODO obtener esto de la query + { + case YEAR: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case ISSUES: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + } + } + + return QVariant(); +} + +QModelIndex VolumesModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + return createIndex(row, column); +} + +QString VolumesModel::getVolumeId(const QModelIndex &index) const +{ + return _data[index.row()][ID]; +} + +int VolumesModel::getNumIssues(const QModelIndex &index) const +{ + return _data[index.row()][ISSUES].toInt(); +} + +QString VolumesModel::getPublisher(const QModelIndex &index) const +{ + return _data[index.row()][PUBLISHER]; +} + +QString VolumesModel::getCoverURL(const QModelIndex &index) const +{ + return _data[index.row()][COVER_URL]; +} + diff --git a/YACReaderLibrary/comic_vine/model/volumes_model.h b/YACReaderLibrary/comic_vine/model/volumes_model.h new file mode 100644 index 00000000..f8a2fe05 --- /dev/null +++ b/YACReaderLibrary/comic_vine/model/volumes_model.h @@ -0,0 +1,50 @@ +#ifndef VOLUMES_MODEL_H +#define VOLUMES_MODEL_H + +#include "json_model.h" + +class VolumesModel : public JSONModel +{ + Q_OBJECT +public: + explicit VolumesModel(QObject *parent = 0); + virtual ~VolumesModel(); + //receive a valid json with a list of volumes + void load(const QString & json); + + //QAbstractItemModel methods + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + + QString getVolumeId(const QModelIndex & index) const; + int getNumIssues(const QModelIndex & index) const; + QString getPublisher(const QModelIndex & index) const; + QString getCoverURL(const QModelIndex & index) const; + +signals: + +public slots: + +private: + QList > _data; + +public: + enum Column { + SERIES = 0, + YEAR, + ISSUES, + PUBLISHER, + COVER_URL, + DECK, + ID + }; + +}; + +#endif // VOLUMES_MODEL_H diff --git a/YACReaderLibrary/comic_vine/scraper_lineedit.cpp b/YACReaderLibrary/comic_vine/scraper_lineedit.cpp new file mode 100644 index 00000000..94d03e95 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_lineedit.cpp @@ -0,0 +1,21 @@ +#include "scraper_lineedit.h" +#include + +ScraperLineEdit::ScraperLineEdit(const QString & title, QWidget * widget) + :QLineEdit(widget) +{ + titleLabel = new QLabel(title,this); + titleLabel->setStyleSheet("QLabel {color:white;}"); + + setStyleSheet(QString("QLineEdit {" + "border:none; background-color: #2E2E2E; color : white; padding-left: %1; padding-bottom: 1px; margin-bottom: 0px;" + "}").arg(titleLabel->sizeHint().width()+6)); + + setFixedHeight(22); +} + +void ScraperLineEdit::resizeEvent(QResizeEvent *) +{ + QSize szl = titleLabel->sizeHint(); + titleLabel->move(6,(rect().bottom() + 1 - szl.height())/2); +} diff --git a/YACReaderLibrary/comic_vine/scraper_lineedit.h b/YACReaderLibrary/comic_vine/scraper_lineedit.h new file mode 100644 index 00000000..30665b11 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_lineedit.h @@ -0,0 +1,19 @@ +#ifndef SCRAPPER_LINEEDIT_H +#define SCRAPPER_LINEEDIT_H + +#include + +class QLabel; + +class ScraperLineEdit : public QLineEdit +{ + Q_OBJECT +public: + ScraperLineEdit(const QString & title, QWidget * widget = 0); +protected: + void resizeEvent(QResizeEvent *); +private: + QLabel * titleLabel; +}; + +#endif // SCRAPPER_LINEEDIT_H diff --git a/YACReaderLibrary/comic_vine/scraper_results_paginator.cpp b/YACReaderLibrary/comic_vine/scraper_results_paginator.cpp new file mode 100644 index 00000000..f627d315 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_results_paginator.cpp @@ -0,0 +1,75 @@ +#include "scraper_results_paginator.h" +#include "response_parser.h" + +#include +#include +#include +#include + + +ScraperResultsPaginator::ScraperResultsPaginator(QWidget *parent) : + QWidget(parent),customLabel("items") +{ + QHBoxLayout * pagesButtonsLayout = new QHBoxLayout; + + QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; + + nextPage = new QToolButton; + nextPage->setStyleSheet("QToolButton {border:none;}"); + QPixmap np(":/images/comic_vine/nextPage.png"); + nextPage->setIconSize(np.size()); + nextPage->setIcon(np); + + previousPage = new QToolButton; + previousPage->setStyleSheet("QToolButton {border:none;}"); + QPixmap pp(":/images/comic_vine/previousPage.png"); + previousPage->setIconSize(pp.size()); + previousPage->setIcon(pp); + + connect(nextPage,SIGNAL(clicked()),this,SIGNAL(loadNextPage())); + connect(previousPage,SIGNAL(clicked()),this,SIGNAL(loadPreviousPage())); + + numElements = new QLabel(tr("Number of volumes found : %1")); + numElements->setStyleSheet(labelStylesheet); + numPages = new QLabel(tr("page %1 of %2")); + numPages->setStyleSheet(labelStylesheet); + + pagesButtonsLayout->addSpacing(15); + pagesButtonsLayout->addWidget(numElements); + pagesButtonsLayout->addStretch(); + pagesButtonsLayout->addWidget(numPages); + pagesButtonsLayout->addWidget(previousPage); + pagesButtonsLayout->addWidget(nextPage); + + setContentsMargins(0,0,0,0); + pagesButtonsLayout->setContentsMargins(0,0,0,0); + + setLayout(pagesButtonsLayout); +} + +void ScraperResultsPaginator::update(const QString &json) +{ + ResponseParser rp; + rp.loadJSONResponse(json); + + currentPage = rp.getCurrentPage(); + numElements->setText(tr("Number of %1 found : %2").arg(customLabel).arg(rp.getNumResults())); + numPages->setText(tr("page %1 of %2").arg(currentPage).arg(rp.getTotalPages())); + + previousPage->setDisabled(currentPage == 1); + nextPage->setDisabled(currentPage == rp.getTotalPages()); + + numPages->setHidden(rp.getTotalPages()==1); + previousPage->setHidden(rp.getTotalPages()==1); + nextPage->setHidden(rp.getTotalPages()==1); +} + +int ScraperResultsPaginator::getCurrentPage() +{ + return currentPage; +} + +void ScraperResultsPaginator::setCustomLabel(const QString &label) +{ + customLabel = label; +} diff --git a/YACReaderLibrary/comic_vine/scraper_results_paginator.h b/YACReaderLibrary/comic_vine/scraper_results_paginator.h new file mode 100644 index 00000000..c371b7af --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_results_paginator.h @@ -0,0 +1,34 @@ +#ifndef SCRAPER_RESULTS_PAGINATOR_H +#define SCRAPER_RESULTS_PAGINATOR_H + +#include + +class QToolButton; +class QLabel; + +class ScraperResultsPaginator : public QWidget +{ + Q_OBJECT +public: + explicit ScraperResultsPaginator(QWidget *parent = 0); + void update(const QString & json); + int getCurrentPage(); + void setCustomLabel(const QString & label); +signals: + void loadNextPage(); + void loadPreviousPage(); + +public slots: + +private: + QToolButton * nextPage; + QToolButton * previousPage; + QLabel * numElements; + QLabel * numPages; + + int currentPage; + + QString customLabel; +}; + +#endif // SCRAPER_RESULTS_PAGINATOR_H diff --git a/YACReaderLibrary/comic_vine/scraper_scroll_label.cpp b/YACReaderLibrary/comic_vine/scraper_scroll_label.cpp new file mode 100644 index 00000000..82ce0bd1 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_scroll_label.cpp @@ -0,0 +1,53 @@ +#include "scraper_scroll_label.h" + +#include +#include +#include + +ScraperScrollLabel::ScraperScrollLabel(QWidget *parent) : + QScrollArea(parent) +{ + textLabel = new QLabel(this); + textLabel->setStyleSheet("QLabel {background-color: #2B2B2B; color:white; font-size:12px; font-family:Arial; }"); + + textLabel->setWordWrap(true); + textLabel->setMinimumSize(168,12); + + setWidget(textLabel); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setStyleSheet( + "QScrollArea {background-color:#2B2B2B; border:none;}" + "QScrollBar:vertical { border: none; background: #2B2B2B; width: 3px; margin: 0; }" + "QScrollBar:horizontal { border: none; background: #2B2B2B; height: 3px; margin: 0; }" + "QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }" + "QScrollBar::handle:horizontal { background: #DDDDDD; width: 7px; min-height: 20px; }" + "QScrollBar::add-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::sub-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::add-line:horizontal { border: none; background: #404040; width: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 0 3px 0;}" + "QScrollBar::sub-line:horizontal { border: none; background: #404040; width: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 0 3px 0;}" + "QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}" + "QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}" + "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical, QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {background: none; }" + ); + + connect(textLabel,SIGNAL(linkActivated(QString)),this,SLOT(openLink(QString))); +} + +void ScraperScrollLabel::setAltText(const QString &text) +{ + textLabel->setAlignment(Qt::AlignTop|Qt::AlignHCenter); + textLabel->setText(text); + textLabel->adjustSize(); +} + +void ScraperScrollLabel::setText(const QString &text) +{ + textLabel->setAlignment(Qt::AlignTop|Qt::AlignLeft); + textLabel->setText(text); + textLabel->adjustSize(); +} + +void ScraperScrollLabel::openLink(const QString & link) +{ + QDesktopServices::openUrl(QUrl("http://www.comicvine.com"+link)); +} diff --git a/YACReaderLibrary/comic_vine/scraper_scroll_label.h b/YACReaderLibrary/comic_vine/scraper_scroll_label.h new file mode 100644 index 00000000..8b4c82be --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_scroll_label.h @@ -0,0 +1,25 @@ +#ifndef SCRAPER_SCROLL_LABEL_H +#define SCRAPER_SCROLL_LABEL_H + +#include + +class QLabel; + +class ScraperScrollLabel : public QScrollArea +{ + Q_OBJECT +public: + explicit ScraperScrollLabel(QWidget *parent = 0); + +signals: + +public slots: + void setText(const QString & text); + void setAltText(const QString &text); + + void openLink(const QString &link); +private: + QLabel * textLabel; +}; + +#endif // SCRAPER_SCROLL_LABEL_H diff --git a/YACReaderLibrary/comic_vine/scraper_selector.cpp b/YACReaderLibrary/comic_vine/scraper_selector.cpp new file mode 100644 index 00000000..e79117b9 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_selector.cpp @@ -0,0 +1,25 @@ +#include "scraper_selector.h" + +ScraperSelector::ScraperSelector(QWidget *parent) : + QWidget(parent) +{ + paginator = new ScraperResultsPaginator; + connect(paginator,SIGNAL(loadNextPage()),this,SLOT(loadNextPage())); + connect(paginator,SIGNAL(loadPreviousPage()),this,SLOT(loadPreviousPage())); +} + +void ScraperSelector::load(const QString &json, const QString &searchString) +{ + currentSearchString = searchString; + paginator->update(json); +} + +void ScraperSelector::loadNextPage() +{ + emit loadPage(currentSearchString,paginator->getCurrentPage()+1); +} + +void ScraperSelector::loadPreviousPage() +{ + emit loadPage(currentSearchString,paginator->getCurrentPage()-1); +} diff --git a/YACReaderLibrary/comic_vine/scraper_selector.h b/YACReaderLibrary/comic_vine/scraper_selector.h new file mode 100644 index 00000000..34ce409f --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_selector.h @@ -0,0 +1,28 @@ +#ifndef SCRAPER_SELECTOR_H +#define SCRAPER_SELECTOR_H + +#include + +#include "scraper_results_paginator.h" + +class ScraperSelector : public QWidget +{ + Q_OBJECT +public: + explicit ScraperSelector(QWidget *parent = 0); + virtual void load(const QString & json, const QString & searchString); +public slots: + +signals: + void loadPage(QString,int); + +private slots: + void loadNextPage(); + void loadPreviousPage(); + +protected: + QString currentSearchString; + ScraperResultsPaginator * paginator; +}; + +#endif // SCRAPER_SELECTOR_H diff --git a/YACReaderLibrary/comic_vine/scraper_tableview.cpp b/YACReaderLibrary/comic_vine/scraper_tableview.cpp new file mode 100644 index 00000000..22dbbed1 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_tableview.cpp @@ -0,0 +1,61 @@ +#include "scraper_tableview.h" + +#include + +ScraperTableView::ScraperTableView(QWidget *parent) : + QTableView(parent) +{ + QString tableStylesheet = "QTableView {color:white; border:0px;alternate-background-color: #2E2E2E;background-color: #2B2B2B; outline: 0px;}" + "QTableView::item {outline: 0px; border: 0px; color:#FFFFFF;}" + "QTableView::item:selected {outline: 0px; background-color: #555555; }" + "QHeaderView::section:horizontal {background-color:#292929; border-bottom:1px solid #1F1F1F; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #292929, stop: 1 #1F1F1F); border-left:none; border-top:none; padding:4px; color:#ebebeb;}" + "QHeaderView::section:vertical {border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE;}" + "QHeaderView::down-arrow {image: url(':/images/comic_vine/downArrow.png');}" + "QHeaderView::up-arrow {image: url(':/images/comic_vine/upArrow.png');}" + "QScrollBar:vertical { border: none; background: #2B2B2B; width: 3px; margin: 0; }" + "QScrollBar:horizontal { border: none; background: #2B2B2B; height: 3px; margin: 0; }" + "QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }" + "QScrollBar::handle:horizontal { background: #DDDDDD; width: 7px; min-height: 20px; }" + "QScrollBar::add-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::sub-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::add-line:horizontal { border: none; background: #404040; width: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 0 3px 0;}" + "QScrollBar::sub-line:horizontal { border: none; background: #404040; width: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 0 3px 0;}" + "QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}" + "QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}" + "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical, QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {background: none; }"; + + setStyleSheet(tableStylesheet); + + setShowGrid(false); +#if QT_VERSION >= 0x050000 + verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); +#else + verticalHeader()->setResizeMode(QHeaderView::Fixed); +#endif + + //comicView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); + horizontalHeader()->setStretchLastSection(true); +#if QT_VERSION >= 0x050000 + horizontalHeader()->setSectionsClickable(false); +#else + horizontalHeader()->setClickable(false); +#endif + //comicView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); + verticalHeader()->setDefaultSectionSize(24); +#if QT_VERSION >= 0x050000 + verticalHeader()->setSectionsClickable(false); //TODO comportamiento anómalo +#else + verticalHeader()->setClickable(false); //TODO comportamiento anómalo +#endif + + setCornerButtonEnabled(false); + + setSelectionBehavior(QAbstractItemView::SelectRows); + setSelectionMode(QAbstractItemView::ExtendedSelection); + + setAlternatingRowColors(true); + + verticalHeader()->hide(); + + setSelectionMode(QAbstractItemView::SingleSelection); +} diff --git a/YACReaderLibrary/comic_vine/scraper_tableview.h b/YACReaderLibrary/comic_vine/scraper_tableview.h new file mode 100644 index 00000000..deb151c7 --- /dev/null +++ b/YACReaderLibrary/comic_vine/scraper_tableview.h @@ -0,0 +1,18 @@ +#ifndef SCRAPPER_TABLEVIEW_H +#define SCRAPPER_TABLEVIEW_H + +#include + +class ScraperTableView : public QTableView +{ + Q_OBJECT +public: + explicit ScraperTableView(QWidget *parent = 0); + +signals: + +public slots: + +}; + +#endif // SCRAPPER_TABLEVIEW_H diff --git a/YACReaderLibrary/comic_vine/search_single_comic.cpp b/YACReaderLibrary/comic_vine/search_single_comic.cpp new file mode 100644 index 00000000..0e4f479d --- /dev/null +++ b/YACReaderLibrary/comic_vine/search_single_comic.cpp @@ -0,0 +1,62 @@ +#include "search_single_comic.h" + +#include "scraper_lineedit.h" + +#include +#include +#include + +SearchSingleComic::SearchSingleComic(QWidget * parent) + :QWidget(parent) +{ + + //QLabel * label = new QLabel(tr("Please provide some additional information. At least one field is needed.")); + QLabel * label = new QLabel(tr("Please provide some additional information.")); + label->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + + //titleEdit = new ScraperLineEdit(tr("Title:")); + //numberEdit = new ScraperLineEdit(tr("Number:")); + volumeEdit = new ScraperLineEdit(tr("Series:")); + + //numberEdit->setMaximumWidth(126); + + QVBoxLayout * l = new QVBoxLayout; + //QHBoxLayout * hl = new QHBoxLayout; + //hl->addWidget(titleEdit); + //hl->addWidget(numberEdit); + + l->addSpacing(35); + l->addWidget(label); + //l->addLayout(hl); + l->addWidget(volumeEdit); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + +QString SearchSingleComic::getVolumeInfo() +{ + return volumeEdit->text(); +} + +QString SearchSingleComic::getComicInfo() +{ + //return titleEdit->text(); + return ""; +} + +int SearchSingleComic::getComicNumber() +{ + //QString numberText = numberEdit->text(); + //if(numberText.isEmpty()) + // return -1; + //return numberText.toInt(); + return 0; +} + +void SearchSingleComic::clean() +{ + volumeEdit->clear(); +} diff --git a/YACReaderLibrary/comic_vine/search_single_comic.h b/YACReaderLibrary/comic_vine/search_single_comic.h new file mode 100644 index 00000000..5045ee69 --- /dev/null +++ b/YACReaderLibrary/comic_vine/search_single_comic.h @@ -0,0 +1,22 @@ +#ifndef SEARCH_SINGLE_COMIC_H +#define SEARCH_SINGLE_COMIC_H + +#include + +class ScraperLineEdit; + +class SearchSingleComic : public QWidget +{ + Q_OBJECT +public: + SearchSingleComic(QWidget * parent = 0); + QString getVolumeInfo(); + QString getComicInfo(); + int getComicNumber(); + void clean(); +private: + ScraperLineEdit * titleEdit; + ScraperLineEdit * numberEdit; + ScraperLineEdit * volumeEdit; +}; +#endif // SEARCH_SINGLE_COMIC_H diff --git a/YACReaderLibrary/comic_vine/search_volume.cpp b/YACReaderLibrary/comic_vine/search_volume.cpp new file mode 100644 index 00000000..8351f685 --- /dev/null +++ b/YACReaderLibrary/comic_vine/search_volume.cpp @@ -0,0 +1,36 @@ +#include "search_volume.h" + +#include "scraper_lineedit.h" + +#include +#include + +SearchVolume::SearchVolume(QWidget * parent) + :QWidget(parent) +{ + QLabel * label = new QLabel(tr("Please provide some additional information.")); + label->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + + volumeEdit = new ScraperLineEdit(tr("Series:")); + + QVBoxLayout * l = new QVBoxLayout; + + l->addSpacing(35); + l->addWidget(label); + l->addWidget(volumeEdit); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + +void SearchVolume::clean() +{ + volumeEdit->clear(); +} + +QString SearchVolume::getVolumeInfo() +{ + return volumeEdit->text(); +} diff --git a/YACReaderLibrary/comic_vine/search_volume.h b/YACReaderLibrary/comic_vine/search_volume.h new file mode 100644 index 00000000..627baebc --- /dev/null +++ b/YACReaderLibrary/comic_vine/search_volume.h @@ -0,0 +1,21 @@ +#ifndef SEARCH_VOLUME_H +#define SEARCH_VOLUME_H + +#include + +class ScraperLineEdit; + + +class SearchVolume : public QWidget +{ + Q_OBJECT +public: + SearchVolume(QWidget * parent = 0); + void clean(); +public slots: + QString getVolumeInfo(); +private: + ScraperLineEdit * volumeEdit; +}; + +#endif // SEARCH_VOLUME_H diff --git a/YACReaderLibrary/comic_vine/select_comic.cpp b/YACReaderLibrary/comic_vine/select_comic.cpp new file mode 100644 index 00000000..8105dfb1 --- /dev/null +++ b/YACReaderLibrary/comic_vine/select_comic.cpp @@ -0,0 +1,150 @@ +#include "select_comic.h" + +#include "comic_vine_client.h" +#include "scraper_scroll_label.h" +#include "scraper_tableview.h" +#include "volume_comics_model.h" + +#include +#include +#include + +SelectComic::SelectComic(QWidget *parent) + :ScraperSelector(parent),model(0) +{ + QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; + + QLabel * label = new QLabel(tr("Please, select the right comic info.")); + label->setStyleSheet(labelStylesheet); + + QVBoxLayout * l = new QVBoxLayout; + QWidget * leftWidget = new QWidget; + QVBoxLayout * left = new QVBoxLayout; + QVBoxLayout * right = new QVBoxLayout; + QHBoxLayout * content = new QHBoxLayout; + + right->setContentsMargins(0,0,0,0); + + //widgets + cover = new QLabel(); + cover->setScaledContents(true); + cover->setAlignment(Qt::AlignTop|Qt::AlignHCenter); + cover->setMinimumSize(168,168*5.0/3); + cover->setStyleSheet("QLabel {background-color: #2B2B2B; color:white; font-size:12px; font-family:Arial; }"); + detailLabel = new ScraperScrollLabel(this); + + tableComics = new ScraperTableView(this); + //connections + connect(tableComics,SIGNAL(clicked(QModelIndex)),this,SLOT(loadComicInfo(QModelIndex))); + + paginator->setCustomLabel(tr("comics")); + + left->addWidget(cover); + left->addWidget(detailLabel,1); + left->addStretch(); + leftWidget->setMaximumWidth(180); + leftWidget->setLayout(left); + left->setContentsMargins(0,0,0,0); + leftWidget->setContentsMargins(0,0,0,0); + + right->addWidget(tableComics,0,Qt::AlignRight|Qt::AlignTop); + right->addWidget(paginator); + + content->addWidget(leftWidget); + content->addLayout(right); + + l->addSpacing(15); + l->addWidget(label); + l->addSpacing(5); + l->addLayout(content); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + +void SelectComic::load(const QString &json, const QString & searchString) +{ + VolumeComicsModel * tempM = new VolumeComicsModel(); + tempM->load(json); + tableComics->setModel(tempM); + + tableComics->setFixedSize(619,341); + + if(model != 0) + delete model; + + model = tempM; + + if(model->rowCount()>0) + { + tableComics->selectRow(0); + loadComicInfo(model->index(0,0)); + } + + tableComics->resizeColumnToContents(0); + + ScraperSelector::load(json,searchString); +} + +SelectComic::~SelectComic() {} + +void SelectComic::loadComicInfo(const QModelIndex &mi) +{ + QString coverURL = model->getCoverURL(mi); + QString id = model->getComicId(mi); + + QString loadingStyle = "%1"; + cover->setText(loadingStyle.arg(tr("loading cover"))); + detailLabel->setAltText(loadingStyle.arg(tr("loading description"))); + + ComicVineClient * comicVineClient = new ComicVineClient; + connect(comicVineClient,SIGNAL(comicCover(const QByteArray &)),this,SLOT(setCover(const QByteArray &))); + connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater())); + comicVineClient->getComicCover(coverURL); + + ComicVineClient * comicVineClient2 = new ComicVineClient; + connect(comicVineClient2,SIGNAL(comicDetail(QString)),this,SLOT(setDescription(QString))); + connect(comicVineClient2,SIGNAL(finished()),comicVineClient2,SLOT(deleteLater())); + comicVineClient2->getComicDetailAsync(id); +} + +void SelectComic::setCover(const QByteArray & data) +{ + QPixmap p; + p.loadFromData(data); + int w = p.width(); + int h = p.height(); + + cover->setPixmap(p); + float aspectRatio = static_cast(w)/h; + + cover->setFixedSize(180,static_cast(180/aspectRatio)); + + cover->update(); +} + +void SelectComic::setDescription(const QString &jsonDetail) +{ + QScriptEngine engine; + QScriptValue sc; + sc = engine.evaluate("(" + jsonDetail + ")"); + + if (!sc.property("error").isValid() && sc.property("error").toString() != "OK") + { + qDebug("Error detected"); + } + else + { + + QScriptValue descriptionValues = sc.property("results").property("description"); + bool valid = !descriptionValues.isNull() && descriptionValues.isValid(); + detailLabel->setText(valid?descriptionValues.toString().replace("getComicId(tableComics->currentIndex()); +} diff --git a/YACReaderLibrary/comic_vine/select_comic.h b/YACReaderLibrary/comic_vine/select_comic.h new file mode 100644 index 00000000..5d14a08b --- /dev/null +++ b/YACReaderLibrary/comic_vine/select_comic.h @@ -0,0 +1,34 @@ +#ifndef SELECT_COMIC_H +#define SELECT_COMIC_H + +#include "scraper_selector.h" + +class QLabel; +class VolumeComicsModel; +class QModelIndex; + +class ScraperScrollLabel; +class ScraperTableView; + +class SelectComic : public ScraperSelector +{ + Q_OBJECT +public: + SelectComic(QWidget * parent = 0); + void load(const QString & json, const QString & searchString); + virtual ~SelectComic(); + +public slots: + void loadComicInfo(const QModelIndex & mi); + void setCover(const QByteArray &); + void setDescription(const QString & jsonDetail); + QString getSelectedComicId(); + +private: + QLabel * cover; + ScraperScrollLabel * detailLabel; + ScraperTableView * tableComics; + VolumeComicsModel * model; +}; + +#endif // SELECT_COMIC_H diff --git a/YACReaderLibrary/comic_vine/select_volume.cpp b/YACReaderLibrary/comic_vine/select_volume.cpp new file mode 100644 index 00000000..9650a7f7 --- /dev/null +++ b/YACReaderLibrary/comic_vine/select_volume.cpp @@ -0,0 +1,191 @@ +#include "select_volume.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "scraper_tableview.h" + +#include + +#include "volumes_model.h" +#include "comic_vine_client.h" +#include "scraper_scroll_label.h" + +#include "response_parser.h" +#include "scraper_results_paginator.h" + +SelectVolume::SelectVolume(QWidget *parent) + :ScraperSelector(parent),model(0) +{ + proxyModel = new QSortFilterProxyModel; + + QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; + + QLabel * label = new QLabel(tr("Please, select the right series for your comic.")); + label->setStyleSheet(labelStylesheet); + + QVBoxLayout * l = new QVBoxLayout; + QWidget * leftWidget = new QWidget; + QVBoxLayout * left = new QVBoxLayout; + QVBoxLayout * right = new QVBoxLayout; + QHBoxLayout * content = new QHBoxLayout; + + right->setContentsMargins(0,0,0,0); + + //widgets + cover = new QLabel(); + cover->setScaledContents(true); + cover->setAlignment(Qt::AlignTop|Qt::AlignHCenter); + cover->setMinimumSize(168,168*5.0/3); + cover->setStyleSheet("QLabel {background-color: #2B2B2B; color:white; font-size:12px; font-family:Arial; }"); + detailLabel = new ScraperScrollLabel(this); + + tableVolumes = new ScraperTableView(this); + tableVolumes->setSortingEnabled(true); +#if QT_VERSION >= 0x050000 + tableVolumes->horizontalHeader()->setSectionsClickable(true); +#else + tableVolumes->horizontalHeader()->setClickable(true); +#endif + //tableVolumes->horizontalHeader()->setSortIndicatorShown(false); + connect(tableVolumes->horizontalHeader(),SIGNAL(sectionClicked(int)), tableVolumes, SLOT(sortByColumn(int))); + //connections + connect(tableVolumes,SIGNAL(clicked(QModelIndex)),this,SLOT(loadVolumeInfo(QModelIndex))); + + paginator->setCustomLabel(tr("volumes")); + + left->addWidget(cover); + left->addWidget(detailLabel,1); + left->addStretch(); + leftWidget->setMaximumWidth(180); + leftWidget->setLayout(left); + left->setContentsMargins(0,0,0,0); + leftWidget->setContentsMargins(0,0,0,0); + + right->addWidget(tableVolumes,0,Qt::AlignRight|Qt::AlignTop); + right->addWidget(paginator); + + content->addWidget(leftWidget); + content->addLayout(right); + + l->addSpacing(15); + l->addWidget(label); + l->addSpacing(5); + l->addLayout(content); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + +void SelectVolume::load(const QString & json, const QString & searchString) +{ + VolumesModel * tempM = new VolumesModel(); + tempM->load(json); + //tableVolumes->setModel(tempM); + + proxyModel->setSourceModel( tempM ); + tableVolumes->setModel(proxyModel); + tableVolumes->sortByColumn(0,Qt::AscendingOrder); + tableVolumes->resizeColumnsToContents(); + + tableVolumes->setFixedSize(619,341); + + if(model != 0) + delete model; + + model = tempM; + + if(model->rowCount()>0) + { + tableVolumes->selectRow(0); + loadVolumeInfo(proxyModel->index(0,0)); + } + + tableVolumes->setColumnWidth(0,350); + + ScraperSelector::load(json,searchString); +} + +SelectVolume::~SelectVolume() {} + +void SelectVolume::loadVolumeInfo(const QModelIndex & omi) +{ + QModelIndex mi = proxyModel->mapToSource(omi); + QString coverURL = model->getCoverURL(mi); + QString id = model->getVolumeId(mi); + + QString loadingStyle = "%1"; + cover->setText(loadingStyle.arg(tr("loading cover"))); + detailLabel->setAltText(loadingStyle.arg(tr("loading description"))); + + ComicVineClient * comicVineClient = new ComicVineClient; + connect(comicVineClient,SIGNAL(seriesCover(const QByteArray &)),this,SLOT(setCover(const QByteArray &))); + connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater())); + comicVineClient->getSeriesCover(coverURL); + + ComicVineClient * comicVineClient2 = new ComicVineClient; + connect(comicVineClient2,SIGNAL(seriesDetail(QString)),this,SLOT(setDescription(QString))); + connect(comicVineClient2,SIGNAL(finished()),comicVineClient2,SLOT(deleteLater())); + comicVineClient2->getSeriesDetail(id); +} + +void SelectVolume::setCover(const QByteArray & data) +{ + QPixmap p; + p.loadFromData(data); + int w = p.width(); + int h = p.height(); + + cover->setPixmap(p); + float aspectRatio = static_cast(w)/h; + + cover->setFixedSize(180,static_cast(180/aspectRatio)); + + cover->update(); +} + +void SelectVolume::setDescription(const QString & jsonDetail) +{ + QScriptEngine engine; + QScriptValue sc; + sc = engine.evaluate("(" + jsonDetail + ")"); + + if (!sc.property("error").isValid() && sc.property("error").toString() != "OK") + { + qDebug("Error detected"); + } + else + { + + QScriptValue descriptionValues = sc.property("results").property("description"); + bool valid = !descriptionValues.isNull() && descriptionValues.isValid(); + detailLabel->setText(valid?descriptionValues.toString().replace("getVolumeId(proxyModel->mapToSource(tableVolumes->currentIndex())); +} + +int SelectVolume::getSelectedVolumeNumIssues() +{ + return model->getNumIssues(proxyModel->mapToSource(tableVolumes->currentIndex())); +} + +QString SelectVolume::getSelectedVolumePublisher() +{ + return model->getPublisher(proxyModel->mapToSource(tableVolumes->currentIndex())); +} + + diff --git a/YACReaderLibrary/comic_vine/select_volume.h b/YACReaderLibrary/comic_vine/select_volume.h new file mode 100644 index 00000000..060933c2 --- /dev/null +++ b/YACReaderLibrary/comic_vine/select_volume.h @@ -0,0 +1,39 @@ +#ifndef SELECT_VOLUME_H +#define SELECT_VOLUME_H + +#include "scraper_selector.h" + +class QLabel; +class VolumesModel; +class QModelIndex; +class QToolButton; +class QSortFilterProxyModel; + +class ScraperScrollLabel; +class ScraperTableView; + +class SelectVolume : public ScraperSelector +{ + Q_OBJECT +public: + SelectVolume(QWidget * parent = 0); + void load(const QString & json, const QString & searchString); + virtual ~SelectVolume(); + +public slots: + void loadVolumeInfo(const QModelIndex & mi); + void setCover(const QByteArray &); + void setDescription(const QString & jsonDetail); + QString getSelectedVolumeId(); + int getSelectedVolumeNumIssues(); + QString getSelectedVolumePublisher(); + +private: + QLabel * cover; + ScraperScrollLabel * detailLabel; + ScraperTableView * tableVolumes; + VolumesModel * model; + QSortFilterProxyModel * proxyModel; +}; + +#endif // SELECT_VOLUME_H diff --git a/YACReaderLibrary/comic_vine/series_question.cpp b/YACReaderLibrary/comic_vine/series_question.cpp new file mode 100644 index 00000000..1fb93cb8 --- /dev/null +++ b/YACReaderLibrary/comic_vine/series_question.cpp @@ -0,0 +1,46 @@ +#include "series_question.h" + +#include +#include +#include + + +SeriesQuestion::SeriesQuestion(QWidget * parent) + :QWidget(parent) +{ + QVBoxLayout * l = new QVBoxLayout; + + QLabel * questionLabel = new QLabel(tr("You are trying to get information for various comics at once, are they part of the same series?")); + questionLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + yes = new QRadioButton(tr("yes")); + no = new QRadioButton(tr("no")); + + QString rbStyle = "QRadioButton {margin-left:27px; margin-top:5px; color:white;font-size:12px;font-family:Arial;}" + "QRadioButton::indicator {width:11px;height:11px;}" + "QRadioButton::indicator::unchecked {image : url(:/images/comic_vine/radioUnchecked.png);}" + "QRadioButton::indicator::checked {image : url(:/images/comic_vine/radioChecked.png);}"; + yes->setStyleSheet(rbStyle); + no->setStyleSheet(rbStyle); + + yes->setChecked(true); + + l->addSpacing(35); + l->addWidget(questionLabel); + l->addWidget(yes); + l->addWidget(no); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); +} + +bool SeriesQuestion::getYes() +{ + return yes->isChecked(); +} + +void SeriesQuestion::setYes(bool y) +{ + yes->setChecked(y); +} diff --git a/YACReaderLibrary/comic_vine/series_question.h b/YACReaderLibrary/comic_vine/series_question.h new file mode 100644 index 00000000..c6620ecd --- /dev/null +++ b/YACReaderLibrary/comic_vine/series_question.h @@ -0,0 +1,23 @@ +#ifndef SERIES_QUESTION_H +#define SERIES_QUESTION_H + +#include + +class QRadioButton; + +class SeriesQuestion : public QWidget +{ + Q_OBJECT + +public: + SeriesQuestion(QWidget * parent = 0); + bool getYes(); + void setYes(bool yes = true); + +private: + QRadioButton * yes; + QRadioButton * no; +}; + + +#endif // SERIES_QUESTION_H diff --git a/YACReaderLibrary/comic_vine/sort_volume_comics.cpp b/YACReaderLibrary/comic_vine/sort_volume_comics.cpp new file mode 100644 index 00000000..16e7d782 --- /dev/null +++ b/YACReaderLibrary/comic_vine/sort_volume_comics.cpp @@ -0,0 +1,226 @@ +#include "sort_volume_comics.h" + +#include +#include +#include +#include +#include + +#include "scraper_tableview.h" +#include "local_comic_list_model.h" +#include "volume_comics_model.h" + +SortVolumeComics::SortVolumeComics(QWidget *parent) : + ScraperSelector(parent) +{ + QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}"; + + QLabel * label = new QLabel(tr("Please, sort the list of comics on the left until it matches the comics' information.")); + label->setStyleSheet(labelStylesheet); + + QLabel * sortLabel = new QLabel(tr("sort comics to match comic information")); + sortLabel->setStyleSheet(labelStylesheet); + + moveUpButtonCL = new ScrapperToolButton(ScrapperToolButton::LEFT); + moveUpButtonCL->setIcon(QIcon(":/images/comic_vine/rowUp.png")); + moveUpButtonCL->setAutoRepeat(true); + moveDownButtonCL = new ScrapperToolButton(ScrapperToolButton::RIGHT); + moveDownButtonCL->setIcon(QIcon(":/images/comic_vine/rowDown.png")); + moveDownButtonCL->setAutoRepeat(true); + //moveUpButtonIL = new ScrapperToolButton(ScrapperToolButton::LEFT); + //moveUpButtonIL->setIcon(QIcon(":/images/comic_vine/rowUp.png")); + //moveDownButtonIL = new ScrapperToolButton(ScrapperToolButton::RIGHT); + //moveDownButtonIL->setIcon(QIcon(":/images/comic_vine/rowDown.png")); + + connect(moveUpButtonCL,SIGNAL(clicked()),this,SLOT(moveUpCL())); + connect(moveDownButtonCL,SIGNAL(clicked()),this,SLOT(moveDownCL())); + //connect(moveUpButtonIL,SIGNAL(clicked()),this,SLOT(moveUpIL())); + //connect(moveUpButtonIL,SIGNAL(clicked()),this,SLOT(moveDownIL())); + + QVBoxLayout * l = new QVBoxLayout; + QHBoxLayout * content = new QHBoxLayout; + QHBoxLayout * sortButtonsLayout = new QHBoxLayout; + + tableFiles = new ScraperTableView(); + tableVolumeComics = new ScraperTableView(); + + tableFiles->setSelectionBehavior(QAbstractItemView::SelectRows); + tableFiles->setSelectionMode(QAbstractItemView::ContiguousSelection); + + tableFiles->setFixedSize(407,341); + tableVolumeComics->setFixedSize(407,341); + content->addWidget(tableFiles,0,Qt::AlignLeft|Qt::AlignTop); + content->addWidget(tableVolumeComics,0,Qt::AlignRight|Qt::AlignTop); + //content->addWidget(tableVolumes,0,Qt::AlignRight|Qt::AlignTop); + + connect(tableVolumeComics->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(synchronizeScroll(int))); + connect(tableFiles->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(synchronizeScroll(int))); + + //connect(tableVolumeComics, SIGNAL(pressed(QModelIndex)), tableFiles, SLOT(setCurrentIndex(QModelIndex))); + //connect(tableFiles, SIGNAL(pressed(QModelIndex)), tableVolumeComics, SLOT(setCurrentIndex(QModelIndex))); + + paginator->setCustomLabel(tr("issues")); + paginator->setMinimumWidth(422); + + sortButtonsLayout->addWidget(moveUpButtonCL); + sortButtonsLayout->addWidget(ScrapperToolButton::getSeparator()); + sortButtonsLayout->addWidget(moveDownButtonCL); + sortButtonsLayout->addSpacing(10); + //sortButtonsLayout->addStretch(); + sortButtonsLayout->addWidget(sortLabel); + sortButtonsLayout->addStretch(); + sortButtonsLayout->addWidget(paginator); + //sortButtonsLayout->addStretch(); + //sortButtonsLayout->addWidget(moveUpButtonIL); + //sortButtonsLayout->addWidget(ScrapperToolButton::getSeparator()); + //sortButtonsLayout->addWidget(moveDownButtonIL); + sortButtonsLayout->setSpacing(0); + + l->addSpacing(15); + l->addWidget(label); + l->addSpacing(5); + l->addLayout(content); + l->addLayout(sortButtonsLayout); + l->addStretch(); + + l->setContentsMargins(0,0,0,0); + setLayout(l); + setContentsMargins(0,0,0,0); + + //rows actions + QAction * removeItemFromList = new QAction(tr("remove selected comics"),this); + QAction * restoreAllItems = new QAction(tr("restore all removed comics"),this); + QAction * restoreItems = new QAction(tr("restore removed comics"),this); + + tableFiles->setContextMenuPolicy(Qt::ActionsContextMenu); + tableFiles->addAction(removeItemFromList); + tableFiles->addAction(restoreAllItems); + //tableFiles->addAction(restoreItems); + + connect(removeItemFromList,SIGNAL(triggered()),this,SLOT(removeSelectedComics())); + connect(restoreAllItems,SIGNAL(triggered()),this,SLOT(restoreAllComics())); + connect(restoreItems,SIGNAL(triggered()),this,SLOT(showRemovedComicsSelector())); +} + +void SortVolumeComics::setData(QList & comics, const QString &json, const QString &vID) +{ + //set up models + localComicsModel = new LocalComicListModel; + localComicsModel->load(comics); + + volumeComicsModel = new VolumeComicsModel; + volumeComicsModel->load(json); + + int numLocalComics = localComicsModel->rowCount(); + int numVolumeComics = volumeComicsModel->rowCount(); + + if(numLocalComics > numVolumeComics) + volumeComicsModel->addExtraRows(numLocalComics - numVolumeComics); + if(numLocalComics < numVolumeComics) + localComicsModel->addExtraRows(numVolumeComics - numLocalComics); + + tableFiles->setModel(localComicsModel); + tableVolumeComics->setModel(volumeComicsModel); + + tableVolumeComics->resizeColumnToContents(0); + + ScraperSelector::load(json,vID); +} + +void SortVolumeComics::synchronizeScroll(int pos) +{ + void * senderObject = sender(); + + if(senderObject == 0) //invalid call + return; + + QScrollBar * tableVolumeComicsScrollBar = tableVolumeComics->verticalScrollBar(); + QScrollBar * tableFilesScrollBar = tableFiles->verticalScrollBar(); + + if(senderObject == tableVolumeComicsScrollBar) + { + disconnect(tableFilesScrollBar,SIGNAL(valueChanged(int)),this,0); + tableFilesScrollBar->setValue(pos); + connect(tableFilesScrollBar, SIGNAL(valueChanged(int)), this, SLOT(synchronizeScroll(int))); + } + else + { + disconnect(tableVolumeComicsScrollBar,SIGNAL(valueChanged(int)),this,0); + tableVolumeComicsScrollBar->setValue(pos); + connect(tableVolumeComicsScrollBar, SIGNAL(valueChanged(int)), this, SLOT(synchronizeScroll(int))); + } +} + +void SortVolumeComics::moveUpCL() +{ + QList selection = tableFiles->selectionModel()->selectedIndexes(); + + if(selection.count() == 0) + return; + + localComicsModel->moveSelectionUp(selection); + + selection = tableFiles->selectionModel()->selectedIndexes(); + tableFiles->scrollTo(selection.first()); +} + +void SortVolumeComics::moveDownCL() +{ + QList selection = tableFiles->selectionModel()->selectedIndexes(); + + if(selection.count() > 0) + { + localComicsModel->moveSelectionDown(selection); + + selection = tableFiles->selectionModel()->selectedIndexes(); + tableFiles->scrollTo(selection.last()); + } +} + +void SortVolumeComics::moveUpIL() +{ + +} + +void SortVolumeComics::moveDownIL() +{ + +} + +void SortVolumeComics::removeSelectedComics() +{ + QList selection = tableFiles->selectionModel()->selectedIndexes(); + + localComicsModel->removeComics(selection); +} + +void SortVolumeComics::restoreAllComics() +{ + localComicsModel->restoreAll(); +} + +void SortVolumeComics::showRemovedComicsSelector() +{ + +} + +QList > SortVolumeComics::getMatchingInfo() +{ + QList comicList = localComicsModel->getData(); + QList > l; + + int index = 0; + + QString id; + foreach(ComicDB c, comicList) + { + id = volumeComicsModel->getComicId(index); + if(!c.getFileName().isEmpty() && !id.isEmpty()) //there is a valid comic, and valid comic ID + { + l.push_back(QPair(c,id)); + } + index++; + } + + return l; +} diff --git a/YACReaderLibrary/comic_vine/sort_volume_comics.h b/YACReaderLibrary/comic_vine/sort_volume_comics.h new file mode 100644 index 00000000..92955f90 --- /dev/null +++ b/YACReaderLibrary/comic_vine/sort_volume_comics.h @@ -0,0 +1,99 @@ +#ifndef SORT_VOLUME_COMICS_H +#define SORT_VOLUME_COMICS_H + +#include "scraper_selector.h" + +#include +#include +#include + +#include "comic_db.h" + +class ScraperTableView; +class LocalComicListModel; +class VolumeComicsModel; + +class ScrapperToolButton : public QPushButton +{ + Q_OBJECT +public: + enum Appearance { + DEFAULT, + LEFT, + RIGHT + }; + + ScrapperToolButton(ScrapperToolButton::Appearance appearance = DEFAULT, QWidget * parent=0):QPushButton(parent),appearance(appearance) { + setStyleSheet("QPushButton {border: none; background: #2e2e2e; color:white; border-radius:2px;}" + "QPushButton::pressed {border: none; background: #282828; color:white; border-radius:2px;}"); + setFixedSize(18,17); + } + static QWidget * getSeparator(){QWidget * w = new QWidget; w->setFixedWidth(1); w->setStyleSheet("QWidget {background:#282828;}"); return w;} + void setAppearance(ScrapperToolButton::Appearance appearance){this->appearance = appearance;} + virtual ~ScrapperToolButton() {} + + + +protected: + void paintEvent(QPaintEvent * e) + { + QPainter p(this); + + switch (appearance) { + case LEFT: + p.fillRect(16,0,2,18,QColor("#2E2E2E")); + break; + case RIGHT: + p.fillRect(0,0,2,18,QColor("#2E2E2E")); + break; + default: + break; + } + + QPushButton::paintEvent(e); + } + +private: + Appearance appearance; +}; + + +class SortVolumeComics : public ScraperSelector +{ + Q_OBJECT +public: + explicit SortVolumeComics(QWidget *parent = 0); + +signals: + +public slots: + void setData(QList & comics, const QString & json, const QString & vID); + QList > getMatchingInfo(); + +protected slots: + void synchronizeScroll(int pos); + void moveUpCL(); + void moveDownCL(); + void moveUpIL(); + void moveDownIL(); + + void removeSelectedComics(); + void restoreAllComics(); + void showRemovedComicsSelector(); + + +private: + ScraperTableView * tableFiles; + ScraperTableView * tableVolumeComics; + + LocalComicListModel * localComicsModel; + VolumeComicsModel * volumeComicsModel; + + ScrapperToolButton * moveUpButtonCL; + ScrapperToolButton * moveDownButtonCL; + ScrapperToolButton * moveUpButtonIL; + ScrapperToolButton * moveDownButtonIL; + +}; + +#endif // SORT_VOLUME_COMICS_H diff --git a/YACReaderLibrary/comic_vine/title_header.cpp b/YACReaderLibrary/comic_vine/title_header.cpp new file mode 100644 index 00000000..cebc0d6f --- /dev/null +++ b/YACReaderLibrary/comic_vine/title_header.cpp @@ -0,0 +1,53 @@ +#include "title_header.h" + +#include +#include +#include + +TitleHeader::TitleHeader(QWidget * parent ) + :QWidget(parent) +{ + mainTitleLabel = new QLabel(); + subTitleLabel = new QLabel(); + + mainTitleLabel->setStyleSheet("QLabel {color:white; font-size:18px;font-family:Arial;}"); + subTitleLabel->setStyleSheet("QLabel {color:white; font-size:12px;font-family:Arial;}"); + + QHBoxLayout * titleLayout = new QHBoxLayout; + QVBoxLayout * titleLabelsLayout = new QVBoxLayout; + + titleLabelsLayout->addWidget(mainTitleLabel); + titleLabelsLayout->addWidget(subTitleLabel); + titleLabelsLayout->setSpacing(0); + + titleLayout->addLayout(titleLabelsLayout); + titleLayout->setContentsMargins(0,0,0,0); + + setLayout(titleLayout); + + setContentsMargins(0,0,0,0); + + setTitle(tr("SEARCH")); +} + +void TitleHeader::setTitle(const QString & title) +{ + mainTitleLabel->setText(title); +} + +void TitleHeader::setSubTitle(const QString & title) +{ + subTitleLabel->setText(title); +} + +void TitleHeader::showButtons(bool show) +{ + if(show) + { + + } + else + { + + } +} diff --git a/YACReaderLibrary/comic_vine/title_header.h b/YACReaderLibrary/comic_vine/title_header.h new file mode 100644 index 00000000..a4e62e98 --- /dev/null +++ b/YACReaderLibrary/comic_vine/title_header.h @@ -0,0 +1,22 @@ +#ifndef TITLE_HEADER_H +#define TITLE_HEADER_H + +#include + +class QLabel; + +class TitleHeader : public QWidget +{ + Q_OBJECT +public: + TitleHeader(QWidget * parent = 0); +public slots: + void setTitle(const QString & title); + void setSubTitle(const QString & title); + void showButtons(bool show); +private: + QLabel * mainTitleLabel; + QLabel * subTitleLabel; +}; + +#endif // TITLE_HEADER_H diff --git a/YACReaderLibrary/comics_remover.cpp b/YACReaderLibrary/comics_remover.cpp new file mode 100644 index 00000000..ef3fd009 --- /dev/null +++ b/YACReaderLibrary/comics_remover.cpp @@ -0,0 +1,63 @@ +#include "comics_remover.h" + +#include +#include + +#include "QsLog.h" + +ComicsRemover::ComicsRemover(QModelIndexList & il, QList & ps, QObject *parent) + :QObject(parent),indexList(il), paths(ps) +{ +} + +void ComicsRemover::process() +{ + QString currentComicPath; + QListIterator i(indexList); + QListIterator i2(paths); + i.toBack(); + i2.toBack(); + + while (i.hasPrevious() && i2.hasPrevious()) + { + QModelIndex mi = i.previous(); + currentComicPath = i2.previous(); + if(QFile::remove(currentComicPath)) + emit remove(mi.row()); + else + emit removeError(); + } + + emit finished(); +} + + +FoldersRemover::FoldersRemover(QModelIndexList &il, QList &ps, QObject *parent) + :QObject(parent),indexList(il), paths(ps) +{ + +} + +void FoldersRemover::process() +{ + QString currentFolderPath; + QListIterator i(indexList); + QListIterator i2(paths); + i.toBack(); + i2.toBack(); + + QLOG_DEBUG() << "Deleting folders" << paths.at(0); + + while (i.hasPrevious() && i2.hasPrevious()) + { + QModelIndex mi = i.previous(); + currentFolderPath = i2.previous(); + QDir d(currentFolderPath); + if(d.removeRecursively() || !d.exists()) //the folder is in the DB but no in the drive... + emit remove(mi); + else + emit removeError(); + } + + emit finished(); +} diff --git a/YACReaderLibrary/comics_remover.h b/YACReaderLibrary/comics_remover.h new file mode 100644 index 00000000..ff9d0a21 --- /dev/null +++ b/YACReaderLibrary/comics_remover.h @@ -0,0 +1,47 @@ +#ifndef COMICS_REMOVER_H +#define COMICS_REMOVER_H + +#include + +#include +#include + +class ComicsRemover : public QObject +{ + Q_OBJECT +public: + explicit ComicsRemover(QModelIndexList & indexList, QList & paths, QObject *parent = 0); + +signals: + void remove(int); + void removeError(); + void finished(); + +public slots: + void process(); + +private: + QModelIndexList indexList; + QList paths; +}; + +class FoldersRemover : public QObject +{ + Q_OBJECT +public: + explicit FoldersRemover(QModelIndexList & indexList, QList & paths, QObject *parent = 0); + +signals: + void remove(QModelIndex); + void removeError(); + void finished(); + +public slots: + void process(); + +private: + QModelIndexList indexList; + QList paths; +}; + +#endif // COMICS_REMOVER_H diff --git a/YACReaderLibrary/comics_view.cpp b/YACReaderLibrary/comics_view.cpp new file mode 100644 index 00000000..2aa52bec --- /dev/null +++ b/YACReaderLibrary/comics_view.cpp @@ -0,0 +1,69 @@ +#include "comics_view.h" +#include "comic.h" +#include "comic_files_manager.h" + +#include "QsLog.h" + +ComicsView::ComicsView(QWidget *parent) : + QWidget(parent),model(NULL) +{ + setAcceptDrops(true); +} + +void ComicsView::setModel(ComicModel *m) +{ + model = m; +} + +void ComicsView::dragEnterEvent(QDragEnterEvent *event) +{ + if(model->canDropMimeData(event->mimeData(),event->proposedAction(),0,0,QModelIndex())) + event->acceptProposedAction(); + else + { + QLOG_INFO() << "dragEnterEvent"; + QList urlList; + + if (event->mimeData()->hasUrls() && event->dropAction() == Qt::CopyAction) + { + urlList = event->mimeData()->urls(); + QString currentPath; + foreach (QUrl url, urlList) + { + //comics or folders are accepted, folders' content is validate in dropEvent (avoid any lag before droping) + currentPath = url.toLocalFile(); + if(Comic::fileIsComic(currentPath) || QFileInfo(currentPath).isDir()) + { + event->acceptProposedAction(); + return; + } + } + } + } +} + +void ComicsView::dropEvent(QDropEvent *event) +{ + QLOG_DEBUG() << "drop" << event->dropAction(); + + bool validAction = event->dropAction() == Qt::CopyAction;// || event->dropAction() & Qt::MoveAction; TODO move + + if(event->mimeData()->hasUrls() && validAction) + { + + QList > droppedFiles = ComicFilesManager::getDroppedFiles(event->mimeData()->urls()); + + if(event->dropAction() == Qt::CopyAction) + { + QLOG_DEBUG() << "copy :" << droppedFiles; + emit copyComicsToCurrentFolder(droppedFiles); + } + else if(event->dropAction() & Qt::MoveAction) + { + QLOG_DEBUG() << "move :" << droppedFiles; + emit moveComicsToCurrentFolder(droppedFiles); + } + + event->acceptProposedAction(); + } +} diff --git a/YACReaderLibrary/comics_view.h b/YACReaderLibrary/comics_view.h new file mode 100644 index 00000000..2d4f1940 --- /dev/null +++ b/YACReaderLibrary/comics_view.h @@ -0,0 +1,56 @@ +#ifndef COMICS_VIEW_H +#define COMICS_VIEW_H + +#include + +#include "comic_model.h" + +class YACReaderTableView; +class QSplitter; +class ComicFlowWidget; +class QToolBar; +class ComicModel; +class ComicsView : public QWidget +{ + Q_OBJECT +public: + explicit ComicsView(QWidget *parent = 0); + virtual void setToolBar(QToolBar * toolBar) = 0; + virtual void setModel(ComicModel *model); + virtual void setCurrentIndex(const QModelIndex &index) = 0; + virtual QModelIndex currentIndex() = 0; + virtual QItemSelectionModel * selectionModel() = 0; + virtual void scrollTo(const QModelIndex & mi, QAbstractItemView::ScrollHint hint ) = 0; + virtual void toFullScreen() = 0; + virtual void toNormal() = 0; + virtual void updateConfig(QSettings * settings) = 0; + virtual void enableFilterMode(bool enabled) = 0; + virtual void selectIndex(int index) = 0; + +signals: + void selected(unsigned int); + void comicRated(int,QModelIndex); + + //Context menus + void customContextMenuViewRequested(QPoint); + void customContextMenuItemRequested(QPoint); + + //Drops + void copyComicsToCurrentFolder(QList >); + void moveComicsToCurrentFolder(QList >); + +public slots: + virtual void setShowMarks(bool show) = 0; + virtual void selectAll() = 0; +protected: + ComicModel * model; + + //Drop to import + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); + +private: + +}; + +#endif // COMICS_VIEW_H diff --git a/YACReaderLibrary/comics_view_transition.cpp b/YACReaderLibrary/comics_view_transition.cpp new file mode 100644 index 00000000..6734d479 --- /dev/null +++ b/YACReaderLibrary/comics_view_transition.cpp @@ -0,0 +1,85 @@ +#include "comics_view_transition.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "yacreader_global.h" + +ComicsViewTransition::ComicsViewTransition(QWidget *parent) : + QWidget(parent),movie(0) +{ + QVBoxLayout * layout = new QVBoxLayout; + + settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); + settings->beginGroup("libraryConfig"); + + movieLabel = new QLabel("Placeholder"); + movieLabel->setAlignment(Qt::AlignCenter); + QLabel * textLabel = new QLabel("Switching comics view"); + textLabel->setAlignment(Qt::AlignCenter); + +#ifdef Q_OS_MAC + textLabel->setStyleSheet("QLabel {color:#888888; font-size:24px;font-family:Arial;font-weight:bold;}"); + setStyleSheet("QWidget {background:#FFFFFF}"); +#else + textLabel->setStyleSheet("QLabel {color:#CCCCCC; font-size:24px;font-family:Arial;font-weight:bold;}"); + setStyleSheet("QWidget {background:#2A2A2A}"); +#endif + + //movieLabel->setFixedSize(450,350); + + layout->addSpacing(100); + layout->addWidget(movieLabel); + layout->addSpacing(20); + layout->addWidget(textLabel); + layout->addStretch(); + layout->setMargin(0); + layout->setSpacing(0); + + setContentsMargins(0,0,0,0); + + //QSizePolicy sp(); + setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding ); + //movieLabel->setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding ); + setLayout(layout); +} + +QSize ComicsViewTransition::sizeHint() +{ + return QSize(450,350); +} + +void ComicsViewTransition::startMovie() +{ + if(movie) + delete movie; + + if(settings->value(COMICS_VIEW_STATUS) == YACReader::Flow) + movie = new QMovie(":/images/flow_to_grid.gif"); + else + movie = new QMovie(":/images/grid_to_flow.gif"); + + connect(movie,SIGNAL(finished()),this,SIGNAL(transitionFinished())); + //connect(movie,SIGNAL(finished()),movie,SLOT(deleteLater()); + movie->setSpeed(200); + movie->jumpToFrame(0); + movieLabel->setMovie(movie); + + QTimer::singleShot(100,movie,SLOT(start())); +} + +void ComicsViewTransition::paintEvent(QPaintEvent *) +{ + QPainter painter (this); + +#ifdef Q_OS_MAC + painter.fillRect(0,0,width(),height(),QColor("#FFFFFF")); +#else + painter.fillRect(0,0,width(),height(),QColor("#2A2A2A")); +#endif +} diff --git a/YACReaderLibrary/comics_view_transition.h b/YACReaderLibrary/comics_view_transition.h new file mode 100644 index 00000000..ed8c55ba --- /dev/null +++ b/YACReaderLibrary/comics_view_transition.h @@ -0,0 +1,31 @@ +#ifndef COMICS_VIEW_TRANSITION_H +#define COMICS_VIEW_TRANSITION_H + +#include + +class QMovie; +class QSettings; +class QLabel; + +class ComicsViewTransition : public QWidget +{ + Q_OBJECT +public: + explicit ComicsViewTransition(QWidget *parent = 0); + QSize sizeHint(); + +signals: + void transitionFinished(); + +public slots: + void startMovie(); + +protected: + QMovie * movie; + QSettings * settings; + QLabel * movieLabel; + + void paintEvent(QPaintEvent *); +}; + +#endif // COMICS_VIEW_TRANSITION_H diff --git a/YACReaderLibrary/create_library_dialog.cpp b/YACReaderLibrary/create_library_dialog.cpp new file mode 100644 index 00000000..1ae28ff1 --- /dev/null +++ b/YACReaderLibrary/create_library_dialog.cpp @@ -0,0 +1,206 @@ +#include "create_library_dialog.h" + +#include +#include +#include +#include +#include + +CreateLibraryDialog::CreateLibraryDialog(QWidget * parent) +:QDialog(parent) +{ + setupUI(); +} + +void CreateLibraryDialog::setupUI() +{ + textLabel = new QLabel(tr("Comics folder : ")); + path = new QLineEdit; + textLabel->setBuddy(path); + connect(path,SIGNAL(textChanged(QString)),this,SLOT(pathSetted(QString))); + + nameLabel = new QLabel(tr("Library Name : ")); + nameEdit = new QLineEdit; + nameLabel->setBuddy(nameEdit); + connect(nameEdit,SIGNAL(textChanged(QString)),this,SLOT(nameSetted(QString))); + + accept = new QPushButton(tr("Create")); + accept->setDisabled(true); + connect(accept,SIGNAL(clicked()),this,SLOT(create())); + + cancel = new QPushButton(tr("Cancel")); + connect(cancel,SIGNAL(clicked()),this,SIGNAL(cancelCreate())); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + + find = new QPushButton(QIcon(":/images/find_folder.png"),""); + connect(find,SIGNAL(clicked()),this,SLOT(findPath())); + + QGridLayout * content = new QGridLayout; + + //QHBoxLayout *nameLayout = new QHBoxLayout; + + content->addWidget(nameLabel,0,0); + content->addWidget(nameEdit,0,1); + + //QHBoxLayout *libraryLayout = new QHBoxLayout; + + content->addWidget(textLabel,1,0); + content->addWidget(path,1,1); + content->addWidget(find,1,2); + content->setColumnMinimumWidth(2,0); //TODO + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addWidget(message = new QLabel(tr("Create a library could take several minutes. You can stop the process and update the library later for completing the task."))); + message->setWordWrap(true); + //message->hide(); + bottomLayout->addStretch(); + bottomLayout->addWidget(accept); + bottomLayout->addWidget(cancel); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(content); + + mainLayout->addLayout(bottomLayout); + + QHBoxLayout * imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(this); + QPixmap p(":/images/new.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setModal(true); + setWindowTitle(tr("Create new library")); +} + +void CreateLibraryDialog::open(const YACReaderLibraries & libs) +{ + libraries = libs; + QDialog::open(); +} + +void CreateLibraryDialog::create() +{ + + QFileInfo f(path->text()); + if(f.exists() && f.isDir() && f.isWritable()) + { + if(!libraries.contains(nameEdit->text())) + { + emit(createLibrary(QDir::cleanPath(path->text()),QDir::cleanPath(path->text())+"/.yacreaderlibrary",nameEdit->text())); + close(); + } + else + emit(libraryExists(nameEdit->text())); + } + else + QMessageBox::critical(NULL,tr("Path not found"),tr("The selected path does not exist or is not a valid path. Be sure that you have write access to this folder")); +} + +void CreateLibraryDialog::nameSetted(const QString & text) +{ + if(!text.isEmpty()) + { + if(!path->text().isEmpty()) + { + QFileInfo fi(path->text()); + if(fi.isDir()) + accept->setEnabled(true); + else + accept->setEnabled(false); + } + } + else + accept->setEnabled(false); +} + +void CreateLibraryDialog::pathSetted(const QString & text) +{ + QFileInfo fi(text); + if(fi.isDir()) + { + if(!nameEdit->text().isEmpty()) + accept->setEnabled(true); + } + else + accept->setEnabled(false); +} + +void CreateLibraryDialog::findPath() +{ + QString s = QFileDialog::getExistingDirectory(0,"Comics directory","."); + if(!s.isEmpty()) + { + path->setText(s); + if(!nameEdit->text().isEmpty()) + accept->setEnabled(true); + } + else + accept->setEnabled(false); +} + +void CreateLibraryDialog::close() +{ + path->clear(); + nameEdit->clear(); + accept->setEnabled(false); + QDialog::close(); +} + +void CreateLibraryDialog::setDataAndStart(QString name, QString path) +{ + this->path->setText(path); + this->nameEdit->setText(name); + QDialog::open(); + create(); +} +//----------------------------------------------------------------------------- +// UpdateLibraryDialog +//----------------------------------------------------------------------------- +UpdateLibraryDialog::UpdateLibraryDialog(QWidget * parent) +:QDialog(parent) +{ + QVBoxLayout * mainLayout = new QVBoxLayout; + mainLayout->addWidget(message = new QLabel(tr("Updating...."))); + mainLayout->addWidget(currentFileLabel = new QLabel("\n\n\n\n")); + currentFileLabel->setWordWrap(true); + + QHBoxLayout * bottom = new QHBoxLayout; + bottom->addStretch(); + bottom->addWidget(cancel = new QPushButton(tr("Cancel"))); + + connect(cancel,SIGNAL(clicked()),this,SIGNAL(cancelUpdate())); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + + mainLayout->addStretch(); + + mainLayout->addLayout(bottom); + + QHBoxLayout * imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(this); + QPixmap p(":/images/updateLibrary.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setModal(true); + setWindowTitle(tr("Update library")); +} + +void UpdateLibraryDialog::showCurrentFile(QString file) +{ + currentFileLabel->setText(file); + currentFileLabel->update(); + this->update(); +} + +void UpdateLibraryDialog::close() +{ + currentFileLabel->setText(""); + this->adjustSize(); + QDialog::close(); +} diff --git a/YACReaderLibrary/create_library_dialog.h b/YACReaderLibrary/create_library_dialog.h new file mode 100644 index 00000000..2736552c --- /dev/null +++ b/YACReaderLibrary/create_library_dialog.h @@ -0,0 +1,61 @@ +#ifndef __CREATE_LIBRARY_DIALOG_H +#define __CREATE_LIBRARY_DIALOG_H + +#include "yacreader_libraries.h" + +#include +#include +#include +#include +#include +#include + + class CreateLibraryDialog : public QDialog + { + Q_OBJECT + public: + CreateLibraryDialog(QWidget * parent = 0); + private: + QLabel * nameLabel; + QLabel * textLabel; + QLabel * message; + QProgressBar *progressBar; + QLineEdit * path; + QLineEdit * nameEdit; + QPushButton * find; + QPushButton * accept; + QPushButton * cancel; + YACReaderLibraries libraries; + void setupUI(); + public slots: + void create(); + void findPath(); + void close(); + void setDataAndStart(QString name, QString paht); + void nameSetted(const QString & text); + void pathSetted(const QString & text); + void open(const YACReaderLibraries &libraries); + signals: + void createLibrary(QString source, QString target, QString name); + void cancelCreate(); + void libraryExists(const QString & name); + }; + + class UpdateLibraryDialog : public QDialog + { + Q_OBJECT + public: + UpdateLibraryDialog(QWidget * parent = 0); + private: + QLabel * message; + QLabel * currentFileLabel; + QProgressBar *progressBar; + QPushButton * cancel; + public slots: + void showCurrentFile(QString file); + void close(); + signals: + void cancelUpdate(); + }; + +#endif diff --git a/YACReaderLibrary/db/comic_item.cpp b/YACReaderLibrary/db/comic_item.cpp new file mode 100644 index 00000000..9382d897 --- /dev/null +++ b/YACReaderLibrary/db/comic_item.cpp @@ -0,0 +1,47 @@ + +#include + +#include "comic_item.h" + +//! [0] +ComicItem::ComicItem(const QList &data) + +{ + itemData = data; +} +//! [0] + +//! [1] +ComicItem::~ComicItem() +{ + +} +//! [1] + + +//! [5] +int ComicItem::columnCount() const +{ + return itemData.count(); +} +//! [5] + +//! [6] +QVariant ComicItem::data(int column) const +{ + return itemData.value(column); +} +//! [6] + +void ComicItem::setData(int column,const QVariant & value) +{ + itemData[column] = value; +} + +//! [8] +int ComicItem::row() const +{ + + return 0; +} +//! [8] diff --git a/YACReaderLibrary/db/comic_item.h b/YACReaderLibrary/db/comic_item.h new file mode 100644 index 00000000..35d6fa54 --- /dev/null +++ b/YACReaderLibrary/db/comic_item.h @@ -0,0 +1,27 @@ +#ifndef TABLEITEM_H +#define TABLEITEM_H + +#include +#include + +//! [0] +class ComicItem : public QObject +{ + Q_OBJECT +public: + ComicItem(const QList &data); + ~ComicItem(); + int columnCount() const; + QVariant data(int column) const; + void setData(int column,const QVariant & value); + int row() const; + //unsigned long long int id; //TODO sustituir por una clase adecuada + //Comic comic; +private: + QList itemData; + + +}; +//! [0] + +#endif diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp new file mode 100644 index 00000000..33ddf459 --- /dev/null +++ b/YACReaderLibrary/db/comic_model.cpp @@ -0,0 +1,1158 @@ + +#include +#include +#include + +#include "comic_item.h" +#include "comic_model.h" +#include "data_base_management.h" +#include "qnaturalsorting.h" +#include "comic_db.h" +#include "db_helper.h" + +//ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read +#include "QsLog.h" + + +ComicModel::ComicModel(QObject *parent) + : QAbstractItemModel(parent) +{ + connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset())); + connect(this,SIGNAL(reset()),this,SIGNAL(modelReset())); +} + +ComicModel::ComicModel( QSqlQuery &sqlquery, QObject *parent) + : QAbstractItemModel(parent) +{ + setupModelData(sqlquery); +} + +ComicModel::~ComicModel() +{ + qDeleteAll(_data); +} + +int ComicModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + if(_data.isEmpty()) + return 0; + return _data.first()->columnCount(); +} + +bool ComicModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const +{ + if(!enableResorting) + return false; + return data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat); +} + +//TODO: optimize this method (seriously) +bool ComicModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + + QAbstractItemModel::dropMimeData(data,action,row,column,parent); + QLOG_INFO() << ">>>>>>>>>>>>>>dropMimeData ComicModel<<<<<<<<<<<<<<<<<"<< parent << row << "," << column; + + if(!data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat)) + return false; + + QList comicIds = YACReader::mimeDataToComicsIds(data); + QList currentIndexes; + int i; + foreach(qulonglong id, comicIds) + { + i = 0; + foreach (ComicItem *item, _data) { + if(item->data(Id)==id) + { + currentIndexes << i; + break; + } + i++; + } + } + + std::sort(currentIndexes.begin(), currentIndexes.end()); + QList resortedData; + + if(currentIndexes.contains(row))//no resorting + return false; + + ComicItem * destinationItem; + if(row == -1 || row >= _data.length()) + destinationItem = 0; + else + destinationItem = _data.at(row); + + QList newSorting; + + i = 0; + foreach (ComicItem *item, _data) { + if(!currentIndexes.contains(i)) + { + + if(item == destinationItem) { + foreach(int index, currentIndexes) + { + resortedData << _data.at(index); + newSorting << index; + } + } + + resortedData << item; + newSorting << i; + } + + i++; + } + + if(destinationItem == 0) + { + foreach(int index, currentIndexes) + { + resortedData << _data.at(index); + newSorting << index; + } + } + + QLOG_INFO() << newSorting; + + int tempRow = row; + foreach(qulonglong id, comicIds) + { + int i = 0; + foreach (ComicItem *item, _data) { + if(item->data(Id) == id) + { + beginMoveRows(parent,i,i,parent,tempRow); + _data.removeAll(item); + _data.insert(tempRow++, item); + endMoveRows(); + break; + } + i++; + } + } + + /*if(!beginMoveRows(parent,currentIndexes.first(),currentIndexes.last(),parent,row)) + return false;*/ + _data = resortedData; //TODO No longer needed + + + //TODO emit signals + //TODO fix selection + QList allComicIds; + foreach (ComicItem *item, _data) { + allComicIds << item->data(Id).toULongLong(); + } + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + switch (mode) { + case Favorites: + DBHelper::reasignOrderToComicsInFavorites(allComicIds,db); + break; + case Label: + DBHelper::reasignOrderToComicsInLabel(sourceId,allComicIds,db); + break; + case ReadingList: + DBHelper::reasignOrderToComicsInReadingList(sourceId,allComicIds,db); + break; + } + + QSqlDatabase::removeDatabase(_databasePath); + + //endMoveRows(); + + emit resortedIndexes(newSorting); + int destSelectedIndex = row<0?_data.length():row; + + if(destSelectedIndex>currentIndexes.at(0)) + emit newSelectedIndex(index(qMax(0,destSelectedIndex-1),0,parent)); + else + emit newSelectedIndex(index(qMax(0,destSelectedIndex),0,parent)); + + return true; +} + +bool ComicModel::canBeResorted() +{ + return enableResorting; +} + +QMimeData *ComicModel::mimeData(const QModelIndexList &indexes) const +{ + //custom model data + //application/yacreader-comics-ids + list of ids in a QByteArray + QList ids; + foreach(QModelIndex index, indexes) + { + QLOG_DEBUG() << "dragging : " << index.data(IdRole).toULongLong(); + ids << index.data(IdRole).toULongLong(); + + } + + QByteArray data; + QDataStream out(&data,QIODevice::WriteOnly); + out << ids; //serialize the list of identifiers + + QMimeData * mimeData = new QMimeData(); + mimeData->setData(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat, data); + + return mimeData; +} + +QStringList ComicModel::mimeTypes() const +{ + QLOG_DEBUG() << "mimeTypes"; + QStringList list; + list << YACReader::YACReaderLibrarComiscSelectionMimeDataFormat; + return list; +} + +QHash ComicModel::roleNames() const { + QHash roles; + + roles[NumberRole] = "number"; + roles[TitleRole] = "title"; + roles[FileNameRole] = "file_name"; + roles[NumPagesRole] = "num_pages"; + roles[IdRole] = "id"; + roles[Parent_IdRole] = "parent_id"; + roles[PathRole] = "path"; + roles[HashRole] = "hash"; + roles[ReadColumnRole] = "read_column"; + roles[IsBisRole] = "is_bis"; + roles[CurrentPageRole] = "current_page"; + roles[RatingRole] = "rating"; + roles[HasBeenOpenedRole] = "has_been_opened"; + roles[CoverPathRole] = "cover_path"; + + return roles; +} + +QVariant ComicModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + /*if (index.column() == TableModel::Rating && role == Qt::DecorationRole) + { + TableItem *item = static_cast(index.internalPointer()); + return QPixmap(QString(":/images/rating%1.png").arg(item->data(index.column()).toInt())); + }*/ + + if (role == Qt::DecorationRole) + { + return QVariant(); + } + + if (role == Qt::TextAlignmentRole) + { + switch(index.column())//TODO obtener esto de la query + { + case ComicModel::Number: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case ComicModel::NumPages: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case ComicModel::Hash: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case ComicModel::CurrentPage: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + default: + return QVariant(Qt::AlignLeft | Qt::AlignVCenter); + } + } + + + //TODO check here if any view is asking for TableModel::Roles + //these roles will be used from QML/GridView + + ComicItem *item = static_cast(index.internalPointer()); + + if (role == NumberRole) + return item->data(Number); + else if (role == TitleRole) + return item->data(Title).isNull()?item->data(FileName):item->data(Title); + else if (role == FileNameRole) + return item->data(FileName); + else if (role == RatingRole) + return item->data(Rating); + else if (role == CoverPathRole) + return QUrl("file:"+_databasePath+"/covers/"+item->data(Hash).toString()+".jpg"); + else if (role == NumPagesRole) + return item->data(NumPages); + else if (role == CurrentPageRole) + return item->data(CurrentPage); + else if (role == ReadColumnRole) + return item->data(ReadColumn).toBool(); + else if (role == HasBeenOpenedRole) + return item->data(ComicModel::HasBeenOpened); + else if (role == IdRole) + return item->data(Id); + + if (role != Qt::DisplayRole) + return QVariant(); + + if(index.column() == ComicModel::Hash) + return QString::number(item->data(index.column()).toString().right(item->data(index.column()).toString().length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb"; + if(index.column() == ComicModel::ReadColumn) + return (item->data(ComicModel::CurrentPage).toInt()==item->data(ComicModel::NumPages).toInt() || item->data(ComicModel::ReadColumn).toBool())?QVariant(tr("yes")):QVariant(tr("no")); + if(index.column() == ComicModel::CurrentPage) + return item->data(ComicModel::HasBeenOpened).toBool()?item->data(index.column()):QVariant("-"); + + if (index.column() == ComicModel::Rating) + return QVariant(); + + return item->data(index.column()); +} + +Qt::ItemFlags ComicModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + if(index.column() == ComicModel::Rating) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled ; +} + +QVariant ComicModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch(section)//TODO obtener esto de la query + { + case ComicModel::Number: + return QVariant(QString("#")); + case ComicModel::Title: + return QVariant(QString(tr("Title"))); + case ComicModel::FileName: + return QVariant(QString(tr("File Name"))); + case ComicModel::NumPages: + return QVariant(QString(tr("Pages"))); + case ComicModel::Hash: + return QVariant(QString(tr("Size"))); + case ComicModel::ReadColumn: + return QVariant(QString(tr("Read"))); + case ComicModel::CurrentPage: + return QVariant(QString(tr("Current Page"))); + case ComicModel::Rating: + return QVariant(QString(tr("Rating"))); + } + } + + if (orientation == Qt::Horizontal && role == Qt::TextAlignmentRole) + { + switch(section)//TODO obtener esto de la query + { + case ComicModel::Number: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case ComicModel::NumPages: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case ComicModel::Hash: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case ComicModel::CurrentPage: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + default: + return QVariant(Qt::AlignLeft | Qt::AlignVCenter); + } + } + + + if(orientation == Qt::Vertical && role == Qt::DecorationRole) + { + QString fileName = _data.value(section)->data(ComicModel::FileName).toString(); + QFileInfo fi(fileName); + QString ext = fi.suffix(); + + if (ext.compare("cbr",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/comicRar.png")); + else if (ext.compare("cbz",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/comicZip.png")); + else if(ext.compare("pdf",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/pdf.png")); + else if (ext.compare("tar",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/tar.png")); + else if(ext.compare("zip",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/zip.png")); + else if(ext.compare("rar",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/rar.png")); +#ifndef use_unarr + else if (ext.compare("7z",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/7z.png")); + else if (ext.compare("cb7",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/comic7z.png")); +#endif + else if (ext.compare("cbt",Qt::CaseInsensitive) == 0) + return QVariant(QIcon(":/images/comicTar.png")); + + } + + return QVariant(); +} + +QModelIndex ComicModel::index(int row, int column, const QModelIndex &parent) + const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + return createIndex(row, column, _data.at(row)); +} + +QModelIndex ComicModel::parent(const QModelIndex &index) const +{ + Q_UNUSED(index) + return QModelIndex(); +} + +int ComicModel::rowCount(const QModelIndex &parent) const +{ + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + return _data.count(); + + return 0; +} + +QStringList ComicModel::getPaths(const QString & _source) +{ + QStringList paths; + QString source = _source + "/.yacreaderlibrary/covers/"; + QList::ConstIterator itr; + for(itr = _data.constBegin();itr != _data.constEnd();itr++) + { + QString hash = (*itr)->data(ComicModel::Hash).toString(); + paths << source+ hash +".jpg"; + } + + return paths; +} + +void ComicModel::setupFolderModelData(unsigned long long int folderId,const QString & databasePath) +{ + enableResorting = false; + mode = Folder; + sourceId=folderId; + + beginResetModel(); + qDeleteAll(_data); + _data.clear(); + + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "WHERE c.parentId = :parentId"); + selectQuery.bindValue(":parentId", folderId); + selectQuery.exec(); + setupModelData(selectQuery); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); + + /*if(_data.length()==0) + emit isEmpty();*/ +} + +void ComicModel::setupLabelModelData(unsigned long long parentLabel, const QString &databasePath) +{ + enableResorting = true; + mode = Label; + sourceId = parentLabel; + + beginResetModel(); + qDeleteAll(_data); + _data.clear(); + + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "INNER JOIN comic_label cl ON (c.id == cl.comic_id) " + "WHERE cl.label_id = :parentLabelId " + "ORDER BY cl.ordering"); + selectQuery.bindValue(":parentLabelId", parentLabel); + selectQuery.exec(); + setupModelDataForList(selectQuery); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); + + /*if(_data.length()==0) + emit isEmpty();*/ +} + +void ComicModel::setupReadingListModelData(unsigned long long parentReadingList, const QString &databasePath) +{ + mode = ReadingList; + sourceId = parentReadingList; + + beginResetModel(); + qDeleteAll(_data); + _data.clear(); + + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QList ids; + ids << parentReadingList; + + QSqlQuery subfolders(db); + subfolders.prepare("SELECT id " + "FROM reading_list " + "WHERE parentId = :parentId " + "ORDER BY ordering ASC"); + subfolders.bindValue(":parentId", parentReadingList); + subfolders.exec(); + while(subfolders.next()) + ids << subfolders.record().value(0).toULongLong(); + + enableResorting = ids.length()==1;//only resorting if no sublists exist + + + foreach(qulonglong id, ids) + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "INNER JOIN comic_reading_list crl ON (c.id == crl.comic_id) " + "WHERE crl.reading_list_id = :parentReadingList " + "ORDER BY crl.ordering"); + selectQuery.bindValue(":parentReadingList", id); + selectQuery.exec(); + + //TODO, extra information is needed (resorting) + QList tempData = _data; + _data.clear(); + + setupModelDataForList(selectQuery); + + _data = tempData << _data; + } + + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); +} + +void ComicModel::setupFavoritesModelData(const QString &databasePath) +{ + enableResorting = true; + mode = Favorites; + + beginResetModel(); + qDeleteAll(_data); + _data.clear(); + + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "INNER JOIN comic_default_reading_list cdrl ON (c.id == cdrl.comic_id) " + "WHERE cdrl.default_reading_list_id = :parentDefaultListId " + "ORDER BY cdrl.ordering"); + selectQuery.bindValue(":parentDefaultListId", 1); + selectQuery.exec(); + setupModelData(selectQuery); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); + + /*if(_data.length()==0) + emit isEmpty();*/ +} + +void ComicModel::setupReadingModelData(const QString &databasePath) +{ + enableResorting = false; + mode = Reading; + + beginResetModel(); + qDeleteAll(_data); + _data.clear(); + + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "WHERE ci.hasBeenOpened = 1 AND ci.read = 0 AND ci.currentPage != ci.numPages AND ci.currentPage != 1"); + selectQuery.exec(); + setupModelData(selectQuery); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); + + /*if(_data.length()==0) + emit isEmpty();*/ +} + +void ComicModel::setupModelData(const SearchModifiers modifier, const QString &filter, const QString &databasePath) +{ + //QFile f(QCoreApplication::applicationDirPath()+"/performance.txt"); + //f.open(QIODevice::Append); + beginResetModel(); + //QElapsedTimer timer; + //timer.start(); + qDeleteAll(_data); + _data.clear(); + + //QTextStream txtS(&f); + //txtS << "TABLEMODEL: Tiempo de borrado: " << timer.elapsed() << "ms\r\n"; + _databasePath = databasePath; + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + { + //crear la consulta + //timer.restart(); + QSqlQuery selectQuery(db); + + switch (modifier) { + case YACReader::NoModifiers: + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "WHERE UPPER(ci.title) LIKE UPPER(:filter) OR UPPER(c.fileName) LIKE UPPER(:filter) LIMIT :limit"); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + selectQuery.bindValue(":limit",500); //TODO, load this value from settings + break; + + case YACReader::OnlyRead: + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "WHERE (UPPER(ci.title) LIKE UPPER(:filter) OR UPPER(c.fileName) LIKE UPPER(:filter)) AND ci.read = 1 LIMIT :limit"); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + selectQuery.bindValue(":limit",500); //TODO, load this value from settings + break; + + case YACReader::OnlyUnread: + selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "WHERE (UPPER(ci.title) LIKE UPPER(:filter) OR UPPER(c.fileName) LIKE UPPER(:filter)) AND ci.read = 0 LIMIT :limit"); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + selectQuery.bindValue(":limit",500); //TODO, load this value from settings + break; + + default: + QLOG_ERROR() << "not implemented"; + break; + } + + + selectQuery.exec(); + + QLOG_DEBUG() << selectQuery.lastError() << "--"; + + //txtS << "TABLEMODEL: Tiempo de consulta: " << timer.elapsed() << "ms\r\n"; + //timer.restart(); + setupModelData(selectQuery); + //txtS << "TABLEMODEL: Tiempo de creaci�n del modelo: " << timer.elapsed() << "ms\r\n"; + //selectQuery.finish(); + } + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endResetModel(); + + emit searchNumResults(_data.length()); +} + +QString ComicModel::getComicPath(QModelIndex mi) +{ + if(mi.isValid()) + return _data.at(mi.row())->data(ComicModel::Path).toString(); + return ""; +} + +void ComicModel::setupModelData(QSqlQuery &sqlquery) +{ + ComicItem * currentItem; + while (sqlquery.next()) + { + QList data; + QSqlRecord record = sqlquery.record(); + for(int i=0;idata(ComicModel::FileName).toString(); + QString nameCurrent = currentItem->data(ComicModel::FileName).toString(); + int numberLast,numberCurrent; + int max = (std::numeric_limits::max)(); + numberLast = numberCurrent = max; + + if(!last->data(ComicModel::Number).isNull()) + numberLast = last->data(ComicModel::Number).toInt(); + + if(!currentItem->data(ComicModel::Number).isNull()) + numberCurrent = currentItem->data(ComicModel::Number).toInt(); + + QList::iterator i; + i = _data.end(); + i--; + + if(numberCurrent != max) //sort the current item by issue number + { + while ((lessThan =numberCurrent < numberLast) && i != _data.begin()) + { + i--; + numberLast = max; + + if(!(*i)->data(ComicModel::Number).isNull()) + numberLast = (*i)->data(ComicModel::Number).toInt(); + } + + if(lessThan) + _data.insert(i,currentItem); + else + { + if(numberCurrent == numberLast) + if(currentItem->data(ComicModel::IsBis).toBool()) + { + _data.insert(++i,currentItem); + } + else + _data.insert(i,currentItem); + else + _data.insert(++i,currentItem); + } + continue; + } + + else //sort the current item by title + { + while ((lessThan = naturalSortLessThanCI(nameCurrent,nameLast)) && i != _data.begin() && numberLast == max) + { + i--; + nameLast = (*i)->data(ComicModel::FileName).toString(); + numberLast = max; + + if(!(*i)->data(ComicModel::Number).isNull()) + numberLast = (*i)->data(ComicModel::Number).toInt(); + } + + if(numberLast != max) + _data.insert(++i,currentItem); + else + if(lessThan) + _data.insert(i,currentItem); + else + _data.insert(++i,currentItem); + continue; + + } + } + } +} + +//comics are sorted by "ordering", the sorting is done in the sql query +void ComicModel::setupModelDataForList(QSqlQuery &sqlquery) +{ + while (sqlquery.next()) + { + QList data; + QSqlRecord record = sqlquery.record(); + for(int i=0;idata(ComicModel::Id).toULongLong(),db); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + return c; +} + +ComicDB ComicModel::_getComic(const QModelIndex & mi) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + ComicDB c = DBHelper::loadComic(_data.at(mi.row())->data(ComicModel::Id).toULongLong(),db); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + return c; +} + + +QVector ComicModel::getReadList() +{ + int numComics = _data.count(); + QVector readList(numComics); + for(int i=0;idata(ComicModel::ReadColumn).toBool()) + readList[i] = YACReader::Read; + else if (_data.value(i)->data(ComicModel::CurrentPage).toInt() == _data.value(i)->data(ComicModel::NumPages).toInt()) + readList[i] = YACReader::Read; + else if (_data.value(i)->data(ComicModel::HasBeenOpened).toBool()) + readList[i] = YACReader::Opened; + else + readList[i] = YACReader::Unread; + } + return readList; +} +//TODO untested, this method is no longer used +QVector ComicModel::setAllComicsRead(YACReaderComicReadStatus read) +{ + return setComicsRead(persistentIndexList(),read); +} + +QList ComicModel::getAllComics() +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + db.transaction(); + + QList comics; + int numComics = _data.count(); + for(int i=0;idata(ComicModel::Id).toULongLong(),db)); + } + + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + return comics; +} + +QList ComicModel::getComics(QList list) +{ + QList comics; + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + db.transaction(); + QList::const_iterator itr; + for(itr = list.constBegin(); itr!= list.constEnd();itr++) + { + comics.append(_getComic(*itr)); + } + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + return comics; +} +//TODO +QVector ComicModel::setComicsRead(QList list,YACReaderComicReadStatus read) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + db.transaction(); + foreach (QModelIndex mi, list) + { + if(read == YACReader::Read) + { + _data.value(mi.row())->setData(ComicModel::ReadColumn, QVariant(true)); + ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(ComicModel::Id).toULongLong(),db); + c.info.read = true; + DBHelper::update(&(c.info),db); + } + if(read == YACReader::Unread) + { + _data.value(mi.row())->setData(ComicModel::ReadColumn, QVariant(false)); + _data.value(mi.row())->setData(ComicModel::CurrentPage, QVariant(1)); + _data.value(mi.row())->setData(ComicModel::HasBeenOpened, QVariant(false)); + ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(ComicModel::Id).toULongLong(),db); + c.info.read = false; + c.info.currentPage = 1; + c.info.hasBeenOpened = false; + DBHelper::update(&(c.info),db); + } + } + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + emit dataChanged(index(list.first().row(),ComicModel::ReadColumn),index(list.last().row(),ComicModel::HasBeenOpened),QVector() << ReadColumnRole << CurrentPageRole << HasBeenOpenedRole); + + return getReadList(); +} +qint64 ComicModel::asignNumbers(QList list,int startingNumber) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + db.transaction(); + qint64 idFirst = _data.value(list[0].row())->data(ComicModel::Id).toULongLong(); + int i = 0; + foreach (QModelIndex mi, list) + { + ComicDB c = DBHelper::loadComic(_data.value(mi.row())->data(ComicModel::Id).toULongLong(),db); + c.info.number = startingNumber+i; + c.info.edited = true; + DBHelper::update(&(c.info),db); + i++; + } + + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + //emit dataChanged(index(0,ComicModel::Number),index(_data.count()-1,ComicModel::HasBeenOpened)); + + return idFirst; +} +QModelIndex ComicModel::getIndexFromId(quint64 id) +{ + QList::ConstIterator itr; + int i=0; + for(itr = _data.constBegin();itr != _data.constEnd();itr++) + { + if((*itr)->data(ComicModel::Id).toULongLong() == id) + break; + i++; + } + + return index(i,0); +} + +//TODO completely inefficiently +QList ComicModel::getIndexesFromIds(const QList &comicIds) +{ + QList comicsIndexes; + + foreach(qulonglong id,comicIds) + comicsIndexes << getIndexFromId(id); + + return comicsIndexes; +} + +void ComicModel::startTransaction() +{ + + dbTransaction = DataBaseManagement::loadDatabase(_databasePath); + dbTransaction.transaction(); +} + +void ComicModel::finishTransaction() +{ + dbTransaction.commit(); + dbTransaction.close(); + QSqlDatabase::removeDatabase(_databasePath); +} + +void ComicModel::removeInTransaction(int row) +{ + ComicDB c = DBHelper::loadComic(_data.at(row)->data(ComicModel::Id).toULongLong(),dbTransaction); + + DBHelper::removeFromDB(&c,dbTransaction); + beginRemoveRows(QModelIndex(),row,row); + removeRow(row); + delete _data.at(row); + _data.removeAt(row); + + endRemoveRows(); +} + +void ComicModel::remove(ComicDB * comic, int row) +{ + beginRemoveRows(QModelIndex(),row,row); + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + DBHelper::removeFromDB(comic,db); + + removeRow(row); + delete _data.at(row); + _data.removeAt(row); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + endRemoveRows(); +} + +/*ComicDB TableModel::getComic(int row) +{ + return getComic(index(row,0)); +}*/ + +void ComicModel::remove(int row) +{ + removeInTransaction(row); +} + +void ComicModel::reload(const ComicDB & comic) +{ + int row = 0; + bool found = false; + foreach(ComicItem * item,_data) + { + if(item->data(ComicModel::Id).toULongLong() == comic.id) + { + found = true; + item->setData(ComicModel::ReadColumn,comic.info.read); + item->setData(ComicModel::CurrentPage,comic.info.currentPage); + item->setData(ComicModel::HasBeenOpened,true); + break; + + } + row++; + } + if(found) + emit dataChanged(index(row,ReadColumn),index(row,HasBeenOpened), QVector() << ReadColumnRole << CurrentPageRole << HasBeenOpenedRole); +} + +void ComicModel::resetComicRating(const QModelIndex &mi) +{ + ComicDB comic = getComic(mi); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + comic.info.rating = 0; + _data[mi.row()]->setData(ComicModel::Rating,0); + DBHelper::update(&(comic.info),db); + + emit dataChanged(mi,mi); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); +} + +void ComicModel::addComicsToFavorites(const QList &comicIds) +{ + addComicsToFavorites(getIndexesFromIds(comicIds)); +} + +void ComicModel::addComicsToFavorites(const QList & comicsList) +{ + QList comics = getComics(comicsList); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + DBHelper::insertComicsInFavorites(comics,db); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); +} + +void ComicModel::addComicsToLabel(const QList &comicIds, qulonglong labelId) +{ + addComicsToLabel(getIndexesFromIds(comicIds),labelId); +} + +void ComicModel::addComicsToLabel(const QList &comicsList, qulonglong labelId) +{ + QList comics = getComics(comicsList); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + DBHelper::insertComicsInLabel(comics,labelId,db); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); +} + +void ComicModel::addComicsToReadingList(const QList &comicIds, qulonglong readingListId) +{ + addComicsToReadingList(getIndexesFromIds(comicIds),readingListId); +} + +void ComicModel::addComicsToReadingList(const QList &comicsList, qulonglong readingListId) +{ + QList comics = getComics(comicsList); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + DBHelper::insertComicsInReadingList(comics,readingListId,db); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); +} + +void ComicModel::deleteComicsFromFavorites(const QList &comicsList) +{ + QList comics = getComics(comicsList); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + DBHelper::deleteComicsFromFavorites(comics,db); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + deleteComicsFromModel(comicsList); + +} + +void ComicModel::deleteComicsFromLabel(const QList &comicsList, qulonglong labelId) +{ + QList comics = getComics(comicsList); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + DBHelper::deleteComicsFromLabel(comics,labelId,db); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + deleteComicsFromModel(comicsList); +} + +void ComicModel::deleteComicsFromReadingList(const QList &comicsList, qulonglong readingListId) +{ + QList comics = getComics(comicsList); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + DBHelper::deleteComicsFromReadingList(comics,readingListId,db); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + deleteComicsFromModel(comicsList); +} + +void ComicModel::deleteComicsFromModel(const QList &comicsList) +{ + QListIterator it(comicsList); + it.toBack(); + while(it.hasPrevious()) + { + int row = it.previous().row(); + beginRemoveRows(QModelIndex(),row,row); + _data.removeAt(row); + endRemoveRows(); + } + + if(_data.isEmpty()) + emit isEmpty(); +} + + +void ComicModel::updateRating(int rating, QModelIndex mi) +{ + ComicDB comic = getComic(mi); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + //TODO optimize update + + comic.info.rating = rating; + _data[mi.row()]->setData(ComicModel::Rating,rating); + DBHelper::update(&(comic.info),db); + + emit dataChanged(mi,mi); + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); +} diff --git a/YACReaderLibrary/db/comic_model.h b/YACReaderLibrary/db/comic_model.h new file mode 100644 index 00000000..bd48038b --- /dev/null +++ b/YACReaderLibrary/db/comic_model.h @@ -0,0 +1,166 @@ +#ifndef TABLEMODEL_H +#define TABLEMODEL_H + +#include +#include +#include +#include +#include + +#include "yacreader_global.h" + +class ComicDB; + +class ComicItem; + +using namespace YACReader; + +//! [0] +class ComicModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + ComicModel(QObject *parent = 0); + ComicModel( QSqlQuery &sqlquery, QObject *parent = 0); + ~ComicModel(); + + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const; + bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + bool canBeResorted(); + QMimeData * mimeData(const QModelIndexList &indexes) const; + QStringList mimeTypes() const; + + void setupFolderModelData(unsigned long long int parentFolder,const QString & databasePath); + void setupLabelModelData(unsigned long long int parentLabel, const QString & databasePath); + void setupReadingListModelData(unsigned long long int parentReadingList, const QString & databasePath); + void setupFavoritesModelData(const QString & databasePath); + void setupReadingModelData(const QString & databasePath); + //configures the model for showing the comics matching the filter criteria. + void setupModelData(const SearchModifiers modifier, const QString & filter, const QString & databasePath); + + //Métodos de conveniencia + QStringList getPaths(const QString & _source); + QString getComicPath(QModelIndex mi); + QString getCurrentPath(){return QString(_databasePath).remove("/.yacreaderlibrary");} + ComicDB getComic(const QModelIndex & mi); //--> para la edición + //ComicDB getComic(int row); + QVector getReadList(); + QVector setAllComicsRead(YACReaderComicReadStatus readStatus); + QList getComics(QList list); //--> recupera la información común a los comics seleccionados + QList getAllComics(); + QModelIndex getIndexFromId(quint64 id); + QList getIndexesFromIds(const QList &comicIds); + //setcomicInfo(QModelIndex & mi); --> inserta en la base datos + //setComicInfoForAllComics(); --> inserta la información común a todos los cómics de una sola vez. + //setComicInfoForSelectedComis(QList list); -->inserta la información común para los comics seleccionados + QVector setComicsRead(QList list,YACReaderComicReadStatus read); + qint64 asignNumbers(QList list,int startingNumber); + void remove(ComicDB * comic, int row); + void removeInTransaction(int row); + void reload(const ComicDB & comic); + void resetComicRating(const QModelIndex & mi); + + + void addComicsToFavorites(const QList &comicsList); + void addComicsToLabel(const QList &comicsList, qulonglong labelId); + void addComicsToReadingList(const QList &comicsList, qulonglong readingListId); + + void deleteComicsFromFavorites(const QList &comicsList); + void deleteComicsFromLabel(const QList &comicsList, qulonglong labelId); + void deleteComicsFromReadingList(const QList &comicsList, qulonglong readingListId); + + void deleteComicsFromModel(const QList &comicsList); + + QHash roleNames() const; + + enum Columns { + Number = 0, + Title = 1, + FileName = 2, + NumPages = 3, + Id = 4, + Parent_Id = 5, + Path = 6, + Hash = 7, + ReadColumn = 8, + IsBis = 9, + CurrentPage = 10, + Rating = 11, + HasBeenOpened = 12 +}; + + enum Roles { + NumberRole = Qt::UserRole + 1, + TitleRole, + FileNameRole, + NumPagesRole, + IdRole, + Parent_IdRole, + PathRole, + HashRole, + ReadColumnRole, + IsBisRole, + CurrentPageRole, + RatingRole, + HasBeenOpenedRole, + CoverPathRole + + }; + + enum Mode { + Folder, + Favorites, + Reading, + Label, + ReadingList + }; + + + +public slots: + void remove(int row); + void startTransaction(); + void finishTransaction(); + void updateRating(int rating, QModelIndex mi); + + void addComicsToFavorites(const QList &comicIds); + void addComicsToLabel(const QList &comicIds, qulonglong labelId); + void addComicsToReadingList(const QList &comicIds, qulonglong readingListId); + +protected: + +private: + void setupModelData( QSqlQuery &sqlquery); + void setupModelDataForList(QSqlQuery &sqlquery); + ComicDB _getComic(const QModelIndex & mi); + QList _data; + + QString _databasePath; + + QSqlDatabase dbTransaction; + + bool enableResorting; + Mode mode; + qulonglong sourceId; + +signals: + void beforeReset(); + void reset(); + void isEmpty(); + void searchNumResults(int); + void resortedIndexes(QList); + void newSelectedIndex(const QModelIndex &); +}; +//! [0] + +#endif diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp new file mode 100644 index 00000000..e8052aee --- /dev/null +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -0,0 +1,790 @@ +#include "data_base_management.h" + +#include +#include "library_creator.h" +#include "check_new_version.h" + +static QString fields = "title ," + + "coverPage," + "numPages," + + "number," + "isBis," + "count," + + "volume," + "storyArc," + "arcNumber," + "arcCount," + + "genere," + + "writer," + "penciller," + "inker," + "colorist," + "letterer," + "coverArtist," + + "date," + "publisher," + "format," + "color," + "ageRating," + + "synopsis," + "characters," + "notes," + + "comicVineID," + + "hash" + ; + +DataBaseManagement::DataBaseManagement() + :QObject(),dataBasesList() +{ + +} + +/*TreeModel * DataBaseManagement::newTreeModel(QString path) +{ + //la consulta se ejecuta... + QSqlQuery selectQuery(loadDatabase(path)); + selectQuery.setForwardOnly(true); + selectQuery.exec("select * from folder order by parentId,name"); + //selectQuery.finish(); + return new TreeModel(selectQuery); +}*/ + +QSqlDatabase DataBaseManagement::createDatabase(QString name, QString path) +{ + return createDatabase(QDir::cleanPath(path) + "/" + name + ".ydb"); +} + +QSqlDatabase DataBaseManagement::createDatabase(QString dest) +{ + QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE",dest); + db.setDatabaseName(dest); + if (!db.open()) + qDebug() << db.lastError(); + else { + qDebug() << db.tables(); + } + + { + QSqlQuery pragma("PRAGMA foreign_keys = ON",db); + //pragma.finish(); + DataBaseManagement::createTables(db); + + QSqlQuery query("INSERT INTO folder (parentId, name, path) " + "VALUES (1,'root', '/')",db); + } + //query.finish(); + //db.close(); + + return db; +} + +QSqlDatabase DataBaseManagement::loadDatabase(QString path) +{ + //TODO check path + QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE",path); + db.setDatabaseName(path+"/library.ydb"); + if (!db.open()) { + //se devuelve una base de datos vacía e inválida + + return QSqlDatabase(); + } + QSqlQuery pragma("PRAGMA foreign_keys = ON",db); + //pragma.finish(); + //devuelve la base de datos + return db; +} + +QSqlDatabase DataBaseManagement::loadDatabaseFromFile(QString filePath) +{ + //TODO check path + QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE",filePath); + db.setDatabaseName(filePath); + if (!db.open()) { + //se devuelve una base de datos vacía e inválida + + return QSqlDatabase(); + } + { + QSqlQuery pragma("PRAGMA foreign_keys = ON",db); + } + //pragma.finish(); + //devuelve la base de datos + return db; +} + +bool DataBaseManagement::createTables(QSqlDatabase & database) +{ + bool success = true; + + //FOLDER (representa una carpeta en disco) + { + QSqlQuery queryFolder(database); + queryFolder.prepare("CREATE TABLE folder (" + "id INTEGER PRIMARY KEY," + "parentId INTEGER NOT NULL," + "name TEXT NOT NULL," + "path TEXT NOT NULL," + //new 7.1 fields + "finished BOOLEAN DEFAULT 0," //reading + "completed BOOLEAN DEFAULT 1," //collecting + //-- + "FOREIGN KEY(parentId) REFERENCES folder(id) ON DELETE CASCADE)"); + success = success && queryFolder.exec(); + + //COMIC INFO (representa la información de un cómic, cada cómic tendrá un idéntificador único formado por un hash sha1'de los primeros 512kb' + su tamaño en bytes) + QSqlQuery queryComicInfo(database); + queryComicInfo.prepare("CREATE TABLE comic_info (" + "id INTEGER PRIMARY KEY," + "title TEXT," + + "coverPage INTEGER DEFAULT 1," + "numPages INTEGER," + + "number INTEGER," + "isBis BOOLEAN," + "count INTEGER," + + "volume TEXT," + "storyArc TEXT," + "arcNumber INTEGER," + "arcCount INTEGER," + + "genere TEXT," + + "writer TEXT," + "penciller TEXT," + "inker TEXT," + "colorist TEXT," + "letterer TEXT," + "coverArtist TEXT," + + "date TEXT," //dd/mm/yyyy --> se mostrará en 3 campos diferentes + "publisher TEXT," + "format TEXT," + "color BOOLEAN," + "ageRating BOOLEAN," + + "synopsis TEXT," + "characters TEXT," + "notes TEXT," + + "hash TEXT UNIQUE NOT NULL," + "edited BOOLEAN DEFAULT 0," + "read BOOLEAN DEFAULT 0," +//new 7.0 fields + + "hasBeenOpened BOOLEAN DEFAULT 0," + "rating INTEGER DEFAULT 0," + "currentPage INTEGER DEFAULT 1, " + "bookmark1 INTEGER DEFAULT -1, " + "bookmark2 INTEGER DEFAULT -1, " + "bookmark3 INTEGER DEFAULT -1, " + "brightness INTEGER DEFAULT -1, " + "contrast INTEGER DEFAULT -1, " + "gamma INTEGER DEFAULT -1, " +//new 7.1 fields + "comicVineID TEXT" + + ")"); + success = success && queryComicInfo.exec(); + //queryComicInfo.finish(); + + //COMIC (representa un cómic en disco, contiene el nombre de fichero) + QSqlQuery queryComic(database); + queryComic.prepare("CREATE TABLE comic (id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, comicInfoId INTEGER NOT NULL, fileName TEXT NOT NULL, path TEXT, FOREIGN KEY(parentId) REFERENCES folder(id) ON DELETE CASCADE, FOREIGN KEY(comicInfoId) REFERENCES comic_info(id))"); + success = success && queryComic.exec(); + //queryComic.finish(); + //DB INFO + QSqlQuery queryDBInfo(database); + queryDBInfo.prepare("CREATE TABLE db_info (version TEXT NOT NULL)"); + success = success && queryDBInfo.exec(); + //queryDBInfo.finish(); + + QSqlQuery query("INSERT INTO db_info (version) " + "VALUES ('" VERSION "')",database); + //query.finish(); + + //8.0> tables + success = success && DataBaseManagement::createV8Tables(database); + + } + + return success; +} + +bool DataBaseManagement::createV8Tables(QSqlDatabase &database) +{ + bool success = true; + { + //8.0> tables + //LABEL + QSqlQuery queryLabel(database); + success = success && queryLabel.exec("CREATE TABLE label (id INTEGER PRIMARY KEY, " + "name TEXT NOT NULL, " + "color TEXT NOT NULL, " + "ordering INTEGER NOT NULL); "); //order depends on the color + + QSqlQuery queryIndexLabel(database); + success = success && queryIndexLabel.exec("CREATE INDEX label_ordering_index ON label (ordering)"); + + //COMIC LABEL + QSqlQuery queryComicLabel(database); + success = success && queryComicLabel.exec("CREATE TABLE comic_label (" + "comic_id INTEGER, " + "label_id INTEGER, " + "ordering INTEGER, " //TODO order???? + "FOREIGN KEY(label_id) REFERENCES label(id) ON DELETE CASCADE, " + "FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE, " + "PRIMARY KEY(label_id, comic_id))"); + + QSqlQuery queryIndexComicLabel(database); + success = success && queryIndexComicLabel.exec("CREATE INDEX comic_label_ordering_index ON label (ordering)"); + + //READING LIST + QSqlQuery queryReadingList(database); + success = success && queryReadingList.exec("CREATE TABLE reading_list (" + "id INTEGER PRIMARY KEY, " + "parentId INTEGER, " + "ordering INTEGER DEFAULT 0, " //only use it if the parentId is NULL + "name TEXT NOT NULL, " + "finished BOOLEAN DEFAULT 0, " + "completed BOOLEAN DEFAULT 1, " + "FOREIGN KEY(parentId) REFERENCES reading_list(id) ON DELETE CASCADE)"); + + QSqlQuery queryIndexReadingList(database); + success = success && queryIndexReadingList.exec("CREATE INDEX reading_list_ordering_index ON label (ordering)"); + + //COMIC READING LIST + QSqlQuery queryComicReadingList(database); + success = success && queryComicReadingList.exec("CREATE TABLE comic_reading_list (" + "reading_list_id INTEGER, " + "comic_id INTEGER, " + "ordering INTEGER, " + "FOREIGN KEY(reading_list_id) REFERENCES reading_list(id) ON DELETE CASCADE, " + "FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE, " + "PRIMARY KEY(reading_list_id, comic_id))"); + + QSqlQuery queryIndexComicReadingList(database); + success = success && queryIndexComicReadingList.exec("CREATE INDEX comic_reading_list_ordering_index ON label (ordering)"); + + //DEFAULT READING LISTS + QSqlQuery queryDefaultReadingList(database); + success = success && queryDefaultReadingList.exec("CREATE TABLE default_reading_list (" + "id INTEGER PRIMARY KEY, " + "name TEXT NOT NULL" + //TODO icon???? + ")"); + + //COMIC DEFAULT READING LISTS + QSqlQuery queryComicDefaultReadingList(database); + success = success && queryComicDefaultReadingList.exec("CREATE TABLE comic_default_reading_list (" + "comic_id INTEGER, " + "default_reading_list_id INTEGER, " + "ordering INTEGER, " //order???? + "FOREIGN KEY(default_reading_list_id) REFERENCES default_reading_list(id) ON DELETE CASCADE, " + "FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE," + "PRIMARY KEY(default_reading_list_id, comic_id))"); + + QSqlQuery queryIndexComicDefaultReadingList(database); + success = success && queryIndexComicDefaultReadingList.exec("CREATE INDEX comic_default_reading_list_ordering_index ON label (ordering)"); + + //INSERT DEFAULT READING LISTS + QSqlQuery queryInsertDefaultReadingList(database); + //if(!queryInsertDefaultReadingList.prepare()) + + //1 Favorites + //queryInsertDefaultReadingList.bindValue(":name", "Favorites"); + success = success && queryInsertDefaultReadingList.exec("INSERT INTO default_reading_list (name) VALUES (\"Favorites\")"); + + //Reading doesn't need its onw list + + } + return success; +} + +#include +void DataBaseManagement::exportComicsInfo(QString source, QString dest) +{ + //QSqlDatabase sourceDB = loadDatabase(source); + QSqlDatabase destDB = loadDatabaseFromFile(dest); + //sourceDB.open(); + { + QSqlQuery attach(destDB); + attach.prepare("ATTACH DATABASE '"+QDir().toNativeSeparators(dest) +"' AS dest;"); + //attach.bindValue(":dest",QDir().toNativeSeparators(dest)); + attach.exec(); + //attach.finish(); + + QSqlQuery attach2(destDB); + attach2.prepare("ATTACH DATABASE '"+QDir().toNativeSeparators(source) +"' AS source;"); + attach2.exec(); + //attach2.finish(); + + //sourceDB.close(); + QSqlQuery queryDBInfo(destDB); + queryDBInfo.prepare("CREATE TABLE dest.db_info (version TEXT NOT NULL)"); + queryDBInfo.exec(); + //queryDBInfo.finish(); + + /*QSqlQuery queryComicsInfo(sourceDB); + queryComicsInfo.prepare("CREATE TABLE dest.comic_info (id INTEGER PRIMARY KEY, hash TEXT NOT NULL, edited BOOLEAN DEFAULT FALSE, title TEXT, read BOOLEAN)"); + queryComicsInfo.exec();*/ + + QSqlQuery query("INSERT INTO dest.db_info (version) " + "VALUES ('" VERSION "')",destDB); + //query.finish(); + + QSqlQuery exportData(destDB); + exportData.prepare("create table dest.comic_info as select " + fields + + " from source.comic_info where source.comic_info.edited = 1"); + exportData.exec(); + //exportData.finish(); + } + + //sourceDB.close(); + destDB.close(); + QSqlDatabase::removeDatabase(dest); + +} + +bool DataBaseManagement::importComicsInfo(QString source, QString dest) +{ + QString error; + QString driver; + QStringList hashes; + + bool b = false; + + QSqlDatabase sourceDB = loadDatabaseFromFile(source); + QSqlDatabase destDB = loadDatabaseFromFile(dest); + + { + QSqlQuery pragma("PRAGMA synchronous=OFF",destDB); + + + QSqlQuery newInfo(sourceDB); + newInfo.prepare("SELECT * FROM comic_info"); + newInfo.exec(); + destDB.transaction(); + int cp; + while (newInfo.next()) //cada tupla deberá ser insertada o actualizada + { + QSqlQuery update(destDB); + update.prepare("UPDATE comic_info SET " + "title = :title," + + "coverPage = :coverPage," + "numPages = :numPages," + + "number = :number," + "isBis = :isBis," + "count = :count," + + "volume = :volume," + "storyArc = :storyArc," + "arcNumber = :arcNumber," + "arcCount = :arcCount," + + "genere = :genere," + + "writer = :writer," + "penciller = :penciller," + "inker = :inker," + "colorist = :colorist," + "letterer = :letterer," + "coverArtist = :coverArtist," + + "date = :date," + "publisher = :publisher," + "format = :format," + "color = :color," + "ageRating = :ageRating," + + "synopsis = :synopsis," + "characters = :characters," + "notes = :notes," + + "edited = :edited," + + "comicVineID = :comicVineID" + + " WHERE hash = :hash "); + + QSqlQuery insert(destDB); + insert.prepare("INSERT INTO comic_info " + "(title," + "coverPage," + "numPages," + "number," + "isBis," + "count," + "volume," + "storyArc," + "arcNumber," + "arcCount," + "genere," + "writer," + "penciller," + "inker," + "colorist," + "letterer," + "coverArtist," + "date," + "publisher," + "format," + "color," + "ageRating," + "synopsis," + "characters," + "notes," + "read," + "edited," + "comicVineID," + "hash)" + + "VALUES (:title," + ":coverPage," + ":numPages," + ":number," + ":isBis," + ":count," + + ":volume," + ":storyArc," + ":arcNumber," + ":arcCount," + + ":genere," + + ":writer," + ":penciller," + ":inker," + ":colorist," + ":letterer," + ":coverArtist," + + ":date," + ":publisher," + ":format," + ":color," + ":ageRating," + + ":synopsis," + ":characters," + ":notes," + + ":read," + ":edited," + ":comicVineID," + + ":hash )"); + + QSqlRecord record = newInfo.record(); + cp = record.value("coverPage").toInt(); + if(cp>1) + { + QSqlQuery checkCoverPage(destDB); + checkCoverPage.prepare("SELECT coverPage FROM comic_info where hash = :hash"); + checkCoverPage.bindValue(":hash",record.value("hash").toString()); + checkCoverPage.exec(); + bool extract = false; + if(checkCoverPage.next()) + { + extract = checkCoverPage.record().value("coverPage").toInt() != cp; + } + if(extract) + hashes.append(record.value("hash").toString()); + } + + bindValuesFromRecord(record,update); + + update.bindValue(":edited",1); + + + update.exec(); + + if(update.numRowsAffected() == 0) + { + + bindValuesFromRecord(record,insert); + insert.bindValue(":edited",1); + insert.bindValue(":read",0); + + insert.exec(); + + QString error1 = insert.lastError().databaseText(); + QString error2 = insert.lastError().driverText(); + + //QMessageBox::critical(NULL,"db",error1); + //QMessageBox::critical(NULL,"driver",error2); + } + //update.finish(); + //insert.finish(); + } + } + + destDB.commit(); + QString hash; + foreach(hash, hashes) + { + QSqlQuery getComic(destDB); + getComic.prepare("SELECT c.path,ci.coverPage FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) where ci.hash = :hash"); + getComic.bindValue(":hash",hash); + getComic.exec(); + if(getComic.next()) + { + QString basePath = QString(dest).remove("/.yacreaderlibrary/library.ydb"); + QString path = basePath + getComic.record().value("path").toString(); + int coverPage = getComic.record().value("coverPage").toInt(); + ThumbnailCreator tc(path,basePath+"/.yacreaderlibrary/covers/"+hash+".jpg",coverPage); + tc.create(); + + } + } + + destDB.close(); + sourceDB.close(); + QSqlDatabase::removeDatabase(source); + QSqlDatabase::removeDatabase(dest); + return b; + +} +//TODO fix these bindings +void DataBaseManagement::bindValuesFromRecord(const QSqlRecord & record, QSqlQuery & query) +{ + bindString("title",record,query); + + bindInt("coverPage",record,query); + bindInt("numPages",record,query); + + bindInt("number",record,query); + bindInt("isBis",record,query); + bindInt("count",record,query); + + bindString("volume",record,query); + bindString("storyArc",record,query); + bindInt("arcNumber",record,query); + bindInt("arcCount",record,query); + + bindString("genere",record,query); + + bindString("writer",record,query); + bindString("penciller",record,query); + bindString("inker",record,query); + bindString("colorist",record,query); + bindString("letterer",record,query); + bindString("coverArtist",record,query); + + bindString("date",record,query); + bindString("publisher",record,query); + bindString("format",record,query); + bindInt("color",record,query); + bindString("ageRating",record,query); + + bindString("synopsis",record,query); + bindString("characters",record,query); + bindString("notes",record,query); + + bindString("comicVineID",record,query); + + bindString("hash",record,query); +} + +bool DataBaseManagement::addColumns(const QString &tableName, const QStringList &columnDefs, const QSqlDatabase &db) +{ + QString sql = "ALTER TABLE %1 ADD COLUMN %2"; + bool returnValue = true; + + foreach(QString columnDef, columnDefs) + { + QSqlQuery alterTable(db); + alterTable.prepare(sql.arg(tableName).arg(columnDef)); + //alterTableComicInfo.bindValue(":column_def",columnDef); + alterTable.exec(); + returnValue = returnValue && (alterTable.numRowsAffected() > 0); + } + + return returnValue; +} + +void DataBaseManagement::bindString(const QString & name, const QSqlRecord & record, QSqlQuery & query) +{ + if(!record.value(name).isNull()) + { + query.bindValue(":"+name,record.value(name).toString()); + } +} +void DataBaseManagement::bindInt(const QString & name, const QSqlRecord & record, QSqlQuery & query) +{ + if(!record.value(name).isNull()) + { + query.bindValue(":"+name,record.value(name).toInt()); + } +} + +QString DataBaseManagement::checkValidDB(const QString & fullPath) +{ + QSqlDatabase db = loadDatabaseFromFile(fullPath); + QString versionString = ""; + if(db.isValid() && db.isOpen()) + { + QSqlQuery version(db); + version.prepare("SELECT * FROM db_info"); + version.exec(); + + if(version.next()) + versionString = version.record().value("version").toString(); + } + + db.close(); + QSqlDatabase::removeDatabase(fullPath); + return versionString; +} + +int DataBaseManagement::compareVersions(const QString & v1, const QString v2) +{ + QStringList v1l = v1.split('.'); + QStringList v2l = v2.split('.'); + QList v1il; + QList v2il; + + foreach(QString s, v1l) + v1il.append(s.toInt()); + + foreach(QString s,v2l) + v2il.append(s.toInt()); + + for(int i=0;iv2il[i]) + return 1; + } + + if(v1il.length() < v2il.length()) + return -1; + if(v1il.length() == v2il.length()) + return 0; + if(v1il.length() > v2il.length()) + return 1; + + return 0; +} + +bool DataBaseManagement::updateToCurrentVersion(const QString & fullPath) +{ + bool pre7 = false; + bool pre7_1 = false; + bool pre8 = false; + + if(compareVersions(DataBaseManagement::checkValidDB(fullPath),"7.0.0")<0) + pre7 = true; + if(compareVersions(DataBaseManagement::checkValidDB(fullPath),"7.0.3")<0) + pre7_1 = true; + if(compareVersions(DataBaseManagement::checkValidDB(fullPath),"8.0.0")<0) + pre8 = true; + + QSqlDatabase db = loadDatabaseFromFile(fullPath); + bool returnValue = false; + if(db.isValid() && db.isOpen()) + { + QSqlQuery updateVersion(db); + updateVersion.prepare("UPDATE db_info SET " + "version = :version"); + updateVersion.bindValue(":version",VERSION); + updateVersion.exec(); + + if(updateVersion.numRowsAffected() > 0) + returnValue = true; + + if(pre7) //TODO: execute only if previous version was < 7.0 + { + //new 7.0 fields + QStringList columnDefs; + columnDefs << "hasBeenOpened BOOLEAN DEFAULT 0" + << "rating INTEGER DEFAULT 0" + << "currentPage INTEGER DEFAULT 1" + << "bookmark1 INTEGER DEFAULT -1" + << "bookmark2 INTEGER DEFAULT -1" + << "bookmark3 INTEGER DEFAULT -1" + << "brightness INTEGER DEFAULT -1" + << "contrast INTEGER DEFAULT -1" + << "gamma INTEGER DEFAULT -1"; + + returnValue = returnValue && addColumns("comic_info", columnDefs, db); + } + //TODO update hasBeenOpened value + + if(pre7_1) + { + { + QStringList columnDefs; + columnDefs << "finished BOOLEAN DEFAULT 0" + << "completed BOOLEAN DEFAULT 1"; + returnValue = returnValue && addColumns("folder", columnDefs, db); + } + + {//comic_info + QStringList columnDefs; + columnDefs << "comicVineID TEXT DEFAULT NULL"; + returnValue = returnValue && addColumns("comic_info", columnDefs, db); + } + } + + if(pre8) + { + returnValue = returnValue && createV8Tables(db); + } + } + + db.close(); + QSqlDatabase::removeDatabase(fullPath); + return returnValue; +} + +//COMICS_INFO_EXPORTER +ComicsInfoExporter::ComicsInfoExporter() +:QThread() +{ +} + +void ComicsInfoExporter::exportComicsInfo(QSqlDatabase & source, QSqlDatabase & dest) +{ + Q_UNUSED(source) + Q_UNUSED(dest) + //TODO check this method +} + +void ComicsInfoExporter::run() +{ + +} + + +//COMICS_INFO_IMPORTER +ComicsInfoImporter::ComicsInfoImporter() +:QThread() +{ +} + +void ComicsInfoImporter::importComicsInfo(QSqlDatabase & source, QSqlDatabase & dest) +{ + Q_UNUSED(source) + Q_UNUSED(dest) + //TODO check this method +} + +void ComicsInfoImporter::run() +{ + +} diff --git a/YACReaderLibrary/db/data_base_management.h b/YACReaderLibrary/db/data_base_management.h new file mode 100644 index 00000000..68540339 --- /dev/null +++ b/YACReaderLibrary/db/data_base_management.h @@ -0,0 +1,62 @@ +#ifndef __DATA_BASE_MANAGEMENT_H +#define __DATA_BASE_MANAGEMENT_H + +#include +#include +#include + +#include "folder_model.h" + +class ComicsInfoExporter : public QThread +{ + Q_OBJECT +public: + ComicsInfoExporter(); + void exportComicsInfo(QSqlDatabase & source, QSqlDatabase & dest); +private: + void run(); +}; + +class ComicsInfoImporter : public QThread +{ + Q_OBJECT +public: + ComicsInfoImporter(); + void importComicsInfo(QSqlDatabase & source, QSqlDatabase & dest); +private: + void run(); + +}; + +class DataBaseManagement : public QObject +{ + Q_OBJECT +private: + QList dataBasesList; + static void bindString(const QString & name, const QSqlRecord & record, QSqlQuery & query); + static void bindInt(const QString & name, const QSqlRecord & record, QSqlQuery & query); + static void bindValuesFromRecord(const QSqlRecord & record, QSqlQuery & query); + + static bool addColumns(const QString & tableName, const QStringList & columnDefs, const QSqlDatabase & db); + +public: + DataBaseManagement(); + //TreeModel * newTreeModel(QString path); + //crea una base de datos y todas sus tablas + static QSqlDatabase createDatabase(QString name, QString path); + static QSqlDatabase createDatabase(QString dest); + //carga una base de datos desde la ruta path + static QSqlDatabase loadDatabase(QString path); + static QSqlDatabase loadDatabaseFromFile(QString path); + static bool createTables(QSqlDatabase & database); + static bool createV8Tables(QSqlDatabase & database); + + static void exportComicsInfo(QString source, QString dest); + static bool importComicsInfo(QString source, QString dest); + + static QString checkValidDB(const QString & fullPath); //retorna "" si la DB es inválida ó la versión si es válida. + static int compareVersions(const QString & v1, const QString v2); //retorna <0 si v1 < v2, 0 si v1 = v2 y >0 si v1 > v2 + static bool updateToCurrentVersion(const QString & path); +}; + +#endif diff --git a/YACReaderLibrary/db/folder_item.cpp b/YACReaderLibrary/db/folder_item.cpp new file mode 100644 index 00000000..069147f3 --- /dev/null +++ b/YACReaderLibrary/db/folder_item.cpp @@ -0,0 +1,103 @@ +#include + +#include "folder_item.h" +#include "qnaturalsorting.h" + +FolderItem::FolderItem(const QList &data, FolderItem *parent) +{ + parentItem = parent; + itemData = data; +} + +FolderItem::~FolderItem() +{ + qDeleteAll(childItems); +} + +void FolderItem::appendChild(FolderItem *item) +{ + item->parentItem = this; + + if(childItems.isEmpty()) + childItems.append(item); + else + { + FolderItem * last = childItems.back(); + QString nameLast = last->data(1).toString(); //TODO usar info name si est� disponible, sino el nombre del fichero..... + QString nameCurrent = item->data(1).toString(); + QList::iterator i; + i = childItems.end(); + i--; + while (naturalSortLessThanCI(nameCurrent,nameLast) && i != childItems.begin()) + { + i--; + nameLast = (*i)->data(1).toString(); + } + if(!naturalSortLessThanCI(nameCurrent,nameLast)) //si se ha encontrado un elemento menor que current, se inserta justo despu�s + childItems.insert(++i,item); + else + childItems.insert(i,item); + + } + + //childItems.append(item); +} + +FolderItem *FolderItem::child(int row) +{ + return childItems.value(row); +} + +int FolderItem::childCount() const +{ + return childItems.count(); +} + +int FolderItem::columnCount() const +{ + return itemData.count(); +} + +QVariant FolderItem::data(int column) const +{ + return itemData.value(column); +} + +void FolderItem::setData(int column, const QVariant & value) +{ + itemData[column] = value; +} + +void FolderItem::removeChild(int childIndex) +{ + childItems.removeAt(childIndex); +} + +void FolderItem::clearChildren() +{ + qDeleteAll(childItems); + childItems.clear(); +} + +QList FolderItem::children() +{ + return childItems; +} + +FolderItem *FolderItem::parent() +{ + return parentItem; +} + +int FolderItem::row() const +{ + if (parentItem) + return parentItem->childItems.indexOf(const_cast(this)); + + return 0; +} + +QList FolderItem::getData() const +{ + return itemData; +} diff --git a/YACReaderLibrary/db/folder_item.h b/YACReaderLibrary/db/folder_item.h new file mode 100644 index 00000000..f0841c0f --- /dev/null +++ b/YACReaderLibrary/db/folder_item.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TREEITEM_H +#define TREEITEM_H + +#include +#include +#include + +class FolderItem +{ +public: + FolderItem(const QList &data, FolderItem *parent = 0); + ~FolderItem(); + + void appendChild(FolderItem *child); + + FolderItem *child(int row); + int childCount() const; + int columnCount() const; + QVariant data(int column) const; + QList getData() const; + int row() const; + FolderItem *parent(); + FolderItem *parentItem; + unsigned long long int id; + QList comicNames; + FolderItem * originalItem; + void setData(int column, const QVariant &value); + void removeChild(int childIndex); + void clearChildren(); + QList children(); +private: + QList childItems; + QList itemData; +}; +//! [0] + +#endif diff --git a/YACReaderLibrary/db/folder_model.cpp b/YACReaderLibrary/db/folder_model.cpp new file mode 100644 index 00000000..10420299 --- /dev/null +++ b/YACReaderLibrary/db/folder_model.cpp @@ -0,0 +1,784 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + treemodel.cpp + + Provides a simple tree model to show how to create and use hierarchical + models. +*/ + +#include + + +#include "folder_item.h" +#include "folder_model.h" +#include "data_base_management.h" +#include "folder.h" +#include "db_helper.h" +#include "qnaturalsorting.h" +#include "yacreader_global.h" +#include "QsLog.h" + +#ifdef Q_OS_MAC +#include +QIcon finishedFolderIcon; +void drawMacOSXFinishedFolderIcon() +{ + QIcon ico = QFileIconProvider().icon(QFileIconProvider::Folder); + QPixmap pixNormalOff = ico.pixmap(16,16, QIcon::Normal, QIcon::Off); + QPixmap pixNormalOn = ico.pixmap(16,16, QIcon::Normal, QIcon::On); + QPixmap pixSelectedOff = ico.pixmap(16,16, QIcon::Selected, QIcon::Off); + QPixmap pixSelectedOn = ico.pixmap(16,16, QIcon::Selected, QIcon::On); + QPixmap tick(":/images/folder_finished_macosx.png"); + + + { + QPainter p(&pixNormalOff); + p.drawPixmap(4,7,tick); + } + finishedFolderIcon.addPixmap(pixNormalOff, QIcon::Normal, QIcon::Off); + + { + QPainter p(&pixNormalOn); + p.drawPixmap(4,7,tick); + } + finishedFolderIcon.addPixmap(pixNormalOn, QIcon::Normal, QIcon::On); + + { + QPainter p(&pixSelectedOff); + p.drawPixmap(4,7,tick); + } + finishedFolderIcon.addPixmap(pixSelectedOff, QIcon::Selected, QIcon::Off); + + { + QPainter p(&pixSelectedOn); + p.drawPixmap(4,7,tick); + } + finishedFolderIcon.addPixmap(pixSelectedOn, QIcon::Selected, QIcon::On); +} +#endif + +#define ROOT 1 + +FolderModel::FolderModel(QObject *parent) + : QAbstractItemModel(parent),rootItem(0) +{ + connect(this,SIGNAL(beforeReset()),this,SIGNAL(modelAboutToBeReset())); + connect(this,SIGNAL(reset()),this,SIGNAL(modelReset())); +} + +//! [0] +FolderModel::FolderModel( QSqlQuery &sqlquery, QObject *parent) + : QAbstractItemModel(parent),rootItem(0) +{ + //lo m�s probable es que el nodo ra�z no necesite tener informaci�n + QList rootData; + rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem) + rootItem = new FolderItem(rootData); + rootItem->id = ROOT; + rootItem->parentItem = 0; + setupModelData(sqlquery, rootItem); + //sqlquery.finish(); +} +//! [0] + +//! [1] +FolderModel::~FolderModel() +{ + if(rootItem != 0) + delete rootItem; +} +//! [1] + +//! [2] +int FolderModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return rootItem->columnCount(); +} +//! [2] + +//! [3] +QVariant FolderModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + FolderItem *item = static_cast(index.internalPointer()); + + if (role == Qt::DecorationRole) + +#ifdef Q_OS_MAC + if(item->data(FolderModel::Finished).toBool()){ + if(finishedFolderIcon.isNull()){ + drawMacOSXFinishedFolderIcon(); + } + + return QVariant(finishedFolderIcon); + } + else { + return QVariant(QFileIconProvider().icon(QFileIconProvider::Folder)); + } +#else + if(item->data(FolderModel::Finished).toBool()) + return QVariant(YACReader::noHighlightedIcon(":/images/sidebar/folder_finished.png")); + else + return QVariant(YACReader::noHighlightedIcon(":/images/sidebar/folder.png")); +#endif + + if(role == FolderModel::CompletedRole) + return item->data(FolderModel::Completed); + + if(role == FolderModel::FinishedRole) + return item->data(FolderModel::Finished); + + if (role != Qt::DisplayRole) + return QVariant(); + + + + return item->data(index.column()); +} +//! [3] + +//! [4] +Qt::ItemFlags FolderModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled; +} +//! [4] + +//! [5] +QVariant FolderModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return rootItem->data(section); + + return QVariant(); +} +//! [5] + +//! [6] +QModelIndex FolderModel::index(int row, int column, const QModelIndex &parent) + const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + FolderItem *parentItem; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + FolderItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} +//! [6] + +//! [7] +QModelIndex FolderModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + return QModelIndex(); + + FolderItem *childItem = static_cast(index.internalPointer()); + FolderItem *parentItem = childItem->parent(); + + if (parentItem == rootItem) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); +} +//! [7] + +/* +QModelIndex FolderModel::indexFromItem(FolderItem * item,int column) +{ + //if(item->parent() != 0) + // return index(item->row(),column,parent(indexFromItem(item->parent(),column-1))); + //else + // return index(item->row(),0,QModelIndex()); + return createIndex(item->row(), column, item); +}*/ + + +//! [8] +int FolderModel::rowCount(const QModelIndex &parent) const +{ + FolderItem *parentItem; + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + return parentItem->childCount(); +} +//! [8] + +void FolderModel::setupModelData(QString path) +{ + beginResetModel(); + if(rootItem != 0) + delete rootItem; //TODO comprobar que se libera bien la memoria + + rootItem = 0; + + //inicializar el nodo ra�z + QList rootData; + rootData << "root"; //id 0, padre 0, title "root" (el id, y el id del padre van a ir en la clase TreeItem) + rootItem = new FolderItem(rootData); + rootItem->id = ROOT; + rootItem->parentItem = 0; + + //cargar la base de datos + _databasePath = path; + QSqlDatabase db = DataBaseManagement::loadDatabase(path); + //crear la consulta + { + QSqlQuery selectQuery("select * from folder where id <> 1 order by parentId,name",db); + + setupModelData(selectQuery,rootItem); + } + //selectQuery.finish(); + db.close(); + QSqlDatabase::removeDatabase(path); + endResetModel(); + +} + + +void FolderModel::setupModelData(QSqlQuery &sqlquery, FolderItem *parent) +{ + //64 bits para la primary key, es decir la misma precisi�n que soporta sqlit 2^64 + //el diccionario permitir� encontrar cualquier nodo del �rbol r�pidamente, de forma que a�adir un hijo a un padre sea O(1) + items.clear(); + //se a�ade el nodo 0 + items.insert(parent->id,parent); + + while (sqlquery.next()) { + QList data; + QSqlRecord record = sqlquery.record(); + + data << record.value("name").toString(); + data << record.value("path").toString(); + data << record.value("finished").toBool(); + data << record.value("completed").toBool(); + FolderItem * item = new FolderItem(data); + + item->id = record.value("id").toULongLong(); + //la inserci�n de hijos se hace de forma ordenada + FolderItem * parent = items.value(record.value("parentId").toULongLong()); + //if(parent !=0) //TODO if parent==0 the parent of item was removed from the DB and delete on cascade didn't work, ERROR. + parent->appendChild(item); + //se a�ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones + items.insert(item->id,item); + } +} + +void FolderModel::updateFolderModelData(QSqlQuery &sqlquery, FolderItem *parent) +{ + while (sqlquery.next()) { + QLOG_DEBUG () << "habia next"; + QList data; + QSqlRecord record = sqlquery.record(); + + data << record.value("name").toString(); + data << record.value("path").toString(); + data << record.value("finished").toBool(); + data << record.value("completed").toBool(); + FolderItem * item = new FolderItem(data); + + item->id = record.value("id").toULongLong(); + //la inserci�n de hijos se hace de forma ordenada + FolderItem * parent = items.value(record.value("parentId").toULongLong()); + if(parent !=0) //TODO if parent==0 the parent of item was removed from the DB and delete on cascade didn't work, ERROR. + parent->appendChild(item); + //se a�ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones + items.insert(item->id,item); + } +} + +QString FolderModel::getDatabase() +{ + return _databasePath; +} + +QString FolderModel::getFolderPath(const QModelIndex &folder) +{ + if(!folder.isValid()) //root folder + return "/"; + return static_cast(folder.internalPointer())->data(FolderModel::Path).toString(); +} + +/* +void FolderModel::resetFilter() +{ + beginResetModel(); + filter = ""; + includeComics = false; + //TODO hay que liberar la memoria reservada para el filtrado + //items.clear(); + filteredItems.clear(); + FolderItem * root = rootItem; + rootItem = rootBeforeFilter; //TODO si no se aplica el filtro previamente, esto invalidar�a en modelo + if(root !=0) + delete root; + + rootBeforeFilter = 0; + filterEnabled = false; + endResetModel(); + + +}*/ + +void FolderModel::updateFolderCompletedStatus(const QModelIndexList &list, bool status) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + db.transaction(); + foreach (QModelIndex mi, list) + { + FolderItem * item = static_cast(mi.internalPointer()); + item->setData(FolderModel::Completed,status); + + Folder f = DBHelper::loadFolder(item->id,db); + f.setCompleted(status); + DBHelper::update(f,db); + } + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + emit dataChanged(index(list.first().row(),FolderModel::Name),index(list.last().row(),FolderModel::Completed)); +} + +void FolderModel::updateFolderFinishedStatus(const QModelIndexList &list, bool status) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + db.transaction(); + foreach (QModelIndex mi, list) + { + FolderItem * item = static_cast(mi.internalPointer()); + item->setData(FolderModel::Finished,status); + + Folder f = DBHelper::loadFolder(item->id,db); + f.setFinished(status); + DBHelper::update(f,db); + } + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + emit dataChanged(index(list.first().row(),FolderModel::Name),index(list.last().row(),FolderModel::Completed)); +} + +QStringList FolderModel::getSubfoldersNames(const QModelIndex &mi) +{ + QStringList result; + qulonglong id = 1; + if(mi.isValid()){ + FolderItem * item = static_cast(mi.internalPointer()); + id = item->id; + } + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + db.transaction(); + + result = DBHelper::loadSubfoldersNames(id,db); + + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(_databasePath); + + //TODO sort result)) + qSort(result.begin(),result.end(),naturalSortLessThanCI); + return result; +} + +void FolderModel::fetchMoreFromDB(const QModelIndex &parent) +{ + FolderItem * item; + if(parent.isValid()) + item = static_cast(parent.internalPointer()); + else + item = rootItem; + + //Remove all children + if(item->childCount() > 0) + { + beginRemoveRows(parent, 0, item->childCount()-1); + item->clearChildren(); + endRemoveRows(); + } + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + QList items; + QList nextLevelItems; + + QSqlQuery selectQuery(db); + selectQuery.prepare("select * from folder where id <> 1 and parentId = :parentId order by parentId,name"); + + items << item; + bool firstLevelUpdated = false; + while(items.size() > 0) + { + nextLevelItems.clear(); + foreach(FolderItem * item, items) + { + QLOG_DEBUG() << "ID " << item->id; + selectQuery.bindValue(":parentId", item->id); + + selectQuery.exec(); + + if(!firstLevelUpdated) + { + //NO size support + int numResults = 0; + while(selectQuery.next()) + numResults++; + + if(!selectQuery.seek(-1)) + selectQuery.exec(); + //END no size support + + beginInsertRows(parent, 0, numResults-1); + } + + updateFolderModelData(selectQuery,item); + + if(!firstLevelUpdated) + { + endInsertRows(); + firstLevelUpdated = true; + } + + nextLevelItems << item->children(); + + } + + items.clear(); + items = nextLevelItems; + } + + QLOG_DEBUG() << "item->childCount()-1" << item->childCount()-1; + + + db.close(); + QSqlDatabase::removeDatabase(_databasePath); +} + +QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QModelIndex &parent) +{ + FolderItem * parentItem; + + if(parent.isValid()) + parentItem = static_cast(parent.internalPointer()); + else + parentItem = rootItem; + + Folder newFolder; + newFolder.name = folderName; + newFolder.parentId = parentItem->id; + newFolder.path = parentItem->data(1).toString() + "/" + folderName; + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + newFolder.id = DBHelper::insert(&newFolder, db); + QSqlDatabase::removeDatabase(_databasePath); + + int destRow = 0; + + QList data; + data << newFolder.name; + data << newFolder.path; + data << false; //finished + data << true; //completed + + FolderItem * item = new FolderItem(data); + item->id = newFolder.id; + + beginInsertRows(parent,0,0); //TODO calculate the destRow before inserting the new child + + parentItem->appendChild(item); + destRow = parentItem->children().indexOf(item); //TODO optimize this, appendChild should return the index of the new item + items.insert(item->id,item); + + endInsertRows(); + + return index(destRow,0,parent); +} + +void FolderModel::deleteFolder(const QModelIndex &mi) +{ + beginRemoveRows(mi.parent(),mi.row(),mi.row()); + + FolderItem * item = static_cast(mi.internalPointer()); + + FolderItem * parent = item->parent(); + parent->removeChild(mi.row()); + + Folder f; + f.setId(item->id); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + DBHelper::removeFromDB(&f,db); + QSqlDatabase::removeDatabase(_databasePath); + + endRemoveRows(); +} + + +//PROXY + +FolderModelProxy::FolderModelProxy(QObject *parent) + :QSortFilterProxyModel(parent),rootItem(0),filterEnabled(false),filter(""),includeComics(true) +{ + +} + +FolderModelProxy::~FolderModelProxy() +{ + +} + +bool FolderModelProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + if(!filterEnabled) + return true; + + FolderItem * parent = static_cast(source_parent.internalPointer()); + + if(parent == 0) + parent = static_cast(sourceModel())->rootItem; + + FolderItem * item = parent->children().at(source_row); + + return filteredItems.contains(item->id); +} + +void FolderModelProxy::setFilter(const YACReader::SearchModifiers modifier, QString filter, bool includeComics) +{ + clear(); + this->filter = filter; + this->includeComics = includeComics; + this->modifier = modifier; + filterEnabled = true; + setupFilteredModelData(); +} + +void FolderModelProxy::setupFilteredModelData() +{ + beginResetModel(); + + //TODO hay que liberar memoria de anteriores filtrados + + //inicializar el nodo ra�z + + if(rootItem != 0) + delete rootItem; //TODO comprobar que se libera bien la memoria + + rootItem = 0; + + //inicializar el nodo ra�z + QList rootData; + rootData << "root"; + rootItem = new FolderItem(rootData); + rootItem->id = ROOT; + rootItem->parentItem = 0; + + FolderModel * model = static_cast(sourceModel()); + + //cargar la base de datos + QSqlDatabase db = DataBaseManagement::loadDatabase(model->_databasePath); + //crear la consulta + { + QSqlQuery selectQuery(db); //TODO check + if(!includeComics) + { + selectQuery.prepare("select * from folder where id <> 1 and upper(name) like upper(:filter) order by parentId,name "); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + } + else + { + switch(modifier) + { + case YACReader::NoModifiers: + selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed " + "FROM folder f LEFT JOIN comic c ON (f.id = c.parentId) " + "WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) ORDER BY f.parentId,f.name"); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + selectQuery.bindValue(":filter2", "%%"+filter+"%%"); + break; + + case YACReader::OnlyRead: + selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed " + "FROM folder f LEFT JOIN (comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id)) ON (f.id = c.parentId) " + "WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) AND ci.read = 1 ORDER BY f.parentId,f.name;"); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + selectQuery.bindValue(":filter2", "%%"+filter+"%%"); + break; + + case YACReader::OnlyUnread: + selectQuery.prepare("SELECT DISTINCT f.id, f.parentId, f.name, f.path, f.finished, f.completed " + "FROM folder f LEFT JOIN (comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id)) ON (f.id = c.parentId) " + "WHERE f.id <> 1 AND ((UPPER(c.fileName) like UPPER(:filter)) OR (UPPER(f.name) like UPPER(:filter2))) AND ci.read = 0 ORDER BY f.parentId,f.name;"); + selectQuery.bindValue(":filter", "%%"+filter+"%%"); + selectQuery.bindValue(":filter2", "%%"+filter+"%%"); + break; + + default: + QLOG_ERROR() << "not implemented"; + break; + + } + + + } + selectQuery.exec(); + + setupFilteredModelData(selectQuery,rootItem); + } + //selectQuery.finish(); + db.close(); + QSqlDatabase::removeDatabase(model->_databasePath); + + endResetModel(); +} + +void FolderModelProxy::clear() +{ + filterEnabled = false; + + filteredItems.clear(); + + QSortFilterProxyModel::clear(); +} + +void FolderModelProxy::setupFilteredModelData(QSqlQuery &sqlquery, FolderItem *parent) +{ + FolderModel * model = static_cast(sourceModel()); + + //64 bits para la primary key, es decir la misma precisi�n que soporta sqlit 2^64 + filteredItems.clear(); + + //se a�ade el nodo 0 al modelo que representa el arbol de elementos que cumplen con el filtro + filteredItems.insert(parent->id,parent); + + while (sqlquery.next()) { //se procesan todos los folders que cumplen con el filtro + //datos de la base de datos + QList data; + QSqlRecord record = sqlquery.record(); + + data << record.value("name").toString(); + data << record.value("path").toString(); + data << record.value("finished").toBool(); + data << record.value("completed").toBool(); + + FolderItem * item = new FolderItem(data); + item->id = sqlquery.value(0).toULongLong(); + + //id del padre + quint64 parentId = record.value("parentId").toULongLong(); + + //se a�ade el item al map, de forma que se pueda encontrar como padre en siguientes iteraciones + if(!filteredItems.contains(item->id)) + filteredItems.insert(item->id,item); + + //es necesario conocer las coordenadas de origen para poder realizar scroll autom�tico en la vista + item->originalItem = model->items.value(item->id); + + //si el padre ya existe en el modelo, el item se a�ade como hijo + if(filteredItems.contains(parentId)) + filteredItems.value(parentId)->appendChild(item); + else//si el padre a�n no se ha a�adido, hay que a�adirlo a �l y todos los padres hasta el nodo ra�z + { + //comprobamos con esta variable si el �ltimo de los padres (antes del nodo ra�z) ya exist�a en el modelo + bool parentPreviousInserted = false; + + //mientras no se alcance el nodo ra�z se procesan todos los padres (de abajo a arriba) + while(parentId != ROOT ) + { + //el padre no estaba en el modelo filtrado, as� que se rescata del modelo original + FolderItem * parentItem = model->items.value(parentId); + //se debe crear un nuevo nodo (para no compartir los hijos con el nodo original) + FolderItem * newparentItem = new FolderItem(parentItem->getData()); //padre que se a�adir� a la estructura de directorios filtrados + newparentItem->id = parentId; + + newparentItem->originalItem = parentItem; + + //si el modelo contiene al padre, se a�ade el item actual como hijo + if(filteredItems.contains(parentId)) + { + filteredItems.value(parentId)->appendChild(item); + parentPreviousInserted = true; + } + //sino se registra el nodo para poder encontrarlo con posterioridad y se a�ade el item actual como hijo + else + { + newparentItem->appendChild(item); + filteredItems.insert(newparentItem->id,newparentItem); + parentPreviousInserted = false; + } + + //variables de control del bucle, se avanza hacia el nodo padre + item = newparentItem; + parentId = parentItem->parentItem->id; + } + + //si el nodo es hijo de 1 y no hab�a sido previamente insertado como hijo, se a�ade como tal + if(!parentPreviousInserted) + filteredItems.value(ROOT)->appendChild(item); + } + } +} diff --git a/YACReaderLibrary/db/folder_model.h b/YACReaderLibrary/db/folder_model.h new file mode 100644 index 00000000..4d0f16bb --- /dev/null +++ b/YACReaderLibrary/db/folder_model.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TREEMODEL_H +#define TREEMODEL_H + +#include +#include +#include +#include +#include +#include + +#include "yacreader_global.h" + +class FolderItem; + +class FolderModelProxy : public QSortFilterProxyModel +{ + Q_OBJECT +public: + explicit FolderModelProxy(QObject *parent = 0); + ~FolderModelProxy(); + + void setFilter(const YACReader::SearchModifiers modifier, QString filter, bool includeComics); + void setupFilteredModelData( QSqlQuery &sqlquery, FolderItem *parent); + void setupFilteredModelData(); + void clear(); + + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + +protected: + FolderItem *rootItem; + QMap filteredItems; //relación entre folders + + bool includeComics; + QString filter; + bool filterEnabled; + + YACReader::SearchModifiers modifier; +}; + +class FolderModel : public QAbstractItemModel +{ + + Q_OBJECT + + friend class FolderModelProxy; + +public: + FolderModel(QObject *parent = 0); + FolderModel( QSqlQuery &sqlquery, QObject *parent = 0); + ~FolderModel(); + + //QAbstractItemModel methods + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + + //Convenience methods + void setupModelData(QString path); + QString getDatabase(); + QString getFolderPath(const QModelIndex &folder); + //QModelIndex indexFromItem(FolderItem * item, int column); + + + //bool isFilterEnabled(){return filterEnabled;}; + + void updateFolderCompletedStatus(const QModelIndexList & list, bool status); + void updateFolderFinishedStatus(const QModelIndexList & list, bool status); + + QStringList getSubfoldersNames(const QModelIndex & mi); + + void fetchMoreFromDB(const QModelIndex & parent); + + QModelIndex addFolderAtParent(const QString & folderName, const QModelIndex & parent); + + enum Columns { + Name = 0, + Path = 1, + Finished = 2, + Completed = 3 + };//id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL + + enum Roles { + FinishedRole = Qt::UserRole + 1, + CompletedRole + }; + +public slots: + void deleteFolder(const QModelIndex & mi); + +private: + void setupModelData( QSqlQuery &sqlquery, FolderItem *parent); + void updateFolderModelData( QSqlQuery &sqlquery, FolderItem *parent); + + FolderItem *rootItem; //el árbol + QMap items; //relación entre folders + + QString _databasePath; + +signals: + void beforeReset(); + void reset(); +}; +//! [0] + +#endif diff --git a/YACReaderLibrary/db/reading_list_item.cpp b/YACReaderLibrary/db/reading_list_item.cpp new file mode 100644 index 00000000..22df4018 --- /dev/null +++ b/YACReaderLibrary/db/reading_list_item.cpp @@ -0,0 +1,239 @@ +#include "reading_list_item.h" +#include "qnaturalsorting.h" + +#include + +ListItem::ListItem(const QList &data) + :itemData(data) +{ + +} + +int ListItem::columnCount() +{ + return itemData.count(); +} + +QVariant ListItem::data(int column) const +{ + return itemData.at(column); +} + +qulonglong ListItem::getId() const +{ + return 0; +} + +//------------------------------------------------------ + +SpecialListItem::SpecialListItem(const QList &data) + :ListItem(data) +{ + +} + +QIcon SpecialListItem::getIcon() const +{ + if(itemData.count()>Id) + { + QString id = itemData.at(Id).toString(); + return YACReader::noHighlightedIcon(QString(":/images/lists/default_%1.png").arg(id)); + } +} + +ReadingListModel::TypeSpecialList SpecialListItem::getType() const +{ + if(itemData.count()>Id) + { + int id = itemData.at(Id).toInt(); + return (ReadingListModel::TypeSpecialList)id; + } +} + +//------------------------------------------------------ + +LabelItem::LabelItem(const QList &data) + :ListItem(data) +{ + +} + +QIcon LabelItem::getIcon() const +{ + if(itemData.count()>Color) + { + QString color = itemData.at(Color).toString(); + return YACReader::noHighlightedIcon(QString(":/images/lists/label_%1.png").arg(color).toLower()); + } +} + +YACReader::LabelColors LabelItem::colorid() const +{ + if(itemData.count()>Ordering) + { + return YACReader::LabelColors(itemData.at(Ordering).toInt()); + } +} + +QString LabelItem::name() const +{ + if(itemData.count()>Name) + { + return itemData.at(Name).toString(); + } +} + +void LabelItem::setName(const QString &name) +{ + if(itemData.count()>Name) + { + itemData[Name] = name; + } +} + +qulonglong LabelItem::getId() const +{ + if(itemData.count()>Id) + { + return YACReader::LabelColors(itemData.at(Id).toULongLong()); + } +} + +//------------------------------------------------------ + +ReadingListItem::ReadingListItem(const QList &data, ReadingListItem *p) + :ListItem(data), parent(p) +{ + +} + +QIcon ReadingListItem::getIcon() const +{ + if(parent->getId() == 0) + return YACReader::noHighlightedIcon(":/images/lists/list.png"); //top level list + else +#ifdef Q_OS_MAC + return QFileIconProvider().icon(QFileIconProvider::Folder); +#else + return YACReader::noHighlightedIcon(":/images/sidebar/folder.png"); //sublist +#endif +} + +int ReadingListItem::childCount() const +{ + return childItems.count(); +} + +ReadingListItem *ReadingListItem::child(int row) +{ + return childItems.at(row); +} + +//items are sorted by order +void ReadingListItem::appendChild(ReadingListItem *item) +{ + item->parent = this; + + if(childItems.isEmpty()) + childItems.append(item); + else + { + if(item->parent->getId()==0) //sort by name, top level child + { + int i= 0; + while(iname(),item->name())) + i++; + childItems.insert(i,item); + } + else + { + int i= 0; + while(igetOrdering()getOrdering())) + i++; + childItems.insert(i,item); + } + + /*ReadingListItem * last = childItems.back(); + QString nameLast = last->data(1).toString(); //TODO usar info name si est� disponible, sino el nombre del fichero..... + QString nameCurrent = item->data(1).toString(); + QList::iterator i; + i = childItems.end(); + i--; + while (naturalSortLessThanCI(nameCurrent,nameLast) && i != childItems.begin()) + { + i--; + nameLast = (*i)->data(1).toString(); + } + if(!naturalSortLessThanCI(nameCurrent,nameLast)) //si se ha encontrado un elemento menor que current, se inserta justo despu�s + childItems.insert(++i,item); + else + childItems.insert(i,item);*/ + + } + +} + +void ReadingListItem::appendChild(ReadingListItem *item, int pos) +{ + childItems.insert(pos, item); +} + +void ReadingListItem::removeChild(ReadingListItem *item) +{ + childItems.removeOne(item); +} + +qulonglong ReadingListItem::getId() const +{ + if(itemData.count()>Id) + return itemData.at(Id).toULongLong(); +} + +QString ReadingListItem::name() const +{ + if(itemData.count()>Name) + return itemData.at(Name).toString(); +} + +void ReadingListItem::setName(const QString &name) +{ + if(itemData.count()>Name) + itemData[Name] = name; +} + +int ReadingListItem::getOrdering() const +{ + if(itemData.count()>Ordering) + return itemData[Ordering].toInt(); +} + +void ReadingListItem::setOrdering(const int ordering) +{ + if(itemData.count()>Ordering) + itemData[Ordering] = ordering; +} + +QList ReadingListItem::children() +{ + return childItems; +} + +int ReadingListItem::row() const +{ + if (parent) + return parent->childItems.indexOf(const_cast(this)); + + return 0; +} + + +ReadingListSeparatorItem::ReadingListSeparatorItem() + :ListItem(QList()) +{ + +} + +QIcon ReadingListSeparatorItem::getIcon() const +{ + return QIcon(); +} diff --git a/YACReaderLibrary/db/reading_list_item.h b/YACReaderLibrary/db/reading_list_item.h new file mode 100644 index 00000000..e79fea62 --- /dev/null +++ b/YACReaderLibrary/db/reading_list_item.h @@ -0,0 +1,103 @@ +#ifndef READING_LIST_ITEM_H +#define READING_LIST_ITEM_H + +#include +#include + +#include "yacreader_global.h" +#include "reading_list_model.h" +//TODO add propper constructors, using QList is not safe + +class ListItem +{ +public: + ListItem(const QList &data); + int columnCount(); + virtual QIcon getIcon() const = 0; + QVariant data(int column) const; + virtual qulonglong getId() const; + QList itemData; +}; + +//------------------------------------------------------ + +class SpecialListItem : public ListItem +{ +public: + SpecialListItem(const QList &data); + QIcon getIcon() const; + ReadingListModel::TypeSpecialList getType() const; +private: + enum DataIndexes { + Name, + Id + }; + +}; + +//------------------------------------------------------ + +class LabelItem : public ListItem +{ +public: + LabelItem(const QList &data); + QIcon getIcon() const; + YACReader::LabelColors colorid() const; + QString name() const; + void setName(const QString & name); + qulonglong getId() const; + + +private: + enum DataIndexes { + Name, + Color, + Id, + Ordering + }; +}; + +//------------------------------------------------------ + +class ReadingListItem : public ListItem +{ +public: + ReadingListItem(const QList &data, ReadingListItem * parent = 0); + QIcon getIcon() const; + ReadingListItem * parent; + int childCount() const; + int row() const; + ReadingListItem * child(int row); + void appendChild(ReadingListItem *item); + void appendChild(ReadingListItem *item, int pos); + void removeChild(ReadingListItem *item); + qulonglong getId() const; + QString name() const; + void setName(const QString & name); + int getOrdering() const; + void setOrdering(const int ordering); + QList children(); + +private: + QList childItems; + + enum DataIndexes { + Name, + Id, + Finished, + Completed, + Ordering + }; + +}; + +//------------------------------------------------------ + +class ReadingListSeparatorItem : public ListItem +{ +public: + ReadingListSeparatorItem(); + QIcon getIcon() const; +}; + +#endif // READING_LIST_ITEM_H diff --git a/YACReaderLibrary/db/reading_list_model.cpp b/YACReaderLibrary/db/reading_list_model.cpp new file mode 100644 index 00000000..7eb76f6d --- /dev/null +++ b/YACReaderLibrary/db/reading_list_model.cpp @@ -0,0 +1,778 @@ +#include "reading_list_model.h" + +#include "reading_list_item.h" + +#include "data_base_management.h" +#include "qnaturalsorting.h" +#include "db_helper.h" + +#include "QsLog.h" + +#include + +ReadingListModel::ReadingListModel(QObject *parent) : + QAbstractItemModel(parent),rootItem(0) +{ + separator1 = new ReadingListSeparatorItem; + separator2 = new ReadingListSeparatorItem; +} + +int ReadingListModel::rowCount(const QModelIndex &parent) const +{ + if(!parent.isValid()) //TOP + { + int separatorsCount = 2;//labels.isEmpty()?1:2; + return specialLists.count() + labels.count() + rootItem->childCount() + separatorsCount; + } + else + { + ListItem * item = static_cast(parent.internalPointer()); + + if(typeid(*item) == typeid(ReadingListItem)) + { + ReadingListItem * item = static_cast(parent.internalPointer()); + return item->childCount(); + } + } + + return 0; +} + +int ReadingListModel::columnCount(const QModelIndex &parent) const +{ + if(parent.isValid()) + { + ListItem * item = static_cast(parent.internalPointer()); + if(typeid(*item) == typeid(ReadingListSeparatorItem)) + return 0; + } + return 1; + /*if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return rootItem->columnCount();*/ +} + +QVariant ReadingListModel::data(const QModelIndex &index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + ListItem * item = static_cast(index.internalPointer()); + + if (role == ReadingListModel::TypeListsRole) + { + if(typeid(*item) == typeid(SpecialListItem)) + return QVariant(ReadingListModel::SpecialList); + + if(typeid(*item) == typeid(LabelItem)) + return QVariant(ReadingListModel::Label); + + if(typeid(*item) == typeid(ReadingListItem)) + return QVariant(ReadingListModel::ReadingList); + + if(typeid(*item) == typeid(ReadingListSeparatorItem)) + return QVariant(ReadingListModel::Separator); + } + + if (role == ReadingListModel::LabelColorRole && typeid(*item) == typeid(LabelItem) ) + { + LabelItem * labelItem = static_cast(item); + return QVariant(labelItem->colorid()); + } + + if (role == ReadingListModel::IDRole) + { + QLOG_DEBUG() << "getting role"; + return item->getId(); +} + + if (role == ReadingListModel::SpecialListTypeRole && typeid(*item) == typeid(SpecialListItem)) + { + SpecialListItem * specialListItem = static_cast(item); + return QVariant(specialListItem->getType()); + } + + if(typeid(*item) == typeid(ReadingListSeparatorItem)) + return QVariant(); + + if (role == Qt::DecorationRole) + { + return QVariant(item->getIcon()); + } + + if (role != Qt::DisplayRole) + return QVariant(); + + return item->data(index.column()); +} + +Qt::ItemFlags ReadingListModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + + ListItem * item = static_cast(index.internalPointer()); + if(typeid(*item) == typeid(ReadingListSeparatorItem)) + return 0; + + if(typeid(*item) == typeid(ReadingListItem) && static_cast(item)->parent->getId()!=0) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled; //only sublists are dragable + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled; +} + +QVariant ReadingListModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return rootItem->data(section); + + return QVariant(); +} + +QModelIndex ReadingListModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + if(!parent.isValid()) + { + int separatorsCount = 2;//labels.isEmpty()?1:2; + + if(rowIsSpecialList(row,parent)) + return createIndex(row, column, specialLists.at(row)); + + if(row == specialLists.count()) + return createIndex(row,column,separator1); + + if(rowIsLabel(row,parent)) + return createIndex(row,column,labels.at(row-specialLists.count()-1)); + + if(separatorsCount == 2) + if(row == specialLists.count() + labels.count() + 1) + return createIndex(row,column,separator2); + + if(rowIsReadingList(row,parent)) + return createIndex(row,column,rootItem->child(row - (specialLists.count() + labels.count() + separatorsCount))); + + } else //sublist + { + ReadingListItem *parentItem; + + if (!parent.isValid()) + parentItem = rootItem; //this should be impossible + else + parentItem = static_cast(parent.internalPointer()); + + ReadingListItem *childItem = parentItem->child(row); + return createIndex(row,column,childItem); + } + /*FolderItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else*/ + return QModelIndex(); + +} + +QModelIndex ReadingListModel::parent(const QModelIndex &index) const +{ + + if(!index.isValid()) + return QModelIndex(); + + ListItem * item = static_cast(index.internalPointer()); + + if(typeid(*item) == typeid(ReadingListItem)) + { + ReadingListItem * childItem = static_cast(index.internalPointer()); + ReadingListItem * parent = childItem->parent; + if(parent->getId() != 0) + return createIndex(parent->row()+specialLists.count()+labels.count()+2, 0, parent); + } + + return QModelIndex(); +} + +bool ReadingListModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const +{ + QLOG_DEBUG() << "trying to drop into row = " << row << "column column = " << column << "parent" << parent; + + if(row == -1) + return false; + + if(!parent.isValid()) //top level items + { + if(row == -1) //no list + return false; + + if(row == 1) //reading is just an smart list + return false; + + if(rowIsSeparator(row,parent)) + return false; + } + + if(data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat)) + return true; + + if(rowIsReadingList(row,parent))// TODO avoid droping in a different parent + if(!parent.isValid()) + return false; + else + { + QList > sublistsRows; + QByteArray rawData = data->data(YACReader::YACReaderLibrarSubReadingListMimeDataFormat); + QDataStream in(&rawData,QIODevice::ReadOnly); + in >> sublistsRows; //deserialize the list of indentifiers + if(parent.row()!= sublistsRows.at(0).second) + return false; + return data->formats().contains(YACReader::YACReaderLibrarSubReadingListMimeDataFormat); + + } + + return false; +} + +bool ReadingListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + QLOG_DEBUG() << "drop mimedata into row = " << row << " column = " << column << "parent" << parent; + if(data->formats().contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat)) + return dropComics(data, action, row, column, parent); + + if(data->formats().contains(YACReader::YACReaderLibrarSubReadingListMimeDataFormat)) + return dropSublist(data, action, row, column, parent); +} + +bool ReadingListModel::dropComics(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + QList comicIds = YACReader::mimeDataToComicsIds(data); + + QLOG_DEBUG() << "dropped : " << comicIds; + + QModelIndex dest; + QModelIndex parentDest; + + if(row == -1) + { + dest = parent; + } + else + dest = index(row,column,parent); + + parentDest = dest.parent(); + + if(rowIsSpecialList(dest.row(),parentDest)) { + if(dest.row() == 0) //add to favorites + { + QLOG_DEBUG() << "-------addComicsToFavorites : " << comicIds << " to " << dest.data(IDRole).toULongLong(); + emit addComicsToFavorites(comicIds); + return true; + } + } + + if(rowIsLabel(dest.row(),parentDest)) { + QLOG_DEBUG() << "+++++++++++addComicsToLabel : " << comicIds << " to " << dest.data(IDRole).toULongLong(); + emit addComicsToLabel(comicIds, dest.data(IDRole).toULongLong()); + return true; + } + + if(rowIsReadingList(dest.row(),parentDest)) { + QLOG_DEBUG() << "///////////addComicsToReadingList : " << comicIds << " to " << dest.data(IDRole).toULongLong(); + emit addComicsToReadingList(comicIds, dest.data(IDRole).toULongLong()); + return true; + } + + return false; +} + +bool ReadingListModel::dropSublist(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + QList > sublistsRows; + QByteArray rawData = data->data(YACReader::YACReaderLibrarSubReadingListMimeDataFormat); + QDataStream in(&rawData,QIODevice::ReadOnly); + in >> sublistsRows; //deserialize the list of indentifiers + + QLOG_DEBUG() << "dropped : " << sublistsRows; + + int sourceRow = sublistsRows.at(0).first; + int destRow = row; + QModelIndex destParent = parent; + if(row == -1) + { + QLOG_DEBUG() << "droping inside parent"; + destRow = parent.row(); + destParent = parent.parent(); + } + QLOG_DEBUG() << "move " << sourceRow << "-" << destRow; + + if(sourceRow == destRow) + return false; + + //beginMoveRows(destParent,sourceRow,sourceRow,destParent,destRow); + + ReadingListItem * parentItem = static_cast(destParent.internalPointer()); + ReadingListItem * child = parentItem->child(sourceRow); + parentItem->removeChild(child); + parentItem->appendChild(child,destRow); + + reorderingChildren(parentItem->children()); + //endMoveRows(); + + return true; +} + +QMimeData *ReadingListModel::mimeData(const QModelIndexList &indexes) const +{ + QLOG_DEBUG() << "mimeData requested" << indexes; + + if(indexes.length() == 0) + { + QLOG_ERROR() << "mimeData requested: indexes is empty"; + return new QMimeData();//TODO what happens if 0 is returned? + } + + if(indexes.length() > 1) + QLOG_DEBUG() << "mimeData requested for more than one index, this shouldn't be possible"; + + QModelIndex modelIndex = indexes.at(0); + + QList > rows; + rows << QPair(modelIndex.row(),modelIndex.parent().row()); + QLOG_DEBUG() << "mimeData requested for row : " << modelIndex.row(); + + QByteArray data; + QDataStream out(&data,QIODevice::WriteOnly); + out << rows; //serialize the list of identifiers + + QMimeData * mimeData = new QMimeData(); + mimeData->setData(YACReader::YACReaderLibrarSubReadingListMimeDataFormat, data); + + return mimeData; +} + +void ReadingListModel::setupReadingListsData(QString path) +{ + beginResetModel(); + + cleanAll(); + + _databasePath = path; + QSqlDatabase db = DataBaseManagement::loadDatabase(path); + + //setup special lists + specialLists = setupSpecialLists(db); + + //separator-------------------------------------------- + + //setup labels + setupLabels(db); + + //separator-------------------------------------------- + + //setup reading list + setupReadingLists(db); + + endResetModel(); +} + +void ReadingListModel::addNewLabel(const QString &name, YACReader::LabelColors color) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + qulonglong id = DBHelper::insertLabel(name, color, db); + + beginInsertRows(QModelIndex(),0, 0); + + int newPos = addLabelIntoList(new LabelItem(QList() << name << YACReader::colorToName(color) << id << color)); + + //beginInsertRows(QModelIndex(),specialLists.count()+1+newPos+1, specialLists.count()+1+newPos+1); + endInsertRows(); + + QSqlDatabase::removeDatabase(_databasePath); +} + +void ReadingListModel::addReadingList(const QString &name) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + beginInsertRows(QModelIndex(), 0, 0); //TODO calculate the right coordinates before inserting + + qulonglong id = DBHelper::insertReadingList(name,db); + ReadingListItem * newItem; + rootItem->appendChild(newItem = new ReadingListItem(QList() + << name + << id + << false + << true + << 0)); + + items.insert(id, newItem); + + /*int pos = rootItem->children().indexOf(newItem); + + pos += specialLists.count()+1+labels.count()+labels.count()>0?1:0;*/ + + + endInsertRows(); + + QSqlDatabase::removeDatabase(_databasePath); +} + +void ReadingListModel::addReadingListAt(const QString &name, const QModelIndex &mi) +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + beginInsertRows(mi, 0, 0); //TODO calculate the right coordinates before inserting + + ReadingListItem * readingListParent = static_cast(mi.internalPointer()); + qulonglong id = DBHelper::insertReadingSubList(name,mi.data(IDRole).toULongLong(),readingListParent->childCount(),db); + ReadingListItem * newItem; + + readingListParent->appendChild(newItem = new ReadingListItem(QList() + << name + << id + << false + << true + << readingListParent->childCount())); + + items.insert(id, newItem); + + /*int pos = readingListParent->children().indexOf(newItem); + + pos += specialLists.count()+1+labels.count()+labels.count()>0?1:0;*/ + + + endInsertRows(); + + QSqlDatabase::removeDatabase(_databasePath); +} + +bool ReadingListModel::isEditable(const QModelIndex &mi) +{ + if(!mi.isValid()) + return false; + ListItem * item = static_cast(mi.internalPointer()); + return typeid(*item) != typeid(SpecialListItem); +} + +bool ReadingListModel::isReadingList(const QModelIndex &mi) +{ + if(!mi.isValid()) + return false; + ListItem * item = static_cast(mi.internalPointer()); + return typeid(*item) == typeid(ReadingListItem); +} + +bool ReadingListModel::isReadingSubList(const QModelIndex &mi) +{ + if(!mi.isValid()) + return false; + ListItem * item = static_cast(mi.internalPointer()); + if(typeid(*item) == typeid(ReadingListItem)) + { + ReadingListItem * readingListItem = static_cast(item); + if(readingListItem->parent == rootItem) + return false; + else + return true; + } + else + return false; +} + +QString ReadingListModel::name(const QModelIndex &mi) +{ + return data(mi,Qt::DisplayRole).toString(); +} + +void ReadingListModel::rename(const QModelIndex &mi, const QString &name) +{ + if(!isEditable(mi)) + return; + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + ListItem * item = static_cast(mi.internalPointer()); + + if(typeid(*item) == typeid(ReadingListItem)) + { + ReadingListItem * rli = static_cast(item); + rli->setName(name); + DBHelper::renameList(item->getId(), name, db); + + if(rli->parent->getId()!=0) + { + //TODO + //move row depending on the name + }else + emit dataChanged(index(mi.row(), 0), index(mi.row(), 0)); + } + else if(typeid(*item) == typeid(LabelItem)) + { + LabelItem * li = static_cast(item); + li->setName(name); + DBHelper::renameLabel(item->getId(), name, db); + emit dataChanged(index(mi.row(), 0), index(mi.row(), 0)); + } + + QSqlDatabase::removeDatabase(_databasePath); +} + +void ReadingListModel::deleteItem(const QModelIndex &mi) +{ + if(isEditable(mi)) + { + QLOG_DEBUG() << "parent row :" << mi.parent().data() << "-" << mi.row(); + beginRemoveRows(mi.parent(),mi.row(),mi.row()); + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + + ListItem * item = static_cast(mi.internalPointer()); + + if(typeid(*item) == typeid(ReadingListItem)) + { + ReadingListItem * rli = static_cast(item); + QLOG_DEBUG() << "num children : " << rli->parent->childCount(); + rli->parent->removeChild(rli); + QLOG_DEBUG() << "num children : " << rli->parent->childCount(); + DBHelper::removeListFromDB(item->getId(), db); + if(rli->parent->getId()!=0) + { + reorderingChildren(rli->parent->children()); + } + QLOG_DEBUG() << "num children : " << rli->parent->childCount(); + } + else if(typeid(*item) == typeid(LabelItem)) + { + LabelItem * li = static_cast(item); + labels.removeOne(li); + DBHelper::removeLabelFromDB(item->getId(), db); + } + + QSqlDatabase::removeDatabase(_databasePath); + + endRemoveRows(); + } +} + +const QList ReadingListModel::getLabels() +{ + return labels; +} + +void ReadingListModel::cleanAll() +{ + if(rootItem != 0) + { + delete rootItem; + + qDeleteAll(specialLists); + qDeleteAll(labels); + + specialLists.clear(); + labels.clear(); + + items.clear(); + } + + rootItem = 0; +} + +void ReadingListModel::setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent) +{ + items.insert(parent->getId(),parent); + + while (sqlquery.next()) + { + QSqlRecord record = sqlquery.record(); + ReadingListItem * rli = new ReadingListItem(QList() + << record.value("name") + << record.value("id") + << record.value("finished") + << record.value("completed") + << record.value("ordering")); + + ReadingListItem * currentParent; + if(record.value("parentId").isNull()) + currentParent = rootItem; + else + currentParent = items.value(record.value("parentId").toULongLong()); + + currentParent->appendChild(rli); + + items.insert(rli->getId(),rli); + } +} + +QList ReadingListModel::setupSpecialLists(QSqlDatabase & db) +{ + QList list; + + QSqlQuery selectQuery("SELECT * FROM default_reading_list ORDER BY id,name",db); + while(selectQuery.next()) { + QSqlRecord record = selectQuery.record(); + list << new SpecialListItem(QList() + << record.value("name") + << record.value("id")); + } + + //Reading after Favorites, Why? Because I want to :P + list.insert(1,new SpecialListItem(QList() << "Reading" << 0)); + + return list; +} + +void ReadingListModel::setupLabels(QSqlDatabase & db) +{ + QSqlQuery selectQuery("SELECT * FROM label ORDER BY ordering,name",db); //TODO add some kind of + while(selectQuery.next()) { + QSqlRecord record = selectQuery.record(); + addLabelIntoList(new LabelItem(QList() + << record.value("name") + << record.value("color") + << record.value("id") + << record.value("ordering"))); + } + + //TEST + +// INSERT INTO label (name, color, ordering) VALUES ("Oh Oh", "red", 1); +// INSERT INTO label (name, color, ordering) VALUES ("lalala", "orange", 2); +// INSERT INTO label (name, color, ordering) VALUES ("we are not sorry", "yellow", 3); +// INSERT INTO label (name, color, ordering) VALUES ("there we go", "green", 4); +// INSERT INTO label (name, color, ordering) VALUES ("oklabunga", "cyan", 5); +// INSERT INTO label (name, color, ordering) VALUES ("hailer mailer", "blue", 6); +// INSERT INTO label (name, color, ordering) VALUES ("lol", "violet", 7); +// INSERT INTO label (name, color, ordering) VALUES ("problems", "purple", 8); +// INSERT INTO label (name, color, ordering) VALUES ("me gussssta", "pink", 9); +// INSERT INTO label (name, color, ordering) VALUES (":D", "white", 10); +// INSERT INTO label (name, color, ordering) VALUES ("ainsss", "light", 11); +// INSERT INTO label (name, color, ordering) VALUES ("put a smile on my face", "dark", 12); + +} + +void ReadingListModel::setupReadingLists(QSqlDatabase & db) +{ + //setup root item + rootItem = new ReadingListItem(QList() << "ROOT" << 0 << true << false); + + QSqlQuery selectQuery("select * from reading_list order by parentId IS NULL DESC",db); + + //setup reading lists + setupReadingListsData(selectQuery,rootItem); + + //TEST +// ReadingListItem * node1; +// rootItem->appendChild(node1 = new ReadingListItem(QList() /*<< 0*/ << "My reading list" << "atr")); +// rootItem->appendChild(new ReadingListItem(QList() /*<< 0*/ << "X timeline" << "atr")); + +// node1->appendChild(new ReadingListItem(QList() /*<< 0*/ << "sublist" << "atr",node1)); +} + +int ReadingListModel::addLabelIntoList(LabelItem *item) +{ + if(labels.isEmpty()) + labels << item; + else + { + int i = 0; + + while (i < labels.count() && (labels.at(i)->colorid() < item->colorid()) ) + i++; + + if(i < labels.count()) + { + if(labels.at(i)->colorid() == item->colorid()) //sort by name + { + while( i < labels.count() && labels.at(i)->colorid() == item->colorid() && naturalSortLessThanCI(labels.at(i)->name(),item->name())) + i++; + } + } + + + if(i >= labels.count()) + { + QLOG_DEBUG() << "insertando label al final " << item->name(); + labels << item; + } + else + { + QLOG_DEBUG() << "insertando label en " << i << "-" << item->name(); + labels.insert(i,item); + } + + return i; + } + + return 0; +} + +void ReadingListModel::reorderingChildren(QList children) +{ + QList childrenIds; + int i = 0; + foreach (ReadingListItem * item, children) { + item->setOrdering(i++); + childrenIds << item->getId(); + } + + QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); + DBHelper::reasignOrderToSublists(childrenIds, db); + QSqlDatabase::removeDatabase(_databasePath); +} + +bool ReadingListModel::rowIsSpecialList(int row, const QModelIndex &parent) const +{ + if(parent.isValid()) + return false; //by now no sublists in special list + + if(row >=0 && row < specialLists.count()) + return true; + + return false; +} + +bool ReadingListModel::rowIsLabel(int row, const QModelIndex &parent) const +{ + if(parent.isValid()) + return false; //by now no sublists in labels + + if(row > specialLists.count() && row <= specialLists.count() + labels.count()) + return true; + + return false; +} + +bool ReadingListModel::rowIsReadingList(int row, const QModelIndex &parent) const +{ + if(parent.isValid()) + return true; //only lists with sublists + + int separatorsCount = labels.isEmpty()?1:2; + + if(row >= specialLists.count() + labels.count() + separatorsCount) + return true; + + return false; +} + +bool ReadingListModel::rowIsSeparator(int row, const QModelIndex &parent) const +{ + if(parent.isValid()) + return false; //only separators at top level + + if(row == specialLists.count()) + return true; + + int separatorsCount = labels.isEmpty()?1:2; + if(separatorsCount == 2 && row == specialLists.count() + labels.count() + 1) + return true; + + return false; +} + +ReadingListModelProxy::ReadingListModelProxy(QObject *parent) + :QSortFilterProxyModel(parent) +{ + +} diff --git a/YACReaderLibrary/db/reading_list_model.h b/YACReaderLibrary/db/reading_list_model.h new file mode 100644 index 00000000..c60eaa3b --- /dev/null +++ b/YACReaderLibrary/db/reading_list_model.h @@ -0,0 +1,117 @@ +#ifndef READING_LIST_MODEL_H +#define READING_LIST_MODEL_H + +#include +#include +#include +#include +#include +#include + +#include "yacreader_global.h" + +class LabelItem; +class SpecialListItem; +class ReadingListItem; +class ReadingListSeparatorItem; + +class ReadingListModelProxy : public QSortFilterProxyModel +{ + Q_OBJECT +public: + explicit ReadingListModelProxy(QObject *parent = 0); +}; + +class ReadingListModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit ReadingListModel(QObject *parent = 0); + + //QAbstractItemModel methods + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const; + bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + QMimeData *mimeData(const QModelIndexList &indexes) const; + + //Convenience methods + void setupReadingListsData(QString path); + void addNewLabel(const QString & name, YACReader::LabelColors color); + void addReadingList(const QString & name);//top level reading list + void addReadingListAt(const QString & name, const QModelIndex & mi); + bool isEditable(const QModelIndex & mi); + bool isReadingList(const QModelIndex & mi); + bool isReadingSubList(const QModelIndex & mi); + QString name(const QModelIndex & mi); + void rename(const QModelIndex & mi, const QString & name); + void deleteItem(const QModelIndex & mi); + const QList getLabels(); + + enum Roles { + TypeListsRole = Qt::UserRole + 1, + IDRole, + LabelColorRole, + SpecialListTypeRole + }; + + enum TypeList { + SpecialList, + Label, + ReadingList, + Separator + }; + + enum TypeSpecialList { + Reading, + Favorites + }; + +signals: + + void addComicsToFavorites(const QList & comicIds); + void addComicsToLabel(const QList & comicIds, qulonglong labelId); + void addComicsToReadingList(const QList & comicIds, qulonglong readingListId); + +private: + void cleanAll(); + void setupReadingListsData(QSqlQuery &sqlquery, ReadingListItem *parent); + QList setupSpecialLists(QSqlDatabase &db); + void setupLabels(QSqlDatabase &db); + void setupReadingLists(QSqlDatabase &db); + int addLabelIntoList(LabelItem *item); + void reorderingChildren(QList children); + + bool rowIsSpecialList(int row, const QModelIndex & parent = QModelIndex()) const; + bool rowIsLabel(int row, const QModelIndex & parent = QModelIndex()) const; + bool rowIsReadingList(int row, const QModelIndex & parent = QModelIndex()) const; + bool rowIsSeparator(int row, const QModelIndex & parent = QModelIndex()) const; + + bool dropComics(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + bool dropSublist(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + //Special lists + QList specialLists; + + //Label + QList labels; + + //Reading lists + ReadingListItem * rootItem; // + QMap items; //lists relationship + + //separators + ReadingListSeparatorItem * separator1; + ReadingListSeparatorItem * separator2; + + QString _databasePath; + +}; + +#endif // READING_LIST_MODEL_H diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp new file mode 100644 index 00000000..d7f9911a --- /dev/null +++ b/YACReaderLibrary/db_helper.cpp @@ -0,0 +1,1054 @@ +#include "db_helper.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "library_item.h" +#include "comic_db.h" +#include "data_base_management.h" +#include "folder.h" +#include "yacreader_libraries.h" + +#include "qnaturalsorting.h" + +#include "QsLog.h" +//server + +YACReaderLibraries DBHelper::getLibraries() +{ + YACReaderLibraries libraries; + libraries.load(); + return libraries; +} +QList DBHelper::getFolderSubfoldersFromLibrary(qulonglong libraryId, qulonglong folderId) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + QList list = DBHelper::getFoldersFromParent(folderId,db,false); + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); + return list; +} +QList DBHelper::getFolderComicsFromLibrary(qulonglong libraryId, qulonglong folderId) +{ + return DBHelper::getFolderComicsFromLibrary(libraryId, folderId, false); +} + +QList DBHelper::getFolderComicsFromLibrary(qulonglong libraryId, qulonglong folderId, bool sort) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + QList list = DBHelper::getComicsFromParent(folderId,db,sort); + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); + return list; +} +qulonglong DBHelper::getParentFromComicFolderId(qulonglong libraryId, qulonglong id) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + Folder f = DBHelper::loadFolder(id,db); + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); + return f.parentId; +} +ComicDB DBHelper::getComicInfo(qulonglong libraryId, qulonglong id) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + ComicDB comic = DBHelper::loadComic(id,db); + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); + return comic; +} + +QList DBHelper::getSiblings(qulonglong libraryId, qulonglong parentId) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + QList comics = DBHelper::getSortedComicsFromParent(parentId,db); + db.close(); + QSqlDatabase::removeDatabase(libraryPath); + return comics; +} + +QString DBHelper::getFolderName(qulonglong libraryId, qulonglong id) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + QString name=""; + + { + QSqlQuery selectQuery(db); //TODO check + selectQuery.prepare("SELECT name FROM folder WHERE id = :id"); + selectQuery.bindValue(":id", id); + selectQuery.exec(); + + if(selectQuery.next()) + { + QSqlRecord record = selectQuery.record(); + name = record.value(0).toString(); + } + } + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); + return name; +} +QList DBHelper::getLibrariesNames() +{ + QStringList names = getLibraries().getNames(); + qSort(names.begin(),names.end(),naturalSortLessThanCI); + return names; +} +QString DBHelper::getLibraryName(int id) +{ + return getLibraries().getName(id); +} +//objects management +//deletes +void DBHelper::removeFromDB(LibraryItem * item, QSqlDatabase & db) +{ + if(item->isDir()) + DBHelper::removeFromDB(dynamic_cast(item),db); + else + DBHelper::removeFromDB(dynamic_cast(item),db); +} +void DBHelper::removeFromDB(Folder * folder, QSqlDatabase & db) +{ + QSqlQuery query(db); + query.prepare("DELETE FROM folder WHERE id = :id"); + query.bindValue(":id", folder->id); + query.exec(); +} +void DBHelper::removeFromDB(ComicDB * comic, QSqlDatabase & db) +{ + QSqlQuery query(db); + query.prepare("DELETE FROM comic WHERE id = :id"); + query.bindValue(":id", comic->id); + query.exec(); +} + +void DBHelper::removeLabelFromDB(qulonglong id, QSqlDatabase &db) +{ + QSqlQuery query(db); + query.prepare("DELETE FROM label WHERE id = :id"); + query.bindValue(":id", id); + query.exec(); +} + +void DBHelper::removeListFromDB(qulonglong id, QSqlDatabase &db) +{ + QSqlQuery query(db); + query.prepare("DELETE FROM reading_list WHERE id = :id"); + query.bindValue(":id", id); + query.exec(); +} + +void DBHelper::deleteComicsFromFavorites(const QList &comicsList, QSqlDatabase &db) +{ + db.transaction(); + + QLOG_DEBUG() << "deleteComicsFromFavorites----------------------------------"; + + QSqlQuery query(db); + query.prepare("DELETE FROM comic_default_reading_list WHERE comic_id = :comic_id AND default_reading_list_id = 1"); + foreach(ComicDB comic, comicsList) + { + query.bindValue(":comic_id", comic.id); + query.exec(); + } + + db.commit(); +} + +void DBHelper::deleteComicsFromLabel(const QList &comicsList, qulonglong labelId, QSqlDatabase &db) +{ + db.transaction(); + + QLOG_DEBUG() << "deleteComicsFromLabel----------------------------------"; + + QSqlQuery query(db); + query.prepare("DELETE FROM comic_label WHERE comic_id = :comic_id AND label_id = :label_id"); + foreach(ComicDB comic, comicsList) + { + query.bindValue(":comic_id", comic.id); + query.bindValue(":label_id", labelId); + query.exec(); + + QLOG_DEBUG() << "cid = " << comic.id << "lid = " << labelId; + QLOG_DEBUG() << query.lastError().databaseText() << "-" << query.lastError().driverText(); + } + + db.commit(); +} + +void DBHelper::deleteComicsFromReadingList(const QList &comicsList, qulonglong readingListId, QSqlDatabase &db) +{ + db.transaction(); + + QLOG_DEBUG() << "deleteComicsFromReadingList----------------------------------"; + + QSqlQuery query(db); + query.prepare("DELETE FROM comic_reading_list WHERE comic_id = :comic_id AND reading_list_id = :reading_list_id"); + foreach(ComicDB comic, comicsList) + { + query.bindValue(":comic_id", comic.id); + query.bindValue(":reading_list_id", readingListId); + query.exec(); + } + + db.commit(); +} + +//updates +void DBHelper::update(ComicDB * comic, QSqlDatabase & db) +{ + Q_UNUSED(comic) + Q_UNUSED(db) + //do nothing +} + +void DBHelper::update(qulonglong libraryId, ComicInfo & comicInfo) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + DBHelper::update(&comicInfo,db); + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); +} + +void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db) +{ + QSqlQuery updateComicInfo(db); + updateComicInfo.prepare("UPDATE comic_info SET " + "title = :title," + + "coverPage = :coverPage," + "numPages = :numPages," + + "number = :number," + "isBis = :isBis," + "count = :count," + + "volume = :volume," + "storyArc = :storyArc," + "arcNumber = :arcNumber," + "arcCount = :arcCount," + + "genere = :genere," + + "writer = :writer," + "penciller = :penciller," + "inker = :inker," + "colorist = :colorist," + "letterer = :letterer," + "coverArtist = :coverArtist," + + "date = :date," + "publisher = :publisher," + "format = :format," + "color = :color," + "ageRating = :ageRating," + + "synopsis = :synopsis," + "characters = :characters," + "notes = :notes," + + "read = :read," + "edited = :edited," + //new 7.0 fields + "hasBeenOpened = :hasBeenOpened," + + "currentPage = :currentPage," + "bookmark1 = :bookmark1," + "bookmark2 = :bookmark2," + "bookmark3 = :bookmark3," + "brightness = :brightness," + "contrast = :contrast, " + "gamma = :gamma," + "rating = :rating," + + //new 7.1 fields + "comicVineID = :comicVineID" + //-- + " WHERE id = :id "); + + updateComicInfo.bindValue(":title",comicInfo->title); + + updateComicInfo.bindValue(":coverPage", comicInfo->coverPage); + updateComicInfo.bindValue(":numPages", comicInfo->numPages); + + updateComicInfo.bindValue(":number", comicInfo->number); + updateComicInfo.bindValue(":isBis", comicInfo->isBis); + updateComicInfo.bindValue(":count", comicInfo->count); + + updateComicInfo.bindValue(":volume", comicInfo->volume); + updateComicInfo.bindValue(":storyArc", comicInfo->storyArc); + updateComicInfo.bindValue(":arcNumber",comicInfo->arcNumber); + updateComicInfo.bindValue(":arcCount",comicInfo->arcCount); + + updateComicInfo.bindValue(":genere",comicInfo->genere); + + updateComicInfo.bindValue(":writer",comicInfo->writer); + updateComicInfo.bindValue(":penciller",comicInfo->penciller); + updateComicInfo.bindValue(":inker",comicInfo->inker); + updateComicInfo.bindValue(":colorist",comicInfo->colorist); + updateComicInfo.bindValue(":letterer",comicInfo->letterer); + updateComicInfo.bindValue(":coverArtist",comicInfo->coverArtist); + + updateComicInfo.bindValue(":date",comicInfo->date); + updateComicInfo.bindValue(":publisher",comicInfo->publisher); + updateComicInfo.bindValue(":format",comicInfo->format); + updateComicInfo.bindValue(":color",comicInfo->color); + updateComicInfo.bindValue(":ageRating",comicInfo->ageRating); + + updateComicInfo.bindValue(":synopsis",comicInfo->synopsis); + updateComicInfo.bindValue(":characters",comicInfo->characters); + updateComicInfo.bindValue(":notes",comicInfo->notes); + + bool read = comicInfo->read || comicInfo->currentPage == comicInfo->numPages.toInt(); //if current page is the las page, the comic is read(completed) + comicInfo->read = read; + updateComicInfo.bindValue(":read", read?1:0); + updateComicInfo.bindValue(":id", comicInfo->id); + updateComicInfo.bindValue(":edited", comicInfo->edited?1:0); + + updateComicInfo.bindValue(":hasBeenOpened", comicInfo->hasBeenOpened?1:0); + updateComicInfo.bindValue(":currentPage", comicInfo->currentPage); + updateComicInfo.bindValue(":bookmark1", comicInfo->bookmark1); + updateComicInfo.bindValue(":bookmark2", comicInfo->bookmark2); + updateComicInfo.bindValue(":bookmark3", comicInfo->bookmark3); + updateComicInfo.bindValue(":brightness", comicInfo->brightness); + updateComicInfo.bindValue(":contrast", comicInfo->contrast); + updateComicInfo.bindValue(":gamma", comicInfo->gamma); + updateComicInfo.bindValue(":rating", comicInfo->rating); + + updateComicInfo.bindValue(":comicVineID", comicInfo->comicVineID); + + updateComicInfo.exec(); +} + +void DBHelper::updateRead(ComicInfo * comicInfo, QSqlDatabase & db) +{ + QSqlQuery updateComicInfo(db); + updateComicInfo.prepare("UPDATE comic_info SET " + "read = :read" + " WHERE id = :id "); + + updateComicInfo.bindValue(":read", comicInfo->read?1:0); + updateComicInfo.bindValue(":id", comicInfo->id); + updateComicInfo.exec(); +} + +void DBHelper::update(const Folder & folder, QSqlDatabase &db) +{ + QSqlQuery updateFolderInfo(db); + updateFolderInfo.prepare("UPDATE folder SET " + "finished = :finished, " + "completed = :completed " + "WHERE id = :id "); + updateFolderInfo.bindValue(":finished", folder.isFinished()?1:0); + updateFolderInfo.bindValue(":completed", folder.isCompleted()?1:0); + updateFolderInfo.bindValue(":id", folder.id); + updateFolderInfo.exec(); +} + +void DBHelper::updateProgress(qulonglong libraryId, const ComicInfo &comicInfo) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + ComicDB comic = DBHelper::loadComic(comicInfo.id,db); + comic.info.currentPage = comicInfo.currentPage; + comic.info.hasBeenOpened = true; + + DBHelper::update(&comic.info,db); + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); +} + +void DBHelper::updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatabase &db) +{ + QSqlQuery updateComicInfo(db); + updateComicInfo.prepare("UPDATE comic_info SET " + "read = :read, " + "currentPage = :currentPage, " + "hasBeenOpened = :hasBeenOpened" + " WHERE id = :id "); + + updateComicInfo.bindValue(":read", comicInfo.read?1:0); + updateComicInfo.bindValue(":currentPage", comicInfo.currentPage); + updateComicInfo.bindValue(":hasBeenOpened", comicInfo.hasBeenOpened?1:0); + updateComicInfo.bindValue(":id", comicInfo.id); + updateComicInfo.exec(); +} + + +void DBHelper::updateFromRemoteClient(qulonglong libraryId,const ComicInfo & comicInfo) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + ComicDB comic = DBHelper::loadComic(comicInfo.id,db); + + if(comic.info.hash == comicInfo.hash) + { + if(comic.info.currentPage == comic.info.numPages) + comic.info.read = true; + comic.info.currentPage = comicInfo.currentPage; + comic.info.hasBeenOpened = true; + + DBHelper::updateReadingRemoteProgress(comic.info,db); + } + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); +} + +void DBHelper::renameLabel(qulonglong id, const QString &name, QSqlDatabase &db) +{ + QSqlQuery renameLabelQuery(db); + renameLabelQuery.prepare("UPDATE label SET " + "name = :name " + "WHERE id = :id"); + renameLabelQuery.bindValue(":name", name); + renameLabelQuery.bindValue(":id", id); + renameLabelQuery.exec(); + + QLOG_DEBUG() << renameLabelQuery.lastError().databaseText(); +} + +void DBHelper::renameList(qulonglong id, const QString &name, QSqlDatabase &db) +{ + QSqlQuery renameLabelQuery(db); + renameLabelQuery.prepare("UPDATE reading_list SET " + "name = :name " + "WHERE id = :id"); + renameLabelQuery.bindValue(":name", name); + renameLabelQuery.bindValue(":id", id); + renameLabelQuery.exec(); +} + +void DBHelper::reasignOrderToSublists(QList ids, QSqlDatabase &db) +{ + QSqlQuery updateOrdering(db); + updateOrdering.prepare("UPDATE reading_list SET " + "ordering = :ordering " + "WHERE id = :id"); + db.transaction(); + int order = 0; + foreach(qulonglong id, ids) + { + updateOrdering.bindValue(":ordering",order++); + updateOrdering.bindValue(":id", id); + updateOrdering.exec(); + } + + db.commit(); +} + +void DBHelper::reasignOrderToComicsInFavorites(QList comicIds, QSqlDatabase &db) +{ + QSqlQuery updateOrdering(db); + updateOrdering.prepare("UPDATE comic_default_reading_list SET " + "ordering = :ordering " + "WHERE comic_id = :comic_id AND default_reading_list_id = 0"); + db.transaction(); + int order = 0; + foreach(qulonglong id, comicIds) + { + updateOrdering.bindValue(":ordering",order++); + updateOrdering.bindValue(":comic_id", id); + updateOrdering.exec(); + } + + db.commit(); +} + +void DBHelper::reasignOrderToComicsInLabel(qulonglong labelId, QList comicIds, QSqlDatabase &db) +{ + QSqlQuery updateOrdering(db); + updateOrdering.prepare("UPDATE comic_label SET " + "ordering = :ordering " + "WHERE comic_id = :comic_id AND label_id = :label_id"); + db.transaction(); + int order = 0; + foreach(qulonglong id, comicIds) + { + updateOrdering.bindValue(":ordering",order++); + updateOrdering.bindValue(":comic_id", id); + updateOrdering.bindValue(":label_id", labelId); + updateOrdering.exec(); + } + + db.commit(); +} + +void DBHelper::reasignOrderToComicsInReadingList(qulonglong readingListId, QList comicIds, QSqlDatabase &db) +{ + QSqlQuery updateOrdering(db); + updateOrdering.prepare("UPDATE comic_reading_list SET " + "ordering = :ordering " + "WHERE comic_id = :comic_id AND reading_list_id = :reading_list_id"); + db.transaction(); + int order = 0; + foreach(qulonglong id, comicIds) + { + updateOrdering.bindValue(":ordering",order++); + updateOrdering.bindValue(":comic_id", id); + updateOrdering.bindValue(":reading_list_id", readingListId); + updateOrdering.exec(); + QLOG_INFO() << updateOrdering.lastError().databaseText() << "-" << updateOrdering.lastError().driverText(); + } + + db.commit(); +} + +//inserts +qulonglong DBHelper::insert(Folder * folder, QSqlDatabase & db) +{ + QSqlQuery query(db); + query.prepare("INSERT INTO folder (parentId, name, path) " + "VALUES (:parentId, :name, :path)"); + query.bindValue(":parentId", folder->parentId); + query.bindValue(":name", folder->name); + query.bindValue(":path", folder->path); + query.exec(); + return query.lastInsertId().toULongLong(); +} + +qulonglong DBHelper::insert(ComicDB * comic, QSqlDatabase & db) +{ + if(!comic->info.existOnDb) + { + QSqlQuery comicInfoInsert(db); + comicInfoInsert.prepare("INSERT INTO comic_info (hash,numPages) " + "VALUES (:hash,:numPages)"); + comicInfoInsert.bindValue(":hash", comic->info.hash); + comicInfoInsert.bindValue(":numPages", comic->info.numPages); + comicInfoInsert.exec(); + comic->info.id =comicInfoInsert.lastInsertId().toULongLong(); + comic->_hasCover = false; + } + else + comic->_hasCover = true; + + QSqlQuery query(db); + query.prepare("INSERT INTO comic (parentId, comicInfoId, fileName, path) " + "VALUES (:parentId,:comicInfoId,:name, :path)"); + query.bindValue(":parentId", comic->parentId); + query.bindValue(":comicInfoId", comic->info.id); + query.bindValue(":name", comic->name); + query.bindValue(":path", comic->path); + query.exec(); + return query.lastInsertId().toULongLong(); +} + +qulonglong DBHelper::insertLabel(const QString &name, YACReader::LabelColors color, QSqlDatabase &db) +{ + QSqlQuery query(db); + query.prepare("INSERT INTO label (name, color, ordering) " + "VALUES (:name, :color, :ordering)"); + query.bindValue(":name", name); + query.bindValue(":color", YACReader::colorToName(color)); + query.bindValue(":ordering", color); + query.exec(); + return query.lastInsertId().toULongLong(); +} + +qulonglong DBHelper::insertReadingList(const QString &name, QSqlDatabase &db) +{ + QSqlQuery query(db); + query.prepare("INSERT INTO reading_list (name) " + "VALUES (:name)"); + query.bindValue(":name", name); + query.exec(); + return query.lastInsertId().toULongLong(); +} + +qulonglong DBHelper::insertReadingSubList(const QString &name, qulonglong parentId, int ordering, QSqlDatabase &db) +{ + QSqlQuery query(db); + query.prepare("INSERT INTO reading_list (name, parentId, ordering) " + "VALUES (:name, :parentId, :ordering)"); + query.bindValue(":name", name); + query.bindValue(":parentId", parentId); + query.bindValue(":ordering", ordering); + query.exec(); + return query.lastInsertId().toULongLong(); +} + +void DBHelper::insertComicsInFavorites(const QList &comicsList, QSqlDatabase &db) +{ + QSqlQuery getNumComicsInFavoritesQuery("SELECT count(*) FROM comic_default_reading_list WHERE default_reading_list_id = 1;",db); + getNumComicsInFavoritesQuery.next(); + QSqlRecord record = getNumComicsInFavoritesQuery.record(); + int numComics = record.value(0).toInt(); + + db.transaction(); + + QSqlQuery query(db); + query.prepare("INSERT INTO comic_default_reading_list (default_reading_list_id, comic_id, ordering) " + "VALUES (1, :comic_id, :ordering)"); + + foreach(ComicDB comic, comicsList) + { + query.bindValue(":comic_id", comic.id); + query.bindValue(":ordering", numComics++); + query.exec(); + } + + db.commit(); +} + +void DBHelper::insertComicsInLabel(const QList &comicsList, qulonglong labelId, QSqlDatabase &db) +{ + QSqlQuery getNumComicsInFavoritesQuery(QString("SELECT count(*) FROM comic_label WHERE label_id = %1;").arg(labelId) ,db); + getNumComicsInFavoritesQuery.next(); + QSqlRecord record = getNumComicsInFavoritesQuery.record(); + int numComics = record.value(0).toInt(); + + db.transaction(); + + QSqlQuery query(db); + query.prepare("INSERT INTO comic_label (label_id, comic_id, ordering) " + "VALUES (:label_id, :comic_id, :ordering)"); + + foreach(ComicDB comic, comicsList) + { + query.bindValue(":label_id", labelId); + query.bindValue(":comic_id", comic.id); + query.bindValue(":ordering", numComics++); + query.exec(); + } + + db.commit(); +} + +void DBHelper::insertComicsInReadingList(const QList &comicsList, qulonglong readingListId, QSqlDatabase &db) +{ + QSqlQuery getNumComicsInFavoritesQuery("SELECT count(*) FROM comic_reading_list;",db); + getNumComicsInFavoritesQuery.next(); + QSqlRecord record = getNumComicsInFavoritesQuery.record(); + int numComics = record.value(0).toInt(); + + db.transaction(); + + QSqlQuery query(db); + query.prepare("INSERT INTO comic_reading_list (reading_list_id, comic_id, ordering) " + "VALUES (:reading_list_id, :comic_id, :ordering)"); + + foreach(ComicDB comic, comicsList) + { + query.bindValue(":reading_list_id", readingListId); + query.bindValue(":comic_id", comic.id); + query.bindValue(":ordering", numComics++); + query.exec(); + } + + db.commit(); +} +//queries +QList DBHelper::getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort) +{ + QList list; + + QSqlQuery selectQuery(db); //TODO check + selectQuery.prepare("SELECT * FROM folder WHERE parentId = :parentId and id <> 1"); + selectQuery.bindValue(":parentId", parentId); + selectQuery.exec(); + + Folder * currentItem; + while (selectQuery.next()) + { + QList data; + QSqlRecord record = selectQuery.record(); + for(int i=0;i(list.back()); + QString nameLast = last->name; + QString nameCurrent = currentItem->name; + QList::iterator i; + i = list.end(); + i--; + while ((0 > (lessThan = naturalSortLessThanCI(nameCurrent,nameLast))) && i != list.begin()) + { + i--; + nameLast = (*i)->name; + } + if(lessThan>=0) //si se ha encontrado un elemento menor que current, se inserta justo después + list.insert(++i,currentItem); + else + list.insert(i,currentItem); + + } + } + + return list; +} + +QList DBHelper::getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db) +{ + + QList list; + + QSqlQuery selectQuery(db); + selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); + selectQuery.bindValue(":parentId", parentId); + selectQuery.exec(); + + ComicDB currentItem; + while (selectQuery.next()) + { + QList data; + QSqlRecord record = selectQuery.record(); + for(int i=0;i(list.back()); + QString nameLast = last.name; + QString nameCurrent = currentItem.name; + + int numberLast,numberCurrent; + int max = (std::numeric_limits::max)(); + numberLast = numberCurrent = max; //TODO change by std limit + + if(!last.info.number.isNull()) + numberLast = last.info.number.toInt(); + + if(!currentItem.info.number.isNull()) + numberCurrent = currentItem.info.number.toInt(); + + QList::iterator i; + i = list.end(); + i--; + + if(numberCurrent != max) + { + while ((lessThan =numberCurrent < numberLast) && i != list.begin()) + { + i--; + numberLast = max; + + if(!(*i).info.number.isNull()) + numberLast = (*i).info.number.toInt(); + } + } + else + { + while ((lessThan = naturalSortLessThanCI(nameCurrent,nameLast)) && i != list.begin() && numberLast == max) + { + i--; + nameLast = (*i).name; + numberLast = max; + + if(!(*i).info.number.isNull()) + numberLast = (*i).info.number.toInt(); + } + + } + if(!lessThan) //si se ha encontrado un elemento menor que current, se inserta justo después + { + if(numberCurrent != max) + { + if(numberCurrent == numberLast) + if(currentItem.info.isBis.toBool()) + { + list.insert(++i,currentItem); + } + else + list.insert(i,currentItem); + else + list.insert(++i,currentItem); + } + else + list.insert(++i,currentItem); + } + else + { + list.insert(i,currentItem); + } + + } + } + //selectQuery.finish(); + return list; +} +QList DBHelper::getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort) +{ + QList list; + + QSqlQuery selectQuery(db); + selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId"); + selectQuery.bindValue(":parentId", parentId); + selectQuery.exec(); + + ComicDB * currentItem; + while (selectQuery.next()) + { + QList data; + QSqlRecord record = selectQuery.record(); + for(int i=0;iid = record.value("id").toULongLong(); + currentItem->parentId = record.value(1).toULongLong(); + currentItem->name = record.value(2).toString(); + currentItem->path = record.value(3).toString(); + currentItem->info = DBHelper::loadComicInfo(record.value(4).toString(),db); + int lessThan = 0; + if(list.isEmpty() || !sort) + list.append(currentItem); + else + { + ComicDB * last = static_cast(list.back()); + QString nameLast = last->name; + QString nameCurrent = currentItem->name; + QList::iterator i; + i = list.end(); + i--; + while ((0 > (lessThan = nameCurrent.localeAwareCompare(nameLast))) && i != list.begin()) //se usa la misma ordenación que en QDir + { + i--; + nameLast = (*i)->name; + } + if(lessThan>0) //si se ha encontrado un elemento menor que current, se inserta justo después + list.insert(++i,currentItem); + else + list.insert(i,currentItem); + + } + } + //selectQuery.finish(); + return list; +} + +//loads +Folder DBHelper::loadFolder(qulonglong id, QSqlDatabase & db) +{ + Folder folder; + + QSqlQuery query(db); + query.prepare("SELECT * FROM folder WHERE id = :id"); + query.bindValue(":id",id); + query.exec(); + folder.id = id; + folder.parentId = 0; + if(query.next()) + { + QSqlRecord record = query.record(); + folder.parentId = record.value("parentId").toULongLong(); + folder.name = record.value("name").toString(); + folder.path = record.value("path").toString(); + folder.knownId = true; + //new 7.1 + folder.setFinished(record.value("finished").toBool()); + folder.setCompleted(record.value("completed").toBool()); + } + + return folder; +} + +Folder DBHelper::loadFolder(const QString &folderName, qulonglong parentId, QSqlDatabase &db) +{ + Folder folder; + + QLOG_DEBUG() << "Looking for folder with name = " << folderName << " and parent " << parentId; + + QSqlQuery query(db); + query.prepare("SELECT * FROM folder WHERE parentId = :parentId AND name = :folderName"); + query.bindValue(":parentId",parentId); + query.bindValue(":folderName", folderName); + query.exec(); + + folder.parentId = parentId; + if(query.next()) + { + QSqlRecord record = query.record(); + folder.id = record.value("id").toULongLong(); + folder.name = record.value("name").toString(); + folder.path = record.value("path").toString(); + folder.knownId = true; + //new 7.1 + folder.setFinished(record.value("finished").toBool()); + folder.setCompleted(record.value("completed").toBool()); + QLOG_DEBUG() << "FOUND!!"; + } + + return folder; +} + +ComicDB DBHelper::loadComic(qulonglong id, QSqlDatabase & db) +{ + ComicDB comic; + + QSqlQuery selectQuery(db); + selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.id = :id"); + selectQuery.bindValue(":id", id); + selectQuery.exec(); + comic.id = id; + if(selectQuery.next()) + { + QSqlRecord record = selectQuery.record(); + //id = record.value("id").toULongLong(); + comic.parentId = record.value("parentId").toULongLong(); + comic.name = record.value("name").toString(); + comic.path = record.value("path").toString(); + comic.info = DBHelper::loadComicInfo(record.value("hash").toString(),db); + } + + return comic; +} + +ComicDB DBHelper::loadComic(QString cname, QString cpath, QString chash, QSqlDatabase & database) +{ + ComicDB comic; + + //comic.parentId = cparentId; + comic.name = cname; + comic.path = cpath; + + comic.info = DBHelper::loadComicInfo(chash,database); + + if(!comic.info.existOnDb) + { + comic.info.hash = chash; + comic.info.coverPage = 1; + comic._hasCover = false; + } + else + comic._hasCover = true; + + return comic; +} + +ComicInfo DBHelper::loadComicInfo(QString hash, QSqlDatabase & db) +{ + ComicInfo comicInfo; + + QSqlQuery findComicInfo(db); + findComicInfo.prepare("SELECT * FROM comic_info WHERE hash = :hash"); + findComicInfo.bindValue(":hash", hash); + findComicInfo.exec(); + + + if(findComicInfo.next()) + { + comicInfo.hash = hash; + QSqlRecord record = findComicInfo.record(); + + comicInfo.hash = hash; + comicInfo.id = record.value("id").toULongLong(); + comicInfo.read = record.value("read").toBool(); + comicInfo.edited = record.value("edited").toBool(); + + //new 7.0 fields + comicInfo.hasBeenOpened = record.value("hasBeenOpened").toBool(); + comicInfo.currentPage = record.value("currentPage").toInt(); + comicInfo.bookmark1 = record.value("bookmark1").toInt(); + comicInfo.bookmark2 = record.value("bookmark2").toInt(); + comicInfo.bookmark3 = record.value("bookmark3").toInt(); + comicInfo.brightness = record.value("brightness").toInt(); + comicInfo.contrast = record.value("contrast").toInt(); + comicInfo.gamma = record.value("gamma").toInt(); + comicInfo.rating = record.value("rating").toInt(); + //-- + + comicInfo.title = record.value("title"); + comicInfo.numPages = record.value("numPages"); + + comicInfo.coverPage = record.value("coverPage"); + + comicInfo.number = record.value("number"); + comicInfo.isBis = record.value("isBis"); + comicInfo.count = record.value("count"); + + comicInfo.volume = record.value("volume"); + comicInfo.storyArc = record.value("storyArc"); + comicInfo.arcNumber = record.value("arcNumber"); + comicInfo.arcCount = record.value("arcCount"); + + comicInfo.genere = record.value("genere"); + + comicInfo.writer = record.value("writer"); + comicInfo.penciller = record.value("penciller"); + comicInfo.inker = record.value("inker"); + comicInfo.colorist = record.value("colorist"); + comicInfo.letterer = record.value("letterer"); + comicInfo.coverArtist = record.value("coverArtist"); + + comicInfo.date = record.value("date"); + comicInfo.publisher = record.value("publisher"); + comicInfo.format = record.value("format"); + comicInfo.color = record.value("color"); + comicInfo.ageRating = record.value("ageRating"); + + comicInfo.synopsis = record.value("synopsis"); + comicInfo.characters = record.value("characters"); + comicInfo.notes = record.value("notes"); + + comicInfo.comicVineID = record.value("comicVineID"); + + comicInfo.existOnDb = true; + } + else + comicInfo.existOnDb = false; + + return comicInfo; +} + +QList DBHelper::loadSubfoldersNames(qulonglong folderId, QSqlDatabase &db) +{ + QList result; + QSqlQuery selectQuery(db); + selectQuery.prepare("SELECT name FROM folder WHERE parentId = :parentId AND id <> 1"); //do not select the root folder + selectQuery.bindValue(":parentId", folderId); + selectQuery.exec(); + while(selectQuery.next()){ + result << selectQuery.record().value("name").toString(); + } + return result; +} diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h new file mode 100644 index 00000000..5eb2eae3 --- /dev/null +++ b/YACReaderLibrary/db_helper.h @@ -0,0 +1,81 @@ +#ifndef DB_HELPER_H +#define DB_HELPER_H + +class QString; +#include +#include +#include "yacreader_global.h" + +class ComicDB; +class Folder; +class LibraryItem; +class QSqlDatabase; +class ComicInfo; +class QSqlRecord; +class QSqlQuery; +class YACReaderLibraries; + +class DBHelper +{ +public: + //server + static YACReaderLibraries getLibraries(); + static QList getFolderSubfoldersFromLibrary(qulonglong libraryId, qulonglong folderId); + static QList getFolderComicsFromLibrary(qulonglong libraryId, qulonglong folderId); + static QList getFolderComicsFromLibrary(qulonglong libraryId, qulonglong folderId, bool sort); + static qulonglong getParentFromComicFolderId(qulonglong libraryId, qulonglong id); + static ComicDB getComicInfo(qulonglong libraryId, qulonglong id); + static QList getSiblings(qulonglong libraryId, qulonglong parentId); + static QString getFolderName(qulonglong libraryId, qulonglong id); + static QList getLibrariesNames(); + static QString getLibraryName(int id); + + //objects management + //deletes + static void removeFromDB(LibraryItem * item, QSqlDatabase & db); + static void removeFromDB(Folder * folder, QSqlDatabase & db); + static void removeFromDB(ComicDB * comic, QSqlDatabase & db); + static void removeLabelFromDB(qulonglong id, QSqlDatabase & db); + static void removeListFromDB(qulonglong id, QSqlDatabase & db); + //logic deletes + static void deleteComicsFromFavorites(const QList & comicsList, QSqlDatabase & db); + static void deleteComicsFromLabel(const QList & comicsList, qulonglong labelId, QSqlDatabase & db); + static void deleteComicsFromReadingList(const QList & comicsList, qulonglong readingListId, QSqlDatabase & db); + //inserts + static qulonglong insert(Folder * folder, QSqlDatabase & db); + static qulonglong insert(ComicDB * comic, QSqlDatabase & db); + static qulonglong insertLabel(const QString & name, YACReader::LabelColors color , QSqlDatabase & db); + static qulonglong insertReadingList(const QString & name, QSqlDatabase & db); + static qulonglong insertReadingSubList(const QString & name, qulonglong parentId, int ordering, QSqlDatabase & db); + static void insertComicsInFavorites(const QList & comicsList, QSqlDatabase & db); + static void insertComicsInLabel(const QList & comicsList, qulonglong labelId, QSqlDatabase & db); + static void insertComicsInReadingList(const QList & comicsList, qulonglong readingListId, QSqlDatabase & db); + //updates + static void update(qulonglong libraryId, ComicInfo & comicInfo); + static void update(ComicDB * comics, QSqlDatabase & db); + static void update(ComicInfo * comicInfo, QSqlDatabase & db); + static void updateRead(ComicInfo * comicInfo, QSqlDatabase & db); + static void update(const Folder & folder, QSqlDatabase & db); + static void updateProgress(qulonglong libraryId,const ComicInfo & comicInfo); + static void updateReadingRemoteProgress(const ComicInfo & comicInfo, QSqlDatabase & db); + static void updateFromRemoteClient(qulonglong libraryId,const ComicInfo & comicInfo); + static void renameLabel(qulonglong id, const QString & name, QSqlDatabase & db); + static void renameList(qulonglong id, const QString & name, QSqlDatabase & db); + static void reasignOrderToSublists(QList ids, QSqlDatabase & db); + static void reasignOrderToComicsInFavorites(QList comicIds, QSqlDatabase & db); + static void reasignOrderToComicsInLabel(qulonglong labelId, QList comicIds, QSqlDatabase & db); + static void reasignOrderToComicsInReadingList(qulonglong readingListId, QList comicIds, QSqlDatabase & db); + + static QList getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true); + static QList getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db); + static QList getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true); + //load + static Folder loadFolder(qulonglong id, QSqlDatabase & db); + static Folder loadFolder(const QString & folderName, qulonglong parentId, QSqlDatabase & db); + static ComicDB loadComic(qulonglong id, QSqlDatabase & db); + static ComicDB loadComic(QString cname, QString cpath, QString chash, QSqlDatabase & database); + static ComicInfo loadComicInfo(QString hash, QSqlDatabase & db); + static QList loadSubfoldersNames(qulonglong folderId, QSqlDatabase & db); +}; + +#endif diff --git a/YACReaderLibrary/empty_container_info.cpp b/YACReaderLibrary/empty_container_info.cpp new file mode 100644 index 00000000..2c5b74d0 --- /dev/null +++ b/YACReaderLibrary/empty_container_info.cpp @@ -0,0 +1,47 @@ +#include "empty_container_info.h" + +EmptyContainerInfo::EmptyContainerInfo(QWidget *parent) : + QWidget(parent), iconLabel(new QLabel()), titleLabel(new QLabel()) +{ +#ifdef Q_OS_MAC + backgroundColor = "#FFFFFF"; + titleLabel->setStyleSheet("QLabel {color:#888888; font-size:24px;font-family:Arial;font-weight:bold;}"); +#else + backgroundColor = "#2A2A2A"; + titleLabel->setStyleSheet("QLabel {color:#CCCCCC; font-size:24px;font-family:Arial;font-weight:bold;}"); +#endif + + iconLabel->setAlignment(Qt::AlignCenter); + titleLabel->setAlignment(Qt::AlignCenter); +} + +void EmptyContainerInfo::setPixmap(const QPixmap &pixmap) +{ + iconLabel->setPixmap(pixmap); +} + +void EmptyContainerInfo::setText(const QString &text) +{ + titleLabel->setText(text); +} + +QVBoxLayout * EmptyContainerInfo::setUpDefaultLayout(bool addStretch) +{ + QVBoxLayout * layout = new QVBoxLayout; + + layout->addSpacing(100); + layout->addWidget(iconLabel); + layout->addSpacing(30); + layout->addWidget(titleLabel); + if(addStretch) + layout->addStretch(); + + setLayout(layout); + return layout; +} + +void EmptyContainerInfo::paintEvent(QPaintEvent *) +{ + QPainter painter (this); + painter.fillRect(0,0,width(),height(),QColor(backgroundColor)); +} diff --git a/YACReaderLibrary/empty_container_info.h b/YACReaderLibrary/empty_container_info.h new file mode 100644 index 00000000..8fd81747 --- /dev/null +++ b/YACReaderLibrary/empty_container_info.h @@ -0,0 +1,26 @@ +#ifndef EMPTY_CONTAINER_INFO_H +#define EMPTY_CONTAINER_INFO_H + +#include + +class EmptyContainerInfo : public QWidget +{ + Q_OBJECT +public: + explicit EmptyContainerInfo(QWidget *parent = 0); + void setPixmap(const QPixmap & pixmap); + void setText(const QString & text); + QVBoxLayout *setUpDefaultLayout(bool addStretch); +signals: + +public slots: + +protected: + void paintEvent(QPaintEvent *); + + QLabel * iconLabel; + QLabel * titleLabel; + QString backgroundColor; +}; + +#endif // EMPTY_CONTAINER_INFO_H diff --git a/YACReaderLibrary/empty_folder_widget.cpp b/YACReaderLibrary/empty_folder_widget.cpp new file mode 100644 index 00000000..e9760ab6 --- /dev/null +++ b/YACReaderLibrary/empty_folder_widget.cpp @@ -0,0 +1,154 @@ +#include "empty_folder_widget.h" + +#include +#include +#include +#include +#include + +#include "comic.h" +#include "comic_files_manager.h" +#include "QsLog.h" + +void testListView(QListView * l) +{ + QStringListModel * slm = new QStringListModel(QStringList() << "Lorem ipsum" << "Hailer skualer"<< "Mumbaluba X" << "Finger layden" << "Pacum tactus filer" << "Aposum" << "En" << "Lorem ipsum" << "Hailer skualer" << "Mumbaluba X" << "Finger layden" << "Pacum tactus filer" << "Aposum" << "En" ); + l->setModel(slm); +} + +EmptyFolderWidget::EmptyFolderWidget(QWidget *parent) : + EmptyContainerInfo(parent),subfoldersModel(new QStringListModel()) +{ + QVBoxLayout * layout = setUpDefaultLayout(false); + + iconLabel->setPixmap(QPixmap(":/images/empty_folder.png")); + titleLabel->setText(tr("Subfolders in this folder")); + + foldersView = new QListView(); + foldersView->setMinimumWidth(282); + //foldersView->setWrapping(true); + foldersView->setAttribute(Qt::WA_MacShowFocusRect,false); +#ifdef Q_OS_MAC + foldersView->setStyleSheet("QListView {background-color:transparent; border: none; color:#959595; outline:0; font-size: 18px; show-decoration-selected: 0; margin:0}" + "QListView::item:selected {background-color: #EFEFEF; color:#CCCCCC;}" + "QListView::item:hover {background-color:#F4F4F8; color:#757575; }" + + + "QScrollBar:vertical { border-radius:3px; background: #FFFFFF; width: 14px; margin: 0 10px 0 0; }" + "QScrollBar::handle:vertical { border: 1px solid #999999; background: #999999; width: 14px; min-height: 20px; border-radius: 2px; }" + "QScrollBar::add-line:vertical { border: none; background: #999999; height: 0px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}" + + "QScrollBar::sub-line:vertical { border: none; background: #999999; height: 0px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}" + "QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}" + + "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background: none; }" + "QScrollBar:horizontal{height:0px;}" + ); +#else + foldersView->setStyleSheet("QListView {background-color:transparent; border: none; color:#858585; outline:0; font-size: 18px; font:bold; show-decoration-selected: 0; margin:0}" + "QListView::item:selected {background-color: #212121; color:#CCCCCC;}" + "QListView::item:hover {background-color:#212121; color:#CCCCCC; }" + + + "QScrollBar:vertical { border: none; background: #212121; width: 14px; margin: 0 10px 0 0; }" + "QScrollBar::handle:vertical { background: #858585; width: 14px; min-height: 20px; }" + "QScrollBar::add-line:vertical { border: none; background: #212121; height: 0px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}" + + "QScrollBar::sub-line:vertical { border: none; background: #212121; height: 0px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}" + "QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}" + + "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background: none; }" + "QScrollBar:horizontal{height:0px;}" + ); + +#endif + foldersView->setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding ); + testListView(foldersView); + + layout->addSpacing(12); + layout->addWidget(foldersView,1,Qt::AlignHCenter); + layout->addStretch(); + layout->setMargin(0); + layout->setSpacing(0); + + setContentsMargins(0,0,0,0); + + setStyleSheet(QString("QWidget {background:%1}").arg(backgroundColor)); + + setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding ); + + setAcceptDrops(true); + + connect(foldersView,SIGNAL(clicked(QModelIndex)),this,SLOT(onItemClicked(QModelIndex))); +} + +void EmptyFolderWidget::setSubfolders(const QModelIndex &mi, const QStringList &foldersNames) +{ + parent = mi; + subfoldersModel->setStringList(foldersNames); + foldersView->setModel(subfoldersModel); + + if(foldersNames.isEmpty()) + { + titleLabel->setText(tr("Empty folder") + QString("

%1

").arg(tr("Drag and drop folders and comics here"))); + } + else + { + titleLabel->setText(tr("Subfolders in this folder")); + } +} + +void EmptyFolderWidget::onItemClicked(const QModelIndex &mi) +{ + emit subfolderSelected(parent,mi.row()); +} + +//TODO remove repeated code in drag & drop support.... +void EmptyFolderWidget::dragEnterEvent(QDragEnterEvent *event) +{ + QList urlList; + + if (event->mimeData()->hasUrls() && event->dropAction() == Qt::CopyAction) + { + urlList = event->mimeData()->urls(); + QString currentPath; + foreach (QUrl url, urlList) + { + //comics or folders are accepted, folders' content is validate in dropEvent (avoid any lag before droping) + currentPath = url.toLocalFile(); + if(Comic::fileIsComic(currentPath) || QFileInfo(currentPath).isDir()) + { + event->acceptProposedAction(); + return; + } + } + } +} + +void EmptyFolderWidget::dropEvent(QDropEvent *event) +{ + QLOG_DEBUG() << "drop in emptyfolder" << event->dropAction(); + + bool validAction = event->dropAction() == Qt::CopyAction; // || event->dropAction() & Qt::MoveAction; TODO move + + if(validAction) + { + + QList > droppedFiles = ComicFilesManager::getDroppedFiles(event->mimeData()->urls()); + + if(event->dropAction() == Qt::CopyAction) + { + QLOG_DEBUG() << "copy in emptyfolder:" << droppedFiles; + emit copyComicsToCurrentFolder(droppedFiles); + } + else if(event->dropAction() & Qt::MoveAction) + { + QLOG_DEBUG() << "move in emptyfolder:" << droppedFiles; + emit moveComicsToCurrentFolder(droppedFiles); + } + + event->acceptProposedAction(); + } +} diff --git a/YACReaderLibrary/empty_folder_widget.h b/YACReaderLibrary/empty_folder_widget.h new file mode 100644 index 00000000..98cb4d01 --- /dev/null +++ b/YACReaderLibrary/empty_folder_widget.h @@ -0,0 +1,36 @@ +#ifndef EMPTY_FOLDER_WIDGET_H +#define EMPTY_FOLDER_WIDGET_H + +#include "empty_container_info.h" +#include + + + +class EmptyFolderWidget : public EmptyContainerInfo +{ + Q_OBJECT +public: + explicit EmptyFolderWidget(QWidget *parent = 0); + void setSubfolders(const QModelIndex & mi, const QStringList & foldersNames); +signals: + void subfolderSelected(QModelIndex, int); + + //Drops + void copyComicsToCurrentFolder(QList >); + void moveComicsToCurrentFolder(QList >); + +public slots: + void onItemClicked(const QModelIndex & mi); + +protected: + QListView * foldersView; + QModelIndex parent; + QStringListModel * subfoldersModel; + QString backgroundColor; + + //Drop to import + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); +}; + +#endif // EMPTY_FOLDER_WIDGET_H diff --git a/YACReaderLibrary/empty_label_widget.cpp b/YACReaderLibrary/empty_label_widget.cpp new file mode 100644 index 00000000..eac010d7 --- /dev/null +++ b/YACReaderLibrary/empty_label_widget.cpp @@ -0,0 +1,21 @@ +#include "empty_label_widget.h" + +EmptyLabelWidget::EmptyLabelWidget(QWidget *parent) : + EmptyContainerInfo(parent) +{ + setUpDefaultLayout(true); + + iconLabel->setPixmap(QPixmap(":/images/empty_label.png")); + + //titleLabel->setText(tr("This label doesn't contain comics yet") + QString("

%1

").arg(tr("Drag and drop folders and comics here"))); + titleLabel->setText(tr("This label doesn't contain comics yet")); +} + +void EmptyLabelWidget::setColor(YACReader::LabelColors color) +{ + QPixmap p(":/images/empty_label.png"); + QImage img = p.toImage().convertToFormat(QImage::Format_ARGB32); + QColor destColor(YACReader::labelColorToRGBString(color)); + YACReader::colorize(img,destColor); + iconLabel->setPixmap(QPixmap::fromImage(img)); +} diff --git a/YACReaderLibrary/empty_label_widget.h b/YACReaderLibrary/empty_label_widget.h new file mode 100644 index 00000000..0e877da6 --- /dev/null +++ b/YACReaderLibrary/empty_label_widget.h @@ -0,0 +1,22 @@ +#ifndef EMPTY_LABEL_WIDGET_H +#define EMPTY_LABEL_WIDGET_H + +#include +#include "empty_container_info.h" +#include "yacreader_global.h" + +class EmptyLabelWidget : public EmptyContainerInfo +{ + Q_OBJECT +public: + explicit EmptyLabelWidget(QWidget *parent = 0); + void setColor(YACReader::LabelColors color); + +signals: + +public slots: + +protected: +}; + +#endif // EMPTY_LABEL_WIDGET_H diff --git a/YACReaderLibrary/empty_reading_list_widget.cpp b/YACReaderLibrary/empty_reading_list_widget.cpp new file mode 100644 index 00000000..f325dc37 --- /dev/null +++ b/YACReaderLibrary/empty_reading_list_widget.cpp @@ -0,0 +1,9 @@ +#include "empty_reading_list_widget.h" + +EmptyReadingListWidget::EmptyReadingListWidget(QWidget *parent) + :EmptyContainerInfo(parent) +{ + setUpDefaultLayout(true); + setPixmap(QPixmap(":/images/empty_reading_list")); + setText(tr("This reading list doesn't cotain comics yet")); +} diff --git a/YACReaderLibrary/empty_reading_list_widget.h b/YACReaderLibrary/empty_reading_list_widget.h new file mode 100644 index 00000000..566b8cfb --- /dev/null +++ b/YACReaderLibrary/empty_reading_list_widget.h @@ -0,0 +1,13 @@ +#ifndef EMPTY_READING_LIST_WIDGET_H +#define EMPTY_READING_LIST_WIDGET_H + +#include +#include "empty_container_info.h" + +class EmptyReadingListWidget : public EmptyContainerInfo +{ +public: + EmptyReadingListWidget(QWidget * parent = 0); +}; + +#endif // EMPTY_READING_LIST_WIDGET_H diff --git a/YACReaderLibrary/empty_special_list.cpp b/YACReaderLibrary/empty_special_list.cpp new file mode 100644 index 00000000..c4ec384d --- /dev/null +++ b/YACReaderLibrary/empty_special_list.cpp @@ -0,0 +1,7 @@ +#include "empty_special_list.h" + +EmptySpecialListWidget::EmptySpecialListWidget(QWidget *parent) + :EmptyContainerInfo(parent) +{ + setUpDefaultLayout(true); +} diff --git a/YACReaderLibrary/empty_special_list.h b/YACReaderLibrary/empty_special_list.h new file mode 100644 index 00000000..f9d4b117 --- /dev/null +++ b/YACReaderLibrary/empty_special_list.h @@ -0,0 +1,13 @@ +#ifndef EMPTY_SPECIAL_LIST_H +#define EMPTY_SPECIAL_LIST_H + +#include +#include "empty_container_info.h" + +class EmptySpecialListWidget : public EmptyContainerInfo +{ +public: + EmptySpecialListWidget(QWidget * parent = 0); +}; + +#endif // EMPTY_SPECIAL_LIST_H diff --git a/YACReaderLibrary/export_comics_info_dialog.cpp b/YACReaderLibrary/export_comics_info_dialog.cpp new file mode 100644 index 00000000..3fb32267 --- /dev/null +++ b/YACReaderLibrary/export_comics_info_dialog.cpp @@ -0,0 +1,92 @@ +#include "export_comics_info_dialog.h" + +#include +#include +#include +#include +#include + +#include "data_base_management.h" + +ExportComicsInfoDialog::ExportComicsInfoDialog(QWidget *parent) + : QDialog(parent) +{ + textLabel = new QLabel(tr("Output file : ")); + path = new QLineEdit; + textLabel->setBuddy(path); + + accept = new QPushButton(tr("Create")); + accept->setDisabled(true); + connect(accept,SIGNAL(clicked()),this,SLOT(exportComicsInfo())); + + cancel = new QPushButton(tr("Cancel")); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + connect(cancel,SIGNAL(clicked()),this,SIGNAL(rejected())); + + find = new QPushButton(QIcon(":/images/find_folder.png"),""); + connect(find,SIGNAL(clicked()),this,SLOT(findPath())); + + QHBoxLayout *libraryLayout = new QHBoxLayout; + + libraryLayout->addWidget(textLabel); + libraryLayout->addWidget(path); + libraryLayout->addWidget(find); + libraryLayout->setStretchFactor(find,0); //TODO + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(accept); + bottomLayout->addWidget(cancel); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(libraryLayout); + mainLayout->addWidget(progress=new QLabel()); + mainLayout->addStretch(); + mainLayout->addLayout(bottomLayout); + + QHBoxLayout * imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(this); + QPixmap p(":/images/exportComicsInfo.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setModal(true); + setWindowTitle(tr("Export comics info")); +} + +ExportComicsInfoDialog::~ExportComicsInfoDialog() +{ + +} + +void ExportComicsInfoDialog::findPath() +{ + QString s = QFileDialog::getSaveFileName(this,tr("Destination database name"),".","*.ydb"); + if(!s.isEmpty()) + { + path->setText(s); + accept->setEnabled(true); + } +} + +void ExportComicsInfoDialog::exportComicsInfo() +{ + QFileInfo f(path->text()); + QFileInfo fPath(f.absoluteDir().path()); + if(fPath.exists() && fPath.isDir() && fPath.isWritable()) + { + DataBaseManagement::exportComicsInfo(source,path->text()); + close(); + } + else + QMessageBox::critical(NULL,tr("Problem found while writing"),tr("The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder")); +} + +void ExportComicsInfoDialog::close() +{ + path->clear(); + QDialog::close(); +} diff --git a/YACReaderLibrary/export_comics_info_dialog.h b/YACReaderLibrary/export_comics_info_dialog.h new file mode 100644 index 00000000..07e3bf0d --- /dev/null +++ b/YACReaderLibrary/export_comics_info_dialog.h @@ -0,0 +1,35 @@ +#ifndef EXPORT_COMICS_INFO_DIALOG_H +#define EXPORT_COMICS_INFO_DIALOG_H + +#include +#include +#include +#include + + +class ExportComicsInfoDialog : public QDialog +{ + Q_OBJECT + +public: + ExportComicsInfoDialog(QWidget *parent = 0); + ~ExportComicsInfoDialog(); + QString source; + +public slots: + void findPath(); + void exportComicsInfo(); + void close(); + +private: + QLabel * progress; + QLabel * textLabel; + QLineEdit * path; + QPushButton * find; + QPushButton * accept; + QPushButton * cancel; + + +}; + +#endif // EXPORT_COMICS_INFO_DIALOG_H diff --git a/YACReaderLibrary/export_library_dialog.cpp b/YACReaderLibrary/export_library_dialog.cpp new file mode 100644 index 00000000..0d20fd2f --- /dev/null +++ b/YACReaderLibrary/export_library_dialog.cpp @@ -0,0 +1,100 @@ +#include "export_library_dialog.h" +#include +#include +#include +#include +#include + +ExportLibraryDialog::ExportLibraryDialog(QWidget * parent) +:QDialog(parent),progressCount(0) +{ + textLabel = new QLabel(tr("Output folder : ")); + path = new QLineEdit; + textLabel->setBuddy(path); + + accept = new QPushButton(tr("Create")); + accept->setDisabled(true); + connect(accept,SIGNAL(clicked()),this,SLOT(exportLibrary())); + + cancel = new QPushButton(tr("Cancel")); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + connect(cancel,SIGNAL(clicked()),this,SIGNAL(rejected())); + + find = new QPushButton(QIcon(":/images/find_folder.png"),""); + connect(find,SIGNAL(clicked()),this,SLOT(findPath())); + + QHBoxLayout *libraryLayout = new QHBoxLayout; + + libraryLayout->addWidget(textLabel); + libraryLayout->addWidget(path); + libraryLayout->addWidget(find); + libraryLayout->setStretchFactor(find,0); //TODO + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(accept); + bottomLayout->addWidget(cancel); + + progressBar = new QProgressBar(this); + progressBar->setMinimum(0); + progressBar->setMaximum(0); + progressBar->setTextVisible(false); + progressBar->hide(); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(libraryLayout); + mainLayout->addStretch(); + mainLayout->addWidget(progressBar); + mainLayout->addLayout(bottomLayout); + + QHBoxLayout * imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(this); + QPixmap p(":/images/exportLibrary.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setModal(true); + setWindowTitle(tr("Create covers package")); +} + +void ExportLibraryDialog::exportLibrary() +{ + QFileInfo f(path->text()); + if(f.exists() && f.isDir() && f.isWritable()) + { + progressBar->show(); + accept->setEnabled(false); + emit exportPath(QDir::cleanPath(path->text())); + } + else + QMessageBox::critical(NULL,tr("Problem found while writing"),tr("The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder")); + +} + +void ExportLibraryDialog::findPath() +{ + QString s = QFileDialog::getExistingDirectory(0,tr("Destination directory"),"."); + if(!s.isEmpty()) + { + path->setText(s); + accept->setEnabled(true); + } +} + +void ExportLibraryDialog::close() +{ + path->clear(); + progressBar->hide(); + accept->setEnabled(false); + progressCount=0; + QDialog::close(); +} + +void ExportLibraryDialog::run() +{ + +} + diff --git a/YACReaderLibrary/export_library_dialog.h b/YACReaderLibrary/export_library_dialog.h new file mode 100644 index 00000000..86bd71b0 --- /dev/null +++ b/YACReaderLibrary/export_library_dialog.h @@ -0,0 +1,35 @@ +#ifndef EXPORT_LIBRARY_DIALOG_H +#define EXPORT_LIBRARY_DIALOG_H + +#include +#include +#include +#include +#include +#include +#include +#include + +class ExportLibraryDialog : public QDialog +{ + Q_OBJECT +public: + ExportLibraryDialog(QWidget * parent = 0); +public slots: + void exportLibrary(); + void findPath(); + void close(); +private: + int progressCount; + QProgressBar *progressBar; + QLabel * textLabel; + QLineEdit * path; + QPushButton * find; + QPushButton * accept; + QPushButton * cancel; + void run(); +signals: + void exportPath(QString); +}; + +#endif diff --git a/YACReaderLibrary/files.qrc b/YACReaderLibrary/files.qrc new file mode 100644 index 00000000..d436db6d --- /dev/null +++ b/YACReaderLibrary/files.qrc @@ -0,0 +1,12 @@ + + + ../files/about.html + ../files/helpYACReaderLibrary.html + + + + ../files/about_es_ES.html + ../files/helpYACReaderLibrary_es_ES.html + + + diff --git a/YACReaderLibrary/grid_comics_view.cpp b/YACReaderLibrary/grid_comics_view.cpp new file mode 100644 index 00000000..aca99e1e --- /dev/null +++ b/YACReaderLibrary/grid_comics_view.cpp @@ -0,0 +1,343 @@ +#include "grid_comics_view.h" + +#include +#include + +#include "yacreader_global.h" +#include "comic.h" +#include "comic_files_manager.h" +#include "QsLog.h" + +GridComicsView::GridComicsView(QWidget *parent) : + ComicsView(parent),_selectionModel(NULL) +{ + qmlRegisterType("comicModel",1,0,"TableModel"); + + view = new QQuickView(); + container = QWidget::createWindowContainer(view, this); + + container->setMinimumSize(200, 200); + container->setFocusPolicy(Qt::TabFocus); + view->setSource(QUrl("qrc:/qml/GridComicsView.qml")); + + setShowMarks(true);//TODO save this in settings + + QVBoxLayout * l = new QVBoxLayout; + l->addWidget(container); + this->setLayout(l); + + setContentsMargins(0,0,0,0); + l->setContentsMargins(0,0,0,0); + l->setSpacing(0); + + QLOG_INFO() << "GridComicsView"; +} + +GridComicsView::~GridComicsView() +{ + delete view; +} + +void GridComicsView::setToolBar(QToolBar *toolBar) +{ + QLOG_INFO() << "setToolBar"; + static_cast(this->layout())->insertWidget(1,toolBar); + this->toolbar = toolBar; +} + +void GridComicsView::setModel(ComicModel *model) +{ + QLOG_INFO() << "setModel"; + + QQmlContext *ctxt = view->rootContext(); + + //there is only one mothel in the system + ComicsView::setModel(model); + if(this->model != NULL) + { + QLOG_INFO() << "xxx"; + + if(_selectionModel != NULL) + delete _selectionModel; + _selectionModel = new QItemSelectionModel(this->model); + + ctxt->setContextProperty("comicsList", this->model); + ctxt->setContextProperty("comicsSelection", _selectionModel); + ctxt->setContextProperty("contextMenuHelper",this); + ctxt->setContextProperty("comicsSelectionHelper", this); + ctxt->setContextProperty("comicRatingHelper", this); + ctxt->setContextProperty("dummyValue", true); + ctxt->setContextProperty("dragManager", this); + ctxt->setContextProperty("dropManager", this); + + if(model->rowCount()>0) + setCurrentIndex(model->index(0,0)); + } + +#ifdef Q_OS_MAC + ctxt->setContextProperty("backgroundColor", "#F5F5F5"); + ctxt->setContextProperty("cellColor", "#FFFFFF"); + ctxt->setContextProperty("selectedColor", "#FFFFFF"); + ctxt->setContextProperty("selectedBorderColor", "#007AFF"); + ctxt->setContextProperty("borderColor", "#DBDBDB"); + ctxt->setContextProperty("titleColor", "#121212"); + ctxt->setContextProperty("textColor", "#636363"); + //fonts settings + ctxt->setContextProperty("fontSize", 11); + ctxt->setContextProperty("fontFamily", QApplication::font().family()); + ctxt->setContextProperty("fontSpacing", 0.5); + +#else + ctxt->setContextProperty("backgroundColor", "#2A2A2A"); + ctxt->setContextProperty("cellColor", "#212121"); + ctxt->setContextProperty("selectedColor", "#121212"); + ctxt->setContextProperty("selectedBorderColor", "#121212"); + ctxt->setContextProperty("borderColor", "#121212"); + ctxt->setContextProperty("titleColor", "#E6E6E6"); + ctxt->setContextProperty("textColor", "#E6E6E6"); + ctxt->setContextProperty("dropShadow",false); + //fonts settings + int fontSize = QApplication::font().pointSize(); + if(fontSize == -1) + fontSize = QApplication::font().pixelSize(); + ctxt->setContextProperty("fontSize", fontSize); + ctxt->setContextProperty("fontFamily", QApplication::font().family()); + ctxt->setContextProperty("fontSpacing", 0.5); +#endif + + +} + +void GridComicsView::setCurrentIndex(const QModelIndex &index) +{ + QLOG_INFO() << "setCurrentIndex"; + _selectionModel->clear(); + _selectionModel->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); + view->rootContext()->setContextProperty("dummyValue", true); +} + +QModelIndex GridComicsView::currentIndex() +{ + QLOG_INFO() << "currentIndex"; + QModelIndexList indexes = _selectionModel->selectedRows(); + if(indexes.length()>0) + return indexes[0]; + + this->selectIndex(0); + return _selectionModel->selectedRows()[0]; +} + +QItemSelectionModel *GridComicsView::selectionModel() +{ + QLOG_INFO() << "selectionModel"; + QModelIndexList indexes = _selectionModel->selectedRows(); + if(indexes.length()==0) + this->selectIndex(0); + + return _selectionModel; +} + +void GridComicsView::scrollTo(const QModelIndex &mi, QAbstractItemView::ScrollHint hint) +{ + QLOG_INFO() << "scrollTo"; +} + +void GridComicsView::toFullScreen() +{ + QLOG_INFO() << "toFullScreen"; + toolbar->hide(); +} + +void GridComicsView::toNormal() +{ + QLOG_INFO() << "toNormal"; + toolbar->show(); +} + +void GridComicsView::updateConfig(QSettings *settings) +{ + QLOG_INFO() << "updateConfig"; +} + +void GridComicsView::enableFilterMode(bool enabled) +{ + +} + +void GridComicsView::selectAll() +{ + QLOG_INFO() << "selectAll"; + QModelIndex top = model->index(0, 0); + QModelIndex bottom = model->index(model->rowCount()-1, 0); + QItemSelection selection(top, bottom); + _selectionModel->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows); + view->rootContext()->setContextProperty("dummyValue", true); +} + +void GridComicsView::rate(int index, int rating) +{ + QLOG_INFO() << "Comic "<< index << "rated" << rating; + model->updateRating(rating,model->index(index,0)); +} + +void GridComicsView::requestedContextMenu(const QPoint &point) +{ + emit customContextMenuViewRequested(point); +} + +QSize GridComicsView::sizeHint() +{ + QLOG_INFO() << "sizeHint"; + return QSize(1280,768); +} + +QByteArray GridComicsView::getMimeDataFromSelection() +{ + QByteArray data; + + QMimeData * mimeData = model->mimeData(_selectionModel->selectedIndexes()); + data = mimeData->data(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat); + + delete mimeData; + + return data; +} + +void GridComicsView::startDrag() +{ + QLOG_DEBUG() << "performDrag"; + QDrag *drag = new QDrag(this); + drag->setMimeData(model->mimeData(_selectionModel->selectedRows())); + drag->setPixmap(QPixmap(":/images/openInYACReader.png")); //TODO add better image + + /*Qt::DropAction dropAction =*/ drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); +} + +bool GridComicsView::canDropUrls(const QList &urls, Qt::DropAction action) +{ + if(action == Qt::CopyAction) + { + QString currentPath; + foreach (QUrl url, urls) + { + //comics or folders are accepted, folders' content is validate in dropEvent (avoid any lag before droping) + currentPath = url.toLocalFile(); + if(Comic::fileIsComic(currentPath) || QFileInfo(currentPath).isDir()) + return true; + } + } + return false; +} + +bool GridComicsView::canDropFormats(const QString &formats) +{ + return (formats.contains(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat) && model->canBeResorted()); +} + +void GridComicsView::droppedFiles(const QList &urls, Qt::DropAction action) +{ + bool validAction = action == Qt::CopyAction; //TODO add move + + if(validAction) + { + QList > droppedFiles = ComicFilesManager::getDroppedFiles(urls); + emit copyComicsToCurrentFolder(droppedFiles); + } +} + +void GridComicsView::droppedComicsForResortingAt(const QString &data, int index) +{ + model->dropMimeData(model->mimeData(_selectionModel->selectedRows()), Qt::MoveAction, index, 0, QModelIndex()); +} + +//helper +void GridComicsView::selectIndex(int index) +{ + QLOG_INFO() << "selectIndex" << index; + if(_selectionModel != NULL && model!=NULL) + { + _selectionModel->select(model->index(index,0),QItemSelectionModel::Select | QItemSelectionModel::Rows); + view->rootContext()->setContextProperty("dummyValue", true); + } +} + +void GridComicsView::setCurrentIndex(int index) +{ + setCurrentIndex(model->index(index,0)); +} + +void GridComicsView::deselectIndex(int index) +{ + if(_selectionModel != NULL && model!=NULL) + { + _selectionModel->select(model->index(index,0),QItemSelectionModel::Deselect | QItemSelectionModel::Rows); + view->rootContext()->setContextProperty("dummyValue", true); + } +} + +bool GridComicsView::isSelectedIndex(int index) +{ + if(_selectionModel != NULL && model!=NULL) + { + QModelIndex mi = model->index(index,0); + return _selectionModel->isSelected(mi); + } + return false; +} + +void GridComicsView::clear() +{ + QLOG_INFO() << "clear"; + if(_selectionModel != NULL) + { + _selectionModel->clear(); + + QQmlContext *ctxt = view->rootContext(); + ctxt->setContextProperty("dummyValue", true); + } + //model->forceClear(); +} + +void GridComicsView::selectedItem(int index) +{ + emit doubleClicked(model->index(index,0)); +} + +int GridComicsView::numItemsSelected() +{ + if(_selectionModel != NULL) + { + return _selectionModel->selectedRows().length(); + } + + return 0; +} + +int GridComicsView::lastSelectedIndex() +{ + if(_selectionModel != NULL) + { + QLOG_INFO() << "last selected index " << _selectionModel->selectedRows().last().row(); + return _selectionModel->selectedRows().last().row(); + } + + return -1; +} + +void GridComicsView::setShowMarks(bool show) +{ + QLOG_INFO() << "setShowMarks"; + QQmlContext *ctxt = view->rootContext(); + ctxt->setContextProperty("show_marks", show); +} + +void GridComicsView::closeEvent(QCloseEvent *event) +{ + QLOG_INFO() << "closeEvent"; + QObject *object = view->rootObject(); + QMetaObject::invokeMethod(object, "exit"); + container->close(); + view->close(); + event->accept(); + ComicsView::closeEvent(event); +} diff --git a/YACReaderLibrary/grid_comics_view.h b/YACReaderLibrary/grid_comics_view.h new file mode 100644 index 00000000..77d3c343 --- /dev/null +++ b/YACReaderLibrary/grid_comics_view.h @@ -0,0 +1,79 @@ +#ifndef GRID_COMICS_VIEW_H +#define GRID_COMICS_VIEW_H + +#include "comics_view.h" + +#include + +class QAbstractListModel; +class QItemSelectionModel; +class QQuickView; +class QQuickView; + + +class GridComicsView : public ComicsView +{ + Q_OBJECT +public: + explicit GridComicsView(QWidget *parent = 0); + virtual ~GridComicsView(); + void setToolBar(QToolBar * toolBar); + void setModel(ComicModel *model); + void setCurrentIndex(const QModelIndex &index); + QModelIndex currentIndex(); + QItemSelectionModel * selectionModel(); + void scrollTo(const QModelIndex & mi, QAbstractItemView::ScrollHint hint ); + void toFullScreen(); + void toNormal(); + void updateConfig(QSettings * settings); + void enableFilterMode(bool enabled); + QSize sizeHint(); + QByteArray getMimeDataFromSelection(); + + +signals: + void comicRated(int,QModelIndex); + void doubleClicked(QModelIndex); + +public slots: + //selection helper + void selectIndex(int index); + void setCurrentIndex(int index); + void deselectIndex(int index); + bool isSelectedIndex(int index); + void clear(); + //double clicked item + void selectedItem(int index); + int numItemsSelected(); + int lastSelectedIndex(); + + //ComicsView + void setShowMarks(bool show); + void selectAll(); + + //rating + void rate(int index, int rating); + + //dragManager + void startDrag(); + //dropManager + bool canDropUrls(const QList & urls, Qt::DropAction action); + bool canDropFormats(const QString &formats); + void droppedFiles(const QList & urls, Qt::DropAction action); + void droppedComicsForResortingAt(const QString & data, int index); + + +protected slots: + void requestedContextMenu(const QPoint & point); + +private: + QToolBar * toolbar; + QItemSelectionModel * _selectionModel; + QQuickView *view; + QWidget *container; + bool dummy; + void closeEvent ( QCloseEvent * event ); + +}; + +#endif // GRID_COMICS_VIEW_H diff --git a/YACReaderLibrary/icon.ico b/YACReaderLibrary/icon.ico new file mode 100644 index 00000000..b2232648 Binary files /dev/null and b/YACReaderLibrary/icon.ico differ diff --git a/YACReaderLibrary/icon.rc b/YACReaderLibrary/icon.rc new file mode 100644 index 00000000..ef707930 --- /dev/null +++ b/YACReaderLibrary/icon.rc @@ -0,0 +1,3 @@ +IDI_ICON1 ICON DISCARDABLE "icon.ico" +IDI_ICON2 ICON DISCARDABLE "icon2.ico" +IDI_ICON3 ICON DISCARDABLE "icon3.ico" \ No newline at end of file diff --git a/YACReaderLibrary/icon2.ico b/YACReaderLibrary/icon2.ico new file mode 100644 index 00000000..e8777842 Binary files /dev/null and b/YACReaderLibrary/icon2.ico differ diff --git a/YACReaderLibrary/icon3.ico b/YACReaderLibrary/icon3.ico new file mode 100644 index 00000000..bf3802dc Binary files /dev/null and b/YACReaderLibrary/icon3.ico differ diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc new file mode 100644 index 00000000..caffa5a1 --- /dev/null +++ b/YACReaderLibrary/images.qrc @@ -0,0 +1,99 @@ + + + ../images/sidebar/folder.png + ../images/sidebar/folder_finished.png + ../images/icon.png + ../images/iconLibrary.png + ../images/new.png + ../images/openLibrary.png + ../images/removeLibraryIcon.png + ../images/updateLibraryIcon.png + ../images/comicFolder.png + ../images/notCover.png + ../images/edit.png + ../images/editIcon.png + ../images/flow1.png + ../images/flow2.png + ../images/flow3.png + ../images/flow4.png + ../images/flow5.png + ../images/importLibrary.png + ../images/importLibraryIcon.png + ../images/exportLibrary.png + ../images/exportLibraryIcon.png + ../images/importLibraryIcon.png + ../images/open.png + ../images/coversPackage.png + ../images/setRead.png + ../images/setUnread.png + ../images/showMarks.png + ../images/editComic.png + ../images/selectAll.png + ../images/hideComicFlow.png + ../images/exportComicsInfo.png + ../images/importComicsInfo.png + ../images/exportComicsInfoIcon.png + ../images/importComicsInfoIcon.png + ../images/db.png + ../images/asignNumber.png + ../images/defaultCover.png + ../images/iphoneConfig.png + ../images/onStartFlowSelection.png + ../images/onStartFlowSelection_es.png + ../images/useNewFlowButton.png + ../images/useOldFlowButton.png + ../images/serverConfigBackground.png + ../images/noLibrariesIcon.png + ../images/noLibrariesLine.png + ../images/importingIcon.png + ../images/updatingIcon.png + ../images/importTopCoversDecoration.png + ../images/importBottomCoversDecoration.png + ../images/glowLine.png + ../images/readRibbon.png + ../images/readingRibbon.png + ../images/shownCovers.png + ../images/hiddenCovers.png + ../images/trash.png + ../images/setReadButton.png + ../images/openInYACReader.png + ../images/main_toolbar/divider.png + ../images/sidebar/collapsed_branch_osx.png + ../images/sidebar/expanded_branch_osx.png + ../images/sidebar/libraryIconSelected.png + ../images/sidebar/libraryOptions.png + ../images/sidebar/branch-open.png + ../images/sidebar/branch-closed.png + ../images/sidebar/expanded_branch_selected.png + ../images/sidebar/collapsed_branch_selected.png + ../images/previousCoverPage.png + ../images/nextCoverPage.png + ../images/getInfo.png + ../images/comic_vine/radioChecked.png + ../images/comic_vine/radioUnchecked.png + ../images/comic_vine/radioUnchecked.png + ../images/comic_vine/rowDown.png + ../images/comic_vine/rowUp.png + ../images/comic_vine/previousPage.png + ../images/comic_vine/nextPage.png + ../images/comic_vine/downArrow.png + ../images/comic_vine/upArrow.png + ../images/find_folder.png + ../images/clear_shortcut.png + ../images/accept_shortcut.png + ../images/f_overlayed.png + ../images/f_overlayed_retina.png + ../images/shortcuts_group_comics.png + ../images/shortcuts_group_folders.png + ../images/shortcuts_group_general.png + ../images/shortcuts_group_libraries.png + ../images/shortcuts_group_mglass.png + ../images/shortcuts_group_page.png + ../images/shortcuts_group_reading.png + ../images/shortcuts_group_visualization.png + ../images/searching_icon.png + ../images/empty_label.png + ../images/empty_current_readings.png + ../images/empty_favorites.png + + diff --git a/YACReaderLibrary/images_osx.qrc b/YACReaderLibrary/images_osx.qrc new file mode 100644 index 00000000..5f9106a3 --- /dev/null +++ b/YACReaderLibrary/images_osx.qrc @@ -0,0 +1,80 @@ + + + ../images/folder_finished_macosx.png + ../images/main_toolbar/back_osx.png + ../images/main_toolbar/back_osx@2x.png + ../images/main_toolbar/forward_osx.png + ../images/main_toolbar/forward_osx@2x.png + ../images/main_toolbar/settings_osx.png + ../images/main_toolbar/settings_osx@2x.png + ../images/main_toolbar/server_osx.png + ../images/main_toolbar/server_osx@2x.png + ../images/main_toolbar/help_osx.png + ../images/main_toolbar/help_osx@2x.png + ../images/main_toolbar/flow_osx.png + ../images/main_toolbar/flow_osx@2x.png + ../images/main_toolbar/grid_osx.png + ../images/main_toolbar/grid_osx@2x.png + ../images/flow_to_grid_osx.gif + ../images/grid_to_flow_osx.gif + ../images/empty_folder_osx.png + ../images/empty_search_osx.png + ../images/iconSearch.png + ../images/clearSearch.png + + ../images/lists/default_0_osx.png + ../images/lists/default_1_osx.png + ../images/lists/label_blue_osx.png + ../images/lists/label_cyan_osx.png + ../images/lists/label_dark_osx.png + ../images/lists/label_green_osx.png + ../images/lists/label_light_osx.png + ../images/lists/label_orange_osx.png + ../images/lists/label_pink_osx.png + ../images/lists/label_purple_osx.png + ../images/lists/label_red_osx.png + ../images/lists/label_violet_osx.png + ../images/lists/label_white_osx.png + ../images/lists/label_yellow_osx.png + ../images/lists/list_osx.png + ../images/empty_reading_list_osx.png + + ../images/lists/default_0_osx@2x.png + ../images/lists/default_1_osx@2x.png + ../images/lists/label_blue_osx@2x.png + ../images/lists/label_cyan_osx@2x.png + ../images/lists/label_dark_osx@2x.png + ../images/lists/label_green_osx@2x.png + ../images/lists/label_light_osx@2x.png + ../images/lists/label_orange_osx@2x.png + ../images/lists/label_pink_osx@2x.png + ../images/lists/label_purple_osx@2x.png + ../images/lists/label_red_osx@2x.png + ../images/lists/label_violet_osx@2x.png + ../images/lists/label_white_osx@2x.png + ../images/lists/label_yellow_osx@2x.png + ../images/lists/list_osx@2x.png + + ../images/sidebar/libraryIcon_osx.png + ../images/sidebar/setRoot_osx.png + ../images/sidebar/expand_osx.png + ../images/sidebar/colapse_osx.png + ../images/sidebar/newLibraryIcon_osx.png + ../images/sidebar/openLibraryIcon_osx.png + ../images/sidebar/addNew_sidebar_osx.png + ../images/sidebar/delete_sidebar_osx.png + ../images/sidebar/addLabelIcon_osx.png + ../images/sidebar/renameListIcon_osx.png + + + ../images/sidebar/setRoot_osx@2x.png + ../images/sidebar/expand_osx@2x.png + ../images/sidebar/colapse_osx@2x.png + ../images/sidebar/newLibraryIcon_osx@2x.png + ../images/sidebar/openLibraryIcon_osx@2x.png + ../images/sidebar/addNew_sidebar_osx@2x.png + ../images/sidebar/delete_sidebar_osx@2x.png + ../images/sidebar/addLabelIcon_osx@2x.png + ../images/sidebar/renameListIcon_osx@2x.png + + diff --git a/YACReaderLibrary/images_win.qrc b/YACReaderLibrary/images_win.qrc new file mode 100644 index 00000000..0e042c76 --- /dev/null +++ b/YACReaderLibrary/images_win.qrc @@ -0,0 +1,47 @@ + + + ../images/main_toolbar/back.png + ../images/main_toolbar/back_disabled.png + ../images/main_toolbar/forward.png + ../images/main_toolbar/forward_disabled.png + ../images/main_toolbar/settings.png + ../images/main_toolbar/server.png + ../images/main_toolbar/help.png + ../images/main_toolbar/fullscreen.png + ../images/sidebar/libraryIcon.png + ../images/sidebar/setRoot.png + ../images/sidebar/expand.png + ../images/sidebar/colapse.png + ../images/sidebar/newLibraryIcon.png + ../images/sidebar/openLibraryIcon.png + ../images/main_toolbar/flow.png + ../images/main_toolbar/grid.png + ../images/flow_to_grid.gif + ../images/grid_to_flow.gif + ../images/empty_folder.png + ../images/empty_search.png + ../images/sidebar/addNew_sidebar.png + ../images/sidebar/delete_sidebar.png + ../images/iconSearchNew.png + ../images/clearSearchNew.png + ../images/sidebar/addLabelIcon.png + ../images/sidebar/renameListIcon.png + + ../images/lists/default_0.png + ../images/lists/default_1.png + ../images/lists/label_blue.png + ../images/lists/label_cyan.png + ../images/lists/label_dark.png + ../images/lists/label_green.png + ../images/lists/label_light.png + ../images/lists/label_orange.png + ../images/lists/label_pink.png + ../images/lists/label_purple.png + ../images/lists/label_red.png + ../images/lists/label_violet.png + ../images/lists/label_white.png + ../images/lists/label_yellow.png + ../images/lists/list.png + ../images/empty_reading_list.png + + \ No newline at end of file diff --git a/YACReaderLibrary/import_comics_info_dialog.cpp b/YACReaderLibrary/import_comics_info_dialog.cpp new file mode 100644 index 00000000..e82ec33d --- /dev/null +++ b/YACReaderLibrary/import_comics_info_dialog.cpp @@ -0,0 +1,111 @@ +#include "import_comics_info_dialog.h" + +#include +#include +#include +#include + +#include "data_base_management.h" + +ImportComicsInfoDialog::ImportComicsInfoDialog(QWidget *parent) + : QDialog(parent) +{ + setModal(true); + setWindowTitle(tr("Import comics info")); + + + textLabel = new QLabel(tr("Info database location : ")); + path = new QLineEdit; + textLabel->setBuddy(path); + + accept = new QPushButton(tr("Import")); + accept->setDisabled(true); + connect(accept,SIGNAL(clicked()),this,SLOT(import())); + + cancel = new QPushButton(tr("Cancel")); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + //connect(cancel,SIGNAL(clicked()),this,SIGNAL(rejected())); + + find = new QPushButton(QIcon(":/images/find_folder.png"),""); + connect(find,SIGNAL(clicked()),this,SLOT(findPath())); + + QHBoxLayout *libraryLayout = new QHBoxLayout; + + libraryLayout->addWidget(textLabel); + libraryLayout->addWidget(path); + libraryLayout->addWidget(find); + libraryLayout->setStretchFactor(find,0); //TODO + + progressBar = new QProgressBar(this); + progressBar->setMinimum(0); + progressBar->setMaximum(0); + progressBar->setTextVisible(false); + progressBar->hide(); + connect(accept,SIGNAL(clicked()),progressBar,SLOT(show())); + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(accept); + bottomLayout->addWidget(cancel); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(libraryLayout); + mainLayout->addStretch(); + mainLayout->addWidget(progressBar); + mainLayout->addLayout(bottomLayout); + + QHBoxLayout * imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(this); + QPixmap p(":/images/importComicsInfo.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setModal(true); +} + +ImportComicsInfoDialog::~ImportComicsInfoDialog() +{ + +} + + +void ImportComicsInfoDialog::findPath() +{ + QString s = QFileDialog::getOpenFileName(0,"Comics Info",".",tr("Comics info file (*.ydb)")); + if(!s.isEmpty()) + { + path->setText(s); + accept->setEnabled(true); + } +} + +void ImportComicsInfoDialog::import() +{ + progressBar->show(); + + Importer * importer = new Importer(); + importer->source = path->text(); + importer->dest = dest; + connect(importer,SIGNAL(finished()),this,SLOT(close())); + connect(importer,SIGNAL(finished()),this,SLOT(hide())); + importer->start(); +} + +void ImportComicsInfoDialog::close() +{ + path->clear(); + progressBar->hide(); + accept->setDisabled(true); + QDialog::close(); + emit(finished(0)); +} + +void Importer::run() +{ + DataBaseManagement::importComicsInfo(source,dest); +} + + diff --git a/YACReaderLibrary/import_comics_info_dialog.h b/YACReaderLibrary/import_comics_info_dialog.h new file mode 100644 index 00000000..edc5e85e --- /dev/null +++ b/YACReaderLibrary/import_comics_info_dialog.h @@ -0,0 +1,52 @@ +#ifndef IMPORT_COMICS_INFO_DIALOG_H +#define IMPORT_COMICS_INFO_DIALOG_H + +#include +#include +#include +#include +#include +#include +#include + +class Importer : public QThread +{ +public: + QString source; + QString dest; +private: + void run(); +}; + +class ImportComicsInfoDialog : public QDialog +{ + Q_OBJECT + +public: + ImportComicsInfoDialog(QWidget *parent = 0); + ~ImportComicsInfoDialog(); + QString dest; + +private: + QLabel * nameLabel; + QLabel * textLabel; + QLabel * destLabel; + QLineEdit * path; + QLineEdit * destPath; + QLineEdit * nameEdit; + QPushButton * find; + QPushButton * findDest; + QPushButton * accept; + QPushButton * cancel; + QLabel * progress; + void setupUI(); + int progressCount; + QProgressBar *progressBar; + +public slots: + void findPath(); + void import(); + void close(); +}; + +#endif // IMPORT_COMICS_INFO_DIALOG_H diff --git a/YACReaderLibrary/import_library_dialog.cpp b/YACReaderLibrary/import_library_dialog.cpp new file mode 100644 index 00000000..7aadbf0c --- /dev/null +++ b/YACReaderLibrary/import_library_dialog.cpp @@ -0,0 +1,157 @@ +#include "import_library_dialog.h" + +#include +#include +#include +#include +#include + +ImportLibraryDialog::ImportLibraryDialog(QWidget * parent) +:QDialog(parent),progressCount(0) +{ + setupUI(); +} + +void ImportLibraryDialog::setupUI() +{ + nameLabel = new QLabel(tr("Library Name : ")); + nameEdit = new QLineEdit; + nameLabel->setBuddy(nameEdit); + connect(nameEdit,SIGNAL(textChanged(QString)),this,SLOT(nameEntered())); + + textLabel = new QLabel(tr("Package location : ")); + path = new QLineEdit; + textLabel->setBuddy(path); + + destLabel = new QLabel(tr("Destination folder : ")); + destPath = new QLineEdit; + textLabel->setBuddy(destPath); + + accept = new QPushButton(tr("Unpack")); + accept->setDisabled(true); + connect(accept,SIGNAL(clicked()),this,SLOT(add())); + + cancel = new QPushButton(tr("Cancel")); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + //connect(cancel,SIGNAL(clicked()),this,SIGNAL(rejected())); + + find = new QPushButton(QIcon(":/images/find_folder.png"),""); + connect(find,SIGNAL(clicked()),this,SLOT(findPath())); + + findDest = new QPushButton(QIcon(":/images/find_folder.png"),""); + connect(findDest,SIGNAL(clicked()),this,SLOT(findDestination())); + + QGridLayout * content = new QGridLayout; + + content->addWidget(nameLabel,0,0); + content->addWidget(nameEdit,0,1); + + content->addWidget(textLabel,1,0); + content->addWidget(path,1,1); + content->addWidget(find,1,2); + content->setColumnStretch(2,0); //TODO + + content->addWidget(destLabel,2,0); + content->addWidget(destPath,2,1); + content->addWidget(findDest,2,2); + //destLayout->setStretchFactor(findDest,0); //TODO + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(accept); + bottomLayout->addWidget(cancel); + + progressBar = new QProgressBar(this); + progressBar->setMinimum(0); + progressBar->setMaximum(0); + progressBar->setTextVisible(false); + progressBar->hide(); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(content); + //mainLayout->addWidget(progress = new QLabel()); + mainLayout->addStretch(); + mainLayout->addWidget(progressBar); + mainLayout->addLayout(bottomLayout); + + QHBoxLayout * imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(this); + QPixmap p(":/images/importLibrary.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setModal(true); + setWindowTitle(tr("Extract a catalog")); +} +void ImportLibraryDialog::open(const YACReaderLibraries &libs) +{ + libraries = libs; + QDialog::open(); +} + +void ImportLibraryDialog::add() +{ + if(!libraries.contains(nameEdit->text())) + { + accept->setEnabled(false); + progressBar->show(); + emit(unpackCLC(QDir::cleanPath(path->text()),QDir::cleanPath(destPath->text()),nameEdit->text())); + } + else + { + emit(libraryExists(nameEdit->text())); + } +} + +void ImportLibraryDialog::findPath() +{ + QString s = QFileDialog::getOpenFileName(0,"Covers Package",".",tr("Compresed library covers (*.clc)")); + if(!s.isEmpty()) + { + path->setText(s); + if(!destPath->text().isEmpty() && !nameEdit->text().isEmpty()) + accept->setEnabled(true); + } +} + + +void ImportLibraryDialog::findDestination() +{ + QString s = QFileDialog::getExistingDirectory(0,"Folder",".",QFileDialog::ShowDirsOnly); + if(!s.isEmpty()) + { + destPath->setText(s); + if(!path->text().isEmpty() && !nameEdit->text().isEmpty()) + accept->setEnabled(true); + } +} + +void ImportLibraryDialog::nameEntered() +{ + if(!nameEdit->text().isEmpty()) + { + if(!path->text().isEmpty() && !destPath->text().isEmpty()) + accept->setEnabled(true); + } + else + accept->setEnabled(false); +} + +void ImportLibraryDialog::close() +{ + path->clear(); + destPath->clear(); + nameEdit->clear(); + accept->setEnabled(false); + progressBar->hide(); + QDialog::hide(); +} + +void ImportLibraryDialog::closeEvent ( QCloseEvent * e ) +{ + close(); + e->accept(); +} diff --git a/YACReaderLibrary/import_library_dialog.h b/YACReaderLibrary/import_library_dialog.h new file mode 100644 index 00000000..09febeae --- /dev/null +++ b/YACReaderLibrary/import_library_dialog.h @@ -0,0 +1,46 @@ +#ifndef IMPORT_LIBRARY_DIALOG_H +#define IMPORT_LIBRARY_DIALOG_H +#include "yacreader_libraries.h" + +#include +#include +#include +#include +#include +#include + + class ImportLibraryDialog : public QDialog + { + Q_OBJECT + public: + ImportLibraryDialog(QWidget * parent = 0); + private: + QLabel * nameLabel; + QLabel * textLabel; + QLabel * destLabel; + QLineEdit * path; + QLineEdit * destPath; + QLineEdit * nameEdit; + QPushButton * find; + QPushButton * findDest; + QPushButton * accept; + QPushButton * cancel; + QProgressBar *progressBar; + void setupUI(); + int progressCount; + void closeEvent ( QCloseEvent * e ); + YACReaderLibraries libraries; + public slots: + void add(); + void findPath(); + void findDestination(); + void close(); + void nameEntered(); + void open(const YACReaderLibraries & libs); + + signals: + void unpackCLC(QString clc,QString targetFolder, QString name); + void libraryExists(const QString & name); + }; + +#endif diff --git a/YACReaderLibrary/import_widget.cpp b/YACReaderLibrary/import_widget.cpp new file mode 100644 index 00000000..0e325e26 --- /dev/null +++ b/YACReaderLibrary/import_widget.cpp @@ -0,0 +1,388 @@ +#include "import_widget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//TODO: is QGLWidget needed here??? +//#include +#include +#include +#include +#include + +#include +#include + +class YACReaderActivityIndicatorWidget : public QWidget +{ +public: + YACReaderActivityIndicatorWidget(QWidget * parent = 0); +public slots: + +private: + QLabel * normal; + QLabel * glow; +}; + +YACReaderActivityIndicatorWidget::YACReaderActivityIndicatorWidget(QWidget * parent) + :QWidget(parent) +{ + QPixmap line(":/images/noLibrariesLine.png"); + QPixmap glowLine(":/images/glowLine.png"); + normal = new QLabel(this); + glow = new QLabel(this); + + normal->setPixmap(line); + glow->setPixmap(glowLine); + + + + QHBoxLayout * layout = new QHBoxLayout(); + + layout->addWidget(normal,0,Qt::AlignVCenter); + + setLayout(layout); + + layout->setMargin(4); + layout->setSpacing(0); + + //setFixedHeight(3); + //resize(579,3); + glow->setGeometry(4,4,glowLine.width(),glowLine.height()); + //normal->setGeometry(0,1,579,1); + + QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect(); + //effect->setOpacity(1.0); + + + QPropertyAnimation * animation = new QPropertyAnimation(effect,"opacity"); + + animation->setDuration(1000); + animation->setStartValue(1); + animation->setEndValue(0); + //animation->setEasingCurve(QEasingCurve::InQuint); + + QPropertyAnimation * animation2 = new QPropertyAnimation(effect,"opacity"); + + animation2->setDuration(1000); + animation2->setStartValue(0); + animation2->setEndValue(1); + //animation2->setEasingCurve(QEasingCurve::InQuint); + + glow->setGraphicsEffect(effect); + + connect(animation,SIGNAL(finished()),animation2,SLOT(start())); + connect(animation2,SIGNAL(finished()),animation,SLOT(start())); + + animation->start(); +} + + + + +ImportWidget::ImportWidget(QWidget *parent) : + QWidget(parent) +{ + setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); + + QPalette p(palette()); + p.setColor(QPalette::Background, QColor(250,250,250)); + setAutoFillBackground(true); + setPalette(p); + + QPixmap icon(":/images/importingIcon.png"); + iconLabel = new QLabel(); + iconLabel->setPixmap(icon); + + /*QPixmap line(":/images/noLibrariesLine.png"); + QLabel * lineLabel = new QLabel(); + lineLabel->setPixmap(line);*/ + + YACReaderActivityIndicatorWidget * activityIndicator = new YACReaderActivityIndicatorWidget(); + + text = new QLabel();//""+tr("Importing comics")+""); + text->setStyleSheet("QLabel {font-size:25px;font-weight:bold;}"); + textDescription = new QLabel();//""+tr("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")+""); + textDescription->setWordWrap(true); + textDescription->setMaximumWidth(330); + currentComicLabel = new QLabel("..."); + + coversViewContainer = new QWidget(this); + QVBoxLayout * coversViewLayout = new QVBoxLayout; + coversViewContainer->setLayout(coversViewLayout); + coversViewContainer->setMaximumHeight(316); + coversViewContainer->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Maximum); + + coversView = new QGraphicsView(); + //coversView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); + coversView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + coversView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + coversView->setMaximumHeight(300); + coversView->setStyleSheet("QGraphicsView {background-color: #E6E6E6;border:none;}"); + + coversScene = new QGraphicsScene(); + coversScene->setSceneRect(0,0,coversView->width(),coversView->height()); + coversView->setAlignment(Qt::AlignLeft); + coversView->setScene(coversScene); + + + QLabel * topDecorator = new QLabel(); + QLabel * bottomDecorator = new QLabel(); + QPixmap top(":/images/importTopCoversDecoration.png"); + QPixmap bottom(":/images/importBottomCoversDecoration.png"); + topDecorator->setPixmap(top); + bottomDecorator->setPixmap(bottom); + topDecorator->setScaledContents(true); + bottomDecorator->setScaledContents(true); + topDecorator->setFixedHeight(top.height()); + bottomDecorator->setFixedHeight(bottom.height()); + + coversViewLayout->addWidget(topDecorator,0); + coversViewLayout->addWidget(coversView,1); + coversViewLayout->addWidget(bottomDecorator,0); + coversViewLayout->setMargin(0); + coversViewLayout->setSpacing(0); + + QPushButton * stop = new QPushButton(tr("stop")); + stop->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum); + + QVBoxLayout * layout = new QVBoxLayout(this); + QHBoxLayout * buttonLayout = new QHBoxLayout(); + QHBoxLayout * topLayout = new QHBoxLayout(); + QVBoxLayout * textLayout = new QVBoxLayout(); + + QWidget * topWidget = new QWidget(); + topWidget->setFixedWidth(650); + textLayout->addStretch(); + textLayout->addWidget(text); + textLayout->addSpacing(12); + textLayout->addWidget(textDescription); + textLayout->addStretch(); + + topLayout->addStretch(); + topLayout->addWidget(iconLabel,0,Qt::AlignVCenter); + topLayout->addSpacing(30); + topLayout->addLayout(textLayout,1); + topLayout->addStretch(); + topLayout->setMargin(0); + + topWidget->setLayout(topLayout); + + layout->setAlignment(Qt::AlignHCenter); + + buttonLayout->addSpacing(250); + buttonLayout->addWidget(stop); + buttonLayout->addSpacing(250); + + layout->addSpacing(50); + layout->addWidget(topWidget,0,Qt::AlignHCenter); + layout->addSpacing(20); + layout->addWidget(activityIndicator,0,Qt::AlignHCenter); + layout->addSpacing(10); + layout->addLayout(buttonLayout,0); + layout->addSpacing(10); + layout->addStretch(); + portadasLabel = new QLabel(""+tr("Some of the comics being added...")+""); + + hideButton = new QToolButton(this); + hideButton->setFixedSize(25,18); + hideButton->setStyleSheet("QToolButton {background: url(\":/images/shownCovers.png\"); border:none;}" + " QToolButton:checked {background:url(\":/images/hiddenCovers.png\"); border:none;}"); + hideButton->setCheckable(true); + + connect(hideButton,SIGNAL(toggled(bool)),this,SLOT(showCovers(bool))); + + layout->addWidget(portadasLabel,0,Qt::AlignHCenter); + layout->addWidget(coversViewContainer); + //layout->addStretch(); + layout->addWidget(currentComicLabel,0,Qt::AlignHCenter); + layout->setContentsMargins(0,layout->contentsMargins().top(),0,layout->contentsMargins().bottom()); + + connect(stop,SIGNAL(clicked()),this,SIGNAL(stop())); + //connect(stop,SIGNAL(clicked()),this,SLOT(addCoverTest())); + + previousWidth = 10; + updatingCovers = false; + elapsedTimer = new QElapsedTimer(); + elapsedTimer->start(); +} + +void ImportWidget::newComic(const QString & path, const QString & coverPath) +{ + currentComicLabel->setText(""+path+""); + + if(((elapsedTimer->elapsed()>=1000) || ((previousWidth < coversView->width()) && (elapsedTimer->elapsed()>=500))) && !updatingCovers)//todo elapsed time + { + + QPixmap p(coverPath); + p = p.scaledToHeight(300,Qt::SmoothTransformation); + QGraphicsPixmapItem * item = new QGraphicsPixmapItem(p); + item->setPos(previousWidth,0); + item->setZValue(i/10000.0); + previousWidth += 10 + p.width(); + coversScene->addItem(item); + + elapsedTimer->start(); + if(previousWidth >= coversView->width()+200 && !updatingCovers) + { + updatingCovers = true; + + foreach(QGraphicsItem * itemToRemove, coversScene->items()) + { + QGraphicsPixmapItem * last = dynamic_cast(itemToRemove); + + if((last->pos().x()+last->pixmap().width())<=0) + { + coversScene->removeItem(last); + delete last; + } + //else + // break; + } + + int width = p.width(); + + foreach(QGraphicsItem * itemToMove, coversScene->items()) + { + QTimeLine *timer = new QTimeLine(400); + timer->setFrameRange(0, 24); + timer->setUpdateInterval(17); + + QGraphicsItemAnimation *animation = new QGraphicsItemAnimation; + animation->setItem(itemToMove); + animation->setTimeLine(timer); + + QPointF point = itemToMove->scenePos(); + float step = (width+10)/24.0; + for (int i = 0; i < 24; ++i) + animation->setPosAt(i / 24.0, QPointF(point.x()-((i+1)*step), point.y())); + + timer->start(); + connect(timer,SIGNAL(finished()),timer,SLOT(deleteLater())); + connect(timer,SIGNAL(finished()),animation,SLOT(deleteLater())); + } + + QTimer::singleShot(400,this,SLOT(finishedUpdatingCover())); + + previousWidth -= 10+width; + } + + } +} + +void ImportWidget::finishedUpdatingCover() +{ + updatingCovers = false; +} + +void ImportWidget::newCover(const QPixmap & image) +{ + Q_UNUSED(image) +} +static int i = 1; +static int previousWidth = 10; +static int j = 0; +void ImportWidget::addCoverTest() +{ + QPixmap p(QString("c:/temp/%1.jpg").arg(i)); + p = p.scaledToHeight(300,Qt::SmoothTransformation); + QGraphicsPixmapItem * item = new QGraphicsPixmapItem(p); + item->setPos(previousWidth,0); + item->setZValue(i/10000.0); + previousWidth += 10 + p.width(); + coversScene->addItem(item); + if(previousWidth >= coversView->width()) + { + QGraphicsItem * last = coversScene->items().last(); + int width = p.width(); + if(j>=1) + { + coversScene->removeItem(last); + delete last; + } + else + j++; + + foreach(QGraphicsItem * itemToMove, coversScene->items()) + { + + QTimeLine *timer = new QTimeLine(/*350*/1000); + timer->setFrameRange(0, 60); + + QGraphicsItemAnimation *animation = new QGraphicsItemAnimation; + animation->setItem(itemToMove); + animation->setTimeLine(timer); + + QPointF point = itemToMove->scenePos(); + float step = (width+10)/60.0; + for (int i = 0; i < 60; ++i) + animation->setPosAt(i / 60.0, QPointF(point.x()-((i+1)*step), point.y())); + + timer->start(); + } + previousWidth -= 10+width; + } + + i++; +} + +void ImportWidget::clear() +{ + previousWidth = 10; + + //nos aseguramos de que las animaciones han finalizado antes de borrar + QList all = coversScene->items(); + for (int i = 0; i < all.size(); i++) + { + QGraphicsItem *gi = all[i]; + if(gi->parentItem()==NULL) + delete gi; + } + coversScene->clear(); + + updatingCovers = false; + + currentComicLabel->setText("..."); + + this->i = 0; +} + +void ImportWidget::setImportLook() +{ + iconLabel->setPixmap(QPixmap(":/images/importingIcon.png")); + text->setText(""+tr("Importing comics")+""); + textDescription->setText(""+tr("

YACReaderLibrary is now creating a new library.

Create a library could take several minutes. You can stop the process and update the library later for completing the task.

")+"
"); +} + +void ImportWidget::setUpdateLook() +{ + iconLabel->setPixmap(QPixmap(":/images/updatingIcon.png")); + text->setText(""+tr("Updating the library")+""); + textDescription->setText(""+tr("

The current library is being updated. For faster updates, please, update your libraries frequently.

You can stop the process and continue updating this library later.

")+"
"); +} + +void ImportWidget::clearScene() +{ + + +} + +void ImportWidget::showCovers(bool hide) +{ + portadasLabel->setHidden(hide); + coversViewContainer->setHidden(hide); +} + +void ImportWidget::resizeEvent(QResizeEvent * event) +{ + hideButton->move(event->size().width()-hideButton->width()- (currentComicLabel->height()/2),event->size().height()-hideButton->height()- (currentComicLabel->height()/2)); + + QWidget::resizeEvent(event); +} diff --git a/YACReaderLibrary/import_widget.h b/YACReaderLibrary/import_widget.h new file mode 100644 index 00000000..5ff57814 --- /dev/null +++ b/YACReaderLibrary/import_widget.h @@ -0,0 +1,52 @@ +#ifndef IMPORT_WIDGET_H +#define IMPORT_WIDGET_H + +#include + +class QLabel; +class QGraphicsView; +class QGraphicsScene; +class QElapsedTimer; +class QVBoxLayout; +class QToolButton; +class QResizeEvent; + +class ImportWidget : public QWidget +{ + Q_OBJECT +public: + explicit ImportWidget(QWidget *parent = 0); + +signals: + void stop(); +public slots: + void newComic(const QString & path, const QString & coverPath); + void newCover(const QPixmap & image); + void clear(); + void addCoverTest(); + void finishedUpdatingCover(); + void clearScene(); + void setImportLook(); + void setUpdateLook(); + void showCovers(bool hide); +private: + QLabel * currentComicLabel; + QLabel * portadasLabel; + QLabel * iconLabel; + QLabel * text; + QLabel * textDescription; + QWidget * coversViewContainer; + QGraphicsView * coversView; + QGraphicsScene * coversScene; + int previousWidth; + bool updatingCovers; + QElapsedTimer * elapsedTimer; + quint64 i; + + QToolButton * hideButton; + + void resizeEvent(QResizeEvent * event); + +}; + +#endif // IMPORT_WIDGET_H diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp new file mode 100644 index 00000000..8b5662f4 --- /dev/null +++ b/YACReaderLibrary/library_creator.cpp @@ -0,0 +1,742 @@ +#include "library_creator.h" +#include "custom_widgets.h" + +#include +#include +#include +#include +#include +#include + +#include "data_base_management.h" +#include "qnaturalsorting.h" +#include "db_helper.h" + +#include "compressed_archive.h" +#include "comic.h" + +#include "yacreader_global.h" + +#include "QsLog.h" + +#include +using namespace std; + +#ifdef Q_OS_MAC + #include "pdf_comic.h" +#else + +#if QT_VERSION >= 0x050000 + #include "poppler-qt5.h" +#else + #include "poppler-qt4.h" +#endif + +#endif + +//-------------------------------------------------------------------------------- +LibraryCreator::LibraryCreator() + :creation(false), partialUpdate(false) +{ + _nameFilter << Comic::comicExtensions; +} + +void LibraryCreator::createLibrary(const QString &source, const QString &target) +{ + creation = true; + processLibrary(source, target); +} + +void LibraryCreator::updateLibrary(const QString &source, const QString &target) +{ + partialUpdate = false; + processLibrary(source, target); +} + +void LibraryCreator::updateFolder(const QString &source, const QString &target, const QString &sourceFolder, const QModelIndex & dest) +{ + partialUpdate = true; + folderDestinationModelIndex = dest; + + _currentPathFolders.clear(); + _currentPathFolders.append(Folder(1,1,"root","/")); + + QString relativeFolderPath = sourceFolder; + relativeFolderPath = relativeFolderPath.remove(QDir::cleanPath(source)); + + if(relativeFolderPath.startsWith("/")) + { + relativeFolderPath = relativeFolderPath.remove(0,1);//remove firts '/' + } + + QStringList folders; + + if(!relativeFolderPath.isEmpty()) //updating root + { + folders = relativeFolderPath.split('/'); + } + + QLOG_DEBUG() << "folders found in relative path : " << folders << "-" << relativeFolderPath; + + QSqlDatabase db = DataBaseManagement::loadDatabase(target); + + foreach (QString folderName, folders) + { + if(folderName.isEmpty()) + { + break; + } + qulonglong parentId = _currentPathFolders.last().id; + _currentPathFolders.append(DBHelper::loadFolder(folderName, parentId, db)); + QLOG_DEBUG() << "Folder appended : " << _currentPathFolders.last().id << " " << _currentPathFolders.last().name << " with parent" << _currentPathFolders.last().parentId; + } + + QSqlDatabase::removeDatabase(_database.connectionName()); + + QLOG_DEBUG() << "Relative path : " << relativeFolderPath; + + _sourceFolder = sourceFolder; + + processLibrary(source, target); +} + +void LibraryCreator::processLibrary(const QString & source, const QString & target) +{ + _source = source; + _target = target; + if(DataBaseManagement::checkValidDB(target+"/library.ydb")=="") + { + //se limpia el directorio ./yacreaderlibrary + QDir d(target); + d.removeRecursively(); + _mode = CREATOR; + } + else + { // + _mode = UPDATER; + } +} + + +// +void LibraryCreator::run() +{ + stopRunning = false; +#ifndef use_unarr +//check for 7z lib +#if defined Q_OS_UNIX && !defined Q_OS_MAC + QLibrary *sevenzLib = new QLibrary(QString(LIBDIR)+"/p7zip/7z.so"); +#else + QLibrary *sevenzLib = new QLibrary(QApplication::applicationDirPath()+"/utils/7z"); +#endif + + if(!sevenzLib->load()) + { + QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << endl; + QApplication::exit(YACReader::SevenZNotFound); + exit(); + } + sevenzLib->deleteLater(); +#endif + if(_mode == CREATOR) + { + QLOG_INFO() << "Starting to create new library ( " << _source << "," << _target << ")"; + _currentPathFolders.clear(); + _currentPathFolders.append(Folder(1,1,"root","/")); + //se crean los directorios .yacreaderlibrary y .yacreaderlibrary/covers + QDir dir; + dir.mkpath(_target+"/covers"); + + //se crea la base de datos .yacreaderlibrary/library.ydb + _database = DataBaseManagement::createDatabase("library",_target);// + if(!_database.isOpen()) + { + QLOG_ERROR() << "Unable to create data base" << _database.lastError().databaseText() + "-" + _database.lastError().driverText(); + emit failedCreatingDB(_database.lastError().databaseText() + "-" + _database.lastError().driverText()); + emit finished(); + creation = false; + return; + } + + /*QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);*/ + _database.transaction(); + //se crea la librería + create(QDir(_source)); + _database.commit(); + _database.close(); + QSqlDatabase::removeDatabase(_database.connectionName()); + emit(created()); + QLOG_INFO() << "Create library END"; + } + else + { + QLOG_INFO() << "Starting to update folder" << _sourceFolder << "in library ( " << _source << "," << _target << ")"; + if(!partialUpdate) + { + _currentPathFolders.clear(); + _currentPathFolders.append(Folder(1,1,"root","/")); + QLOG_DEBUG() << "update whole library"; + } + + _database = DataBaseManagement::loadDatabase(_target); + //_database.setDatabaseName(_target+"/library.ydb"); + if(!_database.open()) + { + QLOG_ERROR() << "Unable to open data base" << _database.lastError().databaseText() + "-" + _database.lastError().driverText(); + emit failedOpeningDB(_database.lastError().databaseText() + "-" + _database.lastError().driverText()); + emit finished(); + creation = false; + return; + } + QSqlQuery pragma("PRAGMA foreign_keys = ON",_database); + _database.transaction(); + + if(partialUpdate) + { + update(QDir(_sourceFolder)); + } + else + { + update(QDir(_source)); + } + _database.commit(); + _database.close(); + QSqlDatabase::removeDatabase(_target); + //si estabamos en modo creación, se está añadiendo una librería que ya existía y se ha actualizado antes de añadirse. + if(!partialUpdate) + { + if(!creation) + { + emit(updated()); + } + else + { + emit(created()); + } + } + QLOG_INFO() << "Update library END"; + } + //msleep(100);//TODO try to solve the problem with the udpate dialog (ya no se usa más...) + if(partialUpdate) + { + emit updatedCurrentFolder(folderDestinationModelIndex); + emit finished(); + } + else //TODO check this part!! + emit finished(); + creation = false; +} + +void LibraryCreator::stop() +{ + _database.commit(); + stopRunning = true; +} + +//retorna el id del ultimo de los folders +qulonglong LibraryCreator::insertFolders() +{ + QList::iterator i; + int currentId = 0; + for (i = _currentPathFolders.begin(); i != _currentPathFolders.end(); ++i) + { + if(!(i->knownId)) + { + i->setFather(currentId); + currentId = DBHelper::insert(&(*i),_database);//insertFolder(currentId,*i); + i->setId(currentId); + } + else + { + currentId = i->id; + } + } + return currentId; +} + +void LibraryCreator::create(QDir dir) +{ + dir.setNameFilters(_nameFilter); + dir.setFilter(QDir::AllDirs|QDir::Files|QDir::NoDotAndDotDot); + QFileInfoList list = dir.entryInfoList(); + for (int i = 0; i < list.size(); ++i) + { + if(stopRunning) + return; + QFileInfo fileInfo = list.at(i); + QString fileName = fileInfo.fileName(); +#ifdef Q_OS_MAC + QStringList src = _source.split("/"); + QString filePath = fileInfo.absoluteFilePath(); + QStringList fp = filePath.split("/"); + for(int i = 0; i< src.count();i++) + { + fp.removeFirst(); + } + QString relativePath = "/" + fp.join("/"); +#else + QString relativePath = QDir::cleanPath(fileInfo.absoluteFilePath()).remove(_source); +#endif + if(fileInfo.isDir()) + { + QLOG_INFO() << "Parsing folder" << fileInfo.canonicalPath() ; + //se añade al path actual el folder, aún no se sabe si habrá que añadirlo a la base de datos + _currentPathFolders.append(Folder(fileInfo.fileName(),relativePath)); + create(QDir(fileInfo.absoluteFilePath())); + //una vez importada la información del folder, se retira del path actual ya que no volverá a ser visitado + _currentPathFolders.pop_back(); + } + else + { + QLOG_INFO() << "Parsing file" << fileInfo.filePath(); + insertComic(relativePath,fileInfo); + } + } +} + +bool LibraryCreator::checkCover(const QString & hash) +{ + return QFile::exists(_target+"/covers/"+hash+".jpg"); +} + +void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo & fileInfo) +{ + //Se calcula el hash del cómic + + QCryptographicHash crypto(QCryptographicHash::Sha1); + QFile file(fileInfo.absoluteFilePath()); + file.open(QFile::ReadOnly); + crypto.addData(file.read(524288)); + file.close(); + //hash Sha1 del primer 0.5MB + filesize + QString hash = QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size()); + ComicDB comic = DBHelper::loadComic(fileInfo.fileName(),relativePath,hash,_database); + int numPages = 0; + bool exists = checkCover(hash); + if(! ( comic.hasCover() && exists)) + { + ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg",comic.info.coverPage.toInt()); + tc.create(); + numPages = tc.getNumPages(); + if (numPages > 0) + { + emit(comicAdded(relativePath,_target+"/covers/"+hash+".jpg")); + } + } + + if (numPages > 0 || exists) + { + //en este punto sabemos que todos los folders que hay en _currentPath, deberían estar añadidos a la base de datos + insertFolders(); + comic.info.numPages = numPages; + comic.parentId = _currentPathFolders.last().id; + DBHelper::insert(&comic,_database); + } +} + +void LibraryCreator::update(QDir dirS) +{ + //QLOG_TRACE() << "Updating" << dirS.absolutePath(); + //QLOG_TRACE() << "Getting info from dir" << dirS.absolutePath(); + dirS.setNameFilters(_nameFilter); + dirS.setFilter(QDir::AllDirs|QDir::NoDotAndDotDot); + dirS.setSorting(QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); + QFileInfoList listSFolders = dirS.entryInfoList(); + dirS.setFilter(QDir::Files|QDir::NoDotAndDotDot); + dirS.setSorting(QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); + QFileInfoList listSFiles = dirS.entryInfoList(); + + qSort(listSFolders.begin(),listSFolders.end(),naturalSortLessThanCIFileInfo); + qSort(listSFiles.begin(),listSFiles.end(),naturalSortLessThanCIFileInfo); + + QFileInfoList listS; + listS.append(listSFolders); + listS.append(listSFiles); + //QLOG_DEBUG() << "---------------------------------------------------------"; + //foreach(QFileInfo info,listS) + // QLOG_DEBUG() << info.fileName(); + + //QLOG_TRACE() << "END Getting info from dir" << dirS.absolutePath(); + + //QLOG_TRACE() << "Getting info from DB" << dirS.absolutePath(); + QList folders = DBHelper::getFoldersFromParent(_currentPathFolders.last().id,_database); + QList comics = DBHelper::getComicsFromParent(_currentPathFolders.last().id,_database); + //QLOG_TRACE() << "END Getting info from DB" << dirS.absolutePath(); + + QList listD; + qSort(folders.begin(),folders.end(),naturalSortLessThanCILibraryItem); + qSort(comics.begin(),comics.end(),naturalSortLessThanCILibraryItem); + listD.append(folders); + listD.append(comics); + //QLOG_DEBUG() << "---------------------------------------------------------"; + //foreach(LibraryItem * info,listD) + // QLOG_DEBUG() << info->name; + //QLOG_DEBUG() << "---------------------------------------------------------"; + int lenghtS = listS.size(); + int lenghtD = listD.size(); + //QLOG_DEBUG() << "S len" << lenghtS << "D len" << lenghtD; + //QLOG_DEBUG() << "---------------------------------------------------------"; + + bool updated; + int i,j; + for (i=0,j=0; (i < lenghtS)||(j < lenghtD);) + { + if(stopRunning) + return; + updated = false; + if(i>=lenghtS) //finished source files/dirs + { + //QLOG_WARN() << "finished source files/dirs" << dirS.absolutePath(); + //delete listD //from j + for(;j=lenghtD) //finished library files/dirs + { + //QLOG_WARN() << "finished library files/dirs" << dirS.absolutePath(); + //create listS //from i + for(;iname; + + int comparation = QString::localeAwareCompare(nameS,nameD); + if(fileInfoS.isDir()&&fileInfoD->isDir()) + if(comparation == 0)//same folder, update + { + _currentPathFolders.append(*static_cast(fileInfoD));//fileInfoD conoce su padre y su id + update(QDir(fileInfoS.absoluteFilePath())); + _currentPathFolders.pop_back(); + i++; + j++; + } + else + if(comparation < 0) //nameS doesn't exist on DB + { + + if(nameS!="/.yacreaderlibrary") + { + //QLOG_WARN() << "dir source < dest" << nameS << nameD; +#ifdef Q_OS_MAC + QStringList src = _source.split("/"); + QString filePath = fileInfoS.absoluteFilePath(); + QStringList fp = filePath.split("/"); + for(int i = 0; i< src.count();i++) + { + fp.removeFirst(); + } + QString path = "/" + fp.join("/"); +#else + QString path = QDir::cleanPath(fileInfoS.absoluteFilePath()).remove(_source); +#endif + _currentPathFolders.append(Folder(fileInfoS.fileName(),path)); + create(QDir(fileInfoS.absoluteFilePath())); + _currentPathFolders.pop_back(); + } + i++; + } + else //nameD no longer available on Source folder... + { + if(nameS!="/.yacreaderlibrary") + { + //QLOG_WARN() << "dir source > dest" << nameS << nameD; + DBHelper::removeFromDB(fileInfoD,_database); + j++; + } + else + i++; //skip library directory + } + else // one of them(or both) is a file + if(fileInfoS.isDir()) //this folder doesn't exist on library + { + if(nameS!="/.yacreaderlibrary") //skip .yacreaderlibrary folder + { + //QLOG_WARN() << "one of them(or both) is a file" << nameS << nameD; +#ifdef Q_OS_MAC + QStringList src = _source.split("/"); + QString filePath = fileInfoS.absoluteFilePath(); + QStringList fp = filePath.split("/"); + for(int i = 0; i< src.count();i++) + { + fp.removeFirst(); + } + QString path = "/" + fp.join("/"); +#else + QString path = QDir::cleanPath(fileInfoS.absoluteFilePath()).remove(_source); +#endif + _currentPathFolders.append(Folder(fileInfoS.fileName(),path)); + create(QDir(fileInfoS.absoluteFilePath())); + _currentPathFolders.pop_back(); + } + i++; + } + else + if(fileInfoD->isDir()) //delete this folder from library + { + DBHelper::removeFromDB(fileInfoD,_database); + j++; + } + else //both are files //BUG on windows (no case sensitive) + { + //nameD.remove(nameD.size()-4,4); + int comparation = QString::localeAwareCompare(nameS,nameD); + if(comparation < 0) //create new thumbnail + { +#ifdef Q_OS_MAC + QStringList src = _source.split("/"); + QString filePath = fileInfoS.absoluteFilePath(); + QStringList fp = filePath.split("/"); + for(int i = 0; i< src.count();i++) + { + fp.removeFirst(); + } + QString path = "/" + fp.join("/"); +#else + QString path = QDir::cleanPath(fileInfoS.absoluteFilePath()).remove(_source); +#endif + insertComic(path,fileInfoS); + i++; + } + else + { + if(comparation > 0) //delete thumbnail + { + DBHelper::removeFromDB(fileInfoD,_database); + j++; + } + else //same file + { + if(fileInfoS.isFile() && !fileInfoD->isDir()) + { + //TODO comprobar fechas + tamaño + //if(fileInfoS.lastModified()>fileInfoD.lastModified()) + //{ + // dirD.mkpath(_target+(QDir::cleanPath(fileInfoS.absolutePath()).remove(_source))); + // emit(coverExtracted(QDir::cleanPath(fileInfoS.absoluteFilePath()).remove(_source))); + // ThumbnailCreator tc(QDir::cleanPath(fileInfoS.absoluteFilePath()),_target+(QDir::cleanPath(fileInfoS.absoluteFilePath()).remove(_source))+".jpg"); + // tc.create(); + //} + } + i++;j++; + } + } + } + } + } +} + +bool ThumbnailCreator::crash = false; + +ThumbnailCreator::ThumbnailCreator(QString fileSource, QString target, int coverPage) +:_fileSource(fileSource),_target(target),_numPages(0),_coverPage(coverPage) +{ +} + +void ThumbnailCreator::create() +{ + QFileInfo fi(_fileSource); + if(!fi.exists()) //TODO: error file not found. + { + _cover.load(":/images/notCover.png"); + QLOG_WARN() << "Extracting cover: file not found " << _fileSource; + return; + } + + if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0) + { + +#ifdef Q_OS_MAC + MacOSXPDFComic * pdfComic = new MacOSXPDFComic(); + if(!pdfComic->openComic(_fileSource)) + { + delete pdfComic; + //QImage p; + //p.load(":/images/notCover.png"); + //p.save(_target); + return; + } +#else + Poppler::Document * pdfComic = Poppler::Document::load(_fileSource); +#endif + if (!pdfComic) + { + QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource; + //delete pdfComic; //TODO check if the delete is needed + pdfComic = 0; + //QImage p; + //p.load(":/images/notCover.png"); + //p.save(_target); + return; + } +#ifndef Q_OS_MAC + //poppler only, not mac + if (pdfComic->isLocked()) + { + QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource; + delete pdfComic; + return; + } +#endif + _numPages = pdfComic->numPages(); + if(_numPages >= _coverPage) + { +#ifdef Q_OS_MAC + { //TODO is this "{" one too much? + QImage p = pdfComic->getPage(_coverPage-1); //TODO check if the page is valid +#else + QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72); +#endif + _cover = QPixmap::fromImage(p); + if(_target!="") + { + QImage scaled; + if(p.width()>p.height()) //landscape?? + { + scaled = p.scaledToWidth(640,Qt::SmoothTransformation); + } + else + { + scaled = p.scaledToWidth(480,Qt::SmoothTransformation); + } + scaled.save(_target,0,75); + } +#ifdef Q_OS_MAC + } //TODO is this "{" one too much? + pdfComic->releaseLastPageData(); +#endif + } + else if(_target!="") + { + QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource; + //QImage p; + //p.load(":/images/notCover.png"); + //p.save(_target); + } + + delete pdfComic; + } + else + { + + if(crash) + { + return; + } + + CompressedArchive archive(_fileSource); + if(!archive.toolsLoaded()) + { + QLOG_WARN() << "Extracting cover: 7z lib not loaded"; + crash = true; + return; + } + if(!archive.isValid()) + { + QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource; + } + //se filtran para obtener sólo los formatos soportados + QList order = archive.getFileNames(); + QList fileNames = FileComic::filter(order); + _numPages = fileNames.size(); + if(_numPages == 0) + { + QLOG_WARN() << "Extracting cover: empty comic " << _fileSource; + _cover.load(":/images/notCover.png"); + if(_target!="") + { + _cover.save(_target); + } + } + else + { + if(_coverPage > _numPages) + { + _coverPage = 1; + } + qSort(fileNames.begin(),fileNames.end(), naturalSortLessThanCI); + int index = order.indexOf(fileNames.at(_coverPage-1)); + + if(_target=="") + { + if(!_cover.loadFromData(archive.getRawDataAtIndex(index))) + { + QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource; + _cover.load(":/images/notCover.png"); + } + } + else + { + QImage p; + if(p.loadFromData(archive.getRawDataAtIndex(index))) + { + QImage scaled; + if(p.width()>p.height()) //landscape?? + { + scaled = p.scaledToWidth(640,Qt::SmoothTransformation); + } + else + { + scaled = p.scaledToWidth(480,Qt::SmoothTransformation); + } + scaled.save(_target,0,75); + } + else + { + QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource; + //p.load(":/images/notCover.png"); + //p.save(_target); + } + } + } + } +} diff --git a/YACReaderLibrary/library_creator.h b/YACReaderLibrary/library_creator.h new file mode 100644 index 00000000..83c06164 --- /dev/null +++ b/YACReaderLibrary/library_creator.h @@ -0,0 +1,94 @@ +#ifndef __LIBRARY_CREATOR_H +#define __LIBRARY_CREATOR_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "folder.h" +#include "comic_db.h" + + + class LibraryCreator : public QThread + { + Q_OBJECT + public: + LibraryCreator(); + void createLibrary(const QString & source, const QString & target); + void updateLibrary(const QString & source, const QString & target); + void updateFolder(const QString & source, const QString & target, const QString & folder, const QModelIndex &dest); + void stop(); + + private: + void processLibrary(const QString & source, const QString & target); + enum Mode {CREATOR,UPDATER}; + //atributos "globales" durante el proceso de creación y actualización + enum Mode _mode; + QString _source; + QString _target; + QString _sourceFolder; //used for partial updates + QStringList _nameFilter; + QSqlDatabase _database; + QList _currentPathFolders; //lista de folders en el orden en el que están siendo explorados, el último es el folder actual + //recursive method + void create(QDir currentDirectory); + void update(QDir currentDirectory); + void run(); + qulonglong insertFolders();//devuelve el id del último folder añadido (último en la ruta) + bool checkCover(const QString & hash); + void insertComic(const QString & relativePath,const QFileInfo & fileInfo); + //qulonglong insertFolder(qulonglong parentId,const Folder & folder); + //qulonglong insertComic(const Comic & comic); + bool stopRunning; + //LibraryCreator está en modo creación si creation == true; + bool creation; + bool partialUpdate; + QModelIndex folderDestinationModelIndex; + + signals: + void finished(); + void coverExtracted(QString); + void folderUpdated(QString); + void comicAdded(QString,QString); + void updated(); + void created(); + void failedCreatingDB(QString); + void failedOpeningDB(QString); + void updatedCurrentFolder(QModelIndex); + }; + + class ThumbnailCreator : public QObject + { + Q_OBJECT + + public: + ThumbnailCreator(QString fileSource, QString target="", int coverPage = 1); + private: + QString _fileSource; + QString _target; + QString _currentName; + int _numPages; + QPixmap _cover; + int _coverPage; + static bool crash; + + public slots: + void create(); + int getNumPages(){return _numPages;}; + QPixmap getCover(){return _cover;}; + signals: + void openingError(QProcess::ProcessError error); + + }; + +#endif diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp new file mode 100644 index 00000000..51675d36 --- /dev/null +++ b/YACReaderLibrary/library_window.cpp @@ -0,0 +1,2722 @@ +#include "library_window.h" +#include "custom_widgets.h" +#include "folder_item.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef NO_OPENGL +#include +#endif +#include + +#include +#include + +#include "data_base_management.h" +#include "yacreader_global.h" +#include "onstart_flow_selection_dialog.h" +#include "no_libraries_widget.h" +#include "import_widget.h" + +#include "yacreader_search_line_edit.h" +#include "comic_db.h" +#include "library_creator.h" +#include "package_manager.h" +#include "comic_flow_widget.h" +#include "create_library_dialog.h" +#include "rename_library_dialog.h" +#include "properties_dialog.h" +#include "export_library_dialog.h" +#include "import_library_dialog.h" +#include "export_comics_info_dialog.h" +#include "import_comics_info_dialog.h" +#include "add_library_dialog.h" +#include "options_dialog.h" +#include "help_about_dialog.h" +#include "server_config_dialog.h" +#include "comic_model.h" +#include "yacreader_tool_bar_stretch.h" +#include "yacreader_table_view.h" + +#include "yacreader_dark_menu.h" +#include "yacreader_titled_toolbar.h" +#include "yacreader_main_toolbar.h" + +#include "yacreader_sidebar.h" + +#include "comics_remover.h" +#include "yacreader_library_list_widget.h" +#include "yacreader_folders_view.h" + +#include "comic_vine_dialog.h" +#include "api_key_dialog.h" +//#include "yacreader_social_dialog.h" + +#include "classic_comics_view.h" +#include "grid_comics_view.h" +#include "comics_view_transition.h" +#include "empty_folder_widget.h" +#include "empty_label_widget.h" +#include "empty_special_list.h" +#include "empty_reading_list_widget.h" + +#include "edit_shortcuts_dialog.h" +#include "shortcuts_manager.h" + +#include "no_search_results_widget.h" + +#include "comic_files_manager.h" + +#include "reading_list_model.h" +#include "yacreader_reading_lists_view.h" +#include "add_label_dialog.h" + +#include "yacreader_history_controller.h" +#include "db_helper.h" + +#include "reading_list_item.h" +#include "opengl_checker.h" + +#include "QsLog.h" + +#ifdef Q_OS_WIN + #include +#endif + +#ifdef Q_OS_MAC +//#include +#endif + +LibraryWindow::LibraryWindow() + :QMainWindow(),fullscreen(false),fetching(false),previousFilter(""),removeError(false),status(LibraryWindow::Normal) +{ + setupUI(); + + loadLibraries(); + + if(libraries.isEmpty()) + { + showNoLibrariesWidget(); + } + else + { + showRootWidget(); + selectedLibrary->setCurrentIndex(0); + } + + +} + +void LibraryWindow::setupUI() +{ + setWindowIcon(QIcon(":/images/iconLibrary.png")); + + setUnifiedTitleAndToolBarOnMac(true); + + libraryCreator = new LibraryCreator(); + packageManager = new PackageManager(); + + settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + settings->beginGroup("libraryConfig"); + + historyController = new YACReaderHistoryController(this); + + createActions(); + doModels(); + + doLayout(); + createToolBars(); + doDialogs(); + createMenus(); + + navigationController = new YACReaderNavigationController(this); + + createConnections(); + + setWindowTitle(tr("YACReader Library")); + + setMinimumSize(800,480); + + //restore + if(settings->contains(MAIN_WINDOW_GEOMETRY)) + restoreGeometry(settings->value(MAIN_WINDOW_GEOMETRY).toByteArray()); + else + //if(settings->value(USE_OPEN_GL).toBool() == false) + showMaximized(); + + /*if(settings->contains(COMICS_VIEW_HEADERS_GEOMETRY)) + comicsView->horizontalHeader()->restoreGeometry(settings->value(COMICS_VIEW_HEADERS_GEOMETRY).toByteArray());*/ + + /*socialDialog = new YACReaderSocialDialog(this); + socialDialog->setHidden(true);*/ +} + +void LibraryWindow::doLayout() +{ + //LAYOUT ELEMENTS------------------------------------------------------------ + //--------------------------------------------------------------------------- + + QSplitter * sHorizontal = new QSplitter(Qt::Horizontal); //spliter principal +#ifdef Q_OS_MAC + sHorizontal->setStyleSheet("QSplitter::handle{image:none;background-color:#B8B8B8;} QSplitter::handle:vertical {height:1px;}"); +#else + sHorizontal->setStyleSheet("QSplitter::handle:vertical {height:4px;}"); +#endif + + //TOOLBARS------------------------------------------------------------------- + //--------------------------------------------------------------------------- + editInfoToolBar = new QToolBar(); + editInfoToolBar->setStyleSheet("QToolBar {border: none;}"); + +#ifdef Q_OS_MAC + libraryToolBar = new YACReaderMacOSXToolbar(this); +#else + libraryToolBar = new YACReaderMainToolBar(this); +#endif + +#ifndef NO_OPENGL + //FLOW----------------------------------------------------------------------- + //--------------------------------------------------------------------------- + + OpenGLChecker openGLChecker; + bool openGLAvailable = openGLChecker.hasCompatibleOpenGLVersion(); + + if(openGLAvailable && !settings->contains(USE_OPEN_GL)) + settings->setValue(USE_OPEN_GL,2); + else + if(!openGLAvailable) + settings->setValue(USE_OPEN_GL,0); +#endif + //FOLDERS FILTER------------------------------------------------------------- + //--------------------------------------------------------------------------- +#ifndef Q_OS_MAC + //in MacOSX the searchEdit is created using the toolbar wrapper + searchEdit = new YACReaderSearchLineEdit(); +#endif + + //SIDEBAR-------------------------------------------------------------------- + //--------------------------------------------------------------------------- + sideBar = new YACReaderSideBar; + + foldersView = sideBar->foldersView; + listsView = sideBar->readingListsView; + selectedLibrary = sideBar->selectedLibrary; + + YACReaderTitledToolBar * librariesTitle = sideBar->librariesTitle; + YACReaderTitledToolBar * foldersTitle = sideBar->foldersTitle; + YACReaderTitledToolBar * readingListsTitle = sideBar->readingListsTitle; + + librariesTitle->addAction(createLibraryAction); + librariesTitle->addAction(openLibraryAction); + librariesTitle->addSpacing(3); + + foldersTitle->addAction(addFolderAction); + foldersTitle->addAction(deleteFolderAction); + foldersTitle->addSepartor(); + foldersTitle->addAction(setRootIndexAction); + foldersTitle->addAction(expandAllNodesAction); + foldersTitle->addAction(colapseAllNodesAction); + + readingListsTitle->addAction(addReadingListAction); + //readingListsTitle->addSepartor(); + readingListsTitle->addAction(addLabelAction); + //readingListsTitle->addSepartor(); + readingListsTitle->addAction(renameListAction); + readingListsTitle->addAction(deleteReadingListAction); + readingListsTitle->addSpacing(3); + + //FINAL LAYOUT------------------------------------------------------------- + comicsViewStack = new QStackedWidget(); + + if(!settings->contains(COMICS_VIEW_STATUS) || settings->value(COMICS_VIEW_STATUS) == Flow) { + comicsView = classicComicsView = new ClassicComicsView(); + comicsViewStatus = Flow; + //comicsViewStack->setCurrentIndex(Flow); + } else { + comicsView = gridComicsView = new GridComicsView(); + comicsViewStatus = Grid; + //comicsViewStack->setCurrentIndex(Grid); + } + + doComicsViewConnections(); + + comicsView->setToolBar(editInfoToolBar); + comicsViewStack->addWidget(comicsViewTransition = new ComicsViewTransition()); + comicsViewStack->addWidget(emptyFolderWidget = new EmptyFolderWidget()); + comicsViewStack->addWidget(emptyLabelWidget = new EmptyLabelWidget()); + comicsViewStack->addWidget(emptySpecialList = new EmptySpecialListWidget()); + comicsViewStack->addWidget(emptyReadingList = new EmptyReadingListWidget()); + comicsViewStack->addWidget(noSearchResultsWidget = new NoSearchResultsWidget()); + + comicsViewStack->addWidget(comicsView); + + comicsViewStack->setCurrentWidget(comicsView); + + sHorizontal->addWidget(sideBar); +#ifndef Q_OS_MAC + QVBoxLayout * rightLayout = new QVBoxLayout; + rightLayout->addWidget(libraryToolBar); + rightLayout->addWidget(comicsViewStack); + + rightLayout->setMargin(0); + rightLayout->setSpacing(0); + + QWidget * rightWidget = new QWidget(); + rightWidget->setLayout(rightLayout); + + sHorizontal->addWidget(rightWidget); +#else + sHorizontal->addWidget(comicsViewStack); +#endif + + sHorizontal->setStretchFactor(0,0); + sHorizontal->setStretchFactor(1,1); + mainWidget = new QStackedWidget(this); + mainWidget->addWidget(sHorizontal); + setCentralWidget(mainWidget); + //FINAL LAYOUT------------------------------------------------------------- + + + //OTHER---------------------------------------------------------------------- + //--------------------------------------------------------------------------- + noLibrariesWidget = new NoLibrariesWidget(); + mainWidget->addWidget(noLibrariesWidget); + + importWidget = new ImportWidget(); + mainWidget->addWidget(importWidget); + + connect(noLibrariesWidget,SIGNAL(createNewLibrary()),this,SLOT(createLibrary())); + connect(noLibrariesWidget,SIGNAL(addExistingLibrary()),this,SLOT(showAddLibrary())); + + + + //collapsible disabled in macosx (only temporaly) +#ifdef Q_OS_MAC + sHorizontal->setCollapsible(0,false); +#endif +} + +void LibraryWindow::doDialogs() +{ + createLibraryDialog = new CreateLibraryDialog(this); + renameLibraryDialog = new RenameLibraryDialog(this); + propertiesDialog = new PropertiesDialog(this); + comicVineDialog = new ComicVineDialog(this); + exportLibraryDialog = new ExportLibraryDialog(this); + importLibraryDialog = new ImportLibraryDialog(this); + exportComicsInfoDialog = new ExportComicsInfoDialog(this); + importComicsInfoDialog = new ImportComicsInfoDialog(this); + addLibraryDialog = new AddLibraryDialog(this); + optionsDialog = new OptionsDialog(this); + optionsDialog->restoreOptions(settings); + + editShortcutsDialog = new EditShortcutsDialog(this); + setUpShortcutsManagement(); + +#ifdef SERVER_RELEASE + serverConfigDialog = new ServerConfigDialog(this); +#endif + + had = new HelpAboutDialog(this); //TODO load data. + QString sufix = QLocale::system().name(); + if(QFile(":/files/about_"+sufix+".html").exists()) + had->loadAboutInformation(":/files/about_"+sufix+".html"); + else + had->loadAboutInformation(":/files/about.html"); + + if(QFile(":/files/helpYACReaderLibrary_"+sufix+".html").exists()) + had->loadHelp(":/files/helpYACReaderLibrary_"+sufix+".html"); + else + had->loadHelp(":/files/helpYACReaderLibrary.html"); + + +} + +void LibraryWindow::setUpShortcutsManagement() +{ + + QList allActions; + QList tmpList; + + editShortcutsDialog->addActionsGroup("Comics",QIcon(":/images/shortcuts_group_comics.png"), + tmpList = QList() + << openComicAction + << saveCoversToAction + << setAsReadAction + << setAsNonReadAction + << openContainingFolderComicAction + << resetComicRatingAction + << selectAllComicsAction + << editSelectedComicsAction + << asignOrderAction + << deleteComicsAction + << getInfoAction); + + allActions << tmpList; + + editShortcutsDialog->addActionsGroup("Folders",QIcon(":/images/shortcuts_group_folders.png"), + tmpList = QList() + << addFolderAction + << deleteFolderAction + << setRootIndexAction + << expandAllNodesAction + << colapseAllNodesAction + << openContainingFolderAction + << setFolderAsNotCompletedAction + << setFolderAsCompletedAction + << setFolderAsReadAction + << setFolderAsUnreadAction + << updateCurrentFolderAction); + allActions << tmpList; + + editShortcutsDialog->addActionsGroup("Lists",QIcon(":/images/shortcuts_group_folders.png"), //TODO change icon + tmpList = QList() + << addReadingListAction + << deleteReadingListAction + << addLabelAction + << renameListAction); + allActions << tmpList; + + editShortcutsDialog->addActionsGroup("General",QIcon(":/images/shortcuts_group_general.png"), + tmpList = QList() + << backAction + << forwardAction + << helpAboutAction + << optionsAction + << serverConfigAction + << showEditShortcutsAction); + + allActions << tmpList; + + editShortcutsDialog->addActionsGroup("Libraries",QIcon(":/images/shortcuts_group_libraries.png"), + tmpList = QList() + << createLibraryAction + << openLibraryAction + << exportComicsInfoAction + << importComicsInfoAction + << exportLibraryAction + << importLibraryAction + << updateLibraryAction + << renameLibraryAction + << removeLibraryAction); + + allActions << tmpList; + + editShortcutsDialog->addActionsGroup("Visualization",QIcon(":/images/shortcuts_group_visualization.png"), + tmpList = QList() + << showHideMarksAction + #ifndef Q_OS_MAC + << toggleFullScreenAction + #endif + << toggleComicsViewAction + << hideComicViewAction); + + allActions << tmpList; + + ShortcutsManager::getShortcutsManager().registerActions(allActions); +} + +void LibraryWindow::doModels() +{ + //folders + foldersModel = new FolderModel(); + foldersModelProxy = new FolderModelProxy(); + //foldersModelProxy->setSourceModel(foldersModel); + //comics + comicsModel = new ComicModel(); + //lists + listsModel = new ReadingListModel(); + listsModelProxy = new ReadingListModelProxy(); + + //setSearchFilter(YACReader::NoModifiers, ""); //clear search filter +} + +void LibraryWindow::disconnectComicsViewConnections(ComicsView * widget) +{ + disconnect(widget, SIGNAL(comicRated(int,QModelIndex)), comicsModel, SLOT(updateRating(int,QModelIndex))); + disconnect(showHideMarksAction,SIGNAL(toggled(bool)),widget,SLOT(setShowMarks(bool))); + disconnect(widget,SIGNAL(selected(unsigned int)),this,SLOT(openComic())); + disconnect(widget,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openComic())); + disconnect(selectAllComicsAction,SIGNAL(triggered()),widget,SLOT(selectAll())); + disconnect(comicsView, SIGNAL(copyComicsToCurrentFolder(QList >)), this, SLOT(copyAndImportComicsToCurrentFolder(QList >))); + disconnect(comicsView, SIGNAL(moveComicsToCurrentFolder(QList >)), this, SLOT(moveAndImportComicsToCurrentFolder(QList >))); + disconnect(comicsView,SIGNAL(customContextMenuViewRequested(QPoint)),this,SLOT(showComicsViewContextMenu(QPoint))); + disconnect(comicsView,SIGNAL(customContextMenuItemRequested(QPoint)),this,SLOT(showComicsItemContextMenu(QPoint))); +} + +void LibraryWindow::doComicsViewConnections() +{ + connect(comicsView, SIGNAL(comicRated(int,QModelIndex)), comicsModel, SLOT(updateRating(int,QModelIndex))); + connect(showHideMarksAction,SIGNAL(toggled(bool)),comicsView,SLOT(setShowMarks(bool))); + connect(comicsView,SIGNAL(selected(unsigned int)),this,SLOT(openComic())); + connect(comicsView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openComic())); + connect(selectAllComicsAction,SIGNAL(triggered()),comicsView,SLOT(selectAll())); + + connect(comicsView,SIGNAL(customContextMenuViewRequested(QPoint)),this,SLOT(showComicsViewContextMenu(QPoint))); + connect(comicsView,SIGNAL(customContextMenuItemRequested(QPoint)),this,SLOT(showComicsItemContextMenu(QPoint))); + //Drops + connect(comicsView, SIGNAL(copyComicsToCurrentFolder(QList >)), this, SLOT(copyAndImportComicsToCurrentFolder(QList >))); + connect(comicsView, SIGNAL(moveComicsToCurrentFolder(QList >)), this, SLOT(moveAndImportComicsToCurrentFolder(QList >))); +} + +void LibraryWindow::createActions() +{ + backAction = new QAction(this); + QIcon icoBackButton; + icoBackButton.addFile(":/images/main_toolbar/back.png",QSize(), QIcon::Normal); + //icoBackButton.addPixmap(QPixmap(":/images/main_toolbar/back_disabled.png"), QIcon::Disabled); + backAction->setData(BACK_ACTION_YL); + backAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(BACK_ACTION_YL)); + backAction->setIcon(icoBackButton); + backAction->setDisabled(true); + + forwardAction = new QAction(this); + QIcon icoFordwardButton; + icoFordwardButton.addFile(":/images/main_toolbar/forward.png", QSize(), QIcon::Normal); + //icoFordwardButton.addPixmap(QPixmap(":/images/main_toolbar/forward_disabled.png"), QIcon::Disabled); + forwardAction->setData(FORWARD_ACTION_YL); + forwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(FORWARD_ACTION_YL)); + forwardAction->setIcon(icoFordwardButton); + forwardAction->setDisabled(true); + + createLibraryAction = new QAction(this); + createLibraryAction->setToolTip(tr("Create a new library")); + createLibraryAction->setData(CREATE_LIBRARY_ACTION_YL); + createLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CREATE_LIBRARY_ACTION_YL)); + createLibraryAction->setIcon(QIcon(":/images/sidebar/newLibraryIcon.png")); + + openLibraryAction = new QAction(this); + openLibraryAction->setToolTip(tr("Open an existing library")); + openLibraryAction->setData(OPEN_LIBRARY_ACTION_YL); + openLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_LIBRARY_ACTION_YL)); + openLibraryAction->setIcon(QIcon(":/images/sidebar/openLibraryIcon.png")); + + exportComicsInfoAction = new QAction(tr("Export comics info"),this); + exportComicsInfoAction->setToolTip(tr("Export comics info")); + exportComicsInfoAction->setData(EXPORT_COMICS_INFO_ACTION_YL); + exportComicsInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(EXPORT_COMICS_INFO_ACTION_YL)); + exportComicsInfoAction->setIcon(QIcon(":/images/exportComicsInfoIcon.png")); + + importComicsInfoAction = new QAction(tr("Import comics info"),this); + importComicsInfoAction->setToolTip(tr("Import comics info")); + importComicsInfoAction->setData(IMPORT_COMICS_INFO_ACTION_YL); + importComicsInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(IMPORT_COMICS_INFO_ACTION_YL)); + importComicsInfoAction->setIcon(QIcon(":/images/importComicsInfoIcon.png")); + + exportLibraryAction = new QAction(tr("Pack covers"),this); + exportLibraryAction->setToolTip(tr("Pack the covers of the selected library")); + exportLibraryAction->setData(EXPORT_LIBRARY_ACTION_YL); + exportLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(EXPORT_LIBRARY_ACTION_YL)); + exportLibraryAction->setIcon(QIcon(":/images/exportLibraryIcon.png")); + + importLibraryAction = new QAction(tr("Unpack covers"),this); + importLibraryAction->setToolTip(tr("Unpack a catalog")); + importLibraryAction->setData(IMPORT_LIBRARY_ACTION_YL); + importLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(IMPORT_LIBRARY_ACTION_YL)); + importLibraryAction->setIcon(QIcon(":/images/importLibraryIcon.png")); + + updateLibraryAction = new QAction(tr("Update library"),this); + updateLibraryAction->setToolTip(tr("Update current library")); + updateLibraryAction->setData(UPDATE_LIBRARY_ACTION_YL); + updateLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(UPDATE_LIBRARY_ACTION_YL)); + updateLibraryAction->setIcon(QIcon(":/images/updateLibraryIcon.png")); + + renameLibraryAction = new QAction(tr("Rename library"),this); + renameLibraryAction->setToolTip(tr("Rename current library")); + renameLibraryAction->setData(RENAME_LIBRARY_ACTION_YL); + renameLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RENAME_LIBRARY_ACTION_YL)); + renameLibraryAction->setIcon(QIcon(":/images/editIcon.png")); + + removeLibraryAction = new QAction(tr("Remove library"),this); + removeLibraryAction->setToolTip(tr("Remove current library from your collection")); + removeLibraryAction->setData(REMOVE_LIBRARY_ACTION_YL); + removeLibraryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(REMOVE_LIBRARY_ACTION_YL)); + removeLibraryAction->setIcon(QIcon(":/images/removeLibraryIcon.png")); + + openComicAction = new QAction(tr("Open current comic"),this); + openComicAction->setToolTip(tr("Open current comic on YACReader")); + openComicAction->setData(OPEN_COMIC_ACTION_YL); + openComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_COMIC_ACTION_YL)); + openComicAction->setIcon(QIcon(":/images/openInYACReader.png")); + + saveCoversToAction = new QAction(tr("Save selected covers to..."),this); + saveCoversToAction->setToolTip(tr("Save covers of the selected comics as JPG files")); + saveCoversToAction->setData(SAVE_COVERS_TO_ACTION_YL); + saveCoversToAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SAVE_COVERS_TO_ACTION_YL)); + + setAsReadAction = new QAction(tr("Set as read"),this); + setAsReadAction->setToolTip(tr("Set comic as read")); + setAsReadAction->setData(SET_AS_READ_ACTION_YL); + setAsReadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_AS_READ_ACTION_YL)); + setAsReadAction->setIcon(QIcon(":/images/setReadButton.png")); + + setAsNonReadAction = new QAction(tr("Set as unread"),this); + setAsNonReadAction->setToolTip(tr("Set comic as unread")); + setAsNonReadAction->setData(SET_AS_NON_READ_ACTION_YL); + setAsNonReadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_AS_NON_READ_ACTION_YL)); + setAsNonReadAction->setIcon(QIcon(":/images/setUnread.png")); + + /*setAllAsReadAction = new QAction(tr("Set all as read"),this); + setAllAsReadAction->setToolTip(tr("Set all comics as read")); + setAllAsReadAction->setIcon(QIcon(":/images/setAllRead.png")); + + setAllAsNonReadAction = new QAction(tr("Set all as unread"),this); + setAllAsNonReadAction->setToolTip(tr("Set all comics as unread")); + setAllAsNonReadAction->setIcon(QIcon(":/images/setAllUnread.png"));*/ + + showHideMarksAction = new QAction(tr("Show/Hide marks"),this); + showHideMarksAction->setToolTip(tr("Show or hide read marks")); + showHideMarksAction->setData(SHOW_HIDE_MARKS_ACTION_YL); + showHideMarksAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_HIDE_MARKS_ACTION_YL)); + showHideMarksAction->setCheckable(true); + showHideMarksAction->setIcon(QIcon(":/images/showMarks.png")); + showHideMarksAction->setChecked(true); +#ifndef Q_OS_MAC + toggleFullScreenAction = new QAction(tr("Fullscreen mode on/off"),this); + toggleFullScreenAction->setToolTip(tr("Fullscreen mode on/off")); + toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_YL); + toggleFullScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_YL)); + QIcon icoFullscreenButton; + icoFullscreenButton.addPixmap(QPixmap(":/images/main_toolbar/fullscreen.png"), QIcon::Normal); + toggleFullScreenAction->setIcon(icoFullscreenButton); +#endif + helpAboutAction = new QAction(this); + helpAboutAction->setToolTip(tr("Help, About YACReader")); + helpAboutAction->setData(HELP_ABOUT_ACTION_YL); + helpAboutAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(HELP_ABOUT_ACTION_YL)); + QIcon icoHelpButton; + icoHelpButton.addFile(":/images/main_toolbar/help.png",QSize(), QIcon::Normal); + helpAboutAction->setIcon(icoHelpButton); + + addFolderAction = new QAction(tr("Add new folder"), this); + addFolderAction->setData(ADD_FOLDER_ACTION_YL); + addFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADD_FOLDER_ACTION_YL)); + addFolderAction->setToolTip(tr("Add new folder to the current library")); + addFolderAction->setIcon(QIcon(":/images/sidebar/addNew_sidebar.png")); + + deleteFolderAction = new QAction(tr("Delete folder"), this); + deleteFolderAction->setData(REMOVE_FOLDER_ACTION_YL); + deleteFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(REMOVE_FOLDER_ACTION_YL)); + deleteFolderAction->setToolTip(tr("Delete current folder from disk")); + deleteFolderAction->setIcon(QIcon(":/images/sidebar/delete_sidebar.png")); + + setRootIndexAction = new QAction(this); + setRootIndexAction->setData(SET_ROOT_INDEX_ACTION_YL); + setRootIndexAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_ROOT_INDEX_ACTION_YL)); + setRootIndexAction->setToolTip(tr("Select root node")); + setRootIndexAction->setIcon(QIcon(":/images/sidebar/setRoot.png")); + + expandAllNodesAction = new QAction(this); + expandAllNodesAction->setToolTip(tr("Expand all nodes")); + expandAllNodesAction->setData(EXPAND_ALL_NODES_ACTION_YL); + expandAllNodesAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(EXPAND_ALL_NODES_ACTION_YL)); + expandAllNodesAction->setIcon(QIcon(":/images/sidebar/expand.png")); + + colapseAllNodesAction = new QAction(this); + colapseAllNodesAction->setToolTip(tr("Colapse all nodes")); + colapseAllNodesAction->setData(COLAPSE_ALL_NODES_ACTION_YL); + colapseAllNodesAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(COLAPSE_ALL_NODES_ACTION_YL)); + colapseAllNodesAction->setIcon(QIcon(":/images/sidebar/colapse.png")); + + optionsAction = new QAction(this); + optionsAction->setToolTip(tr("Show options dialog")); + optionsAction->setData(OPTIONS_ACTION_YL); + optionsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPTIONS_ACTION_YL)); + QIcon icoSettingsButton; + icoSettingsButton.addFile(":/images/main_toolbar/settings.png", QSize(), QIcon::Normal); + optionsAction->setIcon(icoSettingsButton); + + serverConfigAction = new QAction(this); + serverConfigAction->setToolTip(tr("Show comics server options dialog")); + serverConfigAction->setData(SERVER_CONFIG_ACTION_YL); + serverConfigAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SERVER_CONFIG_ACTION_YL)); + QIcon icoServerButton; + icoServerButton.addFile(":/images/main_toolbar/server.png", QSize(), QIcon::Normal); + serverConfigAction->setIcon(icoServerButton); + + toggleComicsViewAction = new QAction(tr("Change between comics views"),this); + toggleComicsViewAction->setToolTip(tr("Change between comics views")); + QIcon icoViewsButton; + if(!settings->contains(COMICS_VIEW_STATUS) || settings->value(COMICS_VIEW_STATUS) == Flow) + icoViewsButton.addFile(":/images/main_toolbar/grid.png", QSize(), QIcon::Normal); + else + icoViewsButton.addFile(":/images/main_toolbar/flow.png", QSize(), QIcon::Normal); + toggleComicsViewAction->setData(TOGGLE_COMICS_VIEW_ACTION_YL); + toggleComicsViewAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_COMICS_VIEW_ACTION_YL)); + toggleComicsViewAction->setIcon(icoViewsButton); + //socialAction = new QAction(this); + + openContainingFolderAction = new QAction(this); + openContainingFolderAction->setText(tr("Open folder...")); + openContainingFolderAction->setData(OPEN_CONTAINING_FOLDER_ACTION_YL); + openContainingFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_CONTAINING_FOLDER_ACTION_YL)); + openContainingFolderAction->setIcon(QIcon(":/images/open.png")); + + setFolderAsNotCompletedAction = new QAction(this); + setFolderAsNotCompletedAction->setText(tr("Set as uncompleted")); + setFolderAsNotCompletedAction->setData(SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL); + setFolderAsNotCompletedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL)); + + setFolderAsCompletedAction = new QAction(this); + setFolderAsCompletedAction->setText(tr("Set as completed")); + setFolderAsCompletedAction->setData(SET_FOLDER_AS_COMPLETED_ACTION_YL); + setFolderAsCompletedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_COMPLETED_ACTION_YL)); + + setFolderAsReadAction = new QAction(this); + setFolderAsReadAction->setText(tr("Set as read")); + setFolderAsReadAction->setData(SET_FOLDER_AS_READ_ACTION_YL); + setFolderAsReadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_READ_ACTION_YL)); + + setFolderAsUnreadAction = new QAction(this); + setFolderAsUnreadAction->setText(tr("Set as unread")); + setFolderAsUnreadAction->setData(SET_FOLDER_AS_UNREAD_ACTION_YL); + setFolderAsUnreadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_UNREAD_ACTION_YL)); + + openContainingFolderComicAction = new QAction(this); + openContainingFolderComicAction->setText(tr("Open containing folder...")); + openContainingFolderComicAction->setData(OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL); + openContainingFolderComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL)); + openContainingFolderComicAction->setIcon(QIcon(":/images/open.png")); + + resetComicRatingAction = new QAction(this); + resetComicRatingAction->setText(tr("Reset comic rating")); + resetComicRatingAction->setData(RESET_COMIC_RATING_ACTION_YL); + resetComicRatingAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RESET_COMIC_RATING_ACTION_YL)); + + //Edit comics actions------------------------------------------------------ + selectAllComicsAction = new QAction(this); + selectAllComicsAction->setText(tr("Select all comics")); + selectAllComicsAction->setData(SELECT_ALL_COMICS_ACTION_YL); + selectAllComicsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SELECT_ALL_COMICS_ACTION_YL)); + selectAllComicsAction->setIcon(QIcon(":/images/selectAll.png")); + + editSelectedComicsAction = new QAction(this); + editSelectedComicsAction->setText(tr("Edit")); + editSelectedComicsAction->setData(EDIT_SELECTED_COMICS_ACTION_YL); + editSelectedComicsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(EDIT_SELECTED_COMICS_ACTION_YL)); + editSelectedComicsAction->setIcon(QIcon(":/images/editComic.png")); + + asignOrderAction = new QAction(this); + asignOrderAction->setText(tr("Asign current order to comics")); + asignOrderAction->setData(ASIGN_ORDER_ACTION_YL); + asignOrderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ASIGN_ORDER_ACTION_YL)); + asignOrderAction->setIcon(QIcon(":/images/asignNumber.png")); + + forceCoverExtractedAction = new QAction(this); + forceCoverExtractedAction->setText(tr("Update cover")); + forceCoverExtractedAction->setData(FORCE_COVER_EXTRACTED_ACTION_YL); + forceCoverExtractedAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(FORCE_COVER_EXTRACTED_ACTION_YL)); + forceCoverExtractedAction->setIcon(QIcon(":/images/importCover.png")); + + deleteComicsAction = new QAction(this); + deleteComicsAction->setText(tr("Delete selected comics")); + deleteComicsAction->setData(DELETE_COMICS_ACTION_YL); + deleteComicsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(DELETE_COMICS_ACTION_YL)); + deleteComicsAction->setIcon(QIcon(":/images/trash.png")); + + hideComicViewAction = new QAction(this); + hideComicViewAction->setText(tr("Hide comic flow")); + hideComicViewAction->setData(HIDE_COMIC_VIEW_ACTION_YL); + hideComicViewAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(HIDE_COMIC_VIEW_ACTION_YL)); + hideComicViewAction->setIcon(QIcon(":/images/hideComicFlow.png")); + hideComicViewAction->setCheckable(true); + hideComicViewAction->setChecked(false); + + getInfoAction = new QAction(this); + getInfoAction->setData(GET_INFO_ACTION_YL); + getInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GET_INFO_ACTION_YL)); + getInfoAction->setText(tr("Download tags from Comic Vine")); + getInfoAction->setIcon(QIcon(":/images/getInfo.png")); + //------------------------------------------------------------------------- + + showEditShortcutsAction = new QAction(tr("Edit shortcuts"),this); + showEditShortcutsAction->setData(SHOW_EDIT_SHORTCUTS_ACTION_YL); + showEditShortcutsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_EDIT_SHORTCUTS_ACTION_YL)); + showEditShortcutsAction->setShortcutContext(Qt::ApplicationShortcut); + addAction(showEditShortcutsAction); + + updateFolderAction = new QAction(tr("Update folder"), this); + updateFolderAction->setIcon(QIcon(":/images/updateLibraryIcon.png")); + + updateCurrentFolderAction = new QAction(tr("Update current folder"), this); + updateCurrentFolderAction->setData(UPDATE_CURRENT_FOLDER_ACTION_YL); + updateCurrentFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(UPDATE_CURRENT_FOLDER_ACTION_YL)); + updateCurrentFolderAction->setIcon(QIcon(":/images/updateLibraryIcon.png")); + + addReadingListAction = new QAction(tr("Add new reading list"), this); + addReadingListAction->setData(ADD_READING_LIST_ACTION_YL); + addReadingListAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADD_READING_LIST_ACTION_YL)); + addReadingListAction->setToolTip(tr("Add a new reading list to the current library")); + addReadingListAction->setIcon(QIcon(":/images/sidebar/addNew_sidebar.png")); + + deleteReadingListAction = new QAction(tr("Remove reading list"), this); + deleteReadingListAction->setData(REMOVE_READING_LIST_ACTION_YL); + deleteReadingListAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(REMOVE_READING_LIST_ACTION_YL)); + deleteReadingListAction->setToolTip(tr("Remove current reading list from the library")); + deleteReadingListAction->setIcon(QIcon(":/images/sidebar/delete_sidebar.png")); + + addLabelAction = new QAction(tr("Add new label"), this); + addLabelAction->setData(ADD_LABEL_ACTION_YL); + addLabelAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADD_LABEL_ACTION_YL)); + addLabelAction->setToolTip(tr("Add a new label to this library")); + addLabelAction->setIcon(QIcon(":/images/sidebar/addLabelIcon.png")); + + renameListAction = new QAction(tr("Rename selected list"), this); + renameListAction->setData(RENAME_LIST_ACTION_YL); + renameListAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RENAME_LIST_ACTION_YL)); + renameListAction->setToolTip(tr("Rename any selected labels or lists")); + renameListAction->setIcon(QIcon(":/images/sidebar/renameListIcon.png")); + + //-- + addToMenuAction = new QAction(tr("Add to..."), this); + + addToFavoritesAction = new QAction(tr("Favorites"), this); + addToFavoritesAction->setData(ADD_TO_FAVORITES_ACTION_YL); + addToFavoritesAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADD_TO_FAVORITES_ACTION_YL)); + addToFavoritesAction->setToolTip(tr("Add selected comics to favorites list")); + addToFavoritesAction->setIcon(QIcon(":/images/lists/default_1.png")); + + //actions not asigned to any widget + this->addAction(saveCoversToAction); + this->addAction(openContainingFolderAction); + this->addAction(updateCurrentFolderAction); + this->addAction(resetComicRatingAction); + this->addAction(setFolderAsCompletedAction); + this->addAction(setFolderAsNotCompletedAction); + this->addAction(setFolderAsReadAction); + this->addAction(setFolderAsUnreadAction); +#ifndef Q_OS_MAC + this->addAction(toggleFullScreenAction); +#endif + + //disable actions + disableAllActions(); +} +void LibraryWindow::disableComicsActions(bool disabled) +{ + //if there aren't comics, no fullscreen option will be available +#ifndef Q_OS_MAC + toggleFullScreenAction->setDisabled(disabled); +#endif + //edit toolbar + openComicAction->setDisabled(disabled); + editSelectedComicsAction->setDisabled(disabled); + selectAllComicsAction->setDisabled(disabled); + asignOrderAction->setDisabled(disabled); + setAsReadAction->setDisabled(disabled); + setAsNonReadAction->setDisabled(disabled); + //setAllAsReadAction->setDisabled(disabled); + //setAllAsNonReadAction->setDisabled(disabled); + showHideMarksAction->setDisabled(disabled); + deleteComicsAction->setDisabled(disabled); + //context menu + openContainingFolderComicAction->setDisabled(disabled); + resetComicRatingAction->setDisabled(disabled); + + getInfoAction->setDisabled(disabled); + + updateCurrentFolderAction->setDisabled(disabled); + + +} +void LibraryWindow::disableLibrariesActions(bool disabled) +{ + updateLibraryAction->setDisabled(disabled); + renameLibraryAction->setDisabled(disabled); + removeLibraryAction->setDisabled(disabled); + exportComicsInfoAction->setDisabled(disabled); + importComicsInfoAction->setDisabled(disabled); + exportLibraryAction->setDisabled(disabled); + //importLibraryAction->setDisabled(disabled); +} + +void LibraryWindow::disableNoUpdatedLibrariesActions(bool disabled) +{ + updateLibraryAction->setDisabled(disabled); + exportComicsInfoAction->setDisabled(disabled); + importComicsInfoAction->setDisabled(disabled); + exportLibraryAction->setDisabled(disabled); +} + +void LibraryWindow::disableFoldersActions(bool disabled) +{ + setRootIndexAction->setDisabled(disabled); + expandAllNodesAction->setDisabled(disabled); + colapseAllNodesAction->setDisabled(disabled); + + openContainingFolderAction->setDisabled(disabled); + + updateFolderAction->setDisabled(disabled); +} + +void LibraryWindow::disableAllActions() +{ + disableComicsActions(true); + disableLibrariesActions(true); + disableFoldersActions(true); +} + +void LibraryWindow::createToolBars() +{ + +#ifdef Q_OS_MAC + //libraryToolBar->setIconSize(QSize(16,16)); //TODO make icon size dynamic + + libraryToolBar->addAction(backAction); + libraryToolBar->addAction(forwardAction); + + libraryToolBar->addSpace(10); + +#ifdef SERVER_RELEASE + libraryToolBar->addAction(serverConfigAction); +#endif + libraryToolBar->addAction(optionsAction); + libraryToolBar->addAction(helpAboutAction); + + libraryToolBar->addSpace(10); + + libraryToolBar->addAction(toggleComicsViewAction); +#ifndef Q_OS_MAC + libraryToolBar->addAction(toggleFullScreenAction); +#endif + + libraryToolBar->addStretch(); + + //Native toolbar search edit + //libraryToolBar->addWidget(searchEdit); + searchEdit = libraryToolBar->addSearchEdit(); + //connect(libraryToolBar,SIGNAL(searchTextChanged(YACReader::SearchModifiers,QString)),this,SLOT(setSearchFilter(YACReader::SearchModifiers, QString))); + + //libraryToolBar->setMovable(false); + + libraryToolBar->attachToWindow(this->windowHandle()); + + +#else + libraryToolBar->backButton->setDefaultAction(backAction); + libraryToolBar->forwardButton->setDefaultAction(forwardAction); + libraryToolBar->settingsButton->setDefaultAction(optionsAction); + libraryToolBar->serverButton->setDefaultAction(serverConfigAction); + libraryToolBar->helpButton->setDefaultAction(helpAboutAction); + libraryToolBar->toggleComicsViewButton->setDefaultAction(toggleComicsViewAction); + libraryToolBar->fullscreenButton->setDefaultAction(toggleFullScreenAction); + libraryToolBar->setSearchWidget(searchEdit); +#endif + + editInfoToolBar->setIconSize(QSize(18,18)); + editInfoToolBar->addAction(openComicAction); + editInfoToolBar->addSeparator(); + editInfoToolBar->addAction(editSelectedComicsAction); + editInfoToolBar->addAction(getInfoAction); + editInfoToolBar->addAction(asignOrderAction); + + editInfoToolBar->addSeparator(); + + editInfoToolBar->addAction(selectAllComicsAction); + + editInfoToolBar->addSeparator(); + + editInfoToolBar->addAction(setAsReadAction); + //editInfoToolBar->addAction(setAllAsReadAction); + editInfoToolBar->addAction(setAsNonReadAction); + //editInfoToolBar->addAction(setAllAsNonReadAction); + + editInfoToolBar->addAction(showHideMarksAction); + + editInfoToolBar->addSeparator(); + + editInfoToolBar->addAction(deleteComicsAction); + + /*editInfoToolBar->addWidget(new QToolBarStretch()); + editInfoToolBar->addAction(hideComicViewAction);*/ +} + +void LibraryWindow::createMenus() +{ + foldersView->addAction(addFolderAction); + foldersView->addAction(deleteFolderAction); + YACReader::addSperator(foldersView); + + foldersView->addAction(openContainingFolderAction); + foldersView->addAction(updateFolderAction); + YACReader::addSperator(foldersView); + + foldersView->addAction(setFolderAsNotCompletedAction); + foldersView->addAction(setFolderAsCompletedAction); + YACReader::addSperator(foldersView); + + foldersView->addAction(setFolderAsReadAction); + foldersView->addAction(setFolderAsUnreadAction); + + selectedLibrary->addAction(updateLibraryAction); + selectedLibrary->addAction(renameLibraryAction); + selectedLibrary->addAction(removeLibraryAction); + YACReader::addSperator(selectedLibrary); + + selectedLibrary->addAction(exportComicsInfoAction); + selectedLibrary->addAction(importComicsInfoAction); + YACReader::addSperator(selectedLibrary); + + selectedLibrary->addAction(exportLibraryAction); + selectedLibrary->addAction(importLibraryAction); + + + + +//MacOSX app menus +#ifdef Q_OS_MACX + QMenuBar * menu = this->menuBar(); + //about / preferences + //TODO + + //library + QMenu * libraryMenu = new QMenu(tr("Library")); + + libraryMenu->addAction(updateLibraryAction); + libraryMenu->addAction(renameLibraryAction); + libraryMenu->addAction(removeLibraryAction); + libraryMenu->addSeparator(); + + libraryMenu->addAction(exportComicsInfoAction); + libraryMenu->addAction(importComicsInfoAction); + + libraryMenu->addSeparator(); + + libraryMenu->addAction(exportLibraryAction); + libraryMenu->addAction(importLibraryAction); + + //folder + QMenu * folderMenu = new QMenu(tr("Folder")); + folderMenu->addAction(openContainingFolderAction); + folderMenu->addAction(updateFolderAction); + folderMenu->addSeparator(); + folderMenu->addAction(setFolderAsNotCompletedAction); + folderMenu->addAction(setFolderAsCompletedAction); + folderMenu->addSeparator(); + folderMenu->addAction(setFolderAsReadAction); + folderMenu->addAction(setFolderAsUnreadAction); + + //comic + QMenu * comicMenu = new QMenu(tr("Comic")); + comicMenu->addAction(openContainingFolderComicAction); + comicMenu->addSeparator(); + comicMenu->addAction(resetComicRatingAction); + + menu->addMenu(libraryMenu); + menu->addMenu(folderMenu); + menu->addMenu(comicMenu); +#endif +} + +void LibraryWindow::createConnections() +{ + //history navigation + connect(backAction,SIGNAL(triggered()),historyController,SLOT(backward())); + connect(forwardAction,SIGNAL(triggered()),historyController,SLOT(forward())); + //-- + connect(historyController,SIGNAL(enabledBackward(bool)),backAction,SLOT(setEnabled(bool))); + connect(historyController,SIGNAL(enabledForward(bool)),forwardAction,SLOT(setEnabled(bool))); + //connect(foldersView, SIGNAL(clicked(QModelIndex)), historyController, SLOT(updateHistory(QModelIndex))); + + //libraryCreator connections + connect(createLibraryDialog,SIGNAL(createLibrary(QString,QString,QString)),this,SLOT(create(QString,QString,QString))); + connect(createLibraryDialog,SIGNAL(libraryExists(QString)),this,SLOT(libraryAlreadyExists(QString))); + connect(importComicsInfoDialog,SIGNAL(finished(int)),this,SLOT(reloadCurrentLibrary())); + + //connect(libraryCreator,SIGNAL(coverExtracted(QString)),createLibraryDialog,SLOT(showCurrentFile(QString))); + //connect(libraryCreator,SIGNAL(coverExtracted(QString)),updateLibraryDialog,SLOT(showCurrentFile(QString))); + connect(libraryCreator,SIGNAL(finished()),this,SLOT(showRootWidget())); + connect(libraryCreator,SIGNAL(updated()),this,SLOT(reloadCurrentLibrary())); + connect(libraryCreator,SIGNAL(created()),this,SLOT(openLastCreated())); + //connect(libraryCreator,SIGNAL(updatedCurrentFolder()), this, SLOT(showRootWidget())); + connect(libraryCreator,SIGNAL(updatedCurrentFolder(QModelIndex)), this, SLOT(reloadAfterCopyMove(QModelIndex))); + connect(libraryCreator,SIGNAL(comicAdded(QString,QString)),importWidget,SLOT(newComic(QString,QString))); + //libraryCreator errors + connect(libraryCreator,SIGNAL(failedCreatingDB(QString)),this,SLOT(manageCreatingError(QString))); + connect(libraryCreator,SIGNAL(failedUpdatingDB(QString)),this,SLOT(manageUpdatingError(QString))); //TODO: implement failedUpdatingDB + + //new import widget + connect(importWidget,SIGNAL(stop()),this,SLOT(stopLibraryCreator())); + + //packageManager connections + connect(exportLibraryDialog,SIGNAL(exportPath(QString)),this,SLOT(exportLibrary(QString))); + connect(exportLibraryDialog,SIGNAL(rejected()),packageManager,SLOT(cancel())); + connect(packageManager,SIGNAL(exported()),exportLibraryDialog,SLOT(close())); + connect(importLibraryDialog,SIGNAL(unpackCLC(QString,QString,QString)),this,SLOT(importLibrary(QString,QString,QString))); + connect(importLibraryDialog,SIGNAL(rejected()),packageManager,SLOT(cancel())); + connect(importLibraryDialog,SIGNAL(rejected()),this,SLOT(deleteCurrentLibrary())); + connect(importLibraryDialog,SIGNAL(libraryExists(QString)),this,SLOT(libraryAlreadyExists(QString))); + connect(packageManager,SIGNAL(imported()),importLibraryDialog,SLOT(hide())); + connect(packageManager,SIGNAL(imported()),this,SLOT(openLastCreated())); + + + //create and update dialogs + connect(createLibraryDialog,SIGNAL(cancelCreate()),this,SLOT(cancelCreating())); + + //open existing library from dialog. + connect(addLibraryDialog,SIGNAL(addLibrary(QString,QString)),this,SLOT(openLibrary(QString,QString))); + + //load library when selected library changes + connect(selectedLibrary,SIGNAL(currentIndexChanged(QString)),this,SLOT(loadLibrary(QString))); + + //rename library dialog + connect(renameLibraryDialog,SIGNAL(renameLibrary(QString)),this,SLOT(rename(QString))); + + //navigations between view modes (tree,list and flow) + //TODO connect(foldersView, SIGNAL(pressed(QModelIndex)), this, SLOT(updateFoldersViewConextMenu(QModelIndex))); + //connect(foldersView, SIGNAL(clicked(QModelIndex)), this, SLOT(loadCovers(QModelIndex))); + + //drops in folders view + connect(foldersView, SIGNAL(copyComicsToFolder(QList >,QModelIndex)), this, SLOT(copyAndImportComicsToFolder(QList >,QModelIndex))); + connect(foldersView, SIGNAL(moveComicsToFolder(QList >,QModelIndex)), this, SLOT(moveAndImportComicsToFolder(QList >,QModelIndex))); + connect(foldersView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showFoldersContextMenu(QPoint))); + + //actions + connect(createLibraryAction,SIGNAL(triggered()),this,SLOT(createLibrary())); + connect(exportLibraryAction,SIGNAL(triggered()),exportLibraryDialog,SLOT(open())); + connect(importLibraryAction,SIGNAL(triggered()),this,SLOT(importLibraryPackage())); + + connect(openLibraryAction,SIGNAL(triggered()),this,SLOT(showAddLibrary())); + connect(setAsReadAction,SIGNAL(triggered()),this,SLOT(setCurrentComicReaded())); + connect(setAsNonReadAction,SIGNAL(triggered()),this,SLOT(setCurrentComicUnreaded())); + //connect(setAllAsReadAction,SIGNAL(triggered()),this,SLOT(setComicsReaded())); + //connect(setAllAsNonReadAction,SIGNAL(triggered()),this,SLOT(setComicsUnreaded())); + + + //comicsInfoManagement + connect(exportComicsInfoAction,SIGNAL(triggered()),this,SLOT(showExportComicsInfo())); + connect(importComicsInfoAction,SIGNAL(triggered()),this,SLOT(showImportComicsInfo())); + + //properties & config + connect(propertiesDialog,SIGNAL(accepted()),navigationController,SLOT(reselectCurrentSource())); + + //comic vine + connect(comicVineDialog,SIGNAL(accepted()),navigationController,SLOT(reselectCurrentSource())); + + connect(updateLibraryAction,SIGNAL(triggered()),this,SLOT(updateLibrary())); + connect(renameLibraryAction,SIGNAL(triggered()),this,SLOT(renameLibrary())); + //connect(deleteLibraryAction,SIGNAL(triggered()),this,SLOT(deleteLibrary())); + connect(removeLibraryAction,SIGNAL(triggered()),this,SLOT(removeLibrary())); + connect(openComicAction,SIGNAL(triggered()),this,SLOT(openComic())); + connect(helpAboutAction,SIGNAL(triggered()),had,SLOT(show())); + connect(addFolderAction,SIGNAL(triggered()),this,SLOT(addFolderToCurrentIndex())); + connect(deleteFolderAction,SIGNAL(triggered()),this,SLOT(deleteSelectedFolder())); + connect(setRootIndexAction,SIGNAL(triggered()),this,SLOT(setRootIndex())); + connect(expandAllNodesAction,SIGNAL(triggered()),foldersView,SLOT(expandAll())); + connect(colapseAllNodesAction,SIGNAL(triggered()),foldersView,SLOT(collapseAll())); +#ifndef Q_OS_MAC + connect(toggleFullScreenAction,SIGNAL(triggered()),this,SLOT(toggleFullScreen())); +#endif + connect(toggleComicsViewAction,SIGNAL(triggered()),this,SLOT(toggleComicsView())); + connect(optionsAction, SIGNAL(triggered()),optionsDialog,SLOT(show())); +#ifdef SERVER_RELEASE + connect(serverConfigAction, SIGNAL(triggered()), serverConfigDialog, SLOT(show())); +#endif + connect(optionsDialog, SIGNAL(optionsChanged()),this,SLOT(reloadOptions())); + connect(optionsDialog, SIGNAL(editShortcuts()),editShortcutsDialog,SLOT(show())); + + //Folders filter + //connect(clearFoldersFilter,SIGNAL(clicked()),foldersFilter,SLOT(clear())); + connect(searchEdit,SIGNAL(filterChanged(YACReader::SearchModifiers, QString)),this,SLOT(setSearchFilter(YACReader::SearchModifiers, QString))); + //connect(includeComicsCheckBox,SIGNAL(stateChanged(int)),this,SLOT(searchInFiles(int))); + + //ContextMenus + connect(openContainingFolderComicAction,SIGNAL(triggered()),this,SLOT(openContainingFolderComic())); + connect(setFolderAsNotCompletedAction,SIGNAL(triggered()),this,SLOT(setFolderAsNotCompleted())); + connect(setFolderAsCompletedAction,SIGNAL(triggered()),this,SLOT(setFolderAsCompleted())); + connect(setFolderAsReadAction,SIGNAL(triggered()),this,SLOT(setFolderAsRead())); + connect(setFolderAsUnreadAction,SIGNAL(triggered()),this,SLOT(setFolderAsUnread())); + connect(openContainingFolderAction,SIGNAL(triggered()),this,SLOT(openContainingFolder())); + connect(resetComicRatingAction,SIGNAL(triggered()),this,SLOT(resetComicRating())); + + //connect(dm,SIGNAL(directoryLoaded(QString)),foldersView,SLOT(expandAll())); + //connect(dm,SIGNAL(directoryLoaded(QString)),this,SLOT(updateFoldersView(QString))); + //Comicts edition + connect(editSelectedComicsAction,SIGNAL(triggered()),this,SLOT(showProperties())); + connect(asignOrderAction,SIGNAL(triggered()),this,SLOT(asignNumbers())); + + connect(deleteComicsAction,SIGNAL(triggered()),this,SLOT(deleteComics())); + + connect(hideComicViewAction, SIGNAL(toggled(bool)),this, SLOT(hideComicFlow(bool))); + + connect(getInfoAction,SIGNAL(triggered()),this,SLOT(showComicVineScraper())); + + //connect(socialAction,SIGNAL(triggered()),this,SLOT(showSocial())); + + connect(comicsViewTransition,SIGNAL(transitionFinished()),this,SLOT(showComicsView())); + + //connect(comicsModel,SIGNAL(isEmpty()),this,SLOT(showEmptyFolderView())); + //connect(comicsModel,SIGNAL(searchNumResults(int)),this,SLOT(checkSearchNumResults(int))); + //connect(emptyFolderWidget,SIGNAL(subfolderSelected(QModelIndex,int)),this,SLOT(selectSubfolder(QModelIndex,int))); + //Drops + connect(emptyFolderWidget, SIGNAL(copyComicsToCurrentFolder(QList >)), this, SLOT(copyAndImportComicsToCurrentFolder(QList >))); + connect(emptyFolderWidget, SIGNAL(moveComicsToCurrentFolder(QList >)), this, SLOT(moveAndImportComicsToCurrentFolder(QList >))); + + connect(showEditShortcutsAction,SIGNAL(triggered()),editShortcutsDialog,SLOT(show())); + + //update folders (partial updates) + connect(updateCurrentFolderAction,SIGNAL(triggered()), this, SLOT(updateCurrentFolder())); + connect(updateFolderAction,SIGNAL(triggered()), this, SLOT(updateCurrentFolder())); + + //lists + connect(addReadingListAction,SIGNAL(triggered()),this,SLOT(addNewReadingList())); + connect(deleteReadingListAction,SIGNAL(triggered()),this,SLOT(deleteSelectedReadingList())); + connect(addLabelAction,SIGNAL(triggered()),this,SLOT(showAddNewLabelDialog())); + connect(renameListAction,SIGNAL(triggered()),this,SLOT(showRenameCurrentList())); + + connect(listsModel,SIGNAL(addComicsToFavorites(QList)),comicsModel,SLOT(addComicsToFavorites(QList))); + connect(listsModel,SIGNAL(addComicsToLabel(QList,qulonglong)),comicsModel,SLOT(addComicsToLabel(QList,qulonglong))); + connect(listsModel,SIGNAL(addComicsToReadingList(QList,qulonglong)),comicsModel,SLOT(addComicsToReadingList(QList,qulonglong))); + //-- + + connect(addToFavoritesAction,SIGNAL(triggered()),this,SLOT(addSelectedComicsToFavorites())); + + //save covers + connect(saveCoversToAction,SIGNAL(triggered()),this,SLOT(saveSelectedCoversTo())); +} + +void LibraryWindow::loadLibrary(const QString & name) +{ + if(!libraries.isEmpty()) //si hay bibliotecas... + { + historyController->clear(); + + showRootWidget(); + QString path=libraries.getPath(name)+"/.yacreaderlibrary"; + QDir d; //TODO change this by static methods (utils class?? with delTree for example) + QString dbVersion; + if(d.exists(path) && d.exists(path+"/library.ydb") && (dbVersion = DataBaseManagement::checkValidDB(path+"/library.ydb")) != "") //si existe en disco la biblioteca seleccionada, y es válida.. + { + int comparation = DataBaseManagement::compareVersions(dbVersion,VERSION); + bool updated = false; + if(comparation < 0) + { + int ret = QMessageBox::question(this,tr("Update needed"),tr("This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now?"),QMessageBox::Yes,QMessageBox::No); + if(ret == QMessageBox::Yes) + { + updated = DataBaseManagement::updateToCurrentVersion(path+"/library.ydb"); + if(!updated) + QMessageBox::critical(this,tr("Update failed"), tr("The current library can't be udpated. Check for write write permissions on: ") + path+"/library.ydb"); + } + else + { + comicsView->setModel(NULL); + foldersView->setModel(NULL); + listsView->setModel(NULL); + disableAllActions();//TODO comprobar que se deben deshabilitar + //será possible renombrar y borrar estas bibliotecas + renameLibraryAction->setEnabled(true); + removeLibraryAction->setEnabled(true); + } + } + + if(comparation == 0 || updated) //en caso de que la versión se igual que la actual + { + foldersModel->setupModelData(path); + foldersModelProxy->setSourceModel(foldersModel); + foldersView->setModel(foldersModelProxy); + foldersView->setCurrentIndex(QModelIndex()); //why is this necesary?? by default it seems that returns an arbitrary index. + + listsModel->setupReadingListsData(path); + listsModelProxy->setSourceModel(listsModel); + listsView->setModel(listsModelProxy); + + if(foldersModel->rowCount(QModelIndex())>0) + disableFoldersActions(false); + else + disableFoldersActions(true); + + d.setCurrent(libraries.getPath(name)); + d.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot); + if(d.count()<=1) //librería de sólo lectura + { + //QMessageBox::critical(NULL,QString::number(d.count()),QString::number(d.count())); + disableLibrariesActions(false); + updateLibraryAction->setDisabled(true); + openContainingFolderAction->setDisabled(true); + disableComicsActions(true); +#ifndef Q_OS_MAC + toggleFullScreenAction->setEnabled(true); +#endif + + importedCovers = true; + } + else //librería normal abierta + { + disableLibrariesActions(false); + importedCovers = false; + } + + setRootIndex(); + + searchEdit->clear(); + } + else if(comparation > 0) + { + int ret = QMessageBox::question(this,tr("Download new version"),tr("This library was created with a newer version of YACReaderLibrary. Download the new version now?"),QMessageBox::Yes,QMessageBox::No); + if(ret == QMessageBox::Yes) + QDesktopServices::openUrl(QUrl("http://www.yacreader.com")); + + comicsView->setModel(NULL); + foldersView->setModel(NULL); + listsView->setModel(NULL); + disableAllActions();//TODO comprobar que se deben deshabilitar + //será possible renombrar y borrar estas bibliotecas + renameLibraryAction->setEnabled(true); + removeLibraryAction->setEnabled(true); + } + } + else + { + comicsView->setModel(NULL); + foldersView->setModel(NULL); + listsView->setModel(NULL); + disableAllActions();//TODO comprobar que se deben deshabilitar + + //si la librería no existe en disco, se ofrece al usuario la posibiliad de eliminarla + if(!d.exists(path)) + { + QString currentLibrary = selectedLibrary->currentText(); + if(QMessageBox::question(this,tr("Library not available"),tr("Library '%1' is no longer available. Do you want to remove it?").arg(currentLibrary),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes) + { + deleteCurrentLibrary(); + } + //será possible renombrar y borrar estas bibliotecas + renameLibraryAction->setEnabled(true); + removeLibraryAction->setEnabled(true); + + } + else//si existe el path, puede ser que la librería sea alguna versión pre-5.0 ó que esté corrupta o que no haya drivers sql + { + + if(d.exists(path+"/library.ydb")) + { + QSqlDatabase db = DataBaseManagement::loadDatabase(path); + manageOpeningLibraryError(db.lastError().databaseText() + "-" + db.lastError().driverText()); + //será possible renombrar y borrar estas bibliotecas + renameLibraryAction->setEnabled(true); + removeLibraryAction->setEnabled(true); + } + else + { + QString currentLibrary = selectedLibrary->currentText(); + QString path = libraries.getPath(selectedLibrary->currentText()); + if(QMessageBox::question(this,tr("Old library"),tr("Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now?").arg(currentLibrary),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes) + { + QDir d(path+"/.yacreaderlibrary"); + d.removeRecursively(); + //d.rmdir(path+"/.yacreaderlibrary"); + createLibraryDialog->setDataAndStart(currentLibrary,path); + //create(path,path+"/.yacreaderlibrary",currentLibrary); + } + //será possible renombrar y borrar estas bibliotecas + renameLibraryAction->setEnabled(true); + removeLibraryAction->setEnabled(true); + } + } + } + } + else //en caso de que no exista ninguna biblioteca se desactivan los botones pertinentes + { + disableAllActions(); + showNoLibrariesWidget(); + } +} + +void LibraryWindow::loadCoversFromCurrentModel() +{ + comicsView->setModel(comicsModel); +} + +void LibraryWindow::copyAndImportComicsToCurrentFolder(const QList > &comics) +{ + QLOG_DEBUG() << "-copyAndImportComicsToCurrentFolder-"; + if(comics.size()>0) + { + QString destFolderPath = currentFolderPath(); + + QModelIndex folderDestination = getCurrentFolderIndex(); + + QProgressDialog * progressDialog = newProgressDialog(tr("Copying comics..."),comics.size()); + + ComicFilesManager * comicFilesManager = new ComicFilesManager(); + comicFilesManager->copyComicsTo(comics,destFolderPath,folderDestination); + + processComicFiles(comicFilesManager, progressDialog); + } +} + +void LibraryWindow::moveAndImportComicsToCurrentFolder(const QList > &comics) +{ + QLOG_DEBUG() << "-moveAndImportComicsToCurrentFolder-"; + if(comics.size()>0) + { + QString destFolderPath = currentFolderPath(); + + QModelIndex folderDestination = getCurrentFolderIndex(); + + QProgressDialog * progressDialog = newProgressDialog(tr("Moving comics..."),comics.size()); + + ComicFilesManager * comicFilesManager = new ComicFilesManager(); + comicFilesManager->moveComicsTo(comics,destFolderPath,folderDestination); + + processComicFiles(comicFilesManager, progressDialog); + } +} + +void LibraryWindow::copyAndImportComicsToFolder(const QList > &comics, const QModelIndex &miFolder) +{ + QLOG_DEBUG() << "-copyAndImportComicsToFolder-"; + if(comics.size()>0) + { + QModelIndex folderDestination = foldersModelProxy->mapToSource(miFolder); + + QString destFolderPath = QDir::cleanPath(currentPath()+foldersModel->getFolderPath(folderDestination)); + + QLOG_DEBUG() << "Coping to " << destFolderPath; + + QProgressDialog * progressDialog = newProgressDialog(tr("Copying comics..."),comics.size()); + + ComicFilesManager * comicFilesManager = new ComicFilesManager(); + comicFilesManager->copyComicsTo(comics,destFolderPath,folderDestination); + + processComicFiles(comicFilesManager, progressDialog); + } +} + +void LibraryWindow::moveAndImportComicsToFolder(const QList > &comics, const QModelIndex &miFolder) +{ + QLOG_DEBUG() << "-moveAndImportComicsToFolder-"; + if(comics.size()>0) + { + QModelIndex folderDestination = foldersModelProxy->mapToSource(miFolder); + + QString destFolderPath = QDir::cleanPath(currentPath()+foldersModel->getFolderPath(folderDestination)); + + QLOG_DEBUG() << "Moving to " << destFolderPath; + + QProgressDialog * progressDialog = newProgressDialog(tr("Moving comics..."),comics.size()); + + ComicFilesManager * comicFilesManager = new ComicFilesManager(); + comicFilesManager->moveComicsTo(comics,destFolderPath,folderDestination); + + processComicFiles(comicFilesManager, progressDialog); + } +} + +void LibraryWindow::processComicFiles(ComicFilesManager * comicFilesManager, QProgressDialog * progressDialog) +{ + connect(comicFilesManager,SIGNAL(progress(int)), progressDialog, SLOT(setValue(int))); + + QThread * thread = NULL; + + thread = new QThread(); + + comicFilesManager->moveToThread(thread); + + connect(progressDialog, SIGNAL(canceled()), comicFilesManager, SLOT(cancel()), Qt::DirectConnection); + + connect(thread, SIGNAL(started()), comicFilesManager, SLOT(process())); + connect(comicFilesManager, SIGNAL(success(QModelIndex)), this, SLOT(updateCopyMoveFolderDestination(QModelIndex))); + connect(comicFilesManager, SIGNAL(finished()), thread, SLOT(quit())); + connect(comicFilesManager, SIGNAL(finished()), comicFilesManager, SLOT(deleteLater())); + connect(comicFilesManager, SIGNAL(finished()), progressDialog, SLOT(close())); + connect(comicFilesManager, SIGNAL(finished()), progressDialog, SLOT(deleteLater())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + if(thread != NULL) + thread->start(); +} + +void LibraryWindow::updateCopyMoveFolderDestination(const QModelIndex & mi) +{ + updateFolder(mi); +} + +void LibraryWindow::updateCurrentFolder() +{ + updateFolder(getCurrentFolderIndex()); +} + +void LibraryWindow::updateFolder(const QModelIndex & miFolder) +{ + QLOG_DEBUG() << "UPDATE FOLDER!!!!"; + + importWidget->setUpdateLook(); + showImportingWidget(); + + QString currentLibrary = selectedLibrary->currentText(); + QString path = libraries.getPath(currentLibrary); + _lastAdded = currentLibrary; + libraryCreator->updateFolder(QDir::cleanPath(path),QDir::cleanPath(path+"/.yacreaderlibrary"),QDir::cleanPath(currentPath()+foldersModel->getFolderPath(miFolder)),miFolder); + libraryCreator->start(); +} + +QProgressDialog *LibraryWindow::newProgressDialog(const QString &label, int maxValue) +{ + QProgressDialog * progressDialog = new QProgressDialog(label,"Cancel",0,maxValue,this); + progressDialog->setWindowModality(Qt::WindowModal); + progressDialog->setMinimumWidth(350); + progressDialog->show(); + return progressDialog; +} + +void LibraryWindow::reloadAfterCopyMove(const QModelIndex & mi) +{ + if(getCurrentFolderIndex() == mi) + { + navigationController->loadFolderInfo(mi); + } + + foldersModel->fetchMoreFromDB(mi); + + enableNeededActions(); +} + +QModelIndex LibraryWindow::getCurrentFolderIndex() +{ + if(foldersView->selectionModel()->selectedRows().length()>0) + return foldersModelProxy->mapToSource(foldersView->currentIndex()); + else + return QModelIndex(); +} + +void LibraryWindow::enableNeededActions() +{ + if(foldersModel->rowCount(QModelIndex())>0) + disableFoldersActions(false); + + if(comicsModel->rowCount()>0) + disableComicsActions(false); + + disableLibrariesActions(false); + +} + +void LibraryWindow::addFolderToCurrentIndex() +{ + QModelIndex currentIndex = getCurrentFolderIndex(); + + bool ok; + QString newFolderName = QInputDialog::getText(this, tr("Add new folder"), + tr("Folder name:"), QLineEdit::Normal, + "", &ok); + + //chars not supported in a folder's name: / \ : * ? " < > | + QRegExp invalidChars("\\/\\:\\*\\?\\\"\\<\\>\\|\\\\");//TODO this regexp is not properly written + bool isValid = !newFolderName.contains(invalidChars); + + if (ok && !newFolderName.isEmpty() && isValid) + { + QString parentPath = QDir::cleanPath(currentPath()+foldersModel->getFolderPath(currentIndex)); + QDir parentDir(parentPath); + QDir newFolder(parentPath+"/"+newFolderName); + if(parentDir.mkdir(newFolderName) || newFolder.exists()) + { + QModelIndex newIndex = foldersModel->addFolderAtParent(newFolderName,currentIndex); + foldersView->setCurrentIndex(foldersModelProxy->mapFromSource(newIndex)); + navigationController->loadFolderInfo(newIndex); + historyController->updateHistory(YACReaderLibrarySourceContainer(newIndex,YACReaderLibrarySourceContainer::Folder)); + //a new folder is always an empty folder + showEmptyFolderView(); + } + } +} + +void LibraryWindow::deleteSelectedFolder() +{ + QModelIndex currentIndex = getCurrentFolderIndex(); + QString relativePath = foldersModel->getFolderPath(currentIndex); + QString folderPath = QDir::cleanPath(currentPath()+relativePath); + + if(!currentIndex.isValid()) + QMessageBox::information(this,tr("No folder selected"), tr("Please, select a folder first")); + else + { + QString libraryPath = QDir::cleanPath(currentPath()); + if((libraryPath == folderPath) || relativePath.isEmpty() || relativePath == "/") + QMessageBox::critical(this,tr("Error in path"),tr("There was an error accessing the folder's path")); + else + { + int ret = QMessageBox::question(this,tr("Delete folder"),tr("The selected folder and all its contents will be deleted from your disk. Are you sure?") + "\n\nFolder : " + folderPath,QMessageBox::Yes,QMessageBox::No); + + if(ret == QMessageBox::Yes) + { + //no folders multiselection by now + QModelIndexList indexList; + indexList << currentIndex; + + QList paths; + paths << folderPath; + + FoldersRemover * remover = new FoldersRemover(indexList,paths); + + QThread * thread = NULL; + + thread = new QThread(this); + + remover->moveToThread(thread); + + connect(thread, SIGNAL(started()), remover, SLOT(process())); + connect(remover, SIGNAL(remove(QModelIndex)), foldersModel, SLOT(deleteFolder(QModelIndex))); + connect(remover, SIGNAL(removeError()),this,SLOT(errorDeletingFolder())); + connect(remover, SIGNAL(finished()),navigationController,SLOT(reselectCurrentFolder())); + connect(remover, SIGNAL(finished()), remover, SLOT(deleteLater())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + if(thread != NULL) + thread->start(); + } + } + } +} + +void LibraryWindow::errorDeletingFolder() +{ + QMessageBox::critical(this,tr("Unable to delete"),tr("There was an issue trying to delete the selected folders. Please, check for write permissions and be sure that any applications are using these folders or any of the contained files.")); +} + +void LibraryWindow::addNewReadingList() +{ + QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes(); + QModelIndex sourceMI; + if(!selectedLists.isEmpty()) + sourceMI = listsModelProxy->mapToSource(selectedLists.at(0)); + + if(selectedLists.isEmpty() || !listsModel->isReadingSubList(sourceMI) ) + { + bool ok; + QString newListName = QInputDialog::getText(this, tr("Add new reading lists"), + tr("List name:"), QLineEdit::Normal, + "", &ok); + if (ok) { + if(selectedLists.isEmpty() || !listsModel->isReadingList(sourceMI)) + listsModel->addReadingList(newListName); //top level + else + { + listsModel->addReadingListAt(newListName,sourceMI); //sublist + } + } + } +} + +void LibraryWindow::deleteSelectedReadingList() +{ + QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes(); + if(!selectedLists.isEmpty()) + { + QModelIndex mi = listsModelProxy->mapToSource(selectedLists.at(0)); + if(listsModel->isEditable(mi)) + { + int ret = QMessageBox::question(this,tr("Delete list/label"),tr("The selected item will be deleted, your comics or folders will NOT be deleted from your disk. Are you sure?"),QMessageBox::Yes,QMessageBox::No); + if(ret == QMessageBox::Yes) + { + listsModel->deleteItem(mi); + navigationController->reselectCurrentList(); + } + } + } +} + +void LibraryWindow::showAddNewLabelDialog() +{ + AddLabelDialog * dialog = new AddLabelDialog(); + int ret = dialog->exec(); + + if (ret == QDialog::Accepted) + { + YACReader::LabelColors color = dialog->selectedColor(); + QString name = dialog->name(); + + listsModel->addNewLabel(name,color); + } +} + +//TODO implement editors in treeview +void LibraryWindow::showRenameCurrentList() +{ + QModelIndexList selectedLists = listsView->selectionModel()->selectedIndexes(); + if(!selectedLists.isEmpty()) + { + QModelIndex mi = listsModelProxy->mapToSource(selectedLists.at(0)); + if(listsModel->isEditable(mi)) + { + bool ok; + QString newListName = QInputDialog::getText(this, tr("Rename list name"), + tr("List name:"), QLineEdit::Normal, + listsModel->name(mi), &ok); + + if(ok) + listsModel->rename(mi,newListName); + } + } + +} + +void LibraryWindow::addSelectedComicsToFavorites() +{ + QModelIndexList indexList = getSelectedComics(); + comicsModel->addComicsToFavorites(indexList); +} + +void LibraryWindow::showComicsViewContextMenu(const QPoint &point) +{ + QMenu menu; + + menu.addAction(openComicAction); + menu.addAction(saveCoversToAction); + menu.addSeparator(); + menu.addAction(openContainingFolderComicAction); + menu.addAction(updateCurrentFolderAction); + menu.addSeparator(); + menu.addAction(resetComicRatingAction); + menu.addSeparator(); + menu.addAction(editSelectedComicsAction); + menu.addAction(getInfoAction); + menu.addAction(asignOrderAction); + menu.addSeparator(); + menu.addAction(selectAllComicsAction); + menu.addSeparator(); + menu.addAction(setAsReadAction); + menu.addAction(setAsNonReadAction); + menu.addSeparator(); + menu.addAction(deleteComicsAction); + menu.addSeparator(); + menu.addAction(addToMenuAction); + QMenu subMenu; + setupAddToSubmenu(subMenu); + +#ifndef Q_OS_MAC + menu.addSeparator(); + menu.addAction(toggleFullScreenAction); +#endif + + menu.exec(comicsView->mapToGlobal(point)); +} + +void LibraryWindow::showComicsItemContextMenu(const QPoint &point) +{ + QMenu menu; + + menu.addAction(openComicAction); + menu.addAction(saveCoversToAction); + menu.addSeparator(); + menu.addAction(openContainingFolderComicAction); + menu.addAction(updateCurrentFolderAction); + menu.addSeparator(); + menu.addAction(resetComicRatingAction); + menu.addSeparator(); + menu.addAction(editSelectedComicsAction); + menu.addAction(getInfoAction); + menu.addAction(asignOrderAction); + menu.addSeparator(); + menu.addAction(setAsReadAction); + menu.addAction(setAsNonReadAction); + menu.addSeparator(); + menu.addAction(deleteComicsAction); + menu.addSeparator(); + menu.addAction(addToMenuAction); + QMenu subMenu; + setupAddToSubmenu(subMenu); + + menu.exec(comicsView->mapToGlobal(point)); +} + +void LibraryWindow::setupAddToSubmenu(QMenu &menu) +{ + menu.addAction(addToFavoritesAction); + addToMenuAction->setMenu(&menu); + + const QList labels = listsModel->getLabels(); + if(labels.count() > 0) + menu.addSeparator(); + foreach(LabelItem * label, labels) + { + QAction * action = new QAction(this); + action->setIcon(label->getIcon()); + action->setText(label->name()); + + action->setData(label->getId()); + + menu.addAction(action); + + connect(action,SIGNAL(triggered()),this,SLOT(onAddComicsToLabel())); + } +} + +void LibraryWindow::onAddComicsToLabel() +{ + QAction * action = static_cast(sender()); + + qulonglong labelId = action->data().toULongLong(); + + QModelIndexList comics = getSelectedComics(); + + comicsModel->addComicsToLabel(comics,labelId); +} + +void LibraryWindow::setToolbarTitle(const QModelIndex &modelIndex) +{ +#ifndef Q_OS_MAC + if(!modelIndex.isValid()) + libraryToolBar->setCurrentFolderName(selectedLibrary->currentText()); + else + libraryToolBar->setCurrentFolderName(modelIndex.data().toString()); +#endif +} + +void LibraryWindow::saveSelectedCoversTo() +{ + QFileDialog saveDialog; + QString folderPath = saveDialog.getExistingDirectory(this,tr("Save covers"),QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); + if (!folderPath.isEmpty()) + { + QModelIndexList comics = getSelectedComics(); + foreach(QModelIndex comic, comics) + { + QString origin = comic.data(ComicModel::CoverPathRole).toString().remove("file:///"); + QString destination = QDir(folderPath).filePath(comic.data(ComicModel::FileNameRole).toString()+".jpg"); + + QLOG_DEBUG() << "From : " << origin; + QLOG_DEBUG() << "To : " << destination; + + QFile::copy(origin,destination); + } + } +} + +void LibraryWindow::selectSubfolder(const QModelIndex &mi, int child) +{ + QModelIndex dest = foldersModel->index(child,0,mi); + foldersView->setCurrentIndex(dest); + navigationController->selectedFolder(dest); +} + +//this methods is only using after deleting comics +//TODO broken window :) +void LibraryWindow::checkEmptyFolder() +{ + if(comicsModel->rowCount()>0 && !importedCovers) + { + disableComicsActions(false); + } + else + { + disableComicsActions(true); +#ifndef Q_OS_MAC + if(comicsModel->rowCount()>0) + toggleFullScreenAction->setEnabled(true); +#endif + if(comicsModel->rowCount() == 0) + navigationController->reselectCurrentFolder(); + } +} + +void LibraryWindow::openComic() +{ + if(!importedCovers) + { + ComicDB comic = comicsModel->getComic(comicsView->currentIndex()); + QString path = currentPath(); + QList siblings = comicsModel->getAllComics(); + + quint64 comicId = comic.id; + //TODO generate IDS for libraries... + quint64 libraryId = libraries.getId(selectedLibrary->currentText()); + + // %1 %2 %3 NO-->%4 %5 %6 %7 %8 %9 %10 + //Invoke YACReader comicPath comicId libraryId NO-->currentPage bookmark1 bookmark2 bookmark3 brightness contrast gamma + bool yacreaderFound = false; +#ifdef Q_OS_MAC + QString comicIdS = QString("--comicId=") + QString("%1").arg(comicId); + QString libraryIdS = QString("--libraryId=") + QString("%1").arg(libraryId); + QString yacreaderPath = QDir::cleanPath(QCoreApplication::applicationDirPath()+"/../../../YACReader.app"); + if(yacreaderFound = QFileInfo(yacreaderPath).exists()) + QProcess::startDetached("open", QStringList() << "-n" << yacreaderPath << "--args" << path << comicIdS << libraryIdS ); /*<< page << bookmark1 << bookmark2 << bookmark3 << brightness << contrast << gamma*///,QStringList() << path); + +#endif + +#ifdef Q_OS_WIN /* \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\" \"%10\" */ + yacreaderFound = QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+QString("/YACReader \"%1\" \"%2\" \"%3\"").arg(path).arg(QString("--comicId=") + QString::number(comicId)).arg(QString("--libraryId=") + QString::number(libraryId))/*.arg(page).arg(bookmark1).arg(bookmark2).arg(bookmark3).arg(brightness).arg(contrast).arg(gamma)*/,QStringList()); +#endif + +#if defined Q_OS_UNIX && !defined Q_OS_MAC + QStringList parameters = QStringList() << path << (QString("--comicId=") + QString::number(comicId)) << (QString("--libraryId=") + QString::number(libraryId)); + yacreaderFound = QProcess::startDetached(QString("YACReader"),parameters); +#endif + if(!yacreaderFound) + QMessageBox::critical(this,tr("YACReader not found"),tr("YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary.")); + + setCurrentComicOpened(); + } +} + +void LibraryWindow::setCurrentComicsStatusReaded(YACReaderComicReadStatus readStatus) { + comicsModel->setComicsRead(getSelectedComics(),readStatus); +} + +void LibraryWindow::setCurrentComicReaded() { + this->setCurrentComicsStatusReaded(YACReader::Read); +} + +void LibraryWindow::setCurrentComicOpened() +{ + //TODO: remove? +} + +void LibraryWindow::setCurrentComicUnreaded() { + this->setCurrentComicsStatusReaded(YACReader::Unread); +} + +void LibraryWindow::createLibrary() { + createLibraryDialog->open(libraries); +} + +void LibraryWindow::create(QString source, QString dest, QString name) +{ + QLOG_INFO() << QString("About to create a library from '%1' to '%2' with name '%3'").arg(source).arg(dest).arg(name); + libraryCreator->createLibrary(source,dest); + libraryCreator->start(); + _lastAdded = name; + _sourceLastAdded = source; + + importWidget->setImportLook(); + showImportingWidget(); + +} + +void LibraryWindow::reloadCurrentLibrary() { + loadLibrary(selectedLibrary->currentText()); +} + +void LibraryWindow::openLastCreated() +{ + + selectedLibrary->disconnect(); + + selectedLibrary->setCurrentIndex(selectedLibrary->findText(_lastAdded)); + libraries.addLibrary(_lastAdded,_sourceLastAdded); + selectedLibrary->addItem(_lastAdded,_sourceLastAdded); + selectedLibrary->setCurrentIndex(selectedLibrary->findText(_lastAdded)); + libraries.save(); + + connect(selectedLibrary,SIGNAL(currentIndexChanged(QString)),this,SLOT(loadLibrary(QString))); + + loadLibrary(_lastAdded); +} + +void LibraryWindow::showAddLibrary() +{ + addLibraryDialog->open(); +} + +void LibraryWindow::openLibrary(QString path, QString name) +{ + if(!libraries.contains(name)) + { + //TODO: fix bug, /a/b/c/.yacreaderlibrary/d/e + path.remove("/.yacreaderlibrary"); + QDir d; //TODO change this by static methods (utils class?? with delTree for example) + if(d.exists(path + "/.yacreaderlibrary")) + { + _lastAdded = name; + _sourceLastAdded = path; + openLastCreated(); + addLibraryDialog->close(); + } + else + QMessageBox::warning(this,tr("Library not found"),tr("The selected folder doesn't contain any library.")); + } + else + { + libraryAlreadyExists(name); + } +} + +void LibraryWindow::loadLibraries() +{ + libraries.load(); + foreach(QString name,libraries.getNames()) + selectedLibrary->addItem(name,libraries.getPath(name)); +} + + +void LibraryWindow::saveLibraries() { + libraries.save(); +} + +void LibraryWindow::updateLibrary() +{ + importWidget->setUpdateLook(); + showImportingWidget(); + + QString currentLibrary = selectedLibrary->currentText(); + QString path = libraries.getPath(currentLibrary); + _lastAdded = currentLibrary; + libraryCreator->updateLibrary(path,path+"/.yacreaderlibrary"); + libraryCreator->start(); +} + +void LibraryWindow::deleteCurrentLibrary() +{ + QString path = libraries.getPath(selectedLibrary->currentText()); + libraries.remove(selectedLibrary->currentText()); + selectedLibrary->removeItem(selectedLibrary->currentIndex()); + //selectedLibrary->setCurrentIndex(0); + path = path+"/.yacreaderlibrary"; + + QDir d(path); + d.removeRecursively(); + if(libraries.isEmpty())//no more libraries available. + { + comicsView->setModel(NULL); + foldersView->setModel(NULL); + listsView->setModel(NULL); + + disableAllActions(); + showNoLibrariesWidget(); + } + libraries.save(); +} + +void LibraryWindow::removeLibrary() +{ + QString currentLibrary = selectedLibrary->currentText(); + QMessageBox * messageBox = new QMessageBox(tr("Are you sure?"),tr("Do you want remove ")+currentLibrary+tr(" library?"),QMessageBox::Question,QMessageBox::Yes,QMessageBox::YesToAll,QMessageBox::No); + messageBox->button(QMessageBox::YesToAll)->setText(tr("Remove and delete metadata")); + messageBox->setParent(this); + messageBox->setWindowModality(Qt::WindowModal); + int ret = messageBox->exec(); + if(ret == QMessageBox::Yes) + { + libraries.remove(currentLibrary); + selectedLibrary->removeItem(selectedLibrary->currentIndex()); + //selectedLibrary->setCurrentIndex(0); + if(libraries.isEmpty())//no more libraries available. + { + comicsView->setModel(NULL); + foldersView->setModel(NULL); + listsView->setModel(NULL); + + disableAllActions(); + showNoLibrariesWidget(); + } + libraries.save(); + } + else if(ret == QMessageBox::YesToAll) + { + deleteCurrentLibrary(); + } + +} + +void LibraryWindow::renameLibrary() +{ + renameLibraryDialog->open(); +} + +void LibraryWindow::rename(QString newName) //TODO replace +{ + QString currentLibrary = selectedLibrary->currentText(); + if(newName != currentLibrary) + { + if(!libraries.contains(newName)) + { + libraries.rename(currentLibrary,newName); + //selectedLibrary->removeItem(selectedLibrary->currentIndex()); + //libraries.addLibrary(newName,path); + selectedLibrary->renameCurrentLibrary(newName); + libraries.save(); + renameLibraryDialog->close(); +#ifndef Q_OS_MAC + if(!foldersModelProxy->mapToSource(foldersView->currentIndex()).isValid()) + libraryToolBar->setCurrentFolderName(selectedLibrary->currentText()); +#endif + } + else + { + libraryAlreadyExists(newName); + } + } + else + renameLibraryDialog->close(); + //selectedLibrary->setCurrentIndex(selectedLibrary->findText(newName)); +} + +void LibraryWindow::cancelCreating() +{ + stopLibraryCreator(); +} + +void LibraryWindow::stopLibraryCreator() +{ + libraryCreator->stop(); + libraryCreator->wait(); +} + +void LibraryWindow::setRootIndex() +{ + if(!libraries.isEmpty()) + { + QString path=libraries.getPath(selectedLibrary->currentText())+"/.yacreaderlibrary"; + QDir d; //TODO change this by static methods (utils class?? with delTree for example) + if(d.exists(path)) + { + navigationController->selectedFolder(QModelIndex()); + } + else + { + comicsView->setModel(NULL); + } + + foldersView->selectionModel()->clear(); + } +} + + +void LibraryWindow::toggleFullScreen() +{ + fullscreen?toNormal():toFullScreen(); + fullscreen = !fullscreen; +} + +void LibraryWindow::toFullScreen() +{ + fromMaximized = this->isMaximized(); + + sideBar->hide(); + libraryToolBar->hide(); + + comicsView->toFullScreen(); + + showFullScreen(); +} + +void LibraryWindow::toNormal() +{ + sideBar->show(); + + comicsView->toNormal(); + + if(fromMaximized) + showMaximized(); + else + showNormal(); + +#ifdef Q_OS_MAC + QTimer * timer = new QTimer(); + timer->setSingleShot(true); + timer->start(); + connect(timer,SIGNAL(timeout()),libraryToolBar,SLOT(show())); + connect(timer,SIGNAL(timeout()),timer,SLOT(deleteLater())); +#else + libraryToolBar->show(); +#endif + +} + +void LibraryWindow::setSearchFilter(const YACReader::SearchModifiers modifier, QString filter) +{ + if(!filter.isEmpty()) + { + status = LibraryWindow::Searching; + foldersModelProxy->setFilter(modifier, filter, true);//includeComicsCheckBox->isChecked()); + comicsModel->setupModelData(modifier, filter, foldersModel->getDatabase()); + comicsView->enableFilterMode(true); + comicsView->setModel(comicsModel); //TODO, columns are messed up after ResetModel some times, this shouldn't be necesary + foldersView->expandAll(); + + if(comicsModel->rowCount() == 0) + showNoSearchResultsView(); + else + showComicsView(); + } + else if(status == LibraryWindow::Searching) + {//if no searching, then ignore this + clearSearchFilter(); + navigationController->loadPreviousStatus(); + } +} + +void LibraryWindow::clearSearchFilter() +{ + foldersModelProxy->clear(); + comicsView->enableFilterMode(false); + foldersView->collapseAll(); + status = LibraryWindow::Normal; +} + + +void LibraryWindow::showProperties() +{ + QModelIndexList indexList = getSelectedComics(); + + QList comics = comicsModel->getComics(indexList); + ComicDB c = comics[0]; + _comicIdEdited = c.id;//static_cast(indexList[0].internalPointer())->data(4).toULongLong(); + + propertiesDialog->databasePath = foldersModel->getDatabase(); + propertiesDialog->basePath = currentPath(); + propertiesDialog->setComics(comics); + + propertiesDialog->show(); +} + +void LibraryWindow::showComicVineScraper() +{ + QSettings s(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + s.beginGroup("ComicVine"); + + if(!s.contains(COMIC_VINE_API_KEY)) + { + ApiKeyDialog d; + d.exec(); + } + + //check if the api key was inserted + if(s.contains(COMIC_VINE_API_KEY)) + { + QModelIndexList indexList = getSelectedComics(); + + QList comics = comicsModel->getComics(indexList); + ComicDB c = comics[0]; + _comicIdEdited = c.id;//static_cast(indexList[0].internalPointer())->data(4).toULongLong(); + + comicVineDialog->databasePath = foldersModel->getDatabase(); + comicVineDialog->basePath = currentPath(); + comicVineDialog->setComics(comics); + + comicVineDialog->show(); + } +} + +void LibraryWindow::setRemoveError() +{ + removeError = true; +} + +void LibraryWindow::checkRemoveError() +{ + if(removeError) + { + QMessageBox::critical(this,tr("Unable to delete"),tr("There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder.")); + } + removeError = false; +} + +void LibraryWindow::resetComicRating() +{ + QModelIndexList indexList = getSelectedComics(); + + comicsModel->startTransaction(); + for(auto & index:indexList) + { + comicsModel->resetComicRating(index); + } + comicsModel->finishTransaction(); +} + +void LibraryWindow::switchToComicsView(ComicsView * from, ComicsView * to) +{ + //setup views + disconnectComicsViewConnections(from); + from->close(); + + comicsView = to; + doComicsViewConnections(); + + comicsView->setToolBar(editInfoToolBar); + + comicsViewStack->removeWidget(from); + comicsViewStack->addWidget(comicsView); + + delete from; + + //load content into current view + loadCoversFromCurrentModel(); + + if(!searchEdit->text().isEmpty()) + { + comicsView->enableFilterMode(true); + } +} + +void LibraryWindow::showComicsViewTransition() +{ + comicsViewStack->setCurrentWidget(comicsViewTransition); + comicsViewTransition->startMovie(); +} + +void LibraryWindow::toggleComicsView_delayed() +{ + if(comicsViewStatus == Flow){ + QIcon icoViewsButton; + icoViewsButton.addFile(":/images/main_toolbar/flow.png", QSize(), QIcon::Normal); + toggleComicsViewAction->setIcon(icoViewsButton); +#ifdef Q_OS_MAC + libraryToolBar->updateViewSelectorIcon(icoViewsButton); +#endif + switchToComicsView(classicComicsView, gridComicsView = new GridComicsView()); + comicsViewStatus = Grid; + } + else{ + QIcon icoViewsButton; + icoViewsButton.addFile(":/images/main_toolbar/grid.png", QSize(), QIcon::Normal); + toggleComicsViewAction->setIcon(icoViewsButton); +#ifdef Q_OS_MAC + libraryToolBar->updateViewSelectorIcon(icoViewsButton); +#endif + switchToComicsView(gridComicsView, classicComicsView = new ClassicComicsView()); + comicsViewStatus = Flow; + } + + settings->setValue(COMICS_VIEW_STATUS, comicsViewStatus); +} + +void LibraryWindow::showComicsView() +{ + comicsViewStack->setCurrentWidget(comicsView); +} + +void LibraryWindow::showEmptyFolderView() +{ + comicsViewStack->setCurrentWidget(emptyFolderWidget); +} + +void LibraryWindow::showEmptyLabelView() +{ + comicsViewStack->setCurrentWidget(emptyLabelWidget); +} + +void LibraryWindow::showEmptySpecialList() +{ + comicsViewStack->setCurrentWidget(emptySpecialList); +} + +void LibraryWindow::showEmptyReadingListWidget() +{ + comicsViewStack->setCurrentWidget(emptyReadingList); +} + +void LibraryWindow::showNoSearchResultsView() +{ + comicsViewStack->setCurrentWidget(noSearchResultsWidget); +} + +//TODO recover the current comics selection and restore it in the destination +void LibraryWindow::toggleComicsView() +{ + if(comicsViewStack->currentWidget()==comicsView) { + QTimer::singleShot(0,this,SLOT(showComicsViewTransition())); + QTimer::singleShot(32,this,SLOT(toggleComicsView_delayed())); + } else + toggleComicsView_delayed(); +} + +void LibraryWindow::checkSearchNumResults(int numResults) +{ + if(numResults == 0) + showNoSearchResultsView(); + else + showComicsView(); +} + +void LibraryWindow::asignNumbers() +{ + QModelIndexList indexList = getSelectedComics(); + + int startingNumber = indexList[0].row()+1; + if(indexList.count()>1) + { + bool ok; + int n = QInputDialog::getInt(this, tr("Asign comics numbers"), + tr("Asign numbers starting in:"), startingNumber,0,2147483647,1,&ok); + if (ok) + startingNumber = n; + else + return; + } + qint64 edited = comicsModel->asignNumbers(indexList,startingNumber); + + //TODO add resorting without reloading + navigationController->loadFolderInfo(foldersModelProxy->mapToSource(foldersView->currentIndex())); + + const QModelIndex & mi = comicsModel->getIndexFromId(edited); + if(mi.isValid()) + { + comicsView->scrollTo(mi,QAbstractItemView::PositionAtCenter); + comicsView->setCurrentIndex(mi); + } +} + +void LibraryWindow::openContainingFolderComic() +{ +QModelIndex modelIndex = comicsView->currentIndex(); +QFileInfo file = QDir::cleanPath(currentPath() + comicsModel->getComicPath(modelIndex)); +#if defined Q_OS_UNIX && !defined Q_OS_MAC + QString path = file.absolutePath(); + QDesktopServices::openUrl(QUrl("file:///"+path, QUrl::TolerantMode)); +#endif + +#ifdef Q_OS_MAC + QString filePath = file.absoluteFilePath(); + QStringList args; + args << "-e"; + args << "tell application \"Finder\""; + args << "-e"; + args << "activate"; + args << "-e"; + args << "select POSIX file \""+filePath+"\""; + args << "-e"; + args << "end tell"; + QProcess::startDetached("osascript", args); +#endif + +#ifdef Q_OS_WIN + QString filePath = file.absoluteFilePath(); + QString cmdArgs = QString("/select,\"") + QDir::toNativeSeparators(filePath) + QStringLiteral("\""); + ShellExecuteW(0, L"open", L"explorer.exe", reinterpret_cast(cmdArgs.utf16()), 0, SW_NORMAL); +#endif +} + +void LibraryWindow::openContainingFolder() +{ + QModelIndex modelIndex = foldersModelProxy->mapToSource(foldersView->currentIndex()); + QString path; + if(modelIndex.isValid()) + path = QDir::cleanPath(currentPath() + foldersModel->getFolderPath(modelIndex)); + else + path = QDir::cleanPath(currentPath()); + QDesktopServices::openUrl(QUrl("file:///"+path, QUrl::TolerantMode)); +} + +void LibraryWindow::setFolderAsNotCompleted() +{ + //foldersModel->updateFolderCompletedStatus(foldersView->selectionModel()->selectedRows(),false); + foldersModel->updateFolderCompletedStatus(QModelIndexList() << foldersModelProxy->mapToSource(foldersView->currentIndex()),false); +} + +void LibraryWindow::setFolderAsCompleted() +{ + //foldersModel->updateFolderCompletedStatus(foldersView->selectionModel()->selectedRows(),true); + foldersModel->updateFolderCompletedStatus(QModelIndexList() << foldersModelProxy->mapToSource(foldersView->currentIndex()),true); +} + +void LibraryWindow::setFolderAsRead() +{ + //foldersModel->updateFolderFinishedStatus(foldersView->selectionModel()->selectedRows(),true); + foldersModel->updateFolderFinishedStatus(QModelIndexList() << foldersModelProxy->mapToSource(foldersView->currentIndex()),true); +} + +void LibraryWindow::setFolderAsUnread() +{ + //foldersModel->updateFolderFinishedStatus(foldersView->selectionModel()->selectedRows(),false); + foldersModel->updateFolderFinishedStatus(QModelIndexList() << foldersModelProxy->mapToSource(foldersView->currentIndex()),false); +} + +void LibraryWindow::exportLibrary(QString destPath) +{ + QString currentLibrary = selectedLibrary->currentText(); + QString path = libraries.getPath(currentLibrary)+"/.yacreaderlibrary"; + packageManager->createPackage(path,destPath+"/"+currentLibrary); +} + +void LibraryWindow::importLibrary(QString clc,QString destPath,QString name) +{ + packageManager->extractPackage(clc,destPath+"/"+name); + _lastAdded = name; + _sourceLastAdded = destPath+"/"+name; +} + +void LibraryWindow::reloadOptions() +{ + //comicFlow->setFlowType(flowType); + comicsView->updateConfig(settings); +} + +QString LibraryWindow::currentPath() +{ + return libraries.getPath(selectedLibrary->currentText()); +} + +QString LibraryWindow::currentFolderPath() +{ + QString path; + + if(foldersView->selectionModel()->selectedRows().length()>0) + path = foldersModel->getFolderPath(foldersModelProxy->mapToSource(foldersView->currentIndex())); + else + path = foldersModel->getFolderPath(QModelIndex()); + + QLOG_DEBUG() << "current folder path : " << QDir::cleanPath(currentPath()+path); + + return QDir::cleanPath(currentPath()+path); +} + +//TODO ComicsView: some actions in the comics toolbar can be relative to a certain view +//show/hide actions on show/hide widget +void LibraryWindow::hideComicFlow(bool hide) +{ + /* + if(hide) + { + QList sizes; + sizes.append(0); + int total = sVertical->sizes().at(0) + sVertical->sizes().at(1); + sizes.append(total); + sVertical->setSizes(sizes); + } + else + { + QList sizes; + int total = sVertical->sizes().at(0) + sVertical->sizes().at(1); + sizes.append(2*total/3); + sizes.append(total/3); + sVertical->setSizes(sizes); + } +*/ +} + +void LibraryWindow::showExportComicsInfo() +{ + exportComicsInfoDialog->source = currentPath() + "/.yacreaderlibrary/library.ydb"; + exportComicsInfoDialog->open(); +} + +void LibraryWindow::showImportComicsInfo() +{ + importComicsInfoDialog->dest = currentPath() + "/.yacreaderlibrary/library.ydb"; + importComicsInfoDialog->open(); +} +#include "startup.h" +extern Startup * s; +void LibraryWindow::closeEvent ( QCloseEvent * event ) +{ + s->stop(); + settings->setValue(MAIN_WINDOW_GEOMETRY, saveGeometry()); + + comicsView->close(); + sideBar->close(); + + QApplication::instance()->processEvents(); + event->accept(); + QMainWindow::closeEvent(event); +} + +void LibraryWindow::showNoLibrariesWidget() +{ + disableAllActions(); + searchEdit->setDisabled(true); + mainWidget->setCurrentIndex(1); +} + +void LibraryWindow::showRootWidget() +{ +#ifndef Q_OS_MAC + libraryToolBar->setDisabled(false); +#endif + searchEdit->setEnabled(true); + mainWidget->setCurrentIndex(0); +} + +void LibraryWindow::showImportingWidget() +{ + disableAllActions(); + importWidget->clear(); +#ifndef Q_OS_MAC + libraryToolBar->setDisabled(true); +#endif + searchEdit->setDisabled(true); + mainWidget->setCurrentIndex(2); +} + +void LibraryWindow::manageCreatingError(const QString & error) +{ + QMessageBox::critical(this,tr("Error creating the library"),error); +} + +void LibraryWindow::manageUpdatingError(const QString & error) +{ + QMessageBox::critical(this,tr("Error updating the library"),error); +} + +void LibraryWindow::manageOpeningLibraryError(const QString & error) +{ + QMessageBox::critical(this,tr("Error opening the library"),error); +} + +bool lessThanModelIndexRow(const QModelIndex & m1, const QModelIndex & m2) +{ + return m1.row()selectionModel()->selectedRows(); + QLOG_INFO() << "selection count " << selection.length(); + qSort(selection.begin(),selection.end(),lessThanModelIndexRow); + + if(selection.count()==0) + { + comicsView->selectIndex(0); + selection = comicsView->selectionModel()->selectedRows(); + } + return selection; +} + +void LibraryWindow::deleteComics() +{ + //TODO + if(!listsView->selectionModel()->selectedRows().isEmpty()) + { + deleteComicsFromList(); + }else + { + deleteComicsFromDisk(); + } +} + +void LibraryWindow::deleteComicsFromDisk() +{ + int ret = QMessageBox::question(this,tr("Delete comics"),tr("All the selected comics will be deleted from your disk. Are you sure?"),QMessageBox::Yes,QMessageBox::No); + + if(ret == QMessageBox::Yes) + { + + QModelIndexList indexList = getSelectedComics(); + + QList comics = comicsModel->getComics(indexList); + + QList paths; + QString libraryPath = currentPath(); + foreach(ComicDB comic, comics) + { + paths.append(libraryPath + comic.path); + QLOG_INFO() << comic.path; + QLOG_INFO() << comic.id; + QLOG_INFO() << comic.parentId; + } + + ComicsRemover * remover = new ComicsRemover(indexList,paths); + QThread * thread = NULL; + + thread = new QThread(this); + + remover->moveToThread(thread); + + comicsModel->startTransaction(); + + connect(thread, SIGNAL(started()), remover, SLOT(process())); + connect(remover, SIGNAL(remove(int)), comicsModel, SLOT(remove(int))); + connect(remover, SIGNAL(removeError()),this,SLOT(setRemoveError())); + connect(remover, SIGNAL(finished()), comicsModel, SLOT(finishTransaction())); + + connect(remover, SIGNAL(finished()),this,SLOT(checkEmptyFolder())); + connect(remover, SIGNAL(finished()),this,SLOT(checkRemoveError())); + connect(remover, SIGNAL(finished()), remover, SLOT(deleteLater())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + if(thread != NULL) + thread->start(); + } +} + +void LibraryWindow::deleteComicsFromList() +{ + int ret = QMessageBox::question(this,tr("Remove comics"),tr("Comics will only be deleted from the current label/list. Are you sure?"),QMessageBox::Yes,QMessageBox::No); + + if(ret == QMessageBox::Yes) + { + QModelIndexList indexList = getSelectedComics(); + if(indexList.isEmpty()) + return; + + QModelIndex mi = listsModelProxy->mapToSource(listsView->currentIndex()); + + ReadingListModel::TypeList typeList = (ReadingListModel::TypeList)mi.data(ReadingListModel::TypeListsRole).toInt(); + + qulonglong id = mi.data(ReadingListModel::IDRole).toULongLong(); + switch (typeList) { + case ReadingListModel::SpecialList: + //by now only 'favorites' + comicsModel->deleteComicsFromFavorites(indexList); + break; + case ReadingListModel::Label: + comicsModel->deleteComicsFromLabel(indexList,id); + break; + case ReadingListModel::ReadingList: + comicsModel->deleteComicsFromReadingList(indexList,id); + break; + } + } + +} + +void LibraryWindow::showFoldersContextMenu(const QPoint &point) +{ + QModelIndex sourceMI = foldersModelProxy->mapToSource(foldersView->indexAt(point)); + + bool isCompleted = sourceMI.data(FolderModel::CompletedRole).toBool(); + bool isRead = sourceMI.data(FolderModel::FinishedRole).toBool(); + + QMenu menu; + //QMenu * folderMenu = new QMenu(tr("Folder")); + menu.addAction(openContainingFolderAction); + menu.addAction(updateFolderAction); + menu.addSeparator();//------------------------------- + if(isCompleted) + menu.addAction(setFolderAsNotCompletedAction); + else + menu.addAction(setFolderAsCompletedAction); + menu.addSeparator();//------------------------------- + if(isRead) + menu.addAction(setFolderAsUnreadAction); + else + menu.addAction(setFolderAsReadAction); + + menu.exec(foldersView->mapToGlobal(point)); + +} + +/* +void LibraryWindow::showSocial() +{ + socialDialog->move(this->mapToGlobal(QPoint(width()-socialDialog->width()-10, centralWidget()->pos().y()+10))); + + QModelIndexList indexList = getSelectedComics(); + + ComicDB comic = dmCV->getComic(indexList.at(0)); + + socialDialog->setComic(comic,currentPath()); + socialDialog->setHidden(false); +}*/ + +void LibraryWindow::libraryAlreadyExists(const QString & name) +{ + QMessageBox::information(this,tr("Library name already exists"),tr("There is another library with the name '%1'.").arg(name)); +} + +void LibraryWindow::importLibraryPackage() +{ + importLibraryDialog->open(libraries); +} + +void LibraryWindow::updateComicsView(quint64 libraryId, const ComicDB & comic) +{ + if(libraryId == libraries.getId(selectedLibrary->currentText())) { + comicsModel->reload(comic); + } +} diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h new file mode 100644 index 00000000..69ae896c --- /dev/null +++ b/YACReaderLibrary/library_window.h @@ -0,0 +1,410 @@ +#ifndef __LIBRARYWINDOW_H +#define __LIBRARYWINDOW_H + +#include +#include +#include +#include +#include "yacreader_global.h" +#include "yacreader_libraries.h" + +#include "yacreader_navigation_controller.h" + +#ifdef Q_OS_MAC + #include "yacreader_macosx_toolbar.h" +#endif + +class QTreeView; +class QDirModel; +class QAction; +class QToolBar; +class QComboBox; +class QThread; +class QStackedWidget; +class YACReaderSearchLineEdit; +class CreateLibraryDialog; +class ExportLibraryDialog; +class ImportLibraryDialog; +class ExportComicsInfoDialog; +class ImportComicsInfoDialog; +class AddLibraryDialog; +class LibraryCreator; +class HelpAboutDialog; +class RenameLibraryDialog; +class PropertiesDialog; +class PackageManager; +class QCheckBox; +class QPushButton; +class ComicModel; +class QSplitter; +class FolderModel; +class FolderModelProxy; +class QItemSelectionModel; +class QString; +class QLabel; +class NoLibrariesWidget; +class OptionsDialog; +class ServerConfigDialog; +class QCloseEvent; +class ImportWidget; +class QSettings; +class LibraryItem; +class YACReaderTableView; +class YACReaderSideBar; +class YACReaderLibraryListWidget; +class YACReaderFoldersView; +class YACReaderMainToolBar; +class ComicVineDialog; +class ComicsView; +class ClassicComicsView; +class GridComicsView; +class ComicsViewTransition; +class EmptyFolderWidget; +class NoSearchResultsWidget; +class EditShortcutsDialog; +class ComicFilesManager; +class QProgressDialog; +class ReadingListModel; +class ReadingListModelProxy; +class YACReaderReadingListsView; +class YACReaderHistoryController; +class EmptyLabelWidget; +class EmptySpecialListWidget; +class EmptyReadingListWidget; + +#include "comic_db.h" + +using namespace YACReader; + +class LibraryWindow : public QMainWindow +{ + friend class YACReaderNavigationController; + + Q_OBJECT +private: + YACReaderSideBar * sideBar; + + CreateLibraryDialog * createLibraryDialog; + ExportLibraryDialog * exportLibraryDialog; + ImportLibraryDialog * importLibraryDialog; + ExportComicsInfoDialog * exportComicsInfoDialog; + ImportComicsInfoDialog * importComicsInfoDialog; + AddLibraryDialog * addLibraryDialog; + LibraryCreator * libraryCreator; + HelpAboutDialog * had; + RenameLibraryDialog * renameLibraryDialog; + PropertiesDialog * propertiesDialog; + ComicVineDialog * comicVineDialog; + EditShortcutsDialog * editShortcutsDialog; + //YACReaderSocialDialog * socialDialog; + bool fullscreen; + bool importedCovers; //if true, the library is read only (not updates,open comic or properties) + bool fromMaximized; + + PackageManager * packageManager; + + QSize slideSizeW; + QSize slideSizeF; + //search filter +#ifdef Q_OS_MAC + YACReaderMacOSXSearchLineEdit * searchEdit; +#else + YACReaderSearchLineEdit * searchEdit; +#endif + + QString previousFilter; + QCheckBox * includeComicsCheckBox; + //------------- + + YACReaderNavigationController * navigationController; + + ComicsView * comicsView; + ClassicComicsView * classicComicsView; + GridComicsView * gridComicsView; + QStackedWidget * comicsViewStack; + ComicsViewTransition * comicsViewTransition; + EmptyFolderWidget * emptyFolderWidget; + EmptyLabelWidget * emptyLabelWidget; + EmptySpecialListWidget * emptySpecialList; + EmptyReadingListWidget * emptyReadingList; + NoSearchResultsWidget * noSearchResultsWidget; + + YACReaderFoldersView * foldersView; + YACReaderReadingListsView * listsView; + YACReaderLibraryListWidget * selectedLibrary; + FolderModel * foldersModel; + FolderModelProxy * foldersModelProxy; + ComicModel * comicsModel; + ReadingListModel * listsModel; + ReadingListModelProxy * listsModelProxy; + //QStringList paths; + YACReaderLibraries libraries; + + QStackedWidget * mainWidget; + NoLibrariesWidget * noLibrariesWidget; + ImportWidget * importWidget; + + bool fetching; + + int i; + + QAction * backAction; + QAction * forwardAction; + + QAction * openComicAction; + QAction * createLibraryAction; + QAction * openLibraryAction; + + QAction * exportComicsInfoAction; + QAction * importComicsInfoAction; + + QAction * exportLibraryAction; + QAction * importLibraryAction; + + QAction * updateLibraryAction; + QAction * removeLibraryAction; + QAction * helpAboutAction; + QAction * renameLibraryAction; +#ifndef Q_OS_MAC + QAction * toggleFullScreenAction; +#endif + QAction * optionsAction; + QAction * serverConfigAction; + QAction * toggleComicsViewAction; + //QAction * socialAction; + + //tree actions + QAction * addFolderAction; + QAction * deleteFolderAction; + //-- + QAction * setRootIndexAction; + QAction * expandAllNodesAction; + QAction * colapseAllNodesAction; + + QAction * openContainingFolderAction; + QAction * saveCoversToAction; + //-- + QAction * setFolderAsNotCompletedAction; + QAction * setFolderAsCompletedAction; + //-- + QAction * setFolderAsReadAction; + QAction * setFolderAsUnreadAction; + + QAction * openContainingFolderComicAction; + QAction * setAsReadAction; + QAction * setAsNonReadAction; + //QAction * setAllAsReadAction; + //QAction * setAllAsNonReadAction; + QAction * showHideMarksAction; + QAction * getInfoAction; //comic vine + QAction * resetComicRatingAction; + + //edit info actions + QAction * selectAllComicsAction; + QAction * editSelectedComicsAction; + QAction * asignOrderAction; + QAction * forceCoverExtractedAction; + QAction * deleteComicsAction; + QAction * hideComicViewAction; + + QAction *showEditShortcutsAction; + + QAction * updateFolderAction; + QAction * updateCurrentFolderAction; + + //reading lists actions + QAction * addReadingListAction; + QAction * deleteReadingListAction; + QAction * addLabelAction; + QAction * renameListAction; + //-- + QAction * addToMenuAction; + QAction * addToFavoritesAction; + +#ifdef Q_OS_MAC + YACReaderMacOSXToolbar * libraryToolBar; +#else + YACReaderMainToolBar * libraryToolBar; +#endif + QToolBar * treeActions; + QToolBar * comicsToolBar; + QToolBar * editInfoToolBar; + + OptionsDialog * optionsDialog; + ServerConfigDialog * serverConfigDialog; + + QString libraryPath; + QString comicsPath; + + QString _lastAdded; + QString _sourceLastAdded; + + //QModelIndex _rootIndex; + //QModelIndex _rootIndexCV; + //QModelIndex updateDestination; + + quint64 _comicIdEdited; + + enum NavigationStatus + { + Normal, // + Searching + }; + + NavigationStatus status; + + void setupUI(); + void createActions(); + void createToolBars(); + void createMenus(); + void createConnections(); + void doLayout(); + void doDialogs(); + void setUpShortcutsManagement(); + void doModels(); + void disconnectComicsViewConnections(ComicsView * widget); + void doComicsViewConnections(); + + + //ACTIONS MANAGEMENT + void disableComicsActions(bool disabled); + void disableLibrariesActions(bool disabled); + void disableNoUpdatedLibrariesActions(bool disabled); + void disableFoldersActions(bool disabled); + + void disableAllActions(); + //void disableActions(); + //void enableActions(); + //void enableLibraryActions(); + + QString currentPath(); + QString currentFolderPath(); + + //settings + QSettings * settings; + + //navigation backward and forward + YACReaderHistoryController * historyController; + + bool removeError; + + ComicsViewStatus comicsViewStatus; + + //QTBUG-41883 + QSize _size; + QPoint _pos; + +protected: + virtual void closeEvent ( QCloseEvent * event ); +public: + LibraryWindow(); + +public slots: + void loadLibrary(const QString & path); + void selectSubfolder(const QModelIndex & mi, int child); + void checkEmptyFolder(); + void openComic(); + void createLibrary(); + void create(QString source,QString dest, QString name); + void showAddLibrary(); + void openLibrary(QString path, QString name); + void loadLibraries(); + void saveLibraries(); + void reloadCurrentLibrary(); + void openLastCreated(); + void updateLibrary(); + //void deleteLibrary(); + void openContainingFolder(); + void setFolderAsNotCompleted(); + void setFolderAsCompleted(); + void setFolderAsRead(); + void setFolderAsUnread(); + void openContainingFolderComic(); + void deleteCurrentLibrary(); + void removeLibrary(); + void renameLibrary(); + void rename(QString newName); + void cancelCreating(); + void stopLibraryCreator(); + void setRootIndex(); + void toggleFullScreen(); + void toNormal(); + void toFullScreen(); + void setSearchFilter(const YACReader::SearchModifiers modifier, QString filter); + void clearSearchFilter(); + void showProperties(); + void exportLibrary(QString destPath); + void importLibrary(QString clc,QString destPath,QString name); + void reloadOptions(); + void setCurrentComicsStatusReaded(YACReaderComicReadStatus readStatus); + void setCurrentComicReaded(); + void setCurrentComicUnreaded(); + void hideComicFlow(bool hide); + void showExportComicsInfo(); + void showImportComicsInfo(); + void asignNumbers(); + void showNoLibrariesWidget(); + void showRootWidget(); + void showImportingWidget(); + void manageCreatingError(const QString & error); + void manageUpdatingError(const QString & error); + void manageOpeningLibraryError(const QString & error); + QModelIndexList getSelectedComics(); + void deleteComics(); + void deleteComicsFromDisk(); + void deleteComicsFromList(); + //void showSocial(); + void showFoldersContextMenu(const QPoint & point); + void libraryAlreadyExists(const QString & name); + void importLibraryPackage(); + void updateComicsView(quint64 libraryId, const ComicDB & comic); + void setCurrentComicOpened(); + void showComicVineScraper(); + void setRemoveError(); + void checkRemoveError(); + void resetComicRating(); + void switchToComicsView(ComicsView *from, ComicsView *to); + void showComicsViewTransition(); + void toggleComicsView_delayed();//used in orther to avoid flickering; + void showComicsView(); + void showEmptyFolderView(); + void showEmptyLabelView(); + void showEmptySpecialList(); + void showEmptyReadingListWidget(); + void showNoSearchResultsView(); + void toggleComicsView(); + void checkSearchNumResults(int numResults); + void loadCoversFromCurrentModel(); + void copyAndImportComicsToCurrentFolder(const QList > & comics); + void moveAndImportComicsToCurrentFolder(const QList > &comics); + void copyAndImportComicsToFolder(const QList > & comics, const QModelIndex & miFolder); + void moveAndImportComicsToFolder(const QList > & comics, const QModelIndex & miFolder); + void processComicFiles(ComicFilesManager * comicFilesManager, QProgressDialog * progressDialog); + void updateCopyMoveFolderDestination(const QModelIndex & mi); //imports new comics from the current folder + void updateCurrentFolder(); + void updateFolder(const QModelIndex & miFolder); + QProgressDialog * newProgressDialog(const QString & label, int maxValue); + void reloadAfterCopyMove(const QModelIndex &mi); + QModelIndex getCurrentFolderIndex(); + void enableNeededActions(); + void addFolderToCurrentIndex(); + void deleteSelectedFolder(); + void errorDeletingFolder(); + void addNewReadingList(); + void deleteSelectedReadingList(); + void showAddNewLabelDialog(); + void showRenameCurrentList(); + void addSelectedComicsToFavorites(); + void showComicsViewContextMenu(const QPoint & point); + void showComicsItemContextMenu(const QPoint & point); + void setupAddToSubmenu(QMenu & menu); + void onAddComicsToLabel(); + void setToolbarTitle(const QModelIndex & modelIndex); + void saveSelectedCoversTo(); + +}; + +#endif + + + diff --git a/YACReaderLibrary/main.cpp b/YACReaderLibrary/main.cpp new file mode 100644 index 00000000..581fcfc3 --- /dev/null +++ b/YACReaderLibrary/main.cpp @@ -0,0 +1,265 @@ +#include "library_window.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "yacreader_global.h" +#include "startup.h" +#include "yacreader_local_server.h" +#include "comic_db.h" +#include "db_helper.h" +#include "yacreader_libraries.h" +#include "exit_check.h" +#include "opengl_checker.h" + +#include "QsLog.h" +#include "QsLogDest.h" + +#define PICTUREFLOW_QT4 1 + +//interfaz al servidor +Startup * s; + +using namespace QsLogging; + +void logSystemAndConfig() +{ + QLOG_INFO() << "---------- System & configuration ----------"; +#if defined(Q_OS_WIN) + switch (QSysInfo::windowsVersion()) + { + case QSysInfo::WV_NT: + QLOG_INFO() << "SO : Windows NT"; + break; + case QSysInfo::WV_2000: + QLOG_INFO() << "SO : Windows 2000"; + break; + case QSysInfo::WV_XP: + QLOG_INFO() << "SO : Windows XP"; + break; + case QSysInfo::WV_2003: + QLOG_INFO() << "SO : Windows 2003"; + break; + case QSysInfo::WV_VISTA: + QLOG_INFO() << "SO : Windows Vista"; + break; + case QSysInfo::WV_WINDOWS7: + QLOG_INFO() << "SO : Windows 7"; + break; + case QSysInfo::WV_WINDOWS8: + QLOG_INFO() << "SO : Windows 8"; + break; + default: + QLOG_INFO() << "Windows (unknown version)"; + break; + } + +#elif defined(Q_OS_MAC) + + switch (QSysInfo::MacVersion()) + { + case QSysInfo::MV_SNOWLEOPARD: + QLOG_INFO() << "SO : MacOSX Snow Leopard"; + break; + case QSysInfo::MV_LION: + QLOG_INFO() << "SO : MacOSX Lion"; + break; + case QSysInfo::MV_MOUNTAINLION: + QLOG_INFO() << "SO : MacOSX Mountain Lion"; + break; +#if QT_VERSION >= 0x050000 + case QSysInfo::MV_MAVERICKS: + QLOG_INFO() << "SO : MacOSX Maverics"; + break; +#endif + default: + QLOG_INFO() << "SO : MacOSX (unknown version)"; + break; + } + +#elif defined(Q_OS_LINUX) + QLOG_INFO() << "SO : Linux (unknown version)"; + +#else + QLOG_INFO() << "SO : Unknown"; +#endif + +#ifndef use_unarr +#ifdef Q_OS_WIN + if(QLibrary::isLibrary(QApplication::applicationDirPath()+"/utils/7z.dll")) +#elif defined Q_OS_UNIX && !defined Q_OS_MAC + if(QLibrary::isLibrary(QString(LIBDIR)+"/yacreader/7z.so") | QLibrary::isLibrary(QString(LIBDIR)+"/p7zip/7z.so")) +#else + if(QLibrary::isLibrary(QApplication::applicationDirPath()+"/utils/7z.so")) +#endif + QLOG_INFO() << "7z : found"; + else + QLOG_ERROR() << "7z : not found"; +#else + QLOG_INFO() << "using unarr decompression backend"; +#endif +#if defined Q_OS_UNIX && !defined Q_OS_MAC + if(QFileInfo(QString(BINDIR)+"/qrencode").exists()) +#else + if(QFileInfo(QApplication::applicationDirPath()+"/utils/qrencode.exe").exists() || QFileInfo("./util/qrencode").exists()) +#endif + QLOG_INFO() << "qrencode : found"; + else + QLOG_INFO() << "qrencode : not found"; + + QSettings settings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); + settings.beginGroup("libraryConfig"); + if(settings.value(SERVER_ON,true).toBool()) + QLOG_INFO() << "server : enabled"; + else + QLOG_INFO() << "server : disabled"; + + if(settings.value(USE_OPEN_GL).toBool()) + QLOG_INFO() << "OpenGL : enabled" << " - " << (settings.value(V_SYNC).toBool()?"VSync on":"VSync off"); + else + QLOG_INFO() << "OpenGL : disabled"; + + OpenGLChecker checker; + QLOG_INFO() << "OpenGL version : " << checker.textVersionDescription(); + + QLOG_INFO() << "Libraries: " << DBHelper::getLibraries().getLibraries(); + QLOG_INFO() << "--------------------------------------------"; +} + +int main( int argc, char ** argv ) +{ + +//fix for misplaced text in Qt4.8 and Mavericks +#ifdef Q_OS_MAC + #if QT_VERSION < 0x050000 + if(QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) + QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); + #endif + +#endif + + QApplication app( argc, argv ); + +#ifdef FORCE_ANGLE + app.setAttribute(Qt::AA_UseOpenGLES); +#endif + + app.setApplicationName("YACReaderLibrary"); + app.setOrganizationName("YACReader"); + app.setAttribute(Qt::AA_UseHighDpiPixmaps); +//simple command line parser +//will be replaced by QCommandLineParser in the future +//TODO: --headless, --server=[on|off], support for file and directory arguments + if (argc > 1) + { + QTextStream parser(stdout); + QStringList optlist = QCoreApplication::arguments().filter(QRegExp ("^-{1,2}")); + if (optlist.contains("--version") || optlist.contains("-v")) + { + parser << app.applicationName() << " " << QString(VERSION) << endl << "Copyright 2014 by Luis Angel San Martin Rodriguez" << endl; + return 0; + } + if (optlist.contains("--help") || optlist.contains("-h")) + { + parser << endl << "Usage:" << "\tYACReaderLibrary [Option]" << endl << endl; + parser << "Options:" << endl; + parser << " none\t\t\tStart YACReaderLibrary" << endl; + parser << " -h, --help\t\tDisplay help text and exit." << endl; + parser << " -v, --version\t\tDisplay version information and exit." << endl; + return 0; + } + parser << "Unsupported command line options. See YACReaderLibrary --help for further information." << endl; + return 0; + } + + QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log"; + QDir().mkpath(YACReader::getSettingsPath()); + + Logger& logger = Logger::instance(); + logger.setLoggingLevel(QsLogging::TraceLevel); + + DestinationPtr fileDestination(DestinationFactory::MakeFileDestination( + destLog, EnableLogRotation, MaxSizeBytes(1048576), MaxOldLogCount(2))); + DestinationPtr debugDestination(DestinationFactory::MakeDebugOutputDestination()); + logger.addDestination(debugDestination); + logger.addDestination(fileDestination); + + QTranslator translator; + QString sufix = QLocale::system().name(); +#if defined Q_OS_UNIX && !defined Q_OS_MAC + translator.load(QString(DATADIR)+"/yacreader/languages/yacreaderlibrary_"+sufix); +#else + translator.load(QCoreApplication::applicationDirPath()+"/languages/yacreaderlibrary_"+sufix); +#endif + app.installTranslator(&translator); + + QTranslator viewerTranslator; +#if defined Q_OS_UNIX && !defined Q_OS_MAC + viewerTranslator.load(QString(DATADIR)+"/yacreader/languages/yacreader_"+sufix); +#else + viewerTranslator.load(QCoreApplication::applicationDirPath()+"/languages/yacreader_"+sufix); +#endif + app.installTranslator(&viewerTranslator); + app.setApplicationName("YACReaderLibrary"); + + qRegisterMetaType("ComicDB"); + +#ifdef SERVER_RELEASE + QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci�n del fichero de config con el servidor + settings->beginGroup("libraryConfig"); + + s = new Startup(); + + if(settings->value(SERVER_ON,true).toBool()) + { + s->start(); + } +#endif + QLOG_INFO() << "YACReaderLibrary attempting to start"; + + logSystemAndConfig(); + + if(YACReaderLocalServer::isRunning()) //s�lo se permite una instancia de YACReaderLibrary + { + QLOG_WARN() << "another instance of YACReaderLibrary is running"; + QsLogging::Logger::destroyInstance(); + return 0; + } + QLOG_INFO() << "YACReaderLibrary starting"; + + YACReaderLocalServer * localServer = new YACReaderLocalServer(); + + LibraryWindow * mw = new LibraryWindow(); + + mw->connect(localServer,SIGNAL(comicUpdated(quint64, const ComicDB &)),mw,SLOT(updateComicsView(quint64, const ComicDB &))); + + //connections to localServer + + mw->show(); + + int ret = app.exec(); + + QLOG_INFO() << "YACReaderLibrary closed with exit code :" << ret; + + YACReader::exitCheck(ret); + + //shutdown + s->stop(); + delete s; + localServer->close(); + delete localServer; + delete mw; + + QsLogging::Logger::destroyInstance(); + + return ret; +} diff --git a/YACReaderLibrary/no_libraries_widget.cpp b/YACReaderLibrary/no_libraries_widget.cpp new file mode 100644 index 00000000..21dfb166 --- /dev/null +++ b/YACReaderLibrary/no_libraries_widget.cpp @@ -0,0 +1,80 @@ +#include "no_libraries_widget.h" + +#include +#include +#include +#include + +NoLibrariesWidget::NoLibrariesWidget(QWidget *parent) : + QWidget(parent) +{ + setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); + + QPalette p(palette()); + p.setColor(QPalette::Background, QColor(250,250,250)); + setAutoFillBackground(true); + setPalette(p); + + QPixmap icon(":/images/noLibrariesIcon.png"); + QLabel * iconLabel = new QLabel(); + iconLabel->setPixmap(icon); + + QPixmap line(":/images/noLibrariesLine.png"); + QLabel * lineLabel = new QLabel(); + lineLabel->setPixmap(line); + + QLabel * text = new QLabel(""+tr("You don't have any librarires yet")+""); + text->setStyleSheet("QLabel {font-size:25px;font-weight:bold;}"); + QLabel * textDescription = new QLabel(""+tr("

You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.

Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.

")+"
"); + textDescription->setWordWrap(true); + textDescription->setMaximumWidth(330); + + QPushButton * createButton = new QPushButton(tr("create your first library")); + createButton->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); + QPushButton * addButton = new QPushButton(tr("add an existing one")); + addButton->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); + + QVBoxLayout * layout = new QVBoxLayout(this); + QHBoxLayout * buttonLayout = new QHBoxLayout(); + QHBoxLayout * topLayout = new QHBoxLayout(); + QVBoxLayout * textLayout = new QVBoxLayout(); + + QWidget * topWidget = new QWidget(); + topWidget->setFixedWidth(650); + textLayout->addStretch(); + textLayout->addWidget(text); + textLayout->addSpacing(12); + textLayout->addWidget(textDescription); + textLayout->addStretch(); + + topLayout->addStretch(); + topLayout->addWidget(iconLabel,0,Qt::AlignVCenter); + topLayout->addSpacing(30); + topLayout->addLayout(textLayout,1); + topLayout->addStretch(); + topLayout->setMargin(0); + + topWidget->setLayout(topLayout); + + layout->setAlignment(Qt::AlignHCenter); + + buttonLayout->addSpacing(125); + buttonLayout->addWidget(createButton); + layout->addSpacing(25); + buttonLayout->addWidget(addButton); + buttonLayout->addSpacing(125); + + layout->addStretch(); + layout->addWidget(topWidget); + layout->addSpacing(20); + layout->addWidget(lineLabel,0,Qt::AlignHCenter); + layout->addSpacing(10); + layout->addLayout(buttonLayout,0); + layout->addSpacing(150); + layout->addStretch(); + + connect(createButton,SIGNAL(clicked()),this,SIGNAL(createNewLibrary())); + connect(addButton,SIGNAL(clicked()),this,SIGNAL(addExistingLibrary())); + + +} diff --git a/YACReaderLibrary/no_libraries_widget.h b/YACReaderLibrary/no_libraries_widget.h new file mode 100644 index 00000000..c522944b --- /dev/null +++ b/YACReaderLibrary/no_libraries_widget.h @@ -0,0 +1,19 @@ +#ifndef NO_LIBRARIES_WIDGET_H +#define NO_LIBRARIES_WIDGET_H + +#include + +class NoLibrariesWidget : public QWidget +{ + Q_OBJECT +public: + explicit NoLibrariesWidget(QWidget *parent = 0); + +signals: + void createNewLibrary(); + void addExistingLibrary(); +public slots: + +}; + +#endif // NO_LIBRARIES_WIDGET_H diff --git a/YACReaderLibrary/no_search_results_widget.cpp b/YACReaderLibrary/no_search_results_widget.cpp new file mode 100644 index 00000000..38b181a4 --- /dev/null +++ b/YACReaderLibrary/no_search_results_widget.cpp @@ -0,0 +1,51 @@ +#include "no_search_results_widget.h" + +#include +#include +#include + +NoSearchResultsWidget::NoSearchResultsWidget(QWidget *parent) : + QWidget(parent) +{ +#ifdef Q_OS_MAC + backgroundColor = "#FFFFFF"; +#else + backgroundColor = "#2A2A2A"; +#endif + + QVBoxLayout * layout = new QVBoxLayout; + + iconLabel = new QLabel(); + iconLabel->setPixmap(QPixmap(":/images/empty_search.png")); + iconLabel->setAlignment(Qt::AlignCenter); + + titleLabel = new QLabel("No results"); + titleLabel->setAlignment(Qt::AlignCenter); + +#ifdef Q_OS_MAC + titleLabel->setStyleSheet("QLabel {color:#888888; font-size:24px;font-family:Arial;font-weight:bold;}"); +#else + titleLabel->setStyleSheet("QLabel {color:#CCCCCC; font-size:24px;font-family:Arial;font-weight:bold;}"); +#endif + + layout->addSpacing(100); + layout->addWidget(iconLabel); + layout->addSpacing(30); + layout->addWidget(titleLabel); + layout->addStretch(); + layout->setMargin(0); + layout->setSpacing(0); + + setContentsMargins(0,0,0,0); + + setStyleSheet(QString("QWidget {background:%1}").arg(backgroundColor)); + + setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding ); + setLayout(layout); +} + +void NoSearchResultsWidget::paintEvent(QPaintEvent *) +{ + QPainter painter (this); + painter.fillRect(0,0,width(),height(),QColor(backgroundColor)); +} diff --git a/YACReaderLibrary/no_search_results_widget.h b/YACReaderLibrary/no_search_results_widget.h new file mode 100644 index 00000000..0cad18fe --- /dev/null +++ b/YACReaderLibrary/no_search_results_widget.h @@ -0,0 +1,26 @@ +#ifndef NO_SEARCH_RESULTS_WIDGET_H +#define NO_SEARCH_RESULTS_WIDGET_H + +#include + +class QLabel; + +class NoSearchResultsWidget : public QWidget +{ + Q_OBJECT +public: + explicit NoSearchResultsWidget(QWidget *parent = 0); + +signals: + +public slots: + +protected: + QLabel * iconLabel; + QLabel * titleLabel; + void paintEvent(QPaintEvent *); + QString backgroundColor; + +}; + +#endif // NO_SEARCH_RESULTS_WIDGET_H diff --git a/YACReaderLibrary/options_dialog.cpp b/YACReaderLibrary/options_dialog.cpp new file mode 100644 index 00000000..6073347f --- /dev/null +++ b/YACReaderLibrary/options_dialog.cpp @@ -0,0 +1,95 @@ +#include "options_dialog.h" + +#ifndef NO_OPENGL +#include "yacreader_flow_gl.h" +#include "yacreader_gl_flow_config_widget.h" +#endif +#include "yacreader_flow_config_widget.h" +#include "api_key_dialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +FlowType flowType = Strip; + +OptionsDialog::OptionsDialog(QWidget * parent) +:YACReaderOptionsDialog(parent) +{ + QTabWidget * tabWidget = new QTabWidget(); + + QVBoxLayout * layout = new QVBoxLayout(this); + + QVBoxLayout * flowLayout = new QVBoxLayout; + QVBoxLayout * generalLayout = new QVBoxLayout(); + + QHBoxLayout * switchFlowType = new QHBoxLayout(); + switchFlowType->addStretch(); +#ifndef NO_OPENGL + switchFlowType->addWidget(useGL); +#endif + QHBoxLayout * buttons = new QHBoxLayout(); + buttons->addStretch(); + buttons->addWidget(accept); + buttons->addWidget(cancel); + + flowLayout->addWidget(sw); +#ifndef NO_OPENGL + flowLayout->addWidget(gl); +#endif + flowLayout->addLayout(switchFlowType); + +#ifndef NO_OPENGL + sw->hide(); +#endif + + QVBoxLayout * apiKeyLayout = new QVBoxLayout(); + QPushButton * apiKeyButton = new QPushButton(tr("Edit Comic Vine API key")); + apiKeyLayout->addWidget(apiKeyButton); + + QGroupBox * apiKeyBox = new QGroupBox(tr("Comic Vine API key")); + apiKeyBox->setLayout(apiKeyLayout); + + connect(apiKeyButton,SIGNAL(clicked()),this,SLOT(editApiKey())); + + QWidget * comicFlowW = new QWidget; + comicFlowW->setLayout(flowLayout); + + QWidget * generalW = new QWidget; + generalW->setLayout(generalLayout); + generalLayout->addWidget(shortcutsBox); + generalLayout->addWidget(apiKeyBox); + generalLayout->addStretch(); + + tabWidget->addTab(comicFlowW,tr("Comic Flow")); + tabWidget->addTab(generalW,tr("General")); + + layout->addWidget(tabWidget); + layout->addLayout(buttons); + setLayout(layout); + //restoreOptions(settings); //load options + //resize(200,0); + setModal (true); + setWindowTitle(tr("Options")); + + this->layout()->setSizeConstraint(QLayout::SetFixedSize); + +} + +void OptionsDialog::editApiKey() +{ + ApiKeyDialog d; + d.exec(); +} + + + diff --git a/YACReaderLibrary/options_dialog.h b/YACReaderLibrary/options_dialog.h new file mode 100644 index 00000000..9a2ca1bc --- /dev/null +++ b/YACReaderLibrary/options_dialog.h @@ -0,0 +1,21 @@ +#ifndef __OPTIONS_DIALOG_H +#define __OPTIONS_DIALOG_H + +#include "yacreader_options_dialog.h" + +#include "yacreader_global.h" + +using namespace YACReader; + +class OptionsDialog : public YACReaderOptionsDialog +{ +Q_OBJECT + public: + OptionsDialog(QWidget * parent = 0); + + public slots: + void editApiKey(); +}; + + +#endif diff --git a/YACReaderLibrary/package_manager.cpp b/YACReaderLibrary/package_manager.cpp new file mode 100644 index 00000000..d5f21ef9 --- /dev/null +++ b/YACReaderLibrary/package_manager.cpp @@ -0,0 +1,55 @@ +#include "package_manager.h" +#include + +PackageManager::PackageManager() +:_7z(0) +{ + +} + +void PackageManager::createPackage(const QString & libraryPath,const QString & dest) +{ + QStringList attributes; + attributes << "a" << "-y" << "-ttar" << dest+".clc" << libraryPath ; + _7z = new QProcess(); + connect(_7z,SIGNAL(error(QProcess::ProcessError)),this,SLOT(openingError(QProcess::ProcessError))); + connect(_7z,SIGNAL(finished(int,QProcess::ExitStatus)),this,SIGNAL(exported())); +#if defined Q_OS_UNIX && !defined Q_OS_MAC + _7z->start("7z",attributes); //TODO: use 7z.so +#else + _7z->start(QCoreApplication::applicationDirPath()+"/utils/7zip",attributes); //TODO: use 7z.dll +#endif +} + +void PackageManager::extractPackage(const QString & packagePath,const QString & destDir) +{ + QStringList attributes; + QString output = "-o"; + output += destDir; + attributes << "x" << "-y" << output << packagePath; + _7z = new QProcess(); + connect(_7z,SIGNAL(error(QProcess::ProcessError)),this,SLOT(openingError(QProcess::ProcessError))); + connect(_7z,SIGNAL(finished(int,QProcess::ExitStatus)),this,SIGNAL(imported())); +#if defined Q_OS_UNIX && !defined Q_OS_MAC + _7z->start("7z",attributes); //TODO: use 7z.so +#else + _7z->start(QCoreApplication::applicationDirPath()+"/utils/7zip",attributes); //TODO: use 7z.dll +#endif +} + +void PackageManager::cancel() +{ + if(_7z!=0) + { + _7z->disconnect(); + _7z->kill(); + if(creating) + { + //TODO remove dest+".clc" + } + else + { + //TODO fixed: is done by libraryWindow + } + } +} diff --git a/YACReaderLibrary/package_manager.h b/YACReaderLibrary/package_manager.h new file mode 100644 index 00000000..235651ef --- /dev/null +++ b/YACReaderLibrary/package_manager.h @@ -0,0 +1,24 @@ +#ifndef PACKAGE_MANAGER_H +#define PACKAGE_MANAGER_H + +#include + +class PackageManager : public QObject +{ + Q_OBJECT +public: + PackageManager(); + void createPackage(const QString & libraryPath,const QString & dest); + void extractPackage(const QString & packagePath,const QString & destDir); + public slots: + void cancel(); +private: + bool creating; + QProcess * _7z; + +signals: + void exported(); + void imported(); +}; + +#endif diff --git a/YACReaderLibrary/properties_dialog.cpp b/YACReaderLibrary/properties_dialog.cpp new file mode 100644 index 00000000..8101c2a6 --- /dev/null +++ b/YACReaderLibrary/properties_dialog.cpp @@ -0,0 +1,896 @@ +#include "properties_dialog.h" + +#include "data_base_management.h" +#include "library_creator.h" +#include "yacreader_field_edit.h" +#include "yacreader_field_plain_text_edit.h" +#include "db_helper.h" +//#include "yacreader_busy_widget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +PropertiesDialog::PropertiesDialog(QWidget * parent) +:QDialog(parent) +{ + + createCoverBox(); + createGeneralInfoBox(); + createAuthorsBox(); + createPublishingBox(); + createButtonBox(); + createPlotBox(); + + createTabBar(); + + mainLayout = new QGridLayout; + //mainLayout->addWidget(coverBox,0,0); + mainLayout->addWidget(tabBar,0,1); + mainLayout->setColumnStretch(1,1); + /*mainLayout->addWidget(authorsBox,1,1); + mainLayout->addWidget(publishingBox,2,1);*/ + mainLayout->addWidget(buttonBox,1,1,Qt::AlignBottom); + + mainWidget = new QWidget(this); + mainWidget->setAutoFillBackground(true); + mainWidget->setFixedSize(470,444); + mainWidget->setLayout(mainLayout); + mainLayout->setSizeConstraint(QLayout::SetMinimumSize); + + int heightDesktopResolution = QApplication::desktop()->screenGeometry().height(); + int widthDesktopResolution = QApplication::desktop()->screenGeometry().width(); + int sHeight,sWidth; + sHeight = static_cast(heightDesktopResolution*0.65); + sWidth = static_cast(sHeight*1.4); + //setCover(QPixmap(":/images/notCover.png")); + + this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2)); + setModal(true); + + setFixedSize( sizeHint() ); + mainWidget->move(280,0); +} + +QSize PropertiesDialog::sizeHint() +{ + return QSize(750,444); +} + +void PropertiesDialog::createTabBar() +{ + tabBar = new QTabWidget; + tabBar->addTab(generalInfoBox,tr("General info")); + tabBar->addTab(authorsBox,tr("Authors")); + tabBar->addTab(publishingBox,tr("Publishing")); + tabBar->addTab(plotBox,tr("Plot")); +} + +void PropertiesDialog::createCoverBox() +{ + coverBox = new QWidget(this); + + QHBoxLayout * layout = new QHBoxLayout; + + QLabel * label = new QLabel(tr("Cover page")); + label->setStyleSheet("QLabel {color: white; font-weight:bold; font-size:14px;}"); + layout->addWidget(label); + layout->addStretch(); + + coverPageEdit = new YACReaderFieldEdit(); + + showPreviousCoverPageButton = new QToolButton(); + showPreviousCoverPageButton->setIcon(QIcon(":/images/previousCoverPage.png")); + showPreviousCoverPageButton->setStyleSheet("QToolButton {border:none;}"); + showNextCoverPageButton = new QToolButton(); + showNextCoverPageButton->setIcon(QIcon(":/images/nextCoverPage.png")); + showNextCoverPageButton->setStyleSheet("QToolButton {border:none;}"); + + coverPageNumberLabel = new QLabel("-"); + + coverPageNumberLabel->setStyleSheet("QLabel {color: white; font-weight:bold; font-size:14px;}"); + + layout->addWidget(showPreviousCoverPageButton); + layout->addSpacing(5); + layout->addWidget(coverPageNumberLabel); + layout->addSpacing(5); + layout->addWidget(showNextCoverPageButton); + + coverPageEdit->setStyleSheet("QLineEdit {border:none;}"); + layout->setSpacing(0); + + coverBox->setLayout(layout); + + coverBox->setFixedWidth(280); + coverBox->move(0,444-28); + layout->setContentsMargins(5,4,5,0); + + //busyIndicator = new YACReaderBusyWidget(this); + //busyIndicator->move((280-busyIndicator->width())/2,(444-busyIndicator->height()-28)/2); + //busyIndicator->hide(); + + connect(showPreviousCoverPageButton,SIGNAL(clicked()),this,SLOT(loadPreviousCover())); + connect(showNextCoverPageButton,SIGNAL(clicked()),this,SLOT(loadNextCover())); + +} + +QFrame * createLine() +{ + QFrame * line = new QFrame(); + line->setObjectName(QString::fromUtf8("line")); + //line->setGeometry(QRect(320, 150, 118, 3)); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + + return line; +} + +void PropertiesDialog::createGeneralInfoBox() +{ + generalInfoBox = new QWidget; + + QFormLayout *generalInfoLayout = new QFormLayout; + + generalInfoLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); + //generalInfoLayout->setRowWrapPolicy(QFormLayout::WrapAllRows); + generalInfoLayout->addRow(tr("Title:"), title = new YACReaderFieldEdit()); + + + QHBoxLayout * number = new QHBoxLayout; + number->addWidget(numberEdit = new YACReaderFieldEdit()); + numberValidator.setBottom(0); + numberEdit->setValidator(&numberValidator); + number->addWidget(new QLabel("Bis:")); + number->addWidget(isBisCheck = new QCheckBox()); + number->addWidget(new QLabel("of:")); + number->addWidget(countEdit = new YACReaderFieldEdit()); + countValidator.setBottom(0); + countEdit->setValidator(&countValidator); + number->addStretch(1); + /*generalInfoLayout->addRow(tr("&Issue number:"), ); + generalInfoLayout->addRow(tr("&Bis:"), );*/ + generalInfoLayout->addRow(tr("Issue number:"), number); + + generalInfoLayout->addRow(tr("Volume:"), volumeEdit = new YACReaderFieldEdit()); + + QHBoxLayout * arc = new QHBoxLayout; + arc->addWidget(storyArcEdit = new YACReaderFieldEdit()); + arc->addWidget(new QLabel("Arc number:")); + arc->addWidget(arcNumberEdit = new YACReaderFieldEdit()); + arcNumberValidator.setBottom(0); + arcNumberEdit->setValidator(&arcNumberValidator); + arc->addWidget(new QLabel("of:")); + arc->addWidget(arcCountEdit = new YACReaderFieldEdit()); + arcCountValidator.setBottom(0); + arcCountEdit->setValidator(&arcCountValidator); + arc->addStretch(1); + generalInfoLayout->addRow(tr("Story arc:"), arc); + + generalInfoLayout->addRow(tr("Genere:"), genereEdit = new YACReaderFieldEdit()); + + generalInfoLayout->addRow(tr("Size:"), size = new QLabel("size")); + + //generalInfoLayout->addRow(tr("Comic Vine link:"), comicVineLink = new QLabel("...")); + //generalInfoLayout->addRow(bottom); + + QVBoxLayout * main = new QVBoxLayout; + main->addLayout(generalInfoLayout); + main->addStretch(); + main->addWidget(comicVineLink = new QLabel("Comic Vine link : ...")); + comicVineLink->setOpenExternalLinks(true); + + generalInfoBox->setLayout(main); +} + +void PropertiesDialog::createAuthorsBox() +{ + authorsBox = new QWidget; + + QVBoxLayout *authorsLayout = new QVBoxLayout; + + //authorsLayout->setRowWrapPolicy(QFormLayout::WrapAllRows); + QHBoxLayout * h1 = new QHBoxLayout; + QVBoxLayout * vl1 = new QVBoxLayout; + QVBoxLayout * vr1 = new QVBoxLayout; + vl1->addWidget(new QLabel(tr("Writer(s):"))); + vl1->addWidget(writer = new YACReaderFieldPlainTextEdit()); + h1->addLayout(vl1); + vr1->addWidget(new QLabel(tr("Penciller(s):"))); + vr1->addWidget(penciller = new YACReaderFieldPlainTextEdit()); + h1->addLayout(vr1); + //authorsLayout->addRow(tr("Writer(s):"), new YACReaderFieldPlainTextEdit()); + //authorsLayout->addRow(tr("Penciller(s):"), new YACReaderFieldPlainTextEdit()); + QHBoxLayout * h2 = new QHBoxLayout; + QVBoxLayout * vl2 = new QVBoxLayout; + QVBoxLayout * vr2 = new QVBoxLayout; + vl2->addWidget(new QLabel(tr("Inker(s):"))); + vl2->addWidget(inker = new YACReaderFieldPlainTextEdit()); + h2->addLayout(vl2); + vr2->addWidget(new QLabel(tr("Colorist(s):"))); + vr2->addWidget(colorist = new YACReaderFieldPlainTextEdit()); + h2->addLayout(vr2); + + //authorsLayout->addRow(tr("Inker(s):"), new YACReaderFieldPlainTextEdit()); + //authorsLayout->addRow(tr("Colorist(s):"), new YACReaderFieldPlainTextEdit()); + + QHBoxLayout * h3 = new QHBoxLayout; + QVBoxLayout * vl3 = new QVBoxLayout; + QVBoxLayout * vr3 = new QVBoxLayout; + vl3->addWidget(new QLabel(tr("Letterer(s):"))); + vl3->addWidget(letterer = new YACReaderFieldPlainTextEdit()); + h3->addLayout(vl3); + vr3->addWidget(new QLabel(tr("Cover Artist(s):"))); + vr3->addWidget(coverArtist = new YACReaderFieldPlainTextEdit()); + h3->addLayout(vr3); + //authorsLayout->addRow(tr("Letterer(es):"), new YACReaderFieldPlainTextEdit()); + //authorsLayout->addRow(tr("Cover Artist(s):"), new YACReaderFieldPlainTextEdit()); + + authorsLayout->addLayout(h1); + authorsLayout->addLayout(h2); + authorsLayout->addLayout(h3); + authorsLayout->addStretch(1); + authorsBox->setLayout(authorsLayout); + +} + +void PropertiesDialog::createPublishingBox() +{ + publishingBox = new QWidget; + + QFormLayout *publishingLayout = new QFormLayout; + + publishingLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); + + QHBoxLayout * date = new QHBoxLayout; + date->addWidget(new QLabel(tr("Day:"))); + date->addWidget(dayEdit = new YACReaderFieldEdit()); + dayValidator.setRange(1,31); + dayEdit->setValidator(&dayValidator); + date->addWidget(new QLabel(tr("Month:"))); + date->addWidget(monthEdit = new YACReaderFieldEdit()); + monthValidator.setRange(1,12); + monthEdit->setValidator(&monthValidator); + date->addWidget(new QLabel(tr("Year:"))); + date->addWidget(yearEdit = new YACReaderFieldEdit()); + yearValidator.setRange(1,9999); + yearEdit->setValidator(&yearValidator); + date->addStretch(1); + + publishingLayout->setRowWrapPolicy(QFormLayout::WrapAllRows); + publishingLayout->addRow(date); + publishingLayout->addRow(tr("Publisher:"), publisherEdit = new YACReaderFieldEdit()); + publishingLayout->addRow(tr("Format:"), formatEdit = new YACReaderFieldEdit()); + publishingLayout->addRow(tr("Color/BW:"), colorCheck = new QCheckBox()); + publishingLayout->addRow(tr("Age rating:"), ageRatingEdit = new YACReaderFieldEdit()); + + publishingBox->setLayout(publishingLayout); +} + +void PropertiesDialog::createPlotBox() +{ + plotBox = new QWidget; + + QFormLayout *plotLayout = new QFormLayout; + plotLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); + + plotLayout->setRowWrapPolicy(QFormLayout::WrapAllRows); + plotLayout->addRow(tr("Synopsis:"), synopsis = new YACReaderFieldPlainTextEdit()); + plotLayout->addRow(tr("Characters:"), characters = new YACReaderFieldPlainTextEdit()); + plotLayout->addRow(tr("Notes:"), notes = new YACReaderFieldPlainTextEdit()); + + plotBox->setLayout(plotLayout); + +} + +void PropertiesDialog::createButtonBox() +{ + buttonBox = new QDialogButtonBox; + + closeButton = buttonBox->addButton(QDialogButtonBox::Close); + saveButton = buttonBox->addButton(QDialogButtonBox::Save); + //rotateWidgetsButton = buttonBox->addButton(tr("Rotate &Widgets"),QDialogButtonBox::ActionRole); + + //connect(rotateWidgetsButton, SIGNAL(clicked()), this, SLOT(rotateWidgets())); + connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); + connect(saveButton, SIGNAL(clicked()), this, SLOT(save())); +} + +QImage blurred(const QImage& image, const QRect& rect, int radius, bool alphaOnly = false) +{ + int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 }; + int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1]; + + QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + int r1 = rect.top(); + int r2 = rect.bottom(); + int c1 = rect.left(); + int c2 = rect.right(); + + int bpl = result.bytesPerLine(); + int rgba[4]; + unsigned char* p; + + int i1 = 0; + int i2 = 3; + + if (alphaOnly) + i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3); + + for (int col = c1; col <= c2; col++) { + p = result.scanLine(r1) + col * 4; + for (int i = i1; i <= i2; i++) + rgba[i] = p[i] << 4; + + p += bpl; + for (int j = r1; j < r2; j++, p += bpl) + for (int i = i1; i <= i2; i++) + p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4; + } + + for (int row = r1; row <= r2; row++) { + p = result.scanLine(row) + c1 * 4; + for (int i = i1; i <= i2; i++) + rgba[i] = p[i] << 4; + + p += 4; + for (int j = c1; j < c2; j++, p += 4) + for (int i = i1; i <= i2; i++) + p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4; + } + + for (int col = c1; col <= c2; col++) { + p = result.scanLine(r2) + col * 4; + for (int i = i1; i <= i2; i++) + rgba[i] = p[i] << 4; + + p -= bpl; + for (int j = r1; j < r2; j++, p -= bpl) + for (int i = i1; i <= i2; i++) + p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4; + } + + for (int row = r1; row <= r2; row++) { + p = result.scanLine(row) + c2 * 4; + for (int i = i1; i <= i2; i++) + rgba[i] = p[i] << 4; + + p -= 4; + for (int j = c1; j < c2; j++, p -= 4) + for (int i = i1; i <= i2; i++) + p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4; + } + + return result; +} + +void PropertiesDialog::setComics(QList comics) +{ + this->comics = comics; + + ComicDB comic = comics.at(0); + + if(!comic.info.title.isNull()) + title->setText(comic.info.title.toString()); + if(!comic.info.comicVineID.isNull()) + { + comicVineLink->setHidden(false); + comicVineLink->setText(QString(tr("Comic Vine link: view ").arg(comic.info.comicVineID.toString()))); + } + else + comicVineLink->setHidden(true); + + if(comics.length()==1 && !comic.info.coverPage.isNull()) + { + coverPageEdit->setText(comic.info.coverPage.toString()); + coverPageValidator.setRange(1,comic.info.numPages.toInt()); + coverPageEdit->setValidator(&coverPageValidator); + //---------- + int coverPage = comic.info.coverPage.toInt(); + coverPageNumberLabel->setText(QString::number(coverPage)); + coverPageNumberLabel->adjustSize(); + + showPreviousCoverPageButton->setEnabled(true); + showNextCoverPageButton->setEnabled(true); + + if(coverPage == 1) + showPreviousCoverPageButton->setDisabled(true); + if(coverPage == comic.info.numPages.toInt()) + showNextCoverPageButton->setDisabled(true); + + coverChanged = false; + coverBox->show(); + + if(!QFileInfo(basePath+comics[0].path).exists()) + { + QMessageBox::warning(this,tr("Not found"),tr("Comic not found. You should update your library.")); + showPreviousCoverPageButton->setDisabled(true); + showNextCoverPageButton->setDisabled(true); + } + } + /*if(comic.info.numPages != NULL) + numPagesEdit->setText(QString::number(*comic.info.numPages));*/ + + + if(!comic.info.number.isNull()) + numberEdit->setText(comic.info.number.toString()); + if(!comic.info.isBis.isNull()) + isBisCheck->setChecked(comic.info.isBis.toBool()); + if(!comic.info.count.isNull()) + countEdit->setText(comic.info.count.toString()); + + if(!comic.info.volume.isNull()) + volumeEdit->setText(comic.info.volume.toString()); + if(!comic.info.storyArc.isNull()) + storyArcEdit->setText(comic.info.storyArc.toString()); + if(!comic.info.arcNumber.isNull()) + arcNumberEdit->setText(comic.info.arcNumber.toString()); + if(!comic.info.arcCount.isNull()) + arcCountEdit->setText(comic.info.arcCount.toString()); + + if(!comic.info.genere.isNull()) + genereEdit->setText(comic.info.genere.toString()); + + if(!comic.info.writer.isNull()) + writer->setPlainText(comic.info.writer.toString()); + if(!comic.info.penciller.isNull()) + penciller->setPlainText(comic.info.penciller.toString()); + if(!comic.info.inker.isNull()) + inker->setPlainText(comic.info.inker.toString()); + if(!comic.info.colorist.isNull()) + colorist->setPlainText(comic.info.colorist.toString()); + if(!comic.info.letterer.isNull()) + letterer->setPlainText(comic.info.letterer.toString()); + if(!comic.info.coverArtist.isNull()) + coverArtist->setPlainText(comic.info.coverArtist.toString()); + + size->setText(QString::number(comic.info.hash.right(comic.info.hash.length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb"); + + if(!comic.info.date.isNull()) + { + QStringList date = (comic.info.date.toString()).split("/"); + dayEdit->setText(date[0]); + monthEdit->setText(date[1]); + yearEdit->setText(date[2]); + } + if(!comic.info.publisher.isNull()) + publisherEdit->setText(comic.info.publisher.toString()); + if(!comic.info.format.isNull()) + formatEdit->setText(comic.info.format.toString()); + if(!comic.info.color.isNull()) + colorCheck->setChecked(comic.info.color.toBool()); + else + colorCheck->setCheckState(Qt::PartiallyChecked); + + if(!comic.info.ageRating.isNull()) + ageRatingEdit->setText(comic.info.ageRating.toString()); + + if(!comic.info.synopsis.isNull()) + synopsis->setPlainText(comic.info.synopsis.toString()); + if(!comic.info.characters.isNull()) + characters->setPlainText(comic.info.characters.toString()); + if(!comic.info.notes.isNull()) + notes->setPlainText(comic.info.notes.toString()); + + + if(comics.length() > 1) + { + coverBox->hide(); + + setDisableUniqueValues(true); + this->setWindowTitle(tr("Edit selected comics information")); + setMultipleCover(); + + QList::iterator itr; + for(itr = ++comics.begin();itr!=comics.end();itr++) + { + if(itr->info.title.isNull() || itr->info.title.toString() != title->text()) + title->clear(); + + if(itr->info.count.isNull() || itr->info.count.toString() != countEdit->text()) + countEdit->clear(); + + if(itr->info.volume.isNull() || itr->info.volume.toString() != volumeEdit->text()) + volumeEdit->clear(); + if(itr->info.storyArc.isNull() || itr->info.storyArc.toString() != storyArcEdit->text()) + storyArcEdit->clear(); + if(itr->info.arcCount.isNull() || itr->info.arcCount.toString() != storyArcEdit->text()) + arcCountEdit->clear(); + + if(itr->info.genere.isNull() || itr->info.genere.toString() != genereEdit->text()) + genereEdit->clear(); + + if(itr->info.writer.isNull() || itr->info.writer.toString() != writer->toPlainText()) + writer->clear(); + if(itr->info.penciller.isNull() || itr->info.penciller.toString() != penciller->toPlainText()) + penciller->clear(); + if(itr->info.inker.isNull() || itr->info.inker.toString() != inker->toPlainText()) + inker->clear(); + if(itr->info.colorist.isNull() || itr->info.colorist.toString() != colorist->toPlainText()) + colorist->clear(); + if(itr->info.letterer.isNull() || itr->info.letterer.toString() != letterer->toPlainText()) + letterer->clear(); + if(itr->info.coverArtist.isNull() || itr->info.coverArtist.toString() != coverArtist->toPlainText()) + coverArtist->clear(); + + if(itr->info.date.isNull()) + { + dayEdit->clear(); + monthEdit->clear(); + yearEdit->clear(); + } + else + { + QStringList date = itr->info.date.toString().split("/"); + if(dayEdit->text() != date[0]) + dayEdit->clear(); + if(monthEdit->text() != date[1]) + monthEdit->clear(); + if(yearEdit->text() != date[2]) + yearEdit->clear(); + } + + if(itr->info.publisher.isNull() || itr->info.publisher.toString() != publisherEdit->text()) + publisherEdit->clear(); + if(itr->info.format.isNull() || itr->info.format.toString() != formatEdit->text()) + formatEdit->clear(); + if(itr->info.color.isNull() || itr->info.color.toBool() != colorCheck->isChecked()) + colorCheck->setCheckState(Qt::PartiallyChecked); + if(itr->info.ageRating.isNull() || itr->info.ageRating.toString() != ageRatingEdit->text()) + ageRatingEdit->clear(); + + if(itr->info.synopsis.isNull() || itr->info.synopsis.toString() != synopsis->toPlainText()) + synopsis->clear(); + if(itr->info.characters.isNull() || itr->info.characters.toString() != characters->toPlainText()) + characters->clear(); + if(itr->info.notes.isNull() || itr->info.notes.toString() != notes->toPlainText()) + notes->clear(); + } + } + else + { + this->setWindowTitle(tr("Edit comic information")); + setCover(comic.info.getCover(basePath)); + } + +} + +void PropertiesDialog::updateComics() +{ + QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath); + db.open(); + db.transaction(); + QList::iterator itr; + for(itr = comics.begin();itr!=comics.end();itr++) + { + if(itr->info.edited) + DBHelper::update(&(itr->info),db); + } + db.commit(); + db.close(); + QSqlDatabase::removeDatabase(databasePath); +} + +void PropertiesDialog::setMultipleCover() +{ + ComicDB lastComic = comics.last(); + QPixmap last = lastComic.info.getCover(basePath); + last = last.scaledToHeight(444,Qt::SmoothTransformation); + + coverImage = QPixmap::fromImage(blurred(last.toImage(),QRect(0,0,last.width(),last.height()),15)); +} + +void PropertiesDialog::setCover(const QPixmap & coverI) +{ + coverImage = coverI.scaledToHeight(444,Qt::SmoothTransformation); +} + +void PropertiesDialog::setFilename(const QString & nameString) +{ + title->setText(nameString); +} +void PropertiesDialog::setNumpages(int pagesNum) +{ + numPagesEdit->setText(QString::number(pagesNum)); +} +void PropertiesDialog::setSize(float sizeFloat) +{ + + size->setText(QString::number(sizeFloat,'f',2) + " MB"); +} + +void PropertiesDialog::save() +{ + QList::iterator itr; + for(itr = comics.begin();itr!=comics.end();itr++) + { + //Comic & comic = comics[0]; + bool edited = false; + + if(title->isModified()) + { + itr->info.title = title->text(); + edited = true; + } + + if(comics.size()==1) + if(coverChanged) + { + itr->info.coverPage = coverPageNumberLabel->text(); + edited = true; + } + + /*if(comic.info.numPages != NULL) + numPagesEdit->setText(QString::number(*comic.info.numPages));*/ + if(comics.size()==1) + if(numberEdit->isModified()) + { + if (numberEdit->text().isEmpty()) + itr->info.number = QVariant(); + else + itr->info.number = numberEdit->text(); + edited = true; + } + if(comics.size()==1) + if(!itr->info.isBis.isNull() || isBisCheck->isChecked()) + { + itr->info.isBis = isBisCheck->isChecked(); + edited = true; + } + + if(countEdit->isModified()) + { + itr->info.count = countEdit->text(); + edited = true; + } + + if(volumeEdit->isModified()) + { + itr->info.volume = volumeEdit->text(); + edited = true; + } + if(storyArcEdit->isModified()) + { + itr->info.storyArc = storyArcEdit->text(); + edited = true; + } + if(comics.size()==1) + if(arcNumberEdit->isModified() && !arcNumberEdit->text().isEmpty()) + { + itr->info.arcNumber = arcNumberEdit->text(); + edited = true; + } + if(arcCountEdit->isModified()) + { + itr->info.arcCount = arcCountEdit->text(); + edited = true; + } + + if(genereEdit->isModified()) + { + itr->info.genere = genereEdit->text(); + edited = true; + } + + if(writer->document()->isModified()) + { + itr->info.writer = writer->toPlainText(); + edited = true; + } + if(penciller->document()->isModified()) + { + itr->info.penciller = penciller->toPlainText(); + edited = true; + } + if(inker->document()->isModified()) + { + itr->info.inker = inker->toPlainText(); + edited = true; + } + if(colorist->document()->isModified()) + { + itr->info.colorist = colorist->toPlainText(); + edited = true; + } + if(letterer->document()->isModified()) + { + itr->info.letterer = letterer->toPlainText(); + edited = true; + } + if(coverArtist->document()->isModified()) + { + itr->info.coverArtist = coverArtist->toPlainText(); + edited = true; + } + + if(dayEdit->isModified() || monthEdit->isModified() || yearEdit->isModified() ) + { + itr->info.date = dayEdit->text()+"/"+monthEdit->text()+"/"+yearEdit->text(); + edited = true; + } + if(publisherEdit->isModified()) + { + itr->info.publisher = publisherEdit->text(); + edited = true; + } + if(formatEdit->isModified()) + { + itr->info.format = formatEdit->text(); + edited = true; + } + if(colorCheck->checkState() != Qt::PartiallyChecked) + { + itr->info.color = colorCheck->isChecked(); + edited = true; + } + if(ageRatingEdit->isModified()) + { + itr->info.ageRating = ageRatingEdit->text(); + edited = true; + } + + if(synopsis->document()->isModified()) + { + itr->info.synopsis = synopsis->toPlainText(); + edited = true; + } + if(characters->document()->isModified()) + { + itr->info.characters = characters->toPlainText(); + edited = true; + } + if(notes->document()->isModified()) + { + itr->info.notes = notes->toPlainText(); + edited = true; + } + + itr->info.edited = edited; + } + updateComics(); + if(comics.count() == 1) + { + if(coverChanged)// && coverPageEdit->text().toInt() != *comics[0].info.coverPage) + { + ThumbnailCreator tc(basePath+comics[0].path,basePath+"/.yacreaderlibrary/covers/"+comics[0].info.hash+".jpg", comics[0].info.coverPage.toInt()); + tc.create(); + } + } + close(); + emit(accepted()); +} + +void PropertiesDialog::setDisableUniqueValues(bool disabled) +{ + coverPageEdit->setDisabled(disabled); + coverPageEdit->clear(); + numberEdit->setDisabled(disabled); + numberEdit->clear(); + isBisCheck->setDisabled(disabled); + isBisCheck->setChecked(false); + arcNumberEdit->setDisabled(disabled); + arcNumberEdit->clear(); +} + +void PropertiesDialog::closeEvent ( QCloseEvent * e ) +{ + + title->clear(); + title->setModified(false); + coverPageEdit->clear(); + // numPagesEdit->setText(QString::number(*comic.info.numPages)); + numberEdit->clear(); + isBisCheck->setChecked(false); + countEdit->clear(); + volumeEdit->clear(); + storyArcEdit->clear(); + arcNumberEdit->clear(); + arcCountEdit->clear(); + genereEdit->clear(); + writer->clear(); + penciller->clear(); + inker->clear(); + colorist->clear(); + letterer->clear(); + coverArtist->clear(); + dayEdit->clear(); + monthEdit->clear(); + yearEdit->clear(); + publisherEdit->clear(); + formatEdit->clear(); + colorCheck->setCheckState(Qt::PartiallyChecked); + ageRatingEdit->clear(); + synopsis->clear(); + characters->clear(); + notes->clear(); + + setDisableUniqueValues(false); + + tabBar->setCurrentIndex(0); + + coverPageEdit->setFocus(); + + QDialog::closeEvent(e); +} + +void PropertiesDialog::paintEvent(QPaintEvent * event) +{ + QDialog::paintEvent(event); + + QPainter p(this); + + p.drawPixmap(0,0,coverImage); + + //QPixmap shadow(":/images/social_dialog/shadow.png"); + //p.drawPixmap(280-shadow.width(),0,shadow.width(),444,shadow); + p.drawLine(279,0,279,444); + if(comics.length()==1) + p.fillRect(0,444-28,280,28,QColor(0,0,0,153)); +} + +void PropertiesDialog::updateCoverPageNumberLabel(int n) +{ + coverPageNumberLabel->setText(QString::number(n)); + coverPageNumberLabel->adjustSize(); +} + +void PropertiesDialog::loadNextCover() +{ + int current = coverPageNumberLabel->text().toInt(); + if(current < comics.at(0).info.numPages.toInt()) + { + updateCoverPageNumberLabel(current+1); + + ThumbnailCreator tc(basePath+comics[0].path,"",current+1); + tc.create(); + setCover(tc.getCover()); + repaint(); + + if((current+1) == comics.at(0).info.numPages.toInt()) + { + showNextCoverPageButton->setDisabled(true); + } + + showPreviousCoverPageButton->setEnabled(true); + //busyIndicator->show(); + if(current+1 != comics.at(0).info.coverPage) + coverChanged = true; + else + coverChanged = false; + } +} + +void PropertiesDialog::loadPreviousCover() +{ + int current = coverPageNumberLabel->text().toInt(); + if(current!=1) + { + updateCoverPageNumberLabel(current-1); + ThumbnailCreator tc(basePath+comics[0].path,"",current-1); + tc.create(); + setCover(tc.getCover()); + repaint(); + + if((current-1) == 1) + { + showPreviousCoverPageButton->setDisabled(true); + } + + showNextCoverPageButton->setEnabled(true); + //busyIndicator->show(); + if(current-1 != comics.at(0).info.coverPage.toInt()) + coverChanged = true; + else + coverChanged = false; + } +} diff --git a/YACReaderLibrary/properties_dialog.h b/YACReaderLibrary/properties_dialog.h new file mode 100644 index 00000000..a3088b1d --- /dev/null +++ b/YACReaderLibrary/properties_dialog.h @@ -0,0 +1,141 @@ +#ifndef __PROPERTIES_DIALOG_H +#define __PROPERTIES_DIALOG_H + +#include + +#include + +class QGridLayout; +class QTabWidget; +class QGroupBox; +class QLabel; +class QScrollArea; +class QWidget; +class YACReaderFieldEdit; +class YACReaderFieldPlainTextEdit; +class QDialogButtonBox; +class QCheckBox; +//class YACReaderBusyWidget; +class QToolButton; + +#include "comic_db.h" + + class PropertiesDialog : public QDialog + { + Q_OBJECT + private: + QWidget * mainWidget; + //YACReaderBusyWidget * busyIndicator; + + QGridLayout * mainLayout; + + QTabWidget * tabBar; + + QWidget * coverBox; + QLabel * cover; + QScrollArea * sa; + + QWidget * generalInfoBox; + YACReaderFieldEdit * title; + YACReaderFieldEdit * numPagesEdit; + QLabel * size; + QLabel * comicVineLink; + + YACReaderFieldEdit * coverPageEdit; + QIntValidator coverPageValidator; + + YACReaderFieldEdit * numberEdit; + QIntValidator numberValidator; + QCheckBox * isBisCheck; + YACReaderFieldEdit * countEdit; + QIntValidator countValidator; + + YACReaderFieldEdit * volumeEdit; + YACReaderFieldEdit * storyArcEdit; + YACReaderFieldEdit * arcNumberEdit; + QIntValidator arcNumberValidator; + YACReaderFieldEdit * arcCountEdit; + QIntValidator arcCountValidator; + + YACReaderFieldEdit * genereEdit; + + YACReaderFieldPlainTextEdit * writer; + YACReaderFieldPlainTextEdit * penciller; + YACReaderFieldPlainTextEdit * inker; + YACReaderFieldPlainTextEdit * colorist; + YACReaderFieldPlainTextEdit * letterer; + YACReaderFieldPlainTextEdit * coverArtist; + + YACReaderFieldEdit * dayEdit; + QIntValidator dayValidator; + YACReaderFieldEdit * monthEdit; + QIntValidator monthValidator; + YACReaderFieldEdit * yearEdit; + QIntValidator yearValidator; + YACReaderFieldEdit * publisherEdit; + YACReaderFieldEdit * formatEdit; + QCheckBox * colorCheck; + YACReaderFieldEdit * ageRatingEdit; + + YACReaderFieldPlainTextEdit * synopsis; + YACReaderFieldPlainTextEdit * characters; + YACReaderFieldPlainTextEdit * notes; + + QWidget * authorsBox; + + QWidget * publishingBox; + + QWidget * plotBox; + + QDialogButtonBox *buttonBox; + QPushButton *closeButton; + QPushButton *saveButton; + QPushButton *restoreButton; //?? + + QPixmap coverImage; + + QToolButton * showPreviousCoverPageButton; + QToolButton * showNextCoverPageButton; + QLabel * coverPageNumberLabel; + + void createTabBar(); + void createCoverBox(); + void createGeneralInfoBox(); + void createAuthorsBox(); + void createPublishingBox(); + void createPlotBox(); + + void createButtonBox(); + + void setDisableUniqueValues(bool disabled); + + QList comics; + void closeEvent ( QCloseEvent * e ); + void updateCoverPageNumberLabel(int n); + + bool coverChanged; + + public: + PropertiesDialog(QWidget * parent = 0); + QString databasePath; + QString basePath; + QSize sizeHint(); + void paintEvent(QPaintEvent * event); + + public slots: + void setComics(QList comics); + void updateComics(); + void save(); + //Deprecated + void setCover(const QPixmap & cover); + void setMultipleCover(); + void setFilename(const QString & name); + void setNumpages(int pages); + void setSize(float size); + void loadNextCover(); + void loadPreviousCover(); + + + }; +#endif + diff --git a/YACReaderLibrary/qml.qrc b/YACReaderLibrary/qml.qrc new file mode 100644 index 00000000..5477ae08 --- /dev/null +++ b/YACReaderLibrary/qml.qrc @@ -0,0 +1,9 @@ + + + qml/GridComicsView.qml + qml/YACReaderScrollView.qml + qml/tick.png + qml/reading.png + qml/star_menu.png + + diff --git a/YACReaderLibrary/qml/GridComicsView.qml b/YACReaderLibrary/qml/GridComicsView.qml new file mode 100644 index 00000000..d947546c --- /dev/null +++ b/YACReaderLibrary/qml/GridComicsView.qml @@ -0,0 +1,446 @@ +import QtQuick 2.3 + +import QtQuick.Controls 1.2 +import comicModel 1.0 + +Rectangle { + id: main + color: backgroundColor + width: parent.width + height: parent.height + anchors.margins: 0 + + function selectAll(from,to) + { + for(var i = from;i<=to;i++) + { + comicsSelectionHelper.selectIndex(i); + } + } + + Component { + id: appDelegate + Rectangle + { + id: cell + width: grid.cellWidth + height: grid.cellHeight + color: backgroundColor + + + Rectangle { + id: realCell + + property int position : 0 + property bool dragging: false; + Drag.active: mouseArea.drag.active + Drag.hotSpot.x: 32 + Drag.hotSpot.y: 32 + Drag.dragType: Drag.Automatic + //Drag.mimeData: { "x": 1 } + Drag.proposedAction: Qt.CopyAction + Drag.onActiveChanged: { + if(!dragging) + { + dragManager.startDrag(); + dragging = true; + }else + dragging = false; + } + + width: 156; height: 287 + color: ((dummyValue || !dummyValue) && comicsSelectionHelper.isSelectedIndex(index))?selectedColor:cellColor; + border.color: ((dummyValue || !dummyValue) && comicsSelectionHelper.isSelectedIndex(index))?selectedBorderColor:borderColor; + border.width: (Qt.platform.os === "osx")?1:0; + + anchors.horizontalCenter: parent.horizontalCenter + + MouseArea { + id: mouseArea + drag.target: realCell + + drag.minimumX: 0 + drag.maximumX: 0 + drag.minimumY: 0 + drag.maximumY: 0 + + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + + onDoubleClicked: { + comicsSelectionHelper.clear(); + + comicsSelectionHelper.selectIndex(index); + grid.currentIndex = index; + comicsSelectionHelper.selectedItem(index); + } + + onPressed: { + + var ci = grid.currentIndex; //save current index + + /*if(mouse.button != Qt.RightButton && !(mouse.modifiers & Qt.ControlModifier || mouse.modifiers & Qt.ShiftModifier)) + { + if(!comicsSelectionHelper.isSelectedIndex(index)) + comicsSelectionHelper.clear(); + }*/ + + if(mouse.modifiers & Qt.ShiftModifier) + if(index < ci) + { + selectAll(index,ci); + grid.currentIndex = index; + } + else if (index > ci) + { + selectAll(ci,index); + grid.currentIndex = index; + } + + mouse.accepted = true; + + if(mouse.button == Qt.RightButton) // context menu is requested + { + + if(!comicsSelectionHelper.isSelectedIndex(index)) //the context menu is requested outside the current selection, the selection will be + { + comicsSelectionHelper.setCurrentIndex(index) + grid.currentIndex = index; + } + + var coordinates = main.mapFromItem(realCell,mouseX,mouseY) + contextMenuHelper.requestedContextMenu(Qt.point(coordinates.x,coordinates.y)); + + } else //left button + { + + if(mouse.modifiers & Qt.ControlModifier) + { + if(comicsSelectionHelper.isSelectedIndex(index)) + { + if(comicsSelectionHelper.numItemsSelected()>1) + { + comicsSelectionHelper.deselectIndex(index); + if(grid.currentIndex === index) + grid.currentIndex = comicsSelectionHelper.lastSelectedIndex(); + } + } + else + { + comicsSelectionHelper.selectIndex(index); + grid.currentIndex = index; + } + } + + if(mouse.button != Qt.RightButton && !(mouse.modifiers & Qt.ControlModifier || mouse.modifiers & Qt.ShiftModifier)) //just left button click + { + if(comicsSelectionHelper.isSelectedIndex(index)) //the context menu is requested outside the current selection, the selection will be + { + + } + else + { + comicsSelectionHelper.setCurrentIndex(index) + } + + grid.currentIndex = index; + } + } + + } + + onReleased: { + if(mouse.button == Qt.LeftButton && !(mouse.modifiers & Qt.ControlModifier || mouse.modifiers & Qt.ShiftModifier)) + { + if(comicsSelectionHelper.isSelectedIndex(index)) + { + comicsSelectionHelper.setCurrentIndex(index) + grid.currentIndex = index; + } + } + } + + } + + } + + /**/ + + //cover + Image { + id: coverElement + width: 148 + height: 224 + anchors {horizontalCenter: parent.horizontalCenter; top: realCell.top; topMargin: 4} + source: cover_path + fillMode: Image.PreserveAspectCrop + smooth: true + mipmap: true + asynchronous : true + cache: false //TODO clear cache only when it is neede + } + //mark + Image { + id: mark + width: 23 + height: 23 + source: read_column&&show_marks?"tick.png":has_been_opened&&show_marks?"reading.png":"" + anchors {right: coverElement.right; top: coverElement.top; topMargin: 11; rightMargin: 11} + asynchronous : true + } + + //title + Text { + id : titleText + anchors { top: realCell.top; left: realCell.left; leftMargin: 4; rightMargin: 4; topMargin: 234; } + width: 148 + maximumLineCount: 2 + wrapMode: Text.WordWrap + text: title + elide: Text.ElideRight + color: titleColor + clip: true + font.letterSpacing: fontSpacing + font.pointSize: fontSize + font.family: fontFamily + } + //number + Text { + anchors {bottom: realCell.bottom; left: realCell.left; margins: 4} + text: number?"#"+number:"" + color: textColor + font.letterSpacing: fontSpacing + font.pointSize: fontSize + font.family: fontFamily + } + //page icon + Image { + id: pageImage + anchors {bottom: realCell.bottom; right: realCell.right; bottomMargin: 5; rightMargin: 4; leftMargin: 4} + source: "page.png" + } + //numPages + Text { + id: pages + anchors {bottom: realCell.bottom; right: pageImage.left; margins: 4} + text: has_been_opened?current_page+"/"+num_pages:num_pages + color: textColor + font.letterSpacing: fontSpacing + font.pointSize: fontSize + font.family: fontFamily + } + //rating icon + Image { + id: ratingImage + anchors {bottom: realCell.bottom; right: pageImage.left; bottomMargin: 5; rightMargin: Math.floor(pages.width)+12} + source: "star.png" + + MouseArea { + anchors.fill: parent + onClicked: { + console.log("rating"); + comicsSelectionHelper.clear(); + comicsSelectionHelper.selectIndex(index); + grid.currentIndex = index; + ratingConextMenu.popup(); + + } + } + + Menu { + id: ratingConextMenu + MenuItem { text: "1"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,1) } + MenuItem { text: "2"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,2) } + MenuItem { text: "3"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,3) } + MenuItem { text: "4"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,4) } + MenuItem { text: "5"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,5) } + + } + } + + //comic rating + Text { + id: comicRating + anchors {bottom: realCell.bottom; right: ratingImage.left; margins: 4} + text: rating>0?rating:"-" + color: textColor + } + } + } + + YACReaderScrollView{ + id: scrollView + anchors.fill: parent + anchors.margins: 0 + + //QTBUG-39453 + //Another fu%$·#& bug in Qt + //https://bugreports.qt.io/browse/QTBUG-39453 + //To solve this I am going to accept any input drag, drops will be filtered in "onDropped" + DropArea { + anchors.fill: parent + + /* + onEntered: { + console.log("onEntered"); + if(drag.hasUrls) + { + console.log("HAS URLS -> ", drag.urls); + if(dropManager.canDropUrls(drag.urls, drag.action)) + { + drag.accepted = true; + console.log("canDropUrls"); + }else + drag.accepted = false; + } + else if (dropManager.canDropFormats(drag.formats)) { + drag.accepted = true; + console.log("canDropFormats"); + } else + drag.accepted = false; + }*/ + + + onDropped: { + if(drop.hasUrls && dropManager.canDropUrls(drop.urls, drop.action)) + { + dropManager.droppedFiles(drop.urls, drop.action); + } + else{ + if (dropManager.canDropFormats(drop.formats)) + { + var destItem = grid.itemAt(drop.x,drop.y + grid.contentY); + var destLocalX = grid.mapToItem(destItem,drop.x,drop.y + grid.contentY).x + var realIndex = grid.indexAt(drop.x,drop.y + grid.contentY); + + if(realIndex === -1) + realIndex = grid.count - 1; + + var destIndex = destLocalX < (grid.cellWidth / 2) ? realIndex : realIndex + 1; + dropManager.droppedComicsForResortingAt(drop.getDataAsString(), destIndex); + } + } + } + + } + + GridView { + id:grid + anchors.fill: parent + cellHeight: 295 + highlight: appHighlight + focus: true + model: comicsList + delegate: appDelegate + anchors.topMargin: 20 + anchors.bottomMargin: 20 + anchors.leftMargin: 10 + anchors.rightMargin: 10 + pixelAligned: true + //flickDeceleration: -2000 + snapMode: GridView.SnapToRow + currentIndex: 0 + cacheBuffer: 0 + + footer: Rectangle { //fix for the scroll issue, TODO find what causes the issue (some times the bottoms cells are hidden for the toolbar, no full scroll) + height : 25 + width : parent.width + color : backgroundColor + } + + move: Transition { + NumberAnimation { properties: "x,y"; duration: 250 } + } + + moveDisplaced: Transition { + NumberAnimation { properties: "x,y"; duration: 250 } + } + + remove: Transition { + ParallelAnimation { + NumberAnimation { property: "opacity"; to: 0; duration: 250 } + + } + } + + removeDisplaced: Transition { + NumberAnimation { properties: "x,y"; duration: 250 } + } + + + + displaced: Transition { + NumberAnimation { properties: "x,y"; duration: 250 } + } + + function numCellsPerRow() { + return Math.floor(width / 185); + } + + onWidthChanged: { + var numCells = numCellsPerRow(); + var rest = width % 185; + + if(numCells > 0) + { + cellWidth = Math.floor(width / numCells) ; + //console.log("numCells=",numCells,"rest=",rest,"cellWidth=",cellWidth,"width=",width); + } + } + } + focus: true + Keys.onPressed: { + if (event.modifiers & Qt.ControlModifier || event.modifiers & Qt.ShiftModifier) + return; + var numCells = grid.numCellsPerRow(); + var ci + if (event.key === Qt.Key_Right) { + ci = Math.min(grid.currentIndex+1,grid.count); + } + else if (event.key === Qt.Key_Left) { + ci = Math.max(0,grid.currentIndex-1); + } + else if (event.key === Qt.Key_Up) { + ci = Math.max(0,grid.currentIndex-numCells); + } + else if (event.key === Qt.Key_Down) { + ci = Math.min(grid.currentIndex+numCells,grid.count); + } + + event.accepted = true; + //var ci = grid.currentIndex; + grid.currentIndex = -1 + comicsSelectionHelper.clear(); + comicsSelectionHelper.setCurrentIndex(ci); + grid.currentIndex = ci; + } + //} + + /*MouseArea { + anchors.fill: parent + onClicked: { + clicked.accepted = false; + console.log("xx"); + } + + onWheel: { + var newValue = Math.max(0,scrollView.flickableItem.contentY - wheel.angleDelta.y) + scrollView.flickableItem.contentY = newValue + + } + }*/ + /*ScrollBar { + flickable: grid; + } + + PerformanceMeter { + anchors {top: parent.top; left: parent.left; margins: 4} + id: performanceMeter + width: 128 + height: 64 + enabled: (dummyValue || !dummyValue) + }*/ + } +} + + diff --git a/YACReaderLibrary/qml/YACReaderScrollView.qml b/YACReaderLibrary/qml/YACReaderScrollView.qml new file mode 100644 index 00000000..a8dc57ad --- /dev/null +++ b/YACReaderLibrary/qml/YACReaderScrollView.qml @@ -0,0 +1,336 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Private 1.0 +import QtQuick.Controls.Styles 1.1 + +/*! + \qmltype ScrollView + \inqmlmodule QtQuick.Controls + \since 5.1 + \ingroup views + \brief Provides a scrolling view within another Item. + + A ScrollView can be used either to replace a \l Flickable or decorate an + existing \l Flickable. Depending on the platform, it will add scroll bars and + a content frame. + + Only one Item can be a direct child of the ScrollView and the child is implicitly anchored + to fill the scroll view. + + Example: + \code + ScrollView { + Image { source: "largeImage.png" } + } + \endcode + + In the previous example the Image item will implicitly get scroll behavior as if it was + used within a \l Flickable. The width and height of the child item will be used to + define the size of the content area. + + Example: + \code + ScrollView { + ListView { + ... + } + } + \endcode + + In this case the content size of the ScrollView will simply mirror that of its contained + \l flickableItem. + + You can create a custom appearance for a ScrollView by + assigning a \l {QtQuick.Controls.Styles::ScrollViewStyle}{ScrollViewStyle}. +*/ + +FocusScope { + id: root + + implicitWidth: 240 + implicitHeight: 150 + + /*! + This property tells the ScrollView if it should render + a frame around its content. + + The default value is \c false. + */ + property bool frameVisible: false + + /*! + This property controls if there should be a highlight + around the frame when the ScrollView has input focus. + + The default value is \c false. + + \note This property is only applicable on some platforms, such + as Mac OS. + */ + property bool highlightOnFocus: false + + /*! + \qmlproperty Item ScrollView::viewport + + The viewport determines the current "window" on the contentItem. + In other words, it clips it and the size of the viewport tells you + how much of the content area is visible. + */ + property alias viewport: viewportItem + + /*! + \qmlproperty Item ScrollView::flickableItem + + The flickableItem of the ScrollView. If the contentItem provided + to the ScrollView is a Flickable, it will be the \l contentItem. + */ + readonly property alias flickableItem: internal.flickableItem + + /*! + The contentItem of the ScrollView. This is set by the user. + + Note that the definition of contentItem is somewhat different to that + of a Flickable, where the contentItem is implicitly created. + */ + default property Item contentItem + + /*! \internal */ + property Item __scroller: scroller + /*! \internal */ + property alias __wheelAreaScrollSpeed: wheelArea.scrollSpeed + /*! \internal */ + property int __scrollBarTopMargin: 0 + /*! \internal */ + property int __viewTopMargin: 0 + /*! \internal */ + property alias __horizontalScrollBar: scroller.horizontalScrollBar + /*! \internal */ + property alias __verticalScrollBar: scroller.verticalScrollBar + /*! \qmlproperty Component ScrollView::style + + The style Component for this control. + \sa {Qt Quick Controls Styles QML Types} + + */ + property Component style: Qt.createComponent(Settings.style + "/ScrollViewStyle.qml", root) + + /*! \internal */ + property Style __style: styleLoader.item + + activeFocusOnTab: true + + onContentItemChanged: { +//console.log("onContentItemChanged"); + if (contentItem.hasOwnProperty("contentY") && // Check if flickable + contentItem.hasOwnProperty("contentHeight")) { + internal.flickableItem = contentItem // "Use content if it is a flickable + internal.flickableItem.parent = viewportItem + } else { + internal.flickableItem = flickableComponent.createObject(viewportItem) + contentItem.parent = internal.flickableItem.contentItem + } + internal.flickableItem.anchors.fill = viewportItem + if (!Settings.hasTouchScreen) + internal.flickableItem.interactive = false + } + + + children: Item { + id: internal + + property Flickable flickableItem + + Loader { + id: styleLoader + sourceComponent: style + onStatusChanged: { + if (status === Loader.Error) + console.error("Failed to load Style for", root) + } + property alias __control: root + } + + Binding { + target: flickableItem + property: "contentHeight" + when: contentItem !== flickableItem + value: contentItem ? contentItem.height : 0 + } + + Binding { + target: flickableItem + when: contentItem !== flickableItem + property: "contentWidth" + value: contentItem ? contentItem.width : 0 + } + + Connections { + target: flickableItem + + onContentYChanged: { + //console.log("onContentYChanged2"); + scroller.blockUpdates = true + scroller.verticalScrollBar.value = flickableItem.contentY + scroller.blockUpdates = false + } + + onContentXChanged: { + //console.log("onContentXChanged2"); + scroller.blockUpdates = true + scroller.horizontalScrollBar.value = flickableItem.contentX + scroller.blockUpdates = false + } + + } + + anchors.fill: parent + + Component { + id: flickableComponent + Flickable {} + } + + WheelArea { + id: wheelArea + parent: flickableItem + + // ### Note this is needed due to broken mousewheel behavior in Flickable. + + anchors.fill: parent + + property int stepSize: 295 + + property int acceleration: 40 + property int flickThreshold: Settings.dragThreshold + property real speedThreshold: 3 + property real ignored: 0.001 // ## flick() does not work with 0 yVelocity + property int maxFlick: 400 + + property bool horizontalRecursionGuard: false + property bool verticalRecursionGuard: false + + horizontalMinimumValue: flickableItem ? flickableItem.originX : 0 + horizontalMaximumValue: flickableItem ? flickableItem.originX + flickableItem.contentWidth - viewport.width : 0 + + verticalMinimumValue: flickableItem ? flickableItem.originY : 0 + verticalMaximumValue: flickableItem ? flickableItem.originY + flickableItem.contentHeight - viewport.height + __viewTopMargin : 0 + + Connections { + target: flickableItem + + onContentYChanged: { + //console.log("onContentYChanged"); + wheelArea.verticalRecursionGuard = true + wheelArea.verticalValue = flickableItem.contentY + wheelArea.verticalRecursionGuard = false + } + onContentXChanged: { + //console.log("onContentXChanged"); + wheelArea.horizontalRecursionGuard = true + wheelArea.horizontalValue = flickableItem.contentX + wheelArea.horizontalRecursionGuard = false + } + } + + onVerticalValueChanged: { + if (!verticalRecursionGuard) { + //console.log(verticalDelta); + + if (flickableItem.contentY < flickThreshold && verticalDelta > speedThreshold) { + flickableItem.flick(ignored, Math.min(maxFlick, acceleration * verticalDelta)) + } else if (flickableItem.contentY > flickableItem.contentHeight + - flickThreshold - viewport.height && verticalDelta < -speedThreshold) { + flickableItem.flick(ignored, Math.max(-maxFlick, acceleration * verticalDelta)) + } else { + var absDelta = Math.abs(verticalDelta); + + if(verticalDelta < 0) + flickableItem.contentY = verticalValue + Math.min(98,0.93*absDelta+4.5); + else + flickableItem.contentY = verticalValue - Math.min(98,0.93*absDelta+4.5); +} + + + //TODO: snap to row + + } + + } + + onHorizontalValueChanged: { + if (!horizontalRecursionGuard) + flickableItem.contentX = horizontalValue + } + } + + ScrollViewHelper { + id: scroller + anchors.fill: parent + active: wheelArea.active + property bool outerFrame: !frameVisible || !(__style ? __style.__externalScrollBars : 0) + property int scrollBarSpacing: outerFrame ? 0 : (__style ? __style.__scrollBarSpacing : 0) + property int verticalScrollbarOffset: verticalScrollBar.visible && !verticalScrollBar.isTransient ? + verticalScrollBar.width + scrollBarSpacing : 0 + property int horizontalScrollbarOffset: horizontalScrollBar.visible && !horizontalScrollBar.isTransient ? + horizontalScrollBar.height + scrollBarSpacing : 0 + Loader { + id: frameLoader + sourceComponent: __style ? __style.frame : null + anchors.fill: parent + anchors.rightMargin: scroller.outerFrame ? 0 : scroller.verticalScrollbarOffset + anchors.bottomMargin: scroller.outerFrame ? 0 : scroller.horizontalScrollbarOffset + } + + Item { + id: viewportItem + anchors.fill: frameLoader + anchors.topMargin: frameVisible ? __style.padding.top : 0 + anchors.leftMargin: frameVisible ? __style.padding.left : 0 + anchors.rightMargin: (frameVisible ? __style.padding.right : 0) + (scroller.outerFrame ? scroller.verticalScrollbarOffset : 0) + anchors.bottomMargin: (frameVisible ? __style.padding.bottom : 0) + (scroller.outerFrame ? scroller.horizontalScrollbarOffset : 0) + clip: true + } + } + FocusFrame { visible: highlightOnFocus && root.activeFocus } + } +} diff --git a/YACReaderLibrary/qml/page-macosx.png b/YACReaderLibrary/qml/page-macosx.png new file mode 100644 index 00000000..c8216591 Binary files /dev/null and b/YACReaderLibrary/qml/page-macosx.png differ diff --git a/YACReaderLibrary/qml/page.png b/YACReaderLibrary/qml/page.png new file mode 100644 index 00000000..100db8a0 Binary files /dev/null and b/YACReaderLibrary/qml/page.png differ diff --git a/YACReaderLibrary/qml/reading.png b/YACReaderLibrary/qml/reading.png new file mode 100644 index 00000000..a26a81d6 Binary files /dev/null and b/YACReaderLibrary/qml/reading.png differ diff --git a/YACReaderLibrary/qml/star-macosx.png b/YACReaderLibrary/qml/star-macosx.png new file mode 100644 index 00000000..37577a74 Binary files /dev/null and b/YACReaderLibrary/qml/star-macosx.png differ diff --git a/YACReaderLibrary/qml/star.png b/YACReaderLibrary/qml/star.png new file mode 100644 index 00000000..4e3c4b6a Binary files /dev/null and b/YACReaderLibrary/qml/star.png differ diff --git a/YACReaderLibrary/qml/star_menu.png b/YACReaderLibrary/qml/star_menu.png new file mode 100644 index 00000000..4472e5a3 Binary files /dev/null and b/YACReaderLibrary/qml/star_menu.png differ diff --git a/YACReaderLibrary/qml/tick.png b/YACReaderLibrary/qml/tick.png new file mode 100644 index 00000000..78a20644 Binary files /dev/null and b/YACReaderLibrary/qml/tick.png differ diff --git a/YACReaderLibrary/qml_osx.qrc b/YACReaderLibrary/qml_osx.qrc new file mode 100644 index 00000000..85397d2f --- /dev/null +++ b/YACReaderLibrary/qml_osx.qrc @@ -0,0 +1,6 @@ + + + qml/page-macosx.png + qml/star-macosx.png + + diff --git a/YACReaderLibrary/qml_win.qrc b/YACReaderLibrary/qml_win.qrc new file mode 100644 index 00000000..59e2872f --- /dev/null +++ b/YACReaderLibrary/qml_win.qrc @@ -0,0 +1,6 @@ + + + qml/page.png + qml/star.png + + diff --git a/YACReaderLibrary/rename_library_dialog.cpp b/YACReaderLibrary/rename_library_dialog.cpp new file mode 100644 index 00000000..22202865 --- /dev/null +++ b/YACReaderLibrary/rename_library_dialog.cpp @@ -0,0 +1,76 @@ +#include "rename_library_dialog.h" + +#include +#include +#include + + + +RenameLibraryDialog::RenameLibraryDialog(QWidget * parent) +:QDialog(parent) +{ + setupUI(); +} + +void RenameLibraryDialog::setupUI() +{ + newNameLabel = new QLabel(tr("New Library Name : ")); + newNameEdit = new QLineEdit; + newNameLabel->setBuddy(newNameEdit); + connect(newNameEdit,SIGNAL(textChanged(QString)),this,SLOT(nameSetted(QString))); + + accept = new QPushButton(tr("Rename")); + accept->setDisabled(true); + connect(accept,SIGNAL(clicked()),this,SLOT(rename())); + + cancel = new QPushButton(tr("Cancel")); + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); + + QHBoxLayout *nameLayout = new QHBoxLayout; + + nameLayout->addWidget(newNameLabel); + nameLayout->addWidget(newNameEdit); + + QHBoxLayout *bottomLayout = new QHBoxLayout; + bottomLayout->addStretch(); + bottomLayout->addWidget(accept); + bottomLayout->addWidget(cancel); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(nameLayout); + mainLayout->addStretch(); + mainLayout->addLayout(bottomLayout); + + QHBoxLayout * imgMainLayout = new QHBoxLayout; + QLabel * imgLabel = new QLabel(this); + QPixmap p(":/images/edit.png"); + imgLabel->setPixmap(p); + imgMainLayout->addWidget(imgLabel); + imgMainLayout->addLayout(mainLayout); + + setLayout(imgMainLayout); + + setModal(true); + setWindowTitle(tr("Rename current library")); +} + +void RenameLibraryDialog::rename() +{ + //accept->setEnabled(false); + emit(renameLibrary(newNameEdit->text())); +} + +void RenameLibraryDialog::nameSetted(const QString & text) +{ + if(!text.isEmpty()) + accept->setEnabled(true); + else + accept->setEnabled(false); +} + +void RenameLibraryDialog::close() +{ + newNameEdit->clear(); + //accept->setEnabled(false); + QDialog::close(); +} \ No newline at end of file diff --git a/YACReaderLibrary/rename_library_dialog.h b/YACReaderLibrary/rename_library_dialog.h new file mode 100644 index 00000000..abdd2e3e --- /dev/null +++ b/YACReaderLibrary/rename_library_dialog.h @@ -0,0 +1,31 @@ +#ifndef __RENAME_LIBRARY_DIALOG_H +#define __RENAME_LIBRARY_DIALOG_H + +#include +#include +#include +#include + + + class RenameLibraryDialog : public QDialog + { + Q_OBJECT + public: + RenameLibraryDialog(QWidget * parent = 0); + private: + QLabel * newNameLabel; + QLineEdit * newNameEdit; + QPushButton * accept; + QPushButton * cancel; + void setupUI(); + public slots: + void rename(); + void close(); + void nameSetted(const QString & name); +signals: + void renameLibrary(QString newName); + }; + + +#endif + diff --git a/YACReaderLibrary/server/controllers/comiccontroller.cpp b/YACReaderLibrary/server/controllers/comiccontroller.cpp new file mode 100644 index 00000000..52ae4e00 --- /dev/null +++ b/YACReaderLibrary/server/controllers/comiccontroller.cpp @@ -0,0 +1,122 @@ +#include "comiccontroller.h" + +#include "db_helper.h" +#include "yacreader_libraries.h" + +#include "template.h" +#include "../static.h" + +#include "comic_db.h" +#include "comic.h" + +#include "QsLog.h" + +#include + +ComicController::ComicController() {} + +void ComicController::service(HttpRequest& request, HttpResponse& response) +{ + HttpSession session=Static::sessionStore->getSession(request,response,false); + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + qulonglong libraryId = pathElements.at(2).toLongLong(); + QString libraryName = DBHelper::getLibraryName(libraryId); + qulonglong comicId = pathElements.at(4).toULongLong(); + + bool remoteComic = path.endsWith("remote"); + + //TODO + //if(pathElements.size() == 6) + //{ + // QString action = pathElements.at(5); + // if(!action.isEmpty() && (action == "close")) + // { + // session.dismissCurrentComic(); + // response.write("",true); + // return; + // } + //} + + YACReaderLibraries libraries = DBHelper::getLibraries(); + + ComicDB comic = DBHelper::getComicInfo(libraryId, comicId); + + if(!remoteComic) + session.setDownloadedComic(comic.info.hash); + + Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryId)+comic.path); + + if(comicFile != NULL) + { + QThread * thread = NULL; + + thread = new QThread(); + + comicFile->moveToThread(thread); + + connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit())); + connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit())); + connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit())); + connect(thread, SIGNAL(started()), comicFile, SLOT(process())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + comicFile->load(libraries.getPath(libraryId)+comic.path); + + if(thread != NULL) + thread->start(); + + if(remoteComic) + { + QLOG_INFO() << "remote comic requested"; + session.setCurrentRemoteComic(comic.id, comicFile); + + } + else + { + QLOG_INFO() << "comic requested"; + session.setCurrentComic(comic.id, comicFile); + } + + response.setHeader("Content-Type", "plain/text; charset=utf-8"); + //TODO this field is not used by the client! + response.writeText(QString("library:%1\r\n").arg(libraryName)); + response.writeText(QString("libraryId:%1\r\n").arg(libraryId)); + if(remoteComic) //send previous and next comics id + { + QList siblings = DBHelper::getFolderComicsFromLibrary(libraryId, comic.parentId, true); + bool found = false; + int i; + for(i = 0; i < siblings.length(); i++) + { + if (siblings.at(i)->id == comic.id) + { + found = true; + break; + } + } + if(found) + { + if(i>0) + response.writeText(QString("previousComic:%1\r\n").arg(siblings.at(i-1)->id)); + if(iid)); + } + else + { + //ERROR + } + qDeleteAll(siblings); + } + response.writeText(comic.toTXT(),true); + } + else + { + //delete comicFile; + response.setStatus(404,"not found"); + response.write("404 not found",true); + } + //response.write(t.toLatin1(),true); + +} diff --git a/YACReaderLibrary/server/controllers/comiccontroller.h b/YACReaderLibrary/server/controllers/comiccontroller.h new file mode 100644 index 00000000..71287b68 --- /dev/null +++ b/YACReaderLibrary/server/controllers/comiccontroller.h @@ -0,0 +1,23 @@ +#ifndef COMICCONTROLLER_H +#define COMICCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +#include +class Comic; +class QString; + +class ComicController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(ComicController); +public: + /** Constructor */ + ComicController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // COMICCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/comicdownloadinfocontroller.cpp b/YACReaderLibrary/server/controllers/comicdownloadinfocontroller.cpp new file mode 100644 index 00000000..aeab979a --- /dev/null +++ b/YACReaderLibrary/server/controllers/comicdownloadinfocontroller.cpp @@ -0,0 +1,26 @@ +#include "comicdownloadinfocontroller.h" + +#include "db_helper.h" +#include "yacreader_libraries.h" + +#include "comic_db.h" + +ComicDownloadInfoController::ComicDownloadInfoController() {} + + +void ComicDownloadInfoController::service(HttpRequest& request, HttpResponse& response) +{ + response.setHeader("Content-Type", "plain/text; charset=utf-8"); + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + + qulonglong libraryId = pathElements.at(2).toLongLong(); + qulonglong comicId = pathElements.at(4).toULongLong(); + + ComicDB comic = DBHelper::getComicInfo(libraryId, comicId); + + //TODO: check if the comic wasn't found; + response.writeText(QString("fileName:%1\r\n").arg(comic.getFileName())); + response.writeText(QString("fileSize:%1\r\n").arg(comic.getFileSize()),true); +} diff --git a/YACReaderLibrary/server/controllers/comicdownloadinfocontroller.h b/YACReaderLibrary/server/controllers/comicdownloadinfocontroller.h new file mode 100644 index 00000000..e98518e8 --- /dev/null +++ b/YACReaderLibrary/server/controllers/comicdownloadinfocontroller.h @@ -0,0 +1,19 @@ +#ifndef COMICDOWNLOADINFOCONTROLLER_H +#define COMICDOWNLOADINFOCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class ComicDownloadInfoController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(ComicDownloadInfoController); +public: + /** Constructor **/ + ComicDownloadInfoController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // COMICDOWNLOADINFOCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/covercontroller.cpp b/YACReaderLibrary/server/controllers/covercontroller.cpp new file mode 100644 index 00000000..da414c80 --- /dev/null +++ b/YACReaderLibrary/server/controllers/covercontroller.cpp @@ -0,0 +1,88 @@ +#include "covercontroller.h" +#include "db_helper.h" //get libraries +#include "yacreader_libraries.h" + +#include "template.h" +#include "../static.h" + +CoverController::CoverController() {} + +void CoverController::service(HttpRequest& request, HttpResponse& response) +{ + + HttpSession session=Static::sessionStore->getSession(request,response,false); + + response.setHeader("Content-Type", "image/jpeg"); + response.setHeader("Connection","close"); + //response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1"); + + YACReaderLibraries libraries = DBHelper::getLibraries(); + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt()); + QString fileName = pathElements.at(4); + + bool folderCover = request.getParameter("folderCover").length()>0; + + //response.writeText(path+"
"); + //response.writeText(libraryName+"
"); + //response.writeText(libraries.value(libraryName)+"/.yacreaderlibrary/covers/"+fileName+"
"); + + //QFile file(libraries.value(libraryName)+"/.yacreaderlibrary/covers/"+fileName); + //if (file.exists()) { + // if (file.open(QIODevice::ReadOnly)) + // { + // qDebug("StaticFileController: Open file %s",qPrintable(file.fileName())); + // // Return the file content, do not store in cache + // while (!file.atEnd() && !file.error()) { + // response.write(file.read(131072)); + // } + // } + + // file.close(); + //} + + QImage img(libraries.getPath(libraryName)+"/.yacreaderlibrary/covers/"+fileName); + if (!img.isNull()) { + + int width = 80, height = 120; + if(session.getDisplayType()=="@2x") + { + width = 160; + height = 240; + } + + if(float(img.width())/img.height() < 0.66666) + img = img.scaledToWidth(width,Qt::SmoothTransformation); + else + img = img.scaledToHeight(height,Qt::SmoothTransformation); + + QImage destImg(width,height,QImage::Format_RGB32); + destImg.fill(Qt::black); + QPainter p(&destImg); + + p.drawImage((width-img.width())/2,(height-img.height())/2,img); + + if(folderCover) + { + if(session.getDisplayType()=="@2x") + p.drawImage(0,0,QImage(":/images/f_overlayed_retina.png")); + else + p.drawImage(0,0,QImage(":/images/f_overlayed.png")); + } + + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + destImg.save(&buffer, "JPG"); + response.write(ba,true); + } + //DONE else, hay que devolver un 404 + else + { + response.setStatus(404,"not found"); + response.write("404 not found",true); + } +} + diff --git a/YACReaderLibrary/server/controllers/covercontroller.h b/YACReaderLibrary/server/controllers/covercontroller.h new file mode 100644 index 00000000..d4948f7c --- /dev/null +++ b/YACReaderLibrary/server/controllers/covercontroller.h @@ -0,0 +1,20 @@ +#ifndef COVERCONTROLLER_H +#define COVERCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class CoverController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(CoverController); +public: + + /** Constructor */ + CoverController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // COVERCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/dumpcontroller.cpp b/YACReaderLibrary/server/controllers/dumpcontroller.cpp new file mode 100644 index 00000000..2b67e536 --- /dev/null +++ b/YACReaderLibrary/server/controllers/dumpcontroller.cpp @@ -0,0 +1,62 @@ +/** + @file + @author Stefan Frings +*/ + +#include "dumpcontroller.h" +#include +#include + +DumpController::DumpController(){} + +void DumpController::service(HttpRequest& request, HttpResponse& response) { + + response.setHeader("Content-Type", "text/html; charset=ISO-8859-1"); + response.setCookie(HttpCookie("firstCookie","hello",600)); + response.setCookie(HttpCookie("secondCookie","world",600)); + + QByteArray body(""); + body.append("Request:"); + body.append("
Method: "); + body.append(request.getMethod()); + body.append("
Path: "); + body.append(request.getPath()); + body.append("
Version: "); + body.append(request.getVersion()); + + body.append("

Headers:"); + QMapIterator i(request.getHeaderMap()); + while (i.hasNext()) { + i.next(); + body.append("
"); + body.append(i.key()); + body.append("="); + body.append(i.value()); + } + + body.append("

Parameters:"); + i=QMapIterator(request.getParameterMap()); + while (i.hasNext()) { + i.next(); + body.append("
"); + body.append(i.key()); + body.append("="); + body.append(i.value()); + } + + body.append("

Cookies:"); + i=QMapIterator(request.getCookieMap()); + while (i.hasNext()) { + i.next(); + body.append("
"); + body.append(i.key()); + body.append("="); + body.append(i.value()); + } + + body.append("

Body:
"); + body.append(request.getBody()); + + body.append(""); + response.write(body,true); +} diff --git a/YACReaderLibrary/server/controllers/dumpcontroller.h b/YACReaderLibrary/server/controllers/dumpcontroller.h new file mode 100644 index 00000000..a3787dbb --- /dev/null +++ b/YACReaderLibrary/server/controllers/dumpcontroller.h @@ -0,0 +1,29 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef DUMPCONTROLLER_H +#define DUMPCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +/** + This controller dumps the received HTTP request in the response. +*/ + +class DumpController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(DumpController); +public: + + /** Constructor */ + DumpController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // DUMPCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/errorcontroller.cpp b/YACReaderLibrary/server/controllers/errorcontroller.cpp new file mode 100644 index 00000000..4bff204b --- /dev/null +++ b/YACReaderLibrary/server/controllers/errorcontroller.cpp @@ -0,0 +1,26 @@ +#include "errorcontroller.h" + +#include "template.h" +#include "../static.h" + + +ErrorController::ErrorController(int errorCode) +:error(errorCode) +{} + +void ErrorController::service(HttpRequest& request, HttpResponse& response) +{ + Q_UNUSED(request) + switch(error) + { + case 300: + response.setStatus(300,"redirect"); + response.write(" ", true); + break; + case 404: + response.setStatus(404,"not found"); + response.write("404 not found",true); + break; + } + +} \ No newline at end of file diff --git a/YACReaderLibrary/server/controllers/errorcontroller.h b/YACReaderLibrary/server/controllers/errorcontroller.h new file mode 100644 index 00000000..82f997df --- /dev/null +++ b/YACReaderLibrary/server/controllers/errorcontroller.h @@ -0,0 +1,22 @@ +#ifndef ERRORCONTROLLER_H +#define ERRORCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class ErrorController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(ErrorController); +public: + + /** Constructor */ + ErrorController(int errorCode); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +private: + int error; +}; + +#endif // ERRORCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/fileuploadcontroller.cpp b/YACReaderLibrary/server/controllers/fileuploadcontroller.cpp new file mode 100644 index 00000000..30d76035 --- /dev/null +++ b/YACReaderLibrary/server/controllers/fileuploadcontroller.cpp @@ -0,0 +1,38 @@ +/** + @file + @author Stefan Frings +*/ + +#include "fileuploadcontroller.h" + +FileUploadController::FileUploadController() {} + +void FileUploadController::service(HttpRequest& request, HttpResponse& response) { + + if (request.getParameter("action")=="show") { + response.setHeader("Content-Type", "image/jpeg"); + QTemporaryFile* file=request.getUploadedFile("file1"); + if (file) { + while (!file->atEnd() && !file->error()) { + QByteArray buffer=file->read(65536); + response.write(buffer); + } + } + else { + response.write("upload failed"); + } + } + + else { + response.setHeader("Content-Type", "text/html; charset=ISO-8859-1"); + response.write(""); + response.write("Upload a JPEG image file

"); + response.write("

"); + response.write(" "); + response.write(" File:
"); + response.write(" "); + response.write("
"); + response.write("",true); + } +} + diff --git a/YACReaderLibrary/server/controllers/fileuploadcontroller.h b/YACReaderLibrary/server/controllers/fileuploadcontroller.h new file mode 100644 index 00000000..01865ea6 --- /dev/null +++ b/YACReaderLibrary/server/controllers/fileuploadcontroller.h @@ -0,0 +1,30 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef FILEUPLOADCONTROLLER_H +#define FILEUPLOADCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +/** + This controller displays a HTML form for file upload and recieved the file. +*/ + + +class FileUploadController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(FileUploadController); +public: + + /** Constructor */ + FileUploadController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // FILEUPLOADCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/foldercontroller.cpp b/YACReaderLibrary/server/controllers/foldercontroller.cpp new file mode 100644 index 00000000..30aa657f --- /dev/null +++ b/YACReaderLibrary/server/controllers/foldercontroller.cpp @@ -0,0 +1,321 @@ +#include "foldercontroller.h" +#include "controllers/errorcontroller.h" + +#include "db_helper.h" //get libraries +#include "comic_db.h" + +#include "folder.h" + +#include "template.h" +#include "../static.h" + +#include "qnaturalsorting.h" + +#include "QsLog.h" + +struct LibraryItemSorter +{ + bool operator()(const LibraryItem * a,const LibraryItem * b) const + { + return naturalSortLessThanCI(a->name,b->name); + } +}; + +FolderController::FolderController() {} + +void FolderController::service(HttpRequest& request, HttpResponse& response) +{ + HttpSession session=Static::sessionStore->getSession(request,response,false); + + response.setHeader("Content-Type", "text/html; charset=utf-8"); + response.setHeader("Connection","close"); + + //QString y = session.get("xxx").toString(); + //response.writeText(QString("session xxx : %1
").arg(y)); + + Template t=Static::templateLoader->getTemplate("folder_"+session.getDeviceType(),request.getHeader("Accept-Language")); + t.enableWarnings(); + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + int libraryId = pathElements.at(2).toInt(); + QString libraryName = DBHelper::getLibraryName(libraryId); + qulonglong folderId = pathElements.at(4).toULongLong(); + + folderId = qMax(1,folderId); + + QString folderName = DBHelper::getFolderName(libraryId,folderId); + if(folderName.isEmpty()) + { + ErrorController(300).service(request,response); + return; + } + + if(folderId!=1) + t.setVariable("folder.name",folderName); + else + t.setVariable("folder.name",libraryName); + QList folderContent = DBHelper::getFolderSubfoldersFromLibrary(libraryId,folderId); + QList folderComics = DBHelper::getFolderComicsFromLibrary(libraryId,folderId); + + //response.writeText(libraryName); + + folderContent.append(folderComics); + + qSort(folderContent.begin(),folderContent.end(),LibraryItemSorter()); + folderComics.clear(); + + //qulonglong backId = DBHelper::getParentFromComicFolderId(libraryName,folderId); + + int page = 0; + QByteArray p = request.getParameter("page"); + if(p.length() != 0) + page = p.toInt(); + + // /comicIdi/pagei/comicIdj/pagej/....../comicIdn/pagen + //QString currentPath = session.get("currentPath").toString(); + //QStringList pathSize = currentPath.split("/").last().toInt; + + bool fromUp = false; + + QMultiMap map = request.getParameterMap(); + if(map.contains("up")) + fromUp = true; + + //int upPage = 0; + + if(folderId == 1) + { + session.clearNavigationPath(); + session.pushNavigationItem(QPair(folderId,page)); + t.setVariable(QString("upurl"),"/"); + } + else + { + if(fromUp) + session.popNavigationItem(); + else //drill down or direct access + { + QStack > path = session.getNavigationPath(); + bool found=false; + for(QStack >::const_iterator itr = path.begin(); itr!=path.end(); itr++) + if(itr->first == folderId) + { + found = true; + break; + } + + if(found) + { + while(session.topNavigationItem().first != folderId) + session.popNavigationItem(); + + session.updateTopItem(QPair(folderId,page)); + } + else + session.pushNavigationItem(QPair(folderId,page)); + } + + QStack > path = session.getNavigationPath(); + if(path.count()>1) + { + QPair parentItem = path.at(path.count()-2); + qulonglong upParent = parentItem.first; + quint32 upPage = parentItem.second; + t.setVariable(QString("upurl"),"/library/" + QString::number(libraryId) + "/folder/" +QString("%1?page=%2&up=true").arg(upParent).arg(upPage)); + } else + t.setVariable(QString("upurl"),"/"); + } + + int elementsPerPage = 24; + + int numFolders = folderContent.length(); + //int numComics = folderComics.length(); + int totalLength = folderContent.length() + folderComics.length(); + +// int numFolderPages = numFolders / elementsPerPage + ((numFolders%elementsPerPage)>0?1:0); + int numPages = totalLength / elementsPerPage + ((totalLength%elementsPerPage)>0?1:0); + + //response.writeText(QString("Number of pages : %1
").arg(numPages)); + + if(page < 0) + page = 0; + else if(page >= numPages) + page = numPages-1; + + int indexCurrentPage = page*elementsPerPage; + int numFoldersAtCurrentPage = qMax(0,qMin(numFolders - indexCurrentPage, elementsPerPage)); + + //PATH + QStack > foldersPath = session.getNavigationPath(); + t.setVariable(QString("library.name"),libraryName); + t.setVariable(QString("library.url"),QString("/library/%1/folder/1").arg(libraryId)); + t.loop("path",foldersPath.count()-1); + for(int i = 1; i < foldersPath.count(); i++){ + t.setVariable(QString("path%1.url").arg(i-1),QString("/library/%1/folder/%2").arg(libraryId).arg(foldersPath[i].first)); + t.setVariable(QString("path%1.name").arg(i-1),DBHelper::getFolderName(libraryId,foldersPath[i].first)); + } + + if(folderContent.length() > 0) + { + t.loop("element",numFoldersAtCurrentPage); + int i = 0; + while(iname); + if(item->isDir()) + { + t.setVariable(QString("element%1.class").arg(i),"folder"); + + QList children = DBHelper::getFolderComicsFromLibrary(libraryId, item->id); + if(children.length()>0) + { + const ComicDB * comic = static_cast(children.at(0)); + t.setVariable(QString("element%1.image.url").arg(i),QString("/library/%1/cover/%2.jpg?folderCover=true").arg(libraryId).arg(comic->info.hash)); + } + else + t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png"); + + t.setVariable(QString("element%1.browse").arg(i),QString("BROWSE").arg(QString("/library/%1/folder/%2").arg(libraryId).arg(item->id))); + t.setVariable(QString("element%1.cover.browse").arg(i),QString("").arg(QString("/library/%1/folder/%2").arg(libraryId).arg(item->id))); + t.setVariable(QString("element%1.cover.browse.end").arg(i),""); + //t.setVariable(QString("element%1.url").arg(i),"/library/"+libraryName+"/folder/"+QString("%1").arg(folderContent.at(i + (page*10))->id)); + //t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*elementsPerPage))->id)); + + t.setVariable(QString("element%1.download").arg(i),QString("IMPORT").arg("/library/"+QString::number(libraryId)+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*elementsPerPage))->id))); + t.setVariable(QString("element%1.read").arg(i),""); + + t.setVariable(QString("element%1.size").arg(i),""); + t.setVariable(QString("element%1.pages").arg(i),""); + t.setVariable(QString("element%1.status").arg(i),""); + } + else + { + t.setVariable(QString("element%1.class").arg(i),"cover"); + const ComicDB * comic = (ComicDB *)item; + t.setVariable(QString("element%1.browse").arg(i),""); + //t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/comic/"+QString("%1").arg(comic->id)); + if(!session.isComicOnDevice(comic->info.hash) && !session.isComicDownloaded(comic->info.hash)) + t.setVariable(QString("element%1.download").arg(i),QString("IMPORT").arg("/library/"+QString::number(libraryId)+"/comic/"+QString("%1").arg(comic->id))); + else if (session.isComicOnDevice(comic->info.hash)) + t.setVariable(QString("element%1.download").arg(i),QString("
IMPORTED
")); + else + t.setVariable(QString("element%1.download").arg(i),QString("
IMPORTING
")); + + //t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png"); + + t.setVariable(QString("element%1.read").arg(i),QString("READ").arg("/library/"+QString::number(libraryId)+"/comic/"+QString("%1").arg(comic->id)+"/remote")); + + t.setVariable(QString("element%1.image.url").arg(i),QString("/library/%1/cover/%2.jpg").arg(libraryId).arg(comic->info.hash)); + + t.setVariable(QString("element%1.size").arg(i),"" + QString::number(comic->info.hash.right(comic->info.hash.length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb"); + if(comic->info.hasBeenOpened) + t.setVariable(QString("element%1.pages").arg(i),QString("%1/%2 pages").arg(comic->info.currentPage).arg(comic->info.numPages.toInt())); + else + t.setVariable(QString("element%1.pages").arg(i),QString("%1 pages").arg(comic->info.numPages.toInt())); + + if(comic->info.read) + t.setVariable(QString("element%1.status").arg(i), QString("
")); + else if(comic->info.hasBeenOpened) + t.setVariable(QString("element%1.status").arg(i), QString("
")); + else + t.setVariable(QString("element%1.status").arg(i),""); + + t.setVariable(QString("element%1.cover.browse").arg(i),""); + t.setVariable(QString("element%1.cover.browse.end").arg(i),""); + } + i++; + } + } else + { + t.loop("element",0); + } + + if(numPages > 1) + { + t.setCondition("pageIndex",true); + + QMap indexCount; + + QString firstChar; + int xyz = 1; + for(QList::const_iterator itr=folderContent.constBegin();itr!=folderContent.constEnd();itr++) + { + firstChar = QString((*itr)->name[0]).toUpper(); + firstChar = firstChar.normalized(QString::NormalizationForm_D).at(0);//TODO _D or _KD?? + bool ok; + /*int dec = */firstChar.toInt(&ok, 10); + if(ok) + firstChar = "#"; + //response.writeText(QString("%1 - %2
").arg((*itr)->name).arg(xyz)); + if(indexCount.contains(firstChar)) + indexCount.insert(firstChar, indexCount.value(firstChar)+1); + else + indexCount.insert(firstChar, 1); + + xyz++; + } + + QList index = indexCount.keys(); + if(index.length()>1) + { + t.setCondition("alphaIndex",true); + + qSort(index.begin(),index.end(),naturalSortLessThanCI); + t.loop("index",index.length()); + int i=0; + int count=0; + int indexPage=0; + for(QList::const_iterator itr=index.constBegin();itr!=index.constEnd();itr++) + { + //response.writeText(QString("%1 - %2
").arg(*itr).arg(count)); + t.setVariable(QString("index%1.indexname").arg(i), *itr); + t.setVariable(QString("index%1.url").arg(i),QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(indexPage)); + i++; + count += indexCount.value(*itr); + indexPage = count/elementsPerPage; + } + } + else + { + t.loop("index",0); + t.setCondition("alphaIndex",false); + + } + + t.loop("page",numPages); + int z = 0; + while(z < numPages) + { + + t.setVariable(QString("page%1.url").arg(z),QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(z)); + t.setVariable(QString("page%1.number").arg(z),QString("%1").arg(z+1)); + if(page == z) + t.setVariable(QString("page%1.current").arg(z),"current"); + else + t.setVariable(QString("page%1.current").arg(z),""); + z++; + } + + t.setVariable("page.first",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(0)); + t.setVariable("page.previous",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg((page==0)?page:page-1)); + t.setVariable("page.next",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg((page==numPages-1)?page:page+1)); + t.setVariable("page.last",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(numPages-1)); + t.setCondition("index", true); + } + else + { + + t.loop("page",0); + t.loop("index",0); + t.setCondition("index", false); + t.setCondition("pageIndex",false); + t.setCondition("alphaIndex",false); + } + + t.setVariable("page",QString("%1").arg(page+1)); + t.setVariable("pages",QString("%1").arg(numPages)); + + response.writeText(t, true); + +} diff --git a/YACReaderLibrary/server/controllers/foldercontroller.h b/YACReaderLibrary/server/controllers/foldercontroller.h new file mode 100644 index 00000000..4d757869 --- /dev/null +++ b/YACReaderLibrary/server/controllers/foldercontroller.h @@ -0,0 +1,20 @@ +#ifndef FOLDERCONTROLLER_H +#define FOLDERCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class FolderController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(FolderController); +public: + + /** Constructor */ + FolderController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // FOLDERCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/folderinfocontroller.cpp b/YACReaderLibrary/server/controllers/folderinfocontroller.cpp new file mode 100644 index 00000000..0d8f333f --- /dev/null +++ b/YACReaderLibrary/server/controllers/folderinfocontroller.cpp @@ -0,0 +1,48 @@ +#include "folderinfocontroller.h" +#include "db_helper.h" //get libraries + +#include "folder.h" +#include "comic_db.h" + +#include "template.h" +#include "../static.h" + + +FolderInfoController::FolderInfoController() {} + +void FolderInfoController::service(HttpRequest& request, HttpResponse& response) +{ + response.setHeader("Content-Type", "plain/text; charset=utf-8"); + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + int libraryId = pathElements.at(2).toInt(); + QString libraryName = DBHelper::getLibraryName(libraryId); + qulonglong parentId = pathElements.at(4).toULongLong(); + + serviceComics(libraryId, parentId, response); + + response.writeText("",true); +} + +void FolderInfoController::serviceComics(const int &library, const qulonglong &folderId, HttpResponse &response) +{ + QList folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId); + QList folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId); + + ComicDB * currentComic; + for(QList::const_iterator itr = folderComics.constBegin();itr!=folderComics.constEnd();itr++) + { + currentComic = (ComicDB *)(*itr); + response.writeText(QString("/library/%1/comic/%2:%3:%4\r\n").arg(library).arg(currentComic->id).arg(currentComic->getFileName()).arg(currentComic->getFileSize())); + delete currentComic; + } + + Folder * currentFolder; + for(QList::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++) + { + currentFolder = (Folder *)(*itr); + serviceComics(library, currentFolder->id, response); + delete currentFolder; + } +} diff --git a/YACReaderLibrary/server/controllers/folderinfocontroller.h b/YACReaderLibrary/server/controllers/folderinfocontroller.h new file mode 100644 index 00000000..87df58ce --- /dev/null +++ b/YACReaderLibrary/server/controllers/folderinfocontroller.h @@ -0,0 +1,23 @@ +#ifndef FOLDERINFOCONTROLLER_H +#define FOLDERINFOCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class FolderInfoController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(FolderInfoController); +public: + + /** Constructor */ + FolderInfoController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); + +private: + void serviceComics(const int &library, const qulonglong & folderId, HttpResponse& response); +}; + +#endif // FOLDERINFOCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/formcontroller.cpp b/YACReaderLibrary/server/controllers/formcontroller.cpp new file mode 100644 index 00000000..7a0f2b27 --- /dev/null +++ b/YACReaderLibrary/server/controllers/formcontroller.cpp @@ -0,0 +1,64 @@ +/** + @file + @author Stefan Frings +*/ + +#include "formcontroller.h" +#include + +FormController::FormController() {} + +void FormController::service(HttpRequest& request, HttpResponse& response) { + + response.setHeader("Content-Type", "text/html; charset=utf-8"); + + QString data(request.getBody()); + + QStringList list = data.split("\n"); + + response.write(""); + response.writeText("á é í ó ú ñ -> \\ /Device type: "+list.first()); + + //test background proccesing + /*int i=0; + int j=0; + while(i<1000000000) + { + if(request.getBody().length()>1) + j++; + else + i++; + if(i%1000000 == 0) + response.write("

lista

"); + }*/ + + response.write("

lista

"); + + response.write("
    "); + + for(int i=1;i"+list.at(i)+""); + } + response.write("
",true); + + /*if (request.getParameter("action")=="show") { + response.write(""); + response.write("Name = "); + response.write(request.getParameter("name")); + response.write("
City = "); + response.write(request.getParameter("city")); + response.write("",true); + } + else { + response.write(""); + response.write("
"); + response.write(" "); + response.write(" Name:
"); + response.write(" City:
"); + response.write(" "); + response.write("
"); + response.write("",true); + }*/ +} + diff --git a/YACReaderLibrary/server/controllers/formcontroller.h b/YACReaderLibrary/server/controllers/formcontroller.h new file mode 100644 index 00000000..5ae709a8 --- /dev/null +++ b/YACReaderLibrary/server/controllers/formcontroller.h @@ -0,0 +1,30 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef FORMCONTROLLER_H +#define FORMCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +/** + This controller displays a HTML form and dumps the submitted input. +*/ + + +class FormController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(FormController); +public: + + /** Constructor */ + FormController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // FORMCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/librariescontroller.cpp b/YACReaderLibrary/server/controllers/librariescontroller.cpp new file mode 100644 index 00000000..ac66981c --- /dev/null +++ b/YACReaderLibrary/server/controllers/librariescontroller.cpp @@ -0,0 +1,40 @@ +#include "librariescontroller.h" +#include "db_helper.h" //get libraries +#include "yacreader_libraries.h" + +#include "template.h" +#include "../static.h" + +#include "QsLog.h" + +LibrariesController::LibrariesController() {} + +void LibrariesController::service(HttpRequest& request, HttpResponse& response) +{ + HttpSession session=Static::sessionStore->getSession(request,response,false); + + response.setHeader("Content-Type", "text/html; charset=utf-8"); + response.setHeader("Connection","close"); + + session.clearNavigationPath(); + + Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language")); + t.enableWarnings(); + + YACReaderLibraries libraries = DBHelper::getLibraries(); + QList names = DBHelper::getLibrariesNames(); + + t.loop("library",names.length()); + + int currentId = 0; + int i = 0; + foreach (QString name,names) { + currentId = libraries.getId(name); + t.setVariable(QString("library%1.name").arg(i),QString::number(currentId)); + t.setVariable(QString("library%1.label").arg(i),name); + i++; + } + + response.setStatus(200,"OK"); + response.writeText(t,true); +} diff --git a/YACReaderLibrary/server/controllers/librariescontroller.h b/YACReaderLibrary/server/controllers/librariescontroller.h new file mode 100644 index 00000000..e61d873f --- /dev/null +++ b/YACReaderLibrary/server/controllers/librariescontroller.h @@ -0,0 +1,25 @@ +#ifndef LIBRARIESCONTROLLER_H +#define LIBRARIESCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +/** + This controller displays a HTML form and dumps the submitted input. +*/ + + +class LibrariesController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(LibrariesController); +public: + + /** Constructor */ + LibrariesController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // LIBRARIESCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/pagecontroller.cpp b/YACReaderLibrary/server/controllers/pagecontroller.cpp new file mode 100644 index 00000000..a7bfee90 --- /dev/null +++ b/YACReaderLibrary/server/controllers/pagecontroller.cpp @@ -0,0 +1,96 @@ +#include "pagecontroller.h" + +#include "../static.h" + +#include "comic.h" +#include "comiccontroller.h" +#include +#include + +#include + +#include "db_helper.h" + +PageController::PageController() {} + +void PageController::service(HttpRequest& request, HttpResponse& response) +{ + HttpSession session=Static::sessionStore->getSession(request,response,false); + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + bool remote = path.endsWith("remote"); + + //QByteArray path2=request.getPath(); + //qDebug("PageController: request to -> %s ",path2.data()); + + QStringList pathElements = path.split('/'); + QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt()); + qulonglong comicId = pathElements.at(4).toULongLong(); + unsigned int page = pathElements.at(6).toUInt(); + + //qDebug("lib name : %s",pathElements.at(2).data()); + + Comic * comicFile; + qulonglong currentComicId; + if(remote) + { + QLOG_INFO() << "se recupera comic remoto para servir páginas"; + comicFile = session.getCurrentRemoteComic(); + currentComicId = session.getCurrentRemoteComicId(); + } + else + { + QLOG_INFO() << "se recupera comic para servir páginas"; + comicFile = session.getCurrentComic(); + currentComicId = session.getCurrentComicId(); + } + + if(currentComicId != 0 && !QPointer(comicFile).isNull()) + { + if(comicId == currentComicId && page < comicFile->numPages()) + { + if(comicFile->pageIsLoaded(page)) + { + //qDebug("PageController: La página estaba cargada -> %s ",path.data()); + response.setHeader("Content-Type", "image/jpeg"); + response.setHeader("Transfer-Encoding","chunked"); + QByteArray pageData = comicFile->getRawPage(page); + QDataStream data(pageData); + char buffer[4096]; + while (!data.atEnd()) { + int len = data.readRawData(buffer,4096); + response.write(QByteArray(buffer,len)); + } + //response.write(pageData,true); + response.write(QByteArray(),true); + } + else + { + //qDebug("PageController: La página NO estaba cargada 404 -> %s ",path.data()); + response.setStatus(404,"not found"); //TODO qué mensaje enviar + response.write("404 not found",true); + } + } + else + { + if(comicId != currentComicId) + { + //delete comicFile; + if(remote) + session.dismissCurrentRemoteComic(); + else + session.dismissCurrentComic(); + } + response.setStatus(404,"not found"); //TODO qué mensaje enviar + response.write("404 not found",true); + } + } + else + { + response.setStatus(404,"not found"); + response.write("404 not found",true); + } + + //response.write(t.toLatin1(),true); + +} diff --git a/YACReaderLibrary/server/controllers/pagecontroller.h b/YACReaderLibrary/server/controllers/pagecontroller.h new file mode 100644 index 00000000..64540bc3 --- /dev/null +++ b/YACReaderLibrary/server/controllers/pagecontroller.h @@ -0,0 +1,20 @@ +#ifndef PAGECONTROLLER_H +#define PAGECONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class PageController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(PageController); +public: + + /** Constructor */ + PageController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // PAGECONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/sessioncontroller.cpp b/YACReaderLibrary/server/controllers/sessioncontroller.cpp new file mode 100644 index 00000000..34d56526 --- /dev/null +++ b/YACReaderLibrary/server/controllers/sessioncontroller.cpp @@ -0,0 +1,31 @@ +/** + @file + @author Stefan Frings +*/ + +#include "sessioncontroller.h" +#include "../static.h" +#include +#include + +SessionController::SessionController(){} + +void SessionController::service(HttpRequest& request, HttpResponse& response) { + + response.setHeader("Content-Type", "text/html; charset=ISO-8859-1"); + + // Get current session, or create a new one + HttpSession session=Static::sessionStore->getSession(request,response); + if (!session.contains("startTime")) { + response.write("New session started. Reload this page now."); + session.set("startTime",QDateTime::currentDateTime()); + } + + else { + QDateTime startTime=session.get("startTime").toDateTime(); + response.write("Your session started "); + response.write(startTime.toString().toLatin1()); + response.write(""); + } + +} diff --git a/YACReaderLibrary/server/controllers/sessioncontroller.h b/YACReaderLibrary/server/controllers/sessioncontroller.h new file mode 100644 index 00000000..a13ee51f --- /dev/null +++ b/YACReaderLibrary/server/controllers/sessioncontroller.h @@ -0,0 +1,29 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef SESSIONCONTROLLER_H +#define SESSIONCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +/** + This controller demonstrates how to use sessions. +*/ + +class SessionController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(SessionController); +public: + + /** Constructor */ + SessionController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // SESSIONCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/sessionmanager.cpp b/YACReaderLibrary/server/controllers/sessionmanager.cpp new file mode 100644 index 00000000..e69de29b diff --git a/YACReaderLibrary/server/controllers/sessionmanager.h b/YACReaderLibrary/server/controllers/sessionmanager.h new file mode 100644 index 00000000..e69de29b diff --git a/YACReaderLibrary/server/controllers/synccontroller.cpp b/YACReaderLibrary/server/controllers/synccontroller.cpp new file mode 100644 index 00000000..7c4c1859 --- /dev/null +++ b/YACReaderLibrary/server/controllers/synccontroller.cpp @@ -0,0 +1,55 @@ +#include "synccontroller.h" + +#include "QsLog.h" +#include + +#include "comic_db.h" +#include "db_helper.h" + +SyncController::SyncController() +{ + +} + +void SyncController::service(HttpRequest &request, HttpResponse &response) +{ + QString postData = QString::fromUtf8(request.getBody()); + + QLOG_INFO() << "POST DATA: " << postData; + + if(postData.length()>0) { + QList data = postData.split("\n"); + + qulonglong libraryId; + qulonglong comicId; + int currentPage; + QString hash; + foreach(QString comicInfo, data) + { + QList comicInfoProgress = comicInfo.split("\t"); + + if(comicInfoProgress.length() == 4) + { + libraryId = comicInfoProgress.at(0).toULongLong(); + comicId = comicInfoProgress.at(1).toULongLong(); + hash = comicInfoProgress.at(2); + currentPage = comicInfoProgress.at(3).toInt(); + + ComicInfo info; + info.currentPage = currentPage; + info.hash = hash; //TODO remove the hash check and add UUIDs for libraries + info.id = comicId; + DBHelper::updateFromRemoteClient(libraryId,info); + } + } + } + else + { + response.setStatus(412,"No comic info received"); + response.writeText("",true); + return; + } + + response.write("OK",true); +} + diff --git a/YACReaderLibrary/server/controllers/synccontroller.h b/YACReaderLibrary/server/controllers/synccontroller.h new file mode 100644 index 00000000..6f6a5d76 --- /dev/null +++ b/YACReaderLibrary/server/controllers/synccontroller.h @@ -0,0 +1,21 @@ +#ifndef SYNCCONTROLLER_H +#define SYNCCONTROLLER_H + +#include + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class SyncController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(SyncController); +public: + /** Constructor */ + SyncController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // SYNCCONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/templatecontroller.cpp b/YACReaderLibrary/server/controllers/templatecontroller.cpp new file mode 100644 index 00000000..d1816808 --- /dev/null +++ b/YACReaderLibrary/server/controllers/templatecontroller.cpp @@ -0,0 +1,31 @@ +/** + @file + @author Stefan Frings +*/ + +#include "templatecontroller.h" +#include "template.h" +#include "../static.h" + +TemplateController::TemplateController(){} + +void TemplateController::service(HttpRequest& request, HttpResponse& response) { + + response.setHeader("Content-Type", "text/html; charset=ISO-8859-1"); + + Template t=Static::templateLoader->getTemplate("demo",request.getHeader("Accept-Language")); + t.enableWarnings(); + t.setVariable("path",request.getPath()); + QMap headers=request.getHeaderMap(); + QMapIterator iterator(headers); + t.loop("header",headers.size()); + int i=0; + while (iterator.hasNext()) { + iterator.next(); + t.setVariable(QString("header%1.name").arg(i),QString(iterator.key())); + t.setVariable(QString("header%1.value").arg(i),QString(iterator.value())); + ++i; + } + + response.write(t.toLatin1(),true); +} diff --git a/YACReaderLibrary/server/controllers/templatecontroller.h b/YACReaderLibrary/server/controllers/templatecontroller.h new file mode 100644 index 00000000..c5b0077d --- /dev/null +++ b/YACReaderLibrary/server/controllers/templatecontroller.h @@ -0,0 +1,30 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef TEMPLATECONTROLLER_H +#define TEMPLATECONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +/** + This controller generates a website using the template engine. + It generates a Latin1 (ISO-8859-1) encoded website from a UTF-8 encoded template file. +*/ + +class TemplateController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(TemplateController); + public: + + /** Constructor */ + TemplateController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); + }; + +#endif // TEMPLATECONTROLLER_H diff --git a/YACReaderLibrary/server/controllers/updatecomiccontroller.cpp b/YACReaderLibrary/server/controllers/updatecomiccontroller.cpp new file mode 100644 index 00000000..038fa7e2 --- /dev/null +++ b/YACReaderLibrary/server/controllers/updatecomiccontroller.cpp @@ -0,0 +1,46 @@ +#include "updatecomiccontroller.h" + +#include "db_helper.h" +#include "yacreader_libraries.h" + +#include "template.h" +#include "../static.h" + +#include "comic_db.h" +#include "comic.h" + +#include "QsLog.h" + +UpdateComicController::UpdateComicController(){} + +void UpdateComicController::service(HttpRequest &request, HttpResponse &response) +{ + HttpSession session=Static::sessionStore->getSession(request,response,false); + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + qulonglong libraryId = pathElements.at(2).toULongLong(); + QString libraryName = DBHelper::getLibraryName(libraryId); + qulonglong comicId = pathElements.at(4).toULongLong(); + + QString postData = QString::fromUtf8(request.getBody()); + + QLOG_INFO() << "POST DATA: " << postData; + + if(postData.length()>0) { + QList data = postData.split("\n"); + int currentPage = data.at(0).split(":").at(1).toInt(); + ComicInfo info; + info.currentPage = currentPage; + info.id = comicId; + DBHelper::updateProgress(libraryId,info); + } + else + { + response.setStatus(412,"No comic info received"); + response.writeText("",true); + return; + } + + response.write("OK",true); +} diff --git a/YACReaderLibrary/server/controllers/updatecomiccontroller.h b/YACReaderLibrary/server/controllers/updatecomiccontroller.h new file mode 100644 index 00000000..13ec4f58 --- /dev/null +++ b/YACReaderLibrary/server/controllers/updatecomiccontroller.h @@ -0,0 +1,22 @@ +#ifndef UPDATECOMICCONTROLLER_H +#define UPDATECOMICCONTROLLER_H + + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + + +class UpdateComicController : public HttpRequestHandler +{ + Q_OBJECT + Q_DISABLE_COPY(UpdateComicController); + +public: + UpdateComicController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); +}; + +#endif // UPDATECOMICCONTROLLER_H diff --git a/YACReaderLibrary/server/documentcache.h b/YACReaderLibrary/server/documentcache.h new file mode 100644 index 00000000..06ff67ac --- /dev/null +++ b/YACReaderLibrary/server/documentcache.h @@ -0,0 +1,4 @@ +#ifndef DOCUMENTCACHE_H +#define DOCUMENTCACHE_H + +#endif // DOCUMENTCACHE_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/bfHttpServer.pri b/YACReaderLibrary/server/lib/bfHttpServer/bfHttpServer.pri new file mode 100644 index 00000000..a109a573 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/bfHttpServer.pri @@ -0,0 +1,12 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +HEADERS += $$PWD/httplistener.h $$PWD/httpconnectionhandler.h $$PWD/httpconnectionhandlerpool.h $$PWD/httprequest.h $$PWD/httpresponse.h $$PWD/httpcookie.h $$PWD/httprequesthandler.h +HEADERS += $$PWD/httpsession.h $$PWD/httpsessionstore.h +HEADERS += $$PWD/staticfilecontroller.h + +SOURCES += $$PWD/httplistener.cpp $$PWD/httpconnectionhandler.cpp $$PWD/httpconnectionhandlerpool.cpp $$PWD/httprequest.cpp $$PWD/httpresponse.cpp $$PWD/httpcookie.cpp $$PWD/httprequesthandler.cpp +SOURCES += $$PWD/httpsession.cpp $$PWD/httpsessionstore.cpp +SOURCES += $$PWD/staticfilecontroller.cpp + +OTHER_FILES += $$PWD/../doc/readme.txt diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandler.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandler.cpp new file mode 100644 index 00000000..b1044b4a --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandler.cpp @@ -0,0 +1,170 @@ +/** + @file + @author Stefan Frings +*/ + +#include "httpconnectionhandler.h" +#include "httpresponse.h" +#include +#include + +HttpConnectionHandler::HttpConnectionHandler(QSettings* settings, HttpRequestHandler* requestHandler) + : QThread() +{ + Q_ASSERT(settings!=0); + Q_ASSERT(requestHandler!=0); + this->settings=settings; + this->requestHandler=requestHandler; + currentRequest=0; + busy = false; + // execute signals in my own thread + moveToThread(this); + socket.moveToThread(this); + readTimer.moveToThread(this); + connect(&socket, SIGNAL(readyRead()), SLOT(read())); + connect(&socket, SIGNAL(disconnected()), SLOT(disconnected())); + connect(&readTimer, SIGNAL(timeout()), SLOT(readTimeout())); + readTimer.setSingleShot(true); + qDebug("HttpConnectionHandler (%p): constructed", this); + this->start(); +} + + +HttpConnectionHandler::~HttpConnectionHandler() { + socket.close(); + quit(); + wait(); + qDebug("HttpConnectionHandler (%p): destroyed", this); +} + + +void HttpConnectionHandler::run() { + qDebug("HttpConnectionHandler (%p): thread started", this); + try { + exec(); + } + catch (...) { + qCritical("HttpConnectionHandler (%p): an uncatched exception occured in the thread",this); + } + qDebug("HttpConnectionHandler (%p): thread stopped", this); + // Change to the main thread, otherwise deleteLater() would not work + moveToThread(QCoreApplication::instance()->thread()); +} + + +void HttpConnectionHandler::handleConnection(tSocketDescriptor socketDescriptor) { + qDebug("HttpConnectionHandler (%p): handle new connection", this); + busy = true; + Q_ASSERT(socket.isOpen()==false); // if not, then the handler is already busy + + if (!socket.setSocketDescriptor(socketDescriptor)) { + qCritical("HttpConnectionHandler (%p): cannot initialize socket: %s", this,qPrintable(socket.errorString())); + return; + } + // Start timer for read timeout + int readTimeout=settings->value("readTimeout",10000).toInt(); + readTimer.start(readTimeout); + // delete previous request + delete currentRequest; + currentRequest=0; +} + + +bool HttpConnectionHandler::isBusy() { + return busy; +} + +void HttpConnectionHandler::setBusy() { + this->busy = true; +} + + +void HttpConnectionHandler::readTimeout() { + qDebug("HttpConnectionHandler (%p): read timeout occured",this); + + //Commented out because QWebView cannot handle this. + //socket.write("HTTP/1.1 408 request timeout\r\nConnection: close\r\n\r\n408 request timeout\r\n"); + + socket.disconnectFromHost(); + delete currentRequest; + currentRequest=0; +} + + +void HttpConnectionHandler::disconnected() { + qDebug("HttpConnectionHandler (%p): disconnected", this); + socket.close(); + readTimer.stop(); + busy = false; +} + +void HttpConnectionHandler::read() { + while (socket.bytesAvailable()) { +#ifdef SUPERVERBOSE + qDebug("HttpConnectionHandler (%p): read input",this); +#endif + + // Create new HttpRequest object if necessary + if (!currentRequest) { + currentRequest=new HttpRequest(settings); + } + + // Collect data for the request object + while (socket.bytesAvailable() && currentRequest->getStatus()!=HttpRequest::complete && currentRequest->getStatus()!=HttpRequest::abort) { + currentRequest->readFromSocket(socket); + if (currentRequest->getStatus()==HttpRequest::waitForBody) { + // Restart timer for read timeout, otherwise it would + // expire during large file uploads. + int readTimeout=settings->value("readTimeout",10000).toInt(); + readTimer.start(readTimeout); + } + } + + // If the request is aborted, return error message and close the connection + if (currentRequest->getStatus()==HttpRequest::abort) { + socket.write("HTTP/1.1 413 entity too large\r\nConnection: close\r\n\r\n413 Entity too large\r\n"); + socket.disconnectFromHost(); + delete currentRequest; + currentRequest=0; + return; + } + + // If the request is complete, let the request mapper dispatch it + if (currentRequest->getStatus()==HttpRequest::complete) { + readTimer.stop(); + qDebug("HttpConnectionHandler (%p): received request",this); + HttpResponse response(&socket); + //response.setHeader("Connection","close"); No funciona bien con NSURLConnection + try { + requestHandler->service(*currentRequest, response); + } + catch (...) { + qCritical("HttpConnectionHandler (%p): An uncatched exception occured in the request handler",this); + } + + // Finalize sending the response if not already done + if (!response.hasSentLastPart()) { + response.write(QByteArray(),true); + } + + //socket.disconnectFromHost(); //CAMBIADO sólo se van a soportar conexiones NO persistentes + + // Close the connection after delivering the response, if requested + if (QString::compare(currentRequest->getHeader("Connection"),"close",Qt::CaseInsensitive)==0) { + socket.disconnectFromHost(); + } + else { + // Start timer for next request + int readTimeout=settings->value("readTimeout",10000).toInt(); + readTimer.start(readTimeout); + } + // Prepare for next request + delete currentRequest; + currentRequest=0; + } + else + { + qDebug("HttpConnectionHandler (%p): received request",this); + } + } +} diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandler.h b/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandler.h new file mode 100644 index 00000000..0e8b4483 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandler.h @@ -0,0 +1,103 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef HTTPCONNECTIONHANDLER_H +#define HTTPCONNECTIONHANDLER_H + +#include +#include +#include +#include +#include "httprequest.h" +#include "httprequesthandler.h" + +/** + The connection handler accepts incoming connections and dispatches incoming requests to to a + request mapper. Since HTTP clients can send multiple requests before waiting for the response, + the incoming requests are queued and processed one after the other. +

+ Example for the required configuration settings: +

+  readTimeout=60000
+  maxRequestSize=16000
+  maxMultiPartSize=1000000
+  
+

+ The readTimeout value defines the maximum time to wait for a complete HTTP request. + @see HttpRequest for description of config settings maxRequestSize and maxMultiPartSize +*/ + +#if QT_VERSION >= 0x050000 + typedef qintptr tSocketDescriptor; +#else + typedef int tSocketDescriptor; +#endif + +class HttpConnectionHandler : public QThread { + Q_OBJECT + Q_DISABLE_COPY(HttpConnectionHandler) +public: + + /** + Constructor. + @param settings Configuration settings of the HTTP webserver + @param requestHandler handler that will process each incomin HTTP request + */ + HttpConnectionHandler(QSettings* settings, HttpRequestHandler* requestHandler); + + /** Destructor */ + virtual ~HttpConnectionHandler(); + + /** Returns true, if this handler is in use. */ + bool isBusy(); + + /** Mark this handler as busy */ + void setBusy(); + +private: + + /** Configuration settings */ + QSettings* settings; + + /** TCP socket of the current connection */ + QTcpSocket socket; + + /** Time for read timeout detection */ + QTimer readTimer; + + /** Storage for the current incoming HTTP request */ + HttpRequest* currentRequest; + + /** Dispatches received requests to services */ + HttpRequestHandler* requestHandler; + + /** This shows the busy-state from a very early time */ + bool busy; + + /** Executes the htreads own event loop */ + void run(); + +public slots: + + /** + Received from from the listener, when the handler shall start processing a new connection. + @param socketDescriptor references the accepted connection. + */ + void handleConnection(tSocketDescriptor socketDescriptor); + +private slots: + + /** Received from the socket when a read-timeout occured */ + void readTimeout(); + + /** Received from the socket when incoming data can be read */ + void read(); + + /** Received from the socket when a connection has been closed */ + void disconnected(); + +}; + +#endif // HTTPCONNECTIONHANDLER_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandlerpool.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandlerpool.cpp new file mode 100644 index 00000000..fbf70b49 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandlerpool.cpp @@ -0,0 +1,64 @@ +#include "httpconnectionhandlerpool.h" + +HttpConnectionHandlerPool::HttpConnectionHandlerPool(QSettings* settings, HttpRequestHandler* requestHandler) + : QObject() +{ + Q_ASSERT(settings!=0); + this->settings=settings; + this->requestHandler=requestHandler; + cleanupTimer.start(settings->value("cleanupInterval",10000).toInt()); + connect(&cleanupTimer, SIGNAL(timeout()), SLOT(cleanup())); +} + + +HttpConnectionHandlerPool::~HttpConnectionHandlerPool() { + foreach(HttpConnectionHandler* handler, pool) { + connect(handler,SIGNAL(finished()),handler,SLOT(deleteLater())); + handler->quit(); + } +} + + +HttpConnectionHandler* HttpConnectionHandlerPool::getConnectionHandler() { + HttpConnectionHandler* freeHandler=0; + mutex.lock(); + // find a free handler in pool + foreach(HttpConnectionHandler* handler, pool) { + if (!handler->isBusy()) { + freeHandler=handler; + freeHandler->setBusy(); + break; + } + } + // create a new handler, if necessary + if (!freeHandler) { + int maxConnectionHandlers=settings->value("maxThreads",1000).toInt(); + if (pool.count()setBusy(); + pool.append(freeHandler); + } + } + mutex.unlock(); + return freeHandler; +} + + + +void HttpConnectionHandlerPool::cleanup() { + int maxIdleHandlers=settings->value("minThreads",50).toInt(); + int idleCounter=0; + mutex.lock(); + foreach(HttpConnectionHandler* handler, pool) { + if (!handler->isBusy()) { + if (++idleCounter > maxIdleHandlers) { + pool.removeOne(handler); + qDebug("HttpConnectionHandlerPool: Removed connection handler (%p), pool size is now %i",handler,pool.size()); + connect(handler,SIGNAL(finished()),handler,SLOT(deleteLater())); + handler->quit(); + break; // remove only one handler in each interval + } + } + } + mutex.unlock(); +} diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandlerpool.h b/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandlerpool.h new file mode 100644 index 00000000..2dc94338 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpconnectionhandlerpool.h @@ -0,0 +1,73 @@ +#ifndef HTTPCONNECTIONHANDLERPOOL_H +#define HTTPCONNECTIONHANDLERPOOL_H + +#include +#include +#include +#include +#include "httpconnectionhandler.h" + +/** + Pool of http connection handlers. Connection handlers are created on demand and idle handlers are + cleaned up in regular time intervals. +

+ Example for the required configuration settings: +

+  minThreads=1
+  maxThreads=100
+  cleanupInterval=1000
+  maxRequestSize=16000
+  maxMultiPartSize=1000000
+  
+ The pool is empty initially and grows with the number of concurrent + connections. A timer removes one idle connection handler at each + interval, but it leaves some spare handlers in memory to improve + performance. + @see HttpConnectionHandler for description of config settings readTimeout + @see HttpRequest for description of config settings maxRequestSize and maxMultiPartSize +*/ + +class HttpConnectionHandlerPool : public QObject { + Q_OBJECT + Q_DISABLE_COPY(HttpConnectionHandlerPool) +public: + + /** + Constructor. + @param settings Configuration settings for the HTTP server. Must not be 0. + @param requestHandler The handler that will process each received HTTP request. + @warning The requestMapper gets deleted by the destructor of this pool + */ + HttpConnectionHandlerPool(QSettings* settings, HttpRequestHandler* requestHandler); + + /** Destructor */ + virtual ~HttpConnectionHandlerPool(); + + /** Get a free connection handler, or 0 if not available. */ + HttpConnectionHandler* getConnectionHandler(); + +private: + + /** Settings for this pool */ + QSettings* settings; + + /** Will be assigned to each Connectionhandler during their creation */ + HttpRequestHandler* requestHandler; + + /** Pool of connection handlers */ + QList pool; + + /** Timer to clean-up unused connection handler */ + QTimer cleanupTimer; + + /** Used to synchronize threads */ + QMutex mutex; + +private slots: + + /** Received from the clean-up timer. */ + void cleanup(); + +}; + +#endif // HTTPCONNECTIONHANDLERPOOL_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpcookie.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httpcookie.cpp new file mode 100644 index 00000000..3f5be929 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpcookie.cpp @@ -0,0 +1,199 @@ +/** + @file + @author Stefan Frings +*/ + +#include "httpcookie.h" + +HttpCookie::HttpCookie() { + version=1; + maxAge=0; + secure=false; +} + +HttpCookie::HttpCookie(const QByteArray name, const QByteArray value, const int maxAge, const QByteArray path, const QByteArray comment, const QByteArray domain, const bool secure) { + this->name=name; + this->value=value; + this->maxAge=maxAge; + this->path=path; + this->comment=comment; + this->domain=domain; + this->secure=secure; + this->version=1; +} + +HttpCookie::HttpCookie(const QByteArray source) { + version=1; + maxAge=0; + secure=false; + QList list=splitCSV(source); + foreach(QByteArray part, list) { + + // Split the part into name and value + QByteArray name; + QByteArray value; + int posi=part.indexOf('='); + if (posi) { + name=part.left(posi).trimmed(); + value=part.mid(posi+1).trimmed(); + } + else { + name=part.trimmed(); + value=""; + } + + // Set fields + if (name=="Comment") { + comment=value; + } + else if (name=="Domain") { + domain=value; + } + else if (name=="Max-Age") { + maxAge=value.toInt(); + } + else if (name=="Path") { + path=value; + } + else if (name=="Secure") { + secure=true; + } + else if (name=="Version") { + version=value.toInt(); + } + else { + if (this->name.isEmpty()) { + this->name=name; + this->value=value; + } + else { + qWarning("HttpCookie: Ignoring unknown %s=%s",name.data(),value.data()); + } + } + } +} + +QByteArray HttpCookie::toByteArray() const { + QByteArray buffer(name); + buffer.append('='); + buffer.append(value); + if (!comment.isEmpty()) { + buffer.append("; Comment="); + buffer.append(comment); + } + if (!domain.isEmpty()) { + buffer.append("; Domain="); + buffer.append(domain); + } + if (maxAge!=0) { + buffer.append("; Max-Age="); + buffer.append(QByteArray::number(maxAge)); + } + if (!path.isEmpty()) { + buffer.append("; Path="); + buffer.append(path); + } + if (secure) { + buffer.append("; Secure"); + } + buffer.append("; Version="); + buffer.append(QByteArray::number(version)); + return buffer; +} + +void HttpCookie::setName(const QByteArray name){ + this->name=name; +} + +void HttpCookie::setValue(const QByteArray value){ + this->value=value; +} + +void HttpCookie::setComment(const QByteArray comment){ + this->comment=comment; +} + +void HttpCookie::setDomain(const QByteArray domain){ + this->domain=domain; +} + +void HttpCookie::setMaxAge(const int maxAge){ + this->maxAge=maxAge; +} + +void HttpCookie::setPath(const QByteArray path){ + this->path=path; +} + +void HttpCookie::setSecure(const bool secure){ + this->secure=secure; +} + +QByteArray HttpCookie::getName() const { + return name; +} + +QByteArray HttpCookie::getValue() const { + return value; +} + +QByteArray HttpCookie::getComment() const { + return comment; +} + +QByteArray HttpCookie::getDomain() const { + return domain; +} + +int HttpCookie::getMaxAge() const { + return maxAge; +} + +QByteArray HttpCookie::getPath() const { + return path; +} + +bool HttpCookie::getSecure() const { + return secure; +} + +int HttpCookie::getVersion() const { + return version; +} + +QList HttpCookie::splitCSV(const QByteArray source) { + bool inString=false; + QList list; + QByteArray buffer; + for (int i=0; i +#include + +/** + HTTP cookie as defined in RFC 2109. This class can also parse + RFC 2965 cookies, but skips fields that are not defined in RFC + 2109. +*/ + +class HttpCookie +{ +public: + + /** Creates an empty cookie */ + HttpCookie(); + + /** + Create a cookie and set name/value pair. + @param name name of the cookie + @param value value of the cookie + @param maxAge maximum age of the cookie in seconds. 0=discard immediately + @param path Path for that the cookie will be sent, default="/" which means the whole domain + @param comment Optional comment, may be displayed by the web browser somewhere + @param domain Optional domain for that the cookie will be sent. Defaults to the current domain + @param secure If true, the cookie will only be sent on secure connections + */ + HttpCookie(const QByteArray name, const QByteArray value, const int maxAge, const QByteArray path="/", const QByteArray comment=QByteArray(), const QByteArray domain=QByteArray(), const bool secure=false); + + /** + Create a cookie from a string. + @param source String as received in a HTTP Cookie2 header. + */ + HttpCookie(const QByteArray source); + + /** Convert this cookie to a string that may be used in a Set-Cookie2 header. */ + QByteArray toByteArray() const ; + + /** + Split a string list into parts, where each part is delimited by semicolon. + Semicolons within double quotes are skipped. Double quotes are removed. + */ + static QList splitCSV(const QByteArray source); + + /** Set the name of this cookie */ + void setName(const QByteArray name); + + /** Set the value of this cookie */ + void setValue(const QByteArray value); + + /** Set the comment of this cookie */ + void setComment(const QByteArray comment); + + /** Set the domain of this cookie */ + void setDomain(const QByteArray domain); + + /** Set the maximum age of this cookie in seconds. 0=discard immediately */ + void setMaxAge(const int maxAge); + + /** Set the path for that the cookie will be sent, default="/" which means the whole domain */ + void setPath(const QByteArray path); + + /** Set secure mode, so that the cokkie will only be sent on secure connections */ + void setSecure(const bool secure); + + /** Get the name of this cookie */ + QByteArray getName() const; + + /** Get the value of this cookie */ + QByteArray getValue() const; + + /** Get the comment of this cookie */ + QByteArray getComment() const; + + /** Get the domain of this cookie */ + QByteArray getDomain() const; + + /** Set the maximum age of this cookie in seconds. */ + int getMaxAge() const; + + /** Set the path of this cookie */ + QByteArray getPath() const; + + /** Get the secure flag of this cookie */ + bool getSecure() const; + + /** Returns always 1 */ + int getVersion() const; + +private: + + QByteArray name; + QByteArray value; + QByteArray comment; + QByteArray domain; + int maxAge; + QByteArray path; + bool secure; + int version; + +}; + +#endif // HTTPCOOKIE_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httplistener.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httplistener.cpp new file mode 100644 index 00000000..b79db686 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httplistener.cpp @@ -0,0 +1,68 @@ +/** + @file + @author Stefan Frings +*/ + +#include "httplistener.h" +#include "httpconnectionhandler.h" +#include "httpconnectionhandlerpool.h" +#include + +HttpListener::HttpListener(QSettings* settings, HttpRequestHandler* requestHandler, QObject *parent) + : QTcpServer(parent) +{ + Q_ASSERT(settings!=0); + // Reqister type of socketDescriptor for signal/slot handling + qRegisterMetaType("tSocketDescriptor"); + // Create connection handler pool + this->settings=settings; + pool=new HttpConnectionHandlerPool(settings,requestHandler); + // Start listening + int port=settings->value("port",8080).toInt(); + listen(QHostAddress::Any, port); + //Cambiado + int i = 0; + while (!isListening() && i < 1000) { + listen(QHostAddress::Any, (rand() % 45535)+20000); + i++; + } + if(!isListening()) + { + qCritical("HttpListener: Cannot bind on port %i: %s",port,qPrintable(errorString())); + } + else { + qDebug("HttpListener: Listening on port %i",port); + } +} + +HttpListener::~HttpListener() { + close(); + qDebug("HttpListener: closed"); + delete pool; + qDebug("HttpListener: destroyed"); +} + +void HttpListener::incomingConnection(tSocketDescriptor socketDescriptor) { +#ifdef SUPERVERBOSE + qDebug("HttpListener: New connection"); +#endif + HttpConnectionHandler* freeHandler=pool->getConnectionHandler(); + + // Let the handler process the new connection. + if (freeHandler) { + // The descriptor is passed via signal/slot because the handler lives in another + // thread and cannot open the socket when called by another thread. + connect(this,SIGNAL(handleConnection(tSocketDescriptor)),freeHandler,SLOT(handleConnection(tSocketDescriptor))); + emit handleConnection(socketDescriptor); + disconnect(this,SIGNAL(handleConnection(tSocketDescriptor)),freeHandler,SLOT(handleConnection(tSocketDescriptor))); + } + else { + // Reject the connection + qDebug("HttpListener: Too many connections"); + QTcpSocket* socket=new QTcpSocket(this); + socket->setSocketDescriptor(socketDescriptor); + connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater())); + socket->write("HTTP/1.1 503 too many connections\r\nConnection: close\r\n\r\nToo many connections\r\n"); + socket->disconnectFromHost(); + } +} diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httplistener.h b/YACReaderLibrary/server/lib/bfHttpServer/httplistener.h new file mode 100644 index 00000000..6ae5d75c --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httplistener.h @@ -0,0 +1,76 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef LISTENER_H +#define LISTENER_H + +#include +#include +#include +#include "httpconnectionhandler.h" +#include "httpconnectionhandlerpool.h" +#include "httprequesthandler.h" + +/** + Listens for incoming TCP connections and and passes all incoming HTTP requests to your implementation of HttpRequestHandler, + which processes the request and generates the response (usually a HTML document). +

+ Example for the required settings in the config file: +

+  port=8080
+  minThreads=1
+  maxThreads=10
+  cleanupInterval=1000
+  readTimeout=60000
+  maxRequestSize=16000
+  maxMultiPartSize=1000000
+  
+ The port number is the incoming TCP port that this listener listens to. + @see HttpConnectionHandlerPool for description of config settings minThreads, maxThreads and cleanupInterval + @see HttpConnectionHandler for description of config settings readTimeout + @see HttpRequest for description of config settings maxRequestSize and maxMultiPartSize +*/ + +class HttpListener : public QTcpServer { + Q_OBJECT + Q_DISABLE_COPY(HttpListener) +public: + + /** + Constructor. + @param settings Configuration settings for the HTTP server. Must not be 0. + @param requestHandler Processes each received HTTP request, usually by dispatching to controller classes. + @param parent Parent object. + */ + HttpListener(QSettings* settings, HttpRequestHandler* requestHandler, QObject* parent = 0); + + /** Destructor */ + virtual ~HttpListener(); + +protected: + + /** Serves new incoming connection requests */ + void incomingConnection(tSocketDescriptor socketDescriptor); + +private: + + /** Configuration settings for the HTTP server */ + QSettings* settings; + + /** Pool of connection handlers */ + HttpConnectionHandlerPool* pool; + +signals: + + /** + Emitted when the connection handler shall process a new incoming onnection. + @param socketDescriptor references the accepted connection. + */ + + void handleConnection(tSocketDescriptor socketDescriptor); + +}; + +#endif // LISTENER_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httprequest.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httprequest.cpp new file mode 100644 index 00000000..8ed427b5 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httprequest.cpp @@ -0,0 +1,431 @@ +/** + @file + @author Stefan Frings +*/ + +#include "httprequest.h" +#include +#include +#include "httpcookie.h" + +HttpRequest::HttpRequest(QSettings* settings) { + status=waitForRequest; + currentSize=0; + expectedBodySize=0; + maxSize=settings->value("maxRequestSize","32000000").toInt(); + maxMultiPartSize=settings->value("maxMultiPartSize","32000000").toInt(); +} + +void HttpRequest::readRequest(QTcpSocket& socket) { +#ifdef SUPERVERBOSE + qDebug("HttpRequest: read request"); +#endif + int toRead=maxSize-currentSize+1; // allow one byte more to be able to detect overflow + QByteArray newData=socket.readLine(toRead).trimmed(); + currentSize+=newData.size(); + if (!newData.isEmpty()) { + QList list=newData.split(' '); + if (list.count()!=3 || !list.at(2).contains("HTTP")) { + qWarning("HttpRequest: received broken HTTP request, invalid first line"); + status=abort; + } + else { + method=list.at(0); + path=list.at(1); + version=list.at(2); + status=waitForHeader; + } + } +} + +void HttpRequest::readHeader(QTcpSocket& socket) { +#ifdef SUPERVERBOSE + qDebug("HttpRequest: read header"); +#endif + int toRead=maxSize-currentSize+1; // allow one byte more to be able to detect overflow + QByteArray newData=socket.readLine(toRead).trimmed(); + currentSize+=newData.size(); + int colon=newData.indexOf(':'); + if (colon>0) { + // Received a line with a colon - a header + currentHeader=newData.left(colon); + QByteArray value=newData.mid(colon+1).trimmed(); + headers.insert(currentHeader,value); +#ifdef SUPERVERBOSE + qDebug("HttpRequest: received header %s: %s",currentHeader.data(),value.data()); +#endif + } + else if (!newData.isEmpty()) { + // received another line - belongs to the previous header +#ifdef SUPERVERBOSE + qDebug("HttpRequest: read additional line of header"); +#endif + // Received additional line of previous header + if (headers.contains(currentHeader)) { + headers.insert(currentHeader,headers.value(currentHeader)+" "+newData); + } + } + else { + // received an empty line - end of headers reached +#ifdef SUPERVERBOSE + qDebug("HttpRequest: headers completed"); +#endif + // Empty line received, that means all headers have been received + // Check for multipart/form-data + QByteArray contentType=headers.value("Content-Type"); + if (contentType.startsWith("multipart/form-data")) { + int posi=contentType.indexOf("boundary="); + if (posi>=0) { + boundary=contentType.mid(posi+9); + } + } + QByteArray contentLength=getHeader("Content-Length"); + if (!contentLength.isEmpty()) { + expectedBodySize=contentLength.toInt(); + } + if (expectedBodySize==0) { +#ifdef SUPERVERBOSE + qDebug("HttpRequest: expect no body"); +#endif + status=complete; + } + else if (boundary.isEmpty() && expectedBodySize+currentSize>maxSize) { + qWarning("HttpRequest: expected body is too large"); + status=abort; + } + else if (!boundary.isEmpty() && expectedBodySize>maxMultiPartSize) { + qWarning("HttpRequest: expected multipart body is too large"); + status=abort; + } + else { +#ifdef SUPERVERBOSE + qDebug("HttpRequest: expect %i bytes body",expectedBodySize); +#endif + status=waitForBody; + } + } +} + +void HttpRequest::readBody(QTcpSocket& socket) { + Q_ASSERT(expectedBodySize!=0); + if (boundary.isEmpty()) { + // normal body, no multipart +#ifdef SUPERVERBOSE + qDebug("HttpRequest: receive body"); +#endif + int toRead=expectedBodySize-bodyData.size(); + QByteArray newData=socket.read(toRead); + currentSize+=newData.size(); + bodyData.append(newData); + if (bodyData.size()>=expectedBodySize) { + status=complete; + } + } + else { + // multipart body, store into temp file +#ifdef SUPERVERBOSE + qDebug("HttpRequest: receiving multipart body"); +#endif + if (!tempFile.isOpen()) { + tempFile.open(); + } + // Transfer data in 64kb blocks + int fileSize=tempFile.size(); + int toRead=expectedBodySize-fileSize; + if (toRead>65536) { + toRead=65536; + } + fileSize+=tempFile.write(socket.read(toRead)); + if (fileSize>=maxMultiPartSize) { + qWarning("HttpRequest: received too many multipart bytes"); + status=abort; + } + else if (fileSize>=expectedBodySize) { +#ifdef SUPERVERBOSE + qDebug("HttpRequest: received whole multipart body"); +#endif + tempFile.flush(); + if (tempFile.error()) { + qCritical("HttpRequest: Error writing temp file for multipart body"); + } + parseMultiPartFile(); + tempFile.close(); + status=complete; + } + } +} + +void HttpRequest::decodeRequestParams() { +#ifdef SUPERVERBOSE + qDebug("HttpRequest: extract and decode request parameters"); +#endif + // Get URL parameters + QByteArray rawParameters; + int questionMark=path.indexOf('?'); + if (questionMark>=0) { + rawParameters=path.mid(questionMark+1); + path=path.left(questionMark); + } + // Get request body parameters + QByteArray contentType=headers.value("Content-Type"); + if (!bodyData.isEmpty() && (contentType.isEmpty() || contentType.startsWith("application/x-www-form-urlencoded"))) { + if (rawParameters.isEmpty()) { + rawParameters.append('&'); + rawParameters.append(bodyData); + } + else { + rawParameters=bodyData; + } + } + // Split the parameters into pairs of value and name + QList list=rawParameters.split('&'); + foreach (QByteArray part, list) { + int equalsChar=part.indexOf('='); + if (equalsChar>=0) { + QByteArray name=part.left(equalsChar).trimmed(); + QByteArray value=part.mid(equalsChar+1).trimmed(); + parameters.insert(urlDecode(name),urlDecode(value)); + } + else if (!part.isEmpty()){ + // Name without value + parameters.insert(urlDecode(part),""); + } + } +} + +void HttpRequest::extractCookies() { +#ifdef SUPERVERBOSE + qDebug("HttpRequest: extract cookies"); +#endif + foreach(QByteArray cookieStr, headers.values("Cookie")) { + QList list=HttpCookie::splitCSV(cookieStr); + foreach(QByteArray part, list) { +#ifdef SUPERVERBOSE + qDebug("HttpRequest: found cookie %s",part.data()); +#endif // Split the part into name and value + QByteArray name; + QByteArray value; + int posi=part.indexOf('='); + if (posi) { + name=part.left(posi).trimmed(); + value=part.mid(posi+1).trimmed(); + } + else { + name=part.trimmed(); + value=""; + } + cookies.insert(name,value); + } + } + headers.remove("Cookie"); +} + +void HttpRequest::readFromSocket(QTcpSocket& socket) { + Q_ASSERT(status!=complete); + if (status==waitForRequest) { + readRequest(socket); + } + else if (status==waitForHeader) { + readHeader(socket); + } + else if (status==waitForBody) { + readBody(socket); + } + if (currentSize>maxSize) { + qWarning("HttpRequest: received too many bytes"); + status=abort; + } + if (status==complete) { + // Extract and decode request parameters from url and body + decodeRequestParams(); + // Extract cookies from headers + extractCookies(); + } +} + + +HttpRequest::RequestStatus HttpRequest::getStatus() const { + return status; +} + + +QByteArray HttpRequest::getMethod() const { + return method; +} + + +QByteArray HttpRequest::getPath() const { + return urlDecode(path); +} + + +QByteArray HttpRequest::getVersion() const { + return version; +} + + +QByteArray HttpRequest::getHeader(const QByteArray& name) const { + return headers.value(name); +} + +QList HttpRequest::getHeaders(const QByteArray& name) const { + return headers.values(name); +} + +QMultiMap HttpRequest::getHeaderMap() const { + return headers; +} + +QByteArray HttpRequest::getParameter(const QByteArray& name) const { + return parameters.value(name); +} + +QList HttpRequest::getParameters(const QByteArray& name) const { + return parameters.values(name); +} + +QMultiMap HttpRequest::getParameterMap() const { + return parameters; +} + +QByteArray HttpRequest::getBody() const { + return bodyData; +} + +QByteArray HttpRequest::urlDecode(const QByteArray source) { + QByteArray buffer(source); + buffer.replace('+',' '); + int percentChar=buffer.indexOf('%'); + while (percentChar>=0) { + bool ok; + char byte=buffer.mid(percentChar+1,2).toInt(&ok,16); + if (ok) { + buffer.replace(percentChar,3,(char*)&byte,1); + } + percentChar=buffer.indexOf('%',percentChar+1); + } + return buffer; +} + + +void HttpRequest::parseMultiPartFile() { + qDebug("HttpRequest: parsing multipart temp file"); + tempFile.seek(0); + bool finished=false; + while (!tempFile.atEnd() && !finished && !tempFile.error()) { + +#ifdef SUPERVERBOSE + qDebug("HttpRequest: reading multpart headers"); +#endif + QByteArray fieldName; + QByteArray fileName; + while (!tempFile.atEnd() && !finished && !tempFile.error()) { + QByteArray line=tempFile.readLine(65536).trimmed(); + if (line.startsWith("Content-Disposition:")) { + if (line.contains("form-data")) { + int start=line.indexOf(" name=\""); + int end=line.indexOf("\"",start+7); + if (start>=0 && end>=start) { + fieldName=line.mid(start+7,end-start-7); + } + start=line.indexOf(" filename=\""); + end=line.indexOf("\"",start+11); + if (start>=0 && end>=start) { + fileName=line.mid(start+11,end-start-11); + } +#ifdef SUPERVERBOSE + qDebug("HttpRequest: multipart field=%s, filename=%s",fieldName.data(),fileName.data()); +#endif + } + else { + qDebug("HttpRequest: ignoring unsupported content part %s",line.data()); + } + } + else if (line.isEmpty()) { + break; + } + } + +#ifdef SUPERVERBOSE + qDebug("HttpRequest: reading multpart data"); +#endif + QTemporaryFile* uploadedFile=0; + QByteArray fieldValue; + while (!tempFile.atEnd() && !finished && !tempFile.error()) { + QByteArray line=tempFile.readLine(65536); + if (line.startsWith("--"+boundary)) { + // Boundary found. Until now we have collected 2 bytes too much, + // so remove them from the last result + if (fileName.isEmpty() && !fieldName.isEmpty()) { + // last field was a form field + fieldValue.remove(fieldValue.size()-2,2); + parameters.insert(fieldName,fieldValue); + qDebug("HttpRequest: set parameter %s=%s",fieldName.data(),fieldValue.data()); + } + else if (!fileName.isEmpty() && !fieldName.isEmpty()) { + // last field was a file +#ifdef SUPERVERBOSE + qDebug("HttpRequest: finishing writing to uploaded file"); +#endif + uploadedFile->resize(uploadedFile->size()-2); + uploadedFile->flush(); + uploadedFile->seek(0); + parameters.insert(fieldName,fileName); + qDebug("HttpRequest: set parameter %s=%s",fieldName.data(),fileName.data()); + uploadedFiles.insert(fieldName,uploadedFile); + qDebug("HttpRequest: uploaded file size is %i",(int) uploadedFile->size()); + } + if (line.contains(boundary+"--")) { + finished=true; + } + break; + } + else { + if (fileName.isEmpty() && !fieldName.isEmpty()) { + // this is a form field. + currentSize+=line.size(); + fieldValue.append(line); + } + else if (!fileName.isEmpty() && !fieldName.isEmpty()) { + // this is a file + if (!uploadedFile) { + uploadedFile=new QTemporaryFile(); + uploadedFile->open(); + } + uploadedFile->write(line); + if (uploadedFile->error()) { + qCritical("HttpRequest: error writing temp file, %s",qPrintable(uploadedFile->errorString())); + } + } + } + } + } + if (tempFile.error()) { + qCritical("HttpRequest: cannot read temp file, %s",qPrintable(tempFile.errorString())); + } +#ifdef SUPERVERBOSE + qDebug("HttpRequest: finished parsing multipart temp file"); +#endif +} + +HttpRequest::~HttpRequest() { + foreach(QByteArray key, uploadedFiles.keys()) { + QTemporaryFile* file=uploadedFiles.value(key); + file->close(); + delete file; + } +} + +QTemporaryFile* HttpRequest::getUploadedFile(const QByteArray fieldName) { + return uploadedFiles.value(fieldName); +} + +QByteArray HttpRequest::getCookie(const QByteArray& name) const { + return cookies.value(name); +} + +/** Get the map of cookies */ +QMap& HttpRequest::getCookieMap() { + return cookies; +} + diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httprequest.h b/YACReaderLibrary/server/lib/bfHttpServer/httprequest.h new file mode 100644 index 00000000..e79fd112 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httprequest.h @@ -0,0 +1,212 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef HTTPREQUEST_H +#define HTTPREQUEST_H + +#include +#include +#include +#include +#include +#include +#include + +/** + This object represents a single HTTP request. It reads the request + from a TCP socket and provides getters for the individual parts + of the request. +

+ The follwing config settings are required: +

+  maxRequestSize=16000
+  maxMultiPartSize=1000000
+  
+

+ MaxRequestSize is the maximum size of a HTTP request. In case of + multipart/form-data requests (also known as file-upload), the maximum + size of the body must not exceed maxMultiPartSize. + The body is always a little larger than the file itself. +*/ + +class HttpRequest { + Q_DISABLE_COPY(HttpRequest) + friend class HttpSessionStore; +public: + + /** Values for getStatus() */ + enum RequestStatus {waitForRequest, waitForHeader, waitForBody, complete, abort}; + + /** + Constructor. + @param settings Configuration settings + */ + HttpRequest(QSettings* settings); + + /** + Destructor. + */ + virtual ~HttpRequest(); + + /** + Read the request from a socket. This method must be called repeatedly + until the status is RequestStatus::complete or RequestStatus::abort. + @param socket Source of the data + */ + void readFromSocket(QTcpSocket& socket); + + /** + Get the status of this reqeust. + @see RequestStatus + */ + RequestStatus getStatus() const; + + /** Get the method of the HTTP request (e.g. "GET") */ + QByteArray getMethod() const; + + /** Get the decoded path of the HTPP request (e.g. "/index.html") */ + QByteArray getPath() const; + + /** Get the version of the HTPP request (e.g. "HTTP/1.1") */ + QByteArray getVersion() const; + + /** + Get the value of a HTTP request header. + @param name Name of the header + @return If the header occurs multiple times, only the last + one is returned. + */ + QByteArray getHeader(const QByteArray& name) const; + + /** + Get the values of a HTTP request header. + @param name Name of the header + */ + QList getHeaders(const QByteArray& name) const; + + /** Get all HTTP request headers */ + QMultiMap getHeaderMap() const; + + /** + Get the value of a HTTP request parameter. + @param name Name of the parameter + @return If the parameter occurs multiple times, only the last + one is returned. + */ + QByteArray getParameter(const QByteArray& name) const; + + /** + Get the values of a HTTP request parameter. + @param name Name of the parameter + */ + QList getParameters(const QByteArray& name) const; + + /** Get all HTTP request parameters */ + QMultiMap getParameterMap() const; + + /** Get the HTTP request body */ + QByteArray getBody() const; + + /** + Decode an URL parameter. + E.g. replace "%23" by '#' and replace '+' by ' '. + @param source The url encoded strings + @see QUrl::toPercentEncoding for the reverse direction + */ + static QByteArray urlDecode(const QByteArray source); + + /** + Get an uploaded file. The file is already open. It will + be closed and deleted by the destructor of this HttpRequest + object (after processing the request). +

+ For uploaded files, the method getParameters() returns + the original fileName as provided by the calling web browser. + */ + QTemporaryFile* getUploadedFile(const QByteArray fieldName); + + /** + Get the value of a cookie + @param name Name of the cookie + */ + QByteArray getCookie(const QByteArray& name) const; + + /** Get the map of cookies */ + QMap& getCookieMap(); + +private: + + /** Request headers */ + QMultiMap headers; + + /** Parameters of the request */ + QMultiMap parameters; + + /** Uploaded files of the request, key is the field name. */ + QMap uploadedFiles; + + /** Received cookies */ + QMap cookies; + + /** Storage for raw body data */ + QByteArray bodyData; + + /** Request method */ + QByteArray method; + + /** Request path (in raw encoded format) */ + QByteArray path; + + /** Request protocol version */ + QByteArray version; + + /** + Status of this request. + @see RequestStatus + */ + RequestStatus status; + + /** Maximum size of requests in bytes. */ + int maxSize; + + /** Maximum allowed size of multipart forms in bytes. */ + int maxMultiPartSize; + + /** Current size */ + int currentSize; + + /** Expected size of body */ + int expectedBodySize; + + /** Name of the current header, or empty if no header is being processed */ + QByteArray currentHeader; + + /** Boundary of multipart/form-data body. Empty if there is no such header */ + QByteArray boundary; + + /** Temp file, that is used to store the multipart/form-data body */ + QTemporaryFile tempFile; + + /** Parset he multipart body, that has been stored in the temp file. */ + void parseMultiPartFile(); + + /** Sub-procedure of readFromSocket(), read the first line of a request. */ + void readRequest(QTcpSocket& socket); + + /** Sub-procedure of readFromSocket(), read header lines. */ + void readHeader(QTcpSocket& socket); + + /** Sub-procedure of readFromSocket(), read the request body. */ + void readBody(QTcpSocket& socket); + + /** Sub-procedure of readFromSocket(), extract and decode request parameters. */ + void decodeRequestParams(); + + /** Sub-procedure of readFromSocket(), extract cookies from headers */ + void extractCookies(); + +}; + +#endif // HTTPREQUEST_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httprequesthandler.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httprequesthandler.cpp new file mode 100644 index 00000000..d8ad7caf --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httprequesthandler.cpp @@ -0,0 +1,19 @@ +/** + @file + @author Stefan Frings +*/ + +#include "httprequesthandler.h" + +HttpRequestHandler::HttpRequestHandler(QObject* parent) + : QObject(parent) +{} + +HttpRequestHandler::~HttpRequestHandler() {} + +void HttpRequestHandler::service(HttpRequest& request, HttpResponse& response) { + qCritical("HttpRequestHandler: you need to override the dispatch() function"); + qDebug("HttpRequestHandler: request=%s %s %s",request.getMethod().data(),request.getPath().data(),request.getVersion().data()); + response.setStatus(501,"not implemented"); + response.write("501 not implemented",true); +} diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httprequesthandler.h b/YACReaderLibrary/server/lib/bfHttpServer/httprequesthandler.h new file mode 100644 index 00000000..a5f9f4e2 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httprequesthandler.h @@ -0,0 +1,45 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef HTTPREQUESTHANDLER_H +#define HTTPREQUESTHANDLER_H + +#include "httprequest.h" +#include "httpresponse.h" + +/** + The request handler generates a response for each HTTP request. Web Applications + usually have one central request handler that maps incoming requests to several + controllers (servlets) based on the requested path. +

+ You need to override the service() method or you will always get an HTTP error 501. +

+ @warning Be aware that the main request handler instance must be created on the heap and + that it is used by multiple threads simultaneously. + @see StaticFileController which delivers static local files. +*/ + +class HttpRequestHandler : public QObject { + Q_OBJECT + Q_DISABLE_COPY(HttpRequestHandler) +public: + + /** Constructor */ + HttpRequestHandler(QObject* parent=0); + + /** Destructor */ + virtual ~HttpRequestHandler(); + + /** + Generate a response for an incoming HTTP request. + @param request The received HTTP request + @param response Must be used to return the response + @warning This method must be thread safe + */ + virtual void service(HttpRequest& request, HttpResponse& response); + +}; + +#endif // HTTPREQUESTHANDLER_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpresponse.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httpresponse.cpp new file mode 100644 index 00000000..ad8efa29 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpresponse.cpp @@ -0,0 +1,132 @@ +/** + @file + @author Stefan Frings +*/ + +#include "httpresponse.h" + +HttpResponse::HttpResponse(QTcpSocket* socket) { + this->socket=socket; + statusCode=200; + statusText="OK"; + sentHeaders=false; + sentLastPart=false; +} + +void HttpResponse::setHeader(QByteArray name, QByteArray value) { + //Q_ASSERT(sentHeaders==false); + headers.insert(name,value); +} + +void HttpResponse::setHeader(QByteArray name, int value) { + //Q_ASSERT(sentHeaders==false); + headers.insert(name,QByteArray::number(value)); +} + +QMap& HttpResponse::getHeaders() { + return headers; +} + +void HttpResponse::setStatus(int statusCode, QByteArray description) { + this->statusCode=statusCode; + statusText=description; +} + +void HttpResponse::writeHeaders() { + //Q_ASSERT(sentHeaders==false); + QByteArray buffer; + buffer.append("HTTP/1.1 "); + buffer.append(QByteArray::number(statusCode)); + buffer.append(' '); + buffer.append(statusText); + buffer.append("\r\n"); + foreach(QByteArray name, headers.keys()) { + buffer.append(name); + buffer.append(": "); + buffer.append(headers.value(name)); + buffer.append("\r\n"); + } + foreach(HttpCookie cookie,cookies.values()) { + buffer.append("Set-Cookie: "); + buffer.append(cookie.toByteArray()); + buffer.append("\r\n"); + } + buffer.append("\r\n"); + writeToSocket(buffer); + sentHeaders=true; +} + +bool HttpResponse::writeToSocket(QByteArray data) { + int remaining=data.size(); + char* ptr=data.data(); + while (socket->isOpen() && remaining>0) { + // Wait until the previous buffer content is written out, otherwise it could become very large + socket->waitForBytesWritten(-1); + int written=socket->write(ptr,remaining); + if (written==-1) { + return false; + } + ptr+=written; + remaining-=written; + } + return true; +} + +void HttpResponse::write(QByteArray data, bool lastPart) { + //Q_ASSERT(sentLastPart==false); + if (sentHeaders==false) { + QByteArray connectionMode=headers.value("Connection"); + if (!headers.contains("Content-Length") && !headers.contains("Transfer-Encoding") && connectionMode!="close" && connectionMode!="Close") { + if (!lastPart) { + headers.insert("Transfer-Encoding","chunked"); + } + else { + headers.insert("Content-Length",QByteArray::number(data.size())); + } + } + writeHeaders(); + } + bool chunked=headers.value("Transfer-Encoding")=="chunked" || headers.value("Transfer-Encoding")=="Chunked"; + if (chunked) { + if (data.size()>0) { + QByteArray buffer=QByteArray::number(data.size(),16); + buffer.append("\r\n"); + writeToSocket(buffer); + writeToSocket(data); + writeToSocket("\r\n"); + } + } + else { + writeToSocket(data); + } + if (lastPart) { + if (chunked) { + writeToSocket("0\r\n\r\n"); + } + else if (!headers.contains("Content-Length")) { + socket->disconnectFromHost(); + } + sentLastPart=true; + } +} + +void HttpResponse::writeText(QString text, bool lastPart) +{ + write(QByteArray(text.toUtf8()),lastPart); +} + +bool HttpResponse::hasSentLastPart() const { + return sentLastPart; +} + + +void HttpResponse::setCookie(const HttpCookie& cookie) { + //Q_ASSERT(sentHeaders==false); + if (!cookie.getName().isEmpty()) { + cookies.insert(cookie.getName(),cookie); + } +} + +QMap& HttpResponse::getCookies() { + return cookies; +} diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpresponse.h b/YACReaderLibrary/server/lib/bfHttpServer/httpresponse.h new file mode 100644 index 00000000..1bdc7733 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpresponse.h @@ -0,0 +1,135 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef HTTPRESPONSE_H +#define HTTPRESPONSE_H + +#include +#include +#include +#include "httpcookie.h" + +/** + This object represents a HTTP response, in particular the response headers. +

+ Example code for proper response generation: +

+    response.setStatus(200,"OK"); // optional, because this is the default
+    response.writeBody("Hello");
+    response.writeBody("World!",true);
+  
+

+ Example how to return an error: +

+    response.setStatus(500,"server error");
+    response.write("The request cannot be processed because the servers is broken",true);
+  
+

+ For performance reason, writing a single or few large packets is better than writing + many small packets. In case of large responses (e.g. file downloads), a Content-Length + header should be set before calling write(). Web Browsers use that information to display + a progress bar. +*/ + +class HttpResponse { + Q_DISABLE_COPY(HttpResponse) +public: + + /** + Constructor. + @param socket used to write the response + */ + HttpResponse(QTcpSocket* socket); + + /** + Set a HTTP response header + @param name name of the header + @param value value of the header + */ + void setHeader(QByteArray name, QByteArray value); + + /** + Set a HTTP response header + @param name name of the header + @param value value of the header + */ + void setHeader(QByteArray name, int value); + + /** Get the map of HTTP response headers */ + QMap& getHeaders(); + + /** Get the map of cookies */ + QMap& getCookies(); + + /** + Set status code and description. The default is 200,OK. + */ + void setStatus(int statusCode, QByteArray description=QByteArray()); + + /** + Write body data to the socket. +

+ The HTTP status line and headers are sent automatically before the first + byte of the body gets sent. +

+ If the response contains only a single chunk (indicated by lastPart=true), + the response is transferred in traditional mode with a Content-Length + header, which is automatically added if not already set before. +

+ Otherwise, each part is transferred in chunked mode. + @param data Data bytes of the body + @param lastPart Indicator, if this is the last part of the response. + */ + void write(QByteArray data, bool lastPart=false); + void writeText(QString text, bool lastPart=false); + + /** + Indicates wheter the body has been sent completely. Used by the connection + handler to terminate the body automatically when necessary. + */ + bool hasSentLastPart() const; + + /** + Set a cookie. Cookies are sent together with the headers when the first + call to write() occurs. + */ + void setCookie(const HttpCookie& cookie); + +private: + + /** Request headers */ + QMap headers; + + /** Socket for writing output */ + QTcpSocket* socket; + + /** HTTP status code*/ + int statusCode; + + /** HTTP status code description */ + QByteArray statusText; + + /** Indicator whether headers have been sent */ + bool sentHeaders; + + /** Indicator whether the body has been sent completely */ + bool sentLastPart; + + /** Cookies */ + QMap cookies; + + /** Write raw data to the socket. This method blocks until all bytes have been passed to the TCP buffer */ + bool writeToSocket(QByteArray data); + + /** + Write the response HTTP status and headers to the socket. + Calling this method is optional, because writeBody() calls + it automatically when required. + */ + void writeHeaders(); + +}; + +#endif // HTTPRESPONSE_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpsession.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httpsession.cpp new file mode 100644 index 00000000..1bfe2f07 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpsession.cpp @@ -0,0 +1,381 @@ +/** + @file + @author Stefan Frings +*/ + +#include "httpsession.h" +#include +#include + + +HttpSession::HttpSession(bool canStore) { + if (canStore) { + dataPtr=new HttpSessionData(); + dataPtr->refCount=1; + dataPtr->lastAccess=QDateTime::currentMSecsSinceEpoch(); + dataPtr->id=QUuid::createUuid().toString().toLatin1(); + dataPtr->yacreaderSessionData.comic = 0; + dataPtr->yacreaderSessionData.comicId = 0; + dataPtr->yacreaderSessionData.remoteComic = 0; + dataPtr->yacreaderSessionData.remoteComicId = 0; +#ifdef SUPERVERBOSE + qDebug("HttpSession: created new session data with id %s",dataPtr->id.data()); +#endif + } + else { + dataPtr=0; + } +} + +HttpSession::HttpSession(const HttpSession& other) { + dataPtr=other.dataPtr; + if (dataPtr) { + dataPtr->lock.lockForWrite(); + dataPtr->refCount++; +#ifdef SUPERVERBOSE + qDebug("HttpSession: refCount of %s is %i",dataPtr->id.data(),dataPtr->refCount); +#endif + dataPtr->lock.unlock(); + } +} + +HttpSession& HttpSession::operator= (const HttpSession& other) { + HttpSessionData* oldPtr=dataPtr; + dataPtr=other.dataPtr; + if (dataPtr) { + dataPtr->lock.lockForWrite(); + dataPtr->refCount++; +#ifdef SUPERVERBOSE + qDebug("HttpSession: refCount of %s is %i",dataPtr->id.data(),dataPtr->refCount); +#endif + dataPtr->lastAccess=QDateTime::currentMSecsSinceEpoch(); + dataPtr->lock.unlock(); + } + if (oldPtr) { + int refCount; + oldPtr->lock.lockForRead(); + refCount=oldPtr->refCount--; +#ifdef SUPERVERBOSE + qDebug("HttpSession: refCount of %s is %i",oldPtr->id.data(),oldPtr->refCount); +#endif + oldPtr->lock.unlock(); + if (refCount==0) { + delete oldPtr; + } + } + return *this; +} + +HttpSession::~HttpSession() { + if (dataPtr) { + int refCount; + dataPtr->lock.lockForRead(); + refCount=--dataPtr->refCount; +#ifdef SUPERVERBOSE + qDebug("HttpSession: refCount of %s is %i",dataPtr->id.data(),dataPtr->refCount); +#endif + dataPtr->lock.unlock(); + if (refCount==0) { + qDebug("HttpSession: deleting data"); + delete dataPtr; + } + } +} + + +QByteArray HttpSession::getId() const { + if (dataPtr) { + return dataPtr->id; + } + else { + return QByteArray(); + } +} + +bool HttpSession::isNull() const { + return dataPtr==0; +} + +void HttpSession::set(const QByteArray& key, const QVariant& value) { + if (dataPtr) { + dataPtr->lock.lockForWrite(); + dataPtr->values.insert(key,value); + dataPtr->lock.unlock(); + } +} + +void HttpSession::remove(const QByteArray& key) { + if (dataPtr) { + dataPtr->lock.lockForWrite(); + dataPtr->values.remove(key); + dataPtr->lock.unlock(); + } +} + +QVariant HttpSession::get(const QByteArray& key) const { + QVariant value; + if (dataPtr) { + dataPtr->lock.lockForRead(); + value=dataPtr->values.value(key); + dataPtr->lock.unlock(); + } + return value; +} + +bool HttpSession::contains(const QByteArray& key) const { + bool found=false; + if (dataPtr) { + dataPtr->lock.lockForRead(); + found=dataPtr->values.contains(key); + dataPtr->lock.unlock(); + } + return found; +} + +QMap HttpSession::getAll() const { + QMap values; + if (dataPtr) { + dataPtr->lock.lockForRead(); + values=dataPtr->values; + dataPtr->lock.unlock(); + } + return values; +} + +qint64 HttpSession::getLastAccess() const { + qint64 value=0; + if (dataPtr) { + dataPtr->lock.lockForRead(); + value=dataPtr->lastAccess; + dataPtr->lock.unlock(); + } + return value; +} + + +void HttpSession::setLastAccess() { + if (dataPtr) { + dataPtr->lock.lockForRead(); + dataPtr->lastAccess=QDateTime::currentMSecsSinceEpoch(); + dataPtr->lock.unlock(); + } +} + +//AÑADIDO +//sets +bool HttpSession::isComicOnDevice(const QString & hash) +{ + if(dataPtr) + return dataPtr->yacreaderSessionData.comicsOnDevice.contains(hash); + else + return false; +} +bool HttpSession::isComicDownloaded(const QString & hash) +{ + if(dataPtr) + return dataPtr->yacreaderSessionData.downloadedComics.contains(hash); + else + return false; +} +void HttpSession::setComicOnDevice(const QString & hash) +{ + if(dataPtr) + { + dataPtr->yacreaderSessionData.comicsOnDevice.insert(hash); + } +} +void HttpSession::setComicsOnDevice(const QSet & set) +{ + if(dataPtr) + { + dataPtr->yacreaderSessionData.comicsOnDevice = set; + } +} +void HttpSession::setDownloadedComic(const QString & hash) +{ + if(dataPtr) + { + dataPtr->yacreaderSessionData.downloadedComics.insert(hash); + } +} +QSet HttpSession::getComicsOnDevice() +{ + if(dataPtr) + return dataPtr->yacreaderSessionData.comicsOnDevice ; + else + return QSet(); +} +QSet HttpSession::getDownloadedComics() +{ + if(dataPtr) + return dataPtr->yacreaderSessionData.downloadedComics ; + else + return QSet(); +} + +void HttpSession::clearComics() +{ + if(dataPtr) + { + dataPtr->yacreaderSessionData.comicsOnDevice.clear(); + dataPtr->yacreaderSessionData.downloadedComics.clear(); + } +} +//current comic (import) +qulonglong HttpSession::getCurrentComicId() +{ + if(dataPtr) + return dataPtr->yacreaderSessionData.comicId ; + else + return 0; +} +Comic* HttpSession::getCurrentComic() +{ + if(dataPtr) + { + return dataPtr->yacreaderSessionData.comic ; + } + else + return 0; +} +void HttpSession::dismissCurrentComic() +{ + if(dataPtr) + { + if(dataPtr->yacreaderSessionData.comic != 0) + { + dataPtr->yacreaderSessionData.comic->deleteLater(); + dataPtr->yacreaderSessionData.comic = 0; + } + dataPtr->yacreaderSessionData.comicId = 0; + } +} +void HttpSession::setCurrentComic(qulonglong id, Comic * comic) +{ + if(dataPtr) + { + dismissCurrentComic(); + dataPtr->yacreaderSessionData.comicId = id; + dataPtr->yacreaderSessionData.comic = comic; + } +} + +//current comic (read) +qulonglong HttpSession::getCurrentRemoteComicId() +{ + if(dataPtr) + return dataPtr->yacreaderSessionData.remoteComicId ; + else + return 0; +} +Comic* HttpSession::getCurrentRemoteComic() +{ + if(dataPtr) + { + return dataPtr->yacreaderSessionData.remoteComic ; + } + else + return 0; +} +void HttpSession::dismissCurrentRemoteComic() +{ + if(dataPtr) + { + if(dataPtr->yacreaderSessionData.remoteComic != 0) + { + dataPtr->yacreaderSessionData.remoteComic->deleteLater(); + dataPtr->yacreaderSessionData.remoteComic = 0; + } + dataPtr->yacreaderSessionData.remoteComicId = 0; + } +} +void HttpSession::setCurrentRemoteComic(qulonglong id, Comic * comic) +{ + if(dataPtr) + { + dismissCurrentRemoteComic(); + dataPtr->yacreaderSessionData.remoteComicId = id; + dataPtr->yacreaderSessionData.remoteComic = comic; + } +} + + +QString HttpSession::getDeviceType() +{ + if(dataPtr) + { + return dataPtr->yacreaderSessionData.device; + } + return ""; +} +QString HttpSession::getDisplayType() +{ + if(dataPtr) + { + return dataPtr->yacreaderSessionData.display; + } + return ""; +} +void HttpSession::setDeviceType(const QString & device) +{ + if(dataPtr) + { + //dataPtr->yacreaderSessionData.comicsOnDevice.clear(); //TODO crear un método clear que limpie la sesión completamente + //dataPtr->yacreaderSessionData.downloadedComics.clear(); + dataPtr->yacreaderSessionData.device = device; + } +} +void HttpSession::setDisplayType(const QString & display) +{ + if(dataPtr) + { + dataPtr->yacreaderSessionData.display = display; + } +} + +void HttpSession::clearNavigationPath() +{ + if(dataPtr) + dataPtr->yacreaderSessionData.navigationPath.clear(); +} + +QPair HttpSession::popNavigationItem() +{ + if(dataPtr && !(dataPtr->yacreaderSessionData.navigationPath.isEmpty())) + return dataPtr->yacreaderSessionData.navigationPath.pop(); + return QPair(); +} + +QPair HttpSession::topNavigationItem() +{ + if(dataPtr && !(dataPtr->yacreaderSessionData.navigationPath.isEmpty())) + return dataPtr->yacreaderSessionData.navigationPath.top(); + return QPair(); +} + +void HttpSession::pushNavigationItem(const QPair &item) +{ + if(dataPtr) + dataPtr->yacreaderSessionData.navigationPath.push(item); +} + +void HttpSession::updateTopItem(const QPair &item) +{ + if(dataPtr && !(dataPtr->yacreaderSessionData.navigationPath.isEmpty())) + { + dataPtr->yacreaderSessionData.navigationPath.pop(); + dataPtr->yacreaderSessionData.navigationPath.push(item); + } else if(dataPtr) + { + dataPtr->yacreaderSessionData.navigationPath.push(item); + } +} + +QStack > HttpSession::getNavigationPath() +{ + if(dataPtr) + return dataPtr->yacreaderSessionData.navigationPath; + else + return QStack >(); +} + diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpsession.h b/YACReaderLibrary/server/lib/bfHttpServer/httpsession.h new file mode 100644 index 00000000..a95f818f --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpsession.h @@ -0,0 +1,193 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef HTTPSESSION_H +#define HTTPSESSION_H + +#include +#include +#include + +#include +#include +#include "comic.h" + +/** + This class stores data for a single HTTP session. + A session can store any number of key/value pairs. This class uses implicit + sharing for read and write access. This class is thread safe. + @see HttpSessionStore should be used to create and get instances of this class. +*/ + +class HttpSession { + +public: + + /** + Constructor. + @param canStore The session can store data, if this parameter is true. + Otherwise all calls to set() and remove() do not have any effect. + */ + HttpSession(bool canStore=false); + + /** + Copy constructor. Creates another HttpSession object that shares the + data of the other object. + */ + HttpSession(const HttpSession& other); + + /** + Copy operator. Detaches from the current shared data and attaches to + the data of the other object. + */ + HttpSession& operator= (const HttpSession& other); + + + /** + Destructor. Detaches from the shared data. + */ + virtual ~HttpSession(); + + /** Get the unique ID of this session. This method is thread safe. */ + QByteArray getId() const; + + /** + Null sessions cannot store data. All calls to set() and remove() + do not have any effect.This method is thread safe. + */ + bool isNull() const; + + /** Set a value. This method is thread safe. */ + void set(const QByteArray& key, const QVariant& value); + + /** Remove a value. This method is thread safe. */ + void remove(const QByteArray& key); + + /** Get a value. This method is thread safe. */ + QVariant get(const QByteArray& key) const; + + /** Check if a key exists. This method is thread safe. */ + bool contains(const QByteArray& key) const; + + /** + Get a copy of all data stored in this session. + Changes to the session do not affect the copy and vice versa. + This method is thread safe. + */ + QMap getAll() const; + + /** + Get the timestamp of last access. That is the time when the last + HttpSessionStore::getSession() has been called. + This method is thread safe. + */ + qint64 getLastAccess() const; + + /** + Set the timestamp of last access, to renew the timeout period. + Called by HttpSessionStore::getSession(). + This method is thread safe. + */ + void setLastAccess(); + + //AÑADIDO + //sets + void setComicsOnDevice(const QSet & set); + void setComicOnDevice(const QString & hash); + void setDownloadedComic(const QString & hash); + bool isComicOnDevice(const QString & hash); + bool isComicDownloaded(const QString & hash); + QSet getComicsOnDevice(); + QSet getDownloadedComics(); + void clearComics(); + + //current comic (import) + qulonglong getCurrentComicId(); + Comic * getCurrentComic(); + void dismissCurrentComic(); + void setCurrentComic(qulonglong id, Comic * comic); + + //current comic (read) + qulonglong getCurrentRemoteComicId(); + Comic * getCurrentRemoteComic(); + void dismissCurrentRemoteComic(); + void setCurrentRemoteComic(qulonglong id, Comic * comic); + + //device identification + QString getDeviceType(); + QString getDisplayType(); + void setDeviceType(const QString & device); + void setDisplayType(const QString & display); + + + /*int popPage(); + void pushPage(int page); + int topPage(); + + void clearFoldersPath(); + int popFolder(); + void pushFolder(int page); + int topFolder(); + QStack getFoldersPath();*/ + + void clearNavigationPath(); + QPair popNavigationItem(); + QPair topNavigationItem(); + void pushNavigationItem(const QPair & item); + void updateTopItem(const QPair & item); + + //TODO replace QPair by a custom class for storing folderId, page and folderName(save some DB accesses) + QStack > getNavigationPath(); + + + + +private: + + struct YACReaderSessionData { + //cómics disponibles en dispositivo + QSet comicsOnDevice; + //cómics que han sido descargados o están siendo descargados en esta sesión + QSet downloadedComics; + //cómic actual que está siendo descargado + QString device; + QString display; + qulonglong comicId; + qulonglong remoteComicId; + + //folder_id, page_number + QStack > navigationPath; + + Comic * comic; + Comic * remoteComic; + }; + + struct HttpSessionData { + + /** Unique ID */ + QByteArray id; + + /** Timestamp of last access, set by the HttpSessionStore */ + qint64 lastAccess; + + /** Reference counter */ + int refCount; + + /** Used to synchronize threads */ + QReadWriteLock lock; + + /** Storage for the key/value pairs; */ + QMap values; + + YACReaderSessionData yacreaderSessionData; + + }; + + /** Pointer to the shared data. */ + HttpSessionData* dataPtr; + +}; + +#endif // HTTPSESSION_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpsessionstore.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httpsessionstore.cpp new file mode 100644 index 00000000..87ce7d4a --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpsessionstore.cpp @@ -0,0 +1,109 @@ +/** + @file + @author Stefan Frings +*/ + +#include "httpsessionstore.h" +#include +#include + +HttpSessionStore::HttpSessionStore(QSettings* settings, QObject* parent) + :QObject(parent) +{ + this->settings=settings; + connect(&cleanupTimer,SIGNAL(timeout()),this,SLOT(timerEvent())); + cleanupTimer.start(60000); + cookieName=settings->value("cookieName","sessionid").toByteArray(); + expirationTime=settings->value("expirationTime",864000000).toInt(); + qDebug("HttpSessionStore: Sessions expire after %i milliseconds",expirationTime); +} + +HttpSessionStore::~HttpSessionStore() +{ + cleanupTimer.stop(); +} + +QByteArray HttpSessionStore::getSessionId(HttpRequest& request, HttpResponse& response) { + // The session ID in the response has priority because this one will be used in the next request. + mutex.lock(); + // Get the session ID from the response cookie + QByteArray sessionId=response.getCookies().value(cookieName).getValue(); + if (sessionId.isEmpty()) { + // Get the session ID from the request cookie + sessionId=request.getCookie(cookieName); + } + // Clear the session ID if there is no such session in the storage. + if (!sessionId.isEmpty()) { + if (!sessions.contains(sessionId)) { + qDebug("HttpSessionStore: received invalid session cookie with ID %s",sessionId.data()); + sessionId.clear(); + } + } + mutex.unlock(); + return sessionId; +} + +HttpSession HttpSessionStore::getSession(HttpRequest& request, HttpResponse& response, bool allowCreate) { + QByteArray sessionId=getSessionId(request,response); + mutex.lock(); + if (!sessionId.isEmpty()) { + HttpSession session=sessions.value(sessionId); + if (!session.isNull()) { + mutex.unlock(); + session.setLastAccess(); + return session; + } + } + // Need to create a new session + if (allowCreate) { + QByteArray cookieName=settings->value("cookieName","sessionid").toByteArray(); + QByteArray cookiePath=settings->value("cookiePath","/").toByteArray(); + QByteArray cookieComment=settings->value("cookieComment").toByteArray(); + QByteArray cookieDomain=settings->value("cookieDomain").toByteArray(); + HttpSession session(true); + qDebug("HttpSessionStore: create new session with ID %s",session.getId().data()); + sessions.insert(session.getId(),session); + response.setCookie(HttpCookie(cookieName,session.getId(),expirationTime/1000,cookiePath,cookieComment,cookieDomain)); + mutex.unlock(); + return session; + } + // Return a null session + mutex.unlock(); + return HttpSession(); +} + +HttpSession HttpSessionStore::getSession(const QByteArray id) { + mutex.lock(); + HttpSession session=sessions.value(id); + mutex.unlock(); + session.setLastAccess(); + return session; +} + +void HttpSessionStore::timerEvent() { + // Todo: find a way to delete sessions only if no controller is accessing them + mutex.lock(); + qint64 now=QDateTime::currentMSecsSinceEpoch(); + QMap::iterator i = sessions.begin(); + while (i != sessions.end()) { + QMap::iterator prev = i; + ++i; + HttpSession session=prev.value(); + qint64 lastAccess=session.getLastAccess(); + if (now-lastAccess>expirationTime) { //TODO cleaning up will cause current opened comic to be deleted, so clients won't be able to download it + //If the cleaning occurs in the midle of a download it going to cause issues + //Temporal fix: use a big expirationTime = 10 days + qDebug("HttpSessionStore: session %s expired",session.getId().data()); + sessions.erase(prev); + } + } + mutex.unlock(); +} + + +/** Delete a session */ +void HttpSessionStore::removeSession(HttpSession session) { + mutex.lock(); + sessions.remove(session.getId()); + mutex.unlock(); +} diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpsessionstore.h b/YACReaderLibrary/server/lib/bfHttpServer/httpsessionstore.h new file mode 100644 index 00000000..e65260d7 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpsessionstore.h @@ -0,0 +1,104 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef HTTPSESSIONSTORE_H +#define HTTPSESSIONSTORE_H + +#include +#include +#include +#include +#include "httpsession.h" +#include "httpresponse.h" +#include "httprequest.h" + +/** + Stores HTTP sessions and deletes them when they have expired. + The following configuration settings are required in the config file: +

+  expirationTime=3600000
+  cookieName=sessionid
+  
+ The following additional configurations settings are optionally: +
+  cookiePath=/
+  cookieComment=Session ID
+  cookieDomain=stefanfrings.de
+  
+*/ + +class HttpSessionStore : public QObject { + Q_OBJECT + Q_DISABLE_COPY(HttpSessionStore) +public: + + /** Constructor. */ + HttpSessionStore(QSettings* settings, QObject* parent); + + /** Destructor */ + virtual ~HttpSessionStore(); + + /** + Get the ID of the current HTTP session, if it is valid. + This method is thread safe. + @warning Sessions may expire at any time, so subsequent calls of + getSession() might return a new session with a different ID. + @param request Used to get the session cookie + @param response Used to get and set the new session cookie + @return Empty string, if there is no valid session. + */ + QByteArray getSessionId(HttpRequest& request, HttpResponse& response); + + /** + Get the session of a HTTP request, eventually create a new one. + This method is thread safe. New sessions can only be created before + the first byte has been written to the HTTP response. + @param request Used to get the session cookie + @param response Used to get and set the new session cookie + @param allowCreate can be set to false, to disable the automatic creation of a new session. + @return If autoCreate is disabled, the function returns a null session if there is no session. + @see HttpSession::isNull() + */ + HttpSession getSession(HttpRequest& request, HttpResponse& response, bool allowCreate=true); + + /** + Get a HTTP session by it's ID number. + This method is thread safe. + @return If there is no such session, the function returns a null session. + @param id ID number of the session + @see HttpSession::isNull() + */ + HttpSession getSession(const QByteArray id); + + /** Delete a session */ + void removeSession(HttpSession session); + +private: + + /** Configuration settings */ + QSettings* settings; + + /** Storage for the sessions */ + QMap sessions; + + /** Timer to remove expired sessions */ + QTimer cleanupTimer; + + /** Name of the session cookie */ + QByteArray cookieName; + + /** Time when sessions expire (in ms)*/ + int expirationTime; + + /** Used to synchronize threads */ + QMutex mutex; + +private slots: + + /** Called every minute to cleanup expired sessions. */ + void timerEvent(); +}; + +#endif // HTTPSESSIONSTORE_H diff --git a/YACReaderLibrary/server/lib/bfHttpServer/staticfilecontroller.cpp b/YACReaderLibrary/server/lib/bfHttpServer/staticfilecontroller.cpp new file mode 100644 index 00000000..b2515e3c --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/staticfilecontroller.cpp @@ -0,0 +1,235 @@ +/** + @file + @author Stefan Frings +*/ + +#include "staticfilecontroller.h" +#include +#include +#include +#include "httpsession.h" +#include "static.h" +#include + + +StaticFileController::StaticFileController(QSettings* settings, QObject* parent) + :HttpRequestHandler(parent) +{ + maxAge=settings->value("maxAge","60000").toInt(); + encoding=settings->value("encoding","UTF-8").toString(); + docroot=settings->value("path","./server/docroot").toString(); + // Convert relative path to absolute, based on the directory of the config file. +#ifdef Q_OS_WIN32 + if (QDir::isRelativePath(docroot) && settings->format()!=QSettings::NativeFormat) +#else + if (QDir::isRelativePath(docroot)) +#endif + { +#if defined Q_OS_UNIX && ! defined Q_OS_MAC + QFileInfo configFile(QString(DATADIR)+"/yacreader"); + docroot=QFileInfo(QString(DATADIR)+"/yacreader",docroot).absoluteFilePath(); +#else + QFileInfo configFile(QApplication::applicationDirPath()); + docroot=QFileInfo(QApplication::applicationDirPath(),docroot).absoluteFilePath(); +#endif + } + qDebug("StaticFileController: docroot=%s, encoding=%s, maxAge=%i",qPrintable(docroot),qPrintable(encoding),maxAge); + maxCachedFileSize=settings->value("maxCachedFileSize","65536").toInt(); + cache.setMaxCost(settings->value("cacheSize","1000000").toInt()); + cacheTimeout=settings->value("cacheTime","60000").toInt(); + qDebug("StaticFileController: cache timeout=%i, size=%i",cacheTimeout,cache.maxCost()); +} + + +void StaticFileController::service(HttpRequest& request, HttpResponse& response) { + QByteArray path=request.getPath(); + // Forbid access to files outside the docroot directory + if (path.startsWith("/..")) { + qWarning("StaticFileController: somebody attempted to access a file outside the docroot directory"); + response.setStatus(403,"forbidden"); + response.write("403 forbidden",true); + } + + //TODO(DONE) carga sensible al dispositivo y a la localización + QString stringPath = path; + QStringList paths = QString(path).split('/'); + QString fileName = paths.last(); + stringPath.remove(fileName); + HttpSession session=Static::sessionStore->getSession(request,response,false); + QString device = session.getDeviceType(); + QString display = session.getDisplayType(); + if(fileName.endsWith(".png")) + fileName = getDeviceAwareFileName(fileName, device, display, request.getHeader("Accept-Language"), stringPath); + else + fileName = getDeviceAwareFileName(fileName, device, request.getHeader("Accept-Language"), stringPath); + QString newPath = stringPath.append(fileName); + path = newPath.toLocal8Bit(); + + //CAMBIADO + response.setHeader("Connection","close"); + //END_TODO + + // Check if we have the file in cache + //qint64 now=QDateTime::currentMSecsSinceEpoch(); + // mutex.lock(); + // CacheEntry* entry=cache.object(path); + //if (entry && (cacheTimeout==0 || entry->created>now-cacheTimeout)) { + // QByteArray document=entry->document; //copy the cached document, because other threads may destroy the cached entry immediately after mutex unlock. + // mutex.unlock(); + // qDebug("StaticFileController: Cache hit for %s",path.data()); + // setContentType(path,response); + // response.setHeader("Cache-Control","max-age="+QByteArray::number(maxAge/1000)); + // response.write(document); + //} + //else { + + // mutex.unlock(); + //qDebug("StaticFileController: Cache miss for %s",path.data()); + // The file is not in cache. + // If the filename is a directory, append index.html. + if (QFileInfo(docroot+path).isDir()) { + path+="/index.html"; + } + + + QFile file(docroot+path); + if (file.exists()) { + qDebug("StaticFileController: Open file %s",qPrintable(file.fileName())); + if (file.open(QIODevice::ReadOnly)) { + setContentType(path,response); + //response.setHeader("Cache-Control","max-age="+QByteArray::number(maxAge/1000)); + //if (file.size()<=maxCachedFileSize) { + // // Return the file content and store it also in the cache + // entry=new CacheEntry(); + // while (!file.atEnd() && !file.error()) { + // QByteArray buffer=file.read(65536); + // response.write(buffer); + // entry->document.append(buffer); + // } + // entry->created=now; + // mutex.lock(); + // cache.insert(request.getPath(),entry,entry->document.size()); + // mutex.unlock(); + //} + //else { + // Return the file content, do not store in cache*/ + while (!file.atEnd() && !file.error()) { + response.write(file.read(131072)); + //} + } + file.close(); + } + else { + qWarning("StaticFileController: Cannot open existing file %s for reading",qPrintable(file.fileName())); + response.setStatus(403,"forbidden"); + response.write("403 forbidden",true); + } + } + else { + response.setStatus(404,"not found"); + response.write("404 not found",true); + } + //} +} + +void StaticFileController::setContentType(QString fileName, HttpResponse& response) const { + if (fileName.endsWith(".png")) { + response.setHeader("Content-Type", "image/png"); + } + else if (fileName.endsWith(".jpg")) { + response.setHeader("Content-Type", "image/jpeg"); + } + else if (fileName.endsWith(".gif")) { + response.setHeader("Content-Type", "image/gif"); + } + else if (fileName.endsWith(".pdf")) { + response.setHeader("Content-Type", "application/pdf"); + } + else if (fileName.endsWith(".txt")) { + response.setHeader("Content-Type", qPrintable("text/plain; charset="+encoding)); + } + else if (fileName.endsWith(".html") || fileName.endsWith(".htm")) { + response.setHeader("Content-Type", qPrintable("text/html; charset="+encoding)); + } + else if (fileName.endsWith(".css")) { + response.setHeader("Content-Type", "text/css"); + } + else if (fileName.endsWith(".js")) { + response.setHeader("Content-Type", "text/javascript"); + } + // Todo: add all of your content types +} + +bool StaticFileController::exists(QString localizedName, QString path) const +{ + QString fileName=docroot+"/"+path + localizedName; + QFile file(fileName); + return file.exists(); +} + +//retorna fileName si no se encontró alternativa traducida ó fileName-locale.extensión si se encontró +QString StaticFileController::getLocalizedFileName(QString fileName, QString locales, QString path) const +{ + QSet tried; // used to suppress duplicate attempts + QStringList locs=locales.split(',',QString::SkipEmptyParts); + QStringList fileNameParts = fileName.split('.'); + QString file = fileNameParts.first(); + QString extension = fileNameParts.last(); + // Search for exact match + foreach (QString loc,locs) { + loc.replace(QRegExp(";.*"),""); + loc.replace('-','_'); + QString localizedName=file+"-"+loc.trimmed()+"."+extension; + if (!tried.contains(localizedName)) { + if(exists(localizedName, path)) + return localizedName; + tried.insert(localizedName); + } + } + + // Search for correct language but any country + foreach (QString loc,locs) { + loc.replace(QRegExp("[;_-].*"),""); + QString localizedName=file+"-"+loc.trimmed()+"."+extension; + if (!tried.contains(localizedName)) { + if(exists(localizedName, path)) + return localizedName; + tried.insert(localizedName); + } + } + + return fileName; +} + +QString StaticFileController::getDeviceAwareFileName(QString fileName, QString device, QString locales, QString path) const +{ + QFileInfo fi(fileName); + QString baseName = fi.baseName(); + QString extension = fi.completeSuffix(); + + QString completeFileName = getLocalizedFileName(baseName+"_"+device+"."+extension,locales,path); + + if(QFile(docroot+"/"+path+completeFileName).exists()) + return completeFileName; //existe un archivo específico para este dispositivo y locales + else + return getLocalizedFileName(fileName,locales,path); //no hay archivo específico para el dispositivo, pero puede haberlo para estas locales +} + +QString StaticFileController::getDeviceAwareFileName(QString fileName, QString device, QString display, QString locales, QString path) const +{ + QFileInfo fi(fileName); + QString baseName = fi.baseName(); + QString extension = fi.completeSuffix(); + + QString completeFileName = baseName+display+"."+extension; + if(QFile(docroot+"/"+path+completeFileName).exists()) + return completeFileName; + else + { + completeFileName = baseName+"_"+device+display+"."+extension; + if((QFile(docroot+"/"+path+completeFileName).exists())) + return completeFileName; + } + + return fileName; +} diff --git a/YACReaderLibrary/server/lib/bfHttpServer/staticfilecontroller.h b/YACReaderLibrary/server/lib/bfHttpServer/staticfilecontroller.h new file mode 100644 index 00000000..26413398 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfHttpServer/staticfilecontroller.h @@ -0,0 +1,92 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef STATICFILECONTROLLER_H +#define STATICFILECONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" +#include +#include + +/** + Delivers static files. It is usually called by the applications main request handler when + the caller request a path that is mapped to static files. +

+ The following settings are required in the config file: +

+  path=docroot
+  encoding=UTF-8
+  maxAge=60000
+  cacheTime=60000
+  cacheSize=1000000
+  maxCachedFileSize=65536
+  
+ The path is relative to the directory of the config file. In case of windows, if the + settings are in the registry, the path is relative to the current working directory. +

+ The encoding is sent to the web browser in case of text and html files. +

+ The cache improves performance of small files when loaded from a network + drive. Large files are not cached. Files are cached as long as possible, + when cacheTime=0. The maxAge value (in msec!) controls the remote browsers cache. +

+ Do not instantiate this class in each request, because this would make the file cache + useless. Better create one instance during start-up and call it when the application + received a related HTTP request. +*/ + +class StaticFileController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(StaticFileController); +public: + + /** Constructor */ + StaticFileController(QSettings* settings, QObject* parent = 0); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); + +private: + + /** Encoding of text files */ + QString encoding; + + /** Root directory of documents */ + QString docroot; + + /** Maximum age of files in the browser cache */ + int maxAge; + + struct CacheEntry { + QByteArray document; + qint64 created; + }; + + /** Timeout for each cached file */ + int cacheTimeout; + + + /** Maximum size of files in cache, larger files are not cached */ + int maxCachedFileSize; + + /** Cache storage */ + QCache cache; + + /** Used to synchronize cache access for threads */ + QMutex mutex; + + /** Set a content-type header in the response depending on the ending of the filename */ + void setContentType(QString file, HttpResponse& response) const; + + QString getLocalizedFileName(QString fileName, QString locales, QString path) const; + QString getDeviceAwareFileName(QString fileName, QString device, QString locales, QString path) const; + QString getDeviceAwareFileName(QString fileName, QString device, QString display, QString locales, QString path) const; + + bool exists(QString localizedName, QString path) const; +}; + +#endif // STATICFILECONTROLLER_H diff --git a/YACReaderLibrary/server/lib/bfLogging/bfLogging.pri b/YACReaderLibrary/server/lib/bfLogging/bfLogging.pri new file mode 100644 index 00000000..17eae35e --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/bfLogging.pri @@ -0,0 +1,5 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +HEADERS += $$PWD/logmessage.h $$PWD/logger.h $$PWD/filelogger.h $$PWD/dualfilelogger.h +SOURCES += $$PWD/logmessage.cpp $$PWD/logger.cpp $$PWD/filelogger.cpp $$PWD/dualfilelogger.cpp diff --git a/YACReaderLibrary/server/lib/bfLogging/dualfilelogger.cpp b/YACReaderLibrary/server/lib/bfLogging/dualfilelogger.cpp new file mode 100644 index 00000000..7329cae0 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/dualfilelogger.cpp @@ -0,0 +1,20 @@ +/** + @file + @author Stefan Frings +*/ + +#include "dualfilelogger.h" + + +DualFileLogger::DualFileLogger(QSettings* firstSettings, QSettings* secondSettings, const int refreshInterval, QObject* parent) + :Logger(parent) +{ + firstLogger=new FileLogger(firstSettings, refreshInterval, this); + secondLogger=new FileLogger(secondSettings, refreshInterval, this); +} + + +void DualFileLogger::log(const QtMsgType type, const QString& message) { + firstLogger->log(type, message); + secondLogger->log(type, message); +} diff --git a/YACReaderLibrary/server/lib/bfLogging/dualfilelogger.h b/YACReaderLibrary/server/lib/bfLogging/dualfilelogger.h new file mode 100644 index 00000000..39bec859 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/dualfilelogger.h @@ -0,0 +1,58 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef DUALFILELOGGER_H +#define DUALFILELOGGER_H + +#include "logger.h" +#include "filelogger.h" +#include +#include +#include + +/** + Logs messages into two log files simultaneously. + May be used to create two logfiles with different configuration settings. + @see FileLogger for a description of the two underlying loggers. +*/ + +class DualFileLogger : public Logger { + Q_OBJECT + Q_DISABLE_COPY(DualFileLogger) +public: + + /** + Constructor. + @param firstSettings Configuration settings for the first log file, usually stored in an INI file. + Must not be 0. + Settings are read from the current group, so the caller must have called settings->beginGroup(). + Because the group must not change during runtime, it is recommended to provide a + separate QSettings instance to the logger that is not used by other parts of the program. + @param secondSettings Same as firstSettings, but for the second log file. + @param refreshInterval Interval of checking for changed config settings in msec, or 0=disabled + @param parent Parent object. + */ + DualFileLogger(QSettings* firstSettings, QSettings* secondSettings, const int refreshInterval=10000, QObject *parent = 0); + + /** + Decorate and log a message. + This method is thread safe. + @param type Message type (level) + @param message Message text + @see LogMessage for a description of the message decoration. + */ + virtual void log(const QtMsgType type, const QString& message); + +private: + + /** First logger */ + FileLogger* firstLogger; + + /** Second logger */ + FileLogger* secondLogger; + +}; + +#endif // DUALFILELOGGER_H diff --git a/YACReaderLibrary/server/lib/bfLogging/filelogger.cpp b/YACReaderLibrary/server/lib/bfLogging/filelogger.cpp new file mode 100644 index 00000000..24e32a35 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/filelogger.cpp @@ -0,0 +1,174 @@ +/** + @file + @author Stefan Frings +*/ + +#include "filelogger.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "yacreader_global.h" + +void FileLogger::refreshSettings() { + mutex.lock(); + // Save old file name for later comparision with new settings + QString oldFileName=fileName; + + // Load new config settings + settings->sync(); + fileName=settings->value("fileName","server_log.log").toString(); + // Convert relative fileName to absolute, based on the directory of the config file. +#ifdef Q_OS_WIN32 + if (QDir::isRelativePath(fileName) && settings->format()!=QSettings::NativeFormat) +#else + if (QDir::isRelativePath(fileName)) +#endif + { + QFileInfo configFile(YACReader::getSettingsPath()); + fileName=QFileInfo(YACReader::getSettingsPath(),fileName).absoluteFilePath(); + } + maxSize=settings->value("maxSize",1048576).toLongLong(); + maxBackups=settings->value("maxBackups",1).toInt(); + msgFormat=settings->value("msgFormat","{timestamp} {type} {msg}").toString(); + timestampFormat=settings->value("timestampFormat","yyyy-MM-dd hh:mm:ss.zzz").toString(); + minLevel=static_cast(settings->value("minLevel",0).toInt()); + bufferSize=settings->value("bufferSize",0).toInt(); + + // Create new file if the filename has been changed + if (oldFileName!=fileName) { + fprintf(stderr,"Logging to %s\n",qPrintable(fileName)); + close(); + open(); + } + mutex.unlock(); +} + + +FileLogger::FileLogger(QSettings* settings, const int refreshInterval, QObject* parent) + : Logger(parent) +{ + Q_ASSERT(settings!=0); + Q_ASSERT(refreshInterval>=0); + this->settings=settings; + file=0; + if (refreshInterval>0) { + refreshTimer.start(refreshInterval,this); + } + flushTimer.start(1000,this); + refreshSettings(); +} + + +FileLogger::~FileLogger() { + close(); +} + + +void FileLogger::write(const LogMessage* logMessage) { + // Try to write to the file + if (file) { + + // Write the message + file->write(qPrintable(logMessage->toString(msgFormat,timestampFormat))); + + // Flush error messages immediately, to ensure that no important message + // gets lost when the program terinates abnormally. + if (logMessage->getType()>=QtCriticalMsg) { + file->flush(); + } + + // Check for success + if (file->error()) { + close(); + qWarning("Cannot write to log file %s: %s",qPrintable(fileName),qPrintable(file->errorString())); + } + + } + + // Fall-back to the super class method, if writing failed + if (!file) { + Logger::write(logMessage); + } + +} + +void FileLogger::open() { + if (fileName.isEmpty()) { + qWarning("Name of logFile is empty"); + } + else { + file=new QFile(fileName); + if (!file->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) { + qWarning("Cannot open log file %s: %s",qPrintable(fileName),qPrintable(file->errorString())); + file=0; + } + } +} + + +void FileLogger::close() { + if (file) { + file->close(); + delete file; + file=0; + } +} + +void FileLogger::rotate() { + // count current number of existing backup files + int count=0; + forever { + QFile bakFile(QString("%1.%2").arg(fileName).arg(count+1)); + if (bakFile.exists()) { + ++count; + } + else { + break; + } + } + + // Remove all old backup files that exceed the maximum number + while (maxBackups>0 && count>=maxBackups) { + QFile::remove(QString("%1.%2").arg(fileName).arg(count)); + --count; + } + + // Rotate backup files + for (int i=count; i>0; --i) { + QFile::rename(QString("%1.%2").arg(fileName).arg(i),QString("%1.%2").arg(fileName).arg(i+1)); + } + + // Backup the current logfile + QFile::rename(fileName,fileName+".1"); +} + + +void FileLogger::timerEvent(QTimerEvent* event) { + if (!event) { + return; + } + else if (event->timerId()==refreshTimer.timerId()) { + refreshSettings(); + } + else if (event->timerId()==flushTimer.timerId() && file) { + mutex.lock(); + + // Flush the I/O buffer + file->flush(); + + // Rotate the file if it is too large + if (maxSize>0 && file->size()>=maxSize) { + close(); + rotate(); + open(); + } + + mutex.unlock(); + } +} diff --git a/YACReaderLibrary/server/lib/bfLogging/filelogger.h b/YACReaderLibrary/server/lib/bfLogging/filelogger.h new file mode 100644 index 00000000..617b5bff --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/filelogger.h @@ -0,0 +1,122 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef FILELOGGER_H +#define FILELOGGER_H + +#include +#include +#include +#include +#include +#include "logger.h" + +/** + Logger that uses a text file for output. Settings are read from a + config file using a QSettings object. Config settings can be changed at runtime. +

+ Example for the configuration settings: +

+  fileName=logs/QtWebApp.log
+  maxSize=1000000
+  maxBackups=2
+  minLevel=0
+  msgformat={timestamp} {typeNr} {type} thread={thread}: {msg}
+  timestampFormat=dd.MM.yyyy hh:mm:ss.zzz
+  bufferSize=0
+  
+ + - fileName is the name of the log file, relative to the directory of the settings file. + In case of windows, if the settings are in the registry, the path is relative to the current + working directory. + - maxSize is the maximum size of that file in bytes. The file will be backed up and + replaced by a new file if it becomes larger than this limit. Please note that + the actual file size may become a little bit larger than this limit. Default is 0=unlimited. + - maxBackups defines the number of backup files to keep. Default is 0=unlimited. + - minLevel defines the minimum type of messages that are written (together with buffered messages) into the file. Defaults is 0=debug. + - msgFormat defines the decoration of log messages, see LogMessage class. Default is "{timestamp} {type} {msg}". + - timestampFormat defines the format of timestamps, see QDateTime::toString(). Default is "yyyy-MM-dd hh:mm:ss.zzz". + - bufferSize defines the size of the buffer. Default is 0=disabled. + + @see set() describes how to set logger variables + @see LogMessage for a description of the message decoration. + @see Logger for a descrition of the buffer. +*/ + +class FileLogger : public Logger { + Q_OBJECT + Q_DISABLE_COPY(FileLogger) +public: + + /** + Constructor. + @param settings Configuration settings, usually stored in an INI file. Must not be 0. + Settings are read from the current group, so the caller must have called settings->beginGroup(). + Because the group must not change during runtime, it is recommended to provide a + separate QSettings instance to the logger that is not used by other parts of the program. + @param refreshInterval Interval of checking for changed config settings in msec, or 0=disabled + @param parent Parent object + */ + FileLogger(QSettings* settings, const int refreshInterval=10000, QObject* parent = 0); + + /** + Destructor. Closes the file. + */ + virtual ~FileLogger(); + + /** Write a message to the log file */ + virtual void write(const LogMessage* logMessage); + +protected: + + /** + Handler for timer events. + Refreshes config settings or synchronizes I/O buffer, depending on the event. + This method is thread-safe. + @param event used to distinguish between the two timers. + */ + void timerEvent(QTimerEvent* event); + +private: + + /** Configured name of the log file */ + QString fileName; + + /** Configured maximum size of the file in bytes, or 0=unlimited */ + long maxSize; + + /** Configured maximum number of backup files, or 0=unlimited */ + int maxBackups; + + /** Pointer to the configuration settings */ + QSettings* settings; + + /** Output file, or 0=disabled */ + QFile* file; + + /** Timer for refreshing configuration settings */ + QBasicTimer refreshTimer; + + /** Timer for flushing the file I/O buffer */ + QBasicTimer flushTimer; + + /** Open the output file */ + void open(); + + /** Close the output file */ + void close(); + + /** Rotate files and delete some backups if there are too many */ + void rotate(); + + /** + Refreshes the configuration settings. + This method is thread-safe. + */ + void refreshSettings(); + +}; + +#endif // FILELOGGER_H diff --git a/YACReaderLibrary/server/lib/bfLogging/logger.cpp b/YACReaderLibrary/server/lib/bfLogging/logger.cpp new file mode 100644 index 00000000..de3ab1a5 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/logger.cpp @@ -0,0 +1,172 @@ +/** + @file + @author Stefan Frings +*/ + +#include "logger.h" +#include +#include +#include +#include +#include + +Logger* Logger::defaultLogger=0; + + +QThreadStorage*> Logger::logVars; + + +QThreadStorage*> Logger::buffers; + + +QMutex Logger::mutex; + + +Logger::Logger(QObject* parent) + : QObject(parent), + msgFormat("{timestamp} {type} {msg}"), + timestampFormat("dd.MM.yyyy hh:mm:ss.zzz"), + minLevel(QtDebugMsg), + bufferSize(0) + {} + + +Logger::Logger(const QString msgFormat, const QString timestampFormat, const QtMsgType minLevel, const int bufferSize, QObject* parent) + :QObject(parent) { + this->msgFormat=msgFormat; + this->timestampFormat=timestampFormat; + this->minLevel=minLevel; + this->bufferSize=bufferSize; +} + + +void Logger::msgHandler(const QtMsgType type, const QString &message, const QString &file, const QString &function, const int line) { + static QMutex recursiveMutex(QMutex::Recursive); + static QMutex nonRecursiveMutex(QMutex::NonRecursive); + + // Prevent multiple threads from calling this method simultaneoulsy. + // But allow recursive calls, which is required to prevent a deadlock + // if the logger itself produces an error message. + recursiveMutex.lock(); + + // Fall back to stderr when this method has been called recursively. + if (defaultLogger && nonRecursiveMutex.tryLock()) { + defaultLogger->log(type, message, file, function, line); + nonRecursiveMutex.unlock(); + } + else { + fputs(qPrintable(message),stderr); + fflush(stderr); + } + + // Abort the program after logging a fatal message + if (type>=QtFatalMsg) { + //abort(); + } + + recursiveMutex.unlock(); +} + + +#if QT_VERSION >= 0x050000 + void Logger::msgHandler5(const QtMsgType type, const QMessageLogContext &context, const QString &message) { + (void)(context); // suppress "unused parameter" warning + msgHandler(type,message,context.file,context.function,context.line); + } +#else + void Logger::msgHandler4(const QtMsgType type, const char* message) { + msgHandler(type,message); + } +#endif + + +Logger::~Logger() { + if (defaultLogger==this) { +#if QT_VERSION >= 0x050000 + qInstallMessageHandler(0); +#else + qInstallMsgHandler(0); +#endif + defaultLogger=0; + } +} + + +void Logger::write(const LogMessage* logMessage) { + fputs(qPrintable(logMessage->toString(msgFormat,timestampFormat)),stderr); + fflush(stderr); +} + + +void Logger::installMsgHandler() { + defaultLogger=this; +#if QT_VERSION >= 0x050000 + qInstallMessageHandler(msgHandler5); +#else + qInstallMsgHandler(msgHandler4); +#endif +} + + +void Logger::set(const QString& name, const QString& value) { + mutex.lock(); + if (!logVars.hasLocalData()) { + logVars.setLocalData(new QHash); + } + logVars.localData()->insert(name,value); + mutex.unlock(); +} + + +void Logger::clear(const bool buffer, const bool variables) { + mutex.lock(); + if (buffer && buffers.hasLocalData()) { + QList* buffer=buffers.localData(); + while (buffer && !buffer->isEmpty()) { + LogMessage* logMessage=buffer->takeLast(); + delete logMessage; + } + } + if (variables && logVars.hasLocalData()) { + logVars.localData()->clear(); + } + mutex.unlock(); +} + + +void Logger::log(const QtMsgType type, const QString& message, const QString &file, const QString &function, const int line) { + mutex.lock(); + + // If the buffer is enabled, write the message into it + if (bufferSize>0) { + // Create new thread local buffer, if necessary + if (!buffers.hasLocalData()) { + buffers.setLocalData(new QList()); + } + QList* buffer=buffers.localData(); + // Append the decorated log message + LogMessage* logMessage=new LogMessage(type,message,logVars.localData(),file,function,line); + buffer->append(logMessage); + // Delete oldest message if the buffer became too large + if (buffer->size()>bufferSize) { + delete buffer->takeFirst(); + } + // If the type of the message is high enough, print the whole buffer + if (type>=minLevel) { + while (!buffer->isEmpty()) { + LogMessage* logMessage=buffer->takeFirst(); + write(logMessage); + delete logMessage; + } + } + } + + // Buffer is disabled, print the message if the type is high enough + else { + if (type>=minLevel) { + LogMessage logMessage(type,message,logVars.localData(),file,function,line); + write(&logMessage); + } + } + mutex.unlock(); +} diff --git a/YACReaderLibrary/server/lib/bfLogging/logger.h b/YACReaderLibrary/server/lib/bfLogging/logger.h new file mode 100644 index 00000000..adcedfd3 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/logger.h @@ -0,0 +1,183 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef LOGGER_H +#define LOGGER_H + +#include + +#include +#include +#include +#include +#include +#include "logmessage.h" + +/** + Decorates and writes log messages to the console, stderr. +

+ The decorator uses a predefined msgFormat string to enrich log messages + with additional information (e.g. timestamp). +

+ The msgFormat string and also the message text may contain additional + variable names in the form {name} that are filled by values + taken from a static thread local dictionary. +

+ The logger keeps a configurable number of messages in a ring-buffer. + A log message with a severity >= minLevel flushes the buffer, + so the stored messages get written out. If the buffer is disabled, then + only messages with severity >= minLevel are written out. +

+ If you enable the buffer and use minLevel=2, then the application logs + only errors together with some buffered debug messages. But as long no + error occurs, nothing gets written out. +

+ Each thread has it's own buffer. +

+ The logger can be registered to handle messages from + the static global functions qDebug(), qWarning(), qCritical() and qFatal(). + + @see set() describes how to set logger variables + @see LogMessage for a description of the message decoration. + @warning You should prefer a derived class, for example FileLogger, + because logging to the console is less useful. +*/ + +class Logger : public QObject { + Q_OBJECT + Q_DISABLE_COPY(Logger) +public: + + /** + Constructor. + Uses the same defaults as the other constructor. + @param parent Parent object + */ + Logger(QObject* parent); + + + /** + Constructor. + @param msgFormat Format of the decoration, e.g. "{timestamp} {type} thread={thread}: {msg}" + @param timestampFormat Format of timestamp, e.g. "dd.MM.yyyy hh:mm:ss.zzz" + @param minLevel Minimum severity that genertes an output (0=debug, 1=warning, 2=critical, 3=fatal). + @param bufferSize Size of the backtrace buffer, number of messages per thread. 0=disabled. + @param parent Parent object + @see LogMessage for a description of the message decoration. + */ + Logger(const QString msgFormat="{timestamp} {type} {msg}", const QString timestampFormat="dd.MM.yyyy hh:mm:ss.zzz", const QtMsgType minLevel=QtDebugMsg, const int bufferSize=0, QObject* parent = 0); + + /** Destructor */ + virtual ~Logger(); + + /** + Decorate and log the message, if type>=minLevel. + This method is thread safe. + @param type Message type (level) + @param message Message text + @param file Name of the source file where the message was generated (usually filled with the macro __FILE__) + @param function Name of the function where the message was generated (usually filled with the macro __LINE__) + @param line Line Number of the source file, where the message was generated (usually filles with the macro __func__ or __FUNCTION__) + @see LogMessage for a description of the message decoration. + */ + virtual void log(const QtMsgType type, const QString& message, const QString &file="", const QString &function="", const int line=0); + + /** + Installs this logger as the default message handler, so it + can be used through the global static logging functions (e.g. qDebug()). + */ + void installMsgHandler(); + + /** + Sets a thread-local variable that may be used to decorate log messages. + This method is thread safe. + @param name Name of the variable + @param value Value of the variable + */ + static void set(const QString& name, const QString& value); + + /** + Clear the thread-local data of the current thread. + @param buffer Whether to clear the backtrace buffer + @param variables Whether to clear the log variables + */ + static void clear(const bool buffer=true, const bool variables=true); + +protected: + + /** Format string for message decoration */ + QString msgFormat; + + /** Format string of timestamps */ + QString timestampFormat; + + /** Minimum level of message types that are written out */ + QtMsgType minLevel; + + /** Size of backtrace buffer, number of messages per thread. 0=disabled */ + int bufferSize; + + /** Used to synchronize access to the static members */ + static QMutex mutex; + + /** + Decorate and write a log message to stderr. Override this method + to provide a different output medium. + */ + virtual void write(const LogMessage* logMessage); + +private: + + /** Pointer to the default logger, used by msgHandler() */ + static Logger* defaultLogger; + + /** + Message Handler for the global static logging functions (e.g. qDebug()). + Forward calls to the default logger. +

+ In case of a fatal message, the program will abort. + Variables in the in the message are replaced by their values. + This method is thread safe. + @param type Message type (level) + @param message Message text + @param file Name of the source file where the message was generated (usually filled with the macro __FILE__) + @param function Name of the function where the message was generated (usually filled with the macro __LINE__) + @param line Line Number of the source file, where the message was generated (usually filles with the macro __func__ or __FUNCTION__) + */ + static void msgHandler(const QtMsgType type, const QString &message, const QString &file="", const QString &function="", const int line=0); + + +#if QT_VERSION >= 0x050000 + + /** + Wrapper for QT version 5. + @param type Message type (level) + @param context Message context + @param message Message text + @see msgHandler() + */ + static void msgHandler5(const QtMsgType type, const QMessageLogContext& context, const QString &message); + +#else + + /** + Wrapper for QT version 4. + @param type Message type (level) + @param message Message text + @see msgHandler() + */ + static void msgHandler4(const QtMsgType type, const char * message); + +#endif + + /** Thread local variables to be used in log messages */ + static QThreadStorage*> logVars; + + /** Thread local backtrace buffers */ + static QThreadStorage*> buffers; + +}; + +#endif // LOGGER_H diff --git a/YACReaderLibrary/server/lib/bfLogging/logmessage.cpp b/YACReaderLibrary/server/lib/bfLogging/logmessage.cpp new file mode 100644 index 00000000..4d610383 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/logmessage.cpp @@ -0,0 +1,75 @@ +/** + @file + @author Stefan Frings +*/ + +#include "logmessage.h" +#include + +LogMessage::LogMessage(const QtMsgType type, const QString& message, QHash* logVars, const QString &file, const QString &function, const int line) { + this->type=type; + this->message=message; + this->file=file; + this->function=function; + this->line=line; + timestamp=QDateTime::currentDateTime(); + threadId=QThread::currentThreadId(); + + // Copy the logVars if not null, + // so that later changes in the original do not affect the copy + if (logVars) { + this->logVars=*logVars; + } +} + +QString LogMessage::toString(const QString& msgFormat, const QString& timestampFormat) const { + QString decorated=msgFormat+"\n"; + decorated.replace("{msg}",message); + + if (decorated.contains("{timestamp}")) { + decorated.replace("{timestamp}",timestamp.toString(timestampFormat)); + } + + QString typeNr; + typeNr.setNum(type); + decorated.replace("{typeNr}",typeNr); + + switch (type) { + case QtDebugMsg: + decorated.replace("{type}","DEBUG"); + break; + case QtWarningMsg: + decorated.replace("{type}","WARNING"); + break; + case QtCriticalMsg: + decorated.replace("{type}","CRITICAL"); + break; + case QtFatalMsg: + decorated.replace("{type}","FATAL"); + break; + default: + decorated.replace("{type}",typeNr); + } + + decorated.replace("{file}",file); + decorated.replace("{function}",function); + decorated.replace("{line}",QString::number(line)); + + QString threadId; + threadId.setNum((quint64)QThread::currentThreadId()); // change to (qint64) for 64bit Mac OS + decorated.replace("{thread}",threadId); + + // Fill in variables + if (decorated.contains("{") && !logVars.isEmpty()) { + QList keys=logVars.keys(); + foreach (QString key, keys) { + decorated.replace("{"+key+"}",logVars.value(key)); + } + } + + return decorated; +} + +QtMsgType LogMessage::getType() const { + return type; +} diff --git a/YACReaderLibrary/server/lib/bfLogging/logmessage.h b/YACReaderLibrary/server/lib/bfLogging/logmessage.h new file mode 100644 index 00000000..433d949d --- /dev/null +++ b/YACReaderLibrary/server/lib/bfLogging/logmessage.h @@ -0,0 +1,91 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef LOGMESSAGE_H +#define LOGMESSAGE_H + +#include +#include +#include + +/** + Represents a single log message together with some data + that are used to decorate the log message. + + The following variables may be used in the message and in msgFormat: + + - {timestamp} Date and time of creation + - {typeNr} Type of the message in numeric format (0-3) + - {type} Type of the message in string format (DEBUG, WARNING, CRITICAL, FATAL) + - {thread} ID number of the thread + - {msg} Message text (only useable in msgFormat) + - {file} Filename where the message was generated # + - {function} Function where the message was generated # + - {line} Line number where the message was generated # + - {xxx} For any user-defined logger variable + + # The macros qDebug()...qFatal() dont fill these variable in case of QT versions before 5.0. +*/ + +class LogMessage +{ + Q_DISABLE_COPY(LogMessage) +public: + + /** + Constructor. All parameters are copied, so that later changes to them do not + affect this object. + @param type Type of the message + @param message Message text + @param logVars Logger variables, 0 is allowed + @param file Name of the source file where the message was generated + @param function Name of the function where the message was generated + @param line Line Number of the source file, where the message was generated + */ + LogMessage(const QtMsgType type, const QString& message, QHash* logVars, const QString &file, const QString &function, const int line); + + /** + Returns the log message as decorated string. + @param msgFormat Format of the decoration. May contain variables and static text, + e.g. "{timestamp} {type} thread={thread}: {msg}". + @param timestampFormat Format of timestamp, e.g. "dd.MM.yyyy hh:mm:ss.zzz", see QDateTime::toString(). + @see QDatetime for a description of the timestamp format pattern + */ + QString toString(const QString& msgFormat, const QString& timestampFormat) const; + + /** + Get the message type. + */ + QtMsgType getType() const; + +private: + + /** Logger variables */ + QHash logVars; + + /** Date and time of creation */ + QDateTime timestamp; + + /** Type of the message */ + QtMsgType type; + + /** ID number of the thread */ + Qt::HANDLE threadId; + + /** Message text */ + QString message; + + /** Filename where the message was generated */ + QString file; + + /** Function name where the message was generated */ + QString function; + + /** Line number where the message was generated */ + int line; + +}; + +#endif // LOGMESSAGE_H diff --git a/YACReaderLibrary/server/lib/bfTemplateEngine/bfTemplateEngine.pri b/YACReaderLibrary/server/lib/bfTemplateEngine/bfTemplateEngine.pri new file mode 100644 index 00000000..d3eba98b --- /dev/null +++ b/YACReaderLibrary/server/lib/bfTemplateEngine/bfTemplateEngine.pri @@ -0,0 +1,7 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +HEADERS += $$PWD/template.h $$PWD/templateloader.h $$PWD/templatecache.h +SOURCES += $$PWD/template.cpp $$PWD/templateloader.cpp $$PWD/templatecache.cpp + +OTHER_FILES += $$PWD/../doc/readme.txt diff --git a/YACReaderLibrary/server/lib/bfTemplateEngine/template.cpp b/YACReaderLibrary/server/lib/bfTemplateEngine/template.cpp new file mode 100644 index 00000000..23abac9e --- /dev/null +++ b/YACReaderLibrary/server/lib/bfTemplateEngine/template.cpp @@ -0,0 +1,188 @@ +/** + @file + @author Stefan Frings +*/ + +#include "template.h" +#include + +Template::Template(QString source, QString sourceName) + : QString(source) { + this->sourceName=sourceName; + this->warnings=false; +} + +Template::Template(QFile& file, QTextCodec* textCodec) { + this->warnings=false; + sourceName=QFileInfo(file.fileName()).baseName(); + if (!file.isOpen()) { + file.open(QFile::ReadOnly | QFile::Text); + } + QByteArray data=file.readAll(); + file.close(); + if (data.size()==0 || file.error()) { + qCritical("Template: cannot read from %s, %s",qPrintable(sourceName),qPrintable(file.errorString())); + append(textCodec->toUnicode(data)); + } +} + + +int Template::setVariable(QString name, QString value) { + int count=0; + QString variable="{"+name+"}"; + int start=indexOf(variable); + while (start>=0) { + replace(start, variable.length(), value); + count++; + start=indexOf(variable,start+value.length()); + } + if (count==0 && warnings) { + qWarning("Template: missing variable %s in %s",qPrintable(variable),qPrintable(sourceName)); + } + return count; +} + +int Template::setCondition(QString name, bool value) { + int count=0; + QString startTag=QString("{if %1}").arg(name); + QString elseTag=QString("{else %1}").arg(name); + QString endTag=QString("{end %1}").arg(name); + // search for if-else-end + int start=indexOf(startTag); + while (start>=0) { + int end=indexOf(endTag,start+startTag.length()); + if (end>=0) { + count++; + int ellse=indexOf(elseTag,start+startTag.length()); + if (ellse>start && ellse=0) { + int end=indexOf(endTag,start+startTag2.length()); + if (end>=0) { + count++; + int ellse=indexOf(elseTag,start+startTag2.length()); + if (ellse>start && ellse=0); + int count=0; + QString startTag="{loop "+name+"}"; + QString elseTag="{else "+name+"}"; + QString endTag="{end "+name+"}"; + // search for loop-else-end + int start=indexOf(startTag); + while (start>=0) { + int end=indexOf(endTag,start+startTag.length()); + if (end>=0) { + count++; + int ellse=indexOf(elseTag,start+startTag.length()); + if (ellse>start && ellse0) { + QString loopPart=mid(start+startTag.length(), ellse-start-startTag.length()); + QString insertMe; + for (int i=0; i0) { // and no else part + QString loopPart=mid(start+startTag.length(), end-start-startTag.length()); + QString insertMe; + for (int i=0; i +#include +#include +#include +#include +#include + +/** + Enhanced version of QString for template processing. Templates + are usually loaded from files, but may also be loaded from + prepared Strings. + Example template file: +

+ Hello {username}, how are you?
+
+ {if locked}
+     Your account is locked.
+ {else locked}
+     Welcome on our system.
+ {end locked}
+
+ The following users are on-line:
+     Username       Time
+ {loop user}
+     {user.name}    {user.time}
+ {end user}
+ 

+

+ Example code to fill this template: +

+ Template t(QFile("test.tpl"),QTextCode::codecForName("UTF-8"));
+ t.setVariable("user", "Stefan");
+ t.setCondition("locked",false);
+ t.loop("user",2);
+ t.setVariable("user0.name,"Markus");
+ t.setVariable("user0.time,"8:30");
+ t.setVariable("user1.name,"Roland");
+ t.setVariable("user1.time,"8:45");
+ 

+

+ The code example above shows how variable within loops are numbered. + Counting starts with 0. Loops can be nested, for example: +

+ <table>
+ {loop row}
+     <tr>
+     {loop row.column}
+         <td>{row.column.value}</td>
+     {end row.column}
+     </tr>
+ {end row}
+ </table>
+ 

+

+ Example code to fill this nested loop with 3 rows and 4 columns: +

+ t.loop("row",3);
+
+ t.loop("row0.column",4);
+ t.setVariable("row0.column0.value","a");
+ t.setVariable("row0.column1.value","b");
+ t.setVariable("row0.column2.value","c");
+ t.setVariable("row0.column3.value","d");
+
+ t.loop("row1.column",4);
+ t.setVariable("row1.column0.value","e");
+ t.setVariable("row1.column1.value","f");
+ t.setVariable("row1.column2.value","g");
+ t.setVariable("row1.column3.value","h");
+
+ t.loop("row2.column",4);
+ t.setVariable("row2.column0.value","i");
+ t.setVariable("row2.column1.value","j");
+ t.setVariable("row2.column2.value","k");
+ t.setVariable("row2.column3.value","l");
+ 

+ @see TemplateLoader + @see TemplateCache +*/ + +class Template : public QString { +public: + + /** + Constructor that reads the template from a string. + @param source The template source text + @param sourceName Name of the source file, used for logging + */ + Template(QString source, QString sourceName); + + /** + Constructor that reads the template from a file. Note that this class does not + cache template files by itself, so using this constructor is only recommended + to be used on local filesystem. + @param file File that provides the source text + @param textCodec Encoding of the source + @see TemplateLoader + @see TemplateCache + */ + Template(QFile& file, QTextCodec* textCodec); + + /** + Replace a variable by the given value. + Affects tags with the syntax + + - {name} + + After settings the + value of a variable, the variable does not exist anymore, + it it cannot be changed multiple times. + @param name name of the variable + @param value new value + @return The count of variables that have been processed + */ + int setVariable(QString name, QString value); + + /** + Set a condition. This affects tags with the syntax + + - {if name}...{end name} + - {if name}...{else name}...{end name} + - {ifnot name}...{end name} + - {ifnot name}...{else name}...{end name} + + @param name Name of the condition + @param value Value of the condition + @return The count of conditions that have been processed + */ + int setCondition(QString name, bool value); + + /** + Set number of repetitions of a loop. + This affects tags with the syntax + + - {loop name}...{end name} + - {loop name}...{else name}...{end name} + + @param name Name of the loop + @param repetitions The number of repetitions + @return The number of loops that have been processed + */ + int loop(QString name, int repetitions); + + /** + Enable warnings for missing tags + @param enable Warnings are enabled, if true + */ + void enableWarnings(bool enable=true); + +private: + + /** Name of the source file */ + QString sourceName; + + /** Enables warnings, if true */ + bool warnings; +}; + +#endif // TEMPLATE_H diff --git a/YACReaderLibrary/server/lib/bfTemplateEngine/templatecache.cpp b/YACReaderLibrary/server/lib/bfTemplateEngine/templatecache.cpp new file mode 100644 index 00000000..823f4f24 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfTemplateEngine/templatecache.cpp @@ -0,0 +1,30 @@ +#include "templatecache.h" +#include +#include +#include + +TemplateCache::TemplateCache(QSettings* settings, QObject* parent) + :TemplateLoader(settings,parent) +{ + cache.setMaxCost(settings->value("cacheSize","160000").toInt());//este tamaño antes era 1000000 + cacheTimeout=settings->value("cacheTime","60000").toInt(); + qDebug("TemplateCache: timeout=%i, size=%i",cacheTimeout,cache.maxCost()); +} + +QString TemplateCache::tryFile(QString localizedName) { + qint64 now=QDateTime::currentMSecsSinceEpoch(); + // search in cache + qDebug("TemplateCache: trying cached %s",qPrintable(localizedName)); + CacheEntry* entry=cache.object(localizedName); + if (entry && (cacheTimeout==0 || entry->created>now-cacheTimeout)) { + return entry->document; + } + // search on filesystem + entry=new CacheEntry(); + entry->created=now; + entry->document=TemplateLoader::tryFile(localizedName); + // Store in cache even when the file did not exist, to remember that there is no such file + cache.insert(localizedName,entry,entry->document.size()); + return entry->document; +} + diff --git a/YACReaderLibrary/server/lib/bfTemplateEngine/templatecache.h b/YACReaderLibrary/server/lib/bfTemplateEngine/templatecache.h new file mode 100644 index 00000000..6e79f119 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfTemplateEngine/templatecache.h @@ -0,0 +1,77 @@ +#ifndef TEMPLATECACHE_H +#define TEMPLATECACHE_H + +#include "templateloader.h" +#include + +/** + Caching template loader, reduces the amount of I/O and improves performance + on remote file systems. The cache has a limited size, it prefers to keep + the last recently used files. Optionally, the maximum time of cached entries + can be defined to enforce a reload of the template file after a while. +

+ In case of local file system, the use of this cache is optionally, since + the operating system caches files already. +

+ Loads localized versions of template files. If the caller requests a file with the + name "index" and the suffix is ".tpl" and the requested locale is "de_DE, de, en-US", + then files are searched in the following order: + + - index-de_DE.tpl + - index-de.tpl + - index-en_US.tpl + - index-en.tpl + - index.tpl +

+ The following settings are required: +

+  path=.
+  suffix=.tpl
+  encoding=UTF-8
+  cacheSize=1000000
+  cacheTime=60000
+  
+ The path is relative to the directory of the config file. In case of windows, if the + settings are in the registry, the path is relative to the current working directory. +

+ Files are cached as long as possible, when cacheTime=0. + @see TemplateLoader +*/ + +class TemplateCache : public TemplateLoader { + Q_OBJECT + Q_DISABLE_COPY(TemplateCache); +public: + + /** + Constructor. + @param settings configurations settings + @param parent Parent object + */ + TemplateCache(QSettings* settings, QObject* parent=0); + +protected: + + /** + Try to get a file from cache or filesystem. + @param localizedName Name of the template with locale to find + @return The template document, or empty string if not found + */ + virtual QString tryFile(QString localizedName); + +private: + + struct CacheEntry { + QString document; + qint64 created; + }; + + /** Timeout for each cached file */ + int cacheTimeout; + + /** Cache storage */ + QCache cache; + +}; + +#endif // TEMPLATECACHE_H diff --git a/YACReaderLibrary/server/lib/bfTemplateEngine/templateloader.cpp b/YACReaderLibrary/server/lib/bfTemplateEngine/templateloader.cpp new file mode 100644 index 00000000..ea3a2dd8 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfTemplateEngine/templateloader.cpp @@ -0,0 +1,109 @@ +/** + @file + @author Stefan Frings +*/ + +#include "templateloader.h" +#include +#include +#include +#include +#include +#include + +TemplateLoader::TemplateLoader(QSettings* settings, QObject* parent) + : QObject(parent) +{ + templatePath=settings->value("path","./server/templates").toString(); + // Convert relative path to absolute, based on the directory of the config file. +#ifdef Q_OS_WIN32 + if (QDir::isRelativePath(templatePath) && settings->format()!=QSettings::NativeFormat) +#else + if (QDir::isRelativePath(templatePath)) +#endif + { +#if defined Q_OS_UNIX && !defined Q_OS_MAC + QFileInfo configFile(QString(DATADIR)+"/yacreader"); + templatePath=QFileInfo(QString(DATADIR)+"/yacreader",templatePath).absoluteFilePath(); +#else + QFileInfo configFile(QApplication::applicationDirPath()); + templatePath=QFileInfo(QApplication::applicationDirPath(),templatePath).absoluteFilePath(); +#endif + } + fileNameSuffix=settings->value("suffix",".tpl").toString(); + QString encoding=settings->value("encoding").toString(); + if (encoding.isEmpty()) { + textCodec=QTextCodec::codecForLocale(); + } + else { + textCodec=QTextCodec::codecForName(encoding.toLocal8Bit()); + } + qDebug("TemplateLoader: path=%s, codec=%s",qPrintable(templatePath),textCodec->name().data()); +} + +TemplateLoader::~TemplateLoader() {} + +QString TemplateLoader::tryFile(QString localizedName) { + QString fileName=templatePath+"/"+localizedName+fileNameSuffix; + qDebug("TemplateCache: trying file %s",qPrintable(fileName)); + QFile file(fileName); + if (file.exists()) { + file.open(QIODevice::ReadOnly); + QString document=textCodec->toUnicode(file.readAll()); + file.close(); + if (file.error()) { + qCritical("TemplateLoader: cannot load file %s, %s",qPrintable(fileName),qPrintable(file.errorString())); + return ""; + } + else { + return document; + } + } + return ""; +} + +Template TemplateLoader::getTemplate(QString templateName, QString locales) { + mutex.lock(); + QSet tried; // used to suppress duplicate attempts + QStringList locs=locales.split(',',QString::SkipEmptyParts); + + // Search for exact match + foreach (QString loc,locs) { + loc.replace(QRegExp(";.*"),""); + loc.replace('-','_'); + QString localizedName=templateName+"-"+loc.trimmed(); + if (!tried.contains(localizedName)) { + QString document=tryFile(localizedName); + if (!document.isEmpty()) { + mutex.unlock(); + return Template(document,localizedName); + } + tried.insert(localizedName); + } + } + + // Search for correct language but any country + foreach (QString loc,locs) { + loc.replace(QRegExp("[;_-].*"),""); + QString localizedName=templateName+"-"+loc.trimmed(); + if (!tried.contains(localizedName)) { + QString document=tryFile(localizedName); + if (!document.isEmpty()) { + mutex.unlock(); + return Template(document,localizedName); + } + tried.insert(localizedName); + } + } + + // Search for default file + QString document=tryFile(templateName); + if (!document.isEmpty()) { + mutex.unlock(); + return Template(document,templateName); + } + + qCritical("TemplateCache: cannot find template %s",qPrintable(templateName)); + mutex.unlock(); + return Template("",templateName); +} diff --git a/YACReaderLibrary/server/lib/bfTemplateEngine/templateloader.h b/YACReaderLibrary/server/lib/bfTemplateEngine/templateloader.h new file mode 100644 index 00000000..5635af40 --- /dev/null +++ b/YACReaderLibrary/server/lib/bfTemplateEngine/templateloader.h @@ -0,0 +1,85 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef TEMPLATELOADER_H +#define TEMPLATELOADER_H + +#include +#include +#include +#include "template.h" +#include + +/** + Loads localized versions of template files. If the caller requests a file with the + name "index" and the suffix is ".tpl" and the requested locale is "de_DE, de, en-US", + then files are searched in the following order: + + - index-de_DE.tpl + - index-de.tpl + - index-en_US.tpl + - index-en.tpl + - index.tpl + + The following settings are required: +

+  path=.
+  suffix=.tpl
+  encoding=UTF-8
+  
+ The path is relative to the directory of the config file. In case of windows, if the + settings are in the registry, the path is relative to the current working directory. + @see TemplateCache +*/ + +class TemplateLoader : public QObject { + Q_OBJECT + Q_DISABLE_COPY(TemplateLoader); +public: + + /** + Constructor. + @param settings configurations settings + @param parent parent object + */ + TemplateLoader(QSettings* settings, QObject* parent=0); + + /** Destructor */ + virtual ~TemplateLoader(); + + /** + Get a template for a given locale. + This method is thread safe. + @param templateName base name of the template file, without suffix and without locale + @param locales Requested locale(s), e.g. "de_DE, en_EN". Strings in the format of + the HTTP header Accept-Locale may be used. Badly formatted parts in the string are silently + ignored. + @return If the template cannot be loaded, an error message is logged and an empty template is returned. + */ + Template getTemplate(QString templateName, QString locales=QString()); + +protected: + + /** + Try to get a file from cache or filesystem. + @param localizedName Name of the template with locale to find + @return The template document, or empty string if not found + */ + virtual QString tryFile(QString localizedName); + + /** Directory where the templates are searched */ + QString templatePath; + + /** Suffix to the filenames */ + QString fileNameSuffix; + + /** Codec for decoding the files */ + QTextCodec* textCodec; + + /** Used to synchronize threads */ + QMutex mutex; +}; + +#endif // TEMPLATELOADER_H diff --git a/YACReaderLibrary/server/requestmapper.cpp b/YACReaderLibrary/server/requestmapper.cpp new file mode 100644 index 00000000..66b03413 --- /dev/null +++ b/YACReaderLibrary/server/requestmapper.cpp @@ -0,0 +1,177 @@ +/** + @file + @author Stefan Frings +*/ + +#include "requestmapper.h" +#include "static.h" +#include "staticfilecontroller.h" +#include "controllers/dumpcontroller.h" +#include "controllers/templatecontroller.h" +#include "controllers/formcontroller.h" +#include "controllers/fileuploadcontroller.h" +#include "controllers/sessioncontroller.h" + +#include "controllers/librariescontroller.h" +#include "controllers/foldercontroller.h" +#include "controllers/covercontroller.h" +#include "controllers/comiccontroller.h" +#include "controllers/folderinfocontroller.h" +#include "controllers/pagecontroller.h" +#include "controllers/updatecomiccontroller.h" +#include "controllers/errorcontroller.h" +#include "controllers/comicdownloadinfocontroller.h" +#include "controllers/synccontroller.h" + +#include "db_helper.h" +#include "yacreader_libraries.h" + +#include "QsLog.h" + +RequestMapper::RequestMapper(QObject* parent) + :HttpRequestHandler(parent) {} + +void RequestMapper::loadSession(HttpRequest & request, HttpResponse& response) +{ + HttpSession session=Static::sessionStore->getSession(request,response); + if(session.contains("ySession")) //session is already alive check if it is needed to update comics + { + QString postData = QString::fromUtf8(request.getBody()); + + if(postData.contains("currentPage")) + return; + + if(postData.length()>0) { + + QList data = postData.split("\n"); + if(data.length() > 2) { + session.setDeviceType(data.at(0).split(":").at(1)); + session.setDisplayType(data.at(1).split(":").at(1)); + QList comics = data.at(2).split(":").at(1).split("\t"); + session.clearComics(); + foreach(QString hash,comics) { + session.setComicOnDevice(hash); + } + } + else + { + if(data.length()>1) + { + session.setDeviceType(data.at(0).split(":").at(1)); + session.setDisplayType(data.at(1).split(":").at(1)); + } + } + } + } + else + { + session.set("ySession","ok"); + + QString postData = QString::fromUtf8(request.getBody()); + //response.writeText(postData); + + QList data = postData.split("\n"); + + if(data.length() > 2) + { + session.setDeviceType(data.at(0).split(":").at(1)); + session.setDisplayType(data.at(1).split(":").at(1)); + QList comics = data.at(2).split(":").at(1).split("\t"); + foreach(QString hash,comics) + { + session.setComicOnDevice(hash); + } + } + else //values by default, only for debug purposes. + { + session.setDeviceType("ipad"); + session.setDisplayType("@2x"); + } + + } +} + +void RequestMapper::service(HttpRequest& request, HttpResponse& response) { + QByteArray path=request.getPath(); + qDebug("RequestMapper: path=%s",path.data()); + + QRegExp folder("/library/.+/folder/[0-9]+/?");//get comic content + QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?"); //get folder info + QRegExp comicDownloadInfo("/library/.+/comic/[0-9]+/?"); //get comic info (basic/download info) + QRegExp comicFullInfo("/library/.+/comic/[0-9]+/info/?"); //get comic info (full info) + QRegExp comicOpen("/library/.+/comic/[0-9]+/remote/?"); //the server will open for reading the comic + QRegExp comicUpdate("/library/.+/comic/[0-9]+/update/?"); //get comic info + QRegExp comicClose("/library/.+/comic/[0-9]+/close/?"); //the server will close the comic and free memory + QRegExp cover("/library/.+/cover/[0-9a-f]+.jpg"); //get comic cover (navigation) + QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?"); //get comic page + QRegExp comicPageRemote("/library/.+/comic/[0-9]+/page/[0-9]+/remote?"); //get comic page (remote reading) + + QRegExp sync("/sync"); + + QRegExp library("/library/([0-9]+)/.+"); //permite verificar que la biblioteca solicitada existe + + path = QUrl::fromPercentEncoding(path).toUtf8(); + + if(!sync.exactMatch(path)) //no session is needed for syncback info, until security will be added + loadSession(request, response); + + //primera petición, se ha hecho un post, se sirven las bibliotecas si la seguridad mediante login no está habilitada + if(path == "/") //Don't send data to the server using '/' !!!! + { + LibrariesController().service(request, response); + } + else + { + if(sync.exactMatch(path)) + SyncController().service(request, response); + else + { + //se comprueba que la sesión sea la correcta con el fin de evitar accesos no autorizados + HttpSession session=Static::sessionStore->getSession(request,response,false); + if(!session.isNull() && session.contains("ySession")) + { + if(library.indexIn(path)!=-1 && DBHelper::getLibraries().contains(library.cap(1).toInt()) ) + { + //listar el contenido del folder + if(folder.exactMatch(path)) + { + FolderController().service(request, response); + } + else if (folderInfo.exactMatch(path)) + { + FolderInfoController().service(request, response); + } + else if(cover.exactMatch(path)) + { + CoverController().service(request, response); + } + else if(comicDownloadInfo.exactMatch(path)) + { + ComicDownloadInfoController().service(request, response); + } + else if(comicFullInfo.exactMatch(path) || comicOpen.exactMatch(path))//start download or start remote reading + { + ComicController().service(request, response); + } + else if(comicPage.exactMatch(path) || comicPageRemote.exactMatch(path)) + { + PageController().service(request,response); + } + else if(comicUpdate.exactMatch(path)) + { + UpdateComicController().service(request, response); + } + } + else + { + //response.writeText(library.cap(1)); + Static::staticFileController->service(request, response); + } + } + else //acceso no autorizado, redirección + { + ErrorController(300).service(request,response); + } + } + } +} diff --git a/YACReaderLibrary/server/requestmapper.h b/YACReaderLibrary/server/requestmapper.h new file mode 100644 index 00000000..332cee09 --- /dev/null +++ b/YACReaderLibrary/server/requestmapper.h @@ -0,0 +1,37 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef REQUESTMAPPER_H +#define REQUESTMAPPER_H + +#include "httprequesthandler.h" + +/** + The request mapper dispatches incoming HTTP requests to controller classes + depending on the requested path. +*/ + +class RequestMapper : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(RequestMapper) +public: + + /** + Constructor. + @param parent Parent object + */ + RequestMapper(QObject* parent=0); + + /** + Dispatch a request to a controller. + @param request The received HTTP request + @param response Must be used to return the response + */ + void service(HttpRequest& request, HttpResponse& response); + void loadSession(HttpRequest & request, HttpResponse& response); + +}; + +#endif // REQUESTMAPPER_H diff --git a/YACReaderLibrary/server/server.pri b/YACReaderLibrary/server/server.pri new file mode 100644 index 00000000..4be20612 --- /dev/null +++ b/YACReaderLibrary/server/server.pri @@ -0,0 +1,38 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +HEADERS += \ + $$PWD/static.h \ + $$PWD/startup.h \ + $$PWD/requestmapper.h \ + $$PWD/controllers/comiccontroller.h \ + $$PWD/controllers/errorcontroller.h \ + $$PWD/controllers/foldercontroller.h \ + $$PWD/controllers/folderinfocontroller.h \ + $$PWD/controllers/librariescontroller.h \ + $$PWD/controllers/pagecontroller.h \ + $$PWD/controllers/sessionmanager.h \ + $$PWD/controllers/covercontroller.h \ + $$PWD/controllers/updatecomiccontroller.h \ + $$PWD/controllers/comicdownloadinfocontroller.h \ + $$PWD/controllers/synccontroller.h + +SOURCES += \ + $$PWD/static.cpp \ + $$PWD/startup.cpp \ + $$PWD/requestmapper.cpp \ + $$PWD/controllers/comiccontroller.cpp \ + $$PWD/controllers/errorcontroller.cpp \ + $$PWD/controllers/foldercontroller.cpp \ + $$PWD/controllers/folderinfocontroller.cpp \ + $$PWD/controllers/librariescontroller.cpp \ + $$PWD/controllers/pagecontroller.cpp \ + $$PWD/controllers/sessionmanager.cpp \ + $$PWD/controllers/covercontroller.cpp \ + $$PWD/controllers/updatecomiccontroller.cpp \ + $$PWD/controllers/comicdownloadinfocontroller.cpp \ + $$PWD/controllers/synccontroller.cpp + +include(lib/bfLogging/bfLogging.pri) +include(lib/bfHttpServer/bfHttpServer.pri) +include(lib/bfTemplateEngine/bfTemplateEngine.pri) diff --git a/YACReaderLibrary/server/startup.cpp b/YACReaderLibrary/server/startup.cpp new file mode 100644 index 00000000..7166e402 --- /dev/null +++ b/YACReaderLibrary/server/startup.cpp @@ -0,0 +1,89 @@ +/** + @file + @author Stefan Frings +*/ + +#include "static.h" +#include "startup.h" +#include "dualfilelogger.h" +#include "httplistener.h" +#include "requestmapper.h" +#include "staticfilecontroller.h" + +#include "yacreader_global.h" + +#include +#include + +/** Name of this application */ +#define APPNAME "YACReaderLibrary" + +/** Publisher of this application */ +#define ORGANISATION "YACReader" + +/** Short description of this application */ +#define DESCRIPTION "Comic reader and organizer" + +void Startup::start() { + // Initialize the core application + QCoreApplication* app = QApplication::instance(); + app->setApplicationName(APPNAME); + app->setOrganizationName(ORGANISATION); + QString configFileName=YACReader::getSettingsPath()+"/"+QCoreApplication::applicationName()+".ini"; + + // Configure logging into files + QSettings* mainLogSettings=new QSettings(configFileName,QSettings::IniFormat,app); + mainLogSettings->beginGroup("mainLogFile"); + //QSettings* debugLogSettings=new QSettings(configFileName,QSettings::IniFormat,app); + //debugLogSettings->beginGroup("debugLogFile"); + Logger* logger=new FileLogger(mainLogSettings,10000,app); + logger->installMsgHandler(); + + // Configure template loader and cache + QSettings* templateSettings=new QSettings(configFileName,QSettings::IniFormat,app); + templateSettings->beginGroup("templates"); + Static::templateLoader=new TemplateCache(templateSettings,app); + + // Configure session store + QSettings* sessionSettings=new QSettings(configFileName,QSettings::IniFormat,app); + sessionSettings->beginGroup("sessions"); + Static::sessionStore=new HttpSessionStore(sessionSettings,app); + + // Configure static file controller + QSettings* fileSettings=new QSettings(configFileName,QSettings::IniFormat,app); + fileSettings->beginGroup("docroot"); + Static::staticFileController=new StaticFileController(fileSettings,app); + + // Configure and start the TCP listener + qDebug("ServiceHelper: Starting service"); + QSettings* listenerSettings=new QSettings(configFileName,QSettings::IniFormat,app); + listenerSettings->beginGroup("listener"); + listener = new HttpListener(listenerSettings,new RequestMapper(app),app); + + qDebug("ServiceHelper: Service has started"); +} + + +void Startup::stop() { + qDebug("ServiceHelper: Service has been stopped"); + // QCoreApplication destroys all objects that have been created in start(). + if(listener!=nullptr) + { + listener->close(); + delete listener; + listener = nullptr; + } +} + + +Startup::Startup() +{ + +} + +QString Startup::getPort() +{ + return QString("%1").arg(listener->serverPort()); +} + + diff --git a/YACReaderLibrary/server/startup.h b/YACReaderLibrary/server/startup.h new file mode 100644 index 00000000..1ad5ebbe --- /dev/null +++ b/YACReaderLibrary/server/startup.h @@ -0,0 +1,34 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef STARTUP_H +#define STARTUP_H + +#include + +class HttpListener; +/** + Helper class to install and run the application as a windows + service. +*/ +class Startup +{ +private: + //QTcpServer + HttpListener * listener; +public: + + /** Constructor */ + Startup(); + /** Start the server */ + void start(); + /** Stop the server */ + void stop(); + + QString getPort(); +protected: +}; + +#endif // STARTUP_H diff --git a/YACReaderLibrary/server/static.cpp b/YACReaderLibrary/server/static.cpp new file mode 100644 index 00000000..49e0060e --- /dev/null +++ b/YACReaderLibrary/server/static.cpp @@ -0,0 +1,63 @@ +/** + @file + @author Stefan Frings +*/ + +#include "static.h" +#include +#include +#include +#include + +QString Static::configDir=0; + +TemplateLoader* Static::templateLoader=0; + +HttpSessionStore* Static::sessionStore=0; + +StaticFileController* Static::staticFileController=0; + +QString Static::getConfigFileName() { + return QString("%1/%2.ini").arg(getConfigDir()).arg(QCoreApplication::applicationName()); +} + +QString Static::getConfigDir() { + if (!configDir.isNull()) { + return configDir; + } + // Search config file + #if defined Q_OS_UNIX && !defined Q_OS_MAC + QString binDir=(QString(DATADIR)+"/yacreader"); + #else + QString binDir=QCoreApplication::applicationDirPath(); + #endif + QString organization=QCoreApplication::organizationName(); + QString configFileName=QCoreApplication::applicationName()+".ini"; + + QStringList searchList; + searchList.append(QDir::cleanPath(binDir)); + searchList.append(QDir::cleanPath(binDir+"/../etc")); + searchList.append(QDir::cleanPath(binDir+"/../../etc")); // for development under windows + searchList.append(QDir::rootPath()+"etc/xdg/"+organization); + searchList.append(QDir::rootPath()+"etc/opt"); + searchList.append(QDir::rootPath()+"etc"); + + foreach (QString dir, searchList) { + QFile file(dir+"/"+configFileName); + if (file.exists()) { + // found + configDir=dir; + qDebug("Using config file %s",qPrintable(file.fileName())); + return configDir; + } + } + + // not found + foreach (QString dir, searchList) { + qWarning("%s/%s not found",qPrintable(dir),qPrintable(configFileName)); + } + qWarning("Cannot find config file %s",qPrintable(configFileName)); //TODO establecer los valores por defecto + + return 0; +} + diff --git a/YACReaderLibrary/server/static.h b/YACReaderLibrary/server/static.h new file mode 100644 index 00000000..74abf55b --- /dev/null +++ b/YACReaderLibrary/server/static.h @@ -0,0 +1,64 @@ +/** + @file + @author Stefan Frings +*/ + +#ifndef STATIC_H +#define STATIC_H + +#include +#include "templatecache.h" +#include "httpsessionstore.h" +#include "staticfilecontroller.h" + +/** + This class contains some static resources that are used by the application. +*/ + +class Static +{ +public: + + /** + Search the main config file and return its full path. + On the first call, the INI file gets searched. If not found, + the application aborts with an error message. +

+ The filename is the applications name plus the ending ".ini". It is searched + in the following directories: + + - Same directory as the applications executable file + - In ../etc relative to the applications executable file + - In ../../etc relative to the applications executable file + - In /etc/xdg/{organisation name} on the root drive + - In /etc/opt on the root drive + - In /etc on the root drive + + */ + static QString getConfigFileName(); + + /** + Gets the directory where the main config file is located. + On the first call, the INI file gets searched. If not found, + the application aborts with an error message. + @see getConfigFileName() + */ + static QString getConfigDir(); + + /** Cache for template files */ + static TemplateLoader* templateLoader; + + /** Storage for session cookies */ + static HttpSessionStore* sessionStore; + + /** Controller for static files */ + static StaticFileController* staticFileController; + +private: + + /** Directory of the main config file */ + static QString configDir; + +}; + +#endif // STATIC_H diff --git a/YACReaderLibrary/server_config_dialog.cpp b/YACReaderLibrary/server_config_dialog.cpp new file mode 100644 index 00000000..3e971668 --- /dev/null +++ b/YACReaderLibrary/server_config_dialog.cpp @@ -0,0 +1,348 @@ +#include "server_config_dialog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "startup.h" +#include "yacreader_global.h" + +#include "qnaturalsorting.h" + +#include + +//192.168 (most comon local subnet for ips are always put first) +//IPs are sorted using natoral sorting +bool ipComparator(const QString & ip1, const QString & ip2) +{ + if(ip1.startsWith("192.168") && ip2.startsWith("192.168")) + return naturalSortLessThanCI(ip1, ip2); + + if(ip1.startsWith("192.168")) + return true; + + if(ip2.startsWith("192.168")) + return false; + + return naturalSortLessThanCI(ip1, ip2); +} + +#ifndef Q_OS_WIN32 + +#include +#include +#include +#include +#include + +QList addresses() +{ + struct ifaddrs * ifAddrStruct=NULL; + struct ifaddrs * ifa=NULL; + void * tmpAddrPtr=NULL; + + QList localAddreses; + + getifaddrs(&ifAddrStruct); + + for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa ->ifa_addr) { + if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4 + // is a valid IP4 Address + tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; + char addressBuffer[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); + QString add(addressBuffer); + localAddreses.push_back(QString(addressBuffer)); + //printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer); + } else if (ifa->ifa_addr->sa_family==AF_INET6) { // check it is IP6 + // is a valid IP6 Address + tmpAddrPtr=&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; + char addressBuffer[INET6_ADDRSTRLEN]; + inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN); + //printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer); + } + } + } + if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct); + return localAddreses; +} + +#endif + +extern Startup * s; + +ServerConfigDialog::ServerConfigDialog(QWidget * parent) + :QDialog(parent) +{ + accept = new QPushButton(tr("set port"),this); + qrCodeImage = new QPixmap(); + qrCode = new QLabel(this); + qrCode->move(64, 112); + qrCode->setFixedSize(200,200); + qrCode->setScaledContents(true); + + QLabel * title1 = new QLabel(tr("Server connectivity information"),this); + title1->move(332, 61); + title1->setStyleSheet("QLabel {color:#474747; font-size:30px; font-family: Arial;}"); + + QLabel * qrMessage = new QLabel(tr("Scan it!"),this); + qrMessage->move(135,388);//373,627); + qrMessage->setStyleSheet("QLabel {color:#A3A3A3; font-size:18px; font-family: Arial;}"); + qrMessage->setWordWrap(true); + qrMessage->setFixedWidth(200); + + QLabel * propaganda = new QLabel(tr("YACReader is available for iOS devices. Discover it! "),this); + propaganda->move(332,505); + propaganda->setStyleSheet("QLabel {color:#4D4D4D; font-size:13px; font-family: Arial; font-style: italic;}"); + /*propaganda->setWordWrap(true); + propaganda->setFixedWidth(590);*/ + propaganda->setOpenExternalLinks(true); + + //FORM--------------------------------------------------------------------- + + QLabel * ipLabel = new QLabel(tr("Choose an IP address"),this); + ipLabel->move(332,117); + ipLabel->setStyleSheet("QLabel {color:#575757; font-size:18px; font-family: Arial;}"); + + QLabel * portLabel = new QLabel(tr("Port"),this); + portLabel->move(332, 211); + portLabel->setStyleSheet("QLabel {color:#575757; font-size:18px; font-family: Arial;}"); + + ip = new QComboBox(this); + connect(ip,SIGNAL(activated(const QString &)),this,SLOT(regenerateQR(const QString &))); + + ip->setFixedWidth(200); + ip->move(332,153); + + + port = new QLineEdit("8080",this); + port->setReadOnly(false); + //port->setFixedWidth(100); + //port->move(332, 244); + + //port->move(520,110); + QValidator *validator = new QIntValidator(1024, 65535, this); + port->setValidator(validator); + + QWidget * portWidget = new QWidget(this); + QHBoxLayout * portWidgetLayout = new QHBoxLayout; + portWidgetLayout->addWidget(port); + portWidgetLayout->addWidget(accept); + portWidgetLayout->setMargin(0); + portWidget->setLayout(portWidgetLayout); + portWidget->move(332, 244); + //accept->move(514,149); + connect(accept,SIGNAL(pressed()),this,SLOT(updatePort())); + //END FORM----------------------------------------------------------------- + + check = new QCheckBox(this); + check->move(332,314); + check->setText(tr("enable the server")); + check->setStyleSheet("QCheckBox {color:#262626; font-size:13px; font-family: Arial;}"); + + + //accept->move(444, 242); + //check->setLayoutDirection(Qt::RightToLeft); + + //elementsLayout->setSpacing(40); + //elementsLayout->addWidget(iphone); + //elementsLayout->addStretch(); + //elementsLayout->addLayout(configLayout); + + //QVBoxLayout * mainLayout = new QVBoxLayout; + //mainLayout->addLayout(elementsLayout); + //mainLayout->addLayout(buttons); + //mainLayout->addWidget(qrCode,0,1); + + //this->setLayout(mainLayout); + + QPalette Pal(palette()); + // set black background + QPalette palette; + QImage image(":/images/serverConfigBackground.png"); + palette.setBrush(this->backgroundRole(), QBrush(image)); + + setPalette(palette); + + this->setFixedSize(image.size()); + + QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + settings->beginGroup("libraryConfig"); + + if(settings->value(SERVER_ON,true).toBool()) + { + check->setChecked(true); + generateQR(); + } + else + check->setChecked(false); + + settings->endGroup(); + + connect(check,SIGNAL(stateChanged(int)),this,SLOT(enableServer(int))); +} + +void ServerConfigDialog::enableServer(int status) +{ + QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + settings->beginGroup("libraryConfig"); + + if(status == Qt::Checked) + { + s->start(); + this->generateQR(); + settings->setValue(SERVER_ON,true); + } + else + { + s->stop(); + qrCode->setPixmap(QPixmap()); + ip->clear(); + port->setText(""); + settings->setValue(SERVER_ON,false); + } + settings->endGroup(); +} + +void ServerConfigDialog::generateQR() +{ + //QString items; + //foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces()) + //{ + // if (~interface.flags() & QNetworkInterface::IsLoopBack)//interface.flags().testFlag(QNetworkInterface::IsRunning)) + // foreach (QNetworkAddressEntry entry, interface.addressEntries()) + // { + // if ( interface.hardwareAddress() != "00:00:00:00:00:00" && entry.ip().toString().contains(".")) + // items.append(interface.name() + entry.ip().toString()); + // } + //} + ip->clear(); + QString dir; + +#ifdef Q_OS_WIN32 + QList list = QHostInfo::fromName( QHostInfo::localHostName() ).addresses(); + + QList otherAddresses; + foreach(QHostAddress add, list) + { + QString tmp = add.toString(); + if(tmp.contains(".") && !tmp.startsWith("127")) + { + otherAddresses.push_back(tmp); + } + } + +#else + QList list = addresses(); + + QList otherAddresses; + foreach(QString add, list) + { + QString tmp = add; + if(tmp.contains(".") && !tmp.startsWith("127")) + { + otherAddresses.push_back(tmp); + } + } +#endif + + std::sort(otherAddresses.begin(),otherAddresses.end(),ipComparator); + + if(!otherAddresses.isEmpty()) + { + dir = otherAddresses.first(); + otherAddresses.pop_front(); + } + + if(otherAddresses.length()>0 || !dir.isEmpty()) + { + if(!dir.isEmpty()) + { + generateQR(dir+":"+s->getPort()); + + ip->addItem(dir); + } + else + { + generateQR(otherAddresses.first()+":"+s->getPort()); + } + ip->addItems(otherAddresses); + port->setText(s->getPort()); + } + else + { + + } + //qrCode->setText(dir+":8080"); +} + +void ServerConfigDialog::generateQR(const QString & serverAddress) +{ + qrCode->clear(); + qrGenerator = new QProcess(); + QStringList attributes; + attributes << "-o" << "-" /*QCoreApplication::applicationDirPath()+"/utils/tmp.png"*/ << "-s" << "8" << "-l" << "H" << "-m" << "0" << serverAddress; + connect(qrGenerator,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(updateImage(void))); + connect(qrGenerator,SIGNAL(error(QProcess::ProcessError)),this,SLOT(openingError(QProcess::ProcessError))); //TODO: implement openingError +#if defined Q_OS_UNIX && !defined Q_OS_MAC + qrGenerator->start(QString("qrencode"),attributes); +#else + qrGenerator->start(QCoreApplication::applicationDirPath()+"/utils/qrencode",attributes); +#endif +} + +void ServerConfigDialog::updateImage() +{ + QByteArray imgBinary = qrGenerator->readAllStandardOutput(); + //imgBinary = imgBinary.replace(0x0D0A,0x0A); + + if(!qrCodeImage->loadFromData(imgBinary)) + qrCode->setText(tr("QR generator error!")); + else + { + QPixmap p = *qrCodeImage; + QPixmap pMask( p.size() ); + pMask.fill( QColor(66, 66, 66) ); + pMask.setMask( p.createMaskFromColor( Qt::white ) ); + + *qrCodeImage = pMask; + + qrCode->setPixmap(*qrCodeImage); + } + + delete qrGenerator; + + + +/* qrCodeImage->load(QCoreApplication::applicationDirPath()+"/utils/tmp.png"); + qrCode->setPixmap(*qrCodeImage); + + delete qrGenerator;*/ +} + +void ServerConfigDialog::regenerateQR(const QString & ip) +{ + generateQR(ip+":"+s->getPort()); +} + +void ServerConfigDialog::updatePort() +{ + + QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + settings->beginGroup("listener"); + settings->setValue("port",port->text().toInt()); + settings->endGroup(); + + s->stop(); + s->start(); + + generateQR(ip->currentText()+":"+port->text()); + +} diff --git a/YACReaderLibrary/server_config_dialog.h b/YACReaderLibrary/server_config_dialog.h new file mode 100644 index 00000000..dfe441b5 --- /dev/null +++ b/YACReaderLibrary/server_config_dialog.h @@ -0,0 +1,45 @@ +#ifndef __SERVER_CONFIG_DIALOG_H +#define __SERVER_CONFIG_DIALOG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class ServerConfigDialog : public QDialog +{ +Q_OBJECT + public: + ServerConfigDialog(QWidget * parent = 0); + private: + QComboBox * ip; + QLineEdit * port; + + QCheckBox * check; + + QPushButton * close; + QPushButton * accept; + QLabel * qrCode; + QPixmap * qrCodeImage; + + QProcess * qrGenerator; + + public slots: + void generateQR(); + void generateQR(const QString & serverAddress); + void regenerateQR(const QString & ip); + void updateImage(); + void enableServer(int status); + void updatePort(); +signals: + void portChanged(QString port); + +}; + + +#endif diff --git a/YACReaderLibrary/yacreader_folders_view.cpp b/YACReaderLibrary/yacreader_folders_view.cpp new file mode 100644 index 00000000..0f774bc5 --- /dev/null +++ b/YACReaderLibrary/yacreader_folders_view.cpp @@ -0,0 +1,104 @@ +#include "yacreader_folders_view.h" + +#include "folder_item.h" +#include "folder_model.h" + +#include "comic.h" +#include "comic_files_manager.h" + +#include "QsLog.h" + + +YACReaderFoldersView::YACReaderFoldersView(QWidget * parent) + :YACReaderTreeView(parent) +{ + setItemDelegate(new YACReaderFoldersViewItemDeletegate(this)); +} + +void YACReaderFoldersView::dragEnterEvent(QDragEnterEvent *event) +{ + YACReaderTreeView::dragEnterEvent(event); + + QList urlList; + + if (event->mimeData()->hasUrls() && event->dropAction() == Qt::CopyAction) + { + urlList = event->mimeData()->urls(); + QString currentPath; + foreach (QUrl url, urlList) + { + //comics or folders are accepted, folders' content is validate in dropEvent (avoid any lag before droping) + currentPath = url.toLocalFile(); + if(Comic::fileIsComic(currentPath) || QFileInfo(currentPath).isDir()) + { + event->acceptProposedAction(); + return; + } + } + } +} + +void YACReaderFoldersView::dragLeaveEvent(QDragLeaveEvent *event) +{ + YACReaderTreeView::dragLeaveEvent(event); +} + +void YACReaderFoldersView::dragMoveEvent(QDragMoveEvent *event) +{ + YACReaderTreeView::dragMoveEvent(event); + event->acceptProposedAction(); +} + +void YACReaderFoldersView::dropEvent(QDropEvent *event) +{ + YACReaderTreeView::dropEvent(event); + + QLOG_DEBUG() << "drop on tree" << event->dropAction(); + + bool validAction = event->dropAction() == Qt::CopyAction; // || event->dropAction() & Qt::MoveAction; TODO move + + if(validAction) + { + QList > droppedFiles = ComicFilesManager::getDroppedFiles(event->mimeData()->urls()); + QModelIndex destinationIndex = indexAt(event->pos()); + + if(event->dropAction() == Qt::CopyAction) + { + QLOG_DEBUG() << "copy - tree :" << droppedFiles; + emit copyComicsToFolder(droppedFiles, destinationIndex); + } + else if(event->dropAction() & Qt::MoveAction) + { + QLOG_DEBUG() << "move - tree :" << droppedFiles; + emit moveComicsToFolder(droppedFiles, destinationIndex); + } + + event->acceptProposedAction(); + } +} + +//---------------------------------------------------------- + +YACReaderFoldersViewItemDeletegate::YACReaderFoldersViewItemDeletegate(QObject *parent) + :QStyledItemDelegate(parent) +{ + +} + +void YACReaderFoldersViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + if(!index.data(FolderModel::CompletedRole).toBool()) + { + painter->save(); +#ifdef Q_OS_MAC + painter->setBrush(QBrush(QColor(85,95,127))); +#else + painter->setBrush(QBrush(QColor(237,197,24))); +#endif + painter->setPen(QPen(QBrush(),0)); + painter->drawRect(0,option.rect.y(),2,option.rect.height()); + painter->restore(); + } + + QStyledItemDelegate::paint(painter, option, index); +} diff --git a/YACReaderLibrary/yacreader_folders_view.h b/YACReaderLibrary/yacreader_folders_view.h new file mode 100644 index 00000000..07d8091c --- /dev/null +++ b/YACReaderLibrary/yacreader_folders_view.h @@ -0,0 +1,36 @@ +#ifndef YACREADER_FOLDERS_VIEW_H +#define YACREADER_FOLDERS_VIEW_H + +#include "yacreader_treeview.h" + +#include + +class YACReaderFoldersView : public YACReaderTreeView +{ + Q_OBJECT +public: + explicit YACReaderFoldersView(QWidget * parent = 0); + +signals: + //Drops + void copyComicsToFolder(QList >,QModelIndex); + void moveComicsToFolder(QList >,QModelIndex); + +protected: + //Drop to import + void dragEnterEvent(QDragEnterEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); +}; + +class YACReaderFoldersViewItemDeletegate: public QStyledItemDelegate +{ + Q_OBJECT +public: + explicit YACReaderFoldersViewItemDeletegate(QObject *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; +}; + + +#endif // YACREADER_FOLDERS_VIEW_H diff --git a/YACReaderLibrary/yacreader_history_controller.cpp b/YACReaderLibrary/yacreader_history_controller.cpp new file mode 100644 index 00000000..cfd82ca8 --- /dev/null +++ b/YACReaderLibrary/yacreader_history_controller.cpp @@ -0,0 +1,108 @@ +#include "yacreader_history_controller.h" + +YACReaderHistoryController::YACReaderHistoryController(QObject *parent) : + QObject(parent) +{ +} + +void YACReaderHistoryController::clear() +{ + currentFolderNavigation = 0; + history.clear(); + history.append(YACReaderLibrarySourceContainer(QModelIndex(),YACReaderLibrarySourceContainer::Folder)); //root folder is always the first item + + emit(enabledBackward(false)); + emit(enabledForward(false)); +} + +void YACReaderHistoryController::backward() +{ + if(currentFolderNavigation>0) + { + currentFolderNavigation--; + emit(modelIndexSelected(history.at(currentFolderNavigation))); + emit(enabledForward(true)); + } + + if(currentFolderNavigation==0) + emit(enabledBackward(false)); +} + +void YACReaderHistoryController::forward() +{ + if(currentFolderNavigation0) + { + numElementsToRemove--; + history.removeLast(); + } + + if(source!=history.at(currentFolderNavigation)) + { + history.append(source); + + emit(enabledBackward(true)); + currentFolderNavigation++; + } + + emit(enabledForward(false)); +} + +YACReaderLibrarySourceContainer YACReaderHistoryController::lastSourceContainer() +{ + return history.last(); +} + +YACReaderLibrarySourceContainer YACReaderHistoryController::currentSourceContainer() +{ + return history.at(currentFolderNavigation); +} + +//------------------------------------------------------------------------------ + +YACReaderLibrarySourceContainer::YACReaderLibrarySourceContainer() + :sourceModelIndex(QModelIndex()),type(None) +{ + +} + +YACReaderLibrarySourceContainer::YACReaderLibrarySourceContainer(const QModelIndex &sourceModelIndex, YACReaderLibrarySourceContainer::SourceType type) + :sourceModelIndex(sourceModelIndex),type(type) +{} + +QModelIndex YACReaderLibrarySourceContainer::getSourceModelIndex() const +{ + return sourceModelIndex; +} + +YACReaderLibrarySourceContainer::SourceType YACReaderLibrarySourceContainer::getType() const +{ + return type; +} + +bool YACReaderLibrarySourceContainer::operator==(const YACReaderLibrarySourceContainer &other) const +{ + return sourceModelIndex == other.sourceModelIndex && type == other.type; +} + +bool YACReaderLibrarySourceContainer::operator!=(const YACReaderLibrarySourceContainer &other) const +{ + return !(*this == other); +} diff --git a/YACReaderLibrary/yacreader_history_controller.h b/YACReaderLibrary/yacreader_history_controller.h new file mode 100644 index 00000000..25e4b8fd --- /dev/null +++ b/YACReaderLibrary/yacreader_history_controller.h @@ -0,0 +1,62 @@ +#ifndef YACREADER_HISTORY_CONTROLLER_H +#define YACREADER_HISTORY_CONTROLLER_H + +#include + +#include + +class YACReaderHistoryController; + +class YACReaderLibrarySourceContainer +{ +public: + enum SourceType { + None, + Folder, + List + }; + + explicit YACReaderLibrarySourceContainer(); + explicit YACReaderLibrarySourceContainer(const QModelIndex & sourceModelIndex, YACReaderLibrarySourceContainer::SourceType type); + QModelIndex getSourceModelIndex() const; + YACReaderLibrarySourceContainer::SourceType getType() const; + + bool operator==(const YACReaderLibrarySourceContainer& other) const; + bool operator!=(const YACReaderLibrarySourceContainer& other) const; + +protected: + QModelIndex sourceModelIndex; + YACReaderLibrarySourceContainer::SourceType type; + + friend class YACReaderHistoryController; + +}; + +Q_DECLARE_METATYPE(YACReaderLibrarySourceContainer) + +class YACReaderHistoryController : public QObject +{ + Q_OBJECT +public: + explicit YACReaderHistoryController(QObject *parent = 0); + +signals: + void enabledForward(bool enabled); + void enabledBackward(bool enabled); + void modelIndexSelected(YACReaderLibrarySourceContainer); + +public slots: + void clear(); + void backward(); + void forward(); + void updateHistory(const YACReaderLibrarySourceContainer & source); + YACReaderLibrarySourceContainer lastSourceContainer(); + YACReaderLibrarySourceContainer currentSourceContainer(); + +protected: + int currentFolderNavigation; + QList history; + +}; + +#endif // YACREADER_HISTORY_CONTROLLER_H diff --git a/YACReaderLibrary/yacreader_libraries.cpp b/YACReaderLibrary/yacreader_libraries.cpp new file mode 100644 index 00000000..2e5e3cd2 --- /dev/null +++ b/YACReaderLibrary/yacreader_libraries.cpp @@ -0,0 +1,147 @@ +#include "yacreader_libraries.h" +#include "yacreader_global.h" + + + +YACReaderLibraries::YACReaderLibraries() + :QObject() +{ + +} + +YACReaderLibraries::YACReaderLibraries(const YACReaderLibraries &source) + :QObject(),libraries(source.libraries) +{ + +} + +QList YACReaderLibraries::getNames() +{ + return libraries.keys(); +} + +QString YACReaderLibraries::getPath(const QString &name) +{ + return libraries.value(name).second; +} + +QString YACReaderLibraries::getPath(int id) +{ + foreach(QString name, libraries.keys()) + if(libraries.value(name).first == id) + return libraries.value(name).second; + return ""; +} + +QString YACReaderLibraries::getName(int id) +{ + foreach(QString name, libraries.keys()) + if(libraries.value(name).first == id) + return name; + return ""; +} + +bool YACReaderLibraries::isEmpty() +{ + return libraries.isEmpty(); +} + +bool YACReaderLibraries::contains(const QString &name) +{ + return libraries.contains(name); +} + +bool YACReaderLibraries::contains(int id) +{ + foreach(QString name, libraries.keys()) + if(libraries.value(name).first == id) + return true; + return false; +} + +void YACReaderLibraries::remove(const QString &name) +{ + libraries.remove(name); +} + +void YACReaderLibraries::rename(const QString &oldName, const QString &newName) +{ + if(libraries.contains(oldName)) + { + QPair value = libraries.value(oldName); + libraries.remove(oldName); + libraries.insert(newName,value); + } +} + +int YACReaderLibraries::getId(const QString &name) +{ + return libraries.value(name).first; +} + +YACReaderLibraries &YACReaderLibraries::operator=(const YACReaderLibraries &source) +{ + libraries = source.libraries; + return *this; +} + +QMap > YACReaderLibraries::getLibraries() +{ + return libraries; +} + + +void YACReaderLibraries::addLibrary(const QString &name, const QString &path) +{ + int newID=0; + foreach(QString lName, libraries.keys()) + newID = qMax(newID,libraries.value(lName).first); + newID++; + libraries.insert(name,QPair(newID,path)); +} + +void YACReaderLibraries::load() +{ + QSettings settings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); + + if(settings.value(LIBRARIES).isValid()) + { + QByteArray data = settings.value(LIBRARIES).toByteArray(); + QDataStream in(&data, QIODevice::ReadOnly); + in >> libraries; + } + else //only for compatibility with old versions (<7.0) + { + QFile f(QCoreApplication::applicationDirPath()+"/libraries.yacr"); + f.open(QIODevice::ReadOnly); + QTextStream txtS(&f); + QString content = txtS.readAll(); + QStringList lines = content.split('\n'); + QString line,name; + int i=0; + + foreach(line,lines) + { + if((i%2)==0) + name = line; + else + addLibrary(name.trimmed(),line.trimmed()); + i++; + } + f.close(); + if(save()) + f.remove(); + } +} + +bool YACReaderLibraries::save() +{ + QSettings settings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); + + QByteArray data; + QDataStream out(&data, QIODevice::WriteOnly); + out << libraries; + settings.setValue(LIBRARIES, data); + + return settings.isWritable(); +} diff --git a/YACReaderLibrary/yacreader_libraries.h b/YACReaderLibrary/yacreader_libraries.h new file mode 100644 index 00000000..5cc32a82 --- /dev/null +++ b/YACReaderLibrary/yacreader_libraries.h @@ -0,0 +1,34 @@ +#ifndef YACREADER_LIBRARIES_H +#define YACREADER_LIBRARIES_H + +#include + +class YACReaderLibraries : public QObject +{ + Q_OBJECT + +public: + YACReaderLibraries(); + YACReaderLibraries(const YACReaderLibraries & source); + QList getNames(); + QString getPath(const QString & name); + QString getPath(int id); + QString getName(int id); + bool isEmpty(); + bool contains(const QString & name); + bool contains(int id); + void remove(const QString & name); + void rename(const QString & oldName, const QString & newName); + int getId(const QString & name); + YACReaderLibraries & operator=(const YACReaderLibraries & source); + QMap > getLibraries(); +public slots: + void addLibrary(const QString & name, const QString & path); + void load(); + bool save(); +private: + //name + QMap > libraries; +}; + +#endif // YACREADER_LIBRARIES_H diff --git a/YACReaderLibrary/yacreader_local_server.cpp b/YACReaderLibrary/yacreader_local_server.cpp new file mode 100644 index 00000000..0e55078d --- /dev/null +++ b/YACReaderLibrary/yacreader_local_server.cpp @@ -0,0 +1,218 @@ +#include "yacreader_local_server.h" + +#include +#include +#include + +#include "yacreader_global.h" +#include "db_helper.h" + +#include "comic_db.h" + +#include "QsLog.h" + +using namespace YACReader; + +QMutex YACReaderClientConnectionWorker::dbMutex; +//int YACReaderClientConnectionWorker::count = 0; +YACReaderLocalServer::YACReaderLocalServer(QObject *parent) : + QObject(parent) +{ + localServer = new QLocalServer(this); + QLocalServer::removeServer(YACREADERLIBRARY_GUID); + if (!localServer->listen(YACREADERLIBRARY_GUID)) { + QLOG_ERROR() << "Unable to create local server"; + } + + connect(localServer, SIGNAL(newConnection()), this, SLOT(sendResponse())); +} + +bool YACReaderLocalServer::isListening() +{ + return localServer->isListening(); +} + +/*void YACReaderLocalServer::run() +{ + while(1) + exec(); +}*/ + +void YACReaderLocalServer::sendResponse() +{ + QLocalSocket *clientConnection = localServer->nextPendingConnection(); + //connect(clientConnection, SIGNAL(disconnected()),clientConnection, SLOT(deleteLater())); + clientConnection->setParent(0); + + YACReaderClientConnectionWorker * worker = new YACReaderClientConnectionWorker(clientConnection); + if(worker != 0) + { + clientConnection->moveToThread(worker); + connect(worker,SIGNAL(comicUpdated(quint64, ComicDB)),this,SIGNAL(comicUpdated(quint64, ComicDB))); + connect(worker,SIGNAL(finished()),worker,SLOT(deleteLater())); + worker->start(); + } + + QLOG_INFO() << "connection incoming"; + //clientConnection->waitForBytesWritten();*/ + //clientConnection->disconnectFromServer(); +} + +bool YACReaderLocalServer::isRunning() +{ + QLocalSocket socket; + socket.connectToServer(YACREADERLIBRARY_GUID); + if (socket.waitForConnected(500)) + return true; // Server is running (another instance of YACReaderLibrary has been launched) + return false; +} + +void YACReaderLocalServer::close() +{ + localServer->close(); +} + + +YACReaderClientConnectionWorker::YACReaderClientConnectionWorker( QLocalSocket *cc) + :QThread(),clientConnection(cc) +{ + +} + +YACReaderClientConnectionWorker::~YACReaderClientConnectionWorker() +{ + +} +/*#include +#include +#include */ +void YACReaderClientConnectionWorker::run() +{ + /*{ + QFile f(QString("c:/temp/thread%1.txt").arg(count)); + f.open(QIODevice::Append); + QTextStream out(&f); + out << QString("Thread%1 starts").arg(count) << endl; + f.close(); + } + uint t1 = QDateTime::currentMSecsSinceEpoch();*/ + + quint64 libraryId; + ComicDB comic; + int tries = 0; + int dataAvailable = 0; + QByteArray packageSize; + clientConnection->waitForReadyRead(1000); + while(packageSize.size() < sizeof(quint32) && tries < 20) + { + packageSize.append(clientConnection->read(sizeof(quint32) - packageSize.size())); + clientConnection->waitForReadyRead(100); + if(dataAvailable == packageSize.size()) + { + tries++; + } + dataAvailable = packageSize.size(); + } + if(tries == 20) + { + QLOG_ERROR() << "Local connection: unable to read the message size" << clientConnection->errorString(); + return; + } + + QDataStream sizeStream(packageSize); + sizeStream.setVersion(QDataStream::Qt_4_8); + quint32 totalSize = 0; + sizeStream >> totalSize; + + tries = 0; + QByteArray data; + int dataRead = 0; + while(data.size() < totalSize && tries < 200) + { + data.append(clientConnection->readAll()); + if(data.length() < totalSize) + clientConnection->waitForReadyRead(100); + if(dataRead == data.length()) //no bytes were read + tries++; + dataRead = data.length(); + } + if(tries == 200) + { + QLOG_ERROR() << QString("Local connection: unable to read message (%1,%2)").arg(data.size()).arg(totalSize); + return; + } + QDataStream dataStream(data); + quint8 msgType; + dataStream >> msgType; + dataStream >> libraryId; + dataStream >> comic; + + switch (msgType) + { + case YACReader::RequestComicInfo: + { + QList siblings; + getComicInfo(libraryId,comic,siblings); + + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_4_8); + out << (quint32)0; + out << comic; + out << siblings; + out.device()->seek(0); + out << (quint32)(block.size() - sizeof(quint32)); + + int written = 0; + tries = 0; + while(written != block.size() && tries < 200) + { + int ret = clientConnection->write(block); + clientConnection->waitForBytesWritten(10); + if(ret != -1) + { + written += ret; + clientConnection->flush(); + } + else + tries++; + } + if(tries == 200 && written != block.size()) + QLOG_ERROR() << QString("Local connection (comic info requested): unable to send response (%1,%2)").arg(written).arg(block.size()); + break; + } + case YACReader::SendComicInfo: + { + updateComic(libraryId,comic); + //clientConnection->disconnectFromServer(); + break; + } + + } + + clientConnection->waitForDisconnected(); + clientConnection->deleteLater(); + /*count++; + uint t2 = QDateTime::currentMSecsSinceEpoch(); + { + QFile f(QString("c:/temp/thread%1.txt").arg(count)); + f.open(QIODevice::Append); + QTextStream out(&f); + out << QString("Thread%1 ends : time - %2").arg(count).arg(t2-t1) << endl; + f.close(); + }*/ +} + +void YACReaderClientConnectionWorker::getComicInfo(quint64 libraryId, ComicDB & comic, QList & siblings) +{ + QMutexLocker locker(&dbMutex); + comic = DBHelper::getComicInfo(libraryId, comic.id); + siblings = DBHelper::getSiblings(libraryId, comic.parentId); +} + +void YACReaderClientConnectionWorker::updateComic(quint64 libraryId, ComicDB & comic) +{ + QMutexLocker locker(&dbMutex); + DBHelper::update(libraryId, comic.info); + emit comicUpdated(libraryId, comic); +} diff --git a/YACReaderLibrary/yacreader_local_server.h b/YACReaderLibrary/yacreader_local_server.h new file mode 100644 index 00000000..d5432e60 --- /dev/null +++ b/YACReaderLibrary/yacreader_local_server.h @@ -0,0 +1,50 @@ +#ifndef YACREADER_LOCAL_SERVER_H +#define YACREADER_LOCAL_SERVER_H + +#include +#include +#include + +class QLocalServer; +class QLocalSocket; +class ComicDB; + +class YACReaderLocalServer : public QObject +{ + Q_OBJECT +public: + explicit YACReaderLocalServer(QObject *parent = 0); + +signals: + void comicUpdated(quint64 libraryId, const ComicDB & comic); +public slots: + bool isListening(); + void sendResponse(); + static bool isRunning(); + void close(); +private: + //void run(); + QLocalServer * localServer; + +}; + +class YACReaderClientConnectionWorker : public QThread +{ + Q_OBJECT +public: + YACReaderClientConnectionWorker( QLocalSocket *clientConnection); + ~YACReaderClientConnectionWorker(); +signals: + void comicUpdated(quint64 libraryId, const ComicDB & comic); +private: + static QMutex dbMutex; + //static int count; + void run(); + + void getComicInfo(quint64 libraryId, ComicDB & comic, QList & sibling); + void updateComic(quint64 libraryId, ComicDB & comic); + + QLocalSocket *clientConnection; +}; + +#endif // YACREADER_LOCAL_SERVER_H diff --git a/YACReaderLibrary/yacreader_main_toolbar.cpp b/YACReaderLibrary/yacreader_main_toolbar.cpp new file mode 100644 index 00000000..e4562abd --- /dev/null +++ b/YACReaderLibrary/yacreader_main_toolbar.cpp @@ -0,0 +1,151 @@ +#include "yacreader_main_toolbar.h" + +#include +#include +#include +#include +#include +#include +#include + +YACReaderMainToolBar::YACReaderMainToolBar(QWidget *parent) : + QWidget(parent) +{ + mainLayout = new QHBoxLayout; + + currentFolder = new QLabel(this); + //currentFolder->setAlignment(Qt::AlignCenter); + currentFolder->setStyleSheet(" QLabel {color:#404040; font-size:22px; font-weight:bold;}"); + + QFont f=currentFolder->font(); + f.setStyleStrategy(QFont::PreferAntialias); + currentFolder->setFont(f); + + QString qToolButtonStyleSheet = "QToolButton {border:none;}"; + + backButton = new QToolButton(); + backButton->setStyleSheet(qToolButtonStyleSheet); + + + forwardButton = new QToolButton(); + forwardButton->setStyleSheet(qToolButtonStyleSheet); + forwardButton->setDisabled(true); + + settingsButton = new QToolButton(); + settingsButton->setStyleSheet(qToolButtonStyleSheet); + settingsButton->setIconSize(QSize(24,24)); + + serverButton = new QToolButton(); + serverButton->setStyleSheet(qToolButtonStyleSheet); + serverButton->setIconSize(QSize(17,24)); + + + helpButton = new QToolButton(); + helpButton->setStyleSheet(qToolButtonStyleSheet); + helpButton->setIconSize(QSize(14,25)); + + toggleComicsViewButton = new QToolButton; + toggleComicsViewButton->setStyleSheet(qToolButtonStyleSheet); + toggleComicsViewButton->setIconSize(QSize(24,24)); + + fullscreenButton = new QToolButton(); + fullscreenButton->setStyleSheet(qToolButtonStyleSheet); + fullscreenButton->setIconSize(QSize(24,24)); + + mainLayout->setMargin(0); + mainLayout->setSpacing(0); + + mainLayout->addSpacing(12); + mainLayout->addWidget(backButton,0,Qt::AlignVCenter); + addDivider(); + mainLayout->addWidget(forwardButton,0,Qt::AlignVCenter); + + mainLayout->addSpacing(34); + mainLayout->addWidget(settingsButton,0,Qt::AlignVCenter); + addWideDivider(); + mainLayout->addWidget(serverButton,0,Qt::AlignVCenter); + addWideDivider(); + mainLayout->addWidget(helpButton,0,Qt::AlignVCenter); + + mainLayout->addStretch(); + + mainLayout->addWidget(toggleComicsViewButton,0,Qt::AlignVCenter); + addWideDivider(); + mainLayout->addWidget(fullscreenButton,0,Qt::AlignVCenter); + + setLayout(mainLayout); + + setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); +} + + +QSize YACReaderMainToolBar::sizeHint() const +{ + return QSize(200,40); +} + +void YACReaderMainToolBar::setSearchWidget(QWidget *w) +{ + addWideDivider(); + mainLayout->addWidget(w,0,Qt::AlignVCenter); +} + +void YACReaderMainToolBar::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event); + + QPainter painter (this); + painter.fillRect(0,0,width(),height(),QColor("#F0F0F0")); +} + +void YACReaderMainToolBar::resizeEvent(QResizeEvent * event) +{ + //210px x 2 = 420px + int freeWidth = event->size().width() - 420; + int maxLabelWidth = freeWidth>=0?freeWidth:0; + currentFolder->setMaximumWidth(maxLabelWidth); + currentFolder->adjustSize(); + + QFontMetrics metrix(currentFolder->font()); + QString clippedText = metrix.elidedText(currentFolderName, Qt::ElideRight, maxLabelWidth); + + currentFolder->setText(clippedText); + currentFolder->adjustSize(); + currentFolder->move((event->size().width()-currentFolder->width())/2,(event->size().height()-currentFolder->height())/2); +} + +void YACReaderMainToolBar::addDivider() +{ + QPixmap img(":/images/main_toolbar/divider.png"); + QLabel * divider = new QLabel(); + divider->setPixmap(img); + + mainLayout->addSpacing(5); + mainLayout->addWidget(divider,0,Qt::AlignVCenter); + mainLayout->addSpacing(5); +} + +void YACReaderMainToolBar::addWideDivider() +{ + mainLayout->addSpacing(3); + addDivider(); + mainLayout->addSpacing(3); +} + +void YACReaderMainToolBar::setCurrentFolderName(const QString & name) +{ + currentFolder->setText(name); + currentFolderName = name; + currentFolder->adjustSize(); + + int freeWidth = size().width() - 420; + int maxLabelWidth = freeWidth>=0?freeWidth:0; + currentFolder->setMaximumWidth(maxLabelWidth); + + QFontMetrics metrix(currentFolder->font()); + QString clippedText = metrix.elidedText(currentFolderName, Qt::ElideRight, maxLabelWidth); + + currentFolder->setText(clippedText); + currentFolder->adjustSize(); + currentFolder->move((width()-currentFolder->width())/2,(height()-currentFolder->height())/2); +} diff --git a/YACReaderLibrary/yacreader_main_toolbar.h b/YACReaderLibrary/yacreader_main_toolbar.h new file mode 100644 index 00000000..b8ed359e --- /dev/null +++ b/YACReaderLibrary/yacreader_main_toolbar.h @@ -0,0 +1,51 @@ +#ifndef YACREADER_MAIN_TOOLBAR_H +#define YACREADER_MAIN_TOOLBAR_H + +#include + +class QToolButton; +class QLabel; +class QResizeEvent; +class QPaintEvent; +class QHBoxLayout; + +//TODO create methods for adding actions, separators and sctreches dynimically +class YACReaderMainToolBar : public QWidget +{ + Q_OBJECT +public: + explicit YACReaderMainToolBar(QWidget *parent = 0); + QSize sizeHint() const; + + QToolButton * backButton; + QToolButton * forwardButton; + QToolButton * settingsButton; + QToolButton * serverButton; + QToolButton * helpButton; + QToolButton * toggleComicsViewButton; + QToolButton * fullscreenButton; + + void setSearchWidget(QWidget * w); + void setCurrentFolderName(const QString & name); +signals: + +public slots: + +private: + void paintEvent(QPaintEvent *); + void resizeEvent(QResizeEvent *); + + + + QHBoxLayout * mainLayout; + + QLabel * currentFolder; + QString currentFolderName; + + void addDivider(); + void addWideDivider(); + + +}; + +#endif // YACREADER_MAIN_TOOLBAR_H diff --git a/YACReaderLibrary/yacreader_navigation_controller.cpp b/YACReaderLibrary/yacreader_navigation_controller.cpp new file mode 100644 index 00000000..3996932b --- /dev/null +++ b/YACReaderLibrary/yacreader_navigation_controller.cpp @@ -0,0 +1,304 @@ +#include "yacreader_navigation_controller.h" + +#include + +#include "library_window.h" +#include "yacreader_folders_view.h" +#include "yacreader_reading_lists_view.h" +#include "folder_item.h" +#include "yacreader_history_controller.h" +#include "comic_model.h" +#include "folder_model.h" +#include "reading_list_model.h" +#include "comics_view.h" +#include "empty_folder_widget.h" +#include "yacreader_search_line_edit.h" +#include "yacreader_global.h" +#include "empty_label_widget.h" +#include "empty_special_list.h" + +#include "QsLog.h" + +YACReaderNavigationController::YACReaderNavigationController(LibraryWindow *parent) : + QObject(parent),libraryWindow(parent) +{ + setupConnections(); +} + +void YACReaderNavigationController::selectedFolder(const QModelIndex &mi) +{ + //A proxy is used + QModelIndex modelIndex = libraryWindow->foldersModelProxy->mapToSource(mi); + + //update history + libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(modelIndex, YACReaderLibrarySourceContainer::Folder)); + + if(libraryWindow->status == LibraryWindow::Searching) + { + //when a folder is selected the search mode has to be reset + libraryWindow->searchEdit->clearText(); + libraryWindow->clearSearchFilter(); + libraryWindow->foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop); + libraryWindow->foldersView->setCurrentIndex(mi); + } + + loadFolderInfo(modelIndex); + + libraryWindow->setToolbarTitle(modelIndex); +} + +void YACReaderNavigationController::reselectCurrentFolder() +{ + selectedFolder(libraryWindow->foldersView->currentIndex()); +} + +void YACReaderNavigationController::loadFolderInfo(const QModelIndex &modelIndex) +{ + //Get FolderItem + qulonglong folderId = folderModelIndexToID(modelIndex); + + //check comics in folder with id = folderId + libraryWindow->comicsModel->setupFolderModelData(folderId,libraryWindow->foldersModel->getDatabase()); + libraryWindow->comicsView->setModel(libraryWindow->comicsModel); + + //configure views + if(libraryWindow->comicsModel->rowCount() > 0) + { + //updateView + libraryWindow->showComicsView(); + libraryWindow->disableComicsActions(false); + } + else{ + //showEmptyFolder + loadEmptyFolderInfo(modelIndex); + libraryWindow->showEmptyFolderView(); + libraryWindow->disableComicsActions(true); + } + + //libraryWindow->updateFoldersViewConextMenu(modelIndex); + + //if a folder is selected, listsView selection must be cleared + libraryWindow->listsView->clearSelection(); +} + +void YACReaderNavigationController::loadListInfo(const QModelIndex &modelIndex) +{ + switch(modelIndex.data(ReadingListModel::TypeListsRole).toInt()) + { + case ReadingListModel::SpecialList: + loadSpecialListInfo(modelIndex); + break; + + case ReadingListModel::Label: + loadLabelInfo(modelIndex); + break; + + case ReadingListModel::ReadingList: + loadReadingListInfo(modelIndex); + break; + } + + //if a list is selected, foldersView selection must be cleared + libraryWindow->foldersView->clearSelection(); +} + +void YACReaderNavigationController::loadSpecialListInfo(const QModelIndex &modelIndex) +{ + ReadingListModel::TypeSpecialList type = (ReadingListModel::TypeSpecialList)modelIndex.data(ReadingListModel::SpecialListTypeRole).toInt(); + + switch(type) + { + case ReadingListModel::Favorites: + libraryWindow->comicsModel->setupFavoritesModelData(libraryWindow->foldersModel->getDatabase()); + break; + case ReadingListModel::Reading: + libraryWindow->comicsModel->setupReadingModelData(libraryWindow->foldersModel->getDatabase()); + break; + } + + libraryWindow->comicsView->setModel(libraryWindow->comicsModel); + + if(libraryWindow->comicsModel->rowCount() > 0) + { + libraryWindow->showComicsView(); + libraryWindow->disableComicsActions(false); + } + else + { + //setup empty special list widget + switch(type) + { + case ReadingListModel::Favorites: + libraryWindow->emptySpecialList->setPixmap(QPixmap(":/images/empty_favorites.png")); + libraryWindow->emptySpecialList->setText(tr("No favorites")); + break; + case ReadingListModel::Reading: + libraryWindow->emptySpecialList->setPixmap(QPixmap(":/images/empty_current_readings.png")); + libraryWindow->emptySpecialList->setText(tr("You are not reading anything yet, come on!!")); + break; + } + + libraryWindow->showEmptySpecialList(); + libraryWindow->disableComicsActions(true); + } +} + +void YACReaderNavigationController::loadLabelInfo(const QModelIndex &modelIndex) +{ + qulonglong id = modelIndex.data(ReadingListModel::IDRole).toULongLong(); + //check comics in label with id = id + libraryWindow->comicsModel->setupLabelModelData(id,libraryWindow->foldersModel->getDatabase()); + libraryWindow->comicsView->setModel(libraryWindow->comicsModel); + + //configure views + if(libraryWindow->comicsModel->rowCount() > 0) + { + //updateView + libraryWindow->showComicsView(); + libraryWindow->disableComicsActions(false); + } + else{ + //showEmptyFolder + //loadEmptyLabelInfo(); //there is no info in an empty label by now, TODO design something + libraryWindow->emptyLabelWidget->setColor((YACReader::LabelColors)modelIndex.data(ReadingListModel::LabelColorRole).toInt()); + libraryWindow->showEmptyLabelView(); + libraryWindow->disableComicsActions(true); + } +} + +void YACReaderNavigationController::loadReadingListInfo(const QModelIndex &modelIndex) +{ + qulonglong id = modelIndex.data(ReadingListModel::IDRole).toULongLong(); + //check comics in label with id = id + libraryWindow->comicsModel->setupReadingListModelData(id,libraryWindow->foldersModel->getDatabase()); + libraryWindow->comicsView->setModel(libraryWindow->comicsModel); + + //configure views + if(libraryWindow->comicsModel->rowCount() > 0) + { + //updateView + libraryWindow->showComicsView(); + libraryWindow->disableComicsActions(false); + } + else{ + libraryWindow->showEmptyReadingListWidget(); + libraryWindow->disableComicsActions(true); + } +} + +void YACReaderNavigationController::selectedList(const QModelIndex &mi) +{ + //A proxy is used + QModelIndex modelIndex = libraryWindow->listsModelProxy->mapToSource(mi); + + //update history + libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(modelIndex,YACReaderLibrarySourceContainer::List)); + + if(libraryWindow->status == LibraryWindow::Searching) + { + //when a list is selected the search mode has to be reset + libraryWindow->searchEdit->clearText(); + libraryWindow->clearSearchFilter(); + libraryWindow->listsView->scrollTo(mi,QAbstractItemView::PositionAtTop); + libraryWindow->listsView->setCurrentIndex(mi); + } + + loadListInfo(modelIndex); + + libraryWindow->setToolbarTitle(modelIndex); +} + +void YACReaderNavigationController::reselectCurrentList() +{ + selectedList(libraryWindow->listsView->currentIndex()); +} + +void YACReaderNavigationController::reselectCurrentSource() +{ + if(!libraryWindow->listsView->selectionModel()->selectedRows().isEmpty()) + { + reselectCurrentList(); + }else + { + reselectCurrentFolder(); + } +} + +void YACReaderNavigationController::selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer) +{ + //TODO NO searching allowed, just disable backward/forward actions in searching mode + if(libraryWindow->status == LibraryWindow::Searching) + { + //when a folder is selected the search mode has to be reset + libraryWindow->searchEdit->clearText(); + libraryWindow->clearSearchFilter(); + } + + loadIndexFromHistory(sourceContainer); +} + +void YACReaderNavigationController::loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer) +{ + QModelIndex sourceMI = sourceContainer.getSourceModelIndex(); + switch(sourceContainer.getType()) + { + case YACReaderLibrarySourceContainer::Folder: + { + QModelIndex mi = libraryWindow->foldersModelProxy->mapFromSource(sourceMI); + libraryWindow->foldersView->scrollTo(mi,QAbstractItemView::PositionAtTop); + libraryWindow->foldersView->setCurrentIndex(mi); + loadFolderInfo(sourceMI); + break; + } + case YACReaderLibrarySourceContainer::List: + { + QModelIndex mi = libraryWindow->listsModelProxy->mapFromSource(sourceMI); + libraryWindow->listsView->scrollTo(mi,QAbstractItemView::PositionAtTop); + libraryWindow->listsView->setCurrentIndex(mi); + loadListInfo(sourceMI); + break; + } + } +} + +void YACReaderNavigationController::selectSubfolder(const QModelIndex &sourceMIParent, int child) +{ + QModelIndex dest = libraryWindow->foldersModel->index(child,0,sourceMIParent); + libraryWindow->foldersView->setCurrentIndex(libraryWindow->foldersModelProxy->mapFromSource(dest)); + libraryWindow->historyController->updateHistory(YACReaderLibrarySourceContainer(dest,YACReaderLibrarySourceContainer::Folder)); + loadFolderInfo(dest); +} + +void YACReaderNavigationController::loadEmptyFolderInfo(const QModelIndex &modelIndex) +{ + QStringList subfolders; + subfolders = libraryWindow->foldersModel->getSubfoldersNames(modelIndex); + libraryWindow->emptyFolderWidget->setSubfolders(modelIndex,subfolders); +} + +void YACReaderNavigationController::loadPreviousStatus() +{ + YACReaderLibrarySourceContainer sourceContainer = libraryWindow->historyController->currentSourceContainer(); + loadIndexFromHistory(sourceContainer); +} + +void YACReaderNavigationController::setupConnections() +{ + connect(libraryWindow->foldersView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedFolder(QModelIndex))); + connect(libraryWindow->listsView,SIGNAL(clicked(QModelIndex)),this,SLOT(selectedList(QModelIndex))); + connect(libraryWindow->historyController,SIGNAL(modelIndexSelected(YACReaderLibrarySourceContainer)),this,SLOT(selectedIndexFromHistory(YACReaderLibrarySourceContainer))); + connect(libraryWindow->emptyFolderWidget,SIGNAL(subfolderSelected(QModelIndex,int)),this,SLOT(selectSubfolder(QModelIndex,int))); + connect(libraryWindow->comicsModel,SIGNAL(isEmpty()),this,SLOT(reselectCurrentSource())); +} + +qulonglong YACReaderNavigationController::folderModelIndexToID(const QModelIndex &mi) +{ + if(!mi.isValid()) + return 1; + + FolderItem * folderItem = static_cast(mi.internalPointer()); + if(folderItem != 0) + return folderItem->id; + + return 1; +} diff --git a/YACReaderLibrary/yacreader_navigation_controller.h b/YACReaderLibrary/yacreader_navigation_controller.h new file mode 100644 index 00000000..2dbeac28 --- /dev/null +++ b/YACReaderLibrary/yacreader_navigation_controller.h @@ -0,0 +1,53 @@ +#ifndef YACREADER_NAVIGATION_CONTROLLER_H +#define YACREADER_NAVIGATION_CONTROLLER_H + +#include +class LibraryWindow; +class YACReaderLibrarySourceContainer; + +class YACReaderNavigationController : public QObject +{ + Q_OBJECT +public: + + explicit YACReaderNavigationController(LibraryWindow * parent); + +signals: + +public slots: + //info origins + //folders view + void selectedFolder(const QModelIndex & mi); + void reselectCurrentFolder(); + //reading lists + void selectedList(const QModelIndex & mi); + void reselectCurrentList(); + + void reselectCurrentSource(); + + //history navigation + void selectedIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer); + void loadIndexFromHistory(const YACReaderLibrarySourceContainer &sourceContainer); + //empty subfolder + void selectSubfolder(const QModelIndex &sourceMI, int child); + + void loadEmptyFolderInfo(const QModelIndex & modelIndex); + + void loadFolderInfo(const QModelIndex & modelIndex); + void loadListInfo(const QModelIndex & modelIndex); + void loadSpecialListInfo(const QModelIndex & modelIndex); + void loadLabelInfo(const QModelIndex & modelIndex); + void loadReadingListInfo(const QModelIndex & modelIndex); + + void loadPreviousStatus(); + +private: + + void setupConnections(); + LibraryWindow * libraryWindow; + + //convenience methods + qulonglong folderModelIndexToID(const QModelIndex & mi); +}; + +#endif // YACREADER_NAVIGATION_CONTROLLER_H diff --git a/YACReaderLibrary/yacreader_reading_lists_view.cpp b/YACReaderLibrary/yacreader_reading_lists_view.cpp new file mode 100644 index 00000000..b95a567e --- /dev/null +++ b/YACReaderLibrary/yacreader_reading_lists_view.cpp @@ -0,0 +1,72 @@ +#include "yacreader_reading_lists_view.h" + +#include "reading_list_item.h" +#include "reading_list_model.h" + +YACReaderReadingListsView::YACReaderReadingListsView(QWidget *parent) + :YACReaderTreeView(parent) +{ + setItemDelegate(new YACReaderReadingListsViewItemDeletegate(this)); + setUniformRowHeights(false); + + //enabling internal drag&drop + setDragDropMode(QAbstractItemView::DragDrop); +} + +void YACReaderReadingListsView::dragEnterEvent(QDragEnterEvent *event) +{ + YACReaderTreeView::dragEnterEvent(event); + + /*QModelIndex destinationIndex = indexAt(event->pos()); + if(model()->canDropMimeData(event->mimeData(), event->proposedAction(), destinationIndex.row(), destinationIndex.column(), destinationIndex.parent()))*/ + event->acceptProposedAction(); +} + +void YACReaderReadingListsView::dragMoveEvent(QDragMoveEvent *event) +{ + YACReaderTreeView::dragMoveEvent(event); + QModelIndex destinationIndex = indexAt(event->pos()); + if(model()->canDropMimeData(event->mimeData(), event->proposedAction(), destinationIndex.row(), destinationIndex.column(), destinationIndex.parent())) + event->acceptProposedAction(); +} + +void YACReaderReadingListsView::dropEvent(QDropEvent *event) +{ + YACReaderTreeView::dropEvent(event); + + +} + +//---------------------------------------------------------------------- + +YACReaderReadingListsViewItemDeletegate::YACReaderReadingListsViewItemDeletegate(QObject *parent) + :QStyledItemDelegate(parent) +{ + +} + +void YACReaderReadingListsViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + ReadingListModel::TypeList typeList = (ReadingListModel::TypeList)index.data(ReadingListModel::TypeListsRole).toInt(); + + if(typeList == ReadingListModel::Separator) + { + return; + } + + QStyledItemDelegate::paint(painter, option, index); +} + +QSize YACReaderReadingListsViewItemDeletegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + ReadingListModel::TypeList typeList = (ReadingListModel::TypeList)index.data(ReadingListModel::TypeListsRole).toInt(); + + if(typeList == ReadingListModel::Separator) + { + QSize newSize = QStyledItemDelegate::sizeHint(option, index); + newSize.setHeight(7); + return newSize; + } + + return QStyledItemDelegate::sizeHint(option, index); +} diff --git a/YACReaderLibrary/yacreader_reading_lists_view.h b/YACReaderLibrary/yacreader_reading_lists_view.h new file mode 100644 index 00000000..31cb099b --- /dev/null +++ b/YACReaderLibrary/yacreader_reading_lists_view.h @@ -0,0 +1,32 @@ +#ifndef YACREADER_READING_LISTS_VIEW_H +#define YACREADER_READING_LISTS_VIEW_H + +#include "yacreader_treeview.h" + +#include + +class YACReaderReadingListsView : public YACReaderTreeView +{ + Q_OBJECT +public: + explicit YACReaderReadingListsView(QWidget * parent = 0); + +protected: + //Drop to import & internal Drag&Drop for resorting + void dragEnterEvent(QDragEnterEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); + +}; + +class YACReaderReadingListsViewItemDeletegate: public QStyledItemDelegate +{ + Q_OBJECT +public: + explicit YACReaderReadingListsViewItemDeletegate(QObject *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; +}; + + +#endif // YACREADER_READING_LISTS_VIEW_H diff --git a/YACReaderLibrary/yacreaderlibrary_de.ts b/YACReaderLibrary/yacreaderlibrary_de.ts new file mode 100644 index 00000000..60eb37a0 --- /dev/null +++ b/YACReaderLibrary/yacreaderlibrary_de.ts @@ -0,0 +1,1520 @@ + + + + + AddLibraryDialog + + + Comics folder : + Comics Ordner : + + + + Library Name : + Bibliothek Name : + + + + Add + Hinzufügen + + + + Cancel + Cancel + + + + Add an existing library + Eine existierende Bibliothek hinzufügen + + + + ComicVineDialog + + + skip + überspringen + + + + back + zurück + + + + next + nächste + + + + search + suche + + + + close + schliessen + + + + + + + + Looking for volume... + Suche nach Band.... + + + + + comic %1 of %2 - %3 + Comic %1 von %2 - %3 + + + + %1 comics selected + %1 Comic ausgewählt + + + + Error connecting to ComicVine + Fehler bei Verbindung zu ComicVine + + + + unknown error + unbekannter Fehler + + + + + Retrieving tags for : %1 + Runterladen von Tags für : %1 + + + + Retrieving volume info... + Runterladen von Ausgabe Info... + + + + Looking for comic... + Suche nach Comic... + + + + CreateLibraryDialog + + + Comics folder : + Comics Ordner : + + + + Library Name : + Bibliothek Name : + + + + Create + Neu erzeugen + + + + Cancel + Abbrechen + + + + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + Eine neue Bibliothek erzeugen kann einige Minuten dauern. Sie können den Prozess abbrechen und die Bibliothek später updaten um den Prozess zu vervollständigen. + + + + Create new library + Kreiere eine neue Bibliothek + + + + Path not found + Pfad nicht gefunden + + + + The selected path does not exist or is not a valid path. Be sure that you have write access to this folder + Der gewählte Pfad existiert nicht oder ist kein gültiger Pfad. Stellen Sie sicher, dass Sie Schreibzugriff zu dem Ordner haben + + + + ExportComicsInfoDialog + + + Output file : + Ziel File : + + + + Create + Neu erzeugen + + + + Cancel + Abbrechen + + + + Export comics info + Export Comic Info + + + + Destination database name + Ziel Datenbasis Name + + + + Problem found while writing + Problem gefunden beim Schreiben + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Der gewählte Pfad existiert nicht oder ist kein gültiger Pfad. Stellen Sie sicher, dass Sie Schreibzugriff zu dem Ordner haben + + + + ExportLibraryDialog + + + Output folder : + Ziel Ordner : + + + + Create + Erzeuge + + + + Cancel + Abbrechen + + + + Create covers package + Erzeuge Titelbild Paket + + + + Problem found while writing + Problem gefunden beim Schreiben + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Der gewählte Pfad existiert nicht oder ist kein gültiger Pfad. Stellen Sie sicher, dass Sie Schreibzugriff zu dem Ordner haben + + + + Destination directory + Ziel Verzeichnis + + + + FileComic + + + CRC error on page (%1): some of the pages will not be displayed correctly + CRC Fehler auf Seite (%1): einige Seiten werden nicht korrekt dargestellt werden + + + + Unknown error opening the file + Unbekannter Fehler beim Öffnen des Files + + + + 7z not found + 7z nicht gefunden + + + + Format not supported + Format wird nicht unterstützt + + + + HelpAboutDialog + + + About + Über + + + + Help + Hilfe + + + + ImportComicsInfoDialog + + + Import comics info + Importiere Comic Info + + + + Info database location : + Info Datenbasis Speicherort : + + + + Import + Importiere + + + + Cancel + Abbrechen + + + + Comics info file (*.ydb) + Comics Info File (*.ydb) + + + + ImportLibraryDialog + + + Library Name : + Bibliothek Name : + + + + Package location : + Paket Ort : + + + + Destination folder : + Zielordner : + + + + Unpack + Entpacken + + + + Cancel + Abbrechen + + + + Extract a catalog + Einen Katalog Extrahieren + + + + Compresed library covers (*.clc) + Komprimierte Bibliotheks Bilder (*.clc) + + + + ImportWidget + + + stop + Stop + + + + Some of the comics being added... + Einige der Comics werden hinzugefügt... + + + + Importing comics + Comics werden importiert + + + + <p>YACReaderLibrary is now creating a new library.</p><p>Create a library could take several minutes. You can stop the process and update the library later for completing the task.</p> + <p>YACReaderLibrary kreiert nun eine neue Bibliothek. </p><p>Eine neue Bibliothek erzeugen kann einige Minuten dauern. Sie können den Prozess stoppen und die Bibliothek später aktualisieren um den Prozess zu vervollständigen.</p> + + + + Updating the library + Aktualisierung der Bibliothek + + + + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later.</p> + <p>Die gerade benutzte Bibliothek wird aktualisiert. Für eine schnellere Aktualisierung aktualisieren Sie bitte die Bibliothek regelmäßig.</p><p>Sie können den Prozess abbrechen und mit der Aktualisierung später fortfahren.<p> + + + + LibraryWindow + + + YACReader Library + YACReader Bibliothek + + + + + Library + Bibliothek + + + + <font color='white'> press 'F' to close fullscreen mode </font> + <font color='white'> drücke 'F' um Vollbildmodus zu schließen </font> + + + + Create a new library + Neue Bibliothek erzeugen + + + + Open an existing library + Eine existierende Bibliothek öffnen + + + + + Export comics info + Export Comics Info + + + + + Import comics info + Import Comics Info + + + + Pack covers + Titelbild Paket erzeugen + + + + Pack the covers of the selected library + Packe die Titelbilder der ausgewählten Bibliothek in ein Paket + + + + Unpack covers + Titelbilder entpacken + + + + Unpack a catalog + Katalog entpacken + + + + Update library + Bibliothek updaten + + + + Update current library + Aktuelle Bibliothek updaten + + + + Rename library + Bibliothek umbenennen + + + + Rename current library + Aktuelle Bibliothek umbenennen + + + + Remove library + Bibliothek entfernen + + + + Remove current library from your collection + Aktuelle Bibliothek aus der Sammlung entfernen + + + + Open current comic + Aktuellen Comic öffnen + + + + Open current comic on YACReader + Aktuellen Comic mit YACReader öffnen + + + + + Set as read + Als gelesen markieren + + + + Set comic as read + Comic als gelesen markieren + + + + + Set as unread + Als ungelesen markieren + + + + Set comic as unread + Comic als ungelesen markieren + + + + Show/Hide marks + Zeige/Verstecke Markierungen + + + + Show or hide readed marks + Zeige oder verstecke gelesene Markierungen + + + + Library not available + Library ' + Bibliothek nicht verfügbar + + + + Fullscreen mode on/off + Vollbildmodus an/aus + + + + Fullscreen mode on/off (F) + Vollbildmodus an/aus (F) + + + + Help, About YACReader + Hilfe, Über YACReader + + + + Select root node + Root Knoten auswählen + + + + + + + + + + + Expand all nodes + Unterordner anzeigen + + + + - + + - + + + + Colapse all nodes + Unterordner verstecken + + + + Show options dialog + Zeige den Optionen Dialog + + + + Show comics server options dialog + Zeige den Comics Optionen Dialog + + + + Open folder... + Öffne Ordner... + + + + Set as uncompleted + Als nicht gelesen markieren + + + + Set as completed + Als gelesen markieren + + + + Open containing folder... + Öffne aktuellen Ordner... + + + + Reset comic rating + Comic Bewertung zurücksetzen + + + + Select all comics + Alle Comics auswählen + + + + Edit + Editieren + + + + Asign current order to comics + Bestimme die Abfolge der Comics + + + + Update cover + Titelbild updaten + + + + Delete selected comics + Ausgewählte Comics löschen + + + + Hide comic flow + Comic "Flow" verstecken + + + + Download tags from Comic Vine + Tags von Comic Vine herunterladen + + + + Folder + Ordner + + + + Comic + Comic + + + + Update needed + Update benötigt + + + + This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now? + Diese Bibliothek wurde mit einer vorherigen Version von YACReader erzeugt. Sie muss geupdated werden. Jetzt updaten? + + + + Update failed + Update fehlgeschlagen + + + + The current library can't be udpated. Check for write write permissions on: + Die aktuelle Bibliothek kann nicht geupdated werden. Überprüfen Sie die Schreibrechte auf: + + + + Download new version + Neue Version herunterladen + + + + This library was created with a newer version of YACReaderLibrary. Download the new version now? + Die Bibliothek wurde mit einer neueren Version von YACReader erzeugt. Die neue Version jetzt herunterladen? + + + + Library '%1' is no longer available. Do you want to remove it? + Bibliothek '%1' ist nicht länger verfügbar. Wollen Sie sie entfernen? + + + + Old library + Alte Bibliothek + + + + Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now? + Bibliothek '%1' ist mit einer älteren Version von YACREader erzeugt worden. Sie muss neu erzeugt werden. Wollen Sie die Bibliothek jetzt erzeugen? + + + + YACReader not found + YACReader nicht gefunden + + + + YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary. + YACReader nicht gefunden. YACReader sollte in demselben Ordner installiert werden wie YACReaderLibrary. + + + + Library not found + Bibliothek nicht gefunden + + + + The selected folder doesn't contain any library. + Der ausgewählte Ordner enthält keine Bibliothek. + + + + Are you sure? + Sind Sie sicher? + + + + Do you want remove + Möchten Sie entfernen + + + + library? + die Bibliothek? + + + + Remove and delete metadata + Entferne und lösche Metadaten + + + + Unable to delete + Löschen nicht möglich + + + + There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder. + Es gab ein Problem beim löschen der ausgewählten Comics. Überprüfen Sie bitte die Schreibberechtigung für die ausgewählten Files oder Ordner. + + + + Asign comics numbers + Comic Nummer setzen + + + + Asign numbers starting in: + Nummern setzen angefangen mit: + + + + Error creating the library + Fehler beim Erzeugen der Bibliothek + + + + Error updating the library + Fehler beim Updaten der Bibliothek + + + + Error opening the library + Fehler beim Öffnen der Bibliothek + + + + Delete comics + Comics löschen + + + + All the selected comics will be deleted from your disk. Are you sure? + Alle ausgewählten Comics werden von Ihrer Festplatte gelöscht. Sind Sie sicher? + + + + Library name already exists + Bibliothek Name existiert bereits + + + + There is another library with the name '%1'. + Es gibt eine andere Bibliothek mit dem Namen '%1'. + + + + LocalComicListModel + + + file name + File Name + + + + NoLibrariesWidget + + + You don't have any librarires yet + Sie haben im Augenblick keine Bibliothek + + + + <p>You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.</p><p>Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.</p> + <p>Sie können eine Bibliothek in einem bliebigen Ordner erzeugen, YACReaderLibrary wird alle Comics und Unterordner von diesem Ordner importieren. Wenn Sie in der Vergangenheit eine Bibliothek erzeugt haben, können Sie sie öffnen.</p><p>Vergessen Sie nicht, Sie können YACReader als unabhängige Anwendung benutzen, um Comics auf Ihrem Computer zu lesen.</p> + + + + create your first library + Erzeugen Sie Ihre erste Bibliothek + + + + add an existing one + Fügen Sie eine existierende hinzu + + + + OptionsDialog + + + Options + Optionen + + + + PropertiesDialog + + + General info + Generelle Info + + + + Authors + Autoren + + + + Publishing + Publishing + + + + Plot + Inhalt + + + + Cover page + Titelbild + + + + Title: + Titel: + + + + Issue number: + Ausgabe Nummer: + + + + Volume: + Band: + + + + Story arc: + Handlung: + + + + Genere: + Genre: + + + + Size: + Größe: + + + + Writer(s): + Author(en): + + + + Penciller(s): + Zeichner: + + + + Inker(s): + Tinte: + + + + Colorist(s): + Farbe: + + + + Letterer(s): + Schrift: + + + + Cover Artist(s): + Titelbild Künstler: + + + + Day: + Tag: + + + + Month: + Monat: + + + + Year: + + + + + Publisher: + Verlag: + + + + Format: + Format: + + + + Color/BW: + Farbe/BW: + + + + Age rating: + Alterhinweis: + + + + Synopsis: + Übersicht: + + + + Characters: + Charaktere: + + + + Notes: + Notizen: + + + + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> view </a> + + + + + Not found + Nicht gefunden + + + + Comic not found. You should update your library. + Comic nicht gefunden. Sie sollten Ihre Bibliothek updaten. + + + + Edit selected comics information + Ausgewählte Comic Informationen editieren + + + + Edit comic information + Comic Informationen editieren + + + + QObject + + + 7z lib not found + 7z Bibliothek nicht gefunden + + + + unable to load 7z lib from ./utils + 7z Bibliothek kann von ./utils nicht geladen werden + + + + RenameLibraryDialog + + + New Library Name : + Neuer Bibliotheks Name : + + + + Rename + Namen ändern + + + + Cancel + Abbrechen + + + + Rename current library + Namen der Bibliothek ändern + + + + ScraperResultsPaginator + + + Number of volumes found : %1 + Anzahl der gefundenen Bände: %1 + + + + + page %1 of %2 + Seite %1 von %2 + + + + Number of %1 found : %2 + Anzahl von %1 gefunden : %2 + + + + SearchSingleComic + + + Please provide some aditional information. + Bitte einige zusätzliche Informationen. + + + + Series: + Serie: + + + + SearchVolume + + + Please provide some aditional information. + Serie: + Bitte einige zusätzliche Informationen. + + + + Series: + Serie: + + + + SelectComic + + + Please, select the right comic info. + Bitte wählen Sie die richtige Comic Information. + + + + comics + Comics + + + + loading cover + Cover laden + + + + loading description + Beschreibung laden + + + + description unavailable + Beschreibung nicht verfügbar + + + + SelectVolume + + + Please, select the right series for your comic. + Bitte wählen Sie die richtige Serie für Ihre Comics. + + + + volumes + Bände + + + + loading cover + Titelbilder werden geladen + + + + loading description + Beschreibung lädt + + + + description unavailable + Beschreibung nicht verfügbar + + + + SeriesQuestion + + + You are trying to get information for various comics at once, are they part of the same series? + Sie versuchen Informationen zu mehreren Comics auf einmal zu laden, sind sie Teil einer Serie? + + + + yes + Ja + + + + no + Nein + + + + ServerConfigDialog + + + set port + Port setzen + + + + EASY SERVER CONNECTION + Einfache Server Verbindung + + + + SERVER ADDRESS + SERVER Adresse + + + + just scan the code with your device!! + Einfach den Code scannen!! + + + + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Discover it! </a> + YACReader ist nun verfügbar für IOS Geräte, die beste Comic Lese Erfahrung für Ihr IPAD, IPhone oder IPod Touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'>Discover it! </a> + + + + IP address + IP Adresse + + + + Port + Port + + + + enable the server + Server aktivieren + + + + QR generator error! + QR Generator Fehler! + + + + SortVolumeComics + + + Please, sort the list of comics on the left until it matches the comics' information. + Sortieren Sie bitte die Comic Informationen links, bis die Informationen für die Comics übereinstimmen. + + + + sort comics to match comic information + Sortieren Sie die Comics um die Informationen zur Übereinstimmung zu bringen + + + + issues + Ausgaben + + + + remove selected comics + Löschen der ausgewählten Comics + + + + restore all removed comics + Wiederherstellung der gelöschten Comics + Wiederherstellen aller gelöschten Comics + + + + restore removed comics + + + + + TableModel + + + yes + Ja + + + + no + Nein + + + + Title + Titel + + + + File Name + File Name + + + + Pages + Seiten + + + + Size + Größe + + + + Read + Lesen + + + + Current Page + Aktuelle Seite + + + + Rating + Bewertung + + + + TitleHeader + + + SEARCH + Suche + + + + UpdateLibraryDialog + + + Updating.... + Aktualisierung... + + + + Cancel + Abbrechen + + + + Update library + Aktualisierung der Bibliothek + + + + VolumeComicsModel + + + title + Titel + + + + VolumesModel + + + year + Jahr + + + + issues + Bände + + + + publisher + Herausgeber + + + + YACReaderDeletingProgress + + + Please wait, deleting in progress... + Bitte warten, Löschvorgang läuft... + + + + cancel + Abbrechen + + + + YACReaderFieldEdit + + + + Click to overwrite + Drücken zum Überschreiben + + + + Restore to default + Ursprungseinstellungen wiederherstellen + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Drücken zum Überschreiben + + + + Restore to default + Ursprungseinstellungen wiederherstellen + + + + YACReaderFlowConfigWidget + + + How to show covers: + Wie zeige ich Titelseiten an: + + + + CoverFlow look + CoverFlow Ansicht + + + + Stripe look + Streifen Ansicht + + + + Overlapped Stripe look + Überlappende Streifen Ansicht + + + + YACReaderGLFlowConfigWidget + + + Presets: + Voreinstellungen: + + + + Classic look + Klassische Darstellung + + + + Stripe look + + + + + Overlapped Stripe look + Überlappende Streifen Darstellung + + + + Modern look + Moderne Drstellung + + + + Roulette look + Zufällige Darstellung + + + + Show advanced settings + Zeige Fortgeschrittenen Einstellungen + + + + Custom: + Benutzerdefiniert: + + + + View angle + Zeige Winkel + + + + Position + Position + + + + Cover gap + Titelbild Abstand + + + + Central gap + Zentral Abstand + + + + Zoom + Vergößern + + + + Y offset + Y Abstand + + + + Z offset + Z Abstand + + + + Cover Angle + Titelbild Winkel + + + + Visibility + Sichtbarkeit + + + + Light + Helligkeit + + + + Max angle + Max Winkel + + + + Low Performance + Niedrige Leistung + + + + High Performance + Hohe Leistung + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + Benutze VSync (verbessert die Darstellung im Vollbild Modus, schlechtere Leistung) + + + + Performance: + Leistung: + + + + YACReaderOptionsDialog + + + Save + Speichern + + + + Cancel + Cancel + + + + Use hardware acceleration (restart needed) + Hardwarebeschleunigung benutzen (Neustart erforderlich) + + + + YACReaderSideBar + + + LIBRARIES + Bibliotheken + + + + FOLDERS + ORDNER + + + + Search folders and comics + Ordner und Comics durchsuchen + + + diff --git a/YACReaderLibrary/yacreaderlibrary_es.qm b/YACReaderLibrary/yacreaderlibrary_es.qm new file mode 100644 index 00000000..370934a5 Binary files /dev/null and b/YACReaderLibrary/yacreaderlibrary_es.qm differ diff --git a/YACReaderLibrary/yacreaderlibrary_es.ts b/YACReaderLibrary/yacreaderlibrary_es.ts new file mode 100644 index 00000000..1d994ae9 --- /dev/null +++ b/YACReaderLibrary/yacreaderlibrary_es.ts @@ -0,0 +1,1521 @@ + + + + + AddLibraryDialog + + + Comics folder : + Carpeta de cómics: + + + + Library Name : + Nombre de la biblioteca: + + + + Add + Añadir + + + + Cancel + Cancelar + + + + Add an existing library + Añadir una biblioteca existente + + + + ComicVineDialog + + + skip + omitir + + + + back + atrás + + + + next + siguiente + + + + search + buscar + + + + close + cerrar + + + + + + + + Looking for volume... + Buscando volumen... + + + + + comic %1 of %2 - %3 + cómic %1 de %2 - %3 + + + + %1 comics selected + %1 comics seleccionados + + + + Error connecting to ComicVine + Error conectando a ComicVine + + + + unknown error + error desconocido + + + + + Retrieving tags for : %1 + Recuperando etiquetas para : %1 + + + + Retrieving volume info... + Recuperando imformación del volumen... + + + + Looking for comic... + Buscando cómic... + + + + CreateLibraryDialog + + + Comics folder : + Carpeta de cómics: + + + + Library Name : + Nombre de la biblioteca: + + + + Create + Crear + + + + Cancel + Cancelar + + + + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + Crear una biblioteca puede llevar varios minutos. Puedes parar el proceso en cualquier momento y completar la tarea más tarde. + + + + Create new library + Crear la nueva biblioteca + + + + Path not found + Ruta no encontrada + + + + The selected path does not exist or is not a valid path. Be sure that you have write access to this folder + La ruta seleccionada no existe o no es válida. Asegúrate de que tienes privilegios de escritura en esta carpeta + + + + ExportComicsInfoDialog + + + Output file : + Archivo de salida : + + + + Create + Crear + + + + Cancel + Cancelar + + + + Export comics info + Exportar información de los cómics + + + + Destination database name + Nombre de la base de datos de destino + + + + Problem found while writing + Problema encontrado mientras se escribía + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + La ruta seleccionada para el archivo de salida no existe o no es una ruta válida. Asegúrate de que tienes permisos de escritura en esta carpeta + + + + ExportLibraryDialog + + + Output folder : + Carpeta de destino: + + + + Create + Crear + + + + Cancel + Cancelar + + + + Create covers package + Crear paquete de portadas + + + + Problem found while writing + Problema encontrado mientras se escribía + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + La ruta seleccionada para el archivo de salida no existe o no es una ruta válida. Asegúrate de que tienes permisos de escritura en esta carpeta + + + + Destination directory + Carpeta de destino + + + + FileComic + + + Unknown error opening the file + Error desconocido abriendo el archivo + + + + 7z not found + 7z no encontrado + + + + Format not supported + Formato no soportado + + + + CRC error on page (%1): some of the pages will not be displayed correctly + Error CRC en la página (%1): algunas de las páginas no se mostrarán correctamente + + + + HelpAboutDialog + + + About + Acerca de + + + + Help + Ayuda + + + + ImportComicsInfoDialog + + + Import comics info + Importar información de cómics + + + + Info database location : + Ubicación de la base de datos de información : + + + + Import + Importar + + + + Cancel + Cancelar + + + + Comics info file (*.ydb) + Archivo de información de cómics (*.ydb) + + + + ImportLibraryDialog + + + Library Name : + Nombre de la biblioteca : + + + + Package location : + Ubicación del paquete: + + + + Destination folder : + Directorio de destino: + + + + Unpack + Desempaquetar + + + + Cancel + Cancelar + + + + Extract a catalog + Extraer un catálogo + + + + Compresed library covers (*.clc) + Compresed library covers (*.clc) + + + + ImportWidget + + + Importing comics + Importando cómics + + + + stop + parar + + + + Some of the comics being added... + Algunos de los cómics que estan siendo añadidos.... + + + + <p>YACReaderLibrary is now creating a new library.</p><p>Create a library could take several minutes. You can stop the process and update the library later for completing the task.</p> + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + <p>YACReaderLibrary está creando una nueva biblioteca.</p><p>Crear una biblioteca puede llevar varios minutos. Puedes parar el proceso en cualquier momento y actualizar la biblioteca más tarde para completar el proceso.</p> + + + + Updating the library + Actualizando la biblioteca + + + + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later.</p> + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later. + <p>La biblioteca actual está siendo actualizada. Para actualizaciones más rápidas, por favor, actualiza tus bibliotecas frecuentemente.</p><p>Puedes parar el proceso y continunar la actualización más tarde.</p> + + + + LibraryWindow + + + <font color='white'> press 'F' to close fullscreen mode </font> + <font color='white'> presiona 'F' para salir de pantalla completa </font> + + + + YACReader Library + YACReader Library + + + + Create a new library + Crear una nueva biblioteca + + + + Open an existing library + Abrir una biblioteca existente + + + + + Export comics info + Exportar información de los cómics + + + + + Import comics info + Importar información de cómics + + + + Pack covers + Empaquetar portadas + + + + Pack the covers of the selected library + Empaquetar las portadas de la biblioteca seleccionada + + + + Unpack covers + Desempaquetar portadas + + + + Unpack a catalog + Desempaquetar un catálogo + + + + Update library + Actualizar biblioteca + + + + Update current library + Actualizar la biblioteca seleccionada + + + + Rename library + Renombrar biblioteca + + + + Rename current library + Renombrar la biblioteca seleccionada + + + + Remove current library from your collection + Eliminar biblioteca de la colección + + + + Open current comic + Abrir cómic actual + + + + Open current comic on YACReader + Abrir el cómic actual en YACReader + + + + + Set as read + Marcar como leído + + + + Set comic as read + Marcar cómic como leído + + + + + Set as unread + Marcar como no leído + + + + Set comic as unread + Marcar cómic como no leído + + + + Show/Hide marks + Mostrar/Ocultar marcas + + + + Show or hide readed marks + Mostrar u ocultar marcas + + + + Fullscreen mode on/off + Modo a pantalla completa on/off + + + + Fullscreen mode on/off (F) + Activar/desactivar modo a pantalla completa (F) + + + + Help, About YACReader + Ayuda, A cerca de... YACReader + + + + Select root node + Seleccionar el nodo raíz + + + + + + + + + + + Expand all nodes + Expandir todos los nodos + + + + - + - + + + + Colapse all nodes + Contraer todos los nodos + + + + Show options dialog + Mostrar opciones + + + + Show comics server options dialog + + + + + Open folder... + Abrir carpeta... + + + + Set as uncompleted + Marcar como incompleto + + + + Set as completed + Marcar como completo + + + + Open containing folder... + Abrir carpeta contenedora... + + + + Reset comic rating + Reseteal cómic rating + + + + Select all comics + Seleccionar todos los cómics + + + + Edit + Editar + + + + Asign current order to comics + Asignar el orden actual a los cómics + + + + Update cover + Actualizar portada + + + + Delete selected comics + Borrar los cómics seleccionados + + + + Hide comic flow + Ocultar cómic flow + + + + Download tags from Comic Vine + Descargar etiquetas de Comic Vine + + + + Folder + Carpeta + + + + Comic + Cómic + + + + Library not available + Library ' + Biblioteca no disponible + + + + Library '%1' is no longer available. Do you want to remove it? + La biblioteca '%1' no está disponible. ¿Deseas eliminarla? + + + + Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now? + La biblioteca '%1' ha sido creada con una versión más antigua de YACReaderLibrary y debe ser creada de nuevo. ¿Deseas crear la biblioteca ahora? + + + + Old library + Biblioteca antigua + + + + YACReader not found + YACReader no encontrado + + + + YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary. + YACReader no encontrado, YACReader debe estar instalado en el mismo directorio que YACReaderLibrary. + + + + Unable to delete + No se ha podido borrar + + + + There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder. + Ha habido algún problema intentando borrar los cómics selecionados. Por favor, verifica los permisos de escritura en los arhicovs seleccionados o los directorios que los conienen. + + + + Error creating the library + Errar creando la biblioteca + + + + Error updating the library + Error actualizando la biblioteca + + + + Error opening the library + Error abriendo la biblioteca + + + + Delete comics + Borrar cómics + + + + All the selected comics will be deleted from your disk. Are you sure? + Todos los cómics seleccionados serán borrados de tu disco. ¿Estás seguro? + + + + Library name already exists + Ya existe el nombre de la biblioteca + + + + There is another library with the name '%1'. + Hay otra biblioteca con el nombre '%1'. + + + + + Library + Librería + + + + Remove library + Eliminar biblioteca + + + + Update needed + Se necesita actualizar + + + + This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now? + Esta biblioteca fue creada con una versión anterior de YACReaderLibrary. Es necesario que se actualice. ¿Deseas hacerlo ahora? + + + + Update failed + La actualización ha fallado + + + + The current library can't be udpated. Check for write write permissions on: + La librería actual no ha podido ser actualizada. Verifica que posees permisos de escritura en: + + + + Download new version + Descargar la nueva versión + + + + This library was created with a newer version of YACReaderLibrary. Download the new version now? + Esta biblioteca fue creada con una versión más nueva de YACReaderLibrary. ¿Deseas descargar la nueva versión ahora? + + + + Library not found + Biblioteca no encontrada + + + + The selected folder doesn't contain any library. + La carpeta seleccionada no contiene ninguna biblioteca. + + + + Are you sure? + ¿Estás seguro? + + + + library? + ? + + + + Remove and delete metadata + Eliminar y borrar metadatos + + + + Do you want remove + ¿Deseas eliminar la biblioteca + + + + Asign comics numbers + Asignar números de cómic + + + + Asign numbers starting in: + Asignar números empezando en: + + + + LocalComicListModel + + + file name + nombre de archivo + + + + NoLibrariesWidget + + + You don't have any librarires yet + Aún no tienes ninguna biblioteca + + + + <p>You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.</p><p>Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.</p> + <p>Puedes crear una biblioteca en cualquier carpeta, YACReaderLibrary importará todos las carpetas y cómics de esa carpeta. Si has creado alguna biblioteca anteriormente, puedes abrirla sin volver a crearla.</p><p>No olvides que puedes usar YACReader como una aplicación independiente para leer los cómics en tu ordenador.</p> + + + + create your first library + crea tu primera biblioteca + + + + add an existing one + añade una existente + + + + OptionsDialog + + + Options + Opciones + + + + PropertiesDialog + + + General info + Información general + + + + Authors + Autores + + + + Publishing + Publicación + + + + Plot + Argumento + + + + Cover page + Página de portada + + + + Title: + Título: + + + + Issue number: + Número: + + + + Volume: + Volumen: + + + + Story arc: + Arco argumental: + + + + Genere: + Género: + + + + Size: + Tamaño: + + + + Writer(s): + Guionista(s): + + + + Penciller(s): + Dibujant(es): + + + + Inker(s): + Entintador(es): + + + + Colorist(s): + Color: + + + + Letterer(s): + Letterer(es): + Rotulista(s): + + + + Cover Artist(s): + Artista(s) portada: + + + + Day: + Día: + + + + Month: + Mes: + + + + Year: + Año: + + + + Publisher: + Editorial: + + + + Format: + Formato: + + + + Color/BW: + Color/BN: + + + + Age rating: + Casificación edades: + + + + Synopsis: + Sinopsis: + + + + Characters: + Personajes: + + + + Notes: + Notas: + + + + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> view </a> + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> ver </a> + + + + Not found + No encontrado + + + + Comic not found. You should update your library. + Cómic no encontrado. Deberias actualizar tu biblioteca. + + + + Edit selected comics information + Editar la información de los cómics seleccionados + + + + Edit comic information + Editar la información del cócmic + + + + QObject + + + 7z lib not found + 7z lib no encontrado + + + + unable to load 7z lib from ./utils + imposible cargar 7z lib de ./utils + + + + RenameLibraryDialog + + + New Library Name : + Nuevo nombre de la biblioteca : + + + + Rename + Renombrar + + + + Cancel + Cancelar + + + + Rename current library + Renombrar la biblioteca seleccionada + + + + ScraperResultsPaginator + + + Number of volumes found : %1 + Número de volúmenes encontrados : %1 + + + + + page %1 of %2 + página %1 de %2 + + + + Number of %1 found : %2 + Número de %1 encontrados : %2 + + + + SearchSingleComic + + + Please provide some additional information. + Por favor, proporciona alguna información adicional. + + + + Series: + Series: + + + + SearchVolume + + + Please provide some additional information. + Por favor, proporciona alguna informacion adicional. + + + + Series: + Series: + + + + SelectComic + + + Please, select the right comic info. + Por favor, selecciona la información correcta. + + + + comics + cómics + + + + loading cover + cargando portada + + + + loading description + cargando descripción + + + + description unavailable + descripción no disponible + + + + SelectVolume + + + Please, select the right series for your comic. + Por favor, seleciona la serie correcta para tu cómic. + + + + volumes + volúmenes + + + + loading cover + cargando portada + + + + loading description + cargando descripción + + + + description unavailable + descripción no disponible + + + + SeriesQuestion + + + You are trying to get information for various comics at once, are they part of the same series? + Estás intentando obtener información de varios cómics a la vez, ¿son parte de la misma serie? + + + + yes + sí + + + + no + no + + + + ServerConfigDialog + + + set port + fijar puerto + + + + EASY SERVER CONNECTION + CONEXIÓN AL SERVIDOR FÃCILMENTE + + + + SERVER ADDRESS + DATOS SERVIDOR + + + + just scan the code with your device!! + ¡simplemente escanea el código con tu dispositivo! + + + + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Discover it! </a> + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com'> Discover it! </a> + YACReader está ahora disponible para dispositivos iOS, la mejor experiencia de lectura de cómics ahora en tu iPad, iPhone o iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> ¡Descúbrelo! </a> + + + + IP address + IP usada + + + + Port + Puerto + + + + enable the server + activar el servidor + + + + QR generator error! + ¡Error del generador QR! + + + + SortVolumeComics + + + Please, sort the list of comics on the left until it matches the comics' information. + Por favor, ordena la lista de cómics en la izquiera hasta que coincida con la información adecuada. + + + + sort comics to match comic information + ordena los cómics para coincidir con la información + + + + issues + números + + + + remove selected comics + eliminar cómics seleccionados + + + + restore all removed comics + restaurar todos los cómics eliminados + + + + restore removed comics + restaurar cómics eliminados + + + + TableModel + + + yes + sí + + + + no + no + + + + Title + Título + + + + File Name + Nombre de archivo + + + + Pages + Páginas + + + + Size + Tamaño + + + + Read + Leído + + + + Current Page + Página Actual + + + + Rating + Nota + + + + TitleHeader + + + SEARCH + BUSCAR + + + + UpdateLibraryDialog + + + Updating.... + Actualizado... + + + + Cancel + Cancelar + + + + Update library + Actualizar biblioteca + + + + VolumeComicsModel + + + title + título + + + + VolumesModel + + + year + año + + + + issues + números + + + + publisher + editor + + + + YACReaderDeletingProgress + + + Please wait, deleting in progress... + Borrando, por favor espera... + + + + cancel + cancelar + + + + YACReaderFieldEdit + + + + Click to overwrite + Click para sobreescribir + + + + Restore to default + Restaurar valor por defecto + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Click para sobreescribir + + + + Restore to default + Restaurar valor por defecto + + + + YACReaderFlowConfigWidget + + + How to show covers: + Cómo mostrar las portadas: + + + + CoverFlow look + Tipo CoverFlow + + + + Stripe look + Tipo tira + + + + Overlapped Stripe look + Tipo tira solapada + + + + YACReaderGLFlowConfigWidget + + + Presets: + Predeterminados: + + + + Classic look + Tipo clásico + + + + Stripe look + Tipo tira + + + + Overlapped Stripe look + Tipo tira solapada + + + + Modern look + Tipo moderno + + + + Roulette look + Tipo ruleta + + + + Show advanced settings + Opciones avanzadas + + + + Custom: + Personalizado: + + + + View angle + Ãngulo de vista + + + + Position + Posición + + + + Cover gap + Hueco entre portadas + + + + Central gap + Hueco central + + + + Zoom + Zoom + + + + Y offset + Desplazamiento en Y + + + + Z offset + Desplazamiento en Z + + + + Cover Angle + Ãngulo de las portadas + + + + Visibility + Visibilidad + + + + Light + Luz + + + + Max angle + Ãngulo máximo + + + + Low Performance + Rendimiento bajo + + + + High Performance + Alto rendimiento + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + Usar VSync (mejora la calidad de imagen en pantalla completa, peor rendimiento) + + + + Performance: + Rendimiento: + + + + YACReaderOptionsDialog + + + Save + Guardar + + + + Cancel + Cancelar + + + + Use hardware acceleration (restart needed) + Usar aceleración por hardware (necesario reiniciar) + + + + YACReaderSideBar + + + LIBRARIES + BIBLIOTECAS + + + + FOLDERS + CARPETAS + + + + Search folders and comics + Buscar carpetas y cómics + + + diff --git a/YACReaderLibrary/yacreaderlibrary_fr.ts b/YACReaderLibrary/yacreaderlibrary_fr.ts new file mode 100644 index 00000000..60a00ec2 --- /dev/null +++ b/YACReaderLibrary/yacreaderlibrary_fr.ts @@ -0,0 +1,1517 @@ + + + + + AddLibraryDialog + + + Comics folder : + Dossier des comics : + + + + Library Name : + Nom de la librairie : + + + + Add + Ajouter + + + + Cancel + Annuler + + + + Add an existing library + Ajouter une librairie existante + + + + ComicVineDialog + + + skip + + + + + back + + + + + next + + + + + search + + + + + close + + + + + + + + + Looking for volume... + + + + + + comic %1 of %2 - %3 + + + + + %1 comics selected + + + + + Error connecting to ComicVine + + + + + unknown error + + + + + + Retrieving tags for : %1 + + + + + Retrieving volume info... + + + + + Looking for comic... + + + + + CreateLibraryDialog + + + Comics folder : + Dossier des comics : + + + + Library Name : + Nom de la librairie : + + + + Create + Créer + + + + Cancel + Annuler + + + + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + La création d'une librairie peut prendre quelques minutes. Vous pouvez arrêter le processus et continuer plus tard. + + + + Create new library + Créer une nouvelle librairie + + + + Path not found + Chemin introuvable + + + + The selected path does not exist or is not a valid path. Be sure that you have write access to this folder + Le chemin sélectionné n'existe pas ou contient un chemin invalide. Assurez-vous d'avoir les droits d'accès à ce dossier + + + + ExportComicsInfoDialog + + + Output file : + Fichier de sortie : + + + + Create + Créer + + + + Cancel + Annuler + + + + Export comics info + Exporter les infos des comics + + + + Destination database name + Nom de la base de données de destination + + + + Problem found while writing + Problème durant l'écriture + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Le chemin sélectionné pour le fichier n'existe pas ou contient un chemin invalide. Assurez-vous d'avoir les droits d'accès à ce dossier + + + + ExportLibraryDialog + + + Output folder : + Dossier de sortie : + + + + Create + Créer + + + + Cancel + Annuler + + + + Create covers package + Créer un pack de couvertures + + + + Problem found while writing + Problème durant l'écriture + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Le chemin sélectionné pour le fichier n'existe pas ou contient un chemin invalide. Assurez-vous d'avoir les droits d'accès à ce dossier + + + + Destination directory + Répertoire de destination + + + + FileComic + + + Unknown error opening the file + + + + + 7z not found + 7z introuvable + + + + Format not supported + + + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + HelpAboutDialog + + + About + A propos + + + + Help + Aide + + + + ImportComicsInfoDialog + + + Import comics info + Importer les infos des comics + + + + Info database location : + Emplacement des infos: + + + + Import + Importer + + + + Cancel + Annuler + + + + Comics info file (*.ydb) + Comics info file (*.ydb) + + + + ImportLibraryDialog + + + Library Name : + Nom de la librairie : + + + + Package location : + Emplacement : + + + + Destination folder : + Dossier de destination : + + + + Unpack + Désarchiver + + + + Cancel + Annuler + + + + Extract a catalog + Extraire un catalogue + + + + Compresed library covers (*.clc) + Compresed library covers (*.clc) + + + + ImportWidget + + + stop + Stop + + + + Some of the comics being added... + Ajout de comics... + + + + Importing comics + Importation de comics + + + + <p>YACReaderLibrary is now creating a new library.</p><p>Create a library could take several minutes. You can stop the process and update the library later for completing the task.</p> + <p>YACReaderLibrary est en train de créer une nouvelle librairie.</p><p>La création d'une librairie peut prendre quelques minutes. Vous pouvez arrêter le processus et poursuivre plus tard.</p> + + + + Updating the library + Mise à jour de la librairie + + + + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later.</p> + <p>Mise à jour de la librairie. Pour plus de rapidité lors de la mise à jour, veuillez effectuer cette dernière régulièrement.</p><p>Vous pouvez arrêter le processus et poursuivre plus tard.</p> + + + + LibraryWindow + + + YACReader Library + Librairie de YACReader + + + + + Library + Librairie + + + + <font color='white'> press 'F' to close fullscreen mode </font> + <font color='white'> appuyez sur 'F' pour quitter le mode plein écran </font> + + + + Create a new library + Créer une nouvelle librairie + + + + Open an existing library + Ouvrir une librairie existante + + + + + Export comics info + Exporter les infos des comics + + + + + Import comics info + Importer les infos des comics + + + + Pack covers + Archiver les couvertures + + + + Pack the covers of the selected library + Archiver les couvertures de la librairie sélectionnée + + + + Unpack covers + Désarchiver les couvertures + + + + Unpack a catalog + Désarchiver un catalogue + + + + Update library + Mettre la librairie à jour + + + + Update current library + Mettre à jour la librairie actuelle + + + + Rename library + Renommer la librairie + + + + Rename current library + Renommer la librairie actuelle + + + + Remove library + Supprimer la librairie + + + + Remove current library from your collection + Enlever cette librairie de votre collection + + + + Open current comic + Ouvrir ce comic + + + + Open current comic on YACReader + Ouvrir ce comic dans YACReader + + + + + Set as read + Marquer comme lu + + + + Set comic as read + Marquer ce comic comme lu + + + + + Set as unread + Marquer comme non-lu + + + + Set comic as unread + Marquer ce comic comme non-lu + + + + Show/Hide marks + Afficher/Cacher les marqueurs + + + + Show or hide readed marks + Afficher ou cacher les marqueurs pour les livres lus + + + + Library not available + Library ' + Librairie non disponible + + + + Fullscreen mode on/off + Mode plein écran activé/désactivé + + + + Fullscreen mode on/off (F) + Mode plein écran activé/désactivé (F) + + + + Help, About YACReader + Aide, à propos de YACReader + + + + Select root node + Allerà la racine + + + + + + + + + + + Expand all nodes + Afficher tous les noeuds + + + + - + - + + + + Colapse all nodes + Masquer tous les noeuds + + + + Show options dialog + Ouvrir la boite de dialogue + + + + Show comics server options dialog + Ouvrir la boite de dialogue du serveur + + + + Open folder... + Ouvrir le dossier... + + + + Set as uncompleted + + + + + Set as completed + + + + + Open containing folder... + Ouvrir le dossier... + + + + Reset comic rating + + + + + Select all comics + Sélectionner tous les comics + + + + Edit + Editer + + + + Asign current order to comics + Assigner l'ordre actuel à vos comics + + + + Update cover + Mise à jour des couvertures + + + + Delete selected comics + Supprimer le comics sélectionné + + + + Hide comic flow + Cacher le comic flow + + + + Download tags from Comic Vine + + + + + Folder + + + + + Comic + + + + + Update needed + Mise à jour requise + + + + This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now? + Cette librairie a été créée avec une ancienne version de YACReaderLibrary. Mise à jour necessaire. Mettre à jour? + + + + Update failed + Echec de la mise à jour + + + + The current library can't be udpated. Check for write write permissions on: + Cette librairie ne peut pas être mise à jour. Vérifiez les droits d'accès: + + + + Download new version + Téléchrger la nouvelle version + + + + This library was created with a newer version of YACReaderLibrary. Download the new version now? + Cette librairie a été créée avec une version plus récente de YACReaderLibrary. Télécharger la nouvelle version? + + + + Library '%1' is no longer available. Do you want to remove it? + La librarie '%1' n'est plus disponible. Voulez-vous la supprimer? + + + + Old library + Ancienne librairie + + + + Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now? + La librarie '%1' a été créée avec une ancienne version de YACReaderLibrary. Elle doit être re-créée. Voulez-vous créer la librairie? + + + + YACReader not found + + + + + YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary. + + + + + Library not found + Librairie introuvable + + + + The selected folder doesn't contain any library. + Le dossier sélectionné ne contient aucune librairie. + + + + Are you sure? + Êtes-vous sûr? + + + + Do you want remove + Voulez-vous supprimer + + + + library? + la librairie? + + + + Remove and delete metadata + Supprimer les métadata + + + + Unable to delete + + + + + There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder. + + + + + Asign comics numbers + Assigner les numéros aux comics + + + + Asign numbers starting in: + Assigner les numéros: + + + + Error creating the library + Erreur lors de la création de la librairie + + + + Error updating the library + Erreur lors de la mise à jour de la librairie + + + + Error opening the library + Erreur lors de l'ouverture de la librairie + + + + Delete comics + Supprimer les comics + + + + All the selected comics will be deleted from your disk. Are you sure? + Tous les comics sélectionnés vont être supprimés de votre disque. Êtes-vous sûr? + + + + Library name already exists + Le nom de la librairie existe déjà + + + + There is another library with the name '%1'. + Une autre librairie a le nom '%1'. + + + + LocalComicListModel + + + file name + + + + + NoLibrariesWidget + + + You don't have any librarires yet + Vous n'avez pas encore de librairie + + + + <p>You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.</p><p>Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.</p> + <p>Vous pouvez creer une librairie dans n'importe quel dossierr, YACReaderLibrary importera les dossiers et les livres contenus dans ce dossier. Si vous avez déjà crer des librairies, vous pouvez les ouvrir.</p><p>N'oubliez pas que vous pouvez utiliser YACReader en tant que stand alone pour lire vos livres sur votre ordinateur.</p> + + + + create your first library + Créez votre première librairie + + + + add an existing one + Ajouter une librairie existante + + + + OptionsDialog + + + Options + Options + + + + PropertiesDialog + + + General info + Infos générales + + + + Authors + Auteurs + + + + Publishing + Publication + + + + Plot + Intrigue + + + + Cover page + Couverture + + + + Title: + Titre: + + + + Issue number: + Numéro: + + + + Volume: + Volume: + + + + Story arc: + Arc narratif: + + + + Genere: + Genre: + + + + Size: + Taille: + + + + Writer(s): + Scénariste(s): + + + + Penciller(s): + Dessinateur(s): + + + + Inker(s): + Encreur(s): + + + + Colorist(s): + Coloriste(s): + + + + Letterer(s): + Lettreur(s): + + + + Cover Artist(s): + Artiste(s) de couverture: + + + + Day: + Jour: + + + + Month: + Mois: + + + + Year: + Année: + + + + Publisher: + Editeur: + + + + Format: + Format: + + + + Color/BW: + Couleur/Noir et blanc: + + + + Age rating: + Limite d'âge: + + + + Synopsis: + Synopsis: + + + + Characters: + Personnages: + + + + Notes: + Notes: + + + + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> view </a> + + + + + Not found + Introuvable + + + + Comic not found. You should update your library. + Comic introuvable. Vous devriez mettre à jour votre librairie. + + + + Edit selected comics information + Editer les informations du comic sélectionné + + + + Edit comic information + Editer les informations du comic + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + RenameLibraryDialog + + + New Library Name : + Nouveau nom de librairie: + + + + Rename + Renommer + + + + Cancel + Annuler + + + + Rename current library + Renommer la librairie actuelle + + + + ScraperResultsPaginator + + + Number of volumes found : %1 + + + + + + page %1 of %2 + + + + + Number of %1 found : %2 + + + + + SearchSingleComic + + + Please provide some additional information. + + + + + Series: + + + + + SearchVolume + + + Please provide some additional information. + + + + + Series: + + + + + SelectComic + + + Please, select the right comic info. + + + + + comics + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SelectVolume + + + Please, select the right series for your comic. + + + + + volumes + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SeriesQuestion + + + You are trying to get information for various comics at once, are they part of the same series? + + + + + yes + oui + + + + no + non + + + + ServerConfigDialog + + + set port + Configurer le port + + + + EASY SERVER CONNECTION + CONNECTION AU SERVEUR + + + + SERVER ADDRESS + ADRESSE DU SERVEUR + + + + just scan the code with your device!! + Scannez simplement le code!! + + + + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Discover it! </a> + YACReader est désormais disponible sur iOS, la meilleur manière de lire sur iPad, iPhone ou iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Essayez-le! </a> + + + + IP address + Adresse IP + + + + Port + Port + + + + enable the server + Autoriser le serveur + + + + QR generator error! + QR generator error! + + + + SortVolumeComics + + + Please, sort the list of comics on the left until it matches the comics' information. + + + + + sort comics to match comic information + + + + + issues + + + + + remove selected comics + + + + + restore all removed comics + + + + + restore removed comics + + + + + TableModel + + + yes + oui + + + + no + non + + + + Title + Titre + + + + File Name + Nom du fichier + + + + Pages + Pages + + + + Size + Taille + + + + Read + Lu + + + + Current Page + + + + + Rating + + + + + TitleHeader + + + SEARCH + + + + + UpdateLibraryDialog + + + Updating.... + Mise à jour... + + + + Cancel + Annuler + + + + Update library + Mettre la librairie à jour + + + + VolumeComicsModel + + + title + + + + + VolumesModel + + + year + + + + + issues + + + + + publisher + + + + + YACReaderDeletingProgress + + + Please wait, deleting in progress... + Attendez, suppression en cours... + + + + cancel + Annuler + + + + YACReaderFieldEdit + + + + Click to overwrite + Cliquer pour modifier + + + + Restore to default + Restaurer les paramètres par défaut + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Cliquer pour modifier + + + + Restore to default + Restaurer les paramètres par défaut + + + + YACReaderFlowConfigWidget + + + How to show covers: + Comment voir les couvertures: + + + + CoverFlow look + Vue CoverFlow + + + + Stripe look + Vue alignée + + + + Overlapped Stripe look + Vue superposée + + + + YACReaderGLFlowConfigWidget + + + Presets: + Réglages: + + + + Classic look + Vue classique + + + + Stripe look + Vue alignée + + + + Overlapped Stripe look + Vue superposée + + + + Modern look + Vue moderne + + + + Roulette look + Vue roulette + + + + Show advanced settings + Réglages avancés + + + + Custom: + Personnalisation: + + + + View angle + Angle de vue + + + + Position + Position + + + + Cover gap + Espace entre les couvertures + + + + Central gap + Espace central + + + + Zoom + Zoom + + + + Y offset + Axe Y + + + + Z offset + Axe Z + + + + Cover Angle + Angle des couvertures + + + + Visibility + Visibilité + + + + Light + Lumière + + + + Max angle + Angle maximum + + + + Low Performance + Basse performance + + + + High Performance + Haute performance + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + Utiliser VSync (améliore la qualité de l'image en plein écran, diminue la performance) + + + + Performance: + Performance: + + + + YACReaderOptionsDialog + + + Save + Sauvegarder + + + + Cancel + Annuler + + + + Use hardware acceleration (restart needed) + Utiliser l'accélération hardware (redémarrage nécessaire) + + + + YACReaderSideBar + + + LIBRARIES + LIBRAIRIES + + + + FOLDERS + DOSSIERS + + + + Search folders and comics + Recherche de dossiers et de comics + + + diff --git a/YACReaderLibrary/yacreaderlibrary_nl.ts b/YACReaderLibrary/yacreaderlibrary_nl.ts new file mode 100644 index 00000000..9bd4189b --- /dev/null +++ b/YACReaderLibrary/yacreaderlibrary_nl.ts @@ -0,0 +1,1517 @@ + + + + + AddLibraryDialog + + + Comics folder : + Strips map: + + + + Library Name : + Bibliotheek Naam : + + + + Add + Toevoegen + + + + Cancel + Annuleren + + + + Add an existing library + Voeg een bestaand bibliotheek toe + + + + ComicVineDialog + + + skip + + + + + back + + + + + next + + + + + search + + + + + close + + + + + + + + + Looking for volume... + + + + + + comic %1 of %2 - %3 + + + + + %1 comics selected + + + + + Error connecting to ComicVine + + + + + unknown error + + + + + + Retrieving tags for : %1 + + + + + Retrieving volume info... + + + + + Looking for comic... + + + + + CreateLibraryDialog + + + Comics folder : + Strips map: + + + + Library Name : + Bibliotheek Naam : + + + + Create + Aanmaken + + + + Cancel + Annuleren + + + + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + Een bibliotheek aanmaken kan enkele minuten duren. U kunt het proces stoppen en de bibliotheek later voltooien. + + + + Create new library + Een nieuwe Bibliotheek aanmaken + + + + Path not found + Pad niet gevonden + + + + The selected path does not exist or is not a valid path. Be sure that you have write access to this folder + De geselecteerde pad bestaat niet of is geen geldig pad. Controleer of u schrijftoegang hebt tot deze map + + + + ExportComicsInfoDialog + + + Output file : + Uitvoerbestand: + + + + Create + Aanmaken + + + + Cancel + Annuleren + + + + Export comics info + Strip info exporteren + + + + Destination database name + Bestemmingsdatabase naam + + + + Problem found while writing + Probleem bij het schrijven + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Het gekozen pad voor het uitvoerbestand bestaat niet of is geen geldig pad. Controleer of u schrijftoegang hebt tot deze map + + + + ExportLibraryDialog + + + Output folder : + Uitvoermap : + + + + Create + Aanmaken + + + + Cancel + Annuleren + + + + Create covers package + Aanmaken omslag pakket + + + + Problem found while writing + Probleem bij het schrijven + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Het gekozen pad voor het uitvoerbestand bestaat niet of is geen geldig pad. Controleer of u schrijftoegang hebt tot deze map + + + + Destination directory + Doeldirectory + + + + FileComic + + + Unknown error opening the file + + + + + 7z not found + 7Z Archiefbestand niet gevonden + + + + Format not supported + + + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + HelpAboutDialog + + + About + Over + + + + Help + Help + + + + ImportComicsInfoDialog + + + Import comics info + Strip info Importeren + + + + Info database location : + Info database locatie : + + + + Import + Importeren + + + + Cancel + Annuleren + + + + Comics info file (*.ydb) + Strips info bestand ( * .ydb) + + + + ImportLibraryDialog + + + Library Name : + Bibliotheek Naam : + + + + Package location : + Arrangement locatie : + + + + Destination folder : + Doelmap: + + + + Unpack + Uitpakken + + + + Cancel + Annuleren + + + + Extract a catalog + Een catalogus uitpakken + + + + Compresed library covers (*.clc) + Compresed omslag- bibliotheek ( * .clc) + + + + ImportWidget + + + stop + stop + + + + Some of the comics being added... + Enkele strips zijn toegevoegd ... + + + + Importing comics + Strips importeren + + + + <p>YACReaderLibrary is now creating a new library.</p><p>Create a library could take several minutes. You can stop the process and update the library later for completing the task.</p> + <P>YACReaderLibrary maak nu een nieuwe bibliotheek. < /p> <p>Een bibliotheek aanmaken kan enkele minuten duren. U kunt het proces stoppen en de bibliotheek later voltooien. < /p> + + + + Updating the library + Actualisering van de bibliotheek + + + + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later.</p> + <P>De huidige bibliotheek wordt bijgewerkt. Voor snellere updates, update uw bibliotheken regelmatig. < /p> <p>u kunt het proces stoppen om later bij te werken. < /p> + + + + LibraryWindow + + + YACReader Library + YACReader Bibliotheek + + + + + Library + Bibliotheek + + + + <font color='white'> press 'F' to close fullscreen mode </font> + <font color='white'>Druk op "F" om 'volledig scherm modus' te sluiten </font> + + + + Create a new library + Maak een nieuwe Bibliotheek + + + + Open an existing library + Open een bestaande Bibliotheek + + + + + Export comics info + Exporteren van strip info + + + + + Import comics info + Importeren van strip info + + + + Pack covers + Inpakken strip voorbladen + + + + Pack the covers of the selected library + Inpakken alle strip voorbladen van de geselecteerde Bibliotheek + + + + Unpack covers + Uitpakken voorbladen + + + + Unpack a catalog + Uitpaken van een catalogus + + + + Update library + Bibliotheek bijwerken + + + + Update current library + Huidige Bibliotheek bijwerken + + + + Rename library + Bibliotheek hernoemen + + + + Rename current library + Huidige Bibliotheek hernoemen + + + + Remove library + Bibliotheek verwijderen + + + + Remove current library from your collection + De huidige Bibliotheek verwijderen uit uw verzameling + + + + Open current comic + Huidige strip openen + + + + Open current comic on YACReader + Huidige strip openen in YACReader + + + + + Set as read + Instellen als gelezen + + + + Set comic as read + Strip Instellen als gelezen + + + + + Set as unread + Instellen als ongelezen + + + + Set comic as unread + Strip Instellen als ongelezen + + + + Show/Hide marks + Toon/Verberg markeringen + + + + Show or hide readed marks + Toon of Verberg gelezen markeringen + + + + Library not available + Library ' + Bibliotheek niet beschikbaar + + + + Fullscreen mode on/off + Volledig scherm modus aan/of + + + + Fullscreen mode on/off (F) + Volledig scherm modus aan/of (F) + + + + Help, About YACReader + Help, Over YACReader + + + + Select root node + Selecteer de hoofd categorie + + + + + + + + + + + Expand all nodes + Alle categorieën uitklappen + + + + - + - + + + + Colapse all nodes + Alle categorieën inklappen + + + + Show options dialog + Toon opties dialoog + + + + Show comics server options dialog + Toon strips-server opties dialoog + + + + Open folder... + Map openen ... + + + + Set as uncompleted + + + + + Set as completed + + + + + Open containing folder... + Open map ... + + + + Reset comic rating + + + + + Select all comics + Selecteer alle strips + + + + Edit + Bewerken + + + + Asign current order to comics + Nummeren van strips + + + + Update cover + Strip omslagen bijwerken + + + + Delete selected comics + Geselecteerde strips verwijderen + + + + Hide comic flow + Sluit de Omslagbrowser + + + + Download tags from Comic Vine + + + + + Folder + + + + + Comic + + + + + Update needed + Bijwerken is nodig + + + + This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now? + Deze bibliotheek is gemaakt met een vorige versie van YACReaderLibrary. Het moet worden bijgewerkt. Nu bijwerken? + + + + Update failed + Bijwerken mislukt + + + + The current library can't be udpated. Check for write write permissions on: + De huidige bibliotheek kan niet worden bijgewerkt. Controleer bij of u schrijfbevoegdheid hebt: + + + + Download new version + Nieuwe versie ophalen + + + + This library was created with a newer version of YACReaderLibrary. Download the new version now? + Deze bibliotheek is gemaakt met een nieuwere versie van YACReaderLibrary. Download de nieuwe versie? + + + + Library '%1' is no longer available. Do you want to remove it? + Bibliotheek ' %1' is niet langer beschikbaar. Wilt u het verwijderen? + + + + Old library + Oude Bibliotheek + + + + Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now? + Bibliotheek ' %1' is gemaakt met een oudere versie van YACReaderLibrary. Zij moet opnieuw worden aangemaakt. Wilt u de bibliotheek nu aanmaken? + + + + YACReader not found + + + + + YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary. + + + + + Library not found + Bibliotheek niet gevonden + + + + The selected folder doesn't contain any library. + De geselecteerde map bevat geen bibliotheek. + + + + Are you sure? + Weet u het zeker? + + + + Do you want remove + Wilt u verwijderen + + + + library? + Bibliotheek? + + + + Remove and delete metadata + Verwijder metagegevens + + + + Unable to delete + + + + + There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder. + + + + + Asign comics numbers + Strips nummeren + + + + Asign numbers starting in: + Strips nummeren beginnen bij: + + + + Error creating the library + Fout bij aanmaken Bibliotheek + + + + Error updating the library + Fout bij bijwerken Bibliotheek + + + + Error opening the library + Fout bij openen Bibliotheek + + + + Delete comics + Strips verwijderen + + + + All the selected comics will be deleted from your disk. Are you sure? + Alle geselecteerde strips worden verwijderd van uw schijf. Weet u het zeker? + + + + Library name already exists + Bibliotheek naam bestaat al + + + + There is another library with the name '%1'. + Er is al een bibliotheek met de naam ' %1 '. + + + + LocalComicListModel + + + file name + + + + + NoLibrariesWidget + + + You don't have any librarires yet + Je hebt geen nog librarires + + + + <p>You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.</p><p>Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.</p> + <P>u kunt een bibliotheek maken in een willekeurige map, YACReaderLibrary importeert alle strips en mappen uit deze map. Alle bibliotheek aangemaakt in het verleden kan je openen. < /p> <p>vergeet niet dat u YACReader kan gebruiken als stand-alone applicatie voor het lezen van de strips op de computer. < /p> + + + + create your first library + Maak uw eerste bibliotheek + + + + add an existing one + voeg een bestaande bibliotheek toe + + + + OptionsDialog + + + Options + Opties + + + + PropertiesDialog + + + General info + Algemene Info + + + + Authors + Auteurs + + + + Publishing + Uitgever + + + + Plot + Verhaal + + + + Cover page + Omslag + + + + Title: + Titel: + + + + Issue number: + Ids: + + + + Volume: + Inhoud: + + + + Story arc: + Verhaallijn: + + + + Genere: + Genre: + + + + Size: + Grootte(MB): + + + + Writer(s): + Schrijver(s): + + + + Penciller(s): + Tekenaar(s): + + + + Inker(s): + Inker(s): + + + + Colorist(s): + Inkleurder(s): + + + + Letterer(s): + Letterzetter(s): + + + + Cover Artist(s): + Omslag ontwikkelaar(s): + + + + Day: + Dag: + + + + Month: + Maand: + + + + Year: + Jaar: + + + + Publisher: + Uitgever: + + + + Format: + Formaat: + + + + Color/BW: + Kleur/ZW: + + + + Age rating: + Leeftijdsbeperking: + + + + Synopsis: + Synopsis: + + + + Characters: + Personages: + + + + Notes: + Opmerkingen: + + + + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> view </a> + + + + + Not found + Niet gevonden + + + + Comic not found. You should update your library. + Strip niet gevonden. U moet uw bibliotheek.bijwerken. + + + + Edit selected comics information + Geselecteerde strip informatie bijwerken + + + + Edit comic information + Strip informatie bijwerken + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + RenameLibraryDialog + + + New Library Name : + Nieuwe Bibliotheek Naam : + + + + Rename + Hernoem + + + + Cancel + Annuleren + + + + Rename current library + Hernoem de huidige bibiliotheek + + + + ScraperResultsPaginator + + + Number of volumes found : %1 + + + + + + page %1 of %2 + + + + + Number of %1 found : %2 + + + + + SearchSingleComic + + + Please provide some additional information. + + + + + Series: + + + + + SearchVolume + + + Please provide some additional information. + + + + + Series: + + + + + SelectComic + + + Please, select the right comic info. + + + + + comics + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SelectVolume + + + Please, select the right series for your comic. + + + + + volumes + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SeriesQuestion + + + You are trying to get information for various comics at once, are they part of the same series? + + + + + yes + Ja + + + + no + neen + + + + ServerConfigDialog + + + set port + Poort instellen + + + + EASY SERVER CONNECTION + GEMAKKELIJKE VERBINDING MET DE SERVER + + + + SERVER ADDRESS + SERVERADRES + + + + just scan the code with your device!! + Scan de code met uw apparaat! + + + + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Discover it! </a> + YACReader is nu beschikbaar voor iOS apparaten, de beste strip leeservaring nu op uw iPad, iPhone of iPod touch. <A href= "http://ios.yacreader.com' style= "color:rgb(193, 148, 65) "> Ontdek het zelf! < /A> + + + + IP address + IP-adres + + + + Port + Poort + + + + enable the server + De server instellen + + + + QR generator error! + QR generator fout! + + + + SortVolumeComics + + + Please, sort the list of comics on the left until it matches the comics' information. + + + + + sort comics to match comic information + + + + + issues + + + + + remove selected comics + + + + + restore all removed comics + + + + + restore removed comics + + + + + TableModel + + + yes + Ja + + + + no + neen + + + + Title + Titel + + + + File Name + Bestandsnaam + + + + Pages + Pagina's + + + + Size + Grootte(MB) + + + + Read + Gelezen + + + + Current Page + + + + + Rating + + + + + TitleHeader + + + SEARCH + + + + + UpdateLibraryDialog + + + Updating.... + Bijwerken.... + + + + Cancel + Annuleren + + + + Update library + Bibliotheek bijwerken + + + + VolumeComicsModel + + + title + + + + + VolumesModel + + + year + + + + + issues + + + + + publisher + + + + + YACReaderDeletingProgress + + + Please wait, deleting in progress... + Even geduld, verwijderen ... + + + + cancel + annuleren + + + + YACReaderFieldEdit + + + + Click to overwrite + Klik hier om te overschrijven + + + + Restore to default + Standaardwaarden herstellen + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Klik hier om te overschrijven + + + + Restore to default + Standaardwaarden herstellen + + + + YACReaderFlowConfigWidget + + + How to show covers: + Hoe omslagbladen bekijken: + + + + CoverFlow look + Omslagbrowser uiterlijk + + + + Stripe look + Brede band + + + + Overlapped Stripe look + Overlappende band + + + + YACReaderGLFlowConfigWidget + + + Presets: + Voorinstellingen: + + + + Classic look + Klassiek + + + + Stripe look + Brede band + + + + Overlapped Stripe look + Overlappende band + + + + Modern look + Modern + + + + Roulette look + Roulette + + + + Show advanced settings + Toon geavanceerde instellingen + + + + Custom: + Aangepast: + + + + View angle + Kijkhoek + + + + Position + Positie + + + + Cover gap + Ruimte tss Omslag + + + + Central gap + Centrale ruimte + + + + Zoom + Zoom + + + + Y offset + Y-positie + + + + Z offset + Z- positie + + + + Cover Angle + Omslag hoek + + + + Visibility + Zichtbaarheid + + + + Light + Licht + + + + Max angle + Maximale hoek + + + + Low Performance + Lage Prestaties + + + + High Performance + Hoge Prestaties + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + Gebruik VSync (verbetering van de beeldkwaliteit in de modus volledig scherm, slechtere prestatie) + + + + Performance: + Prestatie: + + + + YACReaderOptionsDialog + + + Save + Bewaar + + + + Cancel + Annuleren + + + + Use hardware acceleration (restart needed) + Gebruik hardware versnelling (opnieuw opstarten vereist) + + + + YACReaderSideBar + + + LIBRARIES + BIBLIOTHEKEN + + + + FOLDERS + MAPPEN + + + + Search folders and comics + Zoeken in mappen en strips + + + diff --git a/YACReaderLibrary/yacreaderlibrary_pt.ts b/YACReaderLibrary/yacreaderlibrary_pt.ts new file mode 100644 index 00000000..6be9cf09 --- /dev/null +++ b/YACReaderLibrary/yacreaderlibrary_pt.ts @@ -0,0 +1,1520 @@ + + + + + AddLibraryDialog + + + Comics folder : + Pasta dos quadrinhos : + + + + Library Name : + Nome da Biblioteca : + + + + Add + Adicionar + + + + Cancel + Cancelar + + + + Add an existing library + Adicionar uma biblioteca existente + + + + ComicVineDialog + + + skip + + + + + back + + + + + next + + + + + search + + + + + close + + + + + + + + + Looking for volume... + + + + + + comic %1 of %2 - %3 + + + + + %1 comics selected + + + + + Error connecting to ComicVine + + + + + unknown error + + + + + + Retrieving tags for : %1 + + + + + Retrieving volume info... + + + + + Looking for comic... + + + + + CreateLibraryDialog + + + Comics folder : + Pasta dos quadrinhos : + + + + Library Name : + Nome da Biblioteca : + + + + Create + Criar + + + + Cancel + Cancelar + + + + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + + + + + Create new library + Criar uma nova biblioteca + + + + Path not found + + + + + The selected path does not exist or is not a valid path. Be sure that you have write access to this folder + + + + + ExportComicsInfoDialog + + + Output file : + + + + + Create + Criar + + + + Cancel + Cancelar + + + + Export comics info + + + + + Destination database name + + + + + Problem found while writing + + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + + + + + ExportLibraryDialog + + + Output folder : + Pasta de saída : + + + + Create + Criar + + + + Cancel + Cancelar + + + + Create covers package + Criar pacote de capas + + + + Problem found while writing + + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + + + + + Destination directory + Diretório de destino + + + + FileComic + + + Unknown error opening the file + + + + + 7z not found + 7z não encontrado + + + + Format not supported + + + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + HelpAboutDialog + + + About + + + + + Help + + + + + ImportComicsInfoDialog + + + Import comics info + + + + + Info database location : + + + + + Import + + + + + Cancel + Cancelar + + + + Comics info file (*.ydb) + + + + + ImportLibraryDialog + + + Library Name : + Nome da Biblioteca : + + + + Package location : + Local do pacote : + + + + Destination folder : + Pasta de destino : + + + + Unpack + Desempacotar + + + + Cancel + Cancelar + + + + Extract a catalog + Extrair um catálogo + + + + Compresed library covers (*.clc) + Capas da biblioteca compactada (*.clc) + + + + ImportWidget + + + Importing comics + + + + + stop + + + + + Some of the comics being added... + + + + + <p>YACReaderLibrary is now creating a new library.</p><p>Create a library could take several minutes. You can stop the process and update the library later for completing the task.</p> + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + + + + + Updating the library + + + + + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later.</p> + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later. + + + + + LibraryWindow + + + <font color='white'> press 'F' to close fullscreen mode </font> + <font color='white'> pressione 'F' para fechar o modo tela cheia </font> + + + + YACReader Library + Biblioteca YACReader + + + + Create a new library + Criar uma nova biblioteca + + + + Open an existing library + Abrir uma biblioteca existente + + + + + Export comics info + + + + + + Import comics info + + + + + Pack covers + + + + + Pack the covers of the selected library + Pacote de capas da biblioteca selecionada + + + + Unpack covers + + + + + Unpack a catalog + Desempacotar um catálogo + + + + Update current library + Atualizar biblioteca atual + + + + Rename library + + + + + Rename current library + Renomear biblioteca atual + + + + Remove current library from your collection + Remover biblioteca atual da sua coleção + + + + Open current comic + + + + + Open current comic on YACReader + Abrir quadrinho atual no YACReader + + + + + Set as read + + + + + Set comic as read + + + + + + Set as unread + + + + + Set comic as unread + + + + + Show/Hide marks + + + + + Show or hide readed marks + + + + + Fullscreen mode on/off + + + + + Fullscreen mode on/off (F) + Modo tela cheia ligar/desligar (F) + + + + Help, About YACReader + Ajuda, Sobre o YACReader + + + + Select root node + Selecionar raiz + + + + + + + + + + Expand all nodes + Expandir todos + + + + - + + + + + Colapse all nodes + Contrair todos + + + + Show options dialog + Mostrar opções + + + + Show comics server options dialog + + + + + Open folder... + Abrir pasta... + + + + Set as uncompleted + + + + + Set as completed + + + + + Open containing folder... + Abrir a pasta contendo... + + + + Reset comic rating + + + + + Select all comics + + + + + Edit + + + + + Asign current order to comics + + + + + Update cover + + + + + Delete selected comics + + + + + Hide comic flow + + + + + Download tags from Comic Vine + + + + + Folder + + + + + Comic + + + + + Library not available + Library ' + + + + + Old library + + + + + YACReader not found + + + + + YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary. + + + + + Unable to delete + + + + + There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder. + + + + + Error creating the library + + + + + Error updating the library + + + + + Error opening the library + + + + + Delete comics + + + + + All the selected comics will be deleted from your disk. Are you sure? + + + + + Library name already exists + + + + + There is another library with the name '%1'. + + + + + + Library + Biblioteca + + + + Update library + + + + + Remove library + + + + + Update needed + + + + + This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now? + + + + + Update failed + + + + + The current library can't be udpated. Check for write write permissions on: + + + + + Download new version + + + + + This library was created with a newer version of YACReaderLibrary. Download the new version now? + + + + + Library '%1' is no longer available. Do you want to remove it? + + + + + Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now? + + + + + Library not found + + + + + The selected folder doesn't contain any library. + + + + + Are you sure? + Você tem certeza? + + + + library? + + + + + Remove and delete metadata + + + + + Do you want remove + Você deseja remover + + + + Asign comics numbers + + + + + Asign numbers starting in: + + + + + LocalComicListModel + + + file name + + + + + NoLibrariesWidget + + + You don't have any librarires yet + + + + + <p>You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.</p><p>Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.</p> + + + + + create your first library + + + + + add an existing one + + + + + OptionsDialog + + + Options + + + + + PropertiesDialog + + + General info + + + + + Authors + + + + + Publishing + + + + + Plot + + + + + Cover page + + + + + Title: + + + + + Issue number: + + + + + Volume: + + + + + Story arc: + + + + + Genere: + + + + + Size: + + + + + Writer(s): + + + + + Penciller(s): + + + + + Inker(s): + + + + + Colorist(s): + + + + + Letterer(s): + + + + + Cover Artist(s): + + + + + Day: + + + + + Month: + + + + + Year: + + + + + Publisher: + + + + + Format: + + + + + Color/BW: + + + + + Age rating: + + + + + Synopsis: + + + + + Characters: + + + + + Notes: + + + + + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> view </a> + + + + + Not found + + + + + Comic not found. You should update your library. + + + + + Edit selected comics information + + + + + Edit comic information + + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + RenameLibraryDialog + + + New Library Name : + Novo nome da biblioteca : + + + + Rename + Renomear + + + + Cancel + Cancelar + + + + Rename current library + Renomear biblioteca atual + + + + ScraperResultsPaginator + + + Number of volumes found : %1 + + + + + + page %1 of %2 + + + + + Number of %1 found : %2 + + + + + SearchSingleComic + + + Please provide some additional information. + + + + + Series: + + + + + SearchVolume + + + Please provide some additional information. + + + + + Series: + + + + + SelectComic + + + Please, select the right comic info. + + + + + comics + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SelectVolume + + + Please, select the right series for your comic. + + + + + volumes + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SeriesQuestion + + + You are trying to get information for various comics at once, are they part of the same series? + + + + + yes + + + + + no + + + + + ServerConfigDialog + + + set port + + + + + EASY SERVER CONNECTION + + + + + SERVER ADDRESS + + + + + just scan the code with your device!! + + + + + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Discover it! </a> + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com'> Discover it! </a> + + + + + IP address + + + + + Port + + + + + enable the server + + + + + QR generator error! + + + + + SortVolumeComics + + + Please, sort the list of comics on the left until it matches the comics' information. + + + + + sort comics to match comic information + + + + + issues + + + + + remove selected comics + + + + + restore all removed comics + + + + + restore removed comics + + + + + TableModel + + + yes + + + + + no + + + + + Title + + + + + File Name + + + + + Pages + + + + + Size + + + + + Read + + + + + Current Page + + + + + Rating + + + + + TitleHeader + + + SEARCH + + + + + UpdateLibraryDialog + + + Updating.... + Atualizando.... + + + + Cancel + Cancelar + + + + Update library + + + + + VolumeComicsModel + + + title + + + + + VolumesModel + + + year + + + + + issues + + + + + publisher + + + + + YACReaderDeletingProgress + + + Please wait, deleting in progress... + + + + + cancel + + + + + YACReaderFieldEdit + + + + Click to overwrite + + + + + Restore to default + + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + + + + + Restore to default + + + + + YACReaderFlowConfigWidget + + + How to show covers: + Como mostrar capas: + + + + CoverFlow look + Olhar capa cheia + + + + Stripe look + Olhar lista + + + + Overlapped Stripe look + Olhar lista sobreposta + + + + YACReaderGLFlowConfigWidget + + + Presets: + + + + + Classic look + + + + + Stripe look + Olhar lista + + + + Overlapped Stripe look + Olhar lista sobreposta + + + + Modern look + + + + + Roulette look + + + + + Show advanced settings + + + + + Custom: + + + + + View angle + + + + + Position + + + + + Cover gap + + + + + Central gap + + + + + Zoom + + + + + Y offset + + + + + Z offset + + + + + Cover Angle + + + + + Visibility + + + + + Light + + + + + Max angle + + + + + Low Performance + + + + + High Performance + + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + + + + + Performance: + + + + + YACReaderOptionsDialog + + + Save + Salvar + + + + Cancel + Cancelar + + + + Use hardware acceleration (restart needed) + + + + + YACReaderSideBar + + + LIBRARIES + + + + + FOLDERS + + + + + Search folders and comics + + + + diff --git a/YACReaderLibrary/yacreaderlibrary_ru.ts b/YACReaderLibrary/yacreaderlibrary_ru.ts new file mode 100644 index 00000000..fde5a9f6 --- /dev/null +++ b/YACReaderLibrary/yacreaderlibrary_ru.ts @@ -0,0 +1,1520 @@ + + + + + AddLibraryDialog + + + Comics folder : + Папка комикÑов: + + + + Library Name : + Ð˜Ð¼Ñ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñ‚ÐµÐºÐ¸: + + + + Add + Добавить + + + + Cancel + Отменить + + + + Add an existing library + Добавить в ÑущеÑтвующую библиотеку + + + + ComicVineDialog + + + skip + + + + + back + + + + + next + + + + + search + + + + + close + + + + + + + + + Looking for volume... + + + + + + comic %1 of %2 - %3 + + + + + %1 comics selected + + + + + Error connecting to ComicVine + + + + + unknown error + + + + + + Retrieving tags for : %1 + + + + + Retrieving volume info... + + + + + Looking for comic... + + + + + CreateLibraryDialog + + + Comics folder : + Папка комикÑов: + + + + Library Name : + Ð˜Ð¼Ñ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñ‚ÐµÐºÐ¸: + + + + Create + Создать + + + + Cancel + Отмена + + + + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + Создание библиотеки может занÑть неÑколько минут. Ð’Ñ‹ можете оÑтановить процеÑÑ Ð¸ обновить библиотеку позже Ð´Ð»Ñ Ð·Ð°Ð²ÐµÑ€ÑˆÐµÐ½Ð¸Ñ Ð·Ð°Ð´Ð°Ñ‡Ð¸. + + + + Create new library + Создать новую библиотеку + + + + Path not found + Путь не найден + + + + The selected path does not exist or is not a valid path. Be sure that you have write access to this folder + Выбранный путь отÑутÑтвует, либо неверен. УбедитеÑÑŒ , что у Ð²Ð°Ñ ÐµÑть доÑтуп к Ñтой папке + + + + ExportComicsInfoDialog + + + Output file : + Файл вывода: + + + + Create + Создать + + + + Cancel + Отмена + + + + Export comics info + ЭкÑпортировать информацию комикÑа + + + + Destination database name + Ð˜Ð¼Ñ Ð½Ð°Ð·Ð½Ð°Ñ‡ÐµÐ½Ð½Ð¾Ð¹ базы данных + + + + Problem found while writing + Проблема при напиÑании + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Выбранный путь Ð´Ð»Ñ Ð¸Ð¼Ð¿Ð¾Ñ€Ñ‚Ð¸Ñ€ÑƒÐµÐ¼Ð¾Ð³Ð¾ файла отÑутÑтвует, либо неверен. УбедитеÑÑŒ , что у Ð²Ð°Ñ ÐµÑть доÑтуп к Ñтой папке + + + + ExportLibraryDialog + + + Output folder : + Файл вывода: + + + + Create + Создать + + + + Cancel + Отменить + + + + Create covers package + Создать комплект обложек + + + + Problem found while writing + Проблема при напиÑании + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Выбранный путь Ð´Ð»Ñ Ð¸Ð¼Ð¿Ð¾Ñ€Ñ‚Ð¸Ñ€ÑƒÐµÐ¼Ð¾Ð³Ð¾ файла отÑутÑтвует, либо неверен. УбедитеÑÑŒ , что у Ð²Ð°Ñ ÐµÑть доÑтуп к Ñтой папке + + + + Destination directory + Ðазначенное меÑтонахождение + + + + FileComic + + + Unknown error opening the file + + + + + 7z not found + 7z не найден + + + + Format not supported + + + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + HelpAboutDialog + + + About + О программе + + + + Help + ÐаÑтройки + + + + ImportComicsInfoDialog + + + Import comics info + Импортировать информаию комикÑа + + + + Info database location : + МеÑтонахождение базы данных: + + + + Import + Импортировать + + + + Cancel + Отмена + + + + Comics info file (*.ydb) + Ð˜Ð½Ñ„Ð¾Ñ€Ð¼Ð°Ñ†Ð¸Ñ Ñ„Ð°Ð¹Ð»Ð° комикÑа + + + + ImportLibraryDialog + + + Library Name : + Ð˜Ð¼Ñ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñ‚ÐµÐºÐ¸: + + + + Package location : + МеÑтоположение комплекта: + + + + Destination folder : + ÐÐ°Ð·Ð½Ð°Ñ‡ÐµÐ½Ð½Ð°Ñ Ð¿Ð°Ð¿ÐºÐ°: + + + + Unpack + РаÑпаковать + + + + Cancel + Отмена + + + + Extract a catalog + Извлечь каталог + + + + Compresed library covers (*.clc) + Ð¡Ð¶Ð°Ñ‚Ð°Ñ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñ‚ÐµÐºÐ° обложек + + + + ImportWidget + + + Importing comics + + + + + stop + + + + + Some of the comics being added... + + + + + <p>YACReaderLibrary is now creating a new library.</p><p>Create a library could take several minutes. You can stop the process and update the library later for completing the task.</p> + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + Создание библиотеки может занÑть неÑколько минут. Ð’Ñ‹ можете оÑтановить процеÑÑ Ð¸ обновить библиотеку позже Ð´Ð»Ñ Ð·Ð°Ð²ÐµÑ€ÑˆÐµÐ½Ð¸Ñ Ð·Ð°Ð´Ð°Ñ‡Ð¸. + + + + Updating the library + + + + + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later.</p> + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later. + + + + + LibraryWindow + + + YACReader Library + Библиотека YACReader + + + + <font color='white'> press 'F' to close fullscreen mode </font> + <font color='white'> нажмите 'F' чтобы выйте из ПолноÑкранного режима </font> + + + + Create a new library + Создать новую библиотеку + + + + Open an existing library + Открыть ÑущеÑтвующую библиотеку + + + + + Export comics info + ЕкÑпорт комикÑа + + + + + Import comics info + Импорт комикÑа + + + + Pack covers + Запакавать обложки + + + + Pack the covers of the selected library + Запакавать обложки выбранной библиотеки + + + + Unpack covers + РаÑпокавать обложки + + + + Unpack a catalog + РаÑпакавать каталог + + + + Update library + Обновить библиотеку + + + + Update current library + Обновить текущую библиотеку + + + + Rename library + + + + + Rename current library + Переименовать текущую бибилиотеку + + + + Remove current library from your collection + Удалите текущую библиотеку из Ñвоей коллекции + + + + Open current comic + + + + + Open current comic on YACReader + + + + + + Set as read + + + + + Set comic as read + + + + + + Set as unread + + + + + Set comic as unread + + + + + Show/Hide marks + + + + + Show or hide readed marks + + + + + Fullscreen mode on/off + Полноекранный режим включить/выключить + + + + Fullscreen mode on/off (F) + полноекранный режим включить/выключить(F) + + + + Help, About YACReader + Справка, о программе YACReader + + + + Select root node + + + + + + + + + + + Expand all nodes + + + + + - + + + + + Colapse all nodes + + + + + Show options dialog + Показать наÑтройки диаога + + + + Show comics server options dialog + + + + + Open folder... + Открыть папку... + + + + Set as uncompleted + + + + + Set as completed + + + + + Open containing folder... + + + + + Reset comic rating + + + + + Select all comics + Выбрать вÑе комикÑÑ‹ + + + + Edit + Редактировать + + + + Asign current order to comics + + + + + Update cover + Обновить обложки + + + + Delete selected comics + + + + + Hide comic flow + Ðе показывать поток комикÑов + + + + Download tags from Comic Vine + + + + + Folder + + + + + Comic + + + + + Library not available + Library ' + Библиотека не доÑтупна + + + + Library '%1' is no longer available. Do you want to remove it? + + + + + Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now? + + + + + Old library + + + + + YACReader not found + + + + + YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary. + + + + + Unable to delete + + + + + There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder. + + + + + Error creating the library + + + + + Error updating the library + + + + + Error opening the library + + + + + Delete comics + + + + + All the selected comics will be deleted from your disk. Are you sure? + + + + + Library name already exists + + + + + There is another library with the name '%1'. + + + + + + Library + Библиотека + + + + Remove library + + + + + Update needed + Ðеобходимо обновление + + + + This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now? + Эта библиотека была Ñоздана Ñ Ð¿Ñ€ÐµÐ´Ñ‹Ð´ÑƒÑ‰ÐµÐ¹ верÑией YACReaderLibrary. Она должна быть обновлена. Обновить ÑейчаÑ? + + + + Update failed + Обновить неудалоÑÑŒ + + + + The current library can't be udpated. Check for write write permissions on: + Ð’ наÑтоÑщее Ð²Ñ€ÐµÐ¼Ñ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñ‚ÐµÐºÐ° не может быть обновлена. Проверьте права на чтение/запиÑÑŒ: + + + + Download new version + Загрузить новую верÑию + + + + This library was created with a newer version of YACReaderLibrary. Download the new version now? + Эта библиотека был Ñоздан при новой верÑией YACReaderLibrary. Скачать новую верÑию ÑейчаÑ? + + + + Library not found + Библиотека не найдена + + + + The selected folder doesn't contain any library. + Ð’Ñ‹Ð±Ñ€Ð°Ð½Ð½Ð°Ñ Ð¿Ð°Ð¿ÐºÐ° не Ñодержит библиотеку. + + + + Are you sure? + Ð’Ñ‹ уверены? + + + + library? + + + + + Remove and delete metadata + + + + + Do you want remove + Ð’Ñ‹ хотите удалить + + + + Asign comics numbers + Ðазначение номеров комикÑа + + + + Asign numbers starting in: + Ðазначьте номера, начинающиеÑÑ Ð½Ð°: + + + + LocalComicListModel + + + file name + + + + + NoLibrariesWidget + + + You don't have any librarires yet + + + + + <p>You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.</p><p>Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.</p> + + + + + create your first library + + + + + add an existing one + + + + + OptionsDialog + + + Options + ÐаÑтройки + + + + PropertiesDialog + + + General info + ÐžÐ±Ñ‰Ð¸Ñ Ð¸Ð½Ñ„Ð¾Ñ€Ð¼Ð°Ñ†Ð¸Ñ + + + + Authors + + + + + Publishing + + + + + Plot + + + + + Cover page + + + + + Title: + + + + + Issue number: + + + + + Volume: + Объём : + + + + Story arc: + + + + + Genere: + + + + + Size: + Размер: + + + + Writer(s): + + + + + Penciller(s): + + + + + Inker(s): + + + + + Colorist(s): + + + + + Letterer(s): + + + + + Cover Artist(s): + + + + + Day: + День: + + + + Month: + меÑÑц: + + + + Year: + Год: + + + + Publisher: + + + + + Format: + Формат: + + + + Color/BW: + + + + + Age rating: + + + + + Synopsis: + + + + + Characters: + + + + + Notes: + ПримичÑние: + + + + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> view </a> + + + + + Not found + Ðе найдено + + + + Comic not found. You should update your library. + + + + + Edit selected comics information + Редактировать информацию выбранного комикÑа + + + + Edit comic information + Реддактировать информацию + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + RenameLibraryDialog + + + New Library Name : + Ðовое Ð¸Ð¼Ñ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñ‚ÐµÐºÐ¸: + + + + Rename + Переименовать + + + + Cancel + Отмена + + + + Rename current library + Переименовать текущую бибилиотеку + + + + ScraperResultsPaginator + + + Number of volumes found : %1 + + + + + + page %1 of %2 + + + + + Number of %1 found : %2 + + + + + SearchSingleComic + + + Please provide some additional information. + + + + + Series: + + + + + SearchVolume + + + Please provide some additional information. + + + + + Series: + + + + + SelectComic + + + Please, select the right comic info. + + + + + comics + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SelectVolume + + + Please, select the right series for your comic. + + + + + volumes + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SeriesQuestion + + + You are trying to get information for various comics at once, are they part of the same series? + + + + + yes + + + + + no + + + + + ServerConfigDialog + + + set port + + + + + EASY SERVER CONNECTION + + + + + SERVER ADDRESS + + + + + just scan the code with your device!! + + + + + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Discover it! </a> + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com'> Discover it! </a> + + + + + IP address + + + + + Port + Порт + + + + enable the server + + + + + QR generator error! + Ошибка QR генератора! + + + + SortVolumeComics + + + Please, sort the list of comics on the left until it matches the comics' information. + + + + + sort comics to match comic information + + + + + issues + + + + + remove selected comics + + + + + restore all removed comics + + + + + restore removed comics + + + + + TableModel + + + yes + + + + + no + + + + + Title + Заголовок + + + + File Name + Ð˜Ð¼Ñ Ñ„Ð°Ð¹Ð»Ð° + + + + Pages + Страницы + + + + Size + + + + + Read + + + + + Current Page + + + + + Rating + + + + + TitleHeader + + + SEARCH + + + + + UpdateLibraryDialog + + + Updating.... + Обновление... + + + + Cancel + Отмена + + + + Update library + Обновить библиотеку + + + + VolumeComicsModel + + + title + + + + + VolumesModel + + + year + + + + + issues + + + + + publisher + + + + + YACReaderDeletingProgress + + + Please wait, deleting in progress... + + + + + cancel + + + + + YACReaderFieldEdit + + + + Click to overwrite + Ðажмите Ð´Ð»Ñ Ð¿ÐµÑ€ÐµÐ·Ð°Ð¿Ð¸Ñи + + + + Restore to default + Вернуть к первоначальным значениÑм + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + Ðажмите Ð´Ð»Ñ Ð¿ÐµÑ€ÐµÐ·Ð°Ð¿Ð¸Ñи + + + + Restore to default + Вернуть к первоначальным значениÑм + + + + YACReaderFlowConfigWidget + + + How to show covers: + Как показать обложки: + + + + CoverFlow look + ПредоÑмотр обложки + + + + Stripe look + Вид полоÑами + + + + Overlapped Stripe look + Вид перекрывающимиÑÑ Ð¿Ð¾Ð»Ð¾Ñами + + + + YACReaderGLFlowConfigWidget + + + Presets: + ПредуÑтановки: + + + + Classic look + КлаÑÑичеÑкий вид + + + + Stripe look + Вид полоÑами + + + + Overlapped Stripe look + Вид перекрывающимиÑÑ Ð¿Ð¾Ð»Ð¾Ñами + + + + Modern look + Современный вид + + + + Roulette look + Вид рулеткой + + + + Show advanced settings + + + + + Custom: + ПользовательÑкий: + + + + View angle + Угол Ð·Ñ€ÐµÐ½Ð¸Ñ + + + + Position + ÐŸÐ¾Ð·Ð¸Ñ†Ð¸Ñ + + + + Cover gap + Охватить разрыв + + + + Central gap + СфокуÑировать разрыв + + + + Zoom + МаÑштабировать + + + + Y offset + Смещение по Y + + + + Z offset + Смещение по Z + + + + Cover Angle + Охватить угол + + + + Visibility + ПрозрачноÑть + + + + Light + ОÑветить + + + + Max angle + МакÑимальный угол + + + + Low Performance + ÐœÐ¸Ð½Ð¸Ð¼Ð°Ð»ÑŒÐ½Ð°Ñ Ð¿Ñ€Ð¾Ð¸Ð·Ð²Ð¾Ð´Ð¸Ñ‚ÐµÐ»ÑŒÐ½Ð¾Ñть + + + + High Performance + МакÑÐ¸Ð¼Ð°Ð»ÑŒÐ½Ð°Ñ Ð¿Ñ€Ð¾Ð¸Ð·Ð²Ð¾Ð´Ð¸Ñ‚ÐµÐ»ÑŒÐ½Ð¾Ñть + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + ИÑпользовать VSync (повыÑить формат Ð¸Ð·Ð¾Ð±Ñ€Ð°Ð¶ÐµÐ½Ð¸Ñ Ð² полноÑкранном режиме , хуже производительноÑть) + + + + Performance: + ПроизводительноÑть: + + + + YACReaderOptionsDialog + + + Save + Сохранить + + + + Cancel + Отмена + + + + Use hardware acceleration (restart needed) + ИÑпользовать аппаратное уÑкорение (необходима перезагрузка) + + + + YACReaderSideBar + + + LIBRARIES + + + + + FOLDERS + + + + + Search folders and comics + + + + diff --git a/YACReaderLibrary/yacreaderlibrary_source.ts b/YACReaderLibrary/yacreaderlibrary_source.ts new file mode 100644 index 00000000..d6a95767 --- /dev/null +++ b/YACReaderLibrary/yacreaderlibrary_source.ts @@ -0,0 +1,1517 @@ + + + + + AddLibraryDialog + + + Comics folder : + + + + + Library Name : + + + + + Add + + + + + Cancel + + + + + Add an existing library + + + + + ComicVineDialog + + + skip + + + + + back + + + + + next + + + + + search + + + + + close + + + + + + + + + Looking for volume... + + + + + + comic %1 of %2 - %3 + + + + + %1 comics selected + + + + + Error connecting to ComicVine + + + + + unknown error + + + + + + Retrieving tags for : %1 + + + + + Retrieving volume info... + + + + + Looking for comic... + + + + + CreateLibraryDialog + + + Comics folder : + + + + + Library Name : + + + + + Create + + + + + Cancel + + + + + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + + + + + Create new library + + + + + Path not found + + + + + The selected path does not exist or is not a valid path. Be sure that you have write access to this folder + + + + + ExportComicsInfoDialog + + + Output file : + + + + + Create + + + + + Cancel + + + + + Export comics info + + + + + Destination database name + + + + + Problem found while writing + + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + + + + + ExportLibraryDialog + + + Output folder : + + + + + Create + + + + + Cancel + + + + + Create covers package + + + + + Problem found while writing + + + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + + + + + Destination directory + + + + + FileComic + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + + Unknown error opening the file + + + + + 7z not found + + + + + Format not supported + + + + + HelpAboutDialog + + + About + + + + + Help + + + + + ImportComicsInfoDialog + + + Import comics info + + + + + Info database location : + + + + + Import + + + + + Cancel + + + + + Comics info file (*.ydb) + + + + + ImportLibraryDialog + + + Library Name : + + + + + Package location : + + + + + Destination folder : + + + + + Unpack + + + + + Cancel + + + + + Extract a catalog + + + + + Compresed library covers (*.clc) + + + + + ImportWidget + + + stop + + + + + Some of the comics being added... + + + + + Importing comics + + + + + <p>YACReaderLibrary is now creating a new library.</p><p>Create a library could take several minutes. You can stop the process and update the library later for completing the task.</p> + + + + + Updating the library + + + + + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later.</p> + + + + + LibraryWindow + + + YACReader Library + + + + + + Library + + + + + <font color='white'> press 'F' to close fullscreen mode </font> + + + + + Create a new library + + + + + Open an existing library + + + + + + Export comics info + + + + + + Import comics info + + + + + Pack covers + + + + + Pack the covers of the selected library + + + + + Unpack covers + + + + + Unpack a catalog + + + + + Update library + + + + + Update current library + + + + + Rename library + + + + + Rename current library + + + + + Remove library + + + + + Remove current library from your collection + + + + + Open current comic + + + + + Open current comic on YACReader + + + + + + Set as read + + + + + Set comic as read + + + + + + Set as unread + + + + + Set comic as unread + + + + + Show/Hide marks + + + + + Show or hide readed marks + + + + + Library not available + Library ' + + + + + Fullscreen mode on/off + + + + + Fullscreen mode on/off (F) + + + + + Help, About YACReader + + + + + Select root node + + + + + + + + + + + Expand all nodes + + + + + - + + + + + Colapse all nodes + + + + + Show options dialog + + + + + Show comics server options dialog + + + + + Open folder... + + + + + Set as uncompleted + + + + + Set as completed + + + + + Open containing folder... + + + + + Reset comic rating + + + + + Select all comics + + + + + Edit + + + + + Asign current order to comics + + + + + Update cover + + + + + Delete selected comics + + + + + Hide comic flow + + + + + Download tags from Comic Vine + + + + + Folder + + + + + Comic + + + + + Update needed + + + + + This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now? + + + + + Update failed + + + + + The current library can't be udpated. Check for write write permissions on: + + + + + Download new version + + + + + This library was created with a newer version of YACReaderLibrary. Download the new version now? + + + + + Library '%1' is no longer available. Do you want to remove it? + + + + + Old library + + + + + Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now? + + + + + YACReader not found + + + + + YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary. + + + + + Library not found + + + + + The selected folder doesn't contain any library. + + + + + Are you sure? + + + + + Do you want remove + + + + + library? + + + + + Remove and delete metadata + + + + + Unable to delete + + + + + There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder. + + + + + Asign comics numbers + + + + + Asign numbers starting in: + + + + + Error creating the library + + + + + Error updating the library + + + + + Error opening the library + + + + + Delete comics + + + + + All the selected comics will be deleted from your disk. Are you sure? + + + + + Library name already exists + + + + + There is another library with the name '%1'. + + + + + LocalComicListModel + + + file name + + + + + NoLibrariesWidget + + + You don't have any librarires yet + + + + + <p>You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.</p><p>Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.</p> + + + + + create your first library + + + + + add an existing one + + + + + OptionsDialog + + + Options + + + + + PropertiesDialog + + + General info + + + + + Authors + + + + + Publishing + + + + + Plot + + + + + Cover page + + + + + Title: + + + + + Issue number: + + + + + Volume: + + + + + Story arc: + + + + + Genere: + + + + + Size: + + + + + Writer(s): + + + + + Penciller(s): + + + + + Inker(s): + + + + + Colorist(s): + + + + + Letterer(s): + + + + + Cover Artist(s): + + + + + Day: + + + + + Month: + + + + + Year: + + + + + Publisher: + + + + + Format: + + + + + Color/BW: + + + + + Age rating: + + + + + Synopsis: + + + + + Characters: + + + + + Notes: + + + + + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> view </a> + + + + + Not found + + + + + Comic not found. You should update your library. + + + + + Edit selected comics information + + + + + Edit comic information + + + + + QObject + + + 7z lib not found + + + + + unable to load 7z lib from ./utils + + + + + RenameLibraryDialog + + + New Library Name : + + + + + Rename + + + + + Cancel + + + + + Rename current library + + + + + ScraperResultsPaginator + + + Number of volumes found : %1 + + + + + + page %1 of %2 + + + + + Number of %1 found : %2 + + + + + SearchSingleComic + + + Please provide some additional information. + + + + + Series: + + + + + SearchVolume + + + Please provide some additional information. + + + + + Series: + + + + + SelectComic + + + Please, select the right comic info. + + + + + comics + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SelectVolume + + + Please, select the right series for your comic. + + + + + volumes + + + + + loading cover + + + + + loading description + + + + + description unavailable + + + + + SeriesQuestion + + + You are trying to get information for various comics at once, are they part of the same series? + + + + + yes + + + + + no + + + + + ServerConfigDialog + + + set port + + + + + EASY SERVER CONNECTION + + + + + SERVER ADDRESS + + + + + just scan the code with your device!! + + + + + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Discover it! </a> + + + + + IP address + + + + + Port + + + + + enable the server + + + + + QR generator error! + + + + + SortVolumeComics + + + Please, sort the list of comics on the left until it matches the comics' information. + + + + + sort comics to match comic information + + + + + issues + + + + + remove selected comics + + + + + restore all removed comics + + + + + restore removed comics + + + + + TableModel + + + yes + + + + + no + + + + + Title + + + + + File Name + + + + + Pages + + + + + Size + + + + + Read + + + + + Current Page + + + + + Rating + + + + + TitleHeader + + + SEARCH + + + + + UpdateLibraryDialog + + + Updating.... + + + + + Cancel + + + + + Update library + + + + + VolumeComicsModel + + + title + + + + + VolumesModel + + + year + + + + + issues + + + + + publisher + + + + + YACReaderDeletingProgress + + + Please wait, deleting in progress... + + + + + cancel + + + + + YACReaderFieldEdit + + + + Click to overwrite + + + + + Restore to default + + + + + YACReaderFieldPlainTextEdit + + + + + + Click to overwrite + + + + + Restore to default + + + + + YACReaderFlowConfigWidget + + + How to show covers: + + + + + CoverFlow look + + + + + Stripe look + + + + + Overlapped Stripe look + + + + + YACReaderGLFlowConfigWidget + + + Presets: + + + + + Classic look + + + + + Stripe look + + + + + Overlapped Stripe look + + + + + Modern look + + + + + Roulette look + + + + + Show advanced settings + + + + + Custom: + + + + + View angle + + + + + Position + + + + + Cover gap + + + + + Central gap + + + + + Zoom + + + + + Y offset + + + + + Z offset + + + + + Cover Angle + + + + + Visibility + + + + + Light + + + + + Max angle + + + + + Low Performance + + + + + High Performance + + + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + + + + + Performance: + + + + + YACReaderOptionsDialog + + + Save + + + + + Cancel + + + + + Use hardware acceleration (restart needed) + + + + + YACReaderSideBar + + + LIBRARIES + + + + + FOLDERS + + + + + Search folders and comics + + + + diff --git a/YACReaderLibrary/yacreaderlibrary_tr.ts b/YACReaderLibrary/yacreaderlibrary_tr.ts new file mode 100644 index 00000000..06761ae6 --- /dev/null +++ b/YACReaderLibrary/yacreaderlibrary_tr.ts @@ -0,0 +1,1308 @@ + + + + + AddLibraryDialog + + Add + Ekle + + + Add an existing library + Kütüphaneye ekle + + + Cancel + Vazgeç + + + Comics folder : + Çizfi roman dosyası : + + + Library Name : + Kütüphane adı : + + + + ComicVineDialog + + skip + + + + back + + + + next + + + + search + + + + close + + + + Looking for volume... + + + + comic %1 of %2 - %3 + + + + %1 comics selected + + + + Error connecting to ComicVine + + + + unknown error + + + + Retrieving tags for : %1 + + + + Retrieving volume info... + + + + Looking for comic... + + + + + CreateLibraryDialog + + Create new library + Yeni kütüphane oluÅŸtur + + + Cancel + Vazgeç + + + Create + OluÅŸtur + + + Create a library could take several minutes. You can stop the process and update the library later for completing the task. + Yeni kütüphanenin oluÅŸturulması birkaç dakika sürecek. + + + The selected path does not exist or is not a valid path. Be sure that you have write access to this folder + Seçilen dizine yazma iznimiz yok yazma izni olduÄŸundan emin ol + + + Comics folder : + Çizgi dosyası: + + + Library Name : + Kütüphane adı: + + + Path not found + Dizin bulunamadı + + + + ExportComicsInfoDialog + + Output file : + Çıkış dosyası : + + + Destination database name + Hedef adı + + + Cancel + Vazgeç + + + Create + OluÅŸtur + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Seçilen dizine yazma iznimiz yok yazma izni olduÄŸundan emin ol + + + Export comics info + Çizgi roman bilgilerini göster + + + Problem found while writing + Yazma sırasında bir problem oldu + + + + ExportLibraryDialog + + Cancel + Vazgeç + + + Create + Yeni bir tane yap + + + The selected path for the output file does not exist or is not a valid path. Be sure that you have write access to this folder + Seçilen konuma yeni bir kütüphane yazılamıyor + + + Output folder : + Çıkış klasörü: + + + Problem found while writing + Yazım aÅŸamasında bir problem bulundu + + + Create covers package + Kapak paketi oluÅŸtur + + + Destination directory + Hedef dizin + + + + FileComic + + File not found or not images in file + Dosya bulunamadı yada dosyada resim yok + + + 7z not found + 7z bulunamadı + + + Comic not found + Çizgi roman bulunamadı + + + Not found + Bulunamadı + + + File error + Dosya hatası + + + 7z problem + 7z Problemli + + + 7z reading + 7z Okuyor + + + 7z crashed. + 7z BozulmuÅŸ. + + + problem reading from 7z + 7z Dosyası Okunamıyor + + + 7z crashed + 7z BozulmuÅŸ + + + Unknown error 7z + Bilinmeyen 7z hatası + + + 7z wasn't found in your PATH. + 7z Dosya Yolu Bulunamadı. + + + CRC error on page (%1): some of the pages will not be displayed correctly + + + + Unknown error opening the file + + + + Format not supported + + + + + HelpAboutDialog + + Help + Yardım + + + About + Hakkında + + + + ImportComicsInfoDialog + + Cancel + Vazgeç + + + Import + Çıkart + + + Info database location : + Bilgi konumu : + + + Import comics info + Çizgi roman bilgilerini çıkart + + + Comics info file (*.ydb) + +Çizgi Roman bilgileri (*.ydb) + + + + ImportLibraryDialog + + Destination folder : + Hedef klasör: + + + Cancel + Vazgeç + + + Unpack + Paketten çıkar + + + Compresed library covers (*.clc) + Sıkıştırılmış kütüphane kapakları (*.clc) + + + Package location : + Paket konumu: + + + Library Name : + Kütüphane Adı : + + + Extract a catalog + Catalog'a çıkart + + + + ImportWidget + + stop + dur + + + Importing comics + önemli çizgi romanlar + + + <p>YACReaderLibrary is now creating a new library.</p><p>Create a library could take several minutes. You can stop the process and update the library later for completing the task.</p> + <p>YACReaderKütüphane ÅŸu anda yeni bir kütüphane oluÅŸturuyor</p><p>Kütüphanenin oluÅŸturulması birkaç dakika alacak.</p> + + + Some of the comics being added... + Bazı çizgi romanlar önceden eklenmiÅŸ... + + + Updating the library + Kütüphaneyi güncelle + + + <p>The current library is being updated. For faster updates, please, update your libraries frequently.</p><p>You can stop the process and continue updating this library later.</p> + <p>Kütüphane güncelleniyor</p><p>Güncellemeyi daha sonra iptal edebilirsin.</p> + + + + LibraryWindow + + + + + + + + - + - + + + Edit + Düzenle + + + The selected folder doesn't contain any library. + Seçilen dosya kütüphanede yok. + + + This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now? + Bu kütüphane YACReaderKütüphabenin bir önceki versiyonun oluÅŸturulmuÅŸ, güncellemeye ihtiyacın var. Åžimdi güncellemek ister misin ? + + + <font color='white'> press 'F' to close fullscreen mode </font> + <font color='white'> 'F'ye basarak tam ekran modundan çıkabilirsin </font> + + + Asign current order to comics + Asignar el orden actual a los cómics + + + Error opening the library + Haa kütüphanesini aç + + + Show/Hide marks + Altçizgileri aç/kapa + + + Show comics server options dialog + Çizgi romanların server ayarlarını göster + + + Remove current library from your collection + Kütüphaneyi koleksiyonundan kaldır + + + Set comic as read + Çizgi romanı okundu olarak iÅŸaretle + + + Remove and delete metadata + Metadata'yı kaldır ve sil + + + Old library + Eski kütüphane + + + Update cover + Kapağı güncelle + + + Library + Kütüphane + + + Rename current library + Kütüphaneyi adlandır + + + Fullscreen mode on/off + Tam ekran modu açık/kapalı + + + This library was created with a newer version of YACReaderLibrary. Download the new version now? + Bu kütüphane YACRKütüphanenin üst bir versiyonunda oluÅŸturulmu. Yeni versiyonu indirmek ister misiniz ? + + + + Open current comic on YACReader + YACReader'ı geçerli çizgi roman okuyucsu seç + + + Update current library + Kütüphaneyi güncelle + + + Library '%1' is no longer available. Do you want to remove it? + Kütüphane '%1'ulaşılabilir deÄŸil. Kaldırmak ister misin? + + + Update library + Kütüphaneyi güncelle + + + Open folder... + Dosyayı aç... + + + Do you want remove + Kaldırmak ister misin + + + Error updating the library + Kütüphane güncelleme sorunu + + + Hide comic flow + Çizgi roman akışını gizle + + + Expand all nodes + Tüm düğümleri büyüt + + + Library '%1' has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now? + Kütüphane '%1 YACRKütüphanenin eski bir sürümünde oluÅŸturulmuÅŸ, Kütüphaneyi yeniden oluÅŸturmak ister misin? + + + There was a problem saving YACReaderLibrary libraries file. Please, check if you have enough permissions in the YACReader root folder. + YACRKütüphane kütüphane dosyaları kaydedilirken bir sorun çıktı. Lütfen, YACReader root dosyalarını kontrol edin. + + + Pack covers + Paket kapakları + + + Set as read + Okundu olarak iÅŸaretle + + + Fullscreen mode on/off (F) + Tam ekran modunu aç/kapa(F) + + + Saving libraries file.... + Kütüphane dosyalarını kaydet... + + + Asign comics numbers + Çizgi roman numaralarını deÄŸiÅŸtir + + + Delete selected comics + Seçili çizgi romanları sil + + + Export comics info + Çizgi roman bilgilerini çıkart + + + Show options dialog + Ayarları göster + + + Create a new library + Yeni kütüphane oluÅŸtur + + + Library not available + Kütüphane ulaşılabilir deÄŸil + + + Import comics info + Çizgi roman bilgilerini içe aktar + + + The current library can't be udpated. Check for write write permissions on: + Kütüphane güncellenmemiÅŸ. Lütfen yazım izinlerini kontrol et: + + + Open current comic + Seçili çizgi romanı aç + + + Colapse all nodes + Tüm düğümleri daralt + + + YACReader Library + YACReader Kütüphane + + + Error creating the library + Kütüphane oluÅŸturma sorunu + + + Update failed + Güncelleme baÅŸarısız + + + Unpack covers + Kapakları aç + + + Update needed + Güncelleme gerekli + + + Open an existing library + Çıkış kütüphanesini aç + + + Library name already exists + Kütüphane ismi zaten alınmış + + + There is another library with the name '%1'. + Bu baÅŸka bir kütüphanenin adı '%1'. + + + Asign numbers starting in: + BaÅŸlangıç sayılarını düzenle: + + + Download new version + Yeni versiyonu indir + + + Delete comics + Çizgi romanları sil + + + Show or hide readed marks + OkunmuÅŸ iÅŸaretleri göster yada gizle + + + Select all comics + Tüm çizgi romanları seç + + + Set all comics as read + Tüm çizgi romanları okundu olarak ayarla + + + Pack the covers of the selected library + Kütüphanede ki kapakları paketle + + + Help, About YACReader + Yardım, Bigli, YACReader + + + Set comic as unread + Çizgi Romanı okunmadı olarak seç + + + Select root node + Kökü seçin + + + Unpack a catalog + KataloÄŸu çkart + + + All the selected comics will be deleted from your disk. Are you sure? + Seçilen tüm çizgi romanlar diskten silinecek emin misin ? + + + Set all as read + Hepsini okundu iÅŸaretle + + + Set as unread + Hepsini okunmadı iÅŸaretle + + + Library not found + Kütüphane bulunamadı + + + Rename library + Kütüphaneyi yeniden adlandır + + + Remove library + Kütüphaneyi sil + + + Open containing folder... + Klasör açılıyor... + + + Set all comics as unread + Tüm çizgiromanları okunmadı olarak iÅŸaretle + + + library? + kütüphane? + + + Set all as unread + Hepsini okunmadı olarak ayarla + + + Are you sure? + Emin misin? + + + Download tags from Comic Vine + + + + YACReader not found + + + + YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary. + + + + Unable to delete + + + + There was an issue trying to delete the selected comics. Please, check for write permissions in the selected files or containing folder. + + + + Set as uncompleted + + + + Set as completed + + + + Reset comic rating + + + + Folder + + + + Comic + + + + + LocalComicListModel + + file name + + + + + NoLibrariesWidget + + create your first library + İlk kütüphaneni oluÅŸtur + + + You don't have any librarires yet + Henüz bir kütüphaneye sahip deÄŸilsin + + + <p>You can create a library in any folder, YACReaderLibrary will import all comics and folders from this folder. If you have created any library in the past you can open them.</p><p>Don't forget that you can use YACReader as a stand alone application for reading the comics on your computer.</p> + <p>Yeni bir kütüphane oluÅŸturabilmeniçin kütüphane</p><p>No olvides que puedes usar YACReader como una aplicación independiente para leer los cómics en tu ordenador.</p> + + + add an existing one + Var olan bir tane ekle + + + + OptionsDialog + + Options + Ayarlar + + + + PropertiesDialog + + Day: + Gün: + + + Plot + Argumento + + + Size: + Boyut: + + + Year: + Yıl: + + + Inker(s): + Mürekkep(ler): + + + Publishing + Yayın + + + Publisher: + Yayıncı: + + + General info + Genel bilgi + + + Color/BW: + Renk/BW: + + + Edit selected comics information + Seçilen çizgi roman bilgilerini düzenle + + + Penciller(s): + Çizenler: + + + Colorist(s): + Renklendiren: + + + Issue number: + Yayın numarası: + + + Month: + Ay: + + + Notes: + Notlar: + + + Synopsis: + Özet: + + + Title: + BaÅŸlık: + + + Not found + Bulunamad + + + Characters: + Karakterler: + + + Authors + Yazarlar + + + Age rating: + YaÅŸ sınırı: + + + Story arc: + Hiakye: + + + Writer(s): + Yazarlar: + + + Comic not found. You should update your library. + Çizgi roman bulunamadı. Kütüphaneyi güncellemelisin. + + + Edit comic information + Çizgi roman bilgisini düzenle + + + Cover page + Kapak sayfası + + + Cover Artist(s): + Kapak artisti: + + + Volume: + Cilt: + + + Format: + Formato: + + + Genere: + Tür: + + + Letterer(s): + Mesaj(lar): + + + Comic Vine link: <a style='color: #FFCB00; text-decoration:none; font-weight:bold;' href="http://www.comicvine.com/comic/4000-%1/"> view </a> + + + + + QObject + + 7z lib not found + + + + unable to load 7z lib from ./utils + + + + + RenameLibraryDialog + + Rename current library + Kütüphaneyi yeniden adlandır + + + Cancel + Vazgeç + + + Rename + Yeniden adlandır + + + New Library Name : + Yeni Kütüphane Adı : + + + + ScraperResultsPaginator + + Number of volumes found : %1 + + + + page %1 of %2 + + + + Number of %1 found : %2 + + + + + SearchSingleComic + + Please provide some additional information. + + + + Series: + + + + + SearchVolume + + Please provide some additional information. + + + + Series: + + + + + SelectComic + + Please, select the right comic info. + + + + comics + + + + loading cover + + + + loading description + + + + description unavailable + + + + + SelectVolume + + Please, select the right series for your comic. + + + + volumes + + + + loading cover + + + + loading description + + + + description unavailable + + + + + SeriesQuestion + + You are trying to get information for various comics at once, are they part of the same series? + + + + yes + evet + + + no + hayır + + + + ServerConfigDialog + + Port + Port + + + EASY SERVER CONNECTION + KOLAY SERVER BAÄžLANTISI + + + just scan the code with your device!! + Sadece kodu cihaza tarat !! + + + enable the server + eriÅŸilebilir server + + + IP address + IP adres + + + YACReader is now available for iOS devices, the best comic reading experience now in your iPad, iPhone or iPod touch. <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> Discover it! </a> + YACReader ÅŸimdi iOS cihazlarda Hemen iPad, iPhone veya iPod Touch'ına kapmak için tıkla (Çevirisi yapılmayacak) <a href='http://ios.yacreader.com' style='color:rgb(193, 148, 65)'> ¡Descúbrelo! </a> + + + QR generator error! + QR kod oluÅŸturma hatası! + + + set port + Port Ayarla + + + SERVER ADDRESS + Server Adres + + + + SortVolumeComics + + Please, sort the list of comics on the left until it matches the comics' information. + + + + sort comics to match comic information + + + + issues + + + + remove selected comics + + + + restore all removed comics + + + + restore removed comics + + + + + TableModel + + no + hayır + + + yes + evet + + + Read + Oku + + + Size + Boyut + + + Pages + Sayfalar + + + Title + BaÅŸlık + + + File Name + Dosya Adı + + + Current Page + + + + Rating + + + + + TitleHeader + + SEARCH + + + + + UpdateLibraryDialog + + Update library + Kütüphaneyi güncelle + + + Cancel + Vazgeç + + + Updating.... + Güncelleniyor... + + + + VolumeComicsModel + + title + + + + + VolumesModel + + year + + + + issues + + + + publisher + + + + + YACReaderDeletingProgress + + cancel + vazgeç + + + Please wait, deleting in progress... + Lütfen bekleyin, silme iÅŸlemi yapılıyor... + + + + YACReaderFieldEdit + + Restore to default + Varsayılana dön + + + Click to overwrite + Üstüne yazmak için tıkla + + + + YACReaderFieldPlainTextEdit + + Restore to default + Varsayılana dön + + + Click to overwrite + Üstüne yazmak için tıkla + + + + YACReaderFlowConfigWidget + + CoverFlow look + Kapak akışı görünümü + + + How to show covers: + Kapaklar nasıl gözüksün: + + + Stripe look + Åžerit görünüm + + + Overlapped Stripe look + Çakışan ÅŸerit görünüm + + + + YACReaderGLFlowConfigWidget + + Zoom + Zoom + + + Light + Işık + + + Show advanced settings + Daha fazla ayar göster + + + Roulette look + Rulet görünüm + + + Cover Angle + Kapak Açısı + + + Stripe look + Strip görünüm + + + Position + Pozisyon + + + Z offset + Z dengesi + + + Y offset + Y dengesi + + + Central gap + BoÅŸ merkez + + + Presets: + Hazırlayan: + + + Overlapped Stripe look + Çakışan ÅŸerit görünüm + + + Modern look + Modern görünüm + + + View angle + Bakış açısı + + + Max angle + Maksimum açı + + + Custom: + KiÅŸisel: + + + Classic look + Klasik görünüm + + + Cover gap + Kapak + + + High Performance + Yüksek Performans + + + Performance: + Performans: + + + Use VSync (improve the image quality in fullscreen mode, worse performance) + VSync kullan + + + Visibility + Görünülebilirlik + + + Low Performance + Düşük Performans + + + + YACReaderOptionsDialog + + Save + Kaydet + + + Use hardware acceleration (restart needed) + Yüksek donanımlı kullan (yeniden baÅŸlatmak gerekli) + + + Cancel + Vazgeç + + + + YACReaderSideBar + + Search folders and comics + Klasörleri ve çizgi romanları ara + + + LIBRARIES + KÜTÜPHANELER + + + FOLDERS + DOSYALAR + + + + YACReaderSocialDialog + + I am reading %1 using YACReader. + YACReader ile okuyorum %1. + + + send to: + Gönder: + + + Follow YACReader! + YACReader'ı takip et ! + + + diff --git a/background.png b/background.png new file mode 100755 index 00000000..b9a7e42e Binary files /dev/null and b/background.png differ diff --git a/cleanOSX.sh b/cleanOSX.sh new file mode 100755 index 00000000..0e55aa9e --- /dev/null +++ b/cleanOSX.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +rm -R *.app +rm -R YACReader-* +rm -R *.dmg +cd YACReader +make clean +rm -R YACReader.app +cd .. +cd YACReaderLibrary +make clean +rm -R YACReaderLibrary.app +cd .. diff --git a/common/bookmarks.cpp b/common/bookmarks.cpp new file mode 100644 index 00000000..d60d8b60 --- /dev/null +++ b/common/bookmarks.cpp @@ -0,0 +1,174 @@ +#include "bookmarks.h" +#include +#include +#include +#include + +#include +#include + +#include "yacreader_global.h" + +Bookmarks::Bookmarks() +:lastPageIndex(0) +{ + list.load(); +} +void Bookmarks::setLastPage(int index,const QImage & page) +{ + lastPageIndex = index; + lastPage = page; +} +void Bookmarks::setBookmark(int index,const QImage & page) +{ + if(!bookmarks.contains(index)) + { + bookmarks.insert(index,page); + latestBookmarks.push_front(index); + if(latestBookmarks.count()>3) + { + bookmarks.remove(latestBookmarks.back()); + latestBookmarks.pop_back(); + } + } + else //udate de pixmap; + { + bookmarks[index]=page; + } +} + +void Bookmarks::removeBookmark(int index) +{ + bookmarks.remove(index); +} + +QList Bookmarks::getBookmarkPages() const +{ + return bookmarks.keys(); +} + +QImage Bookmarks::getBookmarkPixmap(int page) const +{ + return bookmarks.value(page); +} + +QImage Bookmarks::getLastPagePixmap() const +{ + return lastPage; +} + +int Bookmarks::getLastPage() const +{ + return lastPageIndex; +} + + +bool Bookmarks::isBookmark(int page) +{ + return bookmarks.contains(page); +} + +bool Bookmarks::imageLoaded(int page) +{ + return !bookmarks.value(page).isNull(); +} + +void Bookmarks::newComic(const QString & path) +{ + QFileInfo f(path); + QString comicID = f.fileName().toLower()+QString::number(f.size()); + clear(); + BookmarksList::Bookmark b = list.get(comicID); + comicPath=comicID; + lastPageIndex = b.lastPage; + latestBookmarks = b.bookmarks; + for(int i=0;i & bookmarkIndexes, int lastPage) +{ + lastPageIndex = lastPage; + foreach(int b, bookmarkIndexes) + if(b != -1) + { + latestBookmarks.push_back(b); + bookmarks.insert(b,QImage()); + } + + return true; +} + +void Bookmarks::save() +{ + BookmarksList::Bookmark b; + b.lastPage = lastPageIndex; + b.bookmarks = getBookmarkPages(); + + BookmarksList::Bookmark previousBookmarks; + bool updated = ((previousBookmarks.lastPage != b.lastPage) || (previousBookmarks.bookmarks != b.bookmarks)); + + if(b.added.isNull() || updated) + b.added = QDateTime::currentDateTime(); + list.add(comicPath,b); + list.save(); +} +//----------------------------------------------------------------------------- +void BookmarksList::load() +{ + QFile f(YACReader::getSettingsPath()+"/bookmarks.yacr"); + if(f.open(QIODevice::ReadOnly)) + { + QDataStream dataS(&f); + dataS >> list; + f.close(); + } +} + +void BookmarksList::save() +{ + QFile f(YACReader::getSettingsPath()+"/bookmarks.yacr"); + f.open(QIODevice::WriteOnly); + QDataStream dataS(&f); + if(list.count()>numMaxBookmarks) + deleteOldest(list.count()-numMaxBookmarks); + dataS << list; + f.close(); +} + + +void BookmarksList::deleteOldest(int num) +{ + Q_UNUSED(num) + QString comic; + QDateTime date(QDate(10000,1,1));//TODO MAX_DATE?? + for(QMap::const_iterator itr=list.begin();itr!=list.end();itr++) + { + if(itr->addedadded; + } + } + list.remove(comic); +} + +void BookmarksList::add(const QString & comicID, const Bookmark & b) +{ + list.insert(comicID,b); +} + +BookmarksList::Bookmark BookmarksList::get(const QString & comicID) +{ + //if(list.contains(comicID) + return list.value(comicID); +} diff --git a/common/bookmarks.h b/common/bookmarks.h new file mode 100644 index 00000000..e7d3c43b --- /dev/null +++ b/common/bookmarks.h @@ -0,0 +1,80 @@ +#ifndef BOOKMARKS_H +#define BOOKMARKS_H + +#include +#include +#include +#include +#include +#include +class BookmarksList +{ +public: + struct Bookmark { + int lastPage; + QList bookmarks; + QDateTime added; + Bookmark():lastPage(0){}; + friend QDataStream & operator<< ( QDataStream & out, const Bookmark & bm ) + { + out << bm.lastPage; + out << bm.bookmarks; + out << bm.added; + return out; + } + friend QDataStream & operator>> ( QDataStream & in, Bookmark & bm ) + { + in >> bm.lastPage; + in >> bm.bookmarks; + in >> bm.added; + return in; + } + + }; + BookmarksList():numMaxBookmarks(400){} + void load(); + void save(); + void add(const QString & comicID, const Bookmark & b); + Bookmark get(const QString & comicID); +protected: + QMap list; + void deleteOldest(int num); +private: + int numMaxBookmarks; + +}; + +class Bookmarks : public QObject +{ + Q_OBJECT + + protected: + QString comicPath; + //bookmarks setted by the user + QMap bookmarks; + QList latestBookmarks; + //last page readed + int lastPageIndex; + QImage lastPage; + BookmarksList list; + QDateTime added; + + public: + Bookmarks(); + void setLastPage(int index,const QImage & page); + void setBookmark(int index,const QImage & page); + void removeBookmark(int index); + QList getBookmarkPages() const; + QImage getBookmarkPixmap(int page) const; + QImage getLastPagePixmap() const; + int getLastPage() const; + bool isBookmark(int page); + bool imageLoaded(int page); + void newComic(const QString & path); + void clear(); + void save(); + bool load(const QList & bookmarkIndexes, int lastPage); + +}; + +#endif // BOOKMARKS_H diff --git a/common/check_new_version.cpp b/common/check_new_version.cpp new file mode 100644 index 00000000..6454c980 --- /dev/null +++ b/common/check_new_version.cpp @@ -0,0 +1,84 @@ +#include "check_new_version.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define PREVIOUS_VERSION "6.0.0" + +HttpVersionChecker::HttpVersionChecker() + :HttpWorker("https://bitbucket.org/luisangelsm/yacreader/wiki/Home") +{ + connect(this,SIGNAL(dataReady(const QByteArray &)),this,SLOT(checkNewVersion(const QByteArray &))); +} + +void HttpVersionChecker::checkNewVersion(const QByteArray & data) +{ + checkNewVersion(QString(data)); +} + +bool HttpVersionChecker::checkNewVersion(QString sourceContent) +{ +#ifdef Q_OS_WIN32 + QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}win32.*"); +#endif + +#if defined Q_OS_UNIX && !defined Q_OS_MAC + QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}X11.*"); +#endif + +#ifdef Q_OS_MAC + QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}Mac.*"); +#endif + + int index = 0; + bool newVersion = false; + bool sameVersion = true; + //bool currentVersionIsNewer = false; +#ifdef QT_DEBUG + QString version(PREVIOUS_VERSION); +#else + QString version(VERSION); +#endif + QStringList sl = version.split("."); + if((index = rx.indexIn(sourceContent))!=-1) + { + int length = qMin(sl.size(),(rx.cap(4)!="")?4:3); + for(int i=0;isl.at(i).toInt()){ + newVersion=true; + break; + } + else + sameVersion = sameVersion && rx.cap(i+1).toInt()==sl.at(i).toInt(); + } + if(!newVersion && sameVersion) + { + if((sl.size()==3)&&(rx.cap(4)!="")) + newVersion = true; + } + + + } + + if(newVersion == true) + { + emit newVersionDetected(); + return true; + } + else + { + return false; + } +} diff --git a/common/check_new_version.h b/common/check_new_version.h new file mode 100644 index 00000000..5c5e2fb5 --- /dev/null +++ b/common/check_new_version.h @@ -0,0 +1,27 @@ +#ifndef __CHECKUPDATE_H +#define __CHECKUPDATE_H + +#include "http_worker.h" +#include "yacreader_global.h" + +#include +#include +#include + + class HttpVersionChecker : public HttpWorker + { + Q_OBJECT + public: + HttpVersionChecker(); + public slots: + + private: + bool found; + private slots: + bool checkNewVersion(QString sourceContent); + void checkNewVersion(const QByteArray & data); + signals: + void newVersionDetected(); + }; + +#endif diff --git a/common/comic.cpp b/common/comic.cpp new file mode 100644 index 00000000..9a148cda --- /dev/null +++ b/common/comic.cpp @@ -0,0 +1,827 @@ + #include "comic.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "bookmarks.h" //TODO desacoplar la dependencia con bookmarks +#include "qnaturalsorting.h" +#include "compressed_archive.h" +#include "comic_db.h" + +#include "QsLog.h" + +const QStringList Comic::imageExtensions = QStringList() << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp" << "*.webp"; +const QStringList Comic::literalImageExtensions = QStringList() << "jpg" << "jpeg" << "png" << "gif" << "tiff" << "tif" << "bmp" << "webp"; + +#ifndef use_unarr +const QStringList Comic::comicExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.7z" << "*.cb7" << "*.arj" << "*.cbt"; +const QStringList Comic::literalComicExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "7z" << "cb7" << "arj" << "cbt"; +#else +const QStringList Comic::comicExtensions = QStringList() << "*.cbr" << "*.cbz" << "*.rar" << "*.zip" << "*.tar" << "*.pdf" << "*.cbt"; +const QStringList Comic::literalComicExtensions = QStringList() << "cbr" << "cbz" << "rar" << "zip" << "tar" << "pdf" << "cbt"; +#endif +//----------------------------------------------------------------------------- +Comic::Comic() +:_pages(),_index(0),_path(),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false) +{ + setup(); +} +//----------------------------------------------------------------------------- +Comic::Comic(const QString & pathFile, int atPage ) +:_pages(),_index(0),_path(pathFile),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false),_firstPage(atPage) +{ + setup(); +} +//----------------------------------------------------------------------------- +Comic::~Comic() +{ + delete bm; +} +//----------------------------------------------------------------------------- +void Comic::setup() +{ + connect(this,SIGNAL(pageChanged(int)),this,SLOT(checkIsBookmark(int))); + connect(this,SIGNAL(imageLoaded(int)),this,SLOT(updateBookmarkImage(int))); + connect(this,SIGNAL(imageLoaded(int)),this,SLOT(setPageLoaded(int))); +} +//----------------------------------------------------------------------------- +int Comic::nextPage() +{ + if(_index<_pages.size()-1) + { + _index++; + + emit pageChanged(_index); + } + else + emit isLast(); + return _index; +} +//--------------------------------------------------------------------------- +int Comic::previousPage() +{ + if(_index>0) + { + _index--; + + emit pageChanged(_index); + } + else + emit isCover(); + + return _index; +} +//----------------------------------------------------------------------------- +void Comic::setIndex(unsigned int index) +{ + int previousIndex = _index; + if(static_cast(index)<_pages.size()-1) + _index = index; + else + _index = _pages.size()-1; + + if(previousIndex != _index) + emit pageChanged(_index); +} +//----------------------------------------------------------------------------- +/*QPixmap * Comic::currentPage() +{ + QPixmap * p = new QPixmap(); + p->loadFromData(_pages[_index]); + return p; +} +//----------------------------------------------------------------------------- +QPixmap * Comic::operator[](unsigned int index) +{ + QPixmap * p = new QPixmap(); + p->loadFromData(_pages[index]); + return p; +}*/ +bool Comic::load(const QString & path, const ComicDB & comic) +{ + Q_UNUSED(path); + Q_UNUSED(comic); + return false; +}; +//----------------------------------------------------------------------------- +bool Comic::loaded() +{ + return _loaded; +} +//----------------------------------------------------------------------------- +void Comic::loadFinished() +{ + emit imagesLoaded(); +} +//----------------------------------------------------------------------------- +void Comic::setBookmark() +{ + QImage p; + p.loadFromData(_pages[_index]); + bm->setBookmark(_index,p); + //emit bookmarksLoaded(*bm); + emit bookmarksUpdated(); +} +//----------------------------------------------------------------------------- +void Comic::removeBookmark() +{ + bm->removeBookmark(_index); + //emit bookmarksLoaded(*bm); + emit bookmarksUpdated(); +} +//----------------------------------------------------------------------------- +void Comic::saveBookmarks() +{ + QImage p; + p.loadFromData(_pages[_index]); + bm->setLastPage(_index,p); + bm->save(); +} +//----------------------------------------------------------------------------- +void Comic::checkIsBookmark(int index) +{ + emit isBookmark(bm->isBookmark(index)); +} +//----------------------------------------------------------------------------- +void Comic::updateBookmarkImage(int index) +{ + if(bm->isBookmark(index)) + { + QImage p; + p.loadFromData(_pages[index]); + bm->setBookmark(index,p); + emit bookmarksUpdated(); + //emit bookmarksLoaded(*bm); + + } + if(bm->getLastPage() == index) + { + QImage p; + p.loadFromData(_pages[index]); + bm->setLastPage(index,p); + emit bookmarksUpdated(); + //emit bookmarksLoaded(*bm); + } + +} +//----------------------------------------------------------------------------- +void Comic::setPageLoaded(int page) +{ + _loadedPages[page] = true; +} +//----------------------------------------------------------------------------- +QByteArray Comic::getRawPage(int page) +{ + if(page < 0 || page >= _pages.size()) + return QByteArray(); + return _pages[page]; +} +//----------------------------------------------------------------------------- +bool Comic::pageIsLoaded(int page) +{ + if(page < 0 || page >= _pages.size()) + return false; + return _loadedPages[page]; +} + +bool Comic::fileIsComic(const QString &path) +{ + QFileInfo info(path); + return literalComicExtensions.contains(info.suffix()); +} + +QList Comic::findValidComicFiles(const QList &list) +{ + QLOG_DEBUG() << "-findValidComicFiles-"; + QList validComicFiles; + QString currentPath; + foreach (QUrl url, list) { + currentPath = url.toLocalFile(); + if(Comic::fileIsComic(currentPath)) + validComicFiles << currentPath; + else if(QFileInfo(currentPath).isDir()) + { + validComicFiles << findValidComicFilesInFolder(currentPath); + } + } + QLOG_DEBUG() << "-" << validComicFiles << "-"; + return validComicFiles; +} + +QList Comic::findValidComicFilesInFolder(const QString &path) +{ + QLOG_DEBUG() << "-findValidComicFilesInFolder-" << path; + + if(!QFileInfo(path).isDir()) + return QList(); + + QList validComicFiles; + QDir folder(path); + folder.setNameFilters(Comic::comicExtensions); + folder.setFilter(QDir::AllDirs|QDir::Files|QDir::NoDotAndDotDot); + QFileInfoList folderContent = folder.entryInfoList(); + + QString currentPath; + foreach (QFileInfo info, folderContent) { + currentPath = info.absoluteFilePath(); + if(info.isDir()) + validComicFiles << findValidComicFilesInFolder(currentPath); //find comics recursively + else if(Comic::fileIsComic(currentPath)) + { + validComicFiles << currentPath; + } + } + + return validComicFiles; +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +FileComic::FileComic() + :Comic() +{ + +} + +FileComic::FileComic(const QString & path, int atPage ) + :Comic(path,atPage) +{ + load(path,atPage); +} + +FileComic::~FileComic() +{ + _pages.clear(); + _loadedPages.clear(); + _fileNames.clear(); + _newOrder.clear(); + _order.clear(); +} + +bool FileComic::load(const QString & path, int atPage) +{ + QFileInfo fi(path); + + if(fi.exists()) + { + if(atPage == -1) + { + bm->newComic(path); + emit bookmarksUpdated(); + } + _firstPage = atPage; + //emit bookmarksLoaded(*bm); + + _path = QDir::cleanPath(path); + //load files size + + return true; + } + else + { + //QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path); + emit errorOpening(); + return false; + } +} + +bool FileComic::load(const QString & path, const ComicDB & comic) +{ + QFileInfo fi(path); + + if(fi.exists()) + { + QList bookmarkIndexes; + bookmarkIndexes << comic.info.bookmark1 << comic.info.bookmark2 << comic.info.bookmark3; + if(bm->load(bookmarkIndexes,comic.info.currentPage-1)) + emit bookmarksUpdated(); + _firstPage = comic.info.currentPage-1; + _path = QDir::cleanPath(path); + return true; + } + else + { + //QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path); + moveToThread(QApplication::instance()->thread()); + emit errorOpening(); + return false; + } +} + +QList FileComic::filter(const QList & src) +{ + QList extensions = getSupportedImageLiteralFormats(); + QList filtered; + bool fileAccepted = false; + + foreach(QString fileName,src) + { + fileAccepted = false; + if(!fileName.contains("__MACOSX")) + { + foreach(QString extension,extensions) + { + if(fileName.endsWith(extension,Qt::CaseInsensitive)) + { + fileAccepted = true; + break; + } + } + } + if(fileAccepted) + filtered.append(fileName); + } + + return filtered; +} + +//DELEGATE methods +void FileComic::fileExtracted(int index, const QByteArray & rawData) +{ + /*QFile f("c:/temp/out2.txt"); + f.open(QIODevice::Append); + QTextStream out(&f);*/ + int sortedIndex = _fileNames.indexOf(_order.at(index)); + //out << sortedIndex << " , "; + //f.close(); + if(sortedIndex == -1) + return; + _pages[sortedIndex] = rawData; + emit imageLoaded(sortedIndex); + emit imageLoaded(sortedIndex,_pages[sortedIndex]); +} + +void FileComic::crcError(int index) +{ + emit crcErrorFound(tr("CRC error on page (%1): some of the pages will not be displayed correctly").arg(index+1)); +} + +//TODO: comprobar que si se produce uno de estos errores, la carga del c�mic es irrecuperable +void FileComic::unknownError(int index) +{ + Q_UNUSED(index) + emit errorOpening(tr("Unknown error opening the file")); + //emit errorOpening(); +} + +//-------------------------------------- + +QList > FileComic::getSections(int & sectionIndex) +{ + QVector sortedIndexes; + foreach(QString name, _fileNames) + { + sortedIndexes.append(_order.indexOf(name)); + } + QList > sections; + quint32 previous = 0; + sectionIndex = -1; + int sectionCount = 0; + QVector section; + int idx = 0; + unsigned int realIdx; + foreach(quint32 i, sortedIndexes) + { + + if(_firstPage == idx) + { + sectionIndex = sectionCount; + realIdx = i; + } + if(previous <= i) + { + //out << "idx : " << i << endl; + section.append(i); + previous = i; + } + else + { + if(sectionIndex == sectionCount) //found + { + if(section.indexOf(realIdx)!=0) + { + QVector section1; + QVector section2; + foreach(quint32 si,section) + { + if(si (); + //out << "---------------" << endl; + section.append(i); + //out << "idx : " << i << endl; + previous = i; + sectionCount++; + } + + idx++; + } + if(sectionIndex == sectionCount) //found + { + if(section.indexOf(realIdx)!=0) + { + QVector section1; + QVector section2; + foreach(quint32 si,section) + { + if(sithread()); + emit errorOpening(tr("7z not found")); + return; + } + + if(!archive.isValid()) + { + moveToThread(QApplication::instance()->thread()); + emit errorOpening(tr("Format not supported")); + return; + } + + //se filtran para obtener s�lo los formatos soportados + _order = archive.getFileNames(); + _fileNames = filter(_order); + + if(_fileNames.size()==0) + { + //QMessageBox::critical(NULL,tr("File error"),tr("File not found or not images in file")); + moveToThread(QApplication::instance()->thread()); + emit errorOpening(); + return; + } + + //TODO, cambiar por listas + //_order = _fileNames; + + _pages.resize(_fileNames.size()); + _loadedPages = QVector(_fileNames.size(),false); + + emit pageChanged(0); // this indicates new comic, index=0 + emit numPages(_pages.size()); + _loaded = true; + + _cfi=0; + qSort(_fileNames.begin(),_fileNames.end(), naturalSortLessThanCI); + + if(_firstPage == -1) + _firstPage = bm->getLastPage(); + + if(_firstPage >= _pages.length()) + _firstPage = 0; + + _index = _firstPage; + emit(openAt(_index)); + + int sectionIndex; + QList > sections = getSections(sectionIndex); + + for(int i = sectionIndex; i(),this); + /* + foreach(QString name,_fileNames) + { + index = _order.indexOf(name); + sortedIndex = _fileNames.indexOf(name); + _pages[sortedIndex] = allData.at(index); + emit imageLoaded(sortedIndex); + emit imageLoaded(sortedIndex,_pages[sortedIndex]); + }*/ + moveToThread(QApplication::instance()->thread()); + emit imagesLoaded(); +} + + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +FolderComic::FolderComic() + :Comic() +{ + +} + +FolderComic::FolderComic(const QString & path, int atPage ) + :Comic(path, atPage ) +{ + load(path, atPage ); +} + +FolderComic::~FolderComic() +{ + +} + +bool FolderComic::load(const QString & path, int atPage ) +{ + _path = path; + if(atPage == -1) + { + bm->newComic(_path); + emit bookmarksUpdated(); + } + _firstPage = atPage; + //emit bookmarksLoaded(*bm); + return true; +} + +void FolderComic::process() +{ + QDir d(_path); + + d.setNameFilters(getSupportedImageFormats()); + d.setFilter(QDir::Files|QDir::NoDotAndDotDot); + //d.setSorting(QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); + QFileInfoList list = d.entryInfoList(); + + qSort(list.begin(),list.end(),naturalSortLessThanCIFileInfo); + + int nPages = list.size(); + _pages.clear(); + _pages.resize(nPages); + _loadedPages = QVector(nPages,false); + + if(nPages==0) + { + //TODO emitir este mensaje en otro sitio + //QMessageBox::critical(NULL,QObject::tr("No images found"),QObject::tr("There are not images on the selected folder")); + moveToThread(QApplication::instance()->thread()); + emit errorOpening(); + } + else + { + if(_firstPage == -1) + _firstPage = bm->getLastPage(); + + if(_firstPage >= _pages.length()) + _firstPage = 0; + + _index = _firstPage; + + emit(openAt(_index)); + + emit pageChanged(0); // this indicates new comic, index=0 + emit numPages(_pages.size()); + _loaded = true; + + int count=0; + int i=_firstPage; + while(countthread()); + emit imagesLoaded(); +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +PDFComic::PDFComic() + :Comic() +{ + +} + +PDFComic::PDFComic(const QString & path, int atPage) + :Comic(path,atPage) +{ + load(path,atPage); +} + +PDFComic::~PDFComic() +{ + +} + +bool PDFComic::load(const QString & path, int atPage) +{ + QFileInfo fi(path); + + if(fi.exists()) + { + _path = path; + if(atPage == -1) + { + bm->newComic(_path); + emit bookmarksUpdated(); + } + _firstPage = atPage; + //emit bookmarksLoaded(*bm); + return true; + } + else + { + moveToThread(QApplication::instance()->thread()); + emit errorOpening(); + return false; + } +} + +bool PDFComic::load(const QString & path, const ComicDB & comic) +{ + QFileInfo fi(path); + + if(fi.exists()) + { + QList bookmarkIndexes; + bookmarkIndexes << comic.info.bookmark1 << comic.info.bookmark2 << comic.info.bookmark3; + if(bm->load(bookmarkIndexes,comic.info.currentPage-1)) + emit bookmarksUpdated(); + _firstPage = comic.info.currentPage-1; + _path = QDir::cleanPath(path); + return true; + } + else + { + //QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path); + moveToThread(QApplication::instance()->thread()); + emit errorOpening(); + return false; + } +} + +void PDFComic::process() +{ +#ifdef Q_OS_MAC + pdfComic = new MacOSXPDFComic(); + if(!pdfComic->openComic(_path)) + { + delete pdfComic; + emit errorOpening(); + return; + } +#else + + + pdfComic = Poppler::Document::load(_path); + if (!pdfComic) + { + //delete pdfComic; + //pdfComic = 0; + moveToThread(QApplication::instance()->thread()); + emit errorOpening(); + return; + } + if (pdfComic->isLocked()) + { + moveToThread(QApplication::instance()->thread()); + emit errorOpening(); + return; + } + + //pdfComic->setRenderHint(Poppler::Document::Antialiasing, true); + pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true); +#endif + + int nPages = pdfComic->numPages(); + emit pageChanged(0); // this indicates new comic, index=0 + emit numPages(nPages); + _loaded = true; + //QMessageBox::critical(NULL,QString("%1").arg(nPages),tr("Invalid PDF file")); + + _pages.clear(); + _pages.resize(nPages); + _loadedPages = QVector(nPages,false); + + if(_firstPage == -1) + _firstPage = bm->getLastPage(); + + if(_firstPage >= _pages.length()) + _firstPage = 0; + + _index = _firstPage; + emit(openAt(_index)); + + //buffer index to avoid race conditions + int buffered_index = _index; + for(int i=buffered_index;ithread()); + emit imagesLoaded(); +} + +void PDFComic::renderPage(int page) +{ +#ifdef Q_OS_MAC + { + QImage img = pdfComic->getPage(page); + if(!img.isNull()) + { + QByteArray ba; + QBuffer buf(&ba); + img.save(&buf, "jpg"); + _pages[page] = ba; + emit imageLoaded(page); + emit imageLoaded(page,_pages[page]); + } + } + pdfComic->releaseLastPageData(); +#else + Poppler::Page* pdfpage = pdfComic->page(page); + if (pdfpage) + { + QImage img = pdfpage->renderToImage(150,150); + delete pdfpage; + QByteArray ba; + QBuffer buf(&ba); + img.save(&buf, "jpg"); + _pages[page] = ba; + emit imageLoaded(page); + emit imageLoaded(page,_pages[page]); + } +#endif +} + +Comic * FactoryComic::newComic(const QString & path) +{ + + QFileInfo fi(path); + if(fi.exists()) + { + if(fi.isFile()) + { + if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0) + return new PDFComic(); + else + return new FileComic(); + } + else + { + if(fi.isDir()) + return new FolderComic(); + else + return NULL; + } + } + else + return NULL; + +} diff --git a/common/comic.h b/common/comic.h new file mode 100644 index 00000000..2f633429 --- /dev/null +++ b/common/comic.h @@ -0,0 +1,182 @@ +#ifndef __COMIC_H +#define __COMIC_H +#include +#include +#include +#include +#include + +#include "extract_delegate.h" + +#include "bookmarks.h" + +#ifdef Q_OS_MAC + +#include "pdf_comic.h" + +#else + +#if QT_VERSION >= 0x050000 + #include "poppler-qt5.h" +#else + #include "poppler-qt4.h" +#endif + +#endif + +class ComicDB; +//#define EXTENSIONS << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp" Comic::getSupportedImageFormats() +//#define EXTENSIONS_LITERAL << ".jpg" << ".jpeg" << ".png" << ".gif" << ".tiff" << ".tif" << ".bmp" //Comic::getSupportedImageLiteralFormats() + class Comic : public QObject + { + Q_OBJECT + protected: + //Comic pages, one QPixmap for each file. + QVector _pages; + QVector _loadedPages; + //QVector _sizes; + QStringList _fileNames; + QMap _newOrder; + QList _order; + int _index; + QString _path; + bool _loaded; + + int _cfi; + + //open the comic at this point + int _firstPage; + + bool _isPDF; + + public: + + static const QStringList imageExtensions; + static const QStringList literalImageExtensions; + static const QStringList comicExtensions; + static const QStringList literalComicExtensions; + + Bookmarks * bm; + + //Constructors + Comic(); + Comic(const QString & pathFile, int atPage = -1); + ~Comic(); + void setup(); + //Load pages from file + virtual bool load(const QString & path, int atPage = -1) = 0; + virtual bool load(const QString & path, const ComicDB & comic); + + /*void loadFromFile(const QString & pathFile); + void loadFromDir(const QString & pathDir); + void loadFromPDF(const QString & pathPDF);*/ + int nextPage(); + int previousPage(); + void setIndex(unsigned int index); + unsigned int getIndex(){return _index;}; + unsigned int numPages(){return _pages.size();} + //QPixmap * currentPage(); + bool loaded(); + //QPixmap * operator[](unsigned int index); + QVector * getRawData(){return &_pages;} + QByteArray getRawPage(int page); + bool pageIsLoaded(int page); + + inline static QStringList getSupportedImageFormats() { return imageExtensions;} + inline static QStringList getSupportedImageLiteralFormats() { return literalImageExtensions;} + + static bool fileIsComic(const QString &path); + static QList findValidComicFiles(const QList & list); + static QList findValidComicFilesInFolder(const QString &path); + public slots: + void loadFinished(); + void setBookmark(); + void removeBookmark(); + void saveBookmarks(); + void checkIsBookmark(int index); + void updateBookmarkImage(int); + void setPageLoaded(int page); + signals: + void imagesLoaded(); + void imageLoaded(int index); + void imageLoaded(int index,const QByteArray & image); + void pageChanged(int index); + void openAt(int index); + void numPages(unsigned int numPages); + void errorOpening(); + void errorOpening(QString); + void crcErrorFound(QString); + void isBookmark(bool); + void bookmarksUpdated(); + void isCover(); + void isLast(); + + }; + + class FileComic : public Comic, public ExtractDelegate + { + Q_OBJECT + private: + QList > getSections(int & sectionIndex); + public: + FileComic(); + FileComic(const QString & path, int atPage = -1); + ~FileComic(); + void fileExtracted(int index, const QByteArray & rawData); + virtual bool load(const QString & path, int atPage = -1); + virtual bool load(const QString & path, const ComicDB & comic); + void crcError(int index); + void unknownError(int index); + static QList filter(const QList & src); + public slots: + void process(); + }; + + class FolderComic : public Comic + { + Q_OBJECT + private: + //void run(); + public: + FolderComic(); + FolderComic(const QString & path, int atPage = -1); + ~FolderComic(); + + virtual bool load(const QString & path, int atPage = -1); + public slots: + void process(); + + }; + + class PDFComic : public Comic + { + Q_OBJECT + private: + //pdf +#ifdef Q_OS_MAC + MacOSXPDFComic * pdfComic; +#else + Poppler::Document * pdfComic; +#endif + void renderPage(int page); + + //void run(); + public: + PDFComic(); + PDFComic(const QString & path, int atPage = -1); + ~PDFComic(); + + virtual bool load(const QString & path, int atPage = -1); + virtual bool load(const QString & path, const ComicDB & comic); + public slots: + void process(); + }; + + class FactoryComic + { + public: + static Comic * newComic(const QString & path); + }; + + +#endif diff --git a/common/comic_db.cpp b/common/comic_db.cpp new file mode 100644 index 00000000..6e92b85a --- /dev/null +++ b/common/comic_db.cpp @@ -0,0 +1,483 @@ +#include "comic_db.h" + +#include +#include + +//----------------------------------------------------------------------------- +//COMIC------------------------------------------------------------------------ +//----------------------------------------------------------------------------- +ComicDB::ComicDB() +{ + +} + +bool ComicDB::isDir() +{ + return false; +} + +QString ComicDB::toTXT() +{ + QString txt; + + //Legacy info + txt.append(QString("comicid:%1\r\n").arg(id)); + txt.append(QString("hash:%1\r\n").arg(info.hash)); + txt.append(QString("path:%1\r\n").arg(path)); + txt.append(QString("numpages:%1\r\n").arg(info.numPages.toString())); + + //new 7.0 + txt.append(QString("rating:%1\r\n").arg(info.rating)); + txt.append(QString("currentPage:%1\r\n").arg(info.currentPage)); + txt.append(QString("contrast:%1\r\n").arg(info.contrast)); + + //Informaci�n general + if(!info.coverPage.isNull()) + txt.append(QString("coverPage:%1\r\n").arg(info.coverPage.toString())); + + if(!info.title.isNull()) + txt.append(QString("title:%1\r\n").arg(info.title.toString())); + + if(!info.number.isNull()) + txt.append(QString("number:%1\r\n").arg(info.number.toString())); + + if(!info.isBis.isNull()) + txt.append(QString("isBis:%1\r\n").arg(info.isBis.toBool()?"1":"0")); + + if(!info.count.isNull()) + txt.append(QString("count:%1\r\n").arg(info.count.toString())); + + if(!info.volume.isNull()) + txt.append(QString("volume:%1\r\n").arg(info.volume.toString())); + + if(!info.storyArc.isNull()) + txt.append(QString("storyArc:%1\r\n").arg(info.storyArc.toString())); + + if(!info.arcNumber.isNull()) + txt.append(QString("arcNumber:%1\r\n").arg(info.arcNumber.toString())); + + if(!info.arcCount.isNull()) + txt.append(QString("arcCount:%1\r\n").arg(info.arcCount.toString())); + + if(!info.genere.isNull()) + txt.append(QString("genere:%1\r\n").arg(info.genere.toString())); + + //Autores + if(!info.writer.isNull()) + txt.append(QString("writer:%1\r\n").arg(info.writer.toString())); + + if(!info.penciller.isNull()) + txt.append(QString("penciller:%1\r\n").arg(info.penciller.toString())); + + if(!info.inker.isNull()) + txt.append(QString("inker:%1\r\n").arg(info.inker.toString())); + + if(!info.colorist.isNull()) + txt.append(QString("colorist:%1\r\n").arg(info.colorist.toString())); + + if(!info.letterer.isNull()) + txt.append(QString("letterer:%1\r\n").arg(info.letterer.toString())); + + if(!info.coverArtist.isNull()) + txt.append(QString("coverArtist:%1\r\n").arg(info.coverArtist.toString())); + //Publicaci�n + if(!info.date.isNull()) + txt.append(QString("date:%1\r\n").arg(info.date.toString())); + + if(!info.publisher.isNull()) + txt.append(QString("publisher:%1\r\n").arg(info.publisher.toString())); + + if(!info.format.isNull()) + txt.append(QString("format:%1\r\n").arg(info.format.toString())); + + if(!info.color.isNull()) + txt.append(QString("color:%1\r\n").arg(info.color.toString())); + + if(!info.ageRating.isNull()) + txt.append(QString("ageRating:%1\r\n").arg(info.ageRating.toString())); + //Argumento + if(!info.synopsis.isNull()) + txt.append(QString("synopsis:%1\r\n").arg(info.synopsis.toString())); + + if(!info.characters.isNull()) + txt.append(QString("characters:%1\r\n").arg(info.characters.toString())); + + if(!info.notes.isNull()) + txt.append(QString("notes:%1\r\n").arg(info.notes.toString())); + + return txt; +} + +QString ComicDB::getFileName() const +{ + return QFileInfo(path).fileName(); +} + +QString ComicDB::getTitleOrFileName() const +{ + if(!info.title.isNull() && info.title.toString().isEmpty()) + return info.title.toString(); + else + return QFileInfo(path).fileName(); +} + +QString ComicDB::getParentFolderName() const +{ + QStringList paths = path.split('/'); + if(paths.length()<2) + return ""; + else + return paths[paths.length()-2]; +} + +qulonglong ComicDB::getFileSize() const +{ + //the size is encoded in the hash after the SHA-1 + return info.hash.right(info.hash.length()-40).toLongLong(); +} + +//----------------------------------------------------------------------------- +//COMIC_INFO------------------------------------------------------------------- +//----------------------------------------------------------------------------- +ComicInfo::ComicInfo() + :existOnDb(false), + rating(0), + hasBeenOpened(false), + currentPage(1), + bookmark1(-1), + bookmark2(-1), + bookmark3(-1), + brightness(-1), + contrast(-1), + gamma(-1) +{ + +} + +ComicInfo::ComicInfo(const ComicInfo & comicInfo) +{ + operator=(comicInfo); +} + +ComicInfo::~ComicInfo() +{ + +} +//the default operator= should work +ComicInfo & ComicInfo::operator=(const ComicInfo & comicInfo) +{ + hash = comicInfo.hash; + id = comicInfo.id; + existOnDb = comicInfo.existOnDb; + read = comicInfo.read; + edited = comicInfo.edited; + + hasBeenOpened = comicInfo.hasBeenOpened; + rating = comicInfo.rating; + currentPage = comicInfo.currentPage; + bookmark1 = comicInfo.bookmark1; + bookmark2 = comicInfo.bookmark2; + bookmark3 = comicInfo.bookmark3; + brightness = comicInfo.brightness; + contrast = comicInfo.contrast; + gamma = comicInfo.gamma; + + title = comicInfo.title; + coverPage = comicInfo.coverPage; + numPages = comicInfo.numPages; + number = comicInfo.number; + isBis = comicInfo.isBis; + count = comicInfo.count; + volume = comicInfo.volume; + storyArc = comicInfo.storyArc; + arcNumber = comicInfo.arcNumber; + arcCount = comicInfo.arcCount; + genere = comicInfo.genere; + writer = comicInfo.writer; + penciller = comicInfo.penciller; + inker = comicInfo.inker; + colorist = comicInfo.colorist; + letterer = comicInfo.letterer; + coverArtist = comicInfo.coverArtist; + date = comicInfo.date; + publisher = comicInfo.publisher; + format = comicInfo.format; + color = comicInfo.color; + ageRating = comicInfo.ageRating; + synopsis = comicInfo.synopsis; + characters = comicInfo.characters; + notes = comicInfo.notes; + comicVineID = comicInfo.comicVineID; + + return *this; +} + +//set fields +/* +void ComicInfo::setTitle(QString value) +{ + setValue(title,value); +} + +void ComicInfo::setCoverPage(int value) +{ + setValue(coverPage,value); +} +void ComicInfo::setNumPages(int value) +{ + setValue(numPages,value); +} + +void ComicInfo::setNumber(int value) +{ + setValue(number,value); +} + +void ComicInfo::setIsBis(bool value) +{ + setValue(isBis,value); +} + +void ComicInfo::setCount(int value) +{ + setValue(count,value); +} + +void ComicInfo::setVolume(QString value) +{ + setValue(volume,value); +} + +void ComicInfo::setStoryArc(QString value) +{ + setValue(storyArc,value); +} + +void ComicInfo::setArcNumber(int value) +{ + setValue(arcNumber,value); +} + +void ComicInfo::setArcCount(int value) +{ + setValue(arcCount,value); +} + +void ComicInfo::setGenere(QString value) +{ + setValue(genere,value); +} + +void ComicInfo::setWriter(QString value) +{ + setValue(writer,value); +} + +void ComicInfo::setPenciller(QString value) +{ + setValue(penciller,value); +} + +void ComicInfo::setInker(QString value) +{ + setValue(inker,value); +} + +void ComicInfo::setColorist(QString value) +{ + setValue(colorist,value); +} + +void ComicInfo::setLetterer(QString value) +{ + setValue(letterer,value); +} + +void ComicInfo::setCoverArtist(QString value) +{ + setValue(coverArtist,value); +} + +void ComicInfo::setDate(QString value) +{ + setValue(date,value); +} + +void ComicInfo::setPublisher(QString value) +{ + setValue(publisher,value); +} + +void ComicInfo::setFormat(QString value) +{ + setValue(format,value); +} + +void ComicInfo::setColor(bool value) +{ + setValue(color,value); +} + +void ComicInfo::setAgeRating(QString value) +{ + setValue(ageRating,value); +} + +void ComicInfo::setSynopsis(QString value) +{ + setValue(synopsis,value); +} + +void ComicInfo::setCharacters(QString value) +{ + setValue(characters,value); +} + +void ComicInfo::setNotes(QString value) +{ + setValue(notes,value); +}*/ + +QPixmap ComicInfo::getCover(const QString & basePath) +{ + if(cover.isNull()) + { + cover.load(basePath + "/.yacreaderlibrary/covers/" + hash + ".jpg"); + } + QPixmap c; + c.convertFromImage(cover); + return c; +} +QDataStream &operator<<(QDataStream & stream, const ComicDB & comic) +{ + stream << comic.id; + stream << comic.name; + stream << comic.parentId; + stream << comic.path; + stream << comic._hasCover; + stream << comic.info; + return stream; +} + +QDataStream &operator>>(QDataStream & stream, ComicDB & comic) +{ + stream >> comic.id; + stream >> comic.name; + stream >> comic.parentId; + stream >> comic.path; + stream >> comic._hasCover; + stream >> comic.info; + return stream; +} + +QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo) +{ + stream << comicInfo.id; + stream << comicInfo.read; + stream << comicInfo.edited; + stream << comicInfo.hash; + stream << comicInfo.existOnDb; + + stream << comicInfo.hasBeenOpened; + stream << comicInfo.rating; + stream << comicInfo.currentPage; + stream << comicInfo.bookmark1; + stream << comicInfo.bookmark2; + stream << comicInfo.bookmark3; + stream << comicInfo.brightness; + stream << comicInfo.contrast; + stream << comicInfo.gamma; + + stream << comicInfo.title; + + stream << comicInfo.coverPage; + stream << comicInfo.numPages; + + stream << comicInfo.number; + stream << comicInfo.isBis; + stream << comicInfo.count; + + stream << comicInfo.volume; + stream << comicInfo.storyArc; + stream << comicInfo.arcNumber; + stream << comicInfo.arcCount; + + stream << comicInfo.genere; + + stream << comicInfo.writer; + stream << comicInfo.penciller; + stream << comicInfo.inker; + stream << comicInfo.colorist; + stream << comicInfo.letterer; + stream << comicInfo.coverArtist; + + stream << comicInfo.date; + stream << comicInfo.publisher; + stream << comicInfo.format; + stream << comicInfo.color; + stream << comicInfo.ageRating; + + stream << comicInfo.synopsis; + stream << comicInfo.characters; + stream << comicInfo.notes; + + stream << comicInfo.comicVineID; + + return stream; +} + +QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo) +{ + stream >> comicInfo.id; + stream >> comicInfo.read; + stream >> comicInfo.edited; + stream >> comicInfo.hash; + stream >> comicInfo.existOnDb; + + stream >> comicInfo.hasBeenOpened; + stream >> comicInfo.rating; + stream >> comicInfo.currentPage; + stream >> comicInfo.bookmark1; + stream >> comicInfo.bookmark2; + stream >> comicInfo.bookmark3; + stream >> comicInfo.brightness; + stream >> comicInfo.contrast; + stream >> comicInfo.gamma; + + stream >> comicInfo.title; + + stream >> comicInfo.coverPage; + stream >> comicInfo.numPages; + + stream >> comicInfo.number; + stream >> comicInfo.isBis; + stream >> comicInfo.count; + + stream >> comicInfo.volume; + stream >> comicInfo.storyArc; + stream >> comicInfo.arcNumber; + stream >> comicInfo.arcCount; + + stream >> comicInfo.genere; + + stream >> comicInfo.writer; + stream >> comicInfo.penciller; + stream >> comicInfo.inker; + stream >> comicInfo.colorist; + stream >> comicInfo.letterer; + stream >> comicInfo.coverArtist; + + stream >> comicInfo.date; + stream >> comicInfo.publisher; + stream >> comicInfo.format; + stream >> comicInfo.color; + stream >> comicInfo.ageRating; + + stream >> comicInfo.synopsis; + stream >> comicInfo.characters; + stream >> comicInfo.notes; + + stream >> comicInfo.comicVineID; + + return stream; +} diff --git a/common/comic_db.h b/common/comic_db.h new file mode 100644 index 00000000..417efa4d --- /dev/null +++ b/common/comic_db.h @@ -0,0 +1,157 @@ +#ifndef __COMICDB_H +#define __COMICDB_H + +#include "library_item.h" +#include +#include +#include +#include +#include + +class ComicInfo +{ +public: + ComicInfo(); + ComicInfo(const ComicInfo & comicInfo); + ~ComicInfo(); + + ComicInfo & operator=(const ComicInfo & comicInfo); + + //mandatory fields + qulonglong id; + bool read; + bool edited; + QString hash; + bool existOnDb; + + int rating; + + bool hasBeenOpened; + + //viewer + int currentPage; + int bookmark1; + int bookmark2; + int bookmark3; + int brightness; + int contrast; + int gamma; + //----------------- + + + QVariant title;//string + + QVariant coverPage;//int + QVariant numPages;//int + + QVariant number;//int + QVariant isBis;//bool + QVariant count;//int + + QVariant volume;//string + QVariant storyArc;//string + QVariant arcNumber;//int + QVariant arcCount;//int + + QVariant genere;//string + + QVariant writer;//string + QVariant penciller;//string + QVariant inker;//string + QVariant colorist;//string + QVariant letterer;//string + QVariant coverArtist;//string + + QVariant date;//string + QVariant publisher;//string + QVariant format;//string + QVariant color;//bool + QVariant ageRating;//string + + QVariant synopsis;//string + QVariant characters;//string + QVariant notes;//string + + QVariant comicVineID;//string + + QImage cover; + + /*void setTitle(QVariant value); + + void setCoverPage(QVariant value); + void setNumPages(QVariant value); + + void setNumber(QVariant value); + void setIsBis(QVariant value); + void setCount(QVariant value); + + void setVolume(QVariant value); + void setStoryArc(QVariant value); + void setArcNumber(QVariant value); + void setArcCount(QVariant value); + + void setGenere(QVariant value); + + void setWriter(QVariant value); + void setPenciller(QVariant value); + void setInker(QVariant value); + void setColorist(QVariant value); + void setLetterer(QVariant value); + void setCoverArtist(QVariant value); + + void setDate(QVariant value); + void setPublisher(QVariant value); + void setFormat(QVariant value); + void setColor(QVariant value); + void setAgeRating(QVariant value); + + void setSynopsis(QVariant value); + void setCharacters(QVariant value); + void setNotes(QVariant value);*/ + + QPixmap getCover(const QString & basePath); + + friend QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo); + + friend QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo); + +private: + +}; + +class ComicDB : public LibraryItem +{ +public: + ComicDB(); + + bool isDir(); + + bool _hasCover; + + bool hasCover() {return _hasCover;}; + + //return comic file name + QString getFileName() const; + + //returns comic title if it isn't null or empty, in other case returns fileName + QString getTitleOrFileName() const; + + //returns parent folder name + QString getParentFolderName() const; + + //return the size of the file in bytes + qulonglong getFileSize() const; + + QString toTXT(); + + ComicInfo info; + + bool operator==(const ComicDB & other){return id == other.id;}; + + friend QDataStream &operator<<(QDataStream &, const ComicDB &); + friend QDataStream &operator>>(QDataStream &, ComicDB &); +}; + +Q_DECLARE_METATYPE(ComicDB); + +#endif diff --git a/common/custom_widgets.cpp b/common/custom_widgets.cpp new file mode 100644 index 00000000..5695e144 --- /dev/null +++ b/common/custom_widgets.cpp @@ -0,0 +1 @@ +#include "custom_widgets.h" diff --git a/common/custom_widgets.h b/common/custom_widgets.h new file mode 100644 index 00000000..15430ce7 --- /dev/null +++ b/common/custom_widgets.h @@ -0,0 +1,6 @@ +#ifndef __CUSTOM_WIDGETS_H +#define __CUSTOM_WIDGETS_H + +#endif + + diff --git a/common/exit_check.cpp b/common/exit_check.cpp new file mode 100644 index 00000000..6d1cca54 --- /dev/null +++ b/common/exit_check.cpp @@ -0,0 +1,21 @@ +#include "exit_check.h" + +#include "yacreader_global.h" + +#include + +using namespace YACReader; + +void YACReader::exitCheck(int ret) +{ + switch(ret) + { + case YACReader::SevenZNotFound: + QMessageBox::critical(0,QObject::tr("7z lib not found"),QObject::tr("unable to load 7z lib from ./utils")); + break; + default: + break; + } + +} + diff --git a/common/exit_check.h b/common/exit_check.h new file mode 100644 index 00000000..a2c0b19a --- /dev/null +++ b/common/exit_check.h @@ -0,0 +1,9 @@ +#ifndef EXIT_CHECK_H +#define EXIT_CHECK_H + +namespace YACReader +{ + void exitCheck(int ret); +} + +#endif diff --git a/common/folder.cpp b/common/folder.cpp new file mode 100644 index 00000000..e69de29b diff --git a/common/folder.h b/common/folder.h new file mode 100644 index 00000000..862c05de --- /dev/null +++ b/common/folder.h @@ -0,0 +1,30 @@ +#ifndef __FOLDER_H +#define __FOLDER_H + +#include "library_item.h" + +#include + +class Folder : public LibraryItem +{ +public: + bool knownParent; + bool knownId; + + Folder():knownParent(false), knownId(false){}; + Folder(qulonglong sid, qulonglong pid,QString fn, QString fp):knownParent(true), knownId(true){id = sid; parentId = pid;name = fn; path = fp;}; + Folder(QString fn, QString fp):knownParent(false), knownId(false){name = fn; path = fp;}; + void setId(qulonglong sid){id = sid;knownId = true;}; + void setFather(qulonglong pid){parentId = pid;knownParent = true;}; + bool isDir() {return true;}; + bool isFinished() const {return finished;}; + bool isCompleted() const {return completed;}; + void setFinished(bool b) {finished = b;}; + void setCompleted(bool b) {completed = b;}; + +private: + bool finished; + bool completed; +}; + +#endif diff --git a/common/gl/yacreader_flow_gl.cpp b/common/gl/yacreader_flow_gl.cpp new file mode 100644 index 00000000..6ab56239 --- /dev/null +++ b/common/gl/yacreader_flow_gl.cpp @@ -0,0 +1,1640 @@ +#include "yacreader_flow_gl.h" + +#include +#include +//#include + +#ifdef Q_OS_MAC + #include +#else + #include +#endif + +#include +#include +#include +#include +/*** Animation Settings ***/ + +/*** Position Configuration ***/ + +int YACReaderFlowGL::updateInterval = 16; + +struct Preset defaultYACReaderFlowConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 3.f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.01f, //View_rotate_add sets the speed of the rotation + 0.02f, //View_rotate_sub sets the speed of reversing the rotation + 20.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + 0.f, //CF_Y the Y Position of the Coverflow + -8.f, //CF_Z the Z Position of the Coverflow + + 15.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + -50.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + 0.0f, //Y_Distance sets the elevation amount + + 30.f //zoom level + +}; + +struct Preset presetYACReaderFlowClassicConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 2.f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 30.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + -40.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + 0.0f, //Y_Distance sets the elevation amount + + 22.f //zoom level + +}; + +struct Preset presetYACReaderFlowStripeConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 6.f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 4.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 30.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + 0.f, //Rotation sets the rotation of each cover + 1.1f, //X_Distance sets the distance between the covers + 0.2f, //Center_Distance sets the distance between the centered and the non centered covers + 0.01f, //Z_Distance sets the pushback amount + 0.0f, //Y_Distance sets the elevation amount + + 22.f //zoom level + +}; + +struct Preset presetYACReaderFlowOverlappedStripeConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 2.f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 30.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + 0.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + 0.0f, //Y_Distance sets the elevation amount + + 22.f //zoom level + +}; + +struct Preset pressetYACReaderFlowUpConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 2.5f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 5.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + -50.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + -0.1f, //Y_Distance sets the elevation amount + + 22.f //zoom level + +}; + +struct Preset pressetYACReaderFlowDownConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 2.5f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 5.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + -50.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + 0.1f, //Y_Distance sets the elevation amount + + 22.f //zoom level +}; +/*Constructor*/ +YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p) + :QOpenGLWidget(/*QOpenGLWidget migration QGLFormat(QGL::SampleBuffers),*/ parent),numObjects(0),lazyPopulateObjects(-1),bUseVSync(false),hasBeenInitialized(false) +{ + updateCount = 0; + config = p; + + currentSelected = 0; + + centerPos.x = 0.f; + centerPos.y = 0.f; + centerPos.z = 1.f; + centerPos.rot = 0.f; + + /*** Style ***/ + shadingTop = 0.8f; + shadingBottom = 0.02f; + reflectionUp = 0.f; + reflectionBottom = 0.6f; + + /*** System variables ***/ + numObjects = 0; + //CFImage Dummy; + viewRotate = 0.f; + viewRotateActive = 0; + stepBackup = config.animationStep/config.animationSpeedUp; + + /*QTimer * timer = new QTimer(); + connect(timer, SIGNAL(timeout()), this, SLOT(updateImageData())); + timer->start(70); + */ + + /*loader = new WidgetLoader(0,this); + loader->flow = this; + QThread * loaderThread = new QThread(parent); + + loader->moveToThread(loaderThread); + + loaderThread->start();*/ + + QSurfaceFormat f = format(); + + //TODO add antialiasing + //f.setSamples(4); + f.setVersion(2, 1); + f.setSwapInterval(0); + setFormat(f); + + timerId = startTimer(updateInterval); +} + +void YACReaderFlowGL::timerEvent(QTimerEvent * event) +{ + if(timerId == event->timerId()) + update(); + + //if(!worker->isRunning()) + //worker->start(); +} + +void YACReaderFlowGL::startAnimationTimer() +{ + if(timerId == -1) + timerId = startTimer(updateInterval); +} + +void YACReaderFlowGL::stopAnimationTimer() +{ + if(timerId != -1) + { + killTimer(timerId); + timerId = -1; + } +} + +YACReaderFlowGL::~YACReaderFlowGL() +{ + +} + +QSize YACReaderFlowGL::minimumSizeHint() const +{ + return QSize(320, 200); +} + +/*QSize YACReaderFlowGL::sizeHint() const +{ + return QSize(320, 200); +}*/ + +void YACReaderFlowGL::initializeGL() +{ + glShadeModel(GL_SMOOTH); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + defaultTexture = new QOpenGLTexture(QImage(":/images/defaultCover.png")); + defaultTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear); +#ifdef YACREADER_LIBRARY + markTexture = new QOpenGLTexture(QImage(":/images/readRibbon.png")); + markTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear); + + readingTexture = new QOpenGLTexture(QImage(":/images/readingRibbon.png")); + readingTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear); +#endif + if(lazyPopulateObjects!=-1) + populate(lazyPopulateObjects); + + hasBeenInitialized = true; +} + +void YACReaderFlowGL::paintGL() +{ + QPainter painter; + painter.begin(this); + + painter.beginNativePainting(); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_COLOR_MATERIAL); + glEnable(GL_BLEND); + glEnable(GL_MULTISAMPLE); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if(numObjects>0) + { + updatePositions(); + udpatePerspective(width(),height()); + draw(); + } + + glDisable(GL_MULTISAMPLE); + glDisable(GL_BLEND); + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + + painter.endNativePainting(); + + QFont font = painter.font() ; + font.setFamily("Arial"); + font.setPixelSize(fontSize); + painter.setFont(font); + + painter.setPen(QColor(76,76,76)); + painter.drawText(10,fontSize + 10, QString("%1/%2").arg(currentSelected+1).arg(numObjects)); + + painter.end(); +} + +void YACReaderFlowGL::resizeGL(int width, int height) +{ + float pixelRatio = devicePixelRatio(); + fontSize = (width + height) * 0.010 * pixelRatio; + if(fontSize < 10) + fontSize = 10; + + //int side = qMin(width, height); + udpatePerspective(width,height); + + if(numObjects>0) + updatePositions(); +} + +void YACReaderFlowGL::udpatePerspective(int width, int height) +{ + float pixelRatio = devicePixelRatio(); + glViewport(0, 0, width*pixelRatio, height*pixelRatio); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + gluPerspective(20.0, GLdouble(width) / (float)height, 1.0, 200.0); + + glMatrixMode(GL_MODELVIEW); +} + +//----------------------------------------------------------------------------- +/*Private*/ +void YACReaderFlowGL::calcPos(YACReader3DImage & image, int pos) +{ + if(pos == 0){ + image.current = centerPos; + }else{ + if(pos > 0){ + image.current.x = (config.centerDistance)+(config.xDistance*pos); + image.current.y = config.yDistance*pos*-1; + image.current.z = config.zDistance*pos*-1; + image.current.rot = config.rotation; + }else{ + image.current.x = (config.centerDistance)*-1+(config.xDistance*pos); + image.current.y = config.yDistance*pos; + image.current.z = config.zDistance*pos; + image.current.rot = config.rotation*-1; + } + } + +} +void YACReaderFlowGL::calcVector(YACReader3DVector & vector, int pos) +{ + calcPos(dummy,pos); + + vector.x = dummy.current.x; + vector.y = dummy.current.y; + vector.z = dummy.current.z; + vector.rot = dummy.current.rot; +} + +bool YACReaderFlowGL::animate(YACReader3DVector & currentVector,YACReader3DVector & toVector) +{ + float rotDiff = toVector.rot-currentVector.rot; + float xDiff = toVector.x-currentVector.x; + float yDiff = toVector.y-currentVector.y; + float zDiff = toVector.z-currentVector.z; + + if(fabs(rotDiff) < 0.01 + && fabs(xDiff) < 0.001 + && fabs(yDiff) < 0.001 + && fabs(zDiff) < 0.001) + return true; + + //calculate and apply positions + currentVector.x = currentVector.x+(xDiff)*config.animationStep; + currentVector.y = currentVector.y+(yDiff)*config.animationStep; + currentVector.z = currentVector.z+(zDiff)*config.animationStep; + + if(fabs(rotDiff) > 0.01){ + currentVector.rot = currentVector.rot+(rotDiff)*(config.animationStep*config.preRotation); + } + else + { + viewRotateActive = 0; + } + + return false; +} +void YACReaderFlowGL::drawCover(const YACReader3DImage & image) +{ + float w = image.width; + float h = image.height; + + //fadeout + float opacity = 1-1/(config.animationFadeOutDist+config.viewRotateLightStrenght*fabs(viewRotate))*fabs(0-image.current.x); + + glLoadIdentity(); + glTranslatef(config.cfX,config.cfY,config.cfZ); + glRotatef(config.cfRX,1,0,0); + glRotatef(viewRotate*config.viewAngle+config.cfRY,0,1,0); + glRotatef(config.cfRZ,0,0,1); + + glTranslatef( image.current.x, image.current.y, image.current.z ); + + glPushMatrix(); + glRotatef(image.current.rot,0,1,0); + + glEnable(GL_TEXTURE_2D); + image.texture->bind(); + + //calculate shading + float LShading = ((config.rotation != 0 )?((image.current.rot < 0)?1-1/config.rotation*image.current.rot:1):1); + float RShading = ((config.rotation != 0 )?((image.current.rot > 0)?1-1/(config.rotation*-1)*image.current.rot:1):1); + float LUP = shadingTop+(1-shadingTop)*LShading; + float LDOWN = shadingBottom+(1-shadingBottom)*LShading; + float RUP = shadingTop+(1-shadingTop)*RShading; + float RDOWN = shadingBottom+(1-shadingBottom)*RShading;; + + + //DrawCover + glBegin(GL_QUADS); + + //esquina inferior izquierda + glColor4f(LDOWN*opacity,LDOWN*opacity,LDOWN*opacity,1); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(w/2.f*-1.f, -0.5f, 0.f); + + //esquina inferior derecha + glColor4f(RDOWN*opacity,RDOWN*opacity,RDOWN*opacity,1); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(w/2.f, -0.5f, 0.f); + + //esquina superior derecha + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(w/2.f, -0.5f+h, 0.f); + + //esquina superior izquierda + glColor4f(LUP*opacity,LUP*opacity,LUP*opacity,1); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(w/2.f*-1.f, -0.5f+h, 0.f); + + glEnd(); + + + + //Draw reflection + glBegin(GL_QUADS); + + //esquina inferior izquierda + glColor4f(LUP*opacity*reflectionUp/2,LUP*opacity*reflectionUp/2,LUP*opacity*reflectionUp/2,1); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(w/2.f*-1.f, -0.5f-h, 0.f); + + //esquina inferior derecha + glColor4f(RUP*opacity*reflectionUp/2,RUP*opacity*reflectionUp/2,RUP*opacity*reflectionUp/2,1); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(w/2.f, -0.5f-h, 0.f); + + //esquina superior derecha + glColor4f(RDOWN*opacity/3,RDOWN*opacity/3,RDOWN*opacity/3,1); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(w/2.f, -0.5f, 0.f); + + //esquina superior izquierda + glColor4f(LDOWN*opacity/3,LDOWN*opacity/3,LDOWN*opacity/3,1); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(w/2.f*-1.f, -0.5f, 0.f); + + glEnd(); + glDisable(GL_TEXTURE_2D); + + if(showMarks && loaded[image.index] && marks[image.index] != Unread) + { + glEnable(GL_TEXTURE_2D); + if(marks[image.index] == Read) + markTexture->bind(); + else + readingTexture->bind(); + glBegin(GL_QUADS); + + //esquina inferior izquierda + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(w/2.f-0.2, -0.685f+h, 0.001f); + + //esquina inferior derecha + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(w/2.f-0.05, -0.685f+h, 0.001f); + + //esquina superior derecha + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(w/2.f-0.05, -0.485f+h, 0.001f); + + //esquina superior izquierda + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(w/2.f-0.2, -0.485f+h, 0.001f); + + glEnd(); + glDisable(GL_TEXTURE_2D); + } + + + glPopMatrix(); +} + +/*Public*/ +void YACReaderFlowGL::cleanupAnimation() +{ + config.animationStep = stepBackup; + viewRotateActive = 0; +} + +void YACReaderFlowGL::draw() +{ + int CS = currentSelected; + int count; + + + //Draw right Covers + for(count = numObjects-1;count > -1;count--){ + if(count > CS){ + drawCover(images[count]); + } + } + + //Draw left Covers + for(count = 0;count < numObjects-1;count++){ + if(count < CS){ + drawCover(images[count]); + } + } + + //Draw Center Cover + drawCover(images[CS]); + + +} + +void YACReaderFlowGL::showPrevious() +{ + startAnimationTimer(); + + if(currentSelected > 0){ + + currentSelected--; + emit centerIndexChanged(currentSelected); + config.animationStep *= config.animationSpeedUp; + + if(config.animationStep > config.animationStepMax){ + config.animationStep = config.animationStepMax; + } + + if(viewRotateActive && viewRotate > -1){ + viewRotate -= config.viewRotateAdd; + } + + viewRotateActive = 1; + + } +} + +void YACReaderFlowGL::showNext() +{ + startAnimationTimer(); + + if(currentSelected < numObjects-1){ + + currentSelected++; + emit centerIndexChanged(currentSelected); + config.animationStep *= config.animationSpeedUp; + + if(config.animationStep > config.animationStepMax){ + config.animationStep = config.animationStepMax; + } + + if(viewRotateActive && viewRotate < 1){ + viewRotate += config.viewRotateAdd; + } + + viewRotateActive = 1; + } +} + +void YACReaderFlowGL::setCurrentIndex(int pos) +{ + if(!(pos>=0 && pos < images.length() && images.length()>0)) + return; + if(pos >= images.length() && images.length() > 0) + pos = images.length()-1; + + startAnimationTimer(); + + currentSelected = pos; + + config.animationStep *= config.animationSpeedUp; + + if(config.animationStep > config.animationStepMax){ + config.animationStep = config.animationStepMax; + } + + if(viewRotateActive && viewRotate < 1){ + viewRotate += config.viewRotateAdd; + } + + viewRotateActive = 1; + +} + +void YACReaderFlowGL::updatePositions() +{ + int count; + + bool stopAnimation = true; + for(count = numObjects-1;count > -1;count--){ + calcVector(images[count].animEnd,count-currentSelected); + if(!animate(images[count].current,images[count].animEnd)) + stopAnimation = false; + } + + //slowly reset view angle + if(!viewRotateActive){ + viewRotate += (0-viewRotate)*config.viewRotateSub; + } + + if(fabs (images[currentSelected].current.x - images[currentSelected].animEnd.x) < 1)//viewRotate < 0.2) + { + cleanupAnimation(); + if(updateCount >= 0) //TODO parametrizar + { + + updateCount = 0; + updateImageData(); + } + else + updateCount++; + } + else + updateCount++; + + if(stopAnimation) + stopAnimationTimer(); + +} + +void YACReaderFlowGL::insert(char *name, QOpenGLTexture * texture, float x, float y,int item) +{ + startAnimationTimer(); + + Q_UNUSED(name) + //set a new entry + if(item == -1){ + images.push_back(YACReader3DImage()); + + item = numObjects; + numObjects++; + + calcVector(images[item].current,item); + images[item].current.z = images[item].current.z-1; + } + + images[item].texture = texture; + images[item].width = x; + images[item].height = y; + images[item].index = item; + //strcpy(cfImages[item].name,name); + + +} + +void YACReaderFlowGL::remove(int item) +{ + if(item < 0 || item >= images.size()) + return; + + startAnimationTimer(); + + loaded.remove(item); + marks.remove(item); + + //reposition current selection + if(item <= currentSelected && currentSelected != 0){ + currentSelected--; + } + + QOpenGLTexture * texture = images[item].texture; + + int count = item; + while(count <= numObjects-2){ + images[count].index--; + count++; + } + images.removeAt(item); + + if(texture != defaultTexture) + delete(texture); + + numObjects--; +} + +/*Info*/ +YACReader3DImage YACReaderFlowGL::getCurrentSelected() +{ + return images[currentSelected]; +} + +void YACReaderFlowGL::replace(char *name, QOpenGLTexture * texture, float x, float y,int item) +{ + startAnimationTimer(); + + Q_UNUSED(name) + if(images[item].index == item) + { + images[item].texture = texture; + images[item].width = x; + images[item].height = y; + loaded[item]=true; + } + else + loaded[item]=false; +} + +void YACReaderFlowGL::populate(int n) +{ + emit centerIndexChanged(0); + float x = 1; + float y = 1 * (700.f/480.0f); + int i; + + for(i = 0;i(n,false); + //marks = QVector(n,false); + + + + //worker->start(); +} + +void YACReaderFlowGL::reset() +{ + makeCurrent(); + + startAnimationTimer(); + + currentSelected = 0; + loaded.clear(); + + for(int i = 0;iwidth(); + int height = this->height(); + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + //float sideX = ((float(width)/height)/2)*1.5; + //float sideY = 0.5*1.5; + gluPerspective(zoom, (float)width / (float)height, 1.0, 200.0); + //glOrtho(-sideX, sideX, -sideY+0.2, +sideY+0.2, 4, 11.0); + + glMatrixMode(GL_MODELVIEW); + +} + +void YACReaderFlowGL::setRotation(int angle) +{ + startAnimationTimer(); + + config.rotation = -angle; +} +//sets the distance between the covers +void YACReaderFlowGL::setX_Distance(int distance) +{ + startAnimationTimer(); + + config.xDistance = distance/100.0; +} +//sets the distance between the centered and the non centered covers +void YACReaderFlowGL::setCenter_Distance(int distance) +{ + startAnimationTimer(); + + config.centerDistance = distance/100.0; +} +//sets the pushback amount +void YACReaderFlowGL::setZ_Distance(int distance) +{ + startAnimationTimer(); + + config.zDistance = distance/100.0; +} + +void YACReaderFlowGL::setCF_Y(int value) +{ + startAnimationTimer(); + + config.cfY = value/100.0; +} + +void YACReaderFlowGL::setCF_Z(int value) +{ + startAnimationTimer(); + + config.cfZ = value; +} + +void YACReaderFlowGL::setY_Distance(int value) +{ + startAnimationTimer(); + + config.yDistance = value / 100.0; +} + +void YACReaderFlowGL::setFadeOutDist(int value) +{ + startAnimationTimer(); + + config.animationFadeOutDist = value; +} + +void YACReaderFlowGL::setLightStrenght(int value) +{ + startAnimationTimer(); + + config.viewRotateLightStrenght = value; +} + +void YACReaderFlowGL::setMaxAngle(int value) +{ + startAnimationTimer(); + + config.viewAngle = value; +} + +void YACReaderFlowGL::setPreset(const Preset & p) +{ + startAnimationTimer(); + + config = p; +} + +void YACReaderFlowGL::setPerformance(Performance performance) +{ + if(this->performance != performance) + { + startAnimationTimer(); + + this->performance = performance; + reload(); + } +} + +void YACReaderFlowGL::useVSync(bool b) +{ + if(bUseVSync != b) + { + bUseVSync = b; + if(b) + { + QSurfaceFormat f = format(); + f.setVersion(2, 1); + f.setSwapInterval(1); + setFormat(f); + } + else + { + QSurfaceFormat f = format(); + f.setVersion(2, 1); + f.setSwapInterval(0); + setFormat(f); + } + reset(); + } +} +void YACReaderFlowGL::setShowMarks(bool value) +{ + startAnimationTimer(); + + showMarks = value; +} +void YACReaderFlowGL::setMarks(QVector marks) +{ + startAnimationTimer(); + + this->marks = marks; +} +void YACReaderFlowGL::setMarkImage(QImage & image) +{ + Q_UNUSED(image); + //qué pasa la primera vez?? + //deleteTexture(markTexture); + //markTexture = bindTexture(image,GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption); +} +void YACReaderFlowGL::markSlide(int index, YACReaderComicReadStatus status) +{ + startAnimationTimer(); + + marks[index] = status; +} +void YACReaderFlowGL::unmarkSlide(int index) +{ + startAnimationTimer(); + + marks[index] = YACReader::Unread; +} +void YACReaderFlowGL::setSlideSize(QSize size) +{ + Q_UNUSED(size); + //TODO calcular el tamaño del widget +} +void YACReaderFlowGL::clear() +{ + reset(); +} + +void YACReaderFlowGL::setCenterIndex(unsigned int index) +{ + setCurrentIndex(index); +} +void YACReaderFlowGL::showSlide(int index) +{ + setCurrentIndex(index); +} +int YACReaderFlowGL::centerIndex() +{ + return currentSelected; +} +void YACReaderFlowGL::updateMarks() +{ + //do nothing +} +/*void YACReaderFlowGL::setFlowType(FlowType flowType) +{ + //TODO esperar a que se reimplemente flowtype +}*/ +void YACReaderFlowGL::render() +{ + //do nothing +} + +//EVENTOS + +void YACReaderFlowGL::wheelEvent(QWheelEvent * event) +{ + Movement m = getMovement(event); + switch (m) { + case None: + return; + case Forward: + showNext(); + break; + case Backward: + showPrevious(); + break; + default: + break; + } +} + +void YACReaderFlowGL::keyPressEvent(QKeyEvent *event) +{ + if(event->key() == Qt::Key_Left) + { + if(event->modifiers() == Qt::ControlModifier) + setCurrentIndex((currentSelected-10<0)?0:currentSelected-10); + else + showPrevious(); + event->accept(); + return; + } + + if(event->key() == Qt::Key_Right) + { + if(event->modifiers() == Qt::ControlModifier) + setCurrentIndex((currentSelected+10>=numObjects)?numObjects-1:currentSelected+10); + else + showNext(); + event->accept(); + return; + } + + if(event->key() == Qt::Key_Up) + { + //emit selected(centerIndex()); + return; + } + + event->ignore(); +} + +void YACReaderFlowGL::mousePressEvent(QMouseEvent *event) +{ + makeCurrent(); + if(event->button() == Qt::LeftButton) + { + float x,y; + float pixelRatio = devicePixelRatio(); + x = event->x()*pixelRatio; + y = event->y()*pixelRatio; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY, winZ; + GLdouble posX, posY, posZ; + + glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); + glGetDoublev( GL_PROJECTION_MATRIX, projection ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + winX = (float)x; + winY = (float)viewport[3] - (float)y; + + glReadPixels(winX, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); + + gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); + + if(posX >= 0.5) + { + //int index = currentSelected+1; + //while((cfImages[index].current.x-cfImages[index].width/(2.0*config.rotation)) < posX) + // index++; + //setCurrentIndex(index-1); + showNext(); + } + else if(posX <=-0.5) + showPrevious(); + } else + QOpenGLWidget::mousePressEvent(event); + doneCurrent(); +} + +void YACReaderFlowGL::mouseDoubleClickEvent(QMouseEvent* event) +{ + makeCurrent(); + float x,y; + float pixelRatio = devicePixelRatio(); + x = event->x()*pixelRatio; + y = event->y()*pixelRatio; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY, winZ; + GLdouble posX, posY, posZ; + + glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); + glGetDoublev( GL_PROJECTION_MATRIX, projection ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + winX = (float)x; + winY = (float)viewport[3] - (float)y; + glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); + + gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); + + if(posX <= 0.5 && posX >= -0.5) + { + emit selected(centerIndex()); + event->accept(); + } + doneCurrent(); +} + +YACReaderComicFlowGL::YACReaderComicFlowGL(QWidget *parent,struct Preset p ) + :YACReaderFlowGL(parent,p) +{ + worker = new ImageLoaderGL(this); + worker->flow = this; +} + +void YACReaderComicFlowGL::setImagePaths(QStringList paths) +{ + worker->reset(); + reset(); + numObjects = 0; + if(lazyPopulateObjects!=-1 || hasBeenInitialized) + YACReaderFlowGL::populate(paths.size()); + lazyPopulateObjects = paths.size(); + this->paths = paths; + //numObjects = paths.size(); +} + + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +void YACReaderComicFlowGL::updateImageData() +{ + // can't do anything, wait for the next possibility + if(worker->busy()) + return; + + // set image of last one + int idx = worker->index(); + if( idx >= 0 && !worker->result().isNull()) + { + if(!loaded[idx]) + { + float x = 1; + QImage img = worker->result(); + QOpenGLTexture * texture = new QOpenGLTexture(img); + + if(performance == high || performance == ultraHigh) + { + texture->setAutoMipMapGenerationEnabled(true); + texture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear); + } + else + { + texture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); + } + + float y = 1 * (float(img.height())/img.width()); + QString s = "cover"; + replace(s.toLocal8Bit().data(), texture, x, y,idx); + } + } + + // try to load only few images on the left and right side + // i.e. all visible ones plus some extra + int count=8; + switch(performance) + { + case low: + count = 8; + break; + case medium: + count = 10; + break; + case high: + count = 12; + break; + case ultraHigh: + count = 14; + break; + } + int * indexes = new int[2*count+1]; + int center = currentSelected; + indexes[0] = center; + for(int j = 0; j < count; j++) + { + indexes[j*2+1] = center+j+1; + indexes[j*2+2] = center-j-1; + } + for(int c = 0; c < 2*count+1; c++) + { + int i = indexes[c]; + if((i >= 0) && (i < numObjects)) + if(!loaded[i])//slide(i).isNull()) + { + //loader->loadTexture(i); + //loaded[i]=true; + // schedule thumbnail generation + if(paths.size()>0) + { + QString fname = paths.at(i); + //loaded[i]=true; + + worker->generate(i, fname); + } + delete[] indexes; + return; + } + } + + delete[] indexes; +} + +void YACReaderComicFlowGL::remove(int item) +{ + worker->lock(); + worker->reset(); + YACReaderFlowGL::remove(item); + if(item >= 0 && item < paths.size()) + paths.removeAt(item); + worker->unlock(); +} + +void YACReaderComicFlowGL::resortCovers(QList newOrder) +{ + worker->lock(); + worker->reset();//is this necesary? + startAnimationTimer(); + QList pathsNew; + QVector loadedNew; + QVector marksNew; + QVector imagesNew; + + int index = 0; + foreach (int i, newOrder) { + pathsNew << paths.at(i); + loadedNew << loaded.at(i); + marksNew << marks.at(i); + imagesNew << images.at(i); + imagesNew.last().index = index++; + } + + paths = pathsNew; + loaded = loadedNew; + marks = marksNew; + images = imagesNew; + + worker->unlock(); +} + + +YACReaderPageFlowGL::YACReaderPageFlowGL(QWidget *parent,struct Preset p ) + :YACReaderFlowGL(parent,p) +{ + worker = new ImageLoaderByteArrayGL(this); + worker->flow = this; +} + +YACReaderPageFlowGL::~YACReaderPageFlowGL() +{ + this->killTimer(timerId); + //worker->deleteLater(); + rawImages.clear(); + for(int i = 0;ibusy()) + return; + + // set image of last one + int idx = worker->index(); + if( idx >= 0 && !worker->result().isNull()) + { + if(!loaded[idx]) + { + float x = 1; + QImage img = worker->result(); + QOpenGLTexture * texture = new QOpenGLTexture(img); + + if(performance == high || performance == ultraHigh) + { + texture->setAutoMipMapGenerationEnabled(true); + texture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear,QOpenGLTexture::LinearMipMapLinear); + } + else + { + texture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); + } + + float y = 1 * (float(img.height())/img.width()); + QString s = "cover"; + replace(s.toLocal8Bit().data(), texture, x, y,idx); + loaded[idx] = true; + } + } + + // try to load only few images on the left and right side + // i.e. all visible ones plus some extra + int count=8; + switch(performance) + { + case low: + count = 8; + break; + case medium: + count = 10; + break; + case high: + count = 12; + break; + case ultraHigh: + count = 14; + break; + } + int * indexes = new int[2*count+1]; + int center = currentSelected; + indexes[0] = center; + for(int j = 0; j < count; j++) + { + indexes[j*2+1] = center+j+1; + indexes[j*2+2] = center-j-1; + } + for(int c = 0; c < 2*count+1; c++) + { + int i = indexes[c]; + if((i >= 0) && (i < numObjects)) + if(rawImages.size()>0) + + if(!loaded[i]&&imagesReady[i])//slide(i).isNull()) + { + worker->generate(i, rawImages.at(i)); + + delete[] indexes; + return; + } + } + + delete[] indexes; +} + +void YACReaderPageFlowGL::populate(int n) +{ + worker->reset(); + if(lazyPopulateObjects!=-1 || hasBeenInitialized) + YACReaderFlowGL::populate(n); + lazyPopulateObjects = n; + imagesReady = QVector (n,false); + rawImages = QVector (n); + imagesSetted = QVector (n,false); //puede sobrar +} + + +//----------------------------------------------------------------------------- +//ImageLoader +//----------------------------------------------------------------------------- +QImage ImageLoaderGL::loadImage(const QString& fileName) +{ + QImage image; + bool result = image.load(fileName); + + switch(flow->performance) + { + case low: + image = image.scaledToWidth(200,Qt::SmoothTransformation); + break; + case medium: + image = image.scaledToWidth(256,Qt::SmoothTransformation); + break; + case high: + image = image.scaledToWidth(320,Qt::SmoothTransformation); + break; + + } + + if(!result) + return QImage(); + + return image; +} + +ImageLoaderGL::ImageLoaderGL(YACReaderFlowGL * flow): +QThread(),flow(flow),restart(false), working(false), idx(-1) +{ + +} + +ImageLoaderGL::~ImageLoaderGL() +{ + mutex.lock(); + condition.wakeOne(); + mutex.unlock(); + wait(); +} + +bool ImageLoaderGL::busy() const +{ + return isRunning() ? working : false; +} + +void ImageLoaderGL::generate(int index, const QString& fileName) +{ + mutex.lock(); + this->idx = index; + this->fileName = fileName; + this->size = size; + this->img = QImage(); + mutex.unlock(); + + if (!isRunning()) + start(); + else + { + // already running, wake up whenever ready + restart = true; + condition.wakeOne(); + } +} + +void ImageLoaderGL::lock() +{ + mutex.lock(); +} + +void ImageLoaderGL::unlock() +{ + mutex.unlock(); +} + +void ImageLoaderGL::run() +{ + for(;;) + { + // copy necessary data + mutex.lock(); + this->working = true; + QString fileName = this->fileName; + mutex.unlock(); + + QImage image = loadImage(fileName); + + // let everyone knows it is ready + mutex.lock(); + this->working = false; + this->img = image; + mutex.unlock(); + + // put to sleep + mutex.lock(); + if (!this->restart) + condition.wait(&mutex); + restart = false; + mutex.unlock(); + } +} + +QImage ImageLoaderGL::result() +{ + return img; +} + +//----------------------------------------------------------------------------- +//ImageLoader +//----------------------------------------------------------------------------- +QImage ImageLoaderByteArrayGL::loadImage(const QByteArray& raw) +{ + QImage image; + bool result = image.loadFromData(raw); + + switch(flow->performance) + { + case low: + image = image.scaledToWidth(128,Qt::SmoothTransformation); + break; + case medium: + image = image.scaledToWidth(196,Qt::SmoothTransformation); + break; + case high: + image = image.scaledToWidth(256,Qt::SmoothTransformation); + break; + case ultraHigh: + image = image.scaledToWidth(320,Qt::SmoothTransformation); + break; + } + + if(!result) + return QImage(); + + return image; +} + +ImageLoaderByteArrayGL::ImageLoaderByteArrayGL(YACReaderFlowGL * flow): +QThread(),flow(flow),restart(false), working(false), idx(-1) +{ + +} + +ImageLoaderByteArrayGL::~ImageLoaderByteArrayGL() +{ + mutex.lock(); + condition.wakeOne(); + mutex.unlock(); + wait(); +} + +bool ImageLoaderByteArrayGL::busy() const +{ + return isRunning() ? working : false; +} + +void ImageLoaderByteArrayGL::generate(int index, const QByteArray& raw) +{ + mutex.lock(); + this->idx = index; + this->rawData = raw; + this->size = size; + this->img = QImage(); + mutex.unlock(); + + if (!isRunning()) + start(); + else + { + // already running, wake up whenever ready + restart = true; + condition.wakeOne(); + } +} + +void ImageLoaderByteArrayGL::run() +{ + for(;;) + { + // copy necessary data + mutex.lock(); + this->working = true; + QByteArray raw = this->rawData; + mutex.unlock(); + + QImage image = loadImage(raw); + + // let everyone knows it is ready + mutex.lock(); + this->working = false; + this->img = image; + mutex.unlock(); + + // put to sleep + mutex.lock(); + if (!this->restart) + condition.wait(&mutex); + restart = false; + mutex.unlock(); + } +} + +QImage ImageLoaderByteArrayGL::result() +{ + return img; +} diff --git a/common/gl/yacreader_flow_gl.h b/common/gl/yacreader_flow_gl.h new file mode 100644 index 00000000..2fc37d51 --- /dev/null +++ b/common/gl/yacreader_flow_gl.h @@ -0,0 +1,383 @@ +//OpenGL Coverflow API by J.Roth +#ifndef __YACREADER_FLOW_GL_H +#define __YACREADER_FLOW_GL_H + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "pictureflow.h" //TODO mover los tipos de flow de sitio +#include "scroll_management.h" + +class ImageLoaderGL; +class QGLContext; +class WidgetLoader; +class ImageLoaderByteArrayGL; + +enum Performance +{ + low=0, + medium, + high, + ultraHigh +}; + +//Cover Vector +struct YACReader3DVector{ + float x; + float y; + float z; + float rot; +}; + +//the image/texture info struct +struct YACReader3DImage{ + QOpenGLTexture * texture; + //char name[256]; + + float width; + float height; + + int index; + + YACReader3DVector current; + YACReader3DVector animEnd; +}; + +struct Preset{ + /*** Animation Settings ***/ + //sets the speed of the animation + float animationStep; + //sets the acceleration of the animation + float animationSpeedUp; + //sets the maximum speed of the animation + float animationStepMax; + //sets the distance of view + float animationFadeOutDist; + //sets the rotation increasion + float preRotation; + //sets the light strenght on rotation + float viewRotateLightStrenght; + //sets the speed of the rotation + float viewRotateAdd; + //sets the speed of reversing the rotation + float viewRotateSub; + //sets the maximum view angle + float viewAngle; + + /*** Position Configuration ***/ + //the X Position of the Coverflow + float cfX; + //the Y Position of the Coverflow + float cfY; + //the Z Position of the Coverflow + float cfZ; + //the X Rotation of the Coverflow + float cfRX; + //the Y Rotation of the Coverflow + float cfRY; + //the Z Rotation of the Coverflow + float cfRZ; + //sets the rotation of each cover + float rotation; + //sets the distance between the covers + float xDistance; + //sets the distance between the centered and the non centered covers + float centerDistance; + //sets the pushback amount + float zDistance; + //sets the elevation amount + float yDistance; + + float zoom; +}; + +extern struct Preset defaultYACReaderFlowConfig; +extern struct Preset presetYACReaderFlowClassicConfig; +extern struct Preset presetYACReaderFlowStripeConfig; +extern struct Preset presetYACReaderFlowOverlappedStripeConfig; +extern struct Preset pressetYACReaderFlowUpConfig; +extern struct Preset pressetYACReaderFlowDownConfig; + +class YACReaderFlowGL : public QOpenGLWidget, public ScrollManagement +{ + Q_OBJECT +protected: + int timerId; + /*** System variables ***/ + YACReader3DImage dummy; + int viewRotateActive; + float stepBackup; + + /*functions*/ + void calcPos(YACReader3DImage & image, int pos); + void calcVector(YACReader3DVector & vector, int pos); + //returns true if the animation is finished for Current + bool animate(YACReader3DVector ¤tVector, YACReader3DVector &toVector); + void drawCover(const YACReader3DImage & image); + + void udpatePerspective(int width, int height); + + int updateCount; + WidgetLoader * loader; + int fontSize; + + QOpenGLTexture * defaultTexture; + QOpenGLTexture * markTexture; + QOpenGLTexture * readingTexture; + void initializeGL(); + void paintGL(); + void timerEvent(QTimerEvent *); + + //number of Covers + int numObjects; + int lazyPopulateObjects; + bool showMarks; + QVector loaded; + QVector marks; + + QVector images; + + bool hasBeenInitialized; + + Performance performance; + bool bUseVSync; + + /*** Animation Settings ***/ + Preset config; + + //sets/returns the curent selected cover + int currentSelected; + + //defines the position of the centered cover + YACReader3DVector centerPos; + + /*** Style ***/ + //sets the amount of shading of the covers in the back (0-1) + float shadingTop; + float shadingBottom; + + //sets the reflection strenght (0-1) + float reflectionUp; + float reflectionBottom; + + /*** System info ***/ + float viewRotate; + + //sets the updateInterval in ms + static int updateInterval; + + void startAnimationTimer(); + void stopAnimationTimer(); + +public: + + + /*Constructor*/ + YACReaderFlowGL(QWidget *parent = 0,struct Preset p = pressetYACReaderFlowDownConfig); + virtual ~YACReaderFlowGL(); + + //size; + QSize minimumSizeHint() const; + //QSize sizeHint() const; + + /*functions*/ + + //if called it moves the coverflow to the left + void showPrevious(); + //if called it moves the coverflow to the right + void showNext(); + //go to + void setCurrentIndex(int pos); + //must be called whenever the coverflow animation is stopped + void cleanupAnimation(); + //Draws the coverflow + void draw(); + //updates the coverflow + void updatePositions(); + //inserts a new item to the coverflow + //if item is set to a value > -1 it updates a already set value + //otherwise a new entry is set + void insert(char *name, QOpenGLTexture * texture, float x, float y, int item = -1); + //removes a item + virtual void remove(int item); + //replaces the texture of the item 'item' with Tex + void replace(char *name, QOpenGLTexture * texture, float x, float y, int item); + //create n covers with the default nu + void populate(int n); + /*Info*/ + //retuns the YACReader3DImage Struct of the current selected item + //to read title or textures + YACReader3DImage getCurrentSelected(); + + public slots: + void setCF_RX(int value); + //the Y Rotation of the Coverflow + void setCF_RY(int value); + //the Z Rotation of the Coverflow + void setCF_RZ(int value); + + //perspective + void setZoom(int zoom); + + void setRotation(int angle); + //sets the distance between the covers + void setX_Distance(int distance); + //sets the distance between the centered and the non centered covers + void setCenter_Distance(int distance); + //sets the pushback amount + void setZ_Distance(int distance); + + void setCF_Y(int value); + void setCF_Z(int value); + + void setY_Distance(int value); + + void setFadeOutDist(int value); + + void setLightStrenght(int value); + + void setMaxAngle(int value); + + void setPreset(const Preset & p); + + void setPerformance(Performance performance); + + void useVSync(bool b); + + virtual void updateImageData() = 0; + + void reset(); + void reload(); + + //interface with yacreaderlibrary, compatibility + void setShowMarks(bool value); + void setMarks(QVector marks); + void setMarkImage(QImage & image); + void markSlide(int index, YACReaderComicReadStatus status); + void unmarkSlide(int index); + void setSlideSize(QSize size); + void clear(); + void setCenterIndex(unsigned int index); + void showSlide(int index); + int centerIndex(); + void updateMarks(); + //void setFlowType(PictureFlow::FlowType flowType); + void render(); + + //void paintEvent(QPaintEvent *event); + void mouseDoubleClickEvent(QMouseEvent* event); + void mousePressEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent * event); + void keyPressEvent(QKeyEvent *event); + void resizeGL(int width, int height); + friend class ImageLoaderGL; + friend class ImageLoaderByteArrayGL; + +signals: + void centerIndexChanged(int); + void selected(unsigned int); +}; + +class YACReaderComicFlowGL : public YACReaderFlowGL +{ +public: + YACReaderComicFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig); + void setImagePaths(QStringList paths); + void updateImageData(); + void remove(int item); + void resortCovers(QList newOrder); + friend class ImageLoaderGL; +private: + ImageLoaderGL * worker; +protected: + QList paths; + +}; + +class YACReaderPageFlowGL : public YACReaderFlowGL +{ +public: + YACReaderPageFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig); + ~YACReaderPageFlowGL(); + void updateImageData(); + void populate(int n); + QVector imagesReady; + QVector rawImages; + QVector imagesSetted; + friend class ImageLoaderByteArrayGL; +private: + ImageLoaderByteArrayGL * worker; +}; + +class ImageLoaderGL : public QThread +{ +public: + ImageLoaderGL(YACReaderFlowGL * flow); + ~ImageLoaderGL(); + // returns FALSE if worker is still busy and can't take the task + bool busy() const; + void generate(int index, const QString& fileName); + void reset(){idx = -1;fileName="";} + int index() const { return idx; } + void lock(); + void unlock(); + QImage result(); + YACReaderFlowGL * flow; + GLuint resultTexture; + QImage loadImage(const QString& fileName); + +protected: + void run(); + +private: + QMutex mutex; + QWaitCondition condition; + + + bool restart; + bool working; + int idx; + QString fileName; + QSize size; + QImage img; +}; + +class ImageLoaderByteArrayGL : public QThread +{ +public: + ImageLoaderByteArrayGL(YACReaderFlowGL * flow); + ~ImageLoaderByteArrayGL(); + // returns FALSE if worker is still busy and can't take the task + bool busy() const; + void generate(int index, const QByteArray& raw); + void reset(){idx = -1; rawData.clear();} + int index() const { return idx; } + QImage result(); + YACReaderFlowGL * flow; + GLuint resultTexture; + QImage loadImage(const QByteArray& rawData); + +protected: + void run(); + +private: + QMutex mutex; + QWaitCondition condition; + + + bool restart; + bool working; + int idx; + QByteArray rawData; + QSize size; + QImage img; +}; + +#endif diff --git a/common/gl_legacy/yacreader_flow_gl.cpp b/common/gl_legacy/yacreader_flow_gl.cpp new file mode 100644 index 00000000..d367e20b --- /dev/null +++ b/common/gl_legacy/yacreader_flow_gl.cpp @@ -0,0 +1,1597 @@ +#include "yacreader_flow_gl.h" + +#include +#include +//#include + +#ifdef Q_OS_MAC + #include +#else + #include +#endif + +#include +#include +#include + +/*** Animation Settings ***/ + +/*** Position Configuration ***/ + +int YACReaderFlowGL::updateInterval = 16; + +struct Preset defaultYACReaderFlowConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 3.f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.01f, //View_rotate_add sets the speed of the rotation + 0.02f, //View_rotate_sub sets the speed of reversing the rotation + 20.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + 0.f, //CF_Y the Y Position of the Coverflow + -8.f, //CF_Z the Z Position of the Coverflow + + 15.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + -50.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + 0.0f, //Y_Distance sets the elevation amount + + 30.f //zoom level + +}; + +struct Preset presetYACReaderFlowClassicConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 2.f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 30.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + -40.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + 0.0f, //Y_Distance sets the elevation amount + + 22.f //zoom level + +}; + +struct Preset presetYACReaderFlowStripeConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 6.f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 4.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 30.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + 0.f, //Rotation sets the rotation of each cover + 1.1f, //X_Distance sets the distance between the covers + 0.2f, //Center_Distance sets the distance between the centered and the non centered covers + 0.01f, //Z_Distance sets the pushback amount + 0.0f, //Y_Distance sets the elevation amount + + 22.f //zoom level + +}; + +struct Preset presetYACReaderFlowOverlappedStripeConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 2.f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 30.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + 0.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + 0.0f, //Y_Distance sets the elevation amount + + 22.f //zoom level + +}; + +struct Preset pressetYACReaderFlowUpConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 2.5f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 5.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + -50.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + -0.1f, //Y_Distance sets the elevation amount + + 22.f //zoom level + +}; + +struct Preset pressetYACReaderFlowDownConfig = { + 0.08f, //Animation_step sets the speed of the animation + 1.5f, //Animation_speedup sets the acceleration of the animation + 0.1f, //Animation_step_max sets the maximum speed of the animation + 2.5f, //Animation_Fade_out_dis sets the distance of view + + 1.5f, //pre_rotation sets the rotation increasion + 3.f, //View_rotate_light_strenght sets the light strenght on rotation + 0.08f, //View_rotate_add sets the speed of the rotation + 0.08f, //View_rotate_sub sets the speed of reversing the rotation + 5.f, //View_angle sets the maximum view angle + + 0.f, //CF_X the X Position of the Coverflow + -0.2f, //CF_Y the Y Position of the Coverflow + -7.f, //CF_Z the Z Position of the Coverflow + + 0.f, //CF_RX the X Rotation of the Coverflow + 0.f, //CF_RY the Y Rotation of the Coverflow + 0.f, //CF_RZ the Z Rotation of the Coverflow + + -50.f, //Rotation sets the rotation of each cover + 0.18f, //X_Distance sets the distance between the covers + 1.f, //Center_Distance sets the distance between the centered and the non centered covers + 0.1f, //Z_Distance sets the pushback amount + 0.1f, //Y_Distance sets the elevation amount + + 22.f //zoom level +}; +/*Constructor*/ +YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p) + :QGLWidget(QGLFormat(QGL::SampleBuffers), parent),numObjects(0),lazyPopulateObjects(-1),bUseVSync(false),hasBeenInitialized(false) +{ + updateCount = 0; + config = p; + + currentSelected = 0; + + centerPos.x = 0.f; + centerPos.y = 0.f; + centerPos.z = 1.f; + centerPos.rot = 0.f; + + /*** Style ***/ + shadingTop = 0.8f; + shadingBottom = 0.02f; + reflectionUp = 0.f; + reflectionBottom = 0.6f; + + /*** System variables ***/ + numObjects = 0; + //CFImage Dummy; + viewRotate = 0.f; + viewRotateActive = 0; + stepBackup = config.animationStep/config.animationSpeedUp; + + /*QTimer * timer = new QTimer(); + connect(timer, SIGNAL(timeout()), this, SLOT(updateImageData())); + timer->start(70); + */ + + /*loader = new WidgetLoader(0,this); + loader->flow = this; + QThread * loaderThread = new QThread(parent); + + loader->moveToThread(loaderThread); + + loaderThread->start();*/ + + /*QGLFormat f = format(); + f.setVersion(2, 1); + f.setSwapInterval(0); + setFormat(f);*/ + + timerId = startTimer(updateInterval); + +} + +void YACReaderFlowGL::timerEvent(QTimerEvent * event) +{ + if(timerId == event->timerId()) + updateGL(); + + //if(!worker->isRunning()) + //worker->start(); +} + +void YACReaderFlowGL::startAnimationTimer() +{ + if(timerId == -1) + timerId = startTimer(updateInterval); +} + +void YACReaderFlowGL::stopAnimationTimer() +{ + if(timerId != -1) + { + killTimer(timerId); + timerId = -1; + } +} + +YACReaderFlowGL::~YACReaderFlowGL() +{ + +} + +QSize YACReaderFlowGL::minimumSizeHint() const +{ + return QSize(320, 200); +} + +/*QSize YACReaderFlowGL::sizeHint() const +{ + return QSize(320, 200); +}*/ + +void YACReaderFlowGL::initializeGL() +{ + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_COLOR_MATERIAL); + glShadeModel(GL_SMOOTH); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + defaultTexture = bindTexture(QImage(":/images/defaultCover.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption); + markTexture = bindTexture(QImage(":/images/readRibbon.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption); + readingTexture = bindTexture(QImage(":/images/readingRibbon.png"),GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption); + if(lazyPopulateObjects!=-1) + populate(lazyPopulateObjects); + + hasBeenInitialized = true; +} + +void YACReaderFlowGL::paintGL() +{ + /*glClearDepth(1.0); + glClearColor(1,1,1,1);*/ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + /*glLoadIdentity(); + glTranslatef(0.0, 0.0, -10.0); + glPopMatrix();*/ + if(numObjects>0) + { + updatePositions(); + udpatePerspective(width(),height()); + draw(); + } +} + +void YACReaderFlowGL::resizeGL(int width, int height) +{ + float pixelRatio = devicePixelRatio(); + fontSize = (width + height) * 0.010 * pixelRatio; + if(fontSize < 10) + fontSize = 10; + + //int side = qMin(width, height); + udpatePerspective(width,height); + + if(numObjects>0) + updatePositions(); +} + +void YACReaderFlowGL::udpatePerspective(int width, int height) +{ + float pixelRatio = devicePixelRatio(); + glViewport(0, 0, width*pixelRatio, height*pixelRatio); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + gluPerspective(20.0, GLdouble(width) / (float)height, 1.0, 200.0); + + glMatrixMode(GL_MODELVIEW); +} + +//----------------------------------------------------------------------------- +/*Private*/ +void YACReaderFlowGL::calcPos(YACReader3DImage & image, int pos) +{ + if(pos == 0){ + image.current = centerPos; + }else{ + if(pos > 0){ + image.current.x = (config.centerDistance)+(config.xDistance*pos); + image.current.y = config.yDistance*pos*-1; + image.current.z = config.zDistance*pos*-1; + image.current.rot = config.rotation; + }else{ + image.current.x = (config.centerDistance)*-1+(config.xDistance*pos); + image.current.y = config.yDistance*pos; + image.current.z = config.zDistance*pos; + image.current.rot = config.rotation*-1; + } + } + +} +void YACReaderFlowGL::calcVector(YACReader3DVector & vector, int pos) +{ + calcPos(dummy,pos); + + vector.x = dummy.current.x; + vector.y = dummy.current.y; + vector.z = dummy.current.z; + vector.rot = dummy.current.rot; +} + +bool YACReaderFlowGL::animate(YACReader3DVector & currentVector,YACReader3DVector & toVector) +{ + float rotDiff = toVector.rot-currentVector.rot; + float xDiff = toVector.x-currentVector.x; + float yDiff = toVector.y-currentVector.y; + float zDiff = toVector.z-currentVector.z; + + if(fabs(rotDiff) < 0.01 + && fabs(xDiff) < 0.001 + && fabs(yDiff) < 0.001 + && fabs(zDiff) < 0.001) + return true; + + //calculate and apply positions + currentVector.x = currentVector.x+(xDiff)*config.animationStep; + currentVector.y = currentVector.y+(yDiff)*config.animationStep; + currentVector.z = currentVector.z+(zDiff)*config.animationStep; + + if(fabs(rotDiff) > 0.01){ + currentVector.rot = currentVector.rot+(rotDiff)*(config.animationStep*config.preRotation); + } + else + { + viewRotateActive = 0; + } + + return false; +} +void YACReaderFlowGL::drawCover(const YACReader3DImage & image) +{ + float w = image.width; + float h = image.height; + + //fadeout + float opacity = 1-1/(config.animationFadeOutDist+config.viewRotateLightStrenght*fabs(viewRotate))*fabs(0-image.current.x); + + glLoadIdentity(); + glTranslatef(config.cfX,config.cfY,config.cfZ); + glRotatef(config.cfRX,1,0,0); + glRotatef(viewRotate*config.viewAngle+config.cfRY,0,1,0); + glRotatef(config.cfRZ,0,0,1); + + glTranslatef( image.current.x, image.current.y, image.current.z ); + + glPushMatrix(); + glRotatef(image.current.rot,0,1,0); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, image.texture); + + //calculate shading + float LShading = ((config.rotation != 0 )?((image.current.rot < 0)?1-1/config.rotation*image.current.rot:1):1); + float RShading = ((config.rotation != 0 )?((image.current.rot > 0)?1-1/(config.rotation*-1)*image.current.rot:1):1); + float LUP = shadingTop+(1-shadingTop)*LShading; + float LDOWN = shadingBottom+(1-shadingBottom)*LShading; + float RUP = shadingTop+(1-shadingTop)*RShading; + float RDOWN = shadingBottom+(1-shadingBottom)*RShading;; + + + //DrawCover + glBegin(GL_QUADS); + + //esquina inferior izquierda + glColor4f(LDOWN*opacity,LDOWN*opacity,LDOWN*opacity,1); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(w/2.f*-1.f, -0.5f, 0.f); + + //esquina inferior derecha + glColor4f(RDOWN*opacity,RDOWN*opacity,RDOWN*opacity,1); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(w/2.f, -0.5f, 0.f); + + //esquina superior derecha + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(w/2.f, -0.5f+h, 0.f); + + //esquina superior izquierda + glColor4f(LUP*opacity,LUP*opacity,LUP*opacity,1); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(w/2.f*-1.f, -0.5f+h, 0.f); + + glEnd(); + + + + //Draw reflection + glBegin(GL_QUADS); + + //esquina inferior izquierda + glColor4f(LUP*opacity*reflectionUp/2,LUP*opacity*reflectionUp/2,LUP*opacity*reflectionUp/2,1); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(w/2.f*-1.f, -0.5f-h, 0.f); + + //esquina inferior derecha + glColor4f(RUP*opacity*reflectionUp/2,RUP*opacity*reflectionUp/2,RUP*opacity*reflectionUp/2,1); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(w/2.f, -0.5f-h, 0.f); + + //esquina superior derecha + glColor4f(RDOWN*opacity/3,RDOWN*opacity/3,RDOWN*opacity/3,1); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(w/2.f, -0.5f, 0.f); + + //esquina superior izquierda + glColor4f(LDOWN*opacity/3,LDOWN*opacity/3,LDOWN*opacity/3,1); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(w/2.f*-1.f, -0.5f, 0.f); + + glEnd(); + glDisable(GL_TEXTURE_2D); + + if(showMarks && loaded[image.index] && marks[image.index] != Unread) + { + glEnable(GL_TEXTURE_2D); + if(marks[image.index] == Read) + glBindTexture(GL_TEXTURE_2D, markTexture); + else + glBindTexture(GL_TEXTURE_2D, readingTexture); + glBegin(GL_QUADS); + + //esquina inferior izquierda + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(w/2.f-0.2, -0.685f+h, 0.001f); + + //esquina inferior derecha + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(w/2.f-0.05, -0.685f+h, 0.001f); + + //esquina superior derecha + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(w/2.f-0.05, -0.485f+h, 0.001f); + + //esquina superior izquierda + glColor4f(RUP*opacity,RUP*opacity,RUP*opacity,1); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(w/2.f-0.2, -0.485f+h, 0.001f); + + glEnd(); + glDisable(GL_TEXTURE_2D); + } + + + glPopMatrix(); +} + +/*Public*/ +void YACReaderFlowGL::cleanupAnimation() +{ + config.animationStep = stepBackup; + viewRotateActive = 0; +} + +void YACReaderFlowGL::draw() +{ + int CS = currentSelected; + int count; + + + //Draw right Covers + for(count = numObjects-1;count > -1;count--){ + if(count > CS){ + drawCover(images[count]); + } + } + + //Draw left Covers + for(count = 0;count < numObjects-1;count++){ + if(count < CS){ + drawCover(images[count]); + } + } + + //Draw Center Cover + drawCover(images[CS]); + + //glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-(float(width())/height())/2.0,(float(width())/height())/2.0, 0, 1, -10, 10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glColor4f( 0.3f, 0.3f, 0.3f, 1.0f ); + + renderText(10, fontSize + 10,QString("%1/%2").arg(currentSelected+1).arg(numObjects),QFont("Arial", fontSize)); + + glEnable(GL_DEPTH_TEST); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} + +void YACReaderFlowGL::showPrevious() +{ + startAnimationTimer(); + + if(currentSelected > 0){ + + currentSelected--; + emit centerIndexChanged(currentSelected); + config.animationStep *= config.animationSpeedUp; + + if(config.animationStep > config.animationStepMax){ + config.animationStep = config.animationStepMax; + } + + if(viewRotateActive && viewRotate > -1){ + viewRotate -= config.viewRotateAdd; + } + + viewRotateActive = 1; + + } +} + +void YACReaderFlowGL::showNext() +{ + startAnimationTimer(); + + if(currentSelected < numObjects-1){ + + currentSelected++; + emit centerIndexChanged(currentSelected); + config.animationStep *= config.animationSpeedUp; + + if(config.animationStep > config.animationStepMax){ + config.animationStep = config.animationStepMax; + } + + if(viewRotateActive && viewRotate < 1){ + viewRotate += config.viewRotateAdd; + } + + viewRotateActive = 1; + } +} + +void YACReaderFlowGL::setCurrentIndex(int pos) +{ + if(!(pos>=0 && pos < images.length() && images.length()>0)) + return; + if(pos >= images.length() && images.length() > 0) + pos = images.length()-1; + + startAnimationTimer(); + + currentSelected = pos; + + config.animationStep *= config.animationSpeedUp; + + if(config.animationStep > config.animationStepMax){ + config.animationStep = config.animationStepMax; + } + + if(viewRotateActive && viewRotate < 1){ + viewRotate += config.viewRotateAdd; + } + + viewRotateActive = 1; + +} + +void YACReaderFlowGL::updatePositions() +{ + int count; + + bool stopAnimation = true; + for(count = numObjects-1;count > -1;count--){ + calcVector(images[count].animEnd,count-currentSelected); + if(!animate(images[count].current,images[count].animEnd)) + stopAnimation = false; + } + + //slowly reset view angle + if(!viewRotateActive){ + viewRotate += (0-viewRotate)*config.viewRotateSub; + } + + if(fabs (images[currentSelected].current.x - images[currentSelected].animEnd.x) < 1)//viewRotate < 0.2) + { + cleanupAnimation(); + if(updateCount >= 0) //TODO parametrizar + { + + updateCount = 0; + updateImageData(); + } + else + updateCount++; + } + else + updateCount++; + + if(stopAnimation) + stopAnimationTimer(); + +} + +void YACReaderFlowGL::insert(const char *name, GLuint texture, float x, float y,int item) +{ + startAnimationTimer(); + + Q_UNUSED(name) + //set a new entry + if(item == -1){ + images.push_back(YACReader3DImage()); + + item = numObjects; + numObjects++; + + calcVector(images[item].current,item); + images[item].current.z = images[item].current.z-1; + } + + images[item].texture = texture; + images[item].width = x; + images[item].height = y; + images[item].index = item; + //strcpy(cfImages[item].name,name); +} + +void YACReaderFlowGL::remove(int item) +{ + if(item < 0 || item >= images.size()) + return; + + startAnimationTimer(); + + loaded.remove(item); + marks.remove(item); + + //reposition current selection + if(item <= currentSelected && currentSelected != 0){ + currentSelected--; + } + + int count = item; + while(count <= numObjects-2){ + images[count].index--; + count++; + } + images.removeAt(item); + + + numObjects--; +} + +/*Info*/ +YACReader3DImage YACReaderFlowGL::getCurrentSelected() +{ + return images[currentSelected]; +} + +void YACReaderFlowGL::replace(const char *name, GLuint texture, float x, float y,int item) +{ + startAnimationTimer(); + + Q_UNUSED(name) + if(images[item].index == item) + { + images[item].texture = texture; + images[item].width = x; + images[item].height = y; + loaded[item]=true; + } + else + loaded[item]=false; +} + +void YACReaderFlowGL::populate(int n) +{ + emit centerIndexChanged(0); + float x = 1; + float y = 1 * (700.f/480.0f); + int i; + + for(i = 0;i(n,false); + //marks = QVector(n,false); + + + + //worker->start(); +} + +void YACReaderFlowGL::reset() +{ + startAnimationTimer(); + + currentSelected = 0; + loaded.clear(); + + for(int i = 0;iwidth(); + int height = this->height(); + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + //float sideX = ((float(width)/height)/2)*1.5; + //float sideY = 0.5*1.5; + gluPerspective(zoom, (float)width / (float)height, 1.0, 200.0); + //glOrtho(-sideX, sideX, -sideY+0.2, +sideY+0.2, 4, 11.0); + + glMatrixMode(GL_MODELVIEW); + +} + +void YACReaderFlowGL::setRotation(int angle) +{ + startAnimationTimer(); + + config.rotation = -angle; +} +//sets the distance between the covers +void YACReaderFlowGL::setX_Distance(int distance) +{ + startAnimationTimer(); + + config.xDistance = distance/100.0; +} +//sets the distance between the centered and the non centered covers +void YACReaderFlowGL::setCenter_Distance(int distance) +{ + startAnimationTimer(); + + config.centerDistance = distance/100.0; +} +//sets the pushback amount +void YACReaderFlowGL::setZ_Distance(int distance) +{ + startAnimationTimer(); + + config.zDistance = distance/100.0; +} + +void YACReaderFlowGL::setCF_Y(int value) +{ + startAnimationTimer(); + + config.cfY = value/100.0; +} + +void YACReaderFlowGL::setCF_Z(int value) +{ + startAnimationTimer(); + + config.cfZ = value; +} + +void YACReaderFlowGL::setY_Distance(int value) +{ + startAnimationTimer(); + + config.yDistance = value / 100.0; +} + +void YACReaderFlowGL::setFadeOutDist(int value) +{ + startAnimationTimer(); + + config.animationFadeOutDist = value; +} + +void YACReaderFlowGL::setLightStrenght(int value) +{ + startAnimationTimer(); + + config.viewRotateLightStrenght = value; +} + +void YACReaderFlowGL::setMaxAngle(int value) +{ + startAnimationTimer(); + + config.viewAngle = value; +} + +void YACReaderFlowGL::setPreset(const Preset & p) +{ + startAnimationTimer(); + + config = p; +} + +void YACReaderFlowGL::setPerformance(Performance performance) +{ + if(this->performance != performance) + { + startAnimationTimer(); + + this->performance = performance; + reload(); + } +} + +void YACReaderFlowGL::useVSync(bool b) +{/*if(bUseVSync != b) + { + bUseVSync = b; + if(b) + { + QGLFormat f = format(); + //f.setVersion(2, 1); + f.setSwapInterval(1); + setFormat(f); + } + else + { + QGLFormat f = format(); + //f.setVersion(2, 1); + f.setSwapInterval(0); + setFormat(f); + } + reset(); + }*/ +} +void YACReaderFlowGL::setShowMarks(bool value) +{ + startAnimationTimer(); + + showMarks = value; +} +void YACReaderFlowGL::setMarks(QVector marks) +{ + startAnimationTimer(); + + this->marks = marks; +} +void YACReaderFlowGL::setMarkImage(QImage & image) +{ + Q_UNUSED(image); + //qué pasa la primera vez?? + //deleteTexture(markTexture); + //markTexture = bindTexture(image,GL_TEXTURE_2D,GL_RGBA,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption); +} +void YACReaderFlowGL::markSlide(int index, YACReaderComicReadStatus status) +{ + startAnimationTimer(); + + marks[index] = status; +} +void YACReaderFlowGL::unmarkSlide(int index) +{ + startAnimationTimer(); + + marks[index] = YACReader::Unread; +} +void YACReaderFlowGL::setSlideSize(QSize size) +{ + Q_UNUSED(size); + //TODO calcular el tamaño del widget +} +void YACReaderFlowGL::clear() +{ + reset(); +} + +void YACReaderFlowGL::setCenterIndex(unsigned int index) +{ + setCurrentIndex(index); +} +void YACReaderFlowGL::showSlide(int index) +{ + setCurrentIndex(index); +} +int YACReaderFlowGL::centerIndex() +{ + return currentSelected; +} +void YACReaderFlowGL::updateMarks() +{ + //do nothing +} +/*void YACReaderFlowGL::setFlowType(FlowType flowType) +{ + //TODO esperar a que se reimplemente flowtype +}*/ +void YACReaderFlowGL::render() +{ + //do nothing +} + +//EVENTOS +void YACReaderFlowGL::wheelEvent(QWheelEvent * event) +{ + Movement m = getMovement(event); + switch (m) { + case None: + return; + case Forward: + showNext(); + break; + case Backward: + showPrevious(); + break; + default: + break; + } +} + +void YACReaderFlowGL::keyPressEvent(QKeyEvent *event) +{ + if(event->key() == Qt::Key_Left) + { + if(event->modifiers() == Qt::ControlModifier) + setCurrentIndex((currentSelected-10<0)?0:currentSelected-10); + else + showPrevious(); + event->accept(); + return; + } + + if(event->key() == Qt::Key_Right) + { + if(event->modifiers() == Qt::ControlModifier) + setCurrentIndex((currentSelected+10>=numObjects)?numObjects-1:currentSelected+10); + else + showNext(); + event->accept(); + return; + } + + if(event->key() == Qt::Key_Up) + { + //emit selected(centerIndex()); + return; + } + + event->ignore(); +} + +void YACReaderFlowGL::mousePressEvent(QMouseEvent *event) +{ + if(event->button() == Qt::LeftButton) + { + float x,y; + float pixelRatio = devicePixelRatio(); + x = event->x()*pixelRatio; + y = event->y()*pixelRatio; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY, winZ; + GLdouble posX, posY, posZ; + + glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); + glGetDoublev( GL_PROJECTION_MATRIX, projection ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + winX = (float)x; + winY = (float)viewport[3] - (float)y; + glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); + + gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); + + if(posX >= 0.5) + { + //int index = currentSelected+1; + //while((cfImages[index].current.x-cfImages[index].width/(2.0*config.rotation)) < posX) + // index++; + //setCurrentIndex(index-1); + showNext(); + } + else if(posX <=-0.5) + showPrevious(); + } else + QGLWidget::mousePressEvent(event); +} + +void YACReaderFlowGL::mouseDoubleClickEvent(QMouseEvent* event) +{ + float x,y; + float pixelRatio = devicePixelRatio(); + x = event->x()*pixelRatio; + y = event->y()*pixelRatio; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY, winZ; + GLdouble posX, posY, posZ; + + glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); + glGetDoublev( GL_PROJECTION_MATRIX, projection ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + winX = (float)x; + winY = (float)viewport[3] - (float)y; + glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); + + gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); + + if(posX <= 0.5 && posX >= -0.5) + { + emit selected(centerIndex()); + event->accept(); + } + +} + +YACReaderComicFlowGL::YACReaderComicFlowGL(QWidget *parent,struct Preset p ) + :YACReaderFlowGL(parent,p) +{ + worker = new ImageLoaderGL(this); + worker->flow = this; +} + +void YACReaderComicFlowGL::setImagePaths(QStringList paths) +{ + worker->reset(); + reset(); + numObjects = 0; + if(lazyPopulateObjects!=-1 || hasBeenInitialized) + YACReaderFlowGL::populate(paths.size()); + lazyPopulateObjects = paths.size(); + this->paths = paths; + //numObjects = paths.size(); +} + + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +void YACReaderComicFlowGL::updateImageData() +{ + // can't do anything, wait for the next possibility + if(worker->busy()) + return; + + // set image of last one + int idx = worker->index(); + if( idx >= 0 && !worker->result().isNull()) + { + if(!loaded[idx]) + { + float x = 1; + QImage img = worker->result(); + GLuint cover; + if(performance == high || performance == ultraHigh) + cover = bindTexture(img, GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption); + else + cover = bindTexture(img, GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption); + float y = 1 * (float(img.height())/img.width()); + QString s = "cover"; + replace(s.toLocal8Bit().data(), cover, x, y,idx); + /*CFImages[idx].width = x; + CFImages[idx].height = y; + CFImages[idx].img = worker->resultTexture; + strcpy(CFImages[idx].name,"cover");*/ + //loaded[idx] = true; + //numImagesLoaded++; + } + } + + // try to load only few images on the left and right side + // i.e. all visible ones plus some extra + int count=8; + switch(performance) + { + case low: + count = 8; + break; + case medium: + count = 10; + break; + case high: + count = 12; + break; + case ultraHigh: + count = 14; + break; + } + int * indexes = new int[2*count+1]; + int center = currentSelected; + indexes[0] = center; + for(int j = 0; j < count; j++) + { + indexes[j*2+1] = center+j+1; + indexes[j*2+2] = center-j-1; + } + for(int c = 0; c < 2*count+1; c++) + { + int i = indexes[c]; + if((i >= 0) && (i < numObjects)) + if(!loaded[i])//slide(i).isNull()) + { + //loader->loadTexture(i); + //loaded[i]=true; + // schedule thumbnail generation + if(paths.size()>0) + { + QString fname = paths.at(i); + //loaded[i]=true; + + worker->generate(i, fname); + } + delete[] indexes; + return; + } + } + delete[] indexes; +} + +void YACReaderComicFlowGL::remove(int item) +{ + worker->lock(); + worker->reset(); + YACReaderFlowGL::remove(item); + if(item >= 0 && item < paths.size()) + paths.removeAt(item); + worker->unlock(); +} + +void YACReaderComicFlowGL::resortCovers(QList newOrder) +{ + worker->lock(); + worker->reset();//is this necesary? + startAnimationTimer(); + QList pathsNew; + QVector loadedNew; + QVector marksNew; + QVector imagesNew; + + int index = 0; + foreach (int i, newOrder) { + pathsNew << paths.at(i); + loadedNew << loaded.at(i); + marksNew << marks.at(i); + imagesNew << images.at(i); + imagesNew.last().index = index++; + } + + paths = pathsNew; + loaded = loadedNew; + marks = marksNew; + images = imagesNew; + + worker->unlock(); +} + +YACReaderPageFlowGL::YACReaderPageFlowGL(QWidget *parent,struct Preset p ) + :YACReaderFlowGL(parent,p) +{ + worker = new ImageLoaderByteArrayGL(this); + worker->flow = this; +} + +YACReaderPageFlowGL::~YACReaderPageFlowGL() +{ + this->killTimer(timerId); + //worker->deleteLater(); + rawImages.clear(); +} + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +void YACReaderPageFlowGL::updateImageData() +{ + // can't do anything, wait for the next possibility + if(worker->busy()) + return; + + // set image of last one + int idx = worker->index(); + if( idx >= 0 && !worker->result().isNull()) + { + if(!loaded[idx]) + { + float x = 1; + QImage img = worker->result(); + GLuint cover; + if(performance == high || performance == ultraHigh) + cover = bindTexture(img, GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption); + else + cover = bindTexture(img, GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption); + float y = 1 * (float(img.height())/img.width()); + QString s = "cover"; + replace(s.toLocal8Bit().data(), cover, x, y,idx); + loaded[idx] = true; + + } + } + + // try to load only few images on the left and right side + // i.e. all visible ones plus some extra + int count=8; + switch(performance) + { + case low: + count = 8; + break; + case medium: + count = 10; + break; + case high: + count = 12; + break; + case ultraHigh: + count = 14; + break; + } + int * indexes = new int[2*count+1]; + int center = currentSelected; + indexes[0] = center; + for(int j = 0; j < count; j++) + { + indexes[j*2+1] = center+j+1; + indexes[j*2+2] = center-j-1; + } + for(int c = 0; c < 2*count+1; c++) + { + int i = indexes[c]; + if((i >= 0) && (i < numObjects)) + if(rawImages.size()>0) + + if(!loaded[i]&&imagesReady[i])//slide(i).isNull()) + { + worker->generate(i, rawImages.at(i)); + + delete[] indexes; + return; + } + } + delete[] indexes; +} + +void YACReaderPageFlowGL::populate(int n) +{ + worker->reset(); + if(lazyPopulateObjects!=-1 || hasBeenInitialized) + YACReaderFlowGL::populate(n); + lazyPopulateObjects = n; + imagesReady = QVector (n,false); + rawImages = QVector (n); + imagesSetted = QVector (n,false); //puede sobrar +} + + +//----------------------------------------------------------------------------- +//ImageLoader +//----------------------------------------------------------------------------- +QImage ImageLoaderGL::loadImage(const QString& fileName) +{ + QImage image; + bool result = image.load(fileName); + + switch(flow->performance) + { + case low: + image = image.scaledToWidth(200,Qt::SmoothTransformation); + break; + case medium: + image = image.scaledToWidth(256,Qt::SmoothTransformation); + break; + case high: + image = image.scaledToWidth(320,Qt::SmoothTransformation); + break; + + } + + if(!result) + return QImage(); + + return image; +} + +ImageLoaderGL::ImageLoaderGL(YACReaderFlowGL * flow): +QThread(),flow(flow),restart(false), working(false), idx(-1) +{ + +} + +ImageLoaderGL::~ImageLoaderGL() +{ + mutex.lock(); + condition.wakeOne(); + mutex.unlock(); + wait(); +} + +bool ImageLoaderGL::busy() const +{ + return isRunning() ? working : false; +} + +void ImageLoaderGL::generate(int index, const QString& fileName) +{ + mutex.lock(); + this->idx = index; + this->fileName = fileName; + this->size = size; + this->img = QImage(); + mutex.unlock(); + + if (!isRunning()) + start(); + else + { + // already running, wake up whenever ready + restart = true; + condition.wakeOne(); + } +} + +void ImageLoaderGL::lock() +{ + mutex.lock(); +} + +void ImageLoaderGL::unlock() +{ + mutex.unlock(); +} + +void ImageLoaderGL::run() +{ + for(;;) + { + // copy necessary data + mutex.lock(); + this->working = true; + QString fileName = this->fileName; + mutex.unlock(); + + QImage image = loadImage(fileName); + + // let everyone knows it is ready + mutex.lock(); + this->working = false; + this->img = image; + mutex.unlock(); + + // put to sleep + mutex.lock(); + if (!this->restart) + condition.wait(&mutex); + restart = false; + mutex.unlock(); + } +} + +QImage ImageLoaderGL::result() +{ + return img; +} + +//----------------------------------------------------------------------------- +//ImageLoader +//----------------------------------------------------------------------------- +QImage ImageLoaderByteArrayGL::loadImage(const QByteArray& raw) +{ + QImage image; + bool result = image.loadFromData(raw); + + switch(flow->performance) + { + case low: + image = image.scaledToWidth(128,Qt::SmoothTransformation); + break; + case medium: + image = image.scaledToWidth(196,Qt::SmoothTransformation); + break; + case high: + image = image.scaledToWidth(256,Qt::SmoothTransformation); + break; + case ultraHigh: + image = image.scaledToWidth(320,Qt::SmoothTransformation); + break; + } + + if(!result) + return QImage(); + + return image; +} + +ImageLoaderByteArrayGL::ImageLoaderByteArrayGL(YACReaderFlowGL * flow): +QThread(),flow(flow),restart(false), working(false), idx(-1) +{ + +} + +ImageLoaderByteArrayGL::~ImageLoaderByteArrayGL() +{ + mutex.lock(); + condition.wakeOne(); + mutex.unlock(); + wait(); +} + +bool ImageLoaderByteArrayGL::busy() const +{ + return isRunning() ? working : false; +} + +void ImageLoaderByteArrayGL::generate(int index, const QByteArray& raw) +{ + mutex.lock(); + this->idx = index; + this->rawData = raw; + this->size = size; + this->img = QImage(); + mutex.unlock(); + + if (!isRunning()) + start(); + else + { + // already running, wake up whenever ready + restart = true; + condition.wakeOne(); + } +} + +void ImageLoaderByteArrayGL::run() +{ + for(;;) + { + // copy necessary data + mutex.lock(); + this->working = true; + QByteArray raw = this->rawData; + mutex.unlock(); + + QImage image = loadImage(raw); + + // let everyone knows it is ready + mutex.lock(); + this->working = false; + this->img = image; + mutex.unlock(); + + // put to sleep + mutex.lock(); + if (!this->restart) + condition.wait(&mutex); + restart = false; + mutex.unlock(); + } +} + +QImage ImageLoaderByteArrayGL::result() +{ + return img; +} + diff --git a/common/gl_legacy/yacreader_flow_gl.h b/common/gl_legacy/yacreader_flow_gl.h new file mode 100644 index 00000000..ba025253 --- /dev/null +++ b/common/gl_legacy/yacreader_flow_gl.h @@ -0,0 +1,380 @@ +//OpenGL Coverflow API by J.Roth +#ifndef __YACREADER_FLOW_GL_H +#define __YACREADER_FLOW_GL_H + +#include +#include +#include +#include + +#include +#include +#include + +#include "pictureflow.h" //TODO mover los tipos de flow de sitio +#include "scroll_management.h" + +class ImageLoaderGL; +class QGLContext; +class WidgetLoader; +class ImageLoaderByteArrayGL; + +enum Performance +{ + low=0, + medium, + high, + ultraHigh +}; + +//Cover Vector +struct YACReader3DVector{ + float x; + float y; + float z; + float rot; +}; + +//the image/texture info struct +struct YACReader3DImage{ + GLuint texture; + //char name[256]; + + float width; + float height; + + int index; + + YACReader3DVector current; + YACReader3DVector animEnd; +}; + +struct Preset{ + /*** Animation Settings ***/ + //sets the speed of the animation + float animationStep; + //sets the acceleration of the animation + float animationSpeedUp; + //sets the maximum speed of the animation + float animationStepMax; + //sets the distance of view + float animationFadeOutDist; + //sets the rotation increasion + float preRotation; + //sets the light strenght on rotation + float viewRotateLightStrenght; + //sets the speed of the rotation + float viewRotateAdd; + //sets the speed of reversing the rotation + float viewRotateSub; + //sets the maximum view angle + float viewAngle; + + /*** Position Configuration ***/ + //the X Position of the Coverflow + float cfX; + //the Y Position of the Coverflow + float cfY; + //the Z Position of the Coverflow + float cfZ; + //the X Rotation of the Coverflow + float cfRX; + //the Y Rotation of the Coverflow + float cfRY; + //the Z Rotation of the Coverflow + float cfRZ; + //sets the rotation of each cover + float rotation; + //sets the distance between the covers + float xDistance; + //sets the distance between the centered and the non centered covers + float centerDistance; + //sets the pushback amount + float zDistance; + //sets the elevation amount + float yDistance; + + float zoom; +}; + +extern struct Preset defaultYACReaderFlowConfig; +extern struct Preset presetYACReaderFlowClassicConfig; +extern struct Preset presetYACReaderFlowStripeConfig; +extern struct Preset presetYACReaderFlowOverlappedStripeConfig; +extern struct Preset pressetYACReaderFlowUpConfig; +extern struct Preset pressetYACReaderFlowDownConfig; + +class YACReaderFlowGL : public QGLWidget, public ScrollManagement +{ + Q_OBJECT +protected: + int timerId; + /*** System variables ***/ + YACReader3DImage dummy; + int viewRotateActive; + float stepBackup; + + /*functions*/ + void calcPos(YACReader3DImage & image, int pos); + void calcVector(YACReader3DVector & vector, int pos); + //returns true if the animation is finished for Current + bool animate(YACReader3DVector ¤tVector, YACReader3DVector &toVector); + void drawCover(const YACReader3DImage & image); + + void udpatePerspective(int width, int height); + + int updateCount; + WidgetLoader * loader; + int fontSize; + + GLuint defaultTexture; + GLuint markTexture; + GLuint readingTexture; + void initializeGL(); + void paintGL(); + void timerEvent(QTimerEvent *); + + //number of Covers + int numObjects; + int lazyPopulateObjects; + bool showMarks; + QVector loaded; + QVector marks; + QVector images; + bool hasBeenInitialized; + + Performance performance; + bool bUseVSync; + + /*** Animation Settings ***/ + Preset config; + + //sets/returns the curent selected cover + int currentSelected; + + //defines the position of the centered cover + YACReader3DVector centerPos; + + /*** Style ***/ + //sets the amount of shading of the covers in the back (0-1) + float shadingTop; + float shadingBottom; + + //sets the reflection strenght (0-1) + float reflectionUp; + float reflectionBottom; + + /*** System info ***/ + float viewRotate; + + //sets the updateInterval in ms + static int updateInterval; + + void startAnimationTimer(); + void stopAnimationTimer(); + +public: + + + /*Constructor*/ + YACReaderFlowGL(QWidget *parent = 0,struct Preset p = pressetYACReaderFlowDownConfig); + virtual ~YACReaderFlowGL(); + + //size; + QSize minimumSizeHint() const; + //QSize sizeHint() const; + + /*functions*/ + + //if called it moves the coverflow to the left + void showPrevious(); + //if called it moves the coverflow to the right + void showNext(); + //go to + void setCurrentIndex(int pos); + //must be called whenever the coverflow animation is stopped + void cleanupAnimation(); + //Draws the coverflow + void draw(); + //updates the coverflow + void updatePositions(); + //inserts a new item to the coverflow + //if item is set to a value > -1 it updates a already set value + //otherwise a new entry is set + void insert(const char *name, GLuint Tex, float x, float y,int item = -1); + //removes a item + virtual void remove(int item); + //replaces the texture of the item 'item' with Tex + void replace(const char *name, GLuint Tex, float x, float y,int item); + //create n covers with the default nu + void populate(int n); + /*Info*/ + //retuns the YACReader3DImage Struct of the current selected item + //to read title or textures + YACReader3DImage getCurrentSelected(); + + public slots: + void setCF_RX(int value); + //the Y Rotation of the Coverflow + void setCF_RY(int value); + //the Z Rotation of the Coverflow + void setCF_RZ(int value); + + //perspective + void setZoom(int zoom); + + void setRotation(int angle); + //sets the distance between the covers + void setX_Distance(int distance); + //sets the distance between the centered and the non centered covers + void setCenter_Distance(int distance); + //sets the pushback amount + void setZ_Distance(int distance); + + void setCF_Y(int value); + void setCF_Z(int value); + + void setY_Distance(int value); + + void setFadeOutDist(int value); + + void setLightStrenght(int value); + + void setMaxAngle(int value); + + void setPreset(const Preset & p); + + void setPerformance(Performance performance); + + void useVSync(bool b); + + virtual void updateImageData() = 0; + + void reset(); + void reload(); + + //interface with yacreaderlibrary, compatibility + void setShowMarks(bool value); + void setMarks(QVector marks); + void setMarkImage(QImage & image); + void markSlide(int index, YACReaderComicReadStatus status); + void unmarkSlide(int index); + void setSlideSize(QSize size); + void clear(); + void setCenterIndex(unsigned int index); + void showSlide(int index); + int centerIndex(); + void updateMarks(); + //void setFlowType(PictureFlow::FlowType flowType); + void render(); + + //void paintEvent(QPaintEvent *event); + void mouseDoubleClickEvent(QMouseEvent* event); + void mousePressEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent * event); + void keyPressEvent(QKeyEvent *event); + void resizeGL(int width, int height); + friend class ImageLoaderGL; + friend class ImageLoaderByteArrayGL; + +signals: + void centerIndexChanged(int); + void selected(unsigned int); +}; + +class YACReaderComicFlowGL : public YACReaderFlowGL +{ +public: + YACReaderComicFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig); + void setImagePaths(QStringList paths); + void updateImageData(); + void remove(int item); + void resortCovers(QList newOrder); + friend class ImageLoaderGL; +private: + ImageLoaderGL * worker; +protected: + QList paths; + +}; + +class YACReaderPageFlowGL : public YACReaderFlowGL +{ +public: + YACReaderPageFlowGL(QWidget *parent = 0,struct Preset p = defaultYACReaderFlowConfig); + ~YACReaderPageFlowGL(); + void updateImageData(); + void populate(int n); + QVector imagesReady; + QVector rawImages; + QVector imagesSetted; + friend class ImageLoaderByteArrayGL; +private: + ImageLoaderByteArrayGL * worker; +}; + +class ImageLoaderGL : public QThread +{ +public: + ImageLoaderGL(YACReaderFlowGL * flow); + ~ImageLoaderGL(); + // returns FALSE if worker is still busy and can't take the task + bool busy() const; + void generate(int index, const QString& fileName); + void reset(){idx = -1;fileName="";} + int index() const { return idx; } + void lock(); + void unlock(); + QImage result(); + YACReaderFlowGL * flow; + GLuint resultTexture; + QImage loadImage(const QString& fileName); + +protected: + void run(); + +private: + QMutex mutex; + QWaitCondition condition; + + + bool restart; + bool working; + int idx; + QString fileName; + QSize size; + QImage img; +}; + +class ImageLoaderByteArrayGL : public QThread +{ +public: + ImageLoaderByteArrayGL(YACReaderFlowGL * flow); + ~ImageLoaderByteArrayGL(); + // returns FALSE if worker is still busy and can't take the task + bool busy() const; + void generate(int index, const QByteArray& raw); + void reset(){idx = -1; rawData.clear();} + int index() const { return idx; } + QImage result(); + YACReaderFlowGL * flow; + GLuint resultTexture; + QImage loadImage(const QByteArray& rawData); + +protected: + void run(); + +private: + QMutex mutex; + QWaitCondition condition; + + + bool restart; + bool working; + int idx; + QByteArray rawData; + QSize size; + QImage img; +}; + +#endif diff --git a/common/http_worker.cpp b/common/http_worker.cpp new file mode 100644 index 00000000..eabdcc6c --- /dev/null +++ b/common/http_worker.cpp @@ -0,0 +1,65 @@ +#include "http_worker.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define PREVIOUS_VERSION "6.0.0" + +HttpWorker::HttpWorker(const QString & urlString) + :QThread(),url(urlString),_error(false),_timeout(false) +{ + +} + +void HttpWorker::get() +{ + this->start(); +} + +QByteArray HttpWorker::getResult() +{ + return result; +} + +bool HttpWorker::wasValid() +{ + return !_error; +} + +bool HttpWorker::wasTimeout() +{ + return _timeout; +} + +void HttpWorker::run() +{ + QNetworkAccessManager manager; + QEventLoop q; + QTimer tT; + + tT.setSingleShot(true); + connect(&tT, SIGNAL(timeout()), &q, SLOT(quit())); + connect(&manager, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit())); + QNetworkReply *reply = manager.get(QNetworkRequest(url)); + + tT.start(5000); // 5s timeout + q.exec(); + + if(tT.isActive()){ + // download complete + _error = !(reply->error() == QNetworkReply::NoError); + result = reply->readAll(); + emit dataReady(result); + tT.stop(); + } else { + _timeout = true; + emit timeout(); + } +} diff --git a/common/http_worker.h b/common/http_worker.h new file mode 100644 index 00000000..10034717 --- /dev/null +++ b/common/http_worker.h @@ -0,0 +1,32 @@ +#ifndef __HTTP_WORKER_H +#define __HTTP_WORKER_H + +#include +#include +#include +#include +#include "yacreader_global.h" + + class HttpWorker : public QThread + { + Q_OBJECT + public: + HttpWorker(const QString & urlString); + public slots: + void get(); + QByteArray getResult(); + bool wasValid(); + bool wasTimeout(); + private: + void run(); + QUrl url; + int httpGetId; + QByteArray result; + bool _error; + bool _timeout; + signals: + void dataReady(const QByteArray &); + void timeout(); + }; + +#endif diff --git a/common/library_item.cpp b/common/library_item.cpp new file mode 100644 index 00000000..e69de29b diff --git a/common/library_item.h b/common/library_item.h new file mode 100644 index 00000000..2f6b8d9f --- /dev/null +++ b/common/library_item.h @@ -0,0 +1,16 @@ +#ifndef __LIBRARY_ITEM_H +#define __LIBRARY_ITEM_H + +#include + +class LibraryItem +{ +public: + virtual bool isDir() = 0; + QString name; + QString path; + qulonglong parentId; + qulonglong id; +}; + +#endif \ No newline at end of file diff --git a/common/onstart_flow_selection_dialog.cpp b/common/onstart_flow_selection_dialog.cpp new file mode 100644 index 00000000..57247ce0 --- /dev/null +++ b/common/onstart_flow_selection_dialog.cpp @@ -0,0 +1,54 @@ +#include "onstart_flow_selection_dialog.h" + +#include +#include +#include + +OnStartFlowSelectionDialog::OnStartFlowSelectionDialog(QWidget * parent) + :QDialog(parent) +{ + setModal(true); + QPushButton * acceptHW = new QPushButton(this); + connect(acceptHW,SIGNAL(clicked()),this,SLOT(accept())); + QPushButton * rejectHW = new QPushButton(this); //and use SW flow + connect(rejectHW,SIGNAL(clicked()),this,SLOT(reject())); + + acceptHW->setGeometry(90,165,110,118); + acceptHW->setFlat(true); + acceptHW->setAutoFillBackground(true); + rejectHW->setGeometry(464,165,110,118); + rejectHW->setFlat(true); + rejectHW->setAutoFillBackground(true); + + QPalette paletteHW; + QLocale locale = this->locale(); + QLocale::Language language = locale.language(); + + /*if(language == QLocale::Spanish) + paletteHW.setBrush(acceptHW->backgroundRole(), QBrush(QImage(":/images/useNewFlowButton_es.png"))); + else + paletteHW.setBrush(acceptHW->backgroundRole(), QBrush(QImage(":/images/useNewFlowButton.png")));*/ + + + paletteHW.setBrush(acceptHW->backgroundRole(), QBrush(QImage(":/images/nonexxx.png"))); + acceptHW->setPalette(paletteHW); + QPalette paletteSW; + paletteSW.setBrush(rejectHW->backgroundRole(), QBrush(QImage(":/images/nonexxx.png"))); + rejectHW->setPalette(paletteSW); + //QHBoxLayout * layout = new QHBoxLayout; + //layout->addWidget(acceptHW); + //layout->addWidget(rejectHW); + + QPalette palette; + if(language == QLocale::Spanish) + palette.setBrush(this->backgroundRole(), QBrush(QImage(":/images/onStartFlowSelection_es.png"))); + else + palette.setBrush(this->backgroundRole(), QBrush(QImage(":/images/onStartFlowSelection.png"))); + + setPalette(palette); + + + //setLayout(layout); + + resize(664,371); +} diff --git a/common/onstart_flow_selection_dialog.h b/common/onstart_flow_selection_dialog.h new file mode 100644 index 00000000..c333b48b --- /dev/null +++ b/common/onstart_flow_selection_dialog.h @@ -0,0 +1,13 @@ +#ifndef ONSTART_FLOW_SELECTION_DIALOG_H +#define ONSTART_FLOW_SELECTION_DIALOG_H + +#include + +class OnStartFlowSelectionDialog : public QDialog +{ + Q_OBJECT +public: + OnStartFlowSelectionDialog(QWidget * parent = 0); +}; + +#endif \ No newline at end of file diff --git a/common/opengl_checker.cpp b/common/opengl_checker.cpp new file mode 100644 index 00000000..d62bfac1 --- /dev/null +++ b/common/opengl_checker.cpp @@ -0,0 +1,69 @@ +#include "opengl_checker.h" + +#include "QsLog.h" + +OpenGLChecker::OpenGLChecker() + :compatibleOpenGLVersion(true) +{ + QOpenGLContext * openGLContext = new QOpenGLContext(); + openGLContext->create(); + + if(!openGLContext->isValid()) + { + compatibleOpenGLVersion = false; + description = "unable to create QOpenGLContext"; + } + + QSurfaceFormat format = openGLContext->format(); + + int majorVersion = format.majorVersion(); + int minorVersion = format.minorVersion(); + QString type; + + switch (format.renderableType()) { + case QSurfaceFormat::OpenGL: + type = "desktop"; + break; + + case QSurfaceFormat::OpenGLES: + type = "OpenGL ES"; + break; + + case QSurfaceFormat::OpenVG: + type = "OpenVG"; + + default: case QSurfaceFormat::DefaultRenderableType: + type = "unknown"; + break; + } + + delete openGLContext; + + description = QString("%1.%2 %3").arg(majorVersion).arg(minorVersion).arg(type); + + if(format.renderableType() != QSurfaceFormat::OpenGL) //Desktop OpenGL + compatibleOpenGLVersion = false; + +#ifdef Q_OS_WIN //TODO check Qt version, and set this values depending on the use of QOpenGLWidget or QGLWidget + static const int majorTargetVersion = 1; + static const int minorTargetVersion = 4; +#else + static const int majorTargetVersion = 2; + static const int minorTargetVersion = 0; +#endif + + if(majorVersion < majorTargetVersion) + compatibleOpenGLVersion = false; + if(majorVersion == majorTargetVersion && minorVersion < minorTargetVersion) + compatibleOpenGLVersion = false; +} + +QString OpenGLChecker::textVersionDescription() +{ + return description; +} + +bool OpenGLChecker::hasCompatibleOpenGLVersion() +{ + return compatibleOpenGLVersion; +} diff --git a/common/opengl_checker.h b/common/opengl_checker.h new file mode 100644 index 00000000..cce9772f --- /dev/null +++ b/common/opengl_checker.h @@ -0,0 +1,17 @@ +#ifndef OPENGL_CHECKER_H +#define OPENGL_CHECKER_H + +#include + +class OpenGLChecker +{ +public: + OpenGLChecker(); + bool hasCompatibleOpenGLVersion(); + QString textVersionDescription(); +private: + QString description; + bool compatibleOpenGLVersion; +}; + +#endif // OPENGL_CHECKER_H diff --git a/common/pdf_comic.h b/common/pdf_comic.h new file mode 100644 index 00000000..7c5d7f48 --- /dev/null +++ b/common/pdf_comic.h @@ -0,0 +1,22 @@ +#ifndef PDF_COMIC_H +#define PDF_COMIC_H + +#include +#include + +class MacOSXPDFComic +{ +public: + MacOSXPDFComic(); + ~MacOSXPDFComic(); + bool openComic(const QString & path); + void closeComic(); + unsigned int numPages(); + QImage getPage(const int page); + void releaseLastPageData(); +private: + void * document; + void * lastPageData; +}; + +#endif // PDF_COMIC_H diff --git a/common/pdf_comic.mm b/common/pdf_comic.mm new file mode 100644 index 00000000..7f9b32ce --- /dev/null +++ b/common/pdf_comic.mm @@ -0,0 +1,117 @@ +#include "pdf_comic.h" + +#import +#import +#import + +#include "QsLog.h" +#include "QsLogDest.h" + + +MacOSXPDFComic::MacOSXPDFComic() +{ + +} + +MacOSXPDFComic::~MacOSXPDFComic() +{ + CGPDFDocumentRelease((CGPDFDocumentRef)document); +} + +bool MacOSXPDFComic::openComic(const QString &path) +{ + + CFURLRef pdfFileUrl; + CFStringRef str; + str=CFStringCreateWithCString( kCFAllocatorDefault,path.toUtf8().data(),kCFStringEncodingUTF8); + pdfFileUrl=CFURLCreateWithFileSystemPath( kCFAllocatorDefault,str,kCFURLPOSIXPathStyle,true ); + + CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfFileUrl); + + document = pdf; + + CFRelease(str); + CFRelease(pdfFileUrl); + + return true; +} + +void MacOSXPDFComic::closeComic() +{ + //CGPDFDocumentRelease((CGPDFDocumentRef)document); +} + +unsigned int MacOSXPDFComic::numPages() +{ + return (int)CGPDFDocumentGetNumberOfPages((CGPDFDocumentRef)document); +} + +QImage MacOSXPDFComic::getPage(const int pageNum) +{ + CGPDFPageRef page = CGPDFDocumentGetPage((CGPDFDocumentRef)document, pageNum+1); + // Changed this line for the line above which is a generic line + //CGPDFPageRef page = [self getPage:page_number]; + + + + CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); + int width = 1200; + + //NSLog(@"-----%f",pageRect.size.width); + CGFloat pdfScale = float(width)/pageRect.size.width; + + pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale); + pageRect.origin = CGPointZero; + + CGColorSpaceRef genericColorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef bitmapContext = CGBitmapContextCreate(NULL, + pageRect.size.width, + pageRect.size.height, + 8, 0, + genericColorSpace, + kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little + ); + + CGContextSetInterpolationQuality(bitmapContext, kCGInterpolationHigh); + CGContextSetRenderingIntent(bitmapContext, kCGRenderingIntentDefault); + CGContextSetRGBFillColor( bitmapContext, 1.0, 1.0, 1.0, 1.0 ); + CGContextFillRect( bitmapContext, CGContextGetClipBoundingBox( bitmapContext )); + + //CGContextTranslateCTM( bitmapContext, 0, pageRect.size.height ); + //CGContextScaleCTM( bitmapContext, 1.0, -1.0 ); + + CGContextConcatCTM(bitmapContext, CGAffineTransformMakeScale(pdfScale, pdfScale)); + + + /*CGAffineTransform pdfXfm = CGPDFPageGetDrawingTransform( page, kCGPDFMediaBox, CGRectMake(pageRect.origin.x, pageRect.origin.y, pageRect.size.width, pageRect.size.height) , 0, true ); + */ + //CGContextConcatCTM( bitmapContext, pdfXfm ); + + CGContextDrawPDFPage(bitmapContext, page); + + CGImageRef image = CGBitmapContextCreateImage(bitmapContext); + + QImage qtImage; + + CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(image)); + + lastPageData = (void *)dataRef; + + const uchar *bytes = (const uchar *)CFDataGetBytePtr(dataRef); + + qtImage = QImage(bytes, pageRect.size.width, pageRect.size.height, QImage::Format_ARGB32); + + CGImageRelease(image); + //CFRelease(dataRef); + CGContextRelease(bitmapContext); + //CGPDFPageRelease(page); + CGColorSpaceRelease(genericColorSpace); + + return qtImage; +} + +void MacOSXPDFComic::releaseLastPageData() +{ + CFRelease((CFDataRef)lastPageData); +} + diff --git a/common/pictureflow.cpp b/common/pictureflow.cpp new file mode 100644 index 00000000..d92f4299 --- /dev/null +++ b/common/pictureflow.cpp @@ -0,0 +1,1409 @@ +/* + PictureFlow - animated image show widget + http://pictureflow.googlecode.com + + Copyright (C) 2008 Ariya Hidayat (ariya@kde.org) + Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "pictureflow.h" + +// detect Qt version +#if QT_VERSION >= 0x040000 +#define PICTUREFLOW_QT4 +#elif QT_VERSION >= 0x030000 +#define PICTUREFLOW_QT3 +#elif QT_VERSION >= 235 +#define PICTUREFLOW_QT2 +#else +#error PictureFlow widgets need Qt 2, Qt 3 or Qt 4 +#endif + +#ifdef PICTUREFLOW_QT4 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#ifdef PICTUREFLOW_QT3 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define qMax(x,y) ((x) > (y)) ? (x) : (y) +#define qMin(x,y) ((x) < (y)) ? (x) : (y) + +#define QVector QValueVector + +#define toImage convertToImage +#define contains find +#define modifiers state +#define ControlModifier ControlButton +#endif + +#ifdef PICTUREFLOW_QT2 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define qMax(x,y) ((x) > (y)) ? (x) : (y) +#define qMin(x,y) ((x) < (y)) ? (x) : (y) + +#define QVector QArray + +#define toImage convertToImage +#define contains find +#define modifiers state +#define ControlModifier ControlButton +#define flush flushX +#endif + +// for fixed-point arithmetic, we need minimum 32-bit long +// long long (64-bit) might be useful for multiplication and division +typedef long PFreal; +#define PFREAL_SHIFT 10 +#define PFREAL_ONE (1 << PFREAL_SHIFT) + +#define IANGLE_MAX 1024 +#define IANGLE_MASK 1023 + +inline PFreal fmul(PFreal a, PFreal b) +{ + return ((long long)(a))*((long long)(b)) >> PFREAL_SHIFT; +} + +inline PFreal fdiv(PFreal num, PFreal den) +{ + long long p = (long long)(num) << (PFREAL_SHIFT*2); + long long q = p / (long long)den; + long long r = q >> PFREAL_SHIFT; + + return r; +} + +inline PFreal fsin(int iangle) +{ + // warning: regenerate the table if IANGLE_MAX and PFREAL_SHIFT are changed! + static const PFreal tab[] = { + 3, 103, 202, 300, 394, 485, 571, 652, + 726, 793, 853, 904, 947, 980, 1004, 1019, + 1023, 1018, 1003, 978, 944, 901, 849, 789, + 721, 647, 566, 479, 388, 294, 196, 97, + -4, -104, -203, -301, -395, -486, -572, -653, + -727, -794, -854, -905, -948, -981, -1005, -1020, + -1024, -1019, -1004, -979, -945, -902, -850, -790, + -722, -648, -567, -480, -389, -295, -197, -98, + 3 + }; + + while(iangle < 0) + iangle += IANGLE_MAX; + iangle &= IANGLE_MASK; + + int i = (iangle >> 4); + PFreal p = tab[i]; + PFreal q = tab[(i+1)]; + PFreal g = (q - p); + return p + g * (iangle-i*16)/16; +} + +inline PFreal fcos(int iangle) +{ + return fsin(iangle + (IANGLE_MAX >> 2)); +} + +/* ---------------------------------------------------------- + +PictureFlowState stores the state of all slides, i.e. all the necessary +information to be able to render them. + +PictureFlowAnimator is responsible to move the slides during the +transition between slides, to achieve the effect similar to Cover Flow, +by changing the state. + +PictureFlowSoftwareRenderer (or PictureFlowOpenGLRenderer) is +the actual 3-d renderer. It should render all slides given the state +(an instance of PictureFlowState). + +Instances of all the above three classes are stored in +PictureFlowPrivate. + +------------------------------------------------------- */ + +struct SlideInfo +{ + int slideIndex; + int angle; + PFreal cx; + PFreal cy; + int blend; +}; + +class PictureFlowState +{ +public: + PictureFlowState(int angle=50, float spacingRatio=0); + ~PictureFlowState(); + + void reposition(); + void reset(); + + QRgb backgroundColor; + int slideWidth; + int slideHeight; + PictureFlow::ReflectionEffect reflectionEffect; + QVector slideImages; + + QVector marks; + bool showMarks; + QImage mark; + + int angle; + int rawAngle; + int spacing; + float spacingRatio; + PFreal offsetX; + PFreal offsetY; + + SlideInfo centerSlide; + QVector leftSlides; + QVector rightSlides; + int centerIndex; +}; + +class PictureFlowAnimator +{ +public: + PictureFlowAnimator(); + PictureFlowState* state; + + void start(int slide); + void stop(int slide); + void update(); + + int target; + int step; + int frame; + QTimer animateTimer; + bool animating; +}; + +class PictureFlowAbstractRenderer +{ +public: + PictureFlowAbstractRenderer(): state(0), dirty(false), widget(0) {} + virtual ~PictureFlowAbstractRenderer() {} + + PictureFlowState* state; + bool dirty; + QWidget* widget; + + virtual void init() = 0; + virtual void paint() = 0; +}; + +class PictureFlowSoftwareRenderer: public PictureFlowAbstractRenderer +{ +public: + PictureFlowSoftwareRenderer(); + ~PictureFlowSoftwareRenderer(); + + virtual void init(); + virtual void paint(); + void render(); + + +private: + QSize size; + QRgb bgcolor; + int effect; + QImage buffer; + QVector rays; + QImage* blankSurface; +#ifdef PICTUREFLOW_QT4 + QCache surfaceCache; + QHash imageHash; +#endif +#ifdef PICTUREFLOW_QT3 + QCache surfaceCache; + QMap imageHash; +#endif +#ifdef PICTUREFLOW_QT2 + QCache surfaceCache; + QIntDict imageHash; +#endif + + + void renderSlides(); + QRect renderSlide(const SlideInfo &slide, int col1 = -1, int col2 = -1); + QImage* surface(int slideIndex); +}; + +// ------------- PictureFlowState --------------------------------------- + +PictureFlowState::PictureFlowState(int a, float sr): +backgroundColor(0), slideWidth(150), slideHeight(200), +reflectionEffect(PictureFlow::BlurredReflection), centerIndex(0) , rawAngle(a), spacingRatio(sr) +{ +} + +PictureFlowState::~PictureFlowState() +{ + for(int i = 0; i < (int)slideImages.count(); i++) + delete slideImages[i]; +} + +// readjust the settings, call this when slide dimension is changed +void PictureFlowState::reposition() +{ + // angle = 70 * IANGLE_MAX / 360; // approx. 70 degrees tilted + angle = rawAngle * IANGLE_MAX / 360; + offsetX = slideWidth/2 * (PFREAL_ONE-fcos(angle)); + offsetY = slideWidth/2 * fsin(angle); + offsetX += slideWidth * PFREAL_ONE; + offsetY += slideWidth * PFREAL_ONE / 3; + if(rawAngle < 45) + offsetX += offsetX/4; + if(angle>0) + spacing = slideWidth * 0.35; + else + spacing = slideWidth*spacingRatio + slideWidth*(spacingRatio?0.10:0.2); +} + +// adjust slides so that they are in "steady state" position +void PictureFlowState::reset() +{ + centerSlide.angle = 0; + centerSlide.cx = 0; + centerSlide.cy = 0; + centerSlide.slideIndex = centerIndex; + centerSlide.blend = 256; + + if(angle == 0 && spacingRatio) + leftSlides.resize(4); + else + leftSlides.resize(6); + for(int i = 0; i < (int)leftSlides.count(); i++) + { + SlideInfo& si = leftSlides[i]; + si.angle = angle; + si.cx = -(offsetX + spacing*(i)*PFREAL_ONE); + si.cy = offsetY; + si.slideIndex = centerIndex-1-i; + si.blend = 200; + if(i == (int)leftSlides.count()-2) + si.blend = 128; + if(i == (int)leftSlides.count()-1) + si.blend = 0; + } + if(angle==0 && spacingRatio) + rightSlides.resize(4); + else + rightSlides.resize(6); + for(int i = 0; i < (int)rightSlides.count(); i++) + { + SlideInfo& si = rightSlides[i]; + si.angle = -angle; + si.cx = offsetX + spacing*(i)*PFREAL_ONE; + si.cy = offsetY; + si.slideIndex = centerIndex+1+i; + si.blend = 200; + if(i == (int)rightSlides.count()-2) + si.blend = 128; + if(i == (int)rightSlides.count()-1) + si.blend = 0; + } +} + +// ------------- PictureFlowAnimator --------------------------------------- + +PictureFlowAnimator::PictureFlowAnimator(): +state(0), target(0), step(0), frame(0), animating(false) +{ +} + +void PictureFlowAnimator::start(int slide) +{ + target = slide; + if(!animateTimer.isActive() && state) + { + step = (target < state->centerSlide.slideIndex) ? -1 : 1; + animateTimer.setSingleShot(true); + animateTimer.start(30); //TODO comprobar rendimiento, originalmente era 30 + animating = true; + } +} + +void PictureFlowAnimator::stop(int slide) +{ + step = 0; + target = slide; + frame = slide << 16; + animateTimer.stop(); + animating = false; +} + +void PictureFlowAnimator::update() +{ + /*if(!animateTimer.isActive()) + return;*/ + if(step == 0) + return; + if(!state) + return; + + int speed = 16384/4; //TODO comprobar rendimiento, originalmente era /4 + +#if 1 + // deaccelerate when approaching the target + const int max = 2 * 65536; //TODO cambiado de 2 * a 4 * comprobar rendimiento + + int fi = frame; + fi -= (target << 16); + if(fi < 0) + fi = -fi; + fi = qMin(fi, max); + + int ia = IANGLE_MAX * (fi-max/2) / (max*2); + speed = 512 + 16384 * (PFREAL_ONE+fsin(ia))/PFREAL_ONE; +#endif + + frame += speed*step; + + int index = frame >> 16; + int pos = frame & 0xffff; + int neg = 65536 - pos; + int tick = (step < 0) ? neg : pos; + PFreal ftick = (tick * PFREAL_ONE) >> 16; + + if(step < 0) + index++; + + if(state->centerIndex != index) + { + state->centerIndex = index; + frame = index << 16; + state->centerSlide.slideIndex = state->centerIndex; + for(int i = 0; i < (int)state->leftSlides.count(); i++) + state->leftSlides[i].slideIndex = state->centerIndex-1-i; + for(int i = 0; i < (int)state->rightSlides.count(); i++) + state->rightSlides[i].slideIndex = state->centerIndex+1+i; + } + + state->centerSlide.angle = (step * tick * state->angle) >> 16; + state->centerSlide.cx = -step * fmul(state->offsetX, ftick); + state->centerSlide.cy = fmul(state->offsetY, ftick); + + if(state->centerIndex == target) + { + stop(target); + state->reset(); + return; + } + + for(int i = 0; i < (int)state->leftSlides.count(); i++) + { + SlideInfo& si = state->leftSlides[i]; + si.angle = state->angle; + si.cx = -(state->offsetX + state->spacing*(i)*PFREAL_ONE + step*state->spacing*ftick); + si.cy = state->offsetY; + } + + for(int i = 0; i < (int)state->rightSlides.count(); i++) + { + SlideInfo& si = state->rightSlides[i]; + si.angle = -state->angle; + si.cx = state->offsetX + state->spacing*(i)*PFREAL_ONE - step*state->spacing*ftick; + si.cy = state->offsetY; + } + + if(step > 0) + { + PFreal ftick = (neg * PFREAL_ONE) >> 16; + state->rightSlides[0].angle = -(neg * state->angle) >> 16; + state->rightSlides[0].cx = fmul(state->offsetX, ftick); + state->rightSlides[0].cy = fmul(state->offsetY, ftick); + } + else + { + PFreal ftick = (pos * PFREAL_ONE) >> 16; + state->leftSlides[0].angle = (pos * state->angle) >> 16; + state->leftSlides[0].cx = -fmul(state->offsetX, ftick); + state->leftSlides[0].cy = fmul(state->offsetY, ftick); + } + + // must change direction ? + if(target < index) if(step > 0) + step = -1; + if(target > index) if(step < 0) + step = 1; + + // the first and last slide must fade in/fade out + int nleft = state->leftSlides.count(); + int nright = state->rightSlides.count(); + int fade = pos / 256; + + for(int index = 0; index < nleft; index++) + { + int blend = 200; + if(index == nleft-1) + blend = (step > 0) ? 0 : 128-fade/2; + if(index == nleft-2) + blend = (step > 0) ? 128-fade/2 : 200-(0.5625*fade/2); + if(index == nleft-3) + blend = (step > 0) ? 200-(0.5625*fade/2) : 200; + if(index == 0) + blend = (step > 0) ? 200 : 200 + 56-(0.4375*fade/2) ; + state->leftSlides[index].blend = blend; + } + for(int index = 0; index < nright; index++) + { + int blend = (index < nright-2) ? 200 : 128; + if(index == nright-1) + blend = (step > 0) ? fade/2 : 0; + if(index == nright-2) + blend = (step > 0) ? 128+(0.5625*fade/2) : (0.5625*fade/2); + if(index == nright-3) + blend = (step > 0) ? 200 : 128+(0.5625*fade/2); + if(index == 0) + blend = (step > 0) ? 200 + (0.4375*fade/2) : 200; + state->rightSlides[index].blend = blend; + } + + state->centerSlide.blend = (step > 0) ? 256 - (0.4375*fade/2) : 200 + (0.4375*fade/2); + +} + +// ------------- PictureFlowSoftwareRenderer --------------------------------------- + +PictureFlowSoftwareRenderer::PictureFlowSoftwareRenderer(): +PictureFlowAbstractRenderer(), size(0,0), bgcolor(0), effect(-1), blankSurface(0) +{ +#ifdef PICTUREFLOW_QT3 + surfaceCache.setAutoDelete(true); +#endif +} + +PictureFlowSoftwareRenderer::~PictureFlowSoftwareRenderer() +{ + surfaceCache.clear(); + buffer = QImage(); + delete blankSurface; +} + +void PictureFlowSoftwareRenderer::paint() +{ + if(!widget) + return; + + if(widget->size() != size) + init(); + + if(state->backgroundColor != bgcolor) + { + bgcolor = state->backgroundColor; + surfaceCache.clear(); + } + + if((int)(state->reflectionEffect) != effect) + { + effect = (int)state->reflectionEffect; + surfaceCache.clear(); + } + + if(dirty) + render(); + + QPainter painter(widget); + painter.drawImage(QPoint(0,0), buffer); +} + +void PictureFlowSoftwareRenderer::init() +{ + if(!widget) + return; + + surfaceCache.clear(); + blankSurface = 0; + + size = widget->size(); + int ww = size.width(); + int wh = size.height(); + int w = (ww+1)/2; + int h = (wh+1)/2; + if(h<10)//TODO a partir de qué h es seguro?? + return; + +#ifdef PICTUREFLOW_QT4 + buffer = QImage(ww, wh, QImage::Format_RGB32); +#endif +#if defined(PICTUREFLOW_QT3) || defined(PICTUREFLOW_QT2) + buffer.create(ww, wh, 32); +#endif + buffer.fill(bgcolor); + + rays.resize(w*2); + for(int i = 0; i < w; i++) + { + PFreal gg = ((PFREAL_ONE >> 1) + i * PFREAL_ONE) / (2*h); + rays[w-i-1] = -gg; + rays[w+i] = gg; + } + + dirty = true; +} + +// TODO: optimize this with lookup tables +static QRgb blendColor(QRgb c1, QRgb c2, int blend) +{ + int r = qRed(c1) * blend/256 + qRed(c2)*(256-blend)/256; + int g = qGreen(c1) * blend/256 + qGreen(c2)*(256-blend)/256; + int b = qBlue(c1) * blend/256 + qBlue(c2)*(256-blend)/256; + return qRgb(r, g, b); +} + + +static QImage* prepareSurface(const QImage* slideImage, int w, int h, QRgb bgcolor, +PictureFlow::ReflectionEffect reflectionEffect) +{ + + int iw,ih; + iw = slideImage->width(); + ih = slideImage->height(); + int psw,psh; + if(iw>ih) + { + psw = w; + psh = w * (1.0*ih/iw); + } + else + { + int h1=h; + psw = h1 * (1.0*iw/ih); + psh = h1; + + while(psw>w) + { + h1-=2; + psw = h1 * (1.0*iw/ih); + psh = h1; + } + } + w = psw; + +#ifdef PICTUREFLOW_QT4 + Qt::TransformationMode mode = Qt::SmoothTransformation; + QImage img = slideImage->scaled(psw, psh, Qt::IgnoreAspectRatio, mode); +#endif +#if defined(PICTUREFLOW_QT3) || defined(PICTUREFLOW_QT2) + QImage img = slideImage->smoothScale(w, h); +#endif + + // slightly larger, to accomodate for the reflection + int hs = h * 2; + int hofs = h / 3; + + // offscreen buffer: black is sweet +#ifdef PICTUREFLOW_QT4 + QImage* result = new QImage(hs, w, QImage::Format_RGB32); +#endif +#if defined(PICTUREFLOW_QT3) || defined(PICTUREFLOW_QT2) + QImage* result = new QImage; + result->create(hs, w, 32); +#endif + result->fill(bgcolor); + + // transpose the image, this is to speed-up the rendering + // because we process one column at a time + // (and much better and faster to work row-wise, i.e in one scanline) + int lhof = (h-psh); + //int lwof = (w-psw)/2; + for(int x = 0; x < psw; x++) + for(int y = 0; y < psh; y++) + + result->setPixel(hofs + y + lhof , x, img.pixel(x, y)); + + if(reflectionEffect != PictureFlow::NoReflection) + { + // create the reflection + int ht = hs - (h+hofs); + int hte = ht; + for(int x = 0; x < psw; x++) + for(int y = 0; y < ht; y++) + { + QRgb color; + if(ysetPixel(h+hofs + y, x,blendColor(color,bgcolor,80*(hte-y)/hte)); + } + + + } + + return result; +} + +QImage* PictureFlowSoftwareRenderer::surface(int slideIndex) +{ + if(!state) + return 0; + if(slideIndex < 0) + return 0; + if(slideIndex >= (int)state->slideImages.count()) + return 0; + +#ifdef PICTUREFLOW_QT4 + int key = slideIndex; +#endif +#if defined(PICTUREFLOW_QT3) || defined(PICTUREFLOW_QT2) + QString key = QString::number(slideIndex); +#endif + + QImage* img = state->slideImages.at(slideIndex); + + bool empty = img ? img->isNull() : true; + if(empty) + { + surfaceCache.remove(key); + imageHash.remove(slideIndex); + if(!blankSurface) + { + int sw = state->slideWidth; + int sh = state->slideHeight; + +#ifdef PICTUREFLOW_QT4 + QImage img = QImage(sw, sh, QImage::Format_RGB32); + + QPainter painter(&img); + QPoint p1(sw*4/10, 0); + QPoint p2(sw*6/10, sh); + QLinearGradient linearGrad(p1, p2); + linearGrad.setColorAt(0, Qt::black); + linearGrad.setColorAt(1, Qt::white); + painter.setBrush(linearGrad); + painter.fillRect(0, 0, sw, sh, QBrush(linearGrad)); + + + painter.end(); +#endif +#if defined(PICTUREFLOW_QT3) || defined(PICTUREFLOW_QT2) + QPixmap pixmap(sw, sh, 32); + QPainter painter(&pixmap); + painter.fillRect(pixmap.rect(), QColor(192,192,192)); + painter.fillRect(5, 5, sw-10, sh-10, QColor(64,64,64)); + painter.end(); + QImage img = pixmap.convertToImage(); +#endif + + blankSurface = prepareSurface(&img, sw, sh, bgcolor, state->reflectionEffect); + } + return blankSurface; + } + +#ifdef PICTUREFLOW_QT4 + bool exist = imageHash.contains(slideIndex); + if(exist) + if(img == imageHash.find(slideIndex).value()) +#endif +#ifdef PICTUREFLOW_QT3 + bool exist = imageHash.find(slideIndex) != imageHash.end(); + if(exist) + if(img == imageHash.find(slideIndex).data()) +#endif +#ifdef PICTUREFLOW_QT2 + if(img == imageHash[slideIndex]) +#endif + if(surfaceCache.contains(key)) + return surfaceCache[key]; + + + QImage* sr = prepareSurface(img, state->slideWidth, state->slideHeight, bgcolor, state->reflectionEffect); + //check if this slide must be marked + //if(marks[slideIndex]) + if(state->showMarks) + { + if(state->marks[slideIndex]) + { + QPainter painter(sr); + painter.setPen(QColor(255,0,0).rgb()); + int sh = sr->height(); + int jInit = sh*4/5; + int iInit = state->slideHeight+state->slideHeight/3; + /*for(int j = jInit; j < sh; j ++) + { + for(int i = iInit-(j-jInit); i < iInit; i ++) + { + + painter.drawPoint(i,j); + } + }*/ + painter.drawImage(QRect(iInit-(sh-jInit),jInit,sh-jInit,sh-jInit),state->mark); + } + } + surfaceCache.insert(key, sr); + imageHash.insert(slideIndex, img); + + return sr; +} + +// Renders a slide to offscreen buffer. Returns a rect of the rendered area. +// col1 and col2 limit the column for rendering. +QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1, int col2) +{ + int blend = slide.blend; + if(!blend) + return QRect(); + + QImage* src = surface(slide.slideIndex); + if(!src) + return QRect(); + + QRect rect(0, 0, 0, 0); + + int sw = src->height(); + int sh = src->width(); + int h = buffer.height(); + int w = buffer.width(); + + if(col1 > col2) + { + int c = col2; + col2 = col1; + col1 = c; + } + + col1 = (col1 >= 0) ? col1 : 0; + col2 = (col2 >= 0) ? col2 : w-1; + col1 = qMin(col1, w-1); + col2 = qMin(col2, w-1); + + int zoom = 100; + int distance = h * 100 / zoom; + PFreal sdx = fcos(slide.angle); + PFreal sdy = fsin(slide.angle); + PFreal xs = slide.cx - state->slideWidth * sdx/2; + PFreal ys = slide.cy - state->slideWidth * sdy/2; + PFreal dist = distance * PFREAL_ONE; + + int xi = qMax((PFreal)0, ((w*PFREAL_ONE/2) + fdiv(xs*h, dist+ys)) >> PFREAL_SHIFT); + if(xi >= w) + return rect; + + bool flag = false; + rect.setLeft(xi); + for(int x = qMax(xi, col1); x <= col2; x++) + { + PFreal hity = 0; + PFreal fk = rays[x]; + if(sdy) + { + fk = fk - fdiv(sdx,sdy); + hity = -fdiv((rays[x]*distance - slide.cx + slide.cy*sdx/sdy), fk); + } + + dist = distance*PFREAL_ONE + hity; + if(dist < 0) + continue; + + PFreal hitx = fmul(dist, rays[x]); + PFreal hitdist = fdiv(hitx - slide.cx, sdx); + + int column = sw/2 + (hitdist >> PFREAL_SHIFT); + if(column >= sw) + break; + if(column < 0) + continue; + + rect.setRight(x); + if(!flag) + rect.setLeft(x); + flag = true; + + int y1 = h/2; + int y2 = y1+ 1; + QRgb* pixel1 = (QRgb*)(buffer.scanLine(y1)) + x; + QRgb* pixel2 = (QRgb*)(buffer.scanLine(y2)) + x; + QRgb pixelstep = pixel2 - pixel1; + + int center = (sh/2); + int dy = dist / h; + int p1 = center*PFREAL_ONE - dy/2; + int p2 = center*PFREAL_ONE + dy/2; + + const QRgb *ptr = (const QRgb*)(src->scanLine(column)); + if(blend == 256) + while((y1 >= 0) && (y2 < h) && (p1 >= 0)) + { + *pixel1 = ptr[p1 >> PFREAL_SHIFT]; + *pixel2 = ptr[p2 >> PFREAL_SHIFT]; + p1 -= dy; + p2 += dy; + y1--; + y2++; + pixel1 -= pixelstep; + pixel2 += pixelstep; + } + else + while((y1 >= 0) && (y2 < h) && (p1 >= 0)) + { + QRgb c1 = ptr[p1 >> PFREAL_SHIFT]; + QRgb c2 = ptr[p2 >> PFREAL_SHIFT]; + *pixel1 = blendColor(c1, bgcolor, blend); + *pixel2 = blendColor(c2, bgcolor, blend); + p1 -= dy; + p2 += dy; + y1--; + y2++; + pixel1 -= pixelstep; + pixel2 += pixelstep; + } + } + + rect.setTop(0); + rect.setBottom(h-1); + return rect; +} + +void PictureFlowSoftwareRenderer::renderSlides() +{ + int nleft = state->leftSlides.count(); + int nright = state->rightSlides.count(); + + QRect r = renderSlide(state->centerSlide); + int c1 = r.left(); + int c2 = r.right(); + + for(int index = 0; index < nleft; index++) + { + QRect rs = renderSlide(state->leftSlides[index], 0, c1-1); + if(!rs.isEmpty()) + c1 = rs.left(); + } + for(int index = 0; index < nright; index++) + { + QRect rs = renderSlide(state->rightSlides[index], c2+1, buffer.width()); + if(!rs.isEmpty()) + c2 = rs.right(); + } +} + +// Render the slides. Updates only the offscreen buffer. +void PictureFlowSoftwareRenderer::render() +{ + buffer.fill(state->backgroundColor); + renderSlides(); + if(state->slideImages.size()>0) + { + int size = buffer.width() * 0.015; + int start = buffer.width() * 0.010; + + QPainter painter(&buffer); + painter.setPen(QColor(255,255,255).rgb()-state->backgroundColor); + painter.setFont(QFont("Arial", start+size*0.5)); + painter.drawText(start , start+size, QString().setNum(state->centerIndex+1)+"/"+QString().setNum(state->slideImages.size())); + } + dirty = false; +} + +// ----------------------------------------- + +class PictureFlowPrivate +{ +public: + PictureFlowState* state; + PictureFlowAnimator* animator; + PictureFlowAbstractRenderer* renderer; + QTimer triggerTimer; +}; + + +PictureFlow::PictureFlow(QWidget* parent,FlowType flowType): QWidget(parent) +{ + d = new PictureFlowPrivate; + + switch(flowType){ + case CoverFlowLike: + d->state = new PictureFlowState(50,0); + break; + case Strip: + d->state = new PictureFlowState(0,1); + break; + case StripOverlapped: + d->state = new PictureFlowState(0,0); + break; + } + + framesSkip = 0; + + d->state->reset(); + d->state->reposition(); + + d->renderer = new PictureFlowSoftwareRenderer; + d->renderer->state = d->state; + d->renderer->widget = this; + d->renderer->init(); + + d->animator = new PictureFlowAnimator; + d->animator->state = d->state; + QObject::connect(&d->animator->animateTimer, SIGNAL(timeout()), this, SLOT(updateAnimation())); + + QObject::connect(&d->triggerTimer, SIGNAL(timeout()), this, SLOT(render())); + +#ifdef PICTUREFLOW_QT4 + setAttribute(Qt::WA_StaticContents, true); + setAttribute(Qt::WA_OpaquePaintEvent, true); + setAttribute(Qt::WA_NoSystemBackground, true); +#endif +#ifdef PICTUREFLOW_QT3 + setWFlags(getWFlags() | Qt::WStaticContents); + setWFlags(getWFlags() | Qt::WNoAutoErase); +#endif +#ifdef PICTUREFLOW_QT2 + setWFlags(getWFlags() | Qt::WPaintClever); + setWFlags(getWFlags() | Qt::WRepaintNoErase); + setWFlags(getWFlags() | Qt::WResizeNoErase); +#endif +} + +PictureFlow::~PictureFlow() +{ + delete d->renderer; + delete d->animator; + delete d->state; + delete d; +} + +int PictureFlow::slideCount() const +{ + return d->state->slideImages.count(); +} + +QColor PictureFlow::backgroundColor() const +{ + return QColor(d->state->backgroundColor); +} + +void PictureFlow::setBackgroundColor(const QColor& c) +{ + d->state->backgroundColor = c.rgb(); + triggerRender(); +} + +QSize PictureFlow::slideSize() const +{ + return QSize(d->state->slideWidth, d->state->slideHeight); +} + +void PictureFlow::setSlideSize(QSize size) +{ + d->state->slideWidth = size.width(); + d->state->slideHeight = size.height(); + d->state->reposition(); + triggerRender(); +} + +PictureFlow::ReflectionEffect PictureFlow::reflectionEffect() const +{ + return d->state->reflectionEffect; +} + +void PictureFlow::setReflectionEffect(ReflectionEffect effect) +{ + d->state->reflectionEffect = effect; + triggerRender(); +} + +QImage PictureFlow::slide(int index) const +{ + QImage* i = 0; + if((index >= 0) && (index < slideCount())) + i = d->state->slideImages[index]; + return i ? QImage(*i) : QImage(); +} + +void PictureFlow::addSlide(const QImage& image) +{ + int c = d->state->slideImages.count(); + d->state->slideImages.resize(c+1); + d->state->slideImages[c] = new QImage(image); + d->state->marks.resize(c+1); + d->state->marks[c] = YACReader::Unread; + triggerRender(); +} + +void PictureFlow::addSlide(const QPixmap& pixmap) +{ + addSlide(pixmap.toImage()); +} + +void PictureFlow::removeSlide(int index) +{ + int c = d->state->slideImages.count(); + if (index >= 0 && index < c) + { + d->state->slideImages.remove(index); + d->state->marks.remove(index); + setCenterIndex(index); + } +} + +void PictureFlow::setSlide(int index, const QImage& image) +{ + if((index >= 0) && (index < slideCount())) + { + QImage* i = image.isNull() ? 0 : new QImage(image); + delete d->state->slideImages[index]; + d->state->slideImages[index] = i; + triggerRender(); + } +} + +void PictureFlow::setSlide(int index, const QPixmap& pixmap) +{ + setSlide(index, pixmap.toImage()); +} + +int PictureFlow::centerIndex() const +{ + return d->state->centerIndex; +} + +void PictureFlow::setCenterIndex(int index) +{ + index = qMin(index, slideCount()-1); + index = qMax(index, 0); + d->state->centerIndex = index; + d->state->reset(); + d->animator->stop(index); + triggerRender(); +} + +void PictureFlow::clear() +{ + int c = d->state->slideImages.count(); + for(int i = 0; i < c; i++) + delete d->state->slideImages[i]; + d->state->slideImages.resize(0); + + d->state->marks.resize(0); + + d->state->reset(); + triggerRender(); +} + +void PictureFlow::render() +{ + d->renderer->dirty = true; + update(); +} + +void PictureFlow::triggerRender() +{ +#ifdef PICTUREFLOW_QT4 + d->triggerTimer.setSingleShot(true); + d->triggerTimer.start(0); +#endif +#if defined(PICTUREFLOW_QT3) || defined(PICTUREFLOW_QT2) + d->triggerTimer.start(0, true); +#endif +} + +void PictureFlow::showPrevious() +{ + int step = d->animator->step; + int center = d->state->centerIndex; + + if(step > 0) + { + d->animator->start(center); + emit centerIndexChanged(center); + } + + if(step == 0) + if(center > 0) + { + d->animator->start(center - 1); + emit centerIndexChanged(center - 1); + } + + if(step < 0) + { + d->animator->target = qMax(0, center - 2); + emit centerIndexChanged(qMax(0, center - 2)); + } + +} + +void PictureFlow::showNext() +{ + int step = d->animator->step; + int center = d->state->centerIndex; + + + if(step < 0) + { + d->animator->start(center); + emit centerIndexChanged(center); + } + + if(step == 0) + if(center < slideCount()-1) + { + d->animator->start(center + 1); + emit centerIndexChanged(center + 1); + } + + if(step > 0) + { + d->animator->target = qMin(center + 2, slideCount()-1); + emit centerIndexChanged(qMin(center + 2, slideCount()-1)); + } + + +} + +void PictureFlow::showSlide(unsigned int index) +{ + index = qMax(index, 0); + index = qMin(slideCount()-1, index); + if(index == d->state->centerSlide.slideIndex) + return; + + int distance = centerIndex()-index; + + if(abs(distance)>10) + { + if(distance<0) + setCenterIndex(centerIndex()+(-distance)-10); + else + setCenterIndex(centerIndex()-distance+10); + } + + d->state->centerIndex = index; + d->animator->start(index); +} + +void PictureFlow::keyPressEvent(QKeyEvent* event) +{ + if(event->key() == Qt::Key_Left) + { + /*if(event->modifiers() == Qt::ControlModifier) + showSlide(centerIndex()-10); + else*/ + showPrevious(); + event->accept(); + return; + } + + if(event->key() == Qt::Key_Right) + { + /*if(event->modifiers() == Qt::ControlModifier) + showSlide(centerIndex()+10); + else*/ + showNext(); + event->accept(); + return; + } + + if(event->key() == Qt::Key_Up) + { + //TODO emit selected signal + return; + } + + event->ignore(); +} + +void PictureFlow::mousePressEvent(QMouseEvent* event) +{ + if(event->x() > width()/2) + showNext(); + else + showPrevious(); +} + +void PictureFlow::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + d->renderer->paint(); +} + +void PictureFlow::resizeEvent(QResizeEvent* event) +{ + int heightWidget = event->size().height(); + int height,width; + height = heightWidget*0.55; + width = height*0.65; + setSlideSize(QSize(width,height)); + + render(); + d->animator->start(centerIndex()); + QWidget::resizeEvent(event); +} +#include +void PictureFlow::updateAnimation() //bucle principal +{ + QTime now; + now.start(); + bool frameSkiped = false; + + int old_center = d->state->centerIndex; + d->animator->update(); + if(framesSkip == 0) + render();//triggerRender(); + else + { + framesSkip--; + frameSkiped = true; + } + + + if(d->state->centerIndex != old_center) + emit centerIndexChangedSilent(d->state->centerIndex); + if(d->animator->animating == true) + { + int difference = 10-now.elapsed(); + if(difference >= 0 && !frameSkiped) + QTimer::singleShot(difference, this, SLOT(updateAnimation())); + else + { + QTimer::singleShot(0, this, SLOT(updateAnimation())); + if(!frameSkiped) + framesSkip = -( (difference - 10) / 10); + } + } + +} + +void PictureFlow::setFlowType(FlowType flowType) +{ + switch(flowType){ + case CoverFlowLike: + d->state->rawAngle = 50; + d->state->spacingRatio = 0, + d->state->reposition(); + break; + case Strip: + d->state->rawAngle = 0; + d->state->spacingRatio = 1; + d->state->reposition(); + break; + case StripOverlapped: + d->state->rawAngle = 0; + d->state->spacingRatio = 0; + d->state->reposition(); + break; + } + d->state->reset(); + d->renderer->init(); +} + +void PictureFlow::setMarkImage(const QImage & m) +{ + d->state->mark = m; +} + +void PictureFlow::markSlide(int index, YACReaderComicReadStatus readStatus) +{ + if(indexstate->marks.size()) + d->state->marks[index] = readStatus; +} + +void PictureFlow::updateMarks() +{ + d->renderer->init(); + d->renderer->paint(); + repaint(); +} + +void PictureFlow::unmarkSlide(int index) +{ + if(indexstate->marks.size()) + d->state->marks[index] = YACReader::Unread; +} + +void PictureFlow::setMarks(const QVector & m) +{ + d->state->marks = m; + updateMarks(); +} + +void PictureFlow::setShowMarks(bool enable) +{ + d->state->showMarks = enable; + updateMarks(); +} + +QVector PictureFlow::getMarks() +{ + return d->state->marks; +} + +void PictureFlow::resortCovers(QList newOrder) +{ + QVector slideImagesNew; + + QVector marksNew; + + QVector slidesInfo; + slidesInfo << d->state->leftSlides << d->state->centerSlide << d->state->rightSlides; + QVector slidesInfoNew; + + int order = 0; + foreach(int index, newOrder) + { + slideImagesNew << d->state->slideImages.at(index); + marksNew << d->state->marks.at(index); + slidesInfoNew << slidesInfo.at(index); + slidesInfoNew.last().slideIndex = order++; + } + + d->state->slideImages = slideImagesNew; + d->state->marks = marksNew; + d->state->leftSlides = slidesInfoNew.mid(0,d->state->leftSlides.length()); + d->state->centerSlide = slidesInfoNew.at(d->state->centerIndex); + d->state->leftSlides = slidesInfoNew.mid(d->state->centerIndex+1,d->state->leftSlides.length()); + + setCenterIndex(d->state->centerIndex); +} + diff --git a/common/pictureflow.h b/common/pictureflow.h new file mode 100644 index 00000000..b746ef70 --- /dev/null +++ b/common/pictureflow.h @@ -0,0 +1,228 @@ +/* + PictureFlow - animated image show widget + http://pictureflow.googlecode.com + + Copyright (C) 2008 Ariya Hidayat (ariya@kde.org) + Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef PICTUREFLOW_H +#define PICTUREFLOW_H + +#include +#include "yacreader_global.h" //FlowType + +class PictureFlowPrivate; + +using namespace YACReader; + +/*! + Class PictureFlow implements an image show widget with animation effect + like Apple's CoverFlow (in iTunes and iPod). Images are arranged in form + of slides, one main slide is shown at the center with few slides on + the left and right sides of the center slide. When the next or previous + slide is brought to the front, the whole slides flow to the right or + the right with smooth animation effect; until the new slide is finally + placed at the center. + + */ +class PictureFlow : public QWidget +{ +Q_OBJECT + + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) + Q_PROPERTY(QSize slideSize READ slideSize WRITE setSlideSize) + Q_PROPERTY(int slideCount READ slideCount) + Q_PROPERTY(int centerIndex READ centerIndex WRITE setCenterIndex) + +public: + + enum ReflectionEffect + { + NoReflection, + PlainReflection, + BlurredReflection + }; + + + + /*! + Creates a new PictureFlow widget. + */ + PictureFlow(QWidget* parent = 0, FlowType flowType = CoverFlowLike); + + /*! + Destroys the widget. + */ + ~PictureFlow(); + + /*! + Returns the background color. + */ + QColor backgroundColor() const; + + /*! + Sets the background color. By default it is black. + */ + void setBackgroundColor(const QColor& c); + + /*! + Returns the dimension of each slide (in pixels). + */ + QSize slideSize() const; + + /*! + Sets the dimension of each slide (in pixels). + */ + void setSlideSize(QSize size); + + /*! + Returns the total number of slides. + */ + int slideCount() const; + + /*! + Returns QImage of specified slide. + */ + QImage slide(int index) const; + + /*! + Returns the index of slide currently shown in the middle of the viewport. + */ + int centerIndex() const; + + /*! + Returns the effect applied to the reflection. + */ + ReflectionEffect reflectionEffect() const; + + /*! + Sets the effect applied to the reflection. The default is PlainReflection. + */ + void setReflectionEffect(ReflectionEffect effect); + + +public slots: + + /*! + Adds a new slide. + */ + void addSlide(const QImage& image); + + /*! + Adds a new slide. + */ + void addSlide(const QPixmap& pixmap); + + /*! + Removes an existing slide. + */ + void removeSlide(int index); + + /*! + Sets an image for specified slide. If the slide already exists, + it will be replaced. + */ + void setSlide(int index, const QImage& image); + + /*! + Sets a pixmap for specified slide. If the slide already exists, + it will be replaced. + */ + void setSlide(int index, const QPixmap& pixmap); + + /*! + Sets slide to be shown in the middle of the viewport. No animation + effect will be produced, unlike using showSlide. + */ + void setCenterIndex(int index); + + /*! + Clears all slides. + */ + void clear(); + + /*! + Shows previous slide using animation effect. + */ + void showPrevious(); + + /*! + Shows next slide using animation effect. + */ + void showNext(); + + /*! + Go to specified slide using animation effect. + */ + void showSlide(unsigned int index); + + /*! + Rerender the widget. Normally this function will be automatically invoked + whenever necessary, e.g. during the transition animation. + */ + void render(); + + /*! + Schedules a rendering update. Unlike render(), this function does not cause + immediate rendering. + */ + void triggerRender(); + + void setFlowType(FlowType flowType); + + void setMarkImage(const QImage & mark); + + void markSlide(int index, YACReaderComicReadStatus readStatus = Read); + + void updateMarks(); + + void unmarkSlide(int index); + + void setMarks(const QVector & marks); + + void setShowMarks(bool enable); + + QVector getMarks(); + + void resortCovers(QList newOrder); + +signals: + void centerIndexChanged(int index); + void centerIndexChangedSilent(int index); + +public: + void paintEvent(QPaintEvent *event); + void keyPressEvent(QKeyEvent* event); + void mousePressEvent(QMouseEvent* event); + void resizeEvent(QResizeEvent* event); + +private slots: + void updateAnimation(); + +private: + PictureFlowPrivate* d; + QImage mark; + int framesSkip; +}; + +#endif // PICTUREFLOW_H + diff --git a/common/qnaturalsorting.cpp b/common/qnaturalsorting.cpp new file mode 100644 index 00000000..97cbd5b0 --- /dev/null +++ b/common/qnaturalsorting.cpp @@ -0,0 +1,262 @@ +/* This file contains parts of the KDE libraries + Copyright (C) 1999 Ian Zepp (icszepp@islc.net) + Copyright (C) 2006 by Dominic Battre + Copyright (C) 2006 by Martin Pool + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "qnaturalsorting.h" + +//from KDE +/* +int naturalCompare(const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity) +{ + // This method chops the input a and b into pieces of + // digits and non-digits (a1.05 becomes a | 1 | . | 05) + // and compares these pieces of a and b to each other + // (first with first, second with second, ...). + // + // This is based on the natural sort order code code by Martin Pool + // http://sourcefrog.net/projects/natsort/ + // Martin Pool agreed to license this under LGPL or GPL. + + // FIXME: Using toLower() to implement case insensitive comparison is + // sub-optimal, but is needed because we compare strings with + // localeAwareCompare(), which does not know about case sensitivity. + // A task has been filled for this in Qt Task Tracker with ID 205990. + // http://trolltech.com/developer/task-tracker/index_html?method=entry&id=205990 + QString a; + QString b; + if (caseSensitivity == Qt::CaseSensitive) { + a = _a; + b = _b; + } else { + a = _a.toLower(); + b = _b.toLower(); + } + + const QChar* currA = a.unicode(); // iterator over a + const QChar* currB = b.unicode(); // iterator over b + + if (currA == currB) { + return 0; + } + + const QChar* begSeqA = currA; // beginning of a new character sequence of a + const QChar* begSeqB = currB; + + while (!currA->isNull() && !currB->isNull()) { + if (currA->unicode() == QChar::ObjectReplacementCharacter) { + return 1; + } + + if (currB->unicode() == QChar::ObjectReplacementCharacter) { + return -1; + } + + if (currA->unicode() == QChar::ReplacementCharacter) { + return 1; + } + + if (currB->unicode() == QChar::ReplacementCharacter) { + return -1; + } + + // find sequence of characters ending at the first non-character + while (!currA->isNull() && !currA->isDigit() && !currA->isPunct() && !currA->isSpace()) { + ++currA; + } + + while (!currB->isNull() && !currB->isDigit() && !currB->isPunct() && !currB->isSpace()) { + ++currB; + } + + // compare these sequences + const QStringRef& subA(a.midRef(begSeqA - a.unicode(), currA - begSeqA)); + const QStringRef& subB(b.midRef(begSeqB - b.unicode(), currB - begSeqB)); + const int cmp = QStringRef::localeAwareCompare(subA, subB); + if (cmp != 0) { + return cmp < 0 ? -1 : +1; + } + + if (currA->isNull() || currB->isNull()) { + break; + } + + // find sequence of characters ending at the first non-character + while (currA->isPunct() || currA->isSpace() || currB->isPunct() || currB->isSpace()) { + if (*currA != *currB) { + return (*currA < *currB) ? -1 : +1; + } + ++currA; + ++currB; + } + + // now some digits follow... + if ((*currA == '0') || (*currB == '0')) { + // one digit-sequence starts with 0 -> assume we are in a fraction part + // do left aligned comparison (numbers are considered left aligned) + while (1) { + if (!currA->isDigit() && !currB->isDigit()) { + break; + } else if (!currA->isDigit()) { + return +1; + } else if (!currB->isDigit()) { + return -1; + } else if (*currA < *currB) { + return -1; + } else if (*currA > *currB) { + return + 1; + } + ++currA; + ++currB; + } + } else { + // No digit-sequence starts with 0 -> assume we are looking at some integer + // do right aligned comparison. + // + // The longest run of digits wins. That aside, the greatest + // value wins, but we can't know that it will until we've scanned + // both numbers to know that they have the same magnitude. + + bool isFirstRun = true; + int weight = 0; + while (1) { + if (!currA->isDigit() && !currB->isDigit()) { + if (weight != 0) { + return weight; + } + break; + } else if (!currA->isDigit()) { + if (isFirstRun) { + return *currA < *currB ? -1 : +1; + } else { + return -1; + } + } else if (!currB->isDigit()) { + if (isFirstRun) { + return *currA < *currB ? -1 : +1; + } else { + return +1; + } + } else if ((*currA < *currB) && (weight == 0)) { + weight = -1; + } else if ((*currA > *currB) && (weight == 0)) { + weight = + 1; + } + ++currA; + ++currB; + isFirstRun = false; + } + } + + begSeqA = currA; + begSeqB = currB; + } + + if (currA->isNull() && currB->isNull()) { + return 0; + } + + return currA->isNull() ? -1 : + 1; +} + +*/ +static inline QChar getNextChar(const QString &s, int location) +{ + return (location < s.length()) ? s.at(location) : QChar(); +} + +int naturalCompare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs) +{ + for (int l1 = 0, l2 = 0; l1 <= s1.count() && l2 <= s2.count(); ++l1, ++l2) { + // skip spaces, tabs and 0's + QChar c1 = getNextChar(s1, l1); + while (c1.isSpace()) + c1 = getNextChar(s1, ++l1); + QChar c2 = getNextChar(s2, l2); + while (c2.isSpace()) + c2 = getNextChar(s2, ++l2); + + if (c1.isDigit() && c2.isDigit()) { + while (c1.digitValue() == 0) + c1 = getNextChar(s1, ++l1); + while (c2.digitValue() == 0) + c2 = getNextChar(s2, ++l2); + + int lookAheadLocation1 = l1; + int lookAheadLocation2 = l2; + int currentReturnValue = 0; + // find the last digit, setting currentReturnValue as we go if it isn't equal + for ( + QChar lookAhead1 = c1, lookAhead2 = c2; + (lookAheadLocation1 <= s1.length() && lookAheadLocation2 <= s2.length()); + lookAhead1 = getNextChar(s1, ++lookAheadLocation1), + lookAhead2 = getNextChar(s2, ++lookAheadLocation2) + ) { + bool is1ADigit = !lookAhead1.isNull() && lookAhead1.isDigit(); + bool is2ADigit = !lookAhead2.isNull() && lookAhead2.isDigit(); + if (!is1ADigit && !is2ADigit) + break; + if (!is1ADigit) + return -1; + if (!is2ADigit) + return 1; + if (currentReturnValue == 0) { + if (lookAhead1 < lookAhead2) { + currentReturnValue = -1; + } else if (lookAhead1 > lookAhead2) { + currentReturnValue = 1; + } + } + } + if (currentReturnValue != 0) + return currentReturnValue; + } + + if (cs == Qt::CaseInsensitive) { + if (!c1.isLower()) c1 = c1.toLower(); + if (!c2.isLower()) c2 = c2.toLower(); + } + int r = QString::localeAwareCompare(c1, c2); + if (r < 0) + return -1; + if (r > 0) + return 1; + } + // The two strings are the same (02 == 2) so fall back to the normal sort + return QString::compare(s1, s2, cs); +} +bool naturalSortLessThanCS( const QString &left, const QString &right ) +{ + return (naturalCompare( left, right, Qt::CaseSensitive ) < 0); +} + +bool naturalSortLessThanCI( const QString &left, const QString &right ) +{ + return (naturalCompare( left, right, Qt::CaseInsensitive ) < 0); +} + +bool naturalSortLessThanCIFileInfo(const QFileInfo & left,const QFileInfo & right) +{ + return naturalSortLessThanCI(left.fileName(),right.fileName()); +} + +bool naturalSortLessThanCILibraryItem(LibraryItem * left, LibraryItem * right) +{ + return naturalSortLessThanCI(left->name,right->name); +} diff --git a/common/qnaturalsorting.h b/common/qnaturalsorting.h new file mode 100644 index 00000000..9a84f96a --- /dev/null +++ b/common/qnaturalsorting.h @@ -0,0 +1,15 @@ + + +#ifndef __QNATURALSORTING_H +#define __QNATURALSORTING_H + +#include +#include +#include "library_item.h" + +bool naturalSortLessThanCS( const QString &left, const QString &right ); +bool naturalSortLessThanCI( const QString &left, const QString &right ); +bool naturalSortLessThanCIFileInfo(const QFileInfo & left,const QFileInfo & right); +bool naturalSortLessThanCILibraryItem(LibraryItem * left, LibraryItem * right); + +#endif diff --git a/common/scroll_management.cpp b/common/scroll_management.cpp new file mode 100644 index 00000000..8db92273 --- /dev/null +++ b/common/scroll_management.cpp @@ -0,0 +1,61 @@ +#include "scroll_management.h" + +ScrollManagement::ScrollManagement() +{ + wheelTimer = new QTime(); + wheelTimer->start(); + wheelAccumulator = 0; +} + +ScrollManagement::Movement ScrollManagement::getMovement(QWheelEvent *event) +{ + /*QLOG_DEBUG() << "WheelEvent angle delta : " << event->angleDelta(); + QLOG_DEBUG() << "WheelEvent pixel delta : " << event->pixelDelta();*/ + + int tooFast = 1; + int timeThrottle = 16; + int minimumMove = 70; + + //avoid any events overflood + if((wheelTimer->elapsed() < tooFast)){ + event->setAccepted(true); + return None; + } + + // Accumulate the delta + if(event->delta()<0 != wheelAccumulator<0 ) //different sign means change in direction + wheelAccumulator = 0; + + wheelAccumulator += event->delta(); + + //Do not process events too fast + if((wheelTimer->elapsed() < timeThrottle)){ + event->setAccepted(true); + return None; + } + + //small intervals are ignored until with have enough acumulated delta + if((wheelAccumulator < minimumMove) && (wheelAccumulator > -minimumMove)){ + event->setAccepted(true); + return None; + } + + Movement m; + if(wheelAccumulator<0) + m = Forward; + else + m = Backward; + + event->accept(); + //Clean up + wheelAccumulator = 0; + wheelTimer->restart(); + + return m; +} + +ScrollManagement::~ScrollManagement() +{ + +} + diff --git a/common/scroll_management.h b/common/scroll_management.h new file mode 100644 index 00000000..8c169179 --- /dev/null +++ b/common/scroll_management.h @@ -0,0 +1,25 @@ +#ifndef SCROLLMANAGAMENT_H +#define SCROLLMANAGAMENT_H + +#include +#include + +class ScrollManagement +{ +public: + enum Movement{ + None, + Forward, + Backward + }; + + ScrollManagement(); + ScrollManagement::Movement getMovement(QWheelEvent * event); + ~ScrollManagement(); + +private: + QTime * wheelTimer; + int wheelAccumulator; +}; + +#endif // SCROLLMANAGAMENT_H diff --git a/common/yacreader_global.cpp b/common/yacreader_global.cpp new file mode 100644 index 00000000..fbf2540e --- /dev/null +++ b/common/yacreader_global.cpp @@ -0,0 +1,141 @@ +#include "yacreader_global.h" +#include + +using namespace YACReader; + +QString YACReader::getSettingsPath() +{ +#if QT_VERSION >= 0x050000 + return QStandardPaths::writableLocation(QStandardPaths::DataLocation); +#else + return QDesktopServices::storageLocation(QDesktopServices::DataLocation); +#endif + +} + +void YACReader::addSperator(QWidget *w) +{ + QAction * separator = new QAction(w); + separator->setSeparator(true); + w->addAction(separator); +} + + +QAction * YACReader::createSeparator() +{ + QAction * a = new QAction(0); + a->setSeparator(true); + return a; +} + + +QString YACReader::colorToName(LabelColors colors) +{ + switch(colors){ + case YRed: + return "red"; + case YOrange: + return "orange"; + case YYellow: + return "yellow"; + case YGreen: + return "green"; + case YCyan: + return "cyan"; + case YBlue: + return "blue"; + case YViolet: + return "violet"; + case YPurple: + return "purple"; + case YPink: + return "pink"; + case YWhite: + return "white"; + case YLight: + return "light"; + case YDark: + return "dark"; + } +} + + +QIcon YACReader::noHighlightedIcon(const QString &path) +{ + QPixmap p(path); + + QIcon icon;//(path); + icon.addFile(path,p.size(),QIcon::Normal); + icon.addFile(path,p.size(),QIcon::Selected); + return icon; +} + + +void YACReader::colorize(QImage &img, QColor &col) +{ + QRgb *data = (QRgb *)img.bits(); + QRgb *end = data + img.width()*img.height(); + + int rcol = col.red(), gcol = col.green(), bcol = col.blue(); + while(data != end) { + *data = qRgba(rcol,gcol,bcol,qAlpha(*data)); + ++data; + } +} + + +QString YACReader::labelColorToRGBString(LabelColors color) +{ + switch (color) { + case YRed: + return "#FD777C"; + + case YOrange: + return "#FEBF34"; + + case YYellow: + return "#F5E934"; + + case YGreen: + return "#B6E525"; + + case YCyan: + return "#9FFFDD"; + + case YBlue: + return "#82C7FF"; + + case YViolet: + return "#8286FF"; + + case YPurple: + return "#E39FFF"; + + case YPink: + return "#FF9FDD"; + +#ifdef Q_OS_MAC + case YWhite: + return "#E3E3E3"; +#else + case YWhite: + return "#FFFFFF"; +#endif + case YLight: + return "#C8C8C8"; + case YDark: + return "#ABABAB"; + + + } +} + + +QList YACReader::mimeDataToComicsIds(const QMimeData *data) +{ + QList comicIds; + QByteArray rawData = data->data(YACReader::YACReaderLibrarComiscSelectionMimeDataFormat); + QDataStream in(&rawData,QIODevice::ReadOnly); + in >> comicIds; //deserialize the list of indentifiers + return comicIds; +} diff --git a/common/yacreader_global.h b/common/yacreader_global.h new file mode 100644 index 00000000..74ce104e --- /dev/null +++ b/common/yacreader_global.h @@ -0,0 +1,145 @@ +#ifndef __YACREADER_GLOBAL_H +#define __YACREADER_GLOBAL_H + +#if QT_VERSION >= 0x050000 + #include +#else + #include +#endif + +#include +#include + +#define VERSION "8.0.0" + +#define PATH "PATH" +#define MAG_GLASS_SIZE "MAG_GLASS_SIZE" +#define ZOOM_LEVEL "ZOOM_LEVEL" +#define SLIDE_SIZE "SLIDE_SIZE" +#define GO_TO_FLOW_SIZE "GO_TO_FLOW_SIZE" +#define FLOW_TYPE_SW "FLOW_TYPE_SW" +#define FIT "FIT" +#define FLOW_TYPE "FLOW_TYPE" +#define FULLSCREEN "FULLSCREEN" +#define FIT_TO_WIDTH_RATIO "FIT_TO_WIDTH_RATIO" +#define Y_WINDOW_POS "POS" +#define Y_WINDOW_SIZE "SIZE" +#define MAXIMIZED "MAXIMIZED" +#define DOUBLE_PAGE "DOUBLE_PAGE" +#define DOUBLE_MANGA_PAGE "DOUBLE_MANGA_PAGE" +#define ADJUST_TO_FULL_SIZE "ADJUST_TO_FULL_SIZE" +#define BACKGROUND_COLOR "BACKGROUND_COLOR" +#define ALWAYS_ON_TOP "ALWAYS_ON_TOP" +#define SHOW_TOOLBARS "SHOW_TOOLBARS" +#define BRIGHTNESS "BRIGHTNESS" +#define CONTRAST "CONTRAST" +#define GAMMA "GAMMA" +#define SHOW_INFO "SHOW_INFO" + +#define FLOW_TYPE_GL "FLOW_TYPE_GL" +#define Y_POSITION "Y_POSITION" +#define COVER_DISTANCE "COVER_DISTANCE" +#define CENTRAL_DISTANCE "CENTRAL_DISTANCE" +#define ZOOM_LEVEL "ZOOM_LEVEL" +#define Z_COVER_OFFSET "Z_COVER_OFFSET" +#define COVER_ROTATION "COVER_ROTATION" +#define FADE_OUT_DIST "FADE_OUT_DIST" +#define LIGHT_STRENGTH "LIGHT_STRENGTH" +#define MAX_ANGLE "MAX_ANGLE" +#define PERFORMANCE "PERFORMANCE" +#define USE_OPEN_GL "USE_OPEN_GL" +#define X_ROTATION "X_ROTATION" +#define Y_COVER_OFFSET "Y_COVER_OFFSET" +#define V_SYNC "V_SYNC" +#define SERVER_ON "SERVER_ON" + +#define MAIN_WINDOW_GEOMETRY "MAIN_WINDOW_GEOMETRY" +#define MAIN_WINDOW_STATE "MAIN_WINDOW_STATE" +#define COMICS_VIEW_HEADERS "COMICS_VIEW_HEADERS" +#define COMICS_VIEW_HEADERS_GEOMETRY "COMICS_VIEW_HEADERS_GEOMETRY" +#define COMICS_VIEW_STATUS "COMICS_VIEW_STATUS" +#define COMICS_VIEW_FLOW_SPLITTER_STATUS "COMICS_VIEW_FLOW_SPLITTER_STATUS" +#define SIDEBAR_SPLITTER_STATUS "SIDEBAR_SPLITTER_STATUS" + +#define NUM_DAYS_BETWEEN_VERSION_CHECKS "NUM_DAYS_BETWEEN_VERSION_CHECKS" +#define LAST_VERSION_CHECK "LAST_VERSION_CHECK" + +#define YACREADERLIBRARY_GUID "ea343ff3-2005-4865-b212-7fa7c43999b8" + +#define LIBRARIES "LIBRARIES" + +#define COMIC_VINE_API_KEY "COMIC_VINE_API_KEY" + +namespace YACReader +{ + +static const QString YACReaderLibrarComiscSelectionMimeDataFormat = "application/yacreaderlibrary-comics-ids"; +static const QString YACReaderLibrarSubReadingListMimeDataFormat = "application/yacreaderlibrary-sublist-rows"; + + enum FlowType + { + CoverFlowLike=0, + Strip, + StripOverlapped, + Modern, + Roulette, + Custom + }; + + enum YACReaderIPCMessages + { + RequestComicInfo = 0, + SendComicInfo, + }; + + enum YACReaderComicReadStatus + { + Unread = 0, + Read = 1, + Opened = 2 + }; + + enum YACReaderErrors + { + SevenZNotFound = 700 + }; + + enum ComicsViewStatus + { + Flow, + Grid + }; + + enum SearchModifiers{ + NoModifiers = 0, + OnlyRead, + OnlyUnread, + ByAuthor + }; + + enum LabelColors{ + YRed = 1, + YOrange, + YYellow, + YGreen, + YCyan, + YBlue, + YViolet, + YPurple, + YPink, + YWhite, + YLight, + YDark + }; + +QString getSettingsPath(); +void addSperator(QWidget * w); +QAction * createSeparator(); +QString colorToName(LabelColors colors); +QIcon noHighlightedIcon(const QString & path); +void colorize(QImage &img, QColor &col); +QString labelColorToRGBString(LabelColors color); +QList mimeDataToComicsIds(const QMimeData * data); +} +#endif + diff --git a/compileOSX.sh b/compileOSX.sh new file mode 100755 index 00000000..18228b93 --- /dev/null +++ b/compileOSX.sh @@ -0,0 +1,47 @@ +#! /bin/bash +if [ $2 == "clean" ]; then +./cleanOSX.sh +fi + +echo "Compiling YACReader" +cd ./YACReader +/Users/luisangel/my_dev/Qt5.5.0/5.5/clang_64/bin/qmake -spec macx-clang "CONFIG+=release" +#qmake -spec macx-g++ "CONFIG+=release" +make +cd .. + +echo "Compiling YACReaderLibrary" +cd ./YACReaderLibrary +/Users/luisangel/my_dev/Qt5.5.0/5.5/clang_64/bin/qmake -spec macx-clang "CONFIG+=release" +#qmake -spec macx-g++ "CONFIG+=release" +make +cd .. + +echo "Configuring release apps" + +cp -R ./YACReader/YACReader.app ./YACReader.app +cp -R ./YACReaderLibrary/YACReaderLibrary.app ./YACReaderLibrary.app + +./releaseOSX.sh + +#cp -R ./PlugInsYACReader ./YACReader.app/Contents/PlugIns +#cp -R ./PlugInsLibrary ./YACReaderLibrary.app/Contents/PlugIns + +echo "Copying to destination folder" +dest='YACReader-'$1' MacOSX-Intel' +mkdir "$dest" +cp -R ./YACReader.app "./${dest}/YACReader.app" +cp -R ./YACReaderLibrary.app "./${dest}/YACReaderLibrary.app" +cp ./COPYING.txt "./${dest}/" +cp ./README.txt "./${dest}/" + +mkdir "./${dest}/icons/" +cp ./images/db.png "./${dest}/icons/" +cp ./images/coversPackage.png "./${dest}/icons/" + +echo "Creating dmg package" +#tar -czf "${dest}".tar.gz "${dest}" +#hdiutil create "${dest}".dmg -srcfolder "./${dest}" -ov +./create-dmg --volname 'YACReader '$1' Installer' --volicon icon.icns --window-size 600 403 --icon-size 128 --app-drop-link 485 90 --background background.png --icon YACReader 80 90 --icon YACReaderLibrary 235 90 --eula COPYING.txt --icon icons 470 295 --icon README.txt 120 295 --icon COPYING.txt 290 295 "./${dest}.dmg" "./${dest}" + +echo "Done!" diff --git a/compressed_archive/7z_includes.h b/compressed_archive/7z_includes.h new file mode 100644 index 00000000..d80e8dc1 --- /dev/null +++ b/compressed_archive/7z_includes.h @@ -0,0 +1,65 @@ +#ifndef _7Z_INCLUDES_H +#define _7Z_INCLUDES_H + +//WIN includes +#ifdef Q_OS_WIN +#include "lib7zip/CPP/Common/StringConvert.h" +#include "lib7zip/CPP/Common/MyInitGuid.h" +#include "lib7zip/CPP/Common/MyCom.h" +#include "lib7zip/CPP/7zip/Common/FileStreams.h" +#include "lib7zip/CPP/7zip/Archive/IArchive.h" + +#include "lib7zip/CPP/7zip/IStream.h" + +#include "lib7zip/CPP/7zip/IPassword.h" +#include "lib7zip/CPP/7zip/MyVersion.h" + +#include "lib7zip/C/Types.h" + +#include "lib7zip/CPP/Windows/PropVariant.h" +#include "lib7zip/CPP/Windows/PropVariantConversions.h" + +#include "lib7zip/CPP/7zip/Common/StreamObjects.h" +#include "lib7zip/CPP/7zip/Common/StreamUtils.h" + +extern "C" +{ +#include "lib7zip/C/Alloc.h" +} +#else +//POSIX includes +#include "libp7zip/CPP/myWindows/myPrivate.h" +#include "libp7zip/CPP/myWindows/config.h" + +#include "libp7zip/CPP/Common/MyGuidDef.h" +#include "libp7zip/CPP/Common/MyWindows.h" + +#include "libp7zip/CPP/Common/StringConvert.h" +#include "libp7zip/CPP/Common/MyInitGuid.h" +#include "libp7zip/CPP/Common/MyCom.h" +#include "libp7zip/CPP/7zip/Common/FileStreams.h" +#include "libp7zip/CPP/7zip/Archive/IArchive.h" + +#include "libp7zip/CPP/7zip/IStream.h" + +#include "libp7zip/CPP/7zip/IPassword.h" +#include "libp7zip/CPP/7zip/MyVersion.h" + +#include "libp7zip/C/Types.h" + +#include "libp7zip/CPP/Windows/Defs.h" +#include "libp7zip/CPP/Windows/PropVariant.h" +#include "libp7zip/CPP/Windows/PropVariantConversions.h" + +#include "libp7zip/CPP/7zip/Common/StreamObjects.h" +#include "libp7zip/CPP/7zip/Common/StreamUtils.h" + +#include "libp7zip/CPP/7zip/ICoder.h" + +extern "C" +{ +#include "libp7zip/C/Alloc.h" +} +#endif + +#endif // _7Z_INCLUDES_H diff --git a/compressed_archive/README_7zip.txt b/compressed_archive/README_7zip.txt new file mode 100644 index 00000000..1653bbdd --- /dev/null +++ b/compressed_archive/README_7zip.txt @@ -0,0 +1,13 @@ +If you are trying to compile YACReader with a 7zip decompression backend, you need to download de source code of 7zip (Windows) or p7zip (Linux/MacOSX). + +Please extract it and rename the folder to lib7zip (Windows) or libp7zip (Linux/MacOSX), then copy it to $YACREADER_SRC/compressed_archive/ (this +folder). + +YACReader is compiled using 7zip/p7zip 9.20.1 and will not work with newer versions. + +On Linux/Unix this means your YACReader installation will stop working if you update your installation of p7zip to a newer version. If you wish to keep using +p7zip with YACReader, you can copy 7z.so and Codecs/Rar29.so from p7zip 9.20.1 to "/usr/lib/yacreader/". YACReader will then detect these files and use +them instead of the system provided p7zip files which allows you to keep both YACReader and an up to date p7zip installation. + +Please keep in mind this is only a workaround that is provided for backwards compatibility and not intended as a long time solution. +It is recommended that you switch to unarr as a decompression backend instead (see README.txt in compressed_archive/unarr). \ No newline at end of file diff --git a/compressed_archive/StdAfx.h b/compressed_archive/StdAfx.h new file mode 100644 index 00000000..2edddf4a --- /dev/null +++ b/compressed_archive/StdAfx.h @@ -0,0 +1,9 @@ +// StdAfx.h + +#ifndef __STDAFX_H +#define __STDAFX_H + +#include +#include + +#endif diff --git a/compressed_archive/StdAfx.h.cpp b/compressed_archive/StdAfx.h.cpp new file mode 100644 index 00000000..b86703cb --- /dev/null +++ b/compressed_archive/StdAfx.h.cpp @@ -0,0 +1,10 @@ +/*-------------------------------------------------------------------- +* +* Due to issues with the dependencies checker within the IDE, it +* sometimes fails to recompile the PCH file, if we force the IDE to +* This file is auto-generated by qmake since no PRECOMPILED_SOURCE was +* specified, and is used as the common stdafx.cpp. The file is only +* command line compilations by nmake. +* +--------------------------------------------------------------------*/ +#include "StdAfx.h" diff --git a/compressed_archive/compressed_archive.cpp b/compressed_archive/compressed_archive.cpp new file mode 100644 index 00000000..fe665cca --- /dev/null +++ b/compressed_archive/compressed_archive.cpp @@ -0,0 +1,515 @@ +#include "compressed_archive.h" +#include "extract_delegate.h" + +#include +#include +#include +#include + +#include "open_callbacks.h" +#include "extract_callbacks.h" + + +//DEFINE_GUID(CLSID_CFormat7z,0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00); +//DEFINE_GUID(IArchiveKK,0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00); + +DEFINE_GUID(CLSID_CFormat7z, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatRar, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x03, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatZip, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x01, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatTar, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xee, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatArj, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x04, 0x00, 0x00); + +//unused Formats +/*DEFINE_GUID(CLSID_CFormatBZip2, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x02, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatCab, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x08, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatChm, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xe9, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatCompound,0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xe5, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatCpio, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xed, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatDeb, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xec, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatGZip, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xef, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatIso, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xe7, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatLzh, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x06, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatLzma, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x0a, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatNsis, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x09, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatRpm, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xeb, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatSplit, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xea, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatWim, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xe6, 0x00, 0x00); +DEFINE_GUID(CLSID_CFormatZ, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x05, 0x00, 0x00);*/ + +#ifdef Q_OS_WIN +GUID _supportedFileFormats[] = {CLSID_CFormatRar,CLSID_CFormatZip,CLSID_CFormatTar,CLSID_CFormat7z,CLSID_CFormatArj}; +#else +GUID _supportedFileFormats[] = {CLSID_CFormatZip,CLSID_CFormatTar,CLSID_CFormat7z,CLSID_CFormatArj}; +#endif +std::vector supportedFileFormats (_supportedFileFormats, _supportedFileFormats + sizeof(_supportedFileFormats) / sizeof(_supportedFileFormats[0]) ); + +DEFINE_GUID(IID_InArchive, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00); +DEFINE_GUID(IID_ISetCompressCodecsInfo, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x61, 0x00, 0x00); + +#ifdef Q_OS_UNIX +DEFINE_GUID(IID_IOutStream, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00); +DEFINE_GUID(IID_IInStream, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00); +DEFINE_GUID(IID_IStreamGetSize, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00); +DEFINE_GUID(IID_ISequentialInStream, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00); +#endif + +struct SevenZipInterface { + CreateObjectFunc createObjectFunc; + GetMethodPropertyFunc getMethodPropertyFunc; + GetNumberOfMethodsFunc getNumberOfMethodsFunc; + GetNumberOfFormatsFunc getNumberOfFormatsFunc; + GetHandlerPropertyFunc getHandlerPropertyFunc; + GetHandlerPropertyFunc2 getHandlerPropertyFunc2; + SetLargePageModeFunc setLargePageModeFunc; + +#ifdef Q_OS_UNIX + CreateObjectFunc createObjectFuncRar; + GetMethodPropertyFunc getMethodPropertyFuncRar; + GetNumberOfMethodsFunc getNumberOfMethodsFuncRar; +#endif + + CMyComPtr archive; +}; + +//SevenZipInterface * szInterface; + +const char rar[7]={static_cast(0x52), static_cast(0x61), static_cast(0x72), static_cast(0x21), static_cast(0x1A), static_cast(0x07), static_cast(0x00)}; +const char rar5[8]={static_cast(0x52), static_cast(0x61), static_cast(0x72), static_cast(0x21), static_cast(0x1A), static_cast(0x07), static_cast(0x01), static_cast(0x00)}; +const char zip[2]={static_cast(0x50), static_cast(0x4B)}; +const char sevenz[6]={static_cast(0x37), static_cast(0x7A), static_cast(0xBC), static_cast(0xAF), static_cast(0x27), static_cast(0x1C)}; +const char tar[6]="ustar"; +const char arj[2]={static_cast(0x60), static_cast(0xEA)}; + +CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) : + QObject(parent),sevenzLib(0),valid(false),tools(false) +#ifdef Q_OS_UNIX + ,isRar(false) +#endif +{ + szInterface = new SevenZipInterface; + //load functions + if(!loadFunctions()) + return; + + tools = true; + //load file + if(szInterface->createObjectFunc != 0) + { + //QUuid CLSID_CFormat7z("23170f69-40c1-278a-1000-000110070000"); + //se crea el objeto Archivo: formato,tipo,objeto + bool formatFound = false; + CInFileStream *fileSpec = new CInFileStream; + CMyComPtr file = fileSpec; + + CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback; + CMyComPtr openCallback = openCallbackSpec; + openCallbackSpec->PasswordIsDefined = false; + // openCallbackSpec->PasswordIsDefined = true; + // openCallbackSpec->Password = L"1"; + + //get file type from suffix + int i=-1; + QFile filex(filePath); + + if (!filex.open(QIODevice::ReadOnly)) + return; + QByteArray magicNumber=filex.read(8); //read first 8 bytes + + //if (memcmp(magicNumber,rar5,8)==0) + //return; //rar5 is not supported + //qDebug() << memcmp(magicNumber,rar,7); + //TODO: this suffix matching is rather primitive - better approach? +#ifdef Q_OS_UNIX + if (memcmp(magicNumber,rar,6) != 0) + { + //match suffix to GUID list + if (memcmp(magicNumber,zip,2)==0) + i=0; + else if (memcmp(magicNumber,sevenz,6)==0) + i=2; + else if (memcmp(magicNumber,arj,2)==0) + i=3; + else + { + filex.seek(257); + magicNumber=filex.read(8); + if (memcmp(magicNumber,tar,5)==0) + i=1; + } + if (i==-1) //fallback code + { + QFileInfo fileinfo(filePath); + if (fileinfo.suffix() == "zip" || fileinfo.suffix() == "cbz") + { + i=0; + } + else + { + return; + } + } +#else + if (memcmp(magicNumber,rar,6) == 0) + if (memcmp(magicNumber,rar5,7) == 0) + return; + else + i=0; + else if (memcmp(magicNumber,zip,2)==0) + i=1; + else if (memcmp(magicNumber,sevenz,6)==0) + i=3; + else if (memcmp(magicNumber,arj,2)==0) + i=4; + else { + filex.seek(257); + magicNumber=filex.read(8); + if (memcmp(magicNumber,tar,5)==0) + i=2; + } + if (i==-1) //fallback code + { + QFileInfo fileinfo(filePath); + if (fileinfo.suffix() == "zip" || fileinfo.suffix() == "cbz") + { + i=1; + } + else + { + return; + } + } +#endif + +#ifdef UNICODE + if (!fileSpec->Open((LPCTSTR)filePath.toStdWString().c_str())) +#else + if (!fileSpec->Open((LPCTSTR)filePath.toStdString().c_str())) +#endif + { + qDebug() << "unable to load" + filePath; + return; + } + + //GUID uuid = supportedFileFormats[i]; + //qDebug() << "trying : " << uuid << endl; + if (szInterface->createObjectFunc(&supportedFileFormats[i], &IID_InArchive, (void **)&szInterface->archive) == S_OK) + { + //qDebug() << "Can not open archive file : " + filePath << endl; + + if (szInterface->archive->Open(file, 0, openCallback) == S_OK) + { + valid = formatFound = true; + qDebug() << "Opened archive file : " + filePath << endl; + setupFilesNames(); + return; + } + } + + + +#ifdef Q_OS_WIN + if(!formatFound) + { + qDebug() << "Can not open archive" << endl; + } + } +} +#else + } + else + { + if (memcmp(magicNumber,rar5,7) == 0) + return;//we don't support rar5 + + isRar=true; //tell the destructor we *tried* to open a rar file! + if (szInterface->createObjectFunc(&CLSID_CFormatRar, &IID_InArchive, (void **)&szInterface->archive) != S_OK) + { + qDebug() << "Error creating rar archive :" + filePath; + return; + } + + CMyComPtr codecsInfo; + + if (szInterface->archive->QueryInterface(IID_ISetCompressCodecsInfo,(void **)&codecsInfo) != S_OK) + { + qDebug() << "Error getting rar codec :" + filePath; + return; + } + if (codecsInfo->SetCompressCodecsInfo(this) != S_OK) + { + qDebug() << "Error setting rar codec"; + return; + } + +#ifdef UNICODE + if (!fileSpec->Open((LPCTSTR)filePath.toStdWString().c_str())) +#else + if (!fileSpec->Open((LPCTSTR)filePath.toStdString().c_str())) +#endif + { + qDebug() << "Error opening rar file :" + filePath; + return; + } + //qDebug() << "Can not open archive file : " + filePath << endl; + + if (szInterface->archive->Open(file, 0, openCallback) == S_OK) + { + valid = formatFound = true; + setupFilesNames(); + //isRar = true; + } + } + } +} +#endif + + +CompressedArchive::~CompressedArchive() +{ + //always close the archive! + if (szInterface->archive) + { + szInterface->archive->Close(); + } + +#ifdef Q_OS_UNIX + if(isRar) //TODO: Memory leak!!!! If AddRef is not used, a crash occurs in "delete szInterface" + { + szInterface->archive->AddRef(); + } +#endif + delete szInterface; + +#ifdef Q_OS_UNIX + delete rarLib; +#endif + delete sevenzLib; +} + +bool CompressedArchive::loadFunctions() +{ + //LOAD library + //TODO check if this works in OSX (7z.so instead of 7z.dylib) + // fix1: try to load "7z.so" + // fix2: rename 7z.so to 7z.dylib + if(sevenzLib == 0) + { +#if defined Q_OS_UNIX + #if defined Q_OS_MAC + rarLib = new QLibrary(QCoreApplication::applicationDirPath()+"/utils/Codecs/Rar29"); + #else + //check if a yacreader specific version of p7zip exists on the system + QFileInfo rarCodec(QString(LIBDIR)+"/yacreader/Codecs/Rar29.so"); + if (rarCodec.exists()) + { + rarLib = new QLibrary(rarCodec.absoluteFilePath()); + } + else + { + rarLib = new QLibrary(QString(LIBDIR)+"/p7zip/Codecs/Rar29.so"); + } + #endif + if(!rarLib->load()) + { + qDebug() << "Error Loading Rar29.so : " + rarLib->errorString() << endl; + QCoreApplication::exit(700); //TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound + return false; + } +#endif +#if defined Q_OS_UNIX && !defined Q_OS_MAC + QFileInfo sevenzlibrary(QString(LIBDIR)+"/yacreader/7z.so"); + if (sevenzlibrary.exists()) + { + sevenzLib = new QLibrary(sevenzlibrary.absoluteFilePath()); + } + else + { + sevenzLib = new QLibrary(QString(LIBDIR)+"/p7zip/7z.so"); + } +#else + sevenzLib = new QLibrary(QCoreApplication::applicationDirPath()+"/utils/7z"); +#endif + } + if(!sevenzLib->load()) + { + qDebug() << "Error Loading 7z.dll : " + sevenzLib->errorString() << endl; + QCoreApplication::exit(700); //TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound + return false; + } + else + { + qDebug() << "Loading functions" << endl; + + if((szInterface->createObjectFunc = (CreateObjectFunc)sevenzLib->resolve("CreateObject")) == 0) + qDebug() << "fail loading function : CreateObject" << endl; + if((szInterface->getMethodPropertyFunc = (GetMethodPropertyFunc)sevenzLib->resolve("GetMethodProperty")) == 0) + qDebug() << "fail loading function : GetMethodProperty" << endl; + if((szInterface->getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)sevenzLib->resolve("GetNumberOfMethods")) == 0) + qDebug() << "fail loading function : GetNumberOfMethods" << endl; + if((szInterface->getNumberOfFormatsFunc = (GetNumberOfFormatsFunc)sevenzLib->resolve("GetNumberOfFormats")) == 0) + qDebug() << "fail loading function : GetNumberOfFormats" << endl; + if((szInterface->getHandlerPropertyFunc = (GetHandlerPropertyFunc)sevenzLib->resolve("GetHandlerProperty")) == 0) + qDebug() << "fail loading function : GetHandlerProperty" << endl; + if((szInterface->getHandlerPropertyFunc2 = (GetHandlerPropertyFunc2)sevenzLib->resolve("GetHandlerProperty2")) == 0) + qDebug() << "fail loading function : GetHandlerProperty2" << endl; + if((szInterface->setLargePageModeFunc = (SetLargePageModeFunc)sevenzLib->resolve("SetLargePageMode")) == 0) + qDebug() << "fail loading function : SetLargePageMode" << endl; + +#ifdef Q_OS_UNIX + if((szInterface->createObjectFuncRar = (CreateObjectFunc)rarLib->resolve("CreateObject")) == 0) + qDebug() << "fail loading function (rar) : CreateObject" << endl; + if((szInterface->getMethodPropertyFuncRar = (GetMethodPropertyFunc)rarLib->resolve("GetMethodProperty")) == 0) + qDebug() << "fail loading function (rar) : GetMethodProperty" << endl; + if((szInterface->getNumberOfMethodsFuncRar = (GetNumberOfMethodsFunc)rarLib->resolve("GetNumberOfMethods")) == 0) + qDebug() << "fail loading function (rar) : GetNumberOfMethods" << endl; +#endif + } + + return true; +} + +void CompressedArchive::setupFilesNames() +{ + quint32 numItems = getNumEntries(); + quint32 p = 0; + for (quint32 i = 0; i < numItems; i++) + { + + // Get name of file + NWindows::NCOM::CPropVariant prop; + szInterface->archive->GetProperty(i, kpidIsDir, &prop); + bool isDir; + if (prop.vt == VT_BOOL) + isDir = VARIANT_BOOLToBool(prop.boolVal); + else if (prop.vt == VT_EMPTY) + isDir = false; + + if(!isDir) + { + szInterface->archive->GetProperty(i, kpidPath, &prop); + UString s = ConvertPropVariantToString(prop); + const wchar_t * chars = s.operator const wchar_t *(); + files.append(QString::fromWCharArray(chars)); + offsets.append(i); + indexesToPages.insert(i,p); + p++; + } + + } +} + +QVector CompressedArchive::translateIndexes(const QVector & indexes) +{ + QVector translatedIndexes; + + foreach(quint32 i, indexes) + { + if(i < offsets.length()) + translatedIndexes.append(offsets.at(i)); + } + + return translatedIndexes; +} + +QList CompressedArchive::getFileNames() +{ + return files; +} + +bool CompressedArchive::isValid() +{ + return valid; +} + +bool CompressedArchive::toolsLoaded() +{ + return tools; +} + +int CompressedArchive::getNumFiles() +{ + return files.length(); +} + +int CompressedArchive::getNumEntries() +{ + quint32 numItems = 0; + szInterface->archive->GetNumberOfItems(&numItems); + return numItems; +} + +QList CompressedArchive::getAllData(const QVector & indexes, ExtractDelegate * delegate) +{ + CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(indexesToPages, true, delegate); + CMyComPtr extractCallback(extractCallbackSpec); + extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path + extractCallbackSpec->PasswordIsDefined = false; + + QVector currentIndexes = translateIndexes(indexes); + + HRESULT result; + if(indexes.isEmpty()) + result = szInterface->archive->Extract(NULL, -1, false, extractCallback); + else + result = szInterface->archive->Extract(currentIndexes.data(), currentIndexes.count(), false, extractCallback); + if (result != S_OK) + { + qDebug() << "Extract Error" << endl; + } + + return extractCallbackSpec->allFiles; +} + +QByteArray CompressedArchive::getRawDataAtIndex(int index) +{ + if(index>=0 && index < getNumFiles()) + { + CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(indexesToPages); + CMyComPtr extractCallback(extractCallbackSpec); + extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path + extractCallbackSpec->PasswordIsDefined = false; + + UInt32 indices[1]; + + if(index < offsets.length()) + indices[0] = offsets.at(index); + else + indices[0] = index; + + HRESULT result = szInterface->archive->Extract(indices, 1, false, extractCallback); + if (result != S_OK) + { + qDebug() << "Extract Error" << endl; + } + + return QByteArray((char *)extractCallbackSpec->data,extractCallbackSpec->newFileSize); + } + return QByteArray(); +} + +#ifdef Q_OS_UNIX + +STDMETHODIMP CompressedArchive::GetNumberOfMethods(UInt32 *numMethods) +{ + return szInterface->getNumberOfMethodsFuncRar(numMethods); +} + +STDMETHODIMP CompressedArchive::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) +{ + return szInterface->getMethodPropertyFuncRar(index,propID,value); +} + +int i = 0; +STDMETHODIMP CompressedArchive::CreateDecoder(UInt32 index, const GUID *interfaceID, void **coder) +{ + NCOM::CPropVariant propVariant; + szInterface->getMethodPropertyFuncRar(index,NMethodPropID::kDecoder,&propVariant); + return szInterface->createObjectFuncRar((const GUID *)propVariant.bstrVal,interfaceID,coder); +} + +STDMETHODIMP CompressedArchive::CreateEncoder(UInt32 index, const GUID *interfaceID, void **coder) +{ + return S_OK;//szInterface->createObjectFuncRar(&CLSID_CFormatRar,interfaceID,coder); +} + +#endif diff --git a/compressed_archive/compressed_archive.h b/compressed_archive/compressed_archive.h new file mode 100644 index 00000000..75ace901 --- /dev/null +++ b/compressed_archive/compressed_archive.h @@ -0,0 +1,89 @@ +#ifndef COMPRESSED_ARCHIVE_H +#define COMPRESSED_ARCHIVE_H + +#include + +#ifdef Q_OS_UNIX + #include "libp7zip/CPP/7zip/ICoder.h" + #include "libp7zip/CPP/Common/MyCom.h" +#endif + +class ExtractDelegate; + +#ifdef Q_OS_WIN + #include "7z_includes.h" + #define _MY_WINAPI WINAPI +#else + #define _MY_WINAPI +#endif + +typedef quint32 (_MY_WINAPI * CreateObjectFunc)(const GUID *clsID,const GUID *interfaceID,void **outObject); +typedef quint32 (_MY_WINAPI *GetMethodPropertyFunc)(quint32 index, PROPID propID, PROPVARIANT *value); +typedef quint32 (_MY_WINAPI *GetNumberOfMethodsFunc)(quint32 *numMethods); +typedef quint32 (_MY_WINAPI *GetNumberOfFormatsFunc)(quint32 *numFormats); +typedef quint32 (_MY_WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value); +typedef quint32 (_MY_WINAPI *GetHandlerPropertyFunc2)(quint32 index, PROPID propID, PROPVARIANT *value); +typedef quint32 (_MY_WINAPI *SetLargePageModeFunc)(); + +class QLibrary; +#include +#include +#include + +struct SevenZipInterface; + +class MyCodecs; + +#ifdef Q_OS_UNIX + class CompressedArchive : public QObject, public ICompressCodecsInfo, public CMyUnknownImp +#else + class CompressedArchive : public QObject +#endif +{ + Q_OBJECT +public: + explicit CompressedArchive(const QString & filePath, QObject *parent = 0); + ~CompressedArchive(); + +#ifdef Q_OS_UNIX + MY_UNKNOWN_IMP + + STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods); + STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); + STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder); + STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder); + + bool isRar; +#endif + +signals: + +public slots: + int getNumFiles(); + int getNumEntries(); + QList getAllData(const QVector & indexes, ExtractDelegate * delegate = 0); + QByteArray getRawDataAtIndex(int index); + QList getFileNames(); + bool isValid(); + bool toolsLoaded(); +private: + SevenZipInterface * szInterface; + + QLibrary * sevenzLib; +#ifdef Q_OS_UNIX + QLibrary * rarLib; +#endif + bool loadFunctions(); + bool tools; + bool valid; + QList files; + QList offsets; + QMap indexesToPages; + + void setupFilesNames(); + QVector translateIndexes(const QVector &indexes); + + friend class MyCodecs; +}; + +#endif // COMPRESSED_ARCHIVE_H diff --git a/compressed_archive/extract_callbacks.h b/compressed_archive/extract_callbacks.h new file mode 100644 index 00000000..7b51cee9 --- /dev/null +++ b/compressed_archive/extract_callbacks.h @@ -0,0 +1,333 @@ +#ifndef EXTRACT_CALLBACKS_H +#define EXTRACT_CALLBACKS_H + +#include "7z_includes.h" +#include "extract_delegate.h" +#include + +using namespace NWindows; + +////////////////////////////////////////////////////////////// +// Archive Extracting callback class + +static const wchar_t *kCantDeleteOutputFile = L"ERROR: Can not delete output file "; + +static const char *kTestingString = "Testing "; +static const char *kExtractingString = "Extracting "; +static const char *kSkippingString = "Skipping "; + +static const char *kUnsupportedMethod = "Unsupported Method"; +static const char *kCRCFailed = "CRC Failed"; +static const char *kDataError = "Data Error"; +static const char *kUnknownError = "Unknown Error"; + +static const wchar_t *kEmptyFileAlias = L"[Content]"; + +static HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result) +{ + NCOM::CPropVariant prop; + RINOK(archive->GetProperty(index, propID, &prop)); + if (prop.vt == VT_BOOL) + result = VARIANT_BOOLToBool(prop.boolVal); + else if (prop.vt == VT_EMPTY) + result = false; + else + return E_FAIL; + return S_OK; +} +static HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result) +{ + return IsArchiveItemProp(archive, index, kpidIsDir, result); +} + +class CArchiveExtractCallback: + public IArchiveExtractCallback, + public ICryptoGetTextPassword, + public CMyUnknownImp +{ +public: + MY_UNKNOWN_IMP1(ICryptoGetTextPassword) + + // IProgress + STDMETHOD(SetTotal)(UInt64 size); + STDMETHOD(SetCompleted)(const UInt64 *completeValue); + + // IArchiveExtractCallback + STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode); + STDMETHOD(PrepareOperation)(Int32 askExtractMode); + STDMETHOD(SetOperationResult)(Int32 resultEOperationResult); + + // ICryptoGetTextPassword + STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword); + +private: + CMyComPtr _archiveHandler; + UString _directoryPath; // Output directory + UString _filePath; // name inside arcvhive + UString _diskFilePath; // full path to file on disk + bool _extractMode; + bool all; + ExtractDelegate * delegate; + UInt32 _index; + struct CProcessedFileInfo + { + FILETIME MTime; + UInt32 Attrib; + bool isDir; + bool AttribDefined; + bool MTimeDefined; + } _processedFileInfo; + + COutFileStream *_outFileStreamSpec; + CMyComPtr _outFileStream; + +public: + void Init(IInArchive *archiveHandler, const UString &directoryPath); + + UInt64 NumErrors; + bool PasswordIsDefined; + QList allFiles; + UString Password; + Byte * data; + UInt64 newFileSize; + QMap indexesToPages; + + CArchiveExtractCallback(const QMap & indexesToPages ,bool c = false,ExtractDelegate * d = 0) : PasswordIsDefined(false),all(c),delegate(d),indexesToPages(indexesToPages) {} + ~CArchiveExtractCallback() {MidFree(data);} +}; + +void CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath) +{ + NumErrors = 0; + _archiveHandler = archiveHandler; + directoryPath;//unused +} + +STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */) +{ + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */) +{ + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, + ISequentialOutStream **outStream, Int32 askExtractMode) +{ + *outStream = 0; + _outFileStream.Release(); + + if(indexesToPages.isEmpty()) + _index = index; + else + _index = indexesToPages.value(index); + + { + // Get Name + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop)); + + UString fullPath; + if (prop.vt == VT_EMPTY) + fullPath = kEmptyFileAlias; + else + { + if (prop.vt != VT_BSTR) + return E_FAIL; + fullPath = prop.bstrVal; + } + _filePath = fullPath; + } + + askExtractMode;//unused + //if (askExtractMode != NArchive::NExtract::NAskMode::kExtract) + //return S_OK; + + { + // Get Attrib + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop)); + if (prop.vt == VT_EMPTY) + { + _processedFileInfo.Attrib = 0; + _processedFileInfo.AttribDefined = false; + } + else + { + if (prop.vt != VT_UI4) + return E_FAIL; + _processedFileInfo.Attrib = prop.ulVal; + _processedFileInfo.AttribDefined = true; + } + } + + RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir)); + + { + // Get Modified Time + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop)); + _processedFileInfo.MTimeDefined = false; + switch(prop.vt) + { + case VT_EMPTY: + // _processedFileInfo.MTime = _utcMTimeDefault; + break; + case VT_FILETIME: + _processedFileInfo.MTime = prop.filetime; + _processedFileInfo.MTimeDefined = true; + break; + default: + return E_FAIL; + } + + } + + //se necesita conocer el tamaño del archivo para poder reservar suficiente memoria + bool newFileSizeDefined; + { + // Get Size + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop)); + newFileSizeDefined = (prop.vt != VT_EMPTY); + if (newFileSizeDefined) + newFileSize = ConvertPropVariantToUInt64(prop); + } + + //No hay que crear ningún fichero, ni directorios intermedios + /*{ + // Create folders for file + int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR); + if (slashPos >= 0) + NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos)); + } + + UString fullProcessedPath = _directoryPath + _filePath; + _diskFilePath = fullProcessedPath; + */ + if (_processedFileInfo.isDir) + { + //NFile::NDirectory::CreateComplexDirectory(fullProcessedPath); + } + else + { + /*NFile::NFind::CFileInfoW fi; + if (fi.Find(fullProcessedPath)) + { + if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath)) + { + qDebug() <<(UString(kCantDeleteOutputFile) + fullProcessedPath); + return E_ABORT; + } + }*/ + if(newFileSizeDefined) + { + CBufPtrSeqOutStream *outStreamSpec = new CBufPtrSeqOutStream; + CMyComPtr outStreamLocal(outStreamSpec); + data = (Byte *)MidAlloc(newFileSize); + outStreamSpec->Init(data, newFileSize); + *outStream = outStreamLocal.Detach(); + } + else + { + + } + + } + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode) +{ + _extractMode = false; + switch (askExtractMode) + { + case NArchive::NExtract::NAskMode::kExtract: _extractMode = true; break; + }; + /* switch (askExtractMode) + { + case NArchive::NExtract::NAskMode::kExtract: qDebug() << (kExtractingString); break; + case NArchive::NExtract::NAskMode::kTest: qDebug() <<(kTestingString); break; + case NArchive::NExtract::NAskMode::kSkip: qDebug() <<(kSkippingString); break; + };*/ + //qDebug() << _filePath; + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult) +{ + switch(operationResult) + { + case NArchive::NExtract::NOperationResult::kOK: + if(all && !_processedFileInfo.isDir) + { + QByteArray rawData((char *)data,newFileSize); + MidFree(data); + data = 0; + if(delegate != 0) + delegate->fileExtracted(_index,rawData); + else + { + allFiles.append(rawData); + } + } + break; + default: + { + NumErrors++; + qDebug() << " "; + switch(operationResult) + { + case NArchive::NExtract::NOperationResult::kUnSupportedMethod: + if(delegate != 0) + delegate->unknownError(_index); + qDebug() << kUnsupportedMethod; + break; + case NArchive::NExtract::NOperationResult::kCRCError: + if(delegate != 0) + delegate->crcError(_index); + qDebug() << kCRCFailed; + break; + case NArchive::NExtract::NOperationResult::kDataError: + if(delegate != 0) + delegate->unknownError(_index); + qDebug() << kDataError; + break; + default: + if(delegate != 0) + delegate->unknownError(_index); + qDebug() << kUnknownError; + } + } + } +/* + if (_outFileStream != NULL) + { + if (_processedFileInfo.MTimeDefined) + _outFileStreamSpec->SetMTime(&_processedFileInfo.MTime); + RINOK(_outFileStreamSpec->Close()); + } + _outFileStream.Release(); + if (_extractMode && _processedFileInfo.AttribDefined) + NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);*/ + //qDebug() << endl; + return S_OK; +} + + +STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password) +{ + if (!PasswordIsDefined) + { + // You can ask real password here from user + // Password = GetPassword(OutStream); + // PasswordIsDefined = true; + qDebug() << "Password is not defined" << endl; + return E_ABORT; + } + return StringToBstr(Password, password); +} + +#endif diff --git a/compressed_archive/extract_delegate.h b/compressed_archive/extract_delegate.h new file mode 100644 index 00000000..888d886a --- /dev/null +++ b/compressed_archive/extract_delegate.h @@ -0,0 +1,14 @@ +#ifndef EXTRACT_DELEGATE_H +#define EXTRACT_DELEGATE_H + +#include + +class ExtractDelegate +{ + public: + virtual void fileExtracted(int index, const QByteArray & rawData) = 0; + virtual void crcError(int index) = 0; + virtual void unknownError(int index) = 0; +}; + +#endif //EXTRACT_DELEGATE_H \ No newline at end of file diff --git a/compressed_archive/libp7zip.patch b/compressed_archive/libp7zip.patch new file mode 100644 index 00000000..522c1202 --- /dev/null +++ b/compressed_archive/libp7zip.patch @@ -0,0 +1,11 @@ +--- libp7zip/CPP/myWindows/StdAfx.h 2014-06-06 23:52:13.397311952 +0200 ++++ libp7zip/CPP/myWindows/StdAfx.h 2014-06-06 23:53:20.353981756 +0200 +@@ -114,7 +114,7 @@ + + #if defined( __x86_64__ ) + +-#define _WIN64 1 ++//#define _WIN64 1 + + #endif + diff --git a/compressed_archive/open_callbacks.h b/compressed_archive/open_callbacks.h new file mode 100644 index 00000000..d696c1f6 --- /dev/null +++ b/compressed_archive/open_callbacks.h @@ -0,0 +1,54 @@ +#ifndef OPEN_CALLBACKS_H +#define OPEN_CALLBACKS_H + +#include "7z_includes.h" +#include +////////////////////////////////////////////////////////////// +// Archive Open callback class + + +class CArchiveOpenCallback: + public IArchiveOpenCallback, + public ICryptoGetTextPassword, + public CMyUnknownImp +{ +public: + MY_UNKNOWN_IMP1(ICryptoGetTextPassword) + + STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes); + STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes); + + STDMETHOD(CryptoGetTextPassword)(BSTR *password); + + bool PasswordIsDefined; + UString Password; + + CArchiveOpenCallback() : PasswordIsDefined(false) {} +}; + +STDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */) +{ + return S_OK; +} + +STDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */) +{ + return S_OK; +} + +STDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password) +{ + if (!PasswordIsDefined) + { + // You can ask real password here from user + // Password = GetPassword(OutStream); + // PasswordIsDefined = true; + qDebug() << "Password is not defined" << endl; + return E_ABORT; + } + return StringToBstr(Password, password); +} + + + +#endif \ No newline at end of file diff --git a/compressed_archive/unarr/README.txt b/compressed_archive/unarr/README.txt new file mode 100644 index 00000000..bc96eb93 --- /dev/null +++ b/compressed_archive/unarr/README.txt @@ -0,0 +1,6 @@ +To use unarr as a decompression engine when building YACReader, download https://github.com/zeniko/unarr/archive/master.zip and extract it in this folder. +This will build unarr as a part of YACReader (static build). + +If you're on a Linux/Unix system and prefer to use unarr as a shared library, have a look at https://github.com/selmf/unarr/ +This fork of unarr includes a CMake based build system that allows you to build and install unarr as a shared library. YACReader will detect and use +the installed library at build time if it is installed. \ No newline at end of file diff --git a/compressed_archive/unarr/compressed_archive.cpp b/compressed_archive/unarr/compressed_archive.cpp new file mode 100644 index 00000000..b7594986 --- /dev/null +++ b/compressed_archive/unarr/compressed_archive.cpp @@ -0,0 +1,127 @@ +#include "compressed_archive.h" + +#include +#include + +#include "extract_delegate.h" + +extern"C" { +#include "unarr.h" +} + +CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) : + QObject(parent),valid(false),tools(true),numFiles(0),ar(NULL),stream(NULL) +{ + //open file + stream = ar_open_file(filePath.toStdString().c_str()); + if (!stream) + { + return; + } + + //open archive + ar = ar_open_rar_archive(stream); + //TODO: build unarr with 7z support and test this! + //if (!ar) ar = ar_open_7z_archive(stream); + if (!ar) ar = ar_open_tar_archive(stream); + //zip detection is costly, so it comes last... + if (!ar) ar = ar_open_zip_archive(stream, false); + if (!ar) + { + return; + } + + //initial parse + while (ar_parse_entry(ar)) + { + //make sure we really got a file header + if (ar_entry_get_size(ar) > 0) + { + fileNames.append(ar_entry_get_name(ar)); + offsets.append(ar_entry_get_offset(ar)); + numFiles++; + } + } + if (!ar_at_eof(ar)) + { + //fail if the initial parse didn't reach EOF + //this might be a bit too drastic + qDebug() << "Error while parsing archive"; + return; + } + if (numFiles > 0) + { + valid = true; + } +} + +CompressedArchive::~CompressedArchive() +{ + ar_close_archive(ar); + ar_close(stream); +} + +QList CompressedArchive::getFileNames() +{ + return fileNames; +} + +bool CompressedArchive::isValid() +{ + return valid; +} + +bool CompressedArchive::toolsLoaded() +{ + //for backwards compatibilty + return tools; +} + +int CompressedArchive::getNumFiles() +{ + return numFiles; +} + +void CompressedArchive::getAllData(const QVector & indexes, ExtractDelegate * delegate) +{ + if (indexes.isEmpty()) + return; + + QByteArray buffer; + + int i=0; + while (i < indexes.count()) + { + //use the offset list so we generated so we're not getting any non-page files + ar_parse_entry_at(ar, offsets.at(indexes.at(i))); //set ar_entry to start of indexes + buffer.resize(ar_entry_get_size(ar)); + if (ar_entry_uncompress(ar, buffer.data(), buffer.size())) //did we extract it? + { + delegate->fileExtracted(indexes.at(i), buffer); //return extracted file + } + else + { + delegate->crcError(indexes.at(i)); //we could not extract it... + } + i++; + } +} + +QByteArray CompressedArchive::getRawDataAtIndex(int index) +{ + QByteArray buffer; + if(index >= 0 && index < getNumFiles()) + { + ar_parse_entry_at(ar, offsets.at(index)); + buffer.resize(ar_entry_get_size(ar)); + if(ar_entry_uncompress(ar, buffer.data(), buffer.size())) + { + return buffer; + } + else + { + return QByteArray(); + } + } + return buffer; +} diff --git a/compressed_archive/unarr/compressed_archive.h b/compressed_archive/unarr/compressed_archive.h new file mode 100644 index 00000000..c0a99938 --- /dev/null +++ b/compressed_archive/unarr/compressed_archive.h @@ -0,0 +1,37 @@ +#ifndef COMPRESSED_ARCHIVE_H +#define COMPRESSED_ARCHIVE_H + +#include +#include "extract_delegate.h" +extern"C" { +#include "unarr.h" +} + +class CompressedArchive : public QObject +{ + Q_OBJECT +public: + explicit CompressedArchive(const QString & filePath, QObject *parent = 0); + ~CompressedArchive(); + +signals: + +public slots: + int getNumFiles(); + void getAllData(const QVector & indexes, ExtractDelegate * delegate=0); + QByteArray getRawDataAtIndex(int index); + QList getFileNames(); + bool isValid(); + bool toolsLoaded(); +private: + + bool tools; + bool valid; + QList fileNames; + int numFiles; + ar_archive *ar; + ar_stream *stream; + QList offsets; +}; + +#endif // COMPRESSED_ARCHIVE_H diff --git a/compressed_archive/unarr/extract_delegate.h b/compressed_archive/unarr/extract_delegate.h new file mode 100644 index 00000000..888d886a --- /dev/null +++ b/compressed_archive/unarr/extract_delegate.h @@ -0,0 +1,14 @@ +#ifndef EXTRACT_DELEGATE_H +#define EXTRACT_DELEGATE_H + +#include + +class ExtractDelegate +{ + public: + virtual void fileExtracted(int index, const QByteArray & rawData) = 0; + virtual void crcError(int index) = 0; + virtual void unknownError(int index) = 0; +}; + +#endif //EXTRACT_DELEGATE_H \ No newline at end of file diff --git a/compressed_archive/unarr/unarr-wrapper.pri b/compressed_archive/unarr/unarr-wrapper.pri new file mode 100644 index 00000000..2ba188c6 --- /dev/null +++ b/compressed_archive/unarr/unarr-wrapper.pri @@ -0,0 +1,36 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +HEADERS += $$PWD/extract_delegate.h \ + $$PWD/compressed_archive.h \ + +SOURCES += $$PWD/compressed_archive.cpp \ + +unix:!macx:exists (/usr/include/unarr.h) { + message(Using system provided unarr installation) + LIBS+=-lunarr + DEFINES+=use_unarr + } +else:macx:exists (../../dependencies/unarr/libunarr.dynlib) { + LIBS += -L../../dependencies/unarr/ -lunarr + DEFINES+=use_unarr + } + +else:win32:exists (../../dependencies/unarr/unarr.dll) { + LIBS += -L../../dependencies/unarr/ -lunarr + DEFINES+=use_unarr + } + +else:exists ($$PWD/unarr-master) { + message(Found unarr source-code) + message(Unarr will be build as a part of YACReader) + + #qmake based unarr build system + #this should only be used for testing or as a last resort + include(unarr.pro) + DEFINES+=use_unarr + } + else { + error(Missing dependency: unarr decrompression backend. Please install libunarr on your system\ + or provide a copy of the unarr source code in compressed_archive/unarr/unarr-master) + } \ No newline at end of file diff --git a/compressed_archive/unarr/unarr.pro b/compressed_archive/unarr/unarr.pro new file mode 100644 index 00000000..f024872f --- /dev/null +++ b/compressed_archive/unarr/unarr.pro @@ -0,0 +1,51 @@ +INCLUDEPATH += $$PWD/unarr-master/ +DEPENDPATH += $$PWD/unarr-master/ + +HEADERS+=$$PWD/unarr-master/common/allocator.h\ + $$PWD/unarr-master/common/unarr-imp.h\ + $$PWD/unarr-master/lzmasdk/CpuArch.h\ + $$PWD/unarr-master/lzmasdk/Ppmd7.h\ + $$PWD/unarr-master/lzmasdk/Ppmd.h\ + $$PWD/unarr-master/lzmasdk/LzmaDec.h\ + $$PWD/unarr-master/lzmasdk/Ppmd8.h\ + $$PWD/unarr-master/lzmasdk/Types.h\ + $$PWD/unarr-master/lzmasdk/CpuArch.h\ + $$PWD/unarr-master/lzmasdk/Ppmd7.h\ + $$PWD/unarr-master/lzmasdk/Ppmd.h\ + $$PWD/unarr-master/lzmasdk/LzmaDec.h\ + $$PWD/unarr-master/lzmasdk/Ppmd8.h\ + $$PWD/unarr-master/lzmasdk/Types.h\ + $$PWD/unarr-master/lzmasdk/CpuArch.h\ + $$PWD/unarr-master/lzmasdk/Ppmd7.h\ + $$PWD/unarr-master/lzmasdk/Ppmd.h\ + $$PWD/unarr-master/lzmasdk/LzmaDec.h\ + $$PWD/unarr-master/lzmasdk/Ppmd8.h\ + $$PWD/unarr-master/lzmasdk/Types.h\ + $$PWD/unarr-master/tar/tar.h\ + $$PWD/unarr-master/_7z/_7z.h\ + $$PWD/unarr-master/unarr.h + +SOURCES+=$$PWD/unarr-master/common/conv.c\ + $$PWD/unarr-master/common/custalloc.c\ + $$PWD/unarr-master/common/unarr.c\ + $$PWD/unarr-master/common/crc32.c\ + $$PWD/unarr-master/common/stream.c\ + $$PWD/unarr-master/lzmasdk/CpuArch.c\ + $$PWD/unarr-master/lzmasdk/Ppmd7.c\ + $$PWD/unarr-master/lzmasdk/Ppmd8.c\ + $$PWD/unarr-master/lzmasdk/LzmaDec.c\ + $$PWD/unarr-master/lzmasdk/Ppmd7Dec.c\ + $$PWD/unarr-master/lzmasdk/Ppmd8Dec.c\ + $$PWD/unarr-master/zip/inflate.c\ + $$PWD/unarr-master/zip/parse-zip.c\ + $$PWD/unarr-master/zip/uncompress-zip.c\ + $$PWD/unarr-master/zip/zip.c\ + $$PWD/unarr-master/rar/filter-rar.c\ + $$PWD/unarr-master/rar/parse-rar.c\ + $$PWD/unarr-master/rar/rarvm.c\ + $$PWD/unarr-master/rar/huffman-rar.c\ + $$PWD/unarr-master/rar/rar.c\ + $$PWD/unarr-master/rar/uncompress-rar.c\ + $$PWD/unarr-master/tar/parse-tar.c\ + $$PWD/unarr-master/tar/tar.c\ + $$PWD/unarr-master/_7z/_7z.c \ No newline at end of file diff --git a/compressed_archive/wrapper.pri b/compressed_archive/wrapper.pri new file mode 100644 index 00000000..9ae4b25b --- /dev/null +++ b/compressed_archive/wrapper.pri @@ -0,0 +1,127 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +win32 { +!exists (../compressed_archive/lib7zip) { + error(You\'ll need 7zip source code to compile YACReader. \ + Please check the compressed_archive folder for further instructions.) +} +} + +unix { +exists (../compressed_archive/libp7zip) { + message(Found p7zip source code...) + system(patch -N -p0 -i libp7zip.patch) +} else { + error(You\'ll need 7zip source code to compile YACReader. \ + Please check the compressed_archive folder for further instructions.) +} +} + +CONFIG += precompile_header + +win32 {PRECOMPILED_HEADER = $$PWD/StdAfx.h} +!win32 {PRECOMPILED_HEADER = $$PWD/libp7zip/CPP/myWindows/StdAfx.h} + +win32 { +INCLUDEPATH += $$PWD/lib7zip/CPP/ + +DEFINES += _UNICODE _WIN32 + +SOURCES += $$PWD/compressed_archive.cpp \ + $$PWD/lib7zip/CPP/Windows/FileIO.cpp \ + $$PWD/lib7zip/CPP/Windows/PropVariant.cpp \ + $$PWD/lib7zip/CPP/Windows/PropVariantConversions.cpp \ + $$PWD/lib7zip/CPP/Common/IntToString.cpp \ + $$PWD/lib7zip/CPP/Common/MyString.cpp \ + $$PWD/lib7zip/CPP/Common/MyVector.cpp \ + $$PWD/lib7zip/CPP/Common/StringConvert.cpp \ + $$PWD/lib7zip/CPP/Common/Wildcard.cpp \ + $$PWD/lib7zip/CPP/7zip/Common/FileStreams.cpp \ + $$PWD/lib7zip/CPP/7zip/Common/StreamUtils.cpp \ + $$PWD/lib7zip/C/Alloc.c \ + $$PWD/lib7zip/CPP/7zip/Common/StreamObjects.cpp + +HEADERS += $$PWD/compressed_archive.h \ + $$PWD/extract_delegate.h \ + $$PWD/7z_includes.h \ + $$PWD/open_callbacks.h \ + $$PWD/extract_callbacks.h\ + $$PWD/lib7zip/CPP/Windows/FileIO.h \ + $$PWD/lib7zip/CPP/Windows/PropVariant.h \ + $$PWD/lib7zip/CPP/Windows/PropVariantConversions.h \ + $$PWD/lib7zip/CPP/Common/IntToString.h \ + $$PWD/lib7zip/CPP/Common/MyString.h \ + $$PWD/lib7zip/CPP/Common/MyVector.h \ + $$PWD/lib7zip/CPP/Common/StringConvert.h \ + $$PWD/lib7zip/CPP/Common/Wildcard.h \ + $$PWD/lib7zip/CPP/7zip/Common/FileStreams.h \ + $$PWD/lib7zip/CPP/7zip/IStream.h \ + $$PWD/lib7zip/CPP/7zip/Common/StreamUtils.h \ + $$PWD/lib7zip/C/Alloc.h \ + $$PWD/lib7zip/CPP/7zip/Common/StreamObjects.h +} + +macx{ +LIBS += -framework IOKit -framework CoreFoundation + +DEFINES += UNICODE _UNICODE _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE \ + NDEBUG _REENTRANT ENV_UNIX \ + _7ZIP_LARGE_PAGES ENV_MACOSX _TCHAR_DEFINED +} + +unix:!macx{ +DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE \ + NDEBUG _REENTRANT ENV_UNIX \ + _7ZIP_LARGE_PAGES + } + +!win32 { +INCLUDEPATH += $$PWD/libp7zip/CPP/ \ + $$PWD/libp7zip/CPP/myWindows/ \ + $$PWD/libp7zip/CPP/include_windows/ + +SOURCES += $$PWD/compressed_archive.cpp \ + $$PWD/libp7zip/CPP/Windows/FileIO.cpp \ + $$PWD/libp7zip/CPP/Windows/FileFind.cpp \ + $$PWD/libp7zip/CPP/Windows/PropVariant.cpp \ + $$PWD/libp7zip/CPP/Windows/PropVariantConversions.cpp \ + $$PWD/libp7zip/CPP/Common/IntToString.cpp \ + $$PWD/libp7zip/CPP/Common/MyString.cpp \ + $$PWD/libp7zip/CPP/Common/MyVector.cpp \ + $$PWD/libp7zip/CPP/Common/StringConvert.cpp \ + $$PWD/libp7zip/CPP/Common/Wildcard.cpp \ + $$PWD/libp7zip/CPP/7zip/Common/FileStreams.cpp \ + $$PWD/libp7zip/CPP/7zip/Common/StreamUtils.cpp \ + $$PWD/libp7zip/C/Alloc.c \ + $$PWD/libp7zip/CPP/7zip/Common/StreamObjects.cpp \ + $$PWD/libp7zip/CPP/myWindows/wine_date_and_time.cpp \ + $$PWD/libp7zip/CPP/Common/MyWindows.cpp + +HEADERS += $$PWD/compressed_archive.h \ + $$PWD/7z_includes.h \ + $$PWD/open_callbacks.h \ + $$PWD/extract_callbacks.h\ + $$PWD/libp7zip/CPP/include_windows/windows.h \ + $$PWD/libp7zip/CPP/include_windows/tchar.h \ + $$PWD/libp7zip/CPP/include_windows/basetyps.h \ + $$PWD/libp7zip/CPP/Windows/FileFind.h \ + $$PWD/libp7zip/CPP/Windows/FileIO.h \ + $$PWD/libp7zip/CPP/Windows/PropVariant.h \ + $$PWD/libp7zip/CPP/Windows/PropVariantConversions.h \ + $$PWD/libp7zip/CPP/Common/IntToString.h \ + $$PWD/libp7zip/CPP/Common/MyString.h \ + $$PWD/libp7zip/CPP/Common/MyVector.h \ + $$PWD/libp7zip/CPP/Common/StringConvert.h \ + $$PWD/libp7zip/CPP/Common/Wildcard.h \ + $$PWD/libp7zip/CPP/7zip/Common/FileStreams.h \ + $$PWD/libp7zip/CPP/7zip/IStream.h \ + $$PWD/libp7zip/CPP/7zip/Common/StreamUtils.h \ + $$PWD/libp7zip/C/Alloc.h \ + $$PWD/libp7zip/CPP/7zip/Common/StreamObjects.h \ + $$PWD/libp7zip/CPP/Common/MyWindows.h \ + $$PWD/libp7zip/CPP/7zip/ICoder.h \ +} + + + diff --git a/config.pri b/config.pri new file mode 100644 index 00000000..0d4733bd --- /dev/null +++ b/config.pri @@ -0,0 +1,40 @@ +#functions to automatically initialize some of YACReader's build options to +#default values if they're not set on build time +#for a more detailed description, see INSTALL.TXT + +#check Qt version +QT_VERSION = $$[QT_VERSION] +QT_VERSION = $$split(QT_VERSION, ".") +QT_VER_MAJ = $$member(QT_VERSION, 0) +QT_VER_MIN = $$member(QT_VERSION, 1) + +lessThan(QT_VER_MAJ, 5) { +error(YACReader requires Qt 5 or newer but Qt $$[QT_VERSION] was detected.) + } +lessThan(QT_VER_MIN, 4):!CONFIG(no_opengl) { + CONFIG += legacy_gl_widget + message ("Qt < 5.4 detected. Using QGLWidget for coverflow.") + } +lessThan(QT_VER_MIN, 3){ + error ("You need at least Qt 5.3 to build YACReader or YACReaderLibrary") + } + +#build without opengl widget support +CONFIG(no_opengl) { + DEFINES += NO_OPENGL +} + +!CONFIG(unarr):!CONFIG(7zip) { + unix { + !macx { + CONFIG+=unarr + } + else { + CONFIG+=7zip + } + + } + win32 { + CONFIG+=7zip + } +} \ No newline at end of file diff --git a/create-dmg b/create-dmg new file mode 100755 index 00000000..b581913f --- /dev/null +++ b/create-dmg @@ -0,0 +1,221 @@ +#! /bin/bash + +# Create a read-only disk image of the contents of a folder + +set -e; + +function pure_version() { + echo '1.0.0.2' +} + +function version() { + echo "create-dmg $(pure_version)" +} + +function usage() { + version + echo "Creates a fancy DMG file." + echo "Usage: $(basename $0) options... image.dmg source_folder" + echo "All contents of source_folder will be copied into the disk image." + echo "Options:" + echo " --volname name" + echo " set volume name (displayed in the Finder sidebar and window title)" + echo " --volicon icon.icns" + echo " set volume icon" + echo " --background pic.png" + echo " set folder background image (provide png, gif, jpg)" + echo " --window-pos x y" + echo " set position the folder window" + echo " --window-size width height" + echo " set size of the folder window" + echo " --icon-size icon_size" + echo " set window icons size (up to 128)" + echo " --icon file_name x y" + echo " set position of the file's icon" + echo " --hide-extension file_name" + echo " hide the extension of file" + echo " --custom-icon file_name custom_icon_or_sample_file x y" + echo " set position and custom icon" + echo " --app-drop-link x y" + echo " make a drop link to Applications, at location x,y" + echo " --eula eula_file" + echo " attach a license file to the dmg" + echo " --no-internet-enable" + echo " disable automatic mount©" + echo " --version show tool version number" + echo " -h, --help display this help" + exit 0 +} + +WINX=10 +WINY=60 +WINW=500 +WINH=350 +ICON_SIZE=128 + +while test "${1:0:1}" = "-"; do + case $1 in + --volname) + VOLUME_NAME="$2" + shift; shift;; + --volicon) + VOLUME_ICON_FILE="$2" + shift; shift;; + --background) + BACKGROUND_FILE="$2" + BACKGROUND_FILE_NAME="$(basename $BACKGROUND_FILE)" + BACKGROUND_CLAUSE="set background picture of opts to file \".background:$BACKGROUND_FILE_NAME\"" + shift; shift;; + --icon-size) + ICON_SIZE="$2" + shift; shift;; + --window-pos) + WINX=$2; WINY=$3 + shift; shift; shift;; + --window-size) + WINW=$2; WINH=$3 + shift; shift; shift;; + --icon) + POSITION_CLAUSE="${POSITION_CLAUSE}set position of item \"$2\" to {$3, $4} +" + shift; shift; shift; shift;; + --hide-extension) + HIDING_CLAUSE="${HIDING_CLAUSE}set the extension hidden of item \"$2\" to true" + shift; shift;; + --custom-icon) + shift; shift; shift; shift; shift;; + -h | --help) + usage;; + --version) + version; exit 0;; + --pure-version) + pure_version; exit 0;; + --app-drop-link) + APPLICATION_LINK=$2 + APPLICATION_CLAUSE="set position of item \"Applications\" to {$2, $3} +" + shift; shift; shift;; + --eula) + EULA_RSRC=$2 + shift; shift;; + --no-internet-enable) + NOINTERNET=1 + shift;; + -*) + echo "Unknown option $1. Run with --help for help." + exit 1;; + esac +done + +test -z "$2" && { + echo "Not enough arguments. Invoke with --help for help." + exit 1 +} + +DMG_PATH="$1" +DMG_DIRNAME="$(dirname "$DMG_PATH")" +DMG_DIR="$(cd $DMG_DIRNAME > /dev/null; pwd)" +DMG_NAME="$(basename "$DMG_PATH")" +DMG_TEMP_NAME="$DMG_DIR/rw.${DMG_NAME}" +SRC_FOLDER="$(cd "$2" > /dev/null; pwd)" +test -z "$VOLUME_NAME" && VOLUME_NAME="$(basename "$DMG_PATH" .dmg)" + +AUX_PATH="$(dirname $0)/support" + +test -d "$AUX_PATH" || { + echo "Cannot find support directory: $AUX_PATH" + exit 1 +} + +if [ -f "$SRC_FOLDER/.DS_Store" ]; then + echo "Deleting any .DS_Store in source folder" + rm "$SRC_FOLDER/.DS_Store" +fi + +# Create the image +echo "Creating disk image..." +test -f "${DMG_TEMP_NAME}" && rm -f "${DMG_TEMP_NAME}" +ACTUAL_SIZE=`du -sm "$SRC_FOLDER" | sed -e 's/ .*//g'` +DISK_IMAGE_SIZE=$(expr $ACTUAL_SIZE + 20) +hdiutil create -srcfolder "$SRC_FOLDER" -volname "${VOLUME_NAME}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${DISK_IMAGE_SIZE}m "${DMG_TEMP_NAME}" + +# mount it +echo "Mounting disk image..." +MOUNT_DIR="/Volumes/${VOLUME_NAME}" + +# try unmount dmg if it was mounted previously (e.g. developer mounted dmg, installed app and forgot to unmount it) +echo "Unmounting disk image..." +DEV_NAME=$(hdiutil info | egrep '^/dev/' | sed 1q | awk '{print $1}') +test -d "${MOUNT_DIR}" && hdiutil detach "${DEV_NAME}" + +echo "Mount directory: $MOUNT_DIR" +DEV_NAME=$(hdiutil attach -readwrite -noverify -noautoopen "${DMG_TEMP_NAME}" | egrep '^/dev/' | sed 1q | awk '{print $1}') +echo "Device name: $DEV_NAME" + +if ! test -z "$BACKGROUND_FILE"; then + echo "Copying background file..." + test -d "$MOUNT_DIR/.background" || mkdir "$MOUNT_DIR/.background" + cp "$BACKGROUND_FILE" "$MOUNT_DIR/.background/$BACKGROUND_FILE_NAME" +fi + +if ! test -z "$APPLICATION_LINK"; then + echo "making link to Applications dir" + echo $MOUNT_DIR + ln -s /Applications "$MOUNT_DIR/Applications" +fi + +if ! test -z "$VOLUME_ICON_FILE"; then + echo "Copying volume icon file '$VOLUME_ICON_FILE'..." + cp "$VOLUME_ICON_FILE" "$MOUNT_DIR/.VolumeIcon.icns" + SetFile -c icnC "$MOUNT_DIR/.VolumeIcon.icns" +fi + +# run applescript +APPLESCRIPT=$(mktemp -t createdmg) +cat "$AUX_PATH/template.applescript" | sed -e "s/WINX/$WINX/g" -e "s/WINY/$WINY/g" -e "s/WINW/$WINW/g" -e "s/WINH/$WINH/g" -e "s/BACKGROUND_CLAUSE/$BACKGROUND_CLAUSE/g" -e "s/ICON_SIZE/$ICON_SIZE/g" | perl -pe "s/POSITION_CLAUSE/$POSITION_CLAUSE/g" | perl -pe "s/APPLICATION_CLAUSE/$APPLICATION_CLAUSE/g" | perl -pe "s/HIDING_CLAUSE/$HIDING_CLAUSE/" >"$APPLESCRIPT" + +echo "Running Applescript: /usr/bin/osascript \"${APPLESCRIPT}\" \"${VOLUME_NAME}\"" +"/usr/bin/osascript" "${APPLESCRIPT}" "${VOLUME_NAME}" || true +echo "Done running the applescript..." +sleep 4 + +rm "$APPLESCRIPT" + +# make sure it's not world writeable +echo "Fixing permissions..." +chmod -Rf go-w "${MOUNT_DIR}" &> /dev/null || true +echo "Done fixing permissions." + +# make the top window open itself on mount: +echo "Blessing started" +bless --folder "${MOUNT_DIR}" --openfolder "${MOUNT_DIR}" +echo "Blessing finished" + +if ! test -z "$VOLUME_ICON_FILE"; then + # tell the volume that it has a special file attribute + SetFile -a C "$MOUNT_DIR" +fi + +# unmount +echo "Unmounting disk image..." +hdiutil detach "${DEV_NAME}" + +# compress image +echo "Compressing disk image..." +hdiutil convert "${DMG_TEMP_NAME}" -format UDZO -imagekey zlib-level=9 -o "${DMG_DIR}/${DMG_NAME}" +rm -f "${DMG_TEMP_NAME}" + +# adding EULA resources +if [ ! -z "${EULA_RSRC}" -a "${EULA_RSRC}" != "-null-" ]; then + echo "adding EULA resources" + "${AUX_PATH}/dmg-license.py" "${DMG_DIR}/${DMG_NAME}" "${EULA_RSRC}" +fi + +if [ ! -z "${NOINTERNET}" -a "${NOINTERNET}" == 1 ]; then + echo "not setting 'internet-enable' on the dmg" +else + hdiutil internet-enable -yes "${DMG_DIR}/${DMG_NAME}" +fi + +echo "Disk image done" +exit 0 diff --git a/custom_widgets/custom_widgets_yacreader.pri b/custom_widgets/custom_widgets_yacreader.pri new file mode 100644 index 00000000..fcadc933 --- /dev/null +++ b/custom_widgets/custom_widgets_yacreader.pri @@ -0,0 +1,38 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +HEADERS += $$PWD/help_about_dialog.h \ + $$PWD/yacreader_field_edit.h \ + $$PWD/yacreader_field_plain_text_edit.h \ + $$PWD/yacreader_flow.h \ + $$PWD/yacreader_flow_config_widget.h \ + $$PWD/yacreader_options_dialog.h \ + $$PWD/yacreader_spin_slider_widget.h \ + $$PWD/yacreader_tool_bar_stretch.h \ + $$PWD/yacreader_busy_widget.h +!CONFIG(no_opengl) { + HEADERS += $$PWD/yacreader_gl_flow_config_widget.h +} + +macx{ +HEADERS += $$PWD/yacreader_macosx_toolbar.h +} + + + +SOURCES += $$PWD/help_about_dialog.cpp \ + $$PWD/yacreader_field_edit.cpp \ + $$PWD/yacreader_field_plain_text_edit.cpp \ + $$PWD/yacreader_flow.cpp \ + $$PWD/yacreader_flow_config_widget.cpp \ + $$PWD/yacreader_options_dialog.cpp \ + $$PWD/yacreader_spin_slider_widget.cpp \ + $$PWD/yacreader_tool_bar_stretch.cpp \ + $$PWD/yacreader_busy_widget.cpp +!CONFIG(no_opengl) { + SOURCES += $$PWD/yacreader_gl_flow_config_widget.cpp +} +macx{ +OBJECTIVE_SOURCES += $$PWD/yacreader_macosx_toolbar.mm +} + diff --git a/custom_widgets/custom_widgets_yacreaderlibrary.pri b/custom_widgets/custom_widgets_yacreaderlibrary.pri new file mode 100644 index 00000000..ccb13afe --- /dev/null +++ b/custom_widgets/custom_widgets_yacreaderlibrary.pri @@ -0,0 +1,53 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +HEADERS += $$PWD/help_about_dialog.h \ + $$PWD/yacreader_field_edit.h \ + $$PWD/yacreader_field_plain_text_edit.h \ + $$PWD/yacreader_flow.h \ + $$PWD/yacreader_flow_config_widget.h \ + $$PWD/yacreader_options_dialog.h \ + $$PWD/yacreader_search_line_edit.h \ + $$PWD/yacreader_spin_slider_widget.h \ + $$PWD/yacreader_tool_bar_stretch.h \ + $$PWD/yacreader_titled_toolbar.h \ + $$PWD/yacreader_deleting_progress.h \ + $$PWD/yacreader_table_view.h \ + $$PWD/yacreader_sidebar.h \ + $$PWD/yacreader_library_list_widget.h \ + $$PWD/yacreader_library_item_widget.h \ + $$PWD/yacreader_treeview.h \ + $$PWD/yacreader_busy_widget.h +!CONFIG(no_opengl){ + HEADERS += $$PWD/yacreader_gl_flow_config_widget.h +} + +macx{ +HEADERS += $$PWD/yacreader_macosx_toolbar.h +} + +SOURCES += $$PWD/help_about_dialog.cpp \ + $$PWD/yacreader_field_edit.cpp \ + $$PWD/yacreader_field_plain_text_edit.cpp \ + $$PWD/yacreader_flow.cpp \ + $$PWD/yacreader_flow_config_widget.cpp \ + $$PWD/yacreader_options_dialog.cpp \ + $$PWD/yacreader_search_line_edit.cpp \ + $$PWD/yacreader_spin_slider_widget.cpp \ + $$PWD/yacreader_tool_bar_stretch.cpp \ + $$PWD/yacreader_titled_toolbar.cpp \ + $$PWD/yacreader_deleting_progress.cpp \ + $$PWD/yacreader_table_view.cpp \ + $$PWD/yacreader_sidebar.cpp \ + $$PWD/yacreader_library_list_widget.cpp \ + $$PWD/yacreader_library_item_widget.cpp \ + $$PWD/yacreader_treeview.cpp \ + $$PWD/yacreader_busy_widget.cpp + +!CONFIG(no_opengl){ + SOURCES += $$PWD/yacreader_gl_flow_config_widget.cpp +} + +macx{ +OBJECTIVE_SOURCES += $$PWD/yacreader_macosx_toolbar.mm +} diff --git a/custom_widgets/help_about_dialog.cpp b/custom_widgets/help_about_dialog.cpp new file mode 100644 index 00000000..ff926a6b --- /dev/null +++ b/custom_widgets/help_about_dialog.cpp @@ -0,0 +1,75 @@ +#include "help_about_dialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "yacreader_global.h" + +HelpAboutDialog::HelpAboutDialog(QWidget * parent) +:QDialog(parent) +{ + QVBoxLayout * layout = new QVBoxLayout(); + + tabWidget = new QTabWidget(); + + tabWidget->addTab(aboutText = new QTextBrowser(), tr("About")); + aboutText->setOpenExternalLinks(true); + //aboutText->setFont(QFont("Comic Sans MS", 10)); //purisa + tabWidget->addTab(helpText = new QTextBrowser(), tr("Help")); + helpText->setOpenExternalLinks(true); + //helpText->setFont(QFont("Comic Sans MS", 10)); + //helpText->setDisabled(true); + //tabWidget->addTab(,"About Qt"); + + layout->addWidget(tabWidget); + layout->setContentsMargins(1,3,1,1); + + setLayout(layout); + resize(500, QApplication::desktop()->availableGeometry().height()*0.83); +} + +HelpAboutDialog::~HelpAboutDialog() +{ + delete aboutText; + delete helpText; + delete tabWidget; +} + +HelpAboutDialog::HelpAboutDialog(const QString & pathAbout,const QString & pathHelp,QWidget * parent) +:QDialog(parent) +{ + loadAboutInformation(pathAbout); + loadHelp(pathHelp); +} + +void HelpAboutDialog::loadAboutInformation(const QString & path) +{ + aboutText->setHtml(fileToString(path).arg(VERSION)); + aboutText->moveCursor(QTextCursor::Start); +} + +void HelpAboutDialog::loadHelp(const QString & path) +{ + helpText->setHtml(fileToString(path)); + helpText->moveCursor(QTextCursor::Start); +} + +QString HelpAboutDialog::fileToString(const QString & path) +{ + QFile f(path); + f.open(QIODevice::ReadOnly); + QTextStream txtS(&f); + + txtS.setCodec(QTextCodec::codecForName("UTF-8")); + + QString content = txtS.readAll(); + f.close(); + + return content; +} \ No newline at end of file diff --git a/custom_widgets/help_about_dialog.h b/custom_widgets/help_about_dialog.h new file mode 100644 index 00000000..70a0a662 --- /dev/null +++ b/custom_widgets/help_about_dialog.h @@ -0,0 +1,28 @@ +#ifndef HELP_ABOUT_DIALOG_H +#define HELP_ABOUT_DIALOG_H + +#include + +class QTabWidget; +class QTextBrowser; + +class HelpAboutDialog : public QDialog +{ +Q_OBJECT +public: + HelpAboutDialog(QWidget * parent=0); + HelpAboutDialog(const QString & pathAbout,const QString & pathHelp,QWidget * parent =0); + ~HelpAboutDialog(); +public slots: + void loadAboutInformation(const QString & path); + void loadHelp(const QString & path); + +private: + QTabWidget *tabWidget; + QTextBrowser *aboutText; + QTextBrowser *helpText; + QString fileToString(const QString & path); +}; + + +#endif // HELP_ABOUT_DIALOG_H \ No newline at end of file diff --git a/custom_widgets/yacreader_busy_widget.cpp b/custom_widgets/yacreader_busy_widget.cpp new file mode 100644 index 00000000..94e93718 --- /dev/null +++ b/custom_widgets/yacreader_busy_widget.cpp @@ -0,0 +1,187 @@ +#include "yacreader_busy_widget.h" + +#include +#include +#include +#include + +YACReaderBusyWidget::YACReaderBusyWidget(QWidget *parent) + :QWidget(parent) +{ + setFixedSize(70,70); + BusyIndicator * busy = new BusyIndicator(this); + busy->setIndicatorStyle(BusyIndicator::StyleArc); + busy->setColor(Qt::white); + busy->move(20,20); +} + +void YACReaderBusyWidget::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event); + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.drawPixmap(0,0,width(),height(),QPixmap(":/images/busy_background.png")); +} + +BusyIndicator::BusyIndicator(QWidget *parent) : + QWidget(parent), + startAngle(0), + m_style(StyleArc) +{ + QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Fixed); + policy.setHeightForWidth(true); + setSizePolicy(policy); + + fillColor = palette().color(QPalette::WindowText); + + timer.setInterval(16); + connect(&timer, SIGNAL(timeout()), this, SLOT(rotate())); + timer.start(); +} + +void BusyIndicator::rotate() +{ + startAngle += 9; + startAngle %= 360; + update(); +} + +void BusyIndicator::setIndicatorStyle(IndicatorStyle style) +{ + m_style = style; + update(); +} + +void BusyIndicator::setColor(QColor color) +{ + fillColor = color; +} + +const BusyIndicator::IndicatorStyle BusyIndicator::indicatorStyle() const +{ + return m_style; +} + + +QPixmap BusyIndicator::generatePixmap(int side) +{ + QPixmap pixmap(QSize(side, side)); + pixmap.fill(QColor(255, 255, 255, 0)); + + QPainter painter(&pixmap); + painter.setRenderHint(QPainter::Antialiasing); + + painter.translate(side / 2, side / 2); + painter.scale(side / 200.0, side / 200.0); + + switch (m_style) { + case StyleRect: + drawRectStyle(&painter); + break; + case StyleEllipse: + drawEllipseStyle(&painter); + break; + case StyleArc: + drawArcStyle(&painter); + break; + } + return pixmap; +} + +void BusyIndicator::drawRectStyle(QPainter *painter) +{ + // QColor color = palette().color(QPalette::WindowText); + QColor color = fillColor; + QBrush brush(color); + painter->setPen(Qt::NoPen); + + painter->rotate(startAngle); + + float angle = 0; + while (angle < 360) { + painter->setBrush(brush); + painter->drawRect(-8, -100, 16, 35); + + painter->rotate(30); + angle += 30; + + color.setAlphaF(angle / 360); + brush.setColor(color); + } +} + +void BusyIndicator::drawEllipseStyle(QPainter *painter) +{ + // QColor color = palette().color(QPalette::WindowText); + QColor color = fillColor; + QBrush brush(color); + painter->setPen(Qt::NoPen); + + painter->rotate(startAngle); + + float angle = 0; + while (angle < 360) { + painter->setBrush(brush); + painter->drawEllipse(-10, -100, 30, 30); + + painter->rotate(30); + angle += 30; + + color.setAlphaF(angle / 360); + brush.setColor(color); + } +} + +void BusyIndicator::drawArcStyle(QPainter *painter) +{ + // QColor color = palette().color(QPalette::WindowText); + QColor color = fillColor; + QConicalGradient gradient(0, 0, -startAngle); + gradient.setColorAt(0, color); + color.setAlpha(0); + gradient.setColorAt(0.8, color); + color.setAlpha(255); + gradient.setColorAt(1, color); + + QPen pen; + pen.setWidth(30); + pen.setBrush(QBrush(gradient)); + painter->setPen(pen); + + painter->drawArc(-85, -85, 170, 170, 0 * 16, 360 * 16); +} + +void BusyIndicator::paintEvent(QPaintEvent *) +{ + QString key = QString("%1:%2:%3:%4:%5") + .arg(metaObject()->className()) + .arg(width()) + .arg(height()) + .arg(startAngle) + .arg(m_style); + + QPixmap pixmap; + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + int side = qMin(width(), height()); + + if(!QPixmapCache::find(key, &pixmap)) { + pixmap = generatePixmap(side); + QPixmapCache::insert(key, pixmap); + } + + painter.translate(width() / 2 - side / 2, height() / 2 - side / 2); + + painter.drawPixmap(0, 0, side, side, pixmap); +} + +QSize BusyIndicator::minimumSizeHint() const +{ + return QSize(30, 30); +} + +QSize BusyIndicator::sizeHint() const +{ + return QSize(30, 30); +} diff --git a/custom_widgets/yacreader_busy_widget.h b/custom_widgets/yacreader_busy_widget.h new file mode 100644 index 00000000..c98dda07 --- /dev/null +++ b/custom_widgets/yacreader_busy_widget.h @@ -0,0 +1,50 @@ +#ifndef YACREADER_BUSYINDICATOR_H +#define YACREADER_BUSYINDICATOR_H + +#include +#include + +class YACReaderBusyWidget : public QWidget +{ + Q_OBJECT +public: + explicit YACReaderBusyWidget(QWidget *parent = 0); + void paintEvent(QPaintEvent *); +}; + +class BusyIndicator : public QWidget +{ + Q_OBJECT +public: + enum IndicatorStyle{StyleRect, StyleEllipse, StyleArc}; + + explicit BusyIndicator(QWidget *parent = 0); + + void paintEvent(QPaintEvent *); + QSize minimumSizeHint() const; + QSize sizeHint() const; + + void setIndicatorStyle(IndicatorStyle); + void setColor(QColor color); + const IndicatorStyle indicatorStyle() const; + +signals: + +private slots: + void rotate(); + +private: + QPixmap generatePixmap(int sideLength); + void drawRectStyle(QPainter *painter); + void drawEllipseStyle(QPainter *painter); + void drawArcStyle(QPainter *painter); + + QTimer timer; + int startAngle; + + IndicatorStyle m_style; + + QColor fillColor; +}; + +#endif // BUSYINDICATOR_H diff --git a/custom_widgets/yacreader_dark_menu.cpp b/custom_widgets/yacreader_dark_menu.cpp new file mode 100644 index 00000000..0ed7118c --- /dev/null +++ b/custom_widgets/yacreader_dark_menu.cpp @@ -0,0 +1,38 @@ +#include "yacreader_dark_menu.h" + +#include +#include +#include + +YACReaderDarkMenu::YACReaderDarkMenu(QWidget * parent) + :QMenu(parent) +{ + //solid color: #454545 + QString style = "QMenu {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6B6B6B, stop: 1 #424242); " + "border-left: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #BCBCBC, stop: 1 #4C4C4C);" + "border-right: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #BCBCBC, stop: 1 #4C4C4C);" + "border-top: 1px solid #BCBCBC;" + "border-bottom: 1px solid #4C4C4C;" + "padding-top:5px;padding-bottom:5px;}" + "QMenu::separator {height:0px;border-top: 1px solid #292929; border-bottom:1px solid #737373; margin-left:-1px; margin-right:-1px;}" + "QMenu::item {color:#CFD1D1;padding: 5px 25px 5px 32px;}" + "QMenu::item::selected {background-color:#242424;border-top: 1px solid #151515; border-bottom:1px solid #737373;}" + "QMenu::icon {padding-left:15px;}"; + + setStyleSheet(style); + + /* + QPixmap p(":/images/icon.png"); + QLabel * l = new QLabel(); + l->setPixmap(p); + l->move(0,-10); + + //test + YACReaderDarkMenu * customMenu = new YACReaderDarkMenu(this); + customMenu->addAction(toggleFullScreenAction); + customMenu->addAction(createLibraryAction); + customMenu->addSeparator(); + customMenu->addAction(openComicAction); + customMenu->show(); + */ +} \ No newline at end of file diff --git a/custom_widgets/yacreader_dark_menu.h b/custom_widgets/yacreader_dark_menu.h new file mode 100644 index 00000000..6d28749d --- /dev/null +++ b/custom_widgets/yacreader_dark_menu.h @@ -0,0 +1,14 @@ +#ifndef YACREADER_DARK_MENU_H +#define YACREADER_DARK_MENU_H + +#include + + +class YACReaderDarkMenu : public QMenu +{ + Q_OBJECT + public: + YACReaderDarkMenu(QWidget * parent = 0); +}; + +#endif // YACREADER_DARK_MENU_H \ No newline at end of file diff --git a/custom_widgets/yacreader_deleting_progress.cpp b/custom_widgets/yacreader_deleting_progress.cpp new file mode 100644 index 00000000..62a5a78f --- /dev/null +++ b/custom_widgets/yacreader_deleting_progress.cpp @@ -0,0 +1,106 @@ +#include "yacreader_deleting_progress.h" + +#include +#include +#include +#include +#include +#include + +YACReaderDeletingProgress::YACReaderDeletingProgress(QWidget *parent) : + QWidget(parent) +{ + QVBoxLayout * contentLayout = new QVBoxLayout(this); + + QLabel * iconLabel = new QLabel(); + QPixmap icon(":/images/deleting_progress/icon.png"); + iconLabel->setPixmap(icon); + iconLabel->setStyleSheet("QLabel {padding:0px; margin:0px;}"); + + textMessage = new QLabel(tr("Please wait, deleting in progress...")); + + textMessage->setStyleSheet("QLabel {color:#ABABAB; padding:0 0 0 0px; margin:0px; font-size:18px; font-weight:bold;}"); + + QProgressBar * progressBar = new QProgressBar(); + + progressBar->setTextVisible(false); + progressBar->setFixedHeight(6); + progressBar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); + progressBar->setRange (0,10); + progressBar->setValue(5); + progressBar->setStyleSheet( + "QProgressBar { border: none; border-radius: 3px; background: #ABABAB; margin:0; margin-left:16; margin-right:16px;}" + "QProgressBar::chunk {background-color: #FFC745; border: none; border-radius: 3px;}"); + + QPushButton * button = new QPushButton(tr("cancel")); + + button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + + contentLayout->addSpacing(16); + contentLayout->addWidget(iconLabel,0,Qt::AlignHCenter); + contentLayout->addSpacing(11); + contentLayout->addWidget(textMessage,0,Qt::AlignHCenter); + contentLayout->addSpacing(13); + contentLayout->addWidget(progressBar); + contentLayout->addSpacing(13); + contentLayout->addWidget(button,0,Qt::AlignHCenter); + contentLayout->addSpacing(18); + + contentLayout->setMargin(0); + + setLayout(contentLayout); + + setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + + resize( sizeHint() ); +} + +void YACReaderDeletingProgress::paintEvent(QPaintEvent * event) +{ + int borderTop, borderRight, borderBottom, borderLeft; + + QPixmap pL(":/images/deleting_progress/imgTopLeft.png"); + QPixmap pM(":/images/deleting_progress/imgTopMiddle.png"); + QPixmap pR(":/images/deleting_progress/imgTopRight.png"); + + QPixmap pLM(":/images/deleting_progress/imgLeftMiddle.png"); + + QPixmap pRM(":/images/deleting_progress/imgRightMiddle.png"); + + QPixmap pBL(":/images/deleting_progress/imgBottomLeft.png"); + QPixmap pBM(":/images/deleting_progress/imgBottomMiddle.png"); + QPixmap pBR(":/images/deleting_progress/imgBottomRight.png"); + + borderTop = pL.height(); + borderRight = pRM.width(); + borderBottom = pBM.height(); + borderLeft = pLM.width(); + + int width = this->width()-borderRight-borderLeft; + int height = this->height()-borderTop-borderBottom; + + QPainter painter(this); + + //corners + painter.drawPixmap(0,0,pL); + painter.drawPixmap(this->width()-borderRight,0,pR); + painter.drawPixmap(0,this->height()-pBL.height(),pBL); + painter.drawPixmap(this->width()-pBR.width(),this->height()-borderBottom,pBR); + + //middle + painter.drawPixmap(borderRight,0,width,borderTop,pM); + painter.drawPixmap(0,borderTop,borderLeft,height,pLM); + painter.drawPixmap(width+borderLeft,borderTop,borderRight,height,pRM); + painter.drawPixmap(pBR.width(),height+borderTop,this->width()-pBR.width()-pBL.width(),pBR.height(),pBM); + + //center + painter.fillRect(borderLeft,borderTop,width,height,QColor("#FAFAFA")); + + QWidget::paintEvent(event); +} + + +QSize YACReaderDeletingProgress::sizeHint() const +{ + return QSize(textMessage->sizeHint().width()+120,185); +} diff --git a/custom_widgets/yacreader_deleting_progress.h b/custom_widgets/yacreader_deleting_progress.h new file mode 100644 index 00000000..badf1e6a --- /dev/null +++ b/custom_widgets/yacreader_deleting_progress.h @@ -0,0 +1,26 @@ +#ifndef YACREADER_DELETING_PROGRESS_H +#define YACREADER_DELETING_PROGRESS_H + +#include + +class QLabel; + +class YACReaderDeletingProgress : public QWidget +{ + Q_OBJECT +public: + explicit YACReaderDeletingProgress(QWidget *parent = 0); + QSize sizeHint() const; +signals: + +public slots: + +protected: + void paintEvent(QPaintEvent *); + +private: + QLabel * textMessage; + +}; + +#endif // YACREADER_DELETING_PROGRESS_H diff --git a/custom_widgets/yacreader_field_edit.cpp b/custom_widgets/yacreader_field_edit.cpp new file mode 100644 index 00000000..3169784d --- /dev/null +++ b/custom_widgets/yacreader_field_edit.cpp @@ -0,0 +1,39 @@ +#include "yacreader_field_edit.h" + +#include +#include + +YACReaderFieldEdit::YACReaderFieldEdit(QWidget * parent) + :QLineEdit(parent) +{ + setPlaceholderText(tr("Click to overwrite")); + setModified(false); + restore = new QAction(tr("Restore to default"),this); + this->addAction(restore); + //this->setContextMenuPolicy(Qt::ActionsContextMenu); +} + +void YACReaderFieldEdit::focusInEvent(QFocusEvent* e) +{ + if (e->reason() == Qt::MouseFocusReason) + { + setModified(true); + setPlaceholderText(""); + } + + QLineEdit::focusInEvent(e); +} + +void YACReaderFieldEdit::clear() +{ + setPlaceholderText(tr("Click to overwrite")); + QLineEdit::clear(); + QLineEdit::setModified(false); +} + +void YACReaderFieldEdit::setDisabled(bool disabled) +{ + if(disabled) + setPlaceholderText(""); + QLineEdit::setDisabled(disabled); +} \ No newline at end of file diff --git a/custom_widgets/yacreader_field_edit.h b/custom_widgets/yacreader_field_edit.h new file mode 100644 index 00000000..b7baf0f1 --- /dev/null +++ b/custom_widgets/yacreader_field_edit.h @@ -0,0 +1,23 @@ +#ifndef YACREADER_FIELD_EDIT_H +#define YACREADER_FIELD_EDIT_H + +#include + +class QAction; +class QFocusEvent; + +class YACReaderFieldEdit : public QLineEdit +{ + Q_OBJECT + public: + YACReaderFieldEdit(QWidget * parent = 0); + void clear(); + void setDisabled(bool disabled); + protected: + void focusInEvent(QFocusEvent* e); +private: + QAction * restore; + +}; + +#endif // YACREADER_FIELD_EDIT_H \ No newline at end of file diff --git a/custom_widgets/yacreader_field_plain_text_edit.cpp b/custom_widgets/yacreader_field_plain_text_edit.cpp new file mode 100644 index 00000000..c73cfc03 --- /dev/null +++ b/custom_widgets/yacreader_field_plain_text_edit.cpp @@ -0,0 +1,53 @@ +#include "yacreader_field_plain_text_edit.h" + +#include + +YACReaderFieldPlainTextEdit::YACReaderFieldPlainTextEdit(QWidget * parent) + :QPlainTextEdit(parent) +{ + document()->setModified(false); + setPlainText(tr("Click to overwrite")); + restore = new QAction(tr("Restore to default"),this); + this->addAction(restore); + //this->setContextMenuPolicy(Qt::ActionsContextMenu); +} + +void YACReaderFieldPlainTextEdit::focusInEvent(QFocusEvent* e) +{ + if (e->reason() == Qt::MouseFocusReason || e->reason() == Qt::TabFocusReason) + { + document()->setModified(true); + if(toPlainText()==tr("Click to overwrite")) + setPlainText(""); + } + + QPlainTextEdit::focusInEvent(e); +} + +void YACReaderFieldPlainTextEdit::focusOutEvent(QFocusEvent* e) +{ + /*if (e->reason() == Qt::MouseFocusReason || e->reason() == Qt::TabFocusReason) + { + if(toPlainText().isEmpty()) + { + setPlainText(tr("Click to overwrite")); + document()->setModified(false); + } + } + */ + QPlainTextEdit::focusOutEvent(e); +} + +void YACReaderFieldPlainTextEdit::clear() +{ + QPlainTextEdit::clear(); + document()->setModified(false); + setPlainText(tr("Click to overwrite")); +} + +void YACReaderFieldPlainTextEdit::setDisabled(bool disabled) +{ + if(disabled) + setPlainText(tr("Click to overwrite")); + QPlainTextEdit::setDisabled(disabled); +} diff --git a/custom_widgets/yacreader_field_plain_text_edit.h b/custom_widgets/yacreader_field_plain_text_edit.h new file mode 100644 index 00000000..0d02493c --- /dev/null +++ b/custom_widgets/yacreader_field_plain_text_edit.h @@ -0,0 +1,25 @@ +#ifndef YACREADER_FIELD_PLAIN_TEXT_EDIT_H +#define YACREADER_FIELD_PLAIN_TEXT_EDIT_H + +#include + +class QAction; +class QFocusEvent; + + +class YACReaderFieldPlainTextEdit : public QPlainTextEdit +{ + Q_OBJECT + public: + YACReaderFieldPlainTextEdit(QWidget * parent = 0); + void clear(); + void setDisabled(bool disabled); + protected: + void focusInEvent(QFocusEvent* e); + void focusOutEvent(QFocusEvent* e); +private: + QAction * restore; + +}; + +#endif // YACREADER_FIELD_PLAIN_TEXT_EDIT_H \ No newline at end of file diff --git a/custom_widgets/yacreader_flow.cpp b/custom_widgets/yacreader_flow.cpp new file mode 100644 index 00000000..e40507d3 --- /dev/null +++ b/custom_widgets/yacreader_flow.cpp @@ -0,0 +1,23 @@ +#include "yacreader_flow.h" + +#include + + +YACReaderFlow::YACReaderFlow(QWidget * parent,FlowType flowType) : PictureFlow(parent,flowType) {} + +void YACReaderFlow::mousePressEvent(QMouseEvent* event) +{ + if(event->x() > (width()+slideSize().width())/2) + showNext(); + else + if(event->x() < (width()-slideSize().width())/2) + showPrevious(); + //else (centered cover space) +} + +void YACReaderFlow::mouseDoubleClickEvent(QMouseEvent* event) +{ + if((event->x() > (width()-slideSize().width())/2)&&(event->x() < (width()+slideSize().width())/2)) + emit selected(centerIndex()); +} + diff --git a/custom_widgets/yacreader_flow.h b/custom_widgets/yacreader_flow.h new file mode 100644 index 00000000..7a478967 --- /dev/null +++ b/custom_widgets/yacreader_flow.h @@ -0,0 +1,21 @@ +#ifndef YACREADER_FLOW_H +#define YACREADER_FLOW_H + +#include "pictureflow.h" + +class QMouseEvent; + +class YACReaderFlow : public PictureFlow +{ +Q_OBJECT +public: + YACReaderFlow(QWidget * parent,FlowType flowType = CoverFlowLike); + + void mousePressEvent(QMouseEvent* event); + void mouseDoubleClickEvent(QMouseEvent* event); + +signals: + void selected(unsigned int centerIndex); +}; + +#endif // YACREADER_FLOW_H \ No newline at end of file diff --git a/custom_widgets/yacreader_flow_config_widget.cpp b/custom_widgets/yacreader_flow_config_widget.cpp new file mode 100644 index 00000000..8fd3ba94 --- /dev/null +++ b/custom_widgets/yacreader_flow_config_widget.cpp @@ -0,0 +1,54 @@ +#include "yacreader_flow_config_widget.h" + +#include +#include +#include +#include + +YACReaderFlowConfigWidget::YACReaderFlowConfigWidget(QWidget * parent ) + :QWidget(parent) +{ + QVBoxLayout * layout = new QVBoxLayout(this); + + QGroupBox *groupBox = new QGroupBox(tr("How to show covers:")); + + radio1 = new QRadioButton(tr("CoverFlow look")); + radio2 = new QRadioButton(tr("Stripe look")); + radio3 = new QRadioButton(tr("Overlapped Stripe look")); + + + QVBoxLayout *vbox = new QVBoxLayout; + QHBoxLayout * opt1 = new QHBoxLayout; + opt1->addWidget(radio1); + QLabel * lOpt1 = new QLabel(); + lOpt1->setPixmap(QPixmap(":/images/flow1.png")); + opt1->addStretch(); + opt1->addWidget(lOpt1); + vbox->addLayout(opt1); + + QHBoxLayout * opt2 = new QHBoxLayout; + opt2->addWidget(radio2); + QLabel * lOpt2 = new QLabel(); + lOpt2->setPixmap(QPixmap(":/images/flow2.png")); + opt2->addStretch(); + opt2->addWidget(lOpt2); + vbox->addLayout(opt2); + + QHBoxLayout * opt3 = new QHBoxLayout; + opt3->addWidget(radio3); + QLabel * lOpt3 = new QLabel(); + lOpt3->setPixmap(QPixmap(":/images/flow3.png")); + opt3->addStretch(); + opt3->addWidget(lOpt3); + vbox->addLayout(opt3); + + + //vbox->addStretch(1); + groupBox->setLayout(vbox); + + layout->addWidget(groupBox); + + layout->setContentsMargins(0,0,0,0); + + setLayout(layout); +} \ No newline at end of file diff --git a/custom_widgets/yacreader_flow_config_widget.h b/custom_widgets/yacreader_flow_config_widget.h new file mode 100644 index 00000000..b5dee55d --- /dev/null +++ b/custom_widgets/yacreader_flow_config_widget.h @@ -0,0 +1,19 @@ +#ifndef YACREADER_FLOW_CONFIG_WIDGET_H +#define YACREADER_FLOW_CONFIG_WIDGET_H + +#include + +class QRadioButton; + +class YACReaderFlowConfigWidget : public QWidget +{ + Q_OBJECT +public: + QRadioButton *radio1; + QRadioButton *radio2; + QRadioButton *radio3; + + YACReaderFlowConfigWidget(QWidget * parent = 0); +}; + +#endif // YACREADER_FLOW_CONFIG_WIDGET_H \ No newline at end of file diff --git a/custom_widgets/yacreader_gl_flow_config_widget.cpp b/custom_widgets/yacreader_gl_flow_config_widget.cpp new file mode 100644 index 00000000..35e09a2c --- /dev/null +++ b/custom_widgets/yacreader_gl_flow_config_widget.cpp @@ -0,0 +1,240 @@ +#include "yacreader_gl_flow_config_widget.h" + +#include "yacreader_spin_slider_widget.h" +#include "yacreader_flow_gl.h" //TODO + +#include +#include +#include +#include +#include + + +YACReaderGLFlowConfigWidget::YACReaderGLFlowConfigWidget(QWidget * parent /* = 0 */) + :QWidget(parent) +{ + QVBoxLayout * layout = new QVBoxLayout(this); + + //PRESETS------------------------------------------------------------------ + QGroupBox *groupBox = new QGroupBox(tr("Presets:")); + + radioClassic = new QRadioButton(tr("Classic look")); + //connect(radioClassic,SIGNAL(toggled(bool)),this,SLOT(setClassicConfig())); + + radioStripe = new QRadioButton(tr("Stripe look")); + //connect(radioStripe,SIGNAL(toggled(bool)),this,SLOT(setStripeConfig())); + + radioOver = new QRadioButton(tr("Overlapped Stripe look")); + //connect(radioOver,SIGNAL(toggled(bool)),this,SLOT(setOverlappedStripeConfig())); + + radionModern = new QRadioButton(tr("Modern look")); + //connect(radionModern,SIGNAL(toggled(bool)),this,SLOT(setModernConfig())); + + radioDown = new QRadioButton(tr("Roulette look")); + //connect(radioDown,SIGNAL(toggled(bool)),this,SLOT(setRouletteConfig())); + + QVBoxLayout *vbox = new QVBoxLayout; + QHBoxLayout * opt1 = new QHBoxLayout; + opt1->addWidget(radioClassic); + QLabel * lOpt1 = new QLabel(); + lOpt1->setPixmap(QPixmap(":/images/flow1.png")); + opt1->addStretch(); + opt1->addWidget(lOpt1); + vbox->addLayout(opt1); + + QHBoxLayout * opt2 = new QHBoxLayout; + opt2->addWidget(radioStripe); + QLabel * lOpt2 = new QLabel(); + lOpt2->setPixmap(QPixmap(":/images/flow2.png")); + opt2->addStretch(); + opt2->addWidget(lOpt2); + vbox->addLayout(opt2); + + QHBoxLayout * opt3 = new QHBoxLayout; + opt3->addWidget(radioOver); + QLabel * lOpt3 = new QLabel(); + lOpt3->setPixmap(QPixmap(":/images/flow3.png")); + opt3->addStretch(); + opt3->addWidget(lOpt3); + vbox->addLayout(opt3); + + QHBoxLayout * opt4 = new QHBoxLayout; + opt4->addWidget(radionModern); + QLabel * lOpt4 = new QLabel(); + lOpt4->setPixmap(QPixmap(":/images/flow4.png")); + opt4->addStretch(); + opt4->addWidget(lOpt4); + vbox->addLayout(opt4); + + QHBoxLayout * opt5 = new QHBoxLayout; + opt5->addWidget(radioDown); + QLabel * lOpt5 = new QLabel(); + lOpt5->setPixmap(QPixmap(":/images/flow5.png")); + opt5->addStretch(); + opt5->addWidget(lOpt5); + vbox->addLayout(opt5); + + showAdvancedOptions = new QPushButton(tr("Show advanced settings")); + showAdvancedOptions->setCheckable(true); + connect(showAdvancedOptions,SIGNAL(toggled(bool)),this,SLOT(avancedOptionToogled(bool))); + + vbox->addWidget(showAdvancedOptions,0,Qt::AlignRight); + + groupBox->setLayout(vbox); + + //OPTIONS------------------------------------------------------------------ + optionsGroupBox = new QGroupBox(tr("Custom:")); + + xRotation = new YACReaderSpinSliderWidget(this); + xRotation->setText(tr("View angle")); + xRotation->setRange(0,90); + //connect(xRotation,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(xRotation,SIGNAL(valueChanged(int)),this,SLOT(saveXRotation(int))); + + yPosition = new YACReaderSpinSliderWidget(this); + yPosition->setText(tr("Position")); + yPosition->setRange(-100,100); + //connect(yPosition,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(yPosition,SIGNAL(valueChanged(int)),this,SLOT(saveYPosition(int))); + + coverDistance = new YACReaderSpinSliderWidget(this); + coverDistance->setText(tr("Cover gap")); + coverDistance->setRange(0,150); + //connect(coverDistance,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(coverDistance,SIGNAL(valueChanged(int)),this,SLOT(saveCoverDistance(int))); + + centralDistance = new YACReaderSpinSliderWidget(this); + centralDistance->setText(tr("Central gap")); + centralDistance->setRange(0,150); + //connect(centralDistance,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(centralDistance,SIGNAL(valueChanged(int)),this,SLOT(saveCentralDistance(int))); + + zoomLevel = new YACReaderSpinSliderWidget(this); + zoomLevel->setText(tr("Zoom")); + zoomLevel->setRange(-20,0); + //connect(zoomLevel,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(zoomLevel,SIGNAL(valueChanged(int)),this,SLOT(saveZoomLevel(int))); + + yCoverOffset = new YACReaderSpinSliderWidget(this); + yCoverOffset->setText(tr("Y offset")); + yCoverOffset->setRange(-50,50); + //connect(yCoverOffset,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(yCoverOffset,SIGNAL(valueChanged(int)),this,SLOT(saveYCoverOffset(int))); + + zCoverOffset = new YACReaderSpinSliderWidget(this); + zCoverOffset->setText(tr("Z offset")); + zCoverOffset->setRange(-50,50); + //connect(zCoverOffset,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(zCoverOffset,SIGNAL(valueChanged(int)),this,SLOT(saveZCoverOffset(int))); + + coverRotation = new YACReaderSpinSliderWidget(this); + coverRotation->setText(tr("Cover Angle")); + coverRotation->setRange(0,360); + //connect(coverRotation,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(coverRotation,SIGNAL(valueChanged(int)),this,SLOT(saveCoverRotation(int))); + + fadeOutDist = new YACReaderSpinSliderWidget(this); + fadeOutDist->setText(tr("Visibility")); + fadeOutDist->setRange(0,10); + //connect(fadeOutDist,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(fadeOutDist,SIGNAL(valueChanged(int)),this,SLOT(saveFadeOutDist(int))); + + lightStrength = new YACReaderSpinSliderWidget(this); + lightStrength->setText(tr("Light")); + lightStrength->setRange(0,10); + //connect(lightStrength,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(lightStrength,SIGNAL(valueChanged(int)),this,SLOT(saveLightStrength(int))); + + maxAngle = new YACReaderSpinSliderWidget(this); + maxAngle->setText(tr("Max angle")); + maxAngle->setRange(0,90); + //connect(maxAngle,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + //connect(maxAngle,SIGNAL(valueChanged(int)),this,SLOT(saveMaxAngle(int))); + + QVBoxLayout *optionsLayoutStretch = new QVBoxLayout; + optionsLayoutStretch->setContentsMargins(0,0,0,0); + QGridLayout *optionsLayout = new QGridLayout; + optionsLayout->addWidget(xRotation,0,0); + optionsLayout->addWidget(yPosition,0,1); + optionsLayout->addWidget(coverDistance,1,0); + optionsLayout->addWidget(centralDistance,1,1); + optionsLayout->addWidget(zoomLevel,2,0); + optionsLayout->addWidget(yCoverOffset,2,1); + optionsLayout->addWidget(zCoverOffset,3,0); + optionsLayout->addWidget(coverRotation,3,1); + optionsLayout->addWidget(fadeOutDist,4,0); + optionsLayout->addWidget(lightStrength,4,1); + optionsLayout->addWidget(maxAngle,5,0); + + optionsLayoutStretch->addLayout(optionsLayout); + optionsLayoutStretch->addStretch(); + + optionsGroupBox->setLayout(optionsLayoutStretch); + + QHBoxLayout * groupBoxesLayout = new QHBoxLayout; + groupBoxesLayout->addWidget(groupBox); + groupBoxesLayout->addWidget(optionsGroupBox); + + optionsGroupBox->hide(); + + QHBoxLayout * performanceSliderLayout = new QHBoxLayout; + performanceSliderLayout->addWidget(new QLabel(tr("Low Performance"))); + performanceSliderLayout->addWidget(performanceSlider = new QSlider(Qt::Horizontal)); + performanceSliderLayout->addWidget(new QLabel(tr("High Performance"))); + + performanceSlider->setMinimum(0); + performanceSlider->setMaximum(3); + performanceSlider->setSingleStep(1); + performanceSlider->setPageStep(1); + performanceSlider->setTickInterval(1); + performanceSlider->setTickPosition(QSlider::TicksRight); + + QHBoxLayout * vSyncLayout = new QHBoxLayout; + + vSyncCheck = new QCheckBox(tr("Use VSync (improve the image quality in fullscreen mode, worse performance)")); + vSyncLayout->addStretch(); + vSyncLayout->addWidget(vSyncCheck); + + QVBoxLayout * performanceLayout = new QVBoxLayout; + performanceLayout->addLayout(performanceSliderLayout); + performanceLayout->addLayout(vSyncLayout); + + QGroupBox *performanceGroupBox = new QGroupBox(tr("Performance:")); + + //connect(performanceSlider, SIGNAL(valueChanged(int)),this,SLOT(savePerformance(int))); + //connect(performanceSlider, SIGNAL(valueChanged(int)),this,SLOT(optionsChanged())); + + performanceGroupBox->setLayout(performanceLayout); + + layout->addLayout(groupBoxesLayout); + layout->addWidget(performanceGroupBox); + + layout->setContentsMargins(0,0,0,0); + + setLayout(layout); + + +} + +void YACReaderGLFlowConfigWidget::avancedOptionToogled(bool show) +{ + if(show) + optionsGroupBox->show(); + else + optionsGroupBox->hide(); +} + +void YACReaderGLFlowConfigWidget::setValues(Preset preset) +{ + xRotation->setValue(preset.cfRX); + yPosition->setValue(preset.cfY*100); + coverDistance->setValue(preset.xDistance*100); + centralDistance->setValue(preset.centerDistance*100); + zoomLevel->setValue(preset.cfZ); + yCoverOffset->setValue(preset.yDistance*100); + zCoverOffset->setValue(preset.zDistance*100); + coverRotation->setValue(preset.rotation*-1); + fadeOutDist->setValue(preset.animationFadeOutDist); + lightStrength->setValue(preset.viewRotateLightStrenght); + maxAngle->setValue(preset.viewAngle); +} diff --git a/custom_widgets/yacreader_gl_flow_config_widget.h b/custom_widgets/yacreader_gl_flow_config_widget.h new file mode 100644 index 00000000..83ded28d --- /dev/null +++ b/custom_widgets/yacreader_gl_flow_config_widget.h @@ -0,0 +1,51 @@ +#ifndef YACREADER_GL_FLOW_CONFIG_WIDGET_H +#define YACREADER_GL_FLOW_CONFIG_WIDGET_H + +#include "yacreader_flow_gl.h" //TODO +#include + +class QRadioButton; +class YACReaderSpinSliderWidget; +class QSlider; +class QCheckBox; +class QPushButton; +class QGroupBox; + +class YACReaderGLFlowConfigWidget : public QWidget +{ + Q_OBJECT +public: + YACReaderGLFlowConfigWidget(QWidget * parent = 0); + + //GL......................... + QRadioButton *radioClassic; + QRadioButton *radioStripe; + QRadioButton *radioOver; + QRadioButton *radionModern; + QRadioButton *radioDown; + + YACReaderSpinSliderWidget * xRotation; + YACReaderSpinSliderWidget * yPosition; + YACReaderSpinSliderWidget * coverDistance; + YACReaderSpinSliderWidget * centralDistance; + YACReaderSpinSliderWidget * zoomLevel; + YACReaderSpinSliderWidget * yCoverOffset; + YACReaderSpinSliderWidget * zCoverOffset; + YACReaderSpinSliderWidget * coverRotation; + YACReaderSpinSliderWidget * fadeOutDist; + YACReaderSpinSliderWidget * lightStrength; + YACReaderSpinSliderWidget * maxAngle; + + QSlider * performanceSlider; + QCheckBox * vSyncCheck; + + QPushButton * showAdvancedOptions; + QGroupBox *optionsGroupBox; + +public slots: + void setValues(Preset preset); + void avancedOptionToogled(bool show); +}; + + +#endif // YACREADER_GL_FLOW_CONFIG_WIDGET_H \ No newline at end of file diff --git a/custom_widgets/yacreader_library_item_widget.cpp b/custom_widgets/yacreader_library_item_widget.cpp new file mode 100644 index 00000000..b5f6b259 --- /dev/null +++ b/custom_widgets/yacreader_library_item_widget.cpp @@ -0,0 +1,156 @@ +#include "yacreader_library_item_widget.h" + +#include +#include +#include +#include + +YACReaderLibraryItemWidget::YACReaderLibraryItemWidget(QString n/*ame*/, QString p/*ath*/, QWidget *parent) : + QWidget(parent),name(n),path(p),isSelected(false) +{ + QHBoxLayout * mainLayout = new QHBoxLayout; + mainLayout->setMargin(0); + mainLayout->setSpacing(0); + + //installEventFilter(this); + + QPixmap iconPixmap(":/images/sidebar/libraryIcon.png"); + icon = new QLabel(this); + icon->setPixmap(iconPixmap); + + nameLabel = new QLabel(name,this); + + options = new QToolButton(this); + options->setIcon(QIcon(":/images/sidebar/libraryOptions.png")); + options->setHidden(true); + options->setFixedWidth(18); + options->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum); + options->setStyleSheet("QToolButton {border:none;}"); + connect(options,SIGNAL(clicked()),this,SIGNAL(showOptions())); + /*up = new QToolButton(this); + up->setIcon(QIcon(":/images/libraryUp.png")); + up->setHidden(true); + up->setFixedWidth(18); + up->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum); + + down = new QToolButton(this); + down->setIcon(QIcon(":/images/libraryDown.png")); + down->setHidden(true); + down->setFixedWidth(18); + down->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum);*/ + + + mainLayout->addWidget(icon); + mainLayout->addWidget(nameLabel,Qt::AlignLeft); + mainLayout->addStretch(); + mainLayout->addWidget(options); + /*mainLayout->addWidget(up); + mainLayout->addWidget(down);*/ + + setLayout(mainLayout); +#ifndef Q_OS_MAC + QString styleSheet = "background-color:transparent; color:#DDDFDF;"; + setStyleSheet(styleSheet); +#endif + + + QString iconStyleSheet = "QLabel {padding:0 0 0 24px; margin:0px}"; + icon->setStyleSheet(iconStyleSheet); + + QString nameLabelStyleSheet = "QLabel {padding:0 0 0 3px; margin:0px;}"; + nameLabel->setStyleSheet(nameLabelStyleSheet); + + setMinimumHeight(20); +} + +void YACReaderLibraryItemWidget::showUpDownButtons(bool show) +{ + up->setHidden(!show); + down->setHidden(!show); +} + +/* +bool YACReaderLibraryItemWidget::eventFilter(QObject *object, QEvent *event){ + if(!isSelected && object==this && (event->type()==QEvent::Enter)) + { + QString styleSheet = "background-color:#5E5E5E; border-top: 1px solid #5E5E5E;border-bottom: 1px solid #5E5E5E; "; + setStyleSheet(styleSheet); + + up->setHidden(false); + down->setHidden(false); + options->setHidden(false); + + return true; + } + if(!isSelected && object==this && (event->type()==QEvent::Leave)) + { + QString styleSheet = "background-color:#454545; border-top: 1px solid #454545;border-bottom: 1px solid #454545;"; + setStyleSheet(styleSheet); + + up->setHidden(true); + down->setHidden(true); + options->setHidden(true); + + return true; + } + + if(object==this && (event->type()==QEvent::MouseButtonRelease)) + { + QString styleSheet = "background-color:#2E2E2E; border-top: 1px solid #1F1F1F;border-bottom: 1px solid #636363; padding-top:1px; padding-bottom:1px;"; + setStyleSheet(styleSheet); + emit(selected(name,path)); + isSelected = true; + return true; + } + + return false; +}*/ + + + +void YACReaderLibraryItemWidget::deselect() +{ + +#ifdef Q_OS_MAC + QString styleSheet = "background-color:transparent;"; + setStyleSheet(styleSheet); +#else + QString styleSheet = "background-color:transparent; color:#DDDFDF;"; + setStyleSheet(styleSheet); +#endif + + QPixmap iconPixmap(":/images/sidebar/libraryIcon.png"); + icon->setPixmap(iconPixmap); + + /*up->setHidden(true); + down->setHidden(true);*/ + options->setHidden(true); + + isSelected = false; + + +} + +void YACReaderLibraryItemWidget::select() +{ +#ifdef Q_OS_MAC + //QString styleSheet ="color: white; background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6BAFE4, stop: 1 #3984D2); border-top: 2px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #5EA3DF, stop: 1 #73B8EA); border-left:none;border-right:none;border-bottom:1px solid #3577C2;"; + QString styleSheet = "color: white; background-color:#91c4f4; border-bottom:1px solid #91c4f4;"; +#else + QString styleSheet = "color: white; background-color:#2E2E2E; font-weight:bold;"; +#endif + setStyleSheet(styleSheet); + + options->setHidden(false); + + QPixmap iconPixmap(":/images/sidebar/libraryIconSelected.png"); + icon->setPixmap(iconPixmap); + + isSelected = true; +} + +void YACReaderLibraryItemWidget::setName(const QString & name) +{ + this->name = name; + nameLabel->setText(name); +} diff --git a/custom_widgets/yacreader_library_item_widget.h b/custom_widgets/yacreader_library_item_widget.h new file mode 100644 index 00000000..74d90224 --- /dev/null +++ b/custom_widgets/yacreader_library_item_widget.h @@ -0,0 +1,45 @@ +#ifndef YACREADER_LIBRARY_ITEM_WIDGET_H +#define YACREADER_LIBRARY_ITEM_WIDGET_H + +#include + +class QLabel; +class QToolButton; +class QMouseEvent; +class QEvent; + +class YACReaderLibraryItemWidget : public QWidget +{ + Q_OBJECT + +public: + YACReaderLibraryItemWidget(QString name, QString path, QWidget *parent = 0); + QString name; + QString path; + +signals: + void selected(QString,QString); + void showOptions(); + +public slots: + void showUpDownButtons(bool show); + + //bool eventFilter(QObject *object, QEvent *event); + void select(); + void deselect(); + void setName(const QString & name); + +private: + + QLabel * icon; + QLabel * nameLabel; + + QToolButton * options; + QToolButton * up; + QToolButton * down; + + bool isSelected; + +}; + +#endif // YACREADER_LIBRARY_ITEM_WIDGET_H diff --git a/custom_widgets/yacreader_library_list_widget.cpp b/custom_widgets/yacreader_library_list_widget.cpp new file mode 100644 index 00000000..6e5cc676 --- /dev/null +++ b/custom_widgets/yacreader_library_list_widget.cpp @@ -0,0 +1,128 @@ +#include "yacreader_library_list_widget.h" + +#include "yacreader_library_item_widget.h" +#include +#include +#include +#include "qnaturalsorting.h" + +YACReaderLibraryListWidget::YACReaderLibraryListWidget(QWidget *parent) : + QWidget(parent),currentLibraryIndex(-1) +{ + QVBoxLayout * mainLayout = new QVBoxLayout; + mainLayout->setSpacing(0); + mainLayout->setMargin(0); + + this->setLayout(mainLayout); +} + +void YACReaderLibraryListWidget::addItem(QString name, QString path) +{ + QVBoxLayout * mainLayout = dynamic_cast(layout()); + + YACReaderLibraryItemWidget * library = new YACReaderLibraryItemWidget(name,path,this); + connect(library,SIGNAL(showOptions()),this,SLOT(showContextMenu())); + QList::iterator itr; + int i = 0; + for(itr = librariesList.begin(); itr!=librariesList.end() && !naturalSortLessThanCI(name,(*itr)->name);itr++) + i++; + + librariesList.insert(itr,library); + + //connect(library,SIGNAL(selected(QString,QString)),this,SIGNAL(librarySelected(QString,QString))); + //connect(library,SIGNAL(selected(QString,QString)),this,SLOT(updateLibraries(QString,QString))); + + mainLayout->insertWidget(i,library); +} + +QString YACReaderLibraryListWidget::currentText() +{ + return librariesList.at(currentLibraryIndex)->name; +} +int YACReaderLibraryListWidget::findText(QString text) +{ + for(int i=0;iname == text) + return i; + } + return -1; +} +void YACReaderLibraryListWidget::setCurrentIndex(int index) +{ + if(index>=0 && index < librariesList.count()) + { + librariesList.at(index)->select(); + currentLibraryIndex = index; + deselectAllBut(index); + emit currentIndexChanged(librariesList.at(currentLibraryIndex)->name); + } +} + +int YACReaderLibraryListWidget::currentIndex() +{ + return currentLibraryIndex; +} +void YACReaderLibraryListWidget::removeItem(int index) +{ + YACReaderLibraryItemWidget * itemWidget = librariesList.at(index); + this->layout()->removeWidget(itemWidget); + librariesList.removeAt(index); + if(librariesList.count()>0) + { + setCurrentIndex(0); + } + delete itemWidget; +} + +void YACReaderLibraryListWidget::mousePressEvent ( QMouseEvent * event ) +{ + if(librariesList.count()>0) + { + int h = librariesList.at(0)->height(); + int item = event->pos().y() / h; + if(item!=currentLibraryIndex) + { + setCurrentIndex(item); + } + } + +} + +void YACReaderLibraryListWidget::deselectAllBut(int index) +{ + for(int i=0;ideselect(); + } +} + +void YACReaderLibraryListWidget::showContextMenu() +{ + YACReaderLibraryItemWidget * itemWidget = librariesList.at(currentLibraryIndex); + QMenu::exec(actions(),itemWidget->mapToGlobal(QPoint(itemWidget->width()-8,itemWidget->height()/2))); +} + +void YACReaderLibraryListWidget::renameCurrentLibrary(QString newName) +{ + YACReaderLibraryItemWidget * itemWidget = librariesList.at(currentLibraryIndex); + + + this->layout()->removeWidget(itemWidget); + librariesList.removeOne(itemWidget); + + itemWidget->setName(newName); + + QList::iterator itr; + int i = 0; + for(itr = librariesList.begin(); itr!=librariesList.end() && !naturalSortLessThanCI(newName,(*itr)->name);itr++) + i++; + + librariesList.insert(itr,itemWidget); + + QVBoxLayout * mainLayout = dynamic_cast(layout()); + mainLayout->insertWidget(i,itemWidget); + + currentLibraryIndex = i; +} diff --git a/custom_widgets/yacreader_library_list_widget.h b/custom_widgets/yacreader_library_list_widget.h new file mode 100644 index 00000000..189dee1d --- /dev/null +++ b/custom_widgets/yacreader_library_list_widget.h @@ -0,0 +1,37 @@ +#ifndef YACREADER_LIBRARY_LIST_WIDGET_H +#define YACREADER_LIBRARY_LIST_WIDGET_H + +#include + +class YACReaderLibraryItemWidget; +class QMouseEvent; + +class YACReaderLibraryListWidget : public QWidget +{ + Q_OBJECT +public: + explicit YACReaderLibraryListWidget(QWidget *parent = 0); + +signals: + void currentIndexChanged(QString text); + +public slots: + QString currentText(); + int findText(QString text); + void setCurrentIndex(int index); + void addItem(QString name, QString path); + int currentIndex(); + void removeItem(int index); + void showContextMenu(); + void renameCurrentLibrary(QString newName); +protected: + void mousePressEvent ( QMouseEvent * event ); +private: + int currentLibraryIndex; + QList < YACReaderLibraryItemWidget* > librariesList; + void deselectAllBut(int index); + +}; + +#endif // YACREADER_LIBRARY_LIST_WIDGET_H + diff --git a/custom_widgets/yacreader_macosx_toolbar.h b/custom_widgets/yacreader_macosx_toolbar.h new file mode 100644 index 00000000..a37b144b --- /dev/null +++ b/custom_widgets/yacreader_macosx_toolbar.h @@ -0,0 +1,87 @@ +#ifndef YACREADER_MACOSX_TOOLBAR_H +#define YACREADER_MACOSX_TOOLBAR_H + +#include +#include + +#include "yacreader_global.h" + +//Wrapper for NSTextField +class YACReaderMacOSXSearchLineEdit : public QObject +{ + Q_OBJECT +public: + YACReaderMacOSXSearchLineEdit(); + void * getNSTextField(); + +public slots: + QString text(); + void clear(); + void clearText(); //no signal emited + void setDisabled(bool disabled); + void setEnabled(bool enabled); + +private: + void * nstextfield; + + +signals: + //convenience signal for YACReaderLibrary search edit + void filterChanged(YACReader::SearchModifiers, QString); +}; + +class MacToolBarItemWrapper : public QObject +{ + Q_OBJECT +public: + MacToolBarItemWrapper(QAction * action, QMacToolBarItem * toolbaritem); + +public slots: + void actionToggled(bool toogled); + +private: + QAction * action; + QMacToolBarItem * toolbaritem; + + void updateIcon(bool checked); +}; + + +class YACReaderMacOSXToolbar : public QMacToolBar +{ + Q_OBJECT +public: + explicit YACReaderMacOSXToolbar(QObject *parent = 0); + void addAction(QAction * action); + void addDropDownItem(const QList & actions, const QAction * defaultAction = 0); + void addSpace(int size); //size in points + void addSeparator(); + void addStretch(); + void addWidget(QWidget * widget); + void show(); + void hide(); + QMap actions; + + //hacks everywhere + //convenience method for YACReaderLibrary search edit + YACReaderMacOSXSearchLineEdit *addSearchEdit(); + //convenience method for showing the fit to width slider in MacOSX + QAction * addFitToWidthSlider(QAction * attachToAction); + + + //convenience method for switching the icon of the view selector + void updateViewSelectorIcon(const QIcon & icon); + +signals: + +public slots: + +protected: + NSToolbar * nativeToolBar; + void *delegate; + bool yosemite; + QMacToolBarItem * viewSelector; + +}; + +#endif // YACREADER_MACOSX_TOOLBAR_H diff --git a/custom_widgets/yacreader_macosx_toolbar.mm b/custom_widgets/yacreader_macosx_toolbar.mm new file mode 100644 index 00000000..1570e9b8 --- /dev/null +++ b/custom_widgets/yacreader_macosx_toolbar.mm @@ -0,0 +1,395 @@ +#include "yacreader_macosx_toolbar.h" + +#include +#include +#include +#include +#include + +#import +#import +#import + +#import "shortcuts_manager.h" + +//---------------------------- +//A custom items separator for NSToolbar +@interface CustomSeparator : NSView + +@end + + +@implementation CustomSeparator + +- (void) drawRect:(NSRect)rect { + [[NSColor colorWithDeviceRed:0.5 green:0.5 blue:0.5 alpha:1] setFill]; + NSRectFill(rect); + [super drawRect:rect]; +} + +@end + +//---------------------------- +//Toolbar delegate, needed for allow disabled/enabled items +@interface MyToolbarDelegate : NSObject +{ +@public + YACReaderMacOSXToolbar * mytoolbar; +} + +- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted; +- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar; +- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar; +//- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar; +- (IBAction)itemClicked:(id)sender; +- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem; +@end + + +@implementation MyToolbarDelegate + +- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar +{ + Q_UNUSED(toolbar); + + NSMutableArray *array = [[NSMutableArray alloc] init]; + + QList items = mytoolbar->items(); + foreach (const QMacToolBarItem * item, items) { + [array addObject : item->nativeToolBarItem().itemIdentifier]; + } + return array; +} + +- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar +{ + Q_UNUSED(toolbar); + + NSMutableArray *array = [[NSMutableArray alloc] init]; + + QList items = mytoolbar->items(); + foreach (const QMacToolBarItem * item, items) { + [array addObject : item->nativeToolBarItem().itemIdentifier]; + } + return array; +} + + +/* +- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar +{ + Q_UNUSED(toolbar); + + NSMutableArray *array = [[NSMutableArray alloc] init]; + + QList items = mytoolbar->items(); + foreach (const QMacToolBarItem * item, items) { + [array addObject : item->nativeToolBarItem().itemIdentifier]; + } + return array; + //NSMutableArray *array = toolbarPrivate->getItemIdentifiers(toolbarPrivate->items, true); + //[array addObjectsFromArray:toolbarPrivate->getItemIdentifiers(toolbarPrivate->allowedItems, true)]; + //return array; +}*/ + +- (IBAction)itemClicked:(id)sender +{ + if([sender respondsToSelector:@selector(itemIdentifier)]) + { + NSToolbarItem *item = reinterpret_cast(sender); + + QString identifier = QString::fromNSString([item itemIdentifier]); + QMacToolBarItem *toolButton = reinterpret_cast(identifier.toULongLong()); + Q_EMIT toolButton->activated(); + } +} + +- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdentifier willBeInsertedIntoToolbar:(BOOL) willBeInserted +{ + Q_UNUSED(toolbar); + Q_UNUSED(willBeInserted); + QList items = mytoolbar->items(); + + foreach (const QMacToolBarItem * item, items) { + NSToolbarItem *toolbarItem = item->nativeToolBarItem(); + if([toolbarItem.itemIdentifier isEqual:itemIdentifier]) + { + + [toolbarItem setTarget:self]; + [toolbarItem setAction:@selector(itemClicked:)]; + + return toolbarItem; + } + } + return nil; +} + +- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem +{ + QString identifier = QString::fromNSString(theItem.itemIdentifier); + + if(mytoolbar->actions.contains(identifier)) + { + return mytoolbar->actions.value(identifier)->isEnabled(); + } + else return NO; +} +@end + +//---------------------------- +//detect changes in native text field +//TODO implement validation and auto completion +@interface MyTextFieldDelegate : NSObject +{ +@public + YACReaderMacOSXSearchLineEdit * mylineedit; +} +@end + +@implementation MyTextFieldDelegate + +- (void)controlTextDidChange:(NSNotification *)notification { + NSTextField *textField = [notification object]; + NSLog(@"%@",[textField stringValue]); + Q_EMIT mylineedit->filterChanged(YACReader::NoModifiers, QString::fromNSString([textField stringValue])); +} + +@end +//---------------------------- + +YACReaderMacOSXToolbar::YACReaderMacOSXToolbar(QObject *parent) + :viewSelector(0) +{ + //setup native toolbar + nativeToolBar= nativeToolbar(); + [nativeToolBar setDisplayMode:NSToolbarDisplayModeIconOnly]; + [nativeToolBar setAllowsUserCustomization:NO]; + + delegate = [[MyToolbarDelegate alloc] init]; + ((MyToolbarDelegate *)delegate)->mytoolbar = this; + [nativeToolBar setDelegate:(MyToolbarDelegate *)delegate]; + +#ifdef YACREADER_LIBRARY + NSWindow *nswindow = (NSWindow*) qApp->platformNativeInterface()->nativeResourceForWindow("nswindow", ((QMainWindow*)parent)->windowHandle()); + if([nswindow respondsToSelector:@selector(setTitleVisibility:)]) + { + yosemite = true; + //TODO yosemite new constants are not found in compilation time + [nswindow setTitleVisibility:NSWindowTitleHidden]; + //TODO NSFullSizeContentViewWindowMask produces an offset in the windows' content + //nswindow.styleMask |= 1 << 15; // NSFullSizeContentViewWindowMask; + [nativeToolBar setSizeMode:NSToolbarSizeModeSmall]; //TODO figure out how to load specific images in Yosemite + }else + { + [nativeToolBar setSizeMode:NSToolbarSizeModeSmall]; + yosemite = false; + } +#else + yosemite = false; + [nativeToolBar setAutosavesConfiguration:YES]; //TODO this doesn't work + [nativeToolBar setSizeMode:NSToolbarSizeModeSmall]; +#endif +} + +void YACReaderMacOSXToolbar::addAction(QAction *action) +{ + QMacToolBarItem *toolBarItem = addItem(action->icon(),action->text()); + if(action->data().toString() == TOGGLE_COMICS_VIEW_ACTION_YL) + viewSelector = toolBarItem; + connect(toolBarItem,SIGNAL(activated()),action, SIGNAL(triggered())); + + NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem(); + actions.insert(QString::fromNSString(nativeItem.itemIdentifier),action); + + MacToolBarItemWrapper * wrapper = new MacToolBarItemWrapper(action,toolBarItem); + //wrapper->actionToogled(true); +} + +void YACReaderMacOSXToolbar::addDropDownItem(const QList &actions, const QAction *defaultAction) +{ + //TODO +} + +void YACReaderMacOSXToolbar::addSpace(int size) +{ + QMacToolBarItem *toolBarItem = addItem(QIcon(),""); + NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem(); + + static const NSRect frameRect = { { 0.0, 0.0 }, { CGFloat(size), 16.0 } }; + NSView *view = [[NSView alloc] initWithFrame:frameRect]; + + [nativeItem setView:view]; +} + +//reimplemented for convenience +void YACReaderMacOSXToolbar::addSeparator() +{ + //QMacToolBar::addSeparator(); + + QMacToolBarItem *toolBarItem = addItem(QIcon(),""); + NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem(); + + static const NSRect frameRect = { { 0.0, 0.0 }, { 1, 16.0 } }; + CustomSeparator *view = [[CustomSeparator alloc] initWithFrame:frameRect]; + + [nativeItem setView:view]; +} + +void YACReaderMacOSXToolbar::addStretch() +{ + QMacToolBarItem *toolBarItem = addItem(QIcon(),""); + toolBarItem->setStandardItem(QMacToolBarItem::FlexibleSpace); +} + +void YACReaderMacOSXToolbar::addWidget(QWidget *widget) +{ + //TODO fix it + /* QMacNativeWidget *nativeWidget = new QMacNativeWidget(); + QVBoxLayout *layout = new QVBoxLayout(); + layout->addWidget(widget); + nativeWidget->setLayout(layout); + + + NSView *nativeWidgetView = reinterpret_cast(nativeWidget->winId()); + QMacToolBarItem *toolBarItem = addItem(QIcon(),""); + NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem(); + [nativeItem setView:nativeWidgetView];*/ +} + +void YACReaderMacOSXToolbar::show() +{ + [nativeToolBar setVisible:YES]; +} + +void YACReaderMacOSXToolbar::hide() +{ + [nativeToolBar setVisible:NO]; +} + +YACReaderMacOSXSearchLineEdit * YACReaderMacOSXToolbar::addSearchEdit() +{ + QMacToolBarItem *toolBarItem = addItem(QIcon(),""); + NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem(); + + YACReaderMacOSXSearchLineEdit * searchEdit = new YACReaderMacOSXSearchLineEdit(); + + + if(yosemite) + [nativeItem setView:(NSTextField *)searchEdit->getNSTextField()]; + else + { + static const NSRect searchEditFrameRect = { { 0.0, 0.0 }, { 165, 26.0 } }; + NSView * view = [[NSView alloc] initWithFrame:searchEditFrameRect]; + [view addSubview:((NSTextField *)searchEdit->getNSTextField())]; + [nativeItem setView:view]; + } + + return searchEdit; +} + +QAction *YACReaderMacOSXToolbar::addFitToWidthSlider(QAction *attachToAction) +{ + QMacToolBarItem *toolBarItem = addItem(QIcon(":/images/viewer_toolbar/toWidthSlider.png"),"fit to width slider"); + + NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem(); + actions.insert(QString::fromNSString(nativeItem.itemIdentifier),attachToAction); + + QAction * action = new QAction("",attachToAction->parent()); + + connect(toolBarItem,SIGNAL(activated()), action, SIGNAL(triggered())); + + return action; +} + +void YACReaderMacOSXToolbar::updateViewSelectorIcon(const QIcon &icon) +{ + if(viewSelector) + viewSelector->setIcon(icon); +} + + +YACReaderMacOSXSearchLineEdit::YACReaderMacOSXSearchLineEdit() + :QObject() +{ + NSRect searchEditFrameRect = { { 0.0, -3.0 }, { 165, 32.0 } }; + //NSTextField * searchEdit = [[NSTextField alloc] initWithFrame:searchEditFrameRect]; + + NSTextField * searchEdit = [[NSSearchField alloc] initWithFrame:searchEditFrameRect]; + //[searchEdit setBezelStyle:NSTextFieldRoundedBezel]; + + [[searchEdit cell] setPlaceholderString:@"type to search"]; + + MyTextFieldDelegate * delegate = [[MyTextFieldDelegate alloc] init]; + delegate->mylineedit = this; + [searchEdit setDelegate:delegate]; + + nstextfield = searchEdit; +} + +void *YACReaderMacOSXSearchLineEdit::getNSTextField() +{ + return nstextfield; +} + +QString YACReaderMacOSXSearchLineEdit::text() +{ + return QString::fromNSString([((NSTextField *)nstextfield) stringValue]); +} + +void YACReaderMacOSXSearchLineEdit::clear() +{ + [((NSTextField *)nstextfield) setStringValue:@""]; + emit filterChanged(YACReader::NoModifiers, ""); +} + +void YACReaderMacOSXSearchLineEdit::clearText() +{ + //TODO be sure that this will not generate any event.... + [((NSTextField *)nstextfield) setStringValue:@""]; +} + +void YACReaderMacOSXSearchLineEdit::setDisabled(bool disabled) +{ + [((NSTextField *)nstextfield) setEnabled:!disabled]; +} + +void YACReaderMacOSXSearchLineEdit::setEnabled(bool enabled) +{ + [((NSTextField *)nstextfield) setEnabled:enabled]; +} + + +MacToolBarItemWrapper::MacToolBarItemWrapper(QAction *action, QMacToolBarItem *toolbaritem) + :action(action),toolbaritem(toolbaritem) +{ + if(action->isCheckable()) + { + connect(action,SIGNAL(toggled(bool)),this,SLOT(actionToggled(bool))); + connect(toolbaritem,SIGNAL(activated()), action, SLOT(toggle())); + updateIcon(action->isChecked()); + } +} + +void MacToolBarItemWrapper::actionToggled(bool toogled) +{ + updateIcon(toogled); +} + +void MacToolBarItemWrapper::updateIcon(bool enabled) +{ + if(enabled) + { + QIcon icon = action->icon(); + QPixmap tempPixmap = icon.pixmap(QSize(24,24)); + QPainter painter; + painter.begin(&tempPixmap); + painter.fillRect(QRect(3,21,18,1),QColor("#3F3F3F")); + painter.fillRect(QRect(3,22,18,1),QColor("#6E6E6E")); + painter.fillRect(QRect(3,23,18,1),QColor("#EEEEEE")); + painter.end(); + + toolbaritem->setIcon(QIcon(tempPixmap)); + } + else + toolbaritem->setIcon(action->icon()); +} diff --git a/custom_widgets/yacreader_options_dialog.cpp b/custom_widgets/yacreader_options_dialog.cpp new file mode 100644 index 00000000..db4d1f34 --- /dev/null +++ b/custom_widgets/yacreader_options_dialog.cpp @@ -0,0 +1,401 @@ +#include "yacreader_options_dialog.h" + +#include "yacreader_flow_config_widget.h" +#ifndef NO_OPENGL +#include "yacreader_gl_flow_config_widget.h" +#else +#include "pictureflow.h" +#endif +#include "yacreader_spin_slider_widget.h" +#include "yacreader_global.h" + +#include +#include +#include +#include +#include +#include +#include + +YACReaderOptionsDialog::YACReaderOptionsDialog(QWidget * parent) + :QDialog(parent) +{ + + sw = new YACReaderFlowConfigWidget(this); +#ifndef NO_OPENGL + gl = new YACReaderGLFlowConfigWidget(this); +#endif + accept = new QPushButton(tr("Save")); + cancel = new QPushButton(tr("Cancel")); + + cancel->setDefault(true); + + + QVBoxLayout * shortcutsLayout = new QVBoxLayout(); + QPushButton * shortcutsButton = new QPushButton(tr("Edit shortcuts")); + shortcutsLayout->addWidget(shortcutsButton); + + shortcutsBox = new QGroupBox(tr("Shortcuts")); + shortcutsBox->setLayout(shortcutsLayout); + + connect(shortcutsButton,SIGNAL(clicked()),this,SIGNAL(editShortcuts())); + + connect(accept,SIGNAL(clicked()),this,SLOT(saveOptions())); + connect(cancel,SIGNAL(clicked()),this,SLOT(restoreOptions())); //TODO fix this + connect(cancel,SIGNAL(clicked()),this,SLOT(close())); +#ifndef NO_OPENGL + useGL = new QCheckBox(tr("Use hardware acceleration (restart needed)")); + connect(useGL,SIGNAL(stateChanged(int)),this,SLOT(saveUseGL(int))); +#endif +#ifdef FORCE_ANGLE + useGL->setHidden(true); +#endif + //sw CONNECTIONS + connect(sw->radio1,SIGNAL(toggled(bool)),this,SLOT(setClassicConfigSW())); + connect(sw->radio2,SIGNAL(toggled(bool)),this,SLOT(setStripeConfigSW())); + connect(sw->radio3,SIGNAL(toggled(bool)),this,SLOT(setOverlappedStripeConfigSW())); +#ifndef NO_OPENGL + //gl CONNECTIONS + connect(gl->radioClassic,SIGNAL(toggled(bool)),this,SLOT(setClassicConfig())); + connect(gl->radioStripe,SIGNAL(toggled(bool)),this,SLOT(setStripeConfig())); + connect(gl->radioOver,SIGNAL(toggled(bool)),this,SLOT(setOverlappedStripeConfig())); + connect(gl->radionModern,SIGNAL(toggled(bool)),this,SLOT(setModernConfig())); + connect(gl->radioDown,SIGNAL(toggled(bool)),this,SLOT(setRouletteConfig())); + + connect(gl->radioClassic,SIGNAL(toggled(bool)),this,SIGNAL(optionsChanged())); + connect(gl->radioStripe,SIGNAL(toggled(bool)),this,SIGNAL(optionsChanged())); + connect(gl->radioOver,SIGNAL(toggled(bool)),this,SIGNAL(optionsChanged())); + connect(gl->radionModern,SIGNAL(toggled(bool)),this,SIGNAL(optionsChanged())); + connect(gl->radioDown,SIGNAL(toggled(bool)),this,SIGNAL(optionsChanged())); + + connect(gl->xRotation,SIGNAL(valueChanged(int)),this,SLOT(saveXRotation(int))); + connect(gl->xRotation,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->yPosition,SIGNAL(valueChanged(int)),this,SLOT(saveYPosition(int))); + connect(gl->yPosition,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->coverDistance,SIGNAL(valueChanged(int)),this,SLOT(saveCoverDistance(int))); + connect(gl->coverDistance,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->centralDistance,SIGNAL(valueChanged(int)),this,SLOT(saveCentralDistance(int))); + connect(gl->centralDistance,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->zoomLevel,SIGNAL(valueChanged(int)),this,SLOT(saveZoomLevel(int))); + connect(gl->zoomLevel,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->yCoverOffset,SIGNAL(valueChanged(int)),this,SLOT(saveYCoverOffset(int))); + connect(gl->yCoverOffset,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->zCoverOffset,SIGNAL(valueChanged(int)),this,SLOT(saveZCoverOffset(int))); + connect(gl->zCoverOffset,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->coverRotation,SIGNAL(valueChanged(int)),this,SLOT(saveCoverRotation(int))); + connect(gl->coverRotation,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->fadeOutDist,SIGNAL(valueChanged(int)),this,SLOT(saveFadeOutDist(int))); + connect(gl->fadeOutDist,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->lightStrength,SIGNAL(valueChanged(int)),this,SLOT(saveLightStrength(int))); + connect(gl->lightStrength,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->maxAngle,SIGNAL(valueChanged(int)),this,SLOT(saveMaxAngle(int))); + connect(gl->maxAngle,SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->performanceSlider, SIGNAL(valueChanged(int)),this,SLOT(savePerformance(int))); + connect(gl->performanceSlider, SIGNAL(valueChanged(int)),this,SIGNAL(optionsChanged())); + + connect(gl->vSyncCheck,SIGNAL(stateChanged(int)),this,SLOT(saveUseVSync(int))); +#endif +} + +#ifndef NO_OPENGL +void YACReaderOptionsDialog::savePerformance(int value) +{ + settings->setValue(PERFORMANCE,value); +} + +void YACReaderOptionsDialog::saveUseVSync(int b) +{ + settings->setValue(V_SYNC,b); +} + +void YACReaderOptionsDialog::saveFlowParameters() +{ + settings->setValue(X_ROTATION,gl->xRotation->getValue()); + settings->setValue(Y_POSITION,gl->yPosition->getValue()); + settings->setValue(COVER_DISTANCE,gl->coverDistance->getValue()); + settings->setValue(CENTRAL_DISTANCE,gl->centralDistance->getValue()); + settings->setValue(ZOOM_LEVEL,gl->zoomLevel->getValue()); + settings->setValue(Y_COVER_OFFSET,gl->yCoverOffset->getValue()); + settings->setValue(Z_COVER_OFFSET,gl->zCoverOffset->getValue()); + settings->setValue(COVER_ROTATION,gl->coverRotation->getValue()); + settings->setValue(FADE_OUT_DIST,gl->fadeOutDist->getValue()); + settings->setValue(LIGHT_STRENGTH,gl->lightStrength->getValue()); + settings->setValue(MAX_ANGLE,gl->maxAngle->getValue()); +} +#endif + +void YACReaderOptionsDialog::saveOptions() +{ + emit(optionsChanged()); + close(); +} + +#ifndef NO_OPENGL +void YACReaderOptionsDialog::saveUseGL(int b) +{ + + if(Qt::Checked == b) + { + sw->setVisible(false); + gl->setVisible(true); + } + else + { + gl->setVisible(false); + sw->setVisible(true); + } + resize(0,0); + + settings->setValue(USE_OPEN_GL,b); +} +#endif + +#ifndef NO_OPENGL +void YACReaderOptionsDialog::saveXRotation(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(X_ROTATION,value); +} +void YACReaderOptionsDialog::saveYPosition(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(Y_POSITION,value); +} +void YACReaderOptionsDialog::saveCoverDistance(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(COVER_DISTANCE,value); +} +void YACReaderOptionsDialog::saveCentralDistance(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(CENTRAL_DISTANCE,value); +} +void YACReaderOptionsDialog::saveZoomLevel(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(ZOOM_LEVEL,value); +} +void YACReaderOptionsDialog::saveYCoverOffset(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(Y_COVER_OFFSET,value); +} +void YACReaderOptionsDialog::saveZCoverOffset(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(Z_COVER_OFFSET,value); +} +void YACReaderOptionsDialog::saveCoverRotation(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(COVER_ROTATION,value); +} +void YACReaderOptionsDialog::saveFadeOutDist(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(FADE_OUT_DIST,value); +} +void YACReaderOptionsDialog::saveLightStrength(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(LIGHT_STRENGTH,value); +} + +void YACReaderOptionsDialog::saveMaxAngle(int value) +{ + settings->setValue(FLOW_TYPE_GL,Custom); + settings->setValue(MAX_ANGLE,value); +} +#endif +void YACReaderOptionsDialog::restoreOptions(QSettings * settings) +{ + this->settings = settings; + + //FLOW CONFIG +#ifndef NO_OPENGL + if(settings->contains(USE_OPEN_GL) && settings->value(USE_OPEN_GL).toInt() == Qt::Checked) + { + sw->setVisible(false); + gl->setVisible(true); + useGL->setChecked(true); + } + else + { + gl->setVisible(false); + sw->setVisible(true); + useGL->setChecked(false); + } + + + if(!settings->contains(FLOW_TYPE_GL)) + { + setClassicConfig(); + gl->radioClassic->setChecked(true); + gl->performanceSlider->setValue(1); + return; + } + + if(settings->contains(V_SYNC) && settings->value(V_SYNC).toInt() == Qt::Checked) + gl->vSyncCheck->setChecked(true); + else + gl->vSyncCheck->setChecked(false); + + gl->performanceSlider->setValue(settings->value(PERFORMANCE).toInt()); + + FlowType flowType; + switch(settings->value(FLOW_TYPE_GL).toInt()) + { + case 0: + flowType = CoverFlowLike; + break; + case 1: + flowType = Strip; + break; + case 2: + flowType = StripOverlapped; + break; + case 3: + flowType = Modern; + break; + case 4: + flowType = Roulette; + break; + case 5: + flowType = Custom; + break; + } + + + if(flowType == Custom) + { + loadConfig(); + return; + } + + if(flowType == CoverFlowLike) + { + setClassicConfig(); + gl->radioClassic->setChecked(true); + return; + } + + if(flowType == Strip) + { + setStripeConfig(); + gl->radioStripe->setChecked(true); + return; + } + + if(flowType == StripOverlapped) + { + setOverlappedStripeConfig(); + gl->radioOver->setChecked(true); + return; + } + + if(flowType == Modern) + { + setModernConfig(); + gl->radionModern->setChecked(true); + return; + } + + if(flowType == Roulette) + { + setRouletteConfig(); + gl->radioDown->setChecked(true); + return; + } + + //END FLOW CONFIG + #endif +} +#ifndef NO_OPENGL +void YACReaderOptionsDialog::loadConfig() +{ + gl->xRotation->setValue(settings->value(X_ROTATION).toInt()); + gl->yPosition->setValue(settings->value(Y_POSITION).toInt()); + gl->coverDistance->setValue(settings->value(COVER_DISTANCE).toInt()); + gl->centralDistance->setValue(settings->value(CENTRAL_DISTANCE).toInt()); + gl->zoomLevel->setValue(settings->value(ZOOM_LEVEL).toInt()); + gl->yCoverOffset->setValue(settings->value(Y_COVER_OFFSET).toInt()); + gl->zCoverOffset->setValue(settings->value(Z_COVER_OFFSET).toInt()); + gl->coverRotation->setValue(settings->value(COVER_ROTATION).toInt()); + gl->fadeOutDist->setValue(settings->value(FADE_OUT_DIST).toInt()); + gl->lightStrength->setValue(settings->value(LIGHT_STRENGTH).toInt()); + gl->maxAngle->setValue(settings->value(MAX_ANGLE).toInt()); +} +#endif +void YACReaderOptionsDialog::setClassicConfigSW() +{ + settings->setValue(FLOW_TYPE_SW,CoverFlowLike); +} + +void YACReaderOptionsDialog::setStripeConfigSW() +{ + settings->setValue(FLOW_TYPE_SW,Strip); +} + +void YACReaderOptionsDialog::setOverlappedStripeConfigSW() +{ + settings->setValue(FLOW_TYPE_SW,StripOverlapped); +} + +#ifndef NO_OPENGL +void YACReaderOptionsDialog::setClassicConfig() +{ + settings->setValue(FLOW_TYPE_GL,CoverFlowLike); + + gl->setValues(presetYACReaderFlowClassicConfig); + + saveFlowParameters(); +} + +void YACReaderOptionsDialog::setStripeConfig() +{ + settings->setValue(FLOW_TYPE_GL,Strip); + + gl->setValues(presetYACReaderFlowStripeConfig); + + saveFlowParameters(); +} + +void YACReaderOptionsDialog::setOverlappedStripeConfig() +{ + settings->setValue(FLOW_TYPE_GL,StripOverlapped); + + gl->setValues(presetYACReaderFlowOverlappedStripeConfig); + + saveFlowParameters(); +} + +void YACReaderOptionsDialog::setModernConfig() +{ + settings->setValue(FLOW_TYPE_GL,Modern); + + gl->setValues(defaultYACReaderFlowConfig); + + saveFlowParameters(); +} + +void YACReaderOptionsDialog::setRouletteConfig() +{ + settings->setValue(FLOW_TYPE_GL,Roulette); + + gl->setValues(pressetYACReaderFlowDownConfig); + + saveFlowParameters(); +} +#endif diff --git a/custom_widgets/yacreader_options_dialog.h b/custom_widgets/yacreader_options_dialog.h new file mode 100644 index 00000000..8921e661 --- /dev/null +++ b/custom_widgets/yacreader_options_dialog.h @@ -0,0 +1,72 @@ +#ifndef YACREADER_OPTIONS_DIALOG_H +#define YACREADER_OPTIONS_DIALOG_H + +#include + +class YACReaderFlowConfigWidget; +#ifndef NO_OPENGL +class YACReaderGLFlowConfigWidget; +#endif +class QCheckBox; +class QPushButton; +class QSettings; +class QGroupBox; + +class YACReaderOptionsDialog : public QDialog +{ + Q_OBJECT +protected: + YACReaderFlowConfigWidget * sw; + #ifndef NO_OPENGL + YACReaderGLFlowConfigWidget * gl; + QCheckBox * useGL; + #endif + + QPushButton * accept; + QPushButton * cancel; + + QGroupBox * shortcutsBox; + + QSettings * settings; + QSettings * previousSettings; + +public: + YACReaderOptionsDialog(QWidget * parent); +public slots: + virtual void restoreOptions(QSettings * settings); + virtual void saveOptions(); +protected slots: +#ifndef NO_OPENGL + virtual void savePerformance(int value); + virtual void saveUseVSync(int b); + virtual void saveUseGL(int b); + virtual void saveXRotation(int value); + virtual void saveYPosition(int value); + virtual void saveCoverDistance(int value); + virtual void saveCentralDistance(int value); + virtual void saveZoomLevel(int value); + virtual void saveYCoverOffset(int value); + virtual void saveZCoverOffset(int value); + virtual void saveCoverRotation(int value); + virtual void saveFadeOutDist(int value); + virtual void saveLightStrength(int value); + virtual void saveMaxAngle(int value); + virtual void loadConfig(); + virtual void setClassicConfig(); + virtual void setStripeConfig(); + virtual void setOverlappedStripeConfig(); + virtual void setModernConfig(); + virtual void setRouletteConfig(); + virtual void saveFlowParameters(); +#endif + virtual void setClassicConfigSW(); + virtual void setStripeConfigSW(); + virtual void setOverlappedStripeConfigSW(); + + +signals: + void optionsChanged(); + void editShortcuts(); +}; + +#endif // YACREADER_OPTIONS_DIALOG_H diff --git a/custom_widgets/yacreader_search_line_edit.cpp b/custom_widgets/yacreader_search_line_edit.cpp new file mode 100644 index 00000000..f81d276c --- /dev/null +++ b/custom_widgets/yacreader_search_line_edit.cpp @@ -0,0 +1,146 @@ +#include "yacreader_search_line_edit.h" + +#include +#include +#include + +#include + +#include "QsLog.h" + +YACReaderSearchLineEdit::YACReaderSearchLineEdit(QWidget *parent) + : QLineEdit(parent) +{ + clearButton = new QToolButton(this); + searchLabel = new QLabel(this); + + QPixmap pixmap(":/images/clearSearch.png"); + QPixmap pixmapIcon(":/images/iconSearch.png"); + + searchLabel->setStyleSheet("QLabel { border: none; padding: 0px; }"); + searchLabel->setPixmap(pixmapIcon); + + clearButton->setIcon(QIcon(pixmap)); + clearButton->setIconSize(pixmap.size()); + clearButton->setCursor(Qt::ArrowCursor); + clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); + clearButton->hide(); + connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); + connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&))); + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); +#ifdef Q_OS_MAC + setStyleSheet(QString("QLineEdit {border-top:1px solid #9F9F9F; border-bottom:1px solid #ACACAC; border-right:1px solid #ACACAC; border-left:1px solid #ACACAC; border-radius: 10px; background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #CACACA, stop: 0.15 #FFFFFF); padding-left: %1px; padding-right: %2px; padding-bottom: 1px; margin-bottom: 1px;} ").arg(searchLabel->sizeHint().width() + frameWidth + 6).arg(clearButton->sizeHint().width() + frameWidth + 2)); +#else + setStyleSheet(QString("QLineEdit {color: #ABABAB; border:none; border-radius: 4px; background-color:#404040; padding-left: %1px; padding-right: %2px; padding-bottom: 1px; margin-right: 9px;} ").arg(searchLabel->sizeHint().width() + frameWidth + 6 + 5).arg(clearButton->sizeHint().width() + frameWidth + 2)); +#endif + QSize msz = minimumSizeHint(); + setMinimumSize(qMax(msz.width(), clearButton->sizeHint().height() + frameWidth * 2 + 2), + qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2)); + +#ifdef Q_OS_MAC + setMaximumWidth(212); +#else + setMaximumWidth(173); + setFixedHeight(26); +#endif + + setAttribute(Qt::WA_MacShowFocusRect,false); + setPlaceholderText(tr("type to search")); + + //search modifiers + modifiers << "[read]" << "[unread]";//<< "[author]"; + modifiersCompleter = new QCompleter(modifiers); + + QString regExpString; + foreach(QString modifier, modifiers) + { + regExpString = regExpString + modifier.replace("[","\\[").replace("]","\\]") + ".*|"; + } + + regExpString = regExpString + "[^\\[].*"; + + QLOG_INFO () << regExpString; + + QRegExp regExp(regExpString); + QValidator *validator = new QRegExpValidator(regExp, this); + + setValidator(validator); + setCompleter(modifiersCompleter); + + connect(this,SIGNAL(textChanged(QString)),this,SLOT(processText(QString))); +} + +void YACReaderSearchLineEdit::clearText() +{ + disconnect(this,SIGNAL(textChanged(QString)),this,SLOT(processText(QString))); + clear(); + connect(this,SIGNAL(textChanged(QString)),this,SLOT(processText(QString))); +} + +//modifiers are not returned +const QString YACReaderSearchLineEdit::text() +{ + QString text = QLineEdit::text(); + + QRegExp regExp("\\[.*\\]"); + return text.remove(regExp).trimmed(); +} + +void YACReaderSearchLineEdit::resizeEvent(QResizeEvent *) +{ + #ifdef Q_OS_MAC + QSize sz = clearButton->sizeHint(); + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + clearButton->move(rect().right() - frameWidth - sz.width(), + (rect().bottom() + 1 - sz.height())/2); + + QSize szl = searchLabel->sizeHint(); + searchLabel->move(6,(rect().bottom() + 1 - szl.height())/2); + #else + QSize sz = clearButton->sizeHint(); + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + int marginRight = style()->pixelMetric(QStyle::PM_LayoutRightMargin); + clearButton->move(rect().right() - frameWidth - sz.width() - marginRight - 6, + (rect().bottom() + 2 - sz.height())/2); + + QSize szl = searchLabel->sizeHint(); + searchLabel->move(8,(rect().bottom() + 2 - szl.height())/2); + #endif +} + +void YACReaderSearchLineEdit::updateCloseButton(const QString& text) +{ + clearButton->setVisible(!text.isEmpty()); +} + +void YACReaderSearchLineEdit::processText(const QString &text) +{ + + QRegExp regExp("(\\[.*\\])(.*)"); + if(text.startsWith("[")) + { + if(regExp.exactMatch(text)) //avoid search while the modifiers are being written + { + QString modifier = regExp.cap(1); + QString searchText = regExp.cap(2).trimmed(); + + int indexOfModifier = modifiers.indexOf(modifier); + if(indexOfModifier != -1) + { + QLOG_INFO() << "modifier : " << modifier << "text : " << searchText; + emit filterChanged(static_cast(indexOfModifier+1), searchText); //TODO, do not use on indexOF + } + else + { + QLOG_ERROR() << "invalid modifier : " << modifier; + } + } + + QLOG_INFO() << "full text :" << text << " : " << regExp.indexIn(text); + } + else + { + QLOG_INFO() << "NoModifiers : " << text; + emit filterChanged(YACReader::NoModifiers,text); + } +} diff --git a/custom_widgets/yacreader_search_line_edit.h b/custom_widgets/yacreader_search_line_edit.h new file mode 100644 index 00000000..50f6fdbe --- /dev/null +++ b/custom_widgets/yacreader_search_line_edit.h @@ -0,0 +1,40 @@ +#ifndef YACREADER_SEARCH_LINE_EDIT_H +#define YACREADER_SEARCH_LINE_EDIT_H + +#include +#include + +#include "yacreader_global.h" + +class QToolButton; +class QLabel; + +class YACReaderSearchLineEdit : public QLineEdit +{ + Q_OBJECT + +public: + YACReaderSearchLineEdit(QWidget *parent = 0); + void clearText(); //no signal emited; + const QString text(); + +protected: + void resizeEvent(QResizeEvent *); + +signals: + void filterChanged(const YACReader::SearchModifiers, QString); + +private slots: + void updateCloseButton(const QString &text); + void processText(const QString & text); + +private: + QToolButton *clearButton; + QLabel * searchLabel; + QCompleter * modifiersCompleter; + QStringList modifiers; +}; + + + +#endif // YACREADER_SEARCH_LINE_EDIT_H diff --git a/custom_widgets/yacreader_sidebar.cpp b/custom_widgets/yacreader_sidebar.cpp new file mode 100644 index 00000000..fa9dd5d8 --- /dev/null +++ b/custom_widgets/yacreader_sidebar.cpp @@ -0,0 +1,195 @@ +#include "yacreader_sidebar.h" + +#include +#include + +#include "yacreader_folders_view.h" +#include "yacreader_reading_lists_view.h" +#include "yacreader_library_list_widget.h" +#include "yacreader_search_line_edit.h" +#include "yacreader_titled_toolbar.h" + + +YACReaderSideBar::YACReaderSideBar(QWidget *parent) : + QWidget(parent) +{ + setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Minimum); + + settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor + settings->beginGroup("libraryConfig"); + + //widgets + foldersView = new YACReaderFoldersView; + readingListsView = new YACReaderReadingListsView; + selectedLibrary = new YACReaderLibraryListWidget; + + librariesTitle = new YACReaderTitledToolBar(tr("LIBRARIES")); + foldersTitle = new YACReaderTitledToolBar(tr("FOLDERS")); + readingListsTitle = new YACReaderTitledToolBar(tr("READING LISTS")); + + splitter = new QSplitter(this); + splitter->setOrientation(Qt::Vertical); + +#ifndef Q_OS_MAC + splitter->setStyleSheet("QSplitter::handle { " + " image: none; background-color = black; " + " }" + "QSplitter::handle:vertical { height: 39px;}"); +#else + splitter->setStyleSheet("QSplitter::handle:vertical { height: 26px; background-color: transparent;}"); +#endif + + selectedLibrary->setContextMenuPolicy(Qt::ActionsContextMenu); + selectedLibrary->setAttribute(Qt::WA_MacShowFocusRect,false); + selectedLibrary->setFocusPolicy(Qt::NoFocus); + + //layout + QVBoxLayout * l = new QVBoxLayout; + + l->setContentsMargins(0,0,0,0); + + //LIBRARIES------------------------------------------------------- +#ifndef Q_OS_MAC + l->addSpacing(5); +#endif + + l->addWidget(librariesTitle); + +#ifndef Q_OS_MAC + l->addSpacing(4); + l->addWidget(new YACReaderSideBarSeparator(this)); + l->addSpacing(3); +#endif + + l->addWidget(selectedLibrary); +#ifndef Q_OS_MAC + l->addSpacing(11); +#else + l->addSpacing(6); +#endif + + //END LIBRARIES--------------------------------------------------- + + //FOLDERS--------------------------------------------------------- + QWidget * foldersContainer = new QWidget(this); + QVBoxLayout * foldersLayout = new QVBoxLayout; + foldersLayout->setContentsMargins(0,0,0,0); + foldersLayout->setSpacing(0); + +#ifndef Q_OS_MAC + //foldersLayout->addSpacing(6); + + //foldersLayout->addSpacing(5); + foldersLayout->addWidget(new YACReaderSideBarSeparator(this)); + foldersLayout->addSpacing(4); +#else + //foldersLayout->addSpacing(6); +#endif + + foldersLayout->addWidget(foldersTitle); + +#ifndef Q_OS_MAC + foldersLayout->addSpacing(4); + foldersLayout->addWidget(new YACReaderSideBarSeparator(this)); + foldersLayout->addSpacing(4); +#endif + + foldersLayout->addWidget(foldersView); + foldersLayout->addSpacing(6); + + foldersContainer->setLayout(foldersLayout); + splitter->addWidget(foldersContainer); + //END FOLDERS------------------------------------------------------ + + //READING LISTS---------------------------------------------------- + splitter->addWidget(readingListsView); + + QVBoxLayout * readingListsHeaderLayout = new QVBoxLayout; + readingListsHeaderLayout->setContentsMargins(0,0,0,0); + readingListsHeaderLayout->setSpacing(0); + +#ifndef Q_OS_MAC + //readingListsHeaderLayout->addSpacing(6); + + //readingListsHeaderLayout->addSpacing(5); + readingListsHeaderLayout->addWidget(new YACReaderSideBarSeparator(this)); + readingListsHeaderLayout->addSpacing(4); +#else + //readingListsHeaderLayout->addSpacing(6); +#endif + + readingListsHeaderLayout->addWidget(readingListsTitle); + +#ifndef Q_OS_MAC + readingListsHeaderLayout->addSpacing(4); + readingListsHeaderLayout->addWidget(new YACReaderSideBarSeparator(this)); + readingListsHeaderLayout->addSpacing(4); +#endif + + //readingListsLayout->addWidget(readingListsView); + readingListsHeaderLayout->addStretch(); + QSplitterHandle * handle = splitter->handle(1); + //handle->setCursor(QCursor(Qt::ArrowCursor)); + handle->setLayout(readingListsHeaderLayout); + //END READING LISTS------------------------------------------------ + + l->addWidget(splitter); + l->setSpacing(0); + + setLayout(l); + + if(settings->contains(SIDEBAR_SPLITTER_STATUS)) + splitter->restoreState(settings->value(SIDEBAR_SPLITTER_STATUS).toByteArray()); +} + + +void YACReaderSideBar::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event) + +#ifdef Q_OS_MAC + QPainter painter(this); + + painter.fillRect(0,0,width(),height(),QColor("#FFFFFF")); +#else + QPainter painter(this); + + painter.fillRect(0,0,width(),height(),QColor("#454545")); + //QWidget::paintEvent(event); +#endif + + + + //QPixmap shadow(":/images/side_bar/shadow.png"); + //painter.drawPixmap(width()-shadow.width(),0,shadow.width(),height(),shadow); + + // painter.setRenderHint(QPainter::Antialiasing); + // painter.drawLine(rect().topLeft(), rect().bottomRight()); + + //QWidget::paintEvent(event); +} + +void YACReaderSideBar::closeEvent(QCloseEvent *event) +{ + settings->setValue(SIDEBAR_SPLITTER_STATUS, splitter->saveState()); +} + +QSize YACReaderSideBar::sizeHint() const +{ + return QSize(275,200); +} + +YACReaderSideBarSeparator::YACReaderSideBarSeparator(QWidget *parent) + :QWidget(parent) +{ + setFixedHeight(1); +} + +void YACReaderSideBarSeparator::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event) + + QPainter painter(this); + + painter.fillRect(5,0,width()-10,height(),QColor("#575757")); +} diff --git a/custom_widgets/yacreader_sidebar.h b/custom_widgets/yacreader_sidebar.h new file mode 100644 index 00000000..9cd6d377 --- /dev/null +++ b/custom_widgets/yacreader_sidebar.h @@ -0,0 +1,47 @@ +#ifndef YACREADER_SIDEBAR_H +#define YACREADER_SIDEBAR_H + +#include + +class YACReaderFoldersView; +class YACReaderLibraryListWidget; +class YACReaderSearchLineEdit; +class YACReaderTitledToolBar; +class YACReaderTitledToolBar; +class YACReaderReadingListsView; + +class YACReaderSideBarSeparator : public QWidget +{ +public: + explicit YACReaderSideBarSeparator(QWidget * parent = 0); +protected: + void paintEvent(QPaintEvent *event); +}; + +class YACReaderSideBar : public QWidget +{ + Q_OBJECT +public: + explicit YACReaderSideBar(QWidget *parent = 0); + QSize sizeHint() const; + + YACReaderFoldersView * foldersView; + YACReaderReadingListsView * readingListsView; + YACReaderLibraryListWidget * selectedLibrary; + YACReaderTitledToolBar * librariesTitle; + YACReaderTitledToolBar * foldersTitle; + YACReaderTitledToolBar * readingListsTitle; + +signals: + +public slots: + +protected: + void paintEvent(QPaintEvent *); + void closeEvent ( QCloseEvent * event ); + QSettings * settings; + QSplitter * splitter; + +}; + +#endif // YACREADER_SIDEBAR_H diff --git a/custom_widgets/yacreader_social_dialog.cpp b/custom_widgets/yacreader_social_dialog.cpp new file mode 100644 index 00000000..32cc3d7c --- /dev/null +++ b/custom_widgets/yacreader_social_dialog.cpp @@ -0,0 +1,130 @@ +#include "yacreader_social_dialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "comic_db.h" + +YACReaderSocialDialog::YACReaderSocialDialog(QWidget *parent) : + QWidget(parent) +{ + + //setWindowFlags(Qt::Window | Qt::Dialog | Qt::FramelessWindowHint); + //setModal(true); + + + QToolButton * close = new QToolButton(this); + close->setIcon(QIcon(":/images/social_dialog/close.png")); + + QToolButton * facebook = new QToolButton(this); + facebook->setIcon(QIcon(":/images/social_dialog/facebook.png")); + + QToolButton * twitter = new QToolButton(this); + twitter->setIcon(QIcon(":/images/social_dialog/twitter.png")); + + QToolButton * google = new QToolButton(this); + google->setIcon(QIcon(":/images/social_dialog/google+.png")); + + QString styleSheet = "QToolButton {border:none; }"; + close->setStyleSheet(styleSheet); + facebook->setStyleSheet(styleSheet); + twitter->setStyleSheet(styleSheet); + google->setStyleSheet(styleSheet); + + QLabel * icon = new QLabel(this); + icon->setPixmap(QPixmap(":/images/social_dialog/icon.png")); + + plainText = new QTextEdit (this); + plainText->setStyleSheet("QTextEdit {border:none; padding:11px; font-size:12px; font-weight:bold; color:#525757;}"); + QTextCursor cursor(plainText->textCursor()); + QTextBlockFormat blockFormat = cursor.blockFormat(); + blockFormat.setLineHeight(12,QTextBlockFormat::SingleHeight); + cursor.setBlockFormat(blockFormat); + QLabel * sendTo = new QLabel(tr("send to:"),this); + sendTo->setStyleSheet("QLabel{color:#ABABAB; font-size:12px; font-weight:bold;}"); + + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + resize( sizeHint() ); + + close->move(437,5); + + QWidget * send = new QWidget(this); + QHBoxLayout * sendLayout = new QHBoxLayout; + + QPushButton * follow = new QPushButton(tr("Follow YACReader!"),this); + + follow->setStyleSheet("QPushButton{border:none; color:#FFFFFF;background:#404040; padding: 9px 25px 9px 25px; font-weight:bold; font-size:12px;}" + "QPushButton:hover{background:#E3B800;}"); + + sendLayout->setMargin(0); + sendLayout->setSpacing(0); + + sendLayout->addWidget(sendTo,1,Qt::AlignHCenter); + sendLayout->addSpacing(11); + sendLayout->addWidget(facebook,0,Qt::AlignHCenter); + sendLayout->addSpacing(6); + sendLayout->addWidget(twitter,0,Qt::AlignHCenter); + sendLayout->addSpacing(6); + sendLayout->addWidget(google,0,Qt::AlignHCenter); + + send->setLayout(sendLayout); + send->move(317,259); + + icon->move(279,14); + plainText->setFixedSize(291,155); + plainText->move(169,96); + + follow->move(230,307); + + connect(close,SIGNAL(released()),this,SLOT(close())); + + + +} + +void YACReaderSocialDialog::paintEvent(QPaintEvent * event) +{ + QPainter painter(this); + + //center + painter.fillRect(169,0,291,369,QColor("#F0F0F0")); + painter.fillRect(169,96,291,155,QColor("#FFFFFF")); + + + //QPixmap cover = QPixmap("c:/temp/6.jpg").scaledToHeight(369,Qt::SmoothTransformation); + painter.drawPixmap(0,0,169,369,cover,0,0, (169 * cover.height())/369 ,cover.height()); + + + QPixmap shadow(":/images/social_dialog/shadow.png"); + painter.drawPixmap(169-shadow.width(),0,shadow.width(),369,shadow); + + + QPixmap separtor(":/images/social_dialog/separator.png"); + painter.drawPixmap(169,96-separtor.height(),separtor); + + QPen pen("#C3CAD6"); + painter.setPen(pen); + painter.drawLine(169,251,460,251); + + QWidget::paintEvent(event); + +} + +QSize YACReaderSocialDialog::sizeHint() const +{ + return QSize(460,369); +} + +void YACReaderSocialDialog::setComic(ComicDB & comic, QString & basePath) +{ + this->cover = comic.info.getCover(basePath).scaledToHeight(369,Qt::SmoothTransformation); + plainText->setText(tr("I am reading %1 using YACReader.").arg(comic.path.split('/').last())); +} \ No newline at end of file diff --git a/custom_widgets/yacreader_social_dialog.h b/custom_widgets/yacreader_social_dialog.h new file mode 100644 index 00000000..b4340a92 --- /dev/null +++ b/custom_widgets/yacreader_social_dialog.h @@ -0,0 +1,28 @@ +#ifndef YACREADER_SOCIAL_DIALOG_H +#define YACREADER_SOCIAL_DIALOG_H + +#include + +class QPixmap; +class QTextEdit; +class ComicDB; + +class YACReaderSocialDialog : public QWidget +{ + Q_OBJECT +public: + explicit YACReaderSocialDialog(QWidget *parent = 0); + QSize sizeHint() const; +signals: + +public slots: + void setComic(ComicDB & comic,QString & basePath); +protected: + void paintEvent(QPaintEvent *); + +private: + QPixmap cover; + QTextEdit * plainText; +}; + +#endif // YACREADER_SOCIAL_DIALOG_H diff --git a/custom_widgets/yacreader_spin_slider_widget.cpp b/custom_widgets/yacreader_spin_slider_widget.cpp new file mode 100644 index 00000000..56e8a9dd --- /dev/null +++ b/custom_widgets/yacreader_spin_slider_widget.cpp @@ -0,0 +1,93 @@ +#include "yacreader_spin_slider_widget.h" + +#include +#include +#include +#include + +YACReaderSpinSliderWidget::YACReaderSpinSliderWidget(QWidget * parent,bool strechableSlider) + :QWidget(parent),tracking(true) +{ + QHBoxLayout * layout = new QHBoxLayout; + layout->addWidget(label = new QLabel(this),1); + if(!strechableSlider) + layout->addStretch(); + spinBox = new QSpinBox(this); + layout->addWidget(spinBox); + slider = new QSlider(Qt::Horizontal,this); + layout->addWidget(slider); + if(strechableSlider) + { + layout->setStretchFactor(slider,0.85); + layout->setStretchFactor(spinBox,0); + layout->setStretchFactor(label,0.15); + } + + connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int))); + connect(slider, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue(int))); + + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(valueWillChange(int))); + connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(valueWillChangeFromSpinBox(int))); + + connect(slider, SIGNAL(sliderReleased()), this, SLOT(sliderRelease())); + + setLayout(layout); +} +void YACReaderSpinSliderWidget::valueWillChange(int v) +{ + Q_UNUSED(v) + if(tracking) + emit valueChanged(spinBox->value()); +} + +void YACReaderSpinSliderWidget::valueWillChangeFromSpinBox(int v) +{ + Q_UNUSED(v) + if(!tracking && !slider->isSliderDown()) + emit valueChanged(spinBox->value()); +} + +void YACReaderSpinSliderWidget::sliderRelease() +{ + if(!tracking) + emit valueChanged(spinBox->value()); +} + +void YACReaderSpinSliderWidget::setRange(int lowValue, int topValue, int step) +{ + spinBox->setMinimum(lowValue); + spinBox->setMaximum(topValue); + spinBox->setSingleStep(step); + + slider->setMinimum(lowValue); + slider->setMaximum(topValue); + slider->setSingleStep(step); +} + +void YACReaderSpinSliderWidget::setValue(int value) +{ + disconnect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(valueWillChange(int))); + spinBox->setValue(value); + connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(valueWillChange(int))); +} + +void YACReaderSpinSliderWidget::setText(const QString & text) +{ + label->setText(text); +} + +int YACReaderSpinSliderWidget::getValue() +{ + return spinBox->value(); +} + +QSize YACReaderSpinSliderWidget::minimumSizeHint() const +{ + return QSize(270, 25); +} + +void YACReaderSpinSliderWidget::setTracking(bool b) +{ + tracking = b; + //slider->setTracking(b); +} diff --git a/custom_widgets/yacreader_spin_slider_widget.h b/custom_widgets/yacreader_spin_slider_widget.h new file mode 100644 index 00000000..8be271b0 --- /dev/null +++ b/custom_widgets/yacreader_spin_slider_widget.h @@ -0,0 +1,35 @@ +#ifndef YACREADER_SPIN_SLIDER_WIDGET_H +#define YACREADER_SPIN_SLIDER_WIDGET_H + +#include + +class QLabel; +class QSpinBox; +class QSlider; + +class YACReaderSpinSliderWidget : public QWidget +{ + Q_OBJECT +private: + QLabel * label; + QSpinBox * spinBox; + QSlider * slider; + bool tracking; +public: + YACReaderSpinSliderWidget(QWidget * parent = 0,bool strechableSlider = false); +public slots: + void setRange(int lowValue, int topValue, int step=1); + void setValue(int value); + void setText(const QString & text); + int getValue(); + QSize minimumSizeHint() const; + void setTracking(bool b); + void valueWillChange(int); + void valueWillChangeFromSpinBox(int); + void sliderRelease(); +signals: + void valueChanged(int); + +}; + +#endif // YACREADER_SPIN_SLIDER_WIDGET_H \ No newline at end of file diff --git a/custom_widgets/yacreader_table_view.cpp b/custom_widgets/yacreader_table_view.cpp new file mode 100644 index 00000000..9ace5aef --- /dev/null +++ b/custom_widgets/yacreader_table_view.cpp @@ -0,0 +1,487 @@ +#include "yacreader_table_view.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "QsLog.h" + +#include "comic_item.h" + +YACReaderTableView::YACReaderTableView(QWidget *parent) : + QTableView(parent),showDelete(false),editing(false),myeditor(0) +{ + setAlternatingRowColors(true); + verticalHeader()->setAlternatingRowColors(true); + setStyleSheet("QTableView {alternate-background-color: #F2F2F2;background-color: #FAFAFA; outline: 0px;}"// border: 1px solid #999999; border-right:none; border-bottom:none;}" + "QTableCornerButton::section {background-color:#F5F5F5; border:none; border-bottom:1px solid #B8BDC4; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D1D1D1, stop: 1 #B8BDC4);}" + "QTableView::item {outline: 0px; border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE; padding-bottom:1px; color:#252626;}" + "QTableView {border-top:1px solid #B8B8B8;border-bottom:none;border-left:1px solid #B8B8B8;border-right:none;}" +#ifdef Q_OS_MAC + "QTableView {border-top:1px solid #B8B8B8;border-bottom:none;border-left:none;border-right:none;}" + "QTableView::item:selected {outline: 0px; border-bottom: 1px solid #3875D7;border-top: 1px solid #3875D7; padding-bottom:1px; background-color: #3875D7; color: #FFFFFF; }" + +#else + "QTableView::item:selected {outline: 0px; border-bottom: 1px solid #D4D4D4;border-top: 1px solid #D4D4D4; padding-bottom:1px; background-color: #D4D4D4; }" +#endif + "QHeaderView::section:horizontal {background-color:#F5F5F5; border-bottom:1px solid #B8BDC4; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D1D1D1, stop: 1 #B8BDC4); border-left:none; border-top:none; padding:4px; color:#313232;}" + "QHeaderView::section:vertical {border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE;}" + //"QTableView::item:hover {border-bottom: 1px solid #A3A3A3;border-top: 1px solid #A3A3A3; padding-bottom:1px; background-color: #A3A3A3; color: #FFFFFF; }" + ""); + //comicView->setItemDelegate(new YACReaderComicViewDelegate()); + setContextMenuPolicy(Qt::ActionsContextMenu); + + setShowGrid(false); +#if QT_VERSION >= 0x050000 + verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); +#else + verticalHeader()->setResizeMode(QHeaderView::Fixed); +#endif + + //comicView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); + horizontalHeader()->setStretchLastSection(true); +#if QT_VERSION >= 0x050000 + horizontalHeader()->setSectionsClickable(false); +#else + horizontalHeader()->setClickable(false); +#endif + //comicView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); + verticalHeader()->setDefaultSectionSize(24); +#if QT_VERSION >= 0x050000 + verticalHeader()->setSectionsClickable(false); //TODO comportamiento anómalo +#else + verticalHeader()->setClickable(false); //TODO comportamiento anómalo +#endif + + setCornerButtonEnabled(false); + + setSelectionBehavior(QAbstractItemView::SelectRows); + setSelectionMode(QAbstractItemView::ExtendedSelection); + + setItemDelegateForColumn(11,new YACReaderRatingDelegate(this)); + setEditTriggers(QAbstractItemView::NoEditTriggers); + + setMouseTracking(true); + /*deletingProgress = new YACReaderDeletingProgress(this); + + showDeletingProgressAnimation = new QPropertyAnimation(deletingProgress,"pos"); + showDeletingProgressAnimation->setDuration(150);*/ + + //drag: if the default drag is enabled there is no way for setting a custom image + //TODO report bug/suggestion + //setDragEnabled(true); + //setDragDropMode(QAbstractItemView::DragDrop); + setAcceptDrops(true); +} + +void YACReaderTableView::mouseMoveEvent(QMouseEvent *event) +{ + + QModelIndex mi = indexAt(event->pos()); + if(mi.isValid()) + { + QList selectedIndexes = this->selectedIndexes(); + if(selectedIndexes.contains(mi)) + { + if(mi.column() == 11) + { + if(!editing) + { + editing = true; + currentIndexEditing = mi; + edit(mi); + myeditor = indexWidget(mi); + } + else if(mi.row() != currentIndexEditing.row()) + closeRatingEditor(); + } + else + closeRatingEditor(); + } + else + closeRatingEditor(); + } + else + closeRatingEditor(); + + //are we in a drag action?? + if(event->buttons() & Qt::LeftButton) { + int distance = (event->pos() - startDragPos).manhattanLength(); + if (distance >= QApplication::startDragDistance()) + performDrag(); + } + + //disabled mouseMoveEvent in the parent class +} +void YACReaderTableView::mousePressEvent(QMouseEvent * event) +{ + QTableView::mousePressEvent(event); + QModelIndex mi = indexAt(event->pos()); + if(mi.isValid()) + { + QList selectedIndexes = this->selectedIndexes(); + if(selectedIndexes.contains(mi)) + { + if(mi.column() == 11) + { + if(!editing) + { + editing = true; + currentIndexEditing = mi; + edit(mi); + myeditor = indexWidget(mi); + } + return; + } + } + } + + //this could be the origin of a new drag acction + if(event->button() == Qt::LeftButton) + { + startDragPos = event->pos(); + } +} +void YACReaderTableView::leaveEvent(QEvent * event) +{ + closeRatingEditor(); + event->accept(); +} + +void YACReaderTableView::performDrag() +{ + QLOG_DEBUG() << "performDrag"; + QDrag *drag = new QDrag(this); + drag->setMimeData(model()->mimeData(selectionModel()->selectedRows())); + drag->setPixmap(QPixmap(":/images/openInYACReader.png")); //TODO add better image + + /*Qt::DropAction dropAction =*/ drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); +} + +void YACReaderTableView::dragEnterEvent(QDragEnterEvent *event) +{ + QTableView::dragEnterEvent(event); + + if(model()->canDropMimeData(event->mimeData(),event->proposedAction(),0,0,QModelIndex())) + event->acceptProposedAction(); + QLOG_DEBUG() << "drag enter table"; +} + +void YACReaderTableView::dragMoveEvent(QDragMoveEvent *event) +{ + QTableView::dragMoveEvent(event); + + if(model()->canDropMimeData(event->mimeData(),event->proposedAction(),0,0,QModelIndex())) + event->acceptProposedAction(); + QLOG_DEBUG() << "dragMoveEvent table"; +} + +void YACReaderTableView::dropEvent(QDropEvent *event) +{ + QTableView::dropEvent(event); + + if(model()->canDropMimeData(event->mimeData(),event->proposedAction(),0,0,QModelIndex())) + event->acceptProposedAction(); + QLOG_DEBUG() << "drop on table"; + +} + +void YACReaderTableView::closeRatingEditor() +{ + editing = false; + if(myeditor!=0) + closeEditor(myeditor,QAbstractItemDelegate::NoHint); + myeditor = 0; +} + +void YACReaderTableView::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint ) +{ + editing = false; + myeditor = 0; + QTableView::closeEditor(editor,hint); +} +void YACReaderTableView::commitData ( QWidget * editor ) +{ + //TODO + StarEditor *starEditor = qobject_cast(editor); + if(starEditor->getShouldCommitData()) + emit comicRated(((StarEditor *)editor)->starRating().starCount(),currentIndexEditing); +} + +void YACReaderTableView::showDeleteProgress() +{ + /*showDelete = true; + + showDeletingProgressAnimation->setStartValue(deletingProgress->pos()); + showDeletingProgressAnimation->setEndValue(QPoint((width()-deletingProgress->width())/2 ,1)); + showDeletingProgressAnimation->start();*/ +} + +void YACReaderTableView::hideDeleteProgress() +{ + /*showDelete = false; + + if(showDeletingProgressAnimation->state()==QPropertyAnimation::Running) + showDeletingProgressAnimation->stop(); + + showDeletingProgressAnimation->setStartValue(deletingProgress->pos()); + showDeletingProgressAnimation->setEndValue(QPoint((width()-deletingProgress->width())/2 ,-deletingProgress->height())); + showDeletingProgressAnimation->start();*/ +} + +void YACReaderTableView::resizeEvent(QResizeEvent * event) +{ + /*event->size(); + + if(showDelete) + deletingProgress->move((event->size().width()-deletingProgress->width())/2 ,1); + else + deletingProgress->move((event->size().width()-deletingProgress->width())/2 ,-deletingProgress->height());*/ + + QTableView::resizeEvent(event); +} + +//------------------------------------------------------------------------------ +//YACReaderRatingDelegate------------------------------------------------------- +//------------------------------------------------------------------------------ +void YACReaderRatingDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + int rating = ((ComicItem *)index.internalPointer())->data(11).toInt(); + + StarRating starRating(rating); + + QStyledItemDelegate::paint(painter, option, index); + + if(!(option.state & QStyle::State_Editing)) + { + if (option.state & QStyle::State_Selected) + starRating.paintSelected(painter, option.rect, option.palette, + StarRating::ReadOnly); + else + starRating.paint(painter, option.rect, option.palette, + StarRating::ReadOnly); + } +} + +QSize YACReaderRatingDelegate::sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + Q_UNUSED(option) + int rating = ((ComicItem *)index.internalPointer())->data(11).toInt(); + StarRating starRating(rating); + return starRating.sizeHint(); +} + +QWidget *YACReaderRatingDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + Q_UNUSED(option) + Q_UNUSED(index) + StarEditor *editor = new StarEditor(parent); + connect(editor, SIGNAL(editingFinished()), + this, SLOT(sendCloseEditor())); + connect(editor, SIGNAL(commitData()), + this, SLOT(sendCommitData())); + return editor; +} + +void YACReaderRatingDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + int rating = ((ComicItem *)index.internalPointer())->data(11).toInt(); + + StarRating starRating(rating); + + StarEditor *starEditor = qobject_cast(editor); + starEditor->setStarRating(starRating); +} + +void YACReaderRatingDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + QStyledItemDelegate::setModelData(editor, model, index); +} + +void YACReaderRatingDelegate::sendCommitData() +{ + StarEditor *editor = qobject_cast(sender()); + emit commitData(editor); +} +void YACReaderRatingDelegate::sendCloseEditor() +{ + StarEditor *editor = qobject_cast(sender()); + emit closeEditor(editor); +} + +//------------------------------------------------------------------------------- +//StarRating--------------------------------------------------------------------- +//------------------------------------------------------------------------------- + +const int PaintingScaleFactor = 20; + +StarRating::StarRating(int starCount, int maxStarCount) +{ + myStarCount = starCount; + myMaxStarCount = maxStarCount; + + int numVertex = 5; + double pi = 3.14159265359; + double angle = 3.14159265359 / numVertex; + + float rOuter = 0.3f; + float rInner = 0.15f; + for (int i = 0; i < 2 * numVertex; i++) + { + double r = (i & 1) == 0 ? rOuter : rInner; + starPolygon << QPointF(0.5 + cos((i * angle)-pi/2) * r, 0.5 + sin((i * angle)-pi/2) * r); + } + + diamondPolygon << QPointF(0.4, 0.5) << QPointF(0.5, 0.4) + << QPointF(0.6, 0.5) << QPointF(0.5, 0.6) + << QPointF(0.4, 0.5); +} + +QSize StarRating::sizeHint() const +{ + return PaintingScaleFactor * QSize(myMaxStarCount, 1); +} + +void StarRating::paint(QPainter *painter, const QRect &rect, + const QPalette &palette, EditMode mode) const +{ + Q_UNUSED(palette) + painter->save(); + + painter->setRenderHint(QPainter::Antialiasing, true); + painter->setPen(Qt::NoPen); + + //if (mode == Editable) { + // painter->setBrush(palette.highlight()); + //} else { + QBrush brush(QColor("#e9be0f")); + painter->setBrush(brush); + //} + + int yOffset = (rect.height() - PaintingScaleFactor) / 2; + painter->translate(rect.x(), rect.y() + yOffset); + painter->scale(PaintingScaleFactor, PaintingScaleFactor); + + for (int i = 0; i < myMaxStarCount; ++i) { + if (i < myStarCount) { + painter->drawPolygon(starPolygon, Qt::WindingFill); + } else if (mode == Editable) { + painter->drawEllipse(QPointF(0.5,0.5),0.08,0.08);//(diamondPolygon, Qt::WindingFill); + } + painter->translate(1.0, 0.0); + } + + painter->restore(); +} + +void StarRating::paintSelected(QPainter *painter, const QRect &rect, + const QPalette &palette, EditMode mode, QColor color) const +{ + Q_UNUSED(palette) + Q_UNUSED(mode) + painter->save(); + + painter->setRenderHint(QPainter::Antialiasing, true); + painter->setPen(Qt::NoPen); + + QBrush star(color); + QBrush dot(QColor("#ffffff")); + + int yOffset = (rect.height() - PaintingScaleFactor) / 2; + painter->translate(rect.x(), rect.y() + yOffset); + painter->scale(PaintingScaleFactor, PaintingScaleFactor); + + for (int i = 0; i < myMaxStarCount; ++i) { + if (i < myStarCount) { + painter->setBrush(star); + painter->drawPolygon(starPolygon, Qt::WindingFill); + } else { + painter->setBrush(dot); + painter->drawEllipse(QPointF(0.5,0.5),0.08,0.08); + } + painter->translate(1.0, 0.0); + } + + painter->restore(); +} + +void StarRating::paintSelected(QPainter *painter, const QRect &rect, + const QPalette &palette, EditMode mode) const +{ + paintSelected(painter,rect, palette,mode,QColor("#ffffff")); +} + + +//------------------------------------------------------------------------------- +//StarEditor--------------------------------------------------------------------- +//------------------------------------------------------------------------------- + +StarEditor::StarEditor(QWidget *parent) + : QWidget(parent),shouldCommitData(false) +{ + //setMouseTracking(true); + //setAutoFillBackground(true); +} + +QSize StarEditor::sizeHint() const +{ + return myStarRating.sizeHint(); +} + +void StarEditor::paintEvent(QPaintEvent *) +{ + /* + QPainter painter(this); + myStarRating.paintSelected(&painter, rect(), this->palette(), + StarRating::Editable,QColor("#615f59"));*/ +} + +void StarEditor::mouseMoveEvent(QMouseEvent *event) +{ + Q_UNUSED(event) + /*int star = starAtPosition(event->x()); + + if (star != myStarRating.starCount() && star != -1) { + myStarRating.setStarCount(star); + update(); + }*/ +} +void StarEditor::leaveEvent(QEvent * event){ + emit editingFinished(); + QWidget::leaveEvent(event); +} + +void StarEditor::mousePressEvent(QMouseEvent * event ) +{ + if(event->button() == Qt::LeftButton) + { + int star = starAtPosition(event->x()); + + if (star != myStarRating.starCount() && star != -1) { + myStarRating.setStarCount(star); + shouldCommitData = true; + emit commitData(); + } + } +} + +int StarEditor::starAtPosition(int x) +{ + int star = (x / (myStarRating.sizeHint().width() + / myStarRating.maxStarCount())) + 1; + if (star <= 0 || star > myStarRating.maxStarCount()) + return -1; + + return star; +} diff --git a/custom_widgets/yacreader_table_view.h b/custom_widgets/yacreader_table_view.h new file mode 100644 index 00000000..0c7bb607 --- /dev/null +++ b/custom_widgets/yacreader_table_view.h @@ -0,0 +1,132 @@ +#ifndef YACREADER_TABLE_VIEW_H +#define YACREADER_TABLE_VIEW_H + +#include +#include + +class YACReaderDeletingProgress; +class QResizeEvent; +class QPropertyAnimation; + +class YACReaderTableView : public QTableView +{ + Q_OBJECT +public: + explicit YACReaderTableView(QWidget *parent = 0); + +signals: + void comicRated(int,QModelIndex); +public slots: + void showDeleteProgress(); + void hideDeleteProgress(); + void closeRatingEditor(); +protected slots: + +virtual void closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint ); +virtual void commitData ( QWidget * editor ); +private: + YACReaderDeletingProgress * deletingProgress; + bool showDelete; + QPropertyAnimation * showDeletingProgressAnimation; + + void resizeEvent(QResizeEvent * event); + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent * event); + void leaveEvent(QEvent * event); + void performDrag(); + void dragEnterEvent(QDragEnterEvent * event); + void dragMoveEvent(QDragMoveEvent * event); + void dropEvent(QDropEvent * event); + + + bool editing; + QModelIndex currentIndexEditing; + QWidget * myeditor; + + //drag from here + QPoint startDragPos; +}; + +//--- + +class YACReaderRatingDelegate : public QStyledItemDelegate +{ + Q_OBJECT + +public: + YACReaderRatingDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {} + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const; + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + +private slots: + void sendCloseEditor(); + void sendCommitData(); +}; + +//--- + +class StarRating +{ +public: + enum EditMode { Editable, ReadOnly }; + + StarRating(int starCount = 1, int maxStarCount = 5); + + void paint(QPainter *painter, const QRect &rect, + const QPalette &palette, EditMode mode) const; + void paintSelected(QPainter *painter, const QRect &rect, + const QPalette &palette, EditMode mode, QColor color) const; + void paintSelected(QPainter *painter, const QRect &rect, + const QPalette &palette, EditMode mode) const; + QSize sizeHint() const; + int starCount() const { return myStarCount; } + int maxStarCount() const { return myMaxStarCount; } + void setStarCount(int starCount) { myStarCount = starCount; } + void setMaxStarCount(int maxStarCount) { myMaxStarCount = maxStarCount; } +private: + QPolygonF starPolygon; + QPolygonF diamondPolygon; + int myStarCount; + int myMaxStarCount; +}; +Q_DECLARE_METATYPE(StarRating); +//--- + +class StarEditor : public QWidget +{ + Q_OBJECT + +public: + StarEditor(QWidget *parent = 0); + + QSize sizeHint() const; + void setStarRating(const StarRating &starRating) { + myStarRating = starRating; + } + StarRating starRating() { return myStarRating; } + bool getShouldCommitData() {return shouldCommitData;}; + +signals: + void editingFinished(); + void commitData(); + +protected: + void paintEvent(QPaintEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void leaveEvent(QEvent * event); + +private: + int starAtPosition(int x); + StarRating myStarRating; + bool shouldCommitData; +}; +#endif // YACREADER_TABLE_VIEW_H diff --git a/custom_widgets/yacreader_titled_toolbar.cpp b/custom_widgets/yacreader_titled_toolbar.cpp new file mode 100644 index 00000000..9651a59d --- /dev/null +++ b/custom_widgets/yacreader_titled_toolbar.cpp @@ -0,0 +1,130 @@ +#include "yacreader_titled_toolbar.h" + +#include +#include +#include +#include +#include +#include + + + +DropShadowLabel::DropShadowLabel(QWidget* parent) : + QLabel(parent) +{ } + +void DropShadowLabel::drawText(QPainter *painter, + QPoint offset) +{ + Q_ASSERT(painter != 0); + + // Draw shadow. + painter->setPen(QPen(textColor)); + painter->drawText(rect().translated(offset), + alignment(), text()); +} +void DropShadowLabel::drawTextEffect(QPainter *painter, + QPoint offset) +{ + Q_ASSERT(painter != 0); + + // Draw shadow. + painter->setPen(QPen(dropShadowColor)); + painter->drawText(rect().translated(offset), + alignment(), text()); +} + +void DropShadowLabel::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QPainter painter(this); + painter.setFont(font()); + //TODO find where is the '3' comming from? + drawTextEffect(&painter, QPoint(contentsMargins().left(), 1)); + drawText(&painter, QPoint(contentsMargins().left(), 0)); +} + +void DropShadowLabel::setColor(const QColor & color) +{ + textColor = color; +} + +void DropShadowLabel::setDropShadowColor(const QColor & color) +{ + dropShadowColor = color; +} + + + +YACReaderTitledToolBar::YACReaderTitledToolBar(const QString & title, QWidget *parent) : + QWidget(parent) +{ + QHBoxLayout * mainLayout = new QHBoxLayout; + mainLayout->setMargin(0); + mainLayout->setSpacing(0); + + QString styleSheet = "QWidget {border:0px;}"; + setStyleSheet(styleSheet); + + nameLabel = new DropShadowLabel(this); + nameLabel->setText(title); +#ifdef Q_OS_MAC + QString nameLabelStyleSheet = "QLabel {padding:0 0 0 10px; margin:0px; font-size:11px; font-weight:bold;}"; + nameLabel->setColor(QColor("#707E8C")); + nameLabel->setDropShadowColor(QColor("#F9FAFB")); +#else + QString nameLabelStyleSheet = "QLabel {padding:0 0 0 10px; margin:0px; font-size:11px; font-weight:bold;}"; + nameLabel->setColor(QColor("#BDBFBF")); + nameLabel->setDropShadowColor(QColor("#000000")); +#endif + nameLabel->setStyleSheet(nameLabelStyleSheet); + + mainLayout->addWidget(nameLabel,Qt::AlignLeft); + mainLayout->addStretch(); + + setLayout(mainLayout); + + setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); + + setMinimumHeight(25); +} + + +void YACReaderTitledToolBar::addAction(QAction * action) +{ + QHBoxLayout * mainLayout = dynamic_cast(layout()); + + QToolButton * tb = new QToolButton(this); + tb->setCursor(QCursor(Qt::ArrowCursor)); + tb->setDefaultAction(action); + tb->setIconSize(QSize(16,16)); + tb->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); + //tb->setStyleSheet("QToolButton:hover {background-color:#C5C5C5;}"); + + mainLayout->addWidget(tb); +} + +void YACReaderTitledToolBar::addSpacing(int spacing) +{ + QHBoxLayout * mainLayout = dynamic_cast(layout()); + + mainLayout->addSpacing(spacing); +} + +void YACReaderTitledToolBar::addSepartor() +{ + QHBoxLayout * mainLayout = dynamic_cast(layout()); + + QWidget * w = new QWidget(this); + w->setFixedSize(1,14); +#ifdef Q_OS_MAC + w->setStyleSheet("QWidget {background-color:#AFAFAF;}"); +#else + w->setStyleSheet("QWidget {background-color:#6F6F6F;}"); +#endif + + mainLayout->addSpacing(10); + mainLayout->addWidget(w); + mainLayout->addSpacing(10); +} diff --git a/custom_widgets/yacreader_titled_toolbar.h b/custom_widgets/yacreader_titled_toolbar.h new file mode 100644 index 00000000..21b9b75c --- /dev/null +++ b/custom_widgets/yacreader_titled_toolbar.h @@ -0,0 +1,46 @@ +#ifndef YACREADER_TITLED_TOOLBAR_H +#define YACREADER_TITLED_TOOLBAR_H + +#include +#include +#include +#include +#include + +class QIcon; + +class DropShadowLabel : public QLabel +{ + Q_OBJECT + +public: + + DropShadowLabel(QWidget* parent = 0); + void paintEvent(QPaintEvent *event); + void setColor(const QColor & color); + void setDropShadowColor(const QColor & color); +private: + + QColor dropShadowColor; + QColor textColor; + void drawText(QPainter *painter, QPoint offset); + void drawTextEffect(QPainter* painter, QPoint offset); +}; + +class YACReaderTitledToolBar : public QWidget +{ + Q_OBJECT +public: + explicit YACReaderTitledToolBar(const QString & title, QWidget *parent = 0); + +signals: + +public slots: + void addAction(QAction * action); + void addSpacing(int space); + void addSepartor(); +private: + DropShadowLabel * nameLabel; +}; + +#endif // YACREADER_TITLED_TOOLBAR_H diff --git a/custom_widgets/yacreader_tool_bar_stretch.cpp b/custom_widgets/yacreader_tool_bar_stretch.cpp new file mode 100644 index 00000000..e69de29b diff --git a/custom_widgets/yacreader_tool_bar_stretch.h b/custom_widgets/yacreader_tool_bar_stretch.h new file mode 100644 index 00000000..d4817176 --- /dev/null +++ b/custom_widgets/yacreader_tool_bar_stretch.h @@ -0,0 +1,18 @@ +#ifndef YACREADER_TOOL_BAR_STRETCH_H +#define YACREADER_TOOL_BAR_STRETCH_H + +#include +#include + +class QToolBarStretch : public QWidget +{ +public: + QToolBarStretch(QWidget * parent=0):QWidget(parent) + { + QHBoxLayout * l= new QHBoxLayout(); + l->addStretch(); + setLayout(l); + } +}; + +#endif // YACREADER_TOOL_BAR_STRETCH_H diff --git a/custom_widgets/yacreader_treeview.cpp b/custom_widgets/yacreader_treeview.cpp new file mode 100644 index 00000000..b180b64b --- /dev/null +++ b/custom_widgets/yacreader_treeview.cpp @@ -0,0 +1,154 @@ +#include "yacreader_treeview.h" + +YACReaderTreeView::YACReaderTreeView(QWidget *parent) : + QTreeView(parent) +{ + setAcceptDrops(true); + setDragDropMode(QAbstractItemView::DropOnly); + setItemsExpandable(true); + + //setDragEnabled(true); + /*viewport()->setAcceptDrops(true); + setDropIndicatorShown(true);*/ + + setContextMenuPolicy(Qt::CustomContextMenu); + + header()->hide(); + setUniformRowHeights(true); + setSelectionBehavior(QAbstractItemView::SelectRows); + setAttribute(Qt::WA_MacShowFocusRect,false); + +#ifdef Q_OS_MAC + + bool oldStyle = true; + switch (QSysInfo::MacVersion()) + { + case QSysInfo::MV_SNOWLEOPARD: + case QSysInfo::MV_LION: + case QSysInfo::MV_MOUNTAINLION: + case QSysInfo::MV_MAVERICKS: + oldStyle = true; //TODO fix this + break; + default: + oldStyle = false; + break; + } + + if(oldStyle) + { + setStyleSheet("QTreeView {background-color:transparent; border: none;}" + "QTreeView::item:selected {background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6BAFE4, stop: 1 #3984D2); border-top: 2px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #5EA3DF, stop: 1 #73B8EA); border-left:none;border-right:none;border-bottom:1px solid #3577C2;}" + "QTreeView::branch:selected {background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6BAFE4, stop: 1 #3984D2); border-top: 2px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #5EA3DF, stop: 1 #73B8EA); border-left:none;border-right:none;border-bottom:1px solid #3577C2;}" + "QTreeView::branch:open:selected:has-children {image: url(':/images/sidebar/expanded_branch_osx.png');}" + "QTreeView::branch:closed:selected:has-children {image: url(':/images/sidebar/collapsed_branch_osx.png');}" + + "QScrollBar:vertical { border: none; background: #EFEFEF; width: 9px; margin: 0 3px 0 0; }" + "QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; margin: 1px; border: 1px solid #D0D0D0; }" + "QScrollBar::add-line:vertical { border: none; background: #EFEFEF; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}" + + "QScrollBar::sub-line:vertical { border: none; background: #EFEFEF; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}" + "QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}" + + "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background: none; }" + ); + } + else + { + setStyleSheet("QTreeView {background-color:transparent; border: none;}" + "QTreeView::item:selected {background-color:#91c4f4; border-top: 1px solid #91c4f4; border-left:none;border-right:none;border-bottom:1px solid #91c4f4;}" + "QTreeView::branch:selected {background-color:#91c4f4; border-top: 1px solid #91c4f4; border-left:none;border-right:none;border-bottom:1px solid #91c4f4;}" + "QTreeView::branch:open:selected:has-children {image: url(':/images/sidebar/expanded_branch_osx.png');}" + "QTreeView::branch:closed:selected:has-children {image: url(':/images/sidebar/collapsed_branch_osx.png');}" + + ); + } + + +#else + setStyleSheet("QTreeView {background-color:transparent; border: none; color:#DDDFDF; outline:0; show-decoration-selected: 0;}" + "QTreeView::item:selected {background-color: #2E2E2E; color:white; font:bold;}" + "QTreeView::item:hover {background-color:#2E2E2E; color:white; font:bold;}" + "QTreeView::branch:selected {background-color:#2E2E2E;}" + + "QScrollBar:vertical { border: none; background: #404040; width: 7px; margin: 0 3px 0 0; }" + "QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }" + "QScrollBar::add-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}" + + "QScrollBar::sub-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}" + "QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}" + "QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}" + + "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background: none; }" + + "QTreeView::branch:has-children:!has-siblings:closed,QTreeView::branch:closed:has-children:has-siblings {border-image: none;image: url(':/images/sidebar/branch-closed.png');}" + "QTreeView::branch:has-children:selected:!has-siblings:closed,QTreeView::branch:closed:selected:has-children:has-siblings {border-image: none;image: url(':/images/sidebar/collapsed_branch_selected.png');}" + + "QTreeView::branch:open:has-children:!has-siblings,QTreeView::branch:open:has-children:has-siblings {border-image: none;image: url(':/images/sidebar/branch-open.png');}" + "QTreeView::branch:open:has-children:selected:!has-siblings,QTreeView::branch:open:has-children:selected:has-siblings {border-image: none;image: url(':/images/sidebar/expanded_branch_selected.png');}" + ); +#endif + +} + +void YACReaderTreeView::mousePressEvent(QMouseEvent *event) +{ + QTreeView::mousePressEvent(event); + + QModelIndex destinationIndex = indexAt(event->pos()); + + if(!destinationIndex.isValid() && event->button() == Qt::LeftButton) + { + clearSelection(); + } +} + +void YACReaderTreeView::expandCurrent() +{ + QModelIndex index = indexAt(expandPos); + if(index.isValid()) + expand(index); +} + +void YACReaderTreeView::dragEnterEvent(QDragEnterEvent *event) +{ + QTreeView::dragEnterEvent(event); +} + +void YACReaderTreeView::dragLeaveEvent(QDragLeaveEvent *event) +{ + Q_UNUSED(event) +} + +void YACReaderTreeView::dragMoveEvent(QDragMoveEvent *event) +{ + QTreeView::dragMoveEvent(event); + + //fix for drop auto expand + QModelIndex underMouse = indexAt(event->pos()); + if( underMouse.isValid()) { + expandPos = event->pos(); + connect(&expandTimer,SIGNAL(timeout()),this,SLOT(expandCurrent())); + expandTimer.setSingleShot(true); + expandTimer.start(500); + } + //force mouse hover decoration, TODO why the event loop is not working here? + if(!t.isActive()) + { + t.setSingleShot(true); + t.setInterval(50); + t.start(); + repaint(); + } + +} + +void YACReaderTreeView::dropEvent(QDropEvent *event) +{ + t.stop(); + + QTreeView::dropEvent(event); +} + + + diff --git a/custom_widgets/yacreader_treeview.h b/custom_widgets/yacreader_treeview.h new file mode 100644 index 00000000..d4c719b3 --- /dev/null +++ b/custom_widgets/yacreader_treeview.h @@ -0,0 +1,29 @@ +#ifndef YACREADER_TREEVIEW_H +#define YACREADER_TREEVIEW_H + +#include + +class YACReaderTreeView : public QTreeView +{ + Q_OBJECT +public: + explicit YACReaderTreeView(QWidget *parent = 0); + void mousePressEvent(QMouseEvent *event); +protected slots: + //fix for drop auto expand + void expandCurrent(); + +protected: + //Drop to import + void dragEnterEvent(QDragEnterEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); + + //fix for drop auto expand + QTimer expandTimer; + QTimer t; + QPoint expandPos; +}; + +#endif // YACREADER_TREEVIEW_H diff --git a/dependencies/poppler/bin/poppler-qt5.dll b/dependencies/poppler/bin/poppler-qt5.dll new file mode 100644 index 00000000..675d8ad1 Binary files /dev/null and b/dependencies/poppler/bin/poppler-qt5.dll differ diff --git a/dependencies/poppler/dependencies/bin/freetype6.dll b/dependencies/poppler/dependencies/bin/freetype6.dll new file mode 100644 index 00000000..632b2a40 Binary files /dev/null and b/dependencies/poppler/dependencies/bin/freetype6.dll differ diff --git a/dependencies/poppler/dependencies/bin/freetype6.dll.manifest b/dependencies/poppler/dependencies/bin/freetype6.dll.manifest new file mode 100644 index 00000000..e693382a --- /dev/null +++ b/dependencies/poppler/dependencies/bin/freetype6.dll.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/dependencies/poppler/dependencies/bin/openjpeg.dll b/dependencies/poppler/dependencies/bin/openjpeg.dll new file mode 100644 index 00000000..bdd8f57e Binary files /dev/null and b/dependencies/poppler/dependencies/bin/openjpeg.dll differ diff --git a/dependencies/poppler/dependencies/bin/openjpeg.dll.manifest b/dependencies/poppler/dependencies/bin/openjpeg.dll.manifest new file mode 100644 index 00000000..e693382a --- /dev/null +++ b/dependencies/poppler/dependencies/bin/openjpeg.dll.manifest @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/dependencies/poppler/dependencies/lib/empty.txt b/dependencies/poppler/dependencies/lib/empty.txt new file mode 100644 index 00000000..e69de29b diff --git a/dependencies/poppler/include/qt5/ArthurOutputDev.h b/dependencies/poppler/include/qt5/ArthurOutputDev.h new file mode 100644 index 00000000..9d5e8679 --- /dev/null +++ b/dependencies/poppler/include/qt5/ArthurOutputDev.h @@ -0,0 +1,170 @@ +//======================================================================== +// +// ArthurOutputDev.h +// +// Copyright 2003 Glyph & Cog, LLC +// +//======================================================================== + +//======================================================================== +// +// Modified under the Poppler project - http://poppler.freedesktop.org +// +// All changes made under the Poppler project to this file are licensed +// under GPL version 2 or later +// +// Copyright (C) 2005 Brad Hards +// Copyright (C) 2005 Albert Astals Cid +// Copyright (C) 2009, 2011 Carlos Garcia Campos +// Copyright (C) 2010 Pino Toscano +// Copyright (C) 2011 Andreas Hartmetz +// Copyright (C) 2013 Thomas Freitag +// +// To see a description of the changes please see the Changelog file that +// came with your tarball or type make ChangeLog if you are building from git +// +//======================================================================== + +#ifndef ARTHUROUTPUTDEV_H +#define ARTHUROUTPUTDEV_H + +#ifdef USE_GCC_PRAGMAS +#pragma interface +#endif + +#include "goo/gtypes.h" +#include "OutputDev.h" +#include "GfxState.h" + +#include + +class GfxState; +class GfxPath; +class Gfx8BitFont; +struct GfxRGB; + +class SplashFont; +class SplashFontEngine; +struct SplashGlyphBitmap; + +//------------------------------------------------------------------------ +// ArthurOutputDev - Qt 4 QPainter renderer +//------------------------------------------------------------------------ + +class ArthurOutputDev: public OutputDev { +public: + /** + * Describes how fonts are distorted (aka hinted) to fit the pixel grid. + * More hinting means sharper edges and less adherence to the true letter shapes. + */ + enum FontHinting { + NoHinting = 0, ///< Font shapes are left unchanged + SlightHinting, ///< Font shapes are distorted vertically only + FullHinting ///< Font shapes are distorted horizontally and vertically + }; + + // Constructor. + ArthurOutputDev(QPainter *painter ); + + // Destructor. + virtual ~ArthurOutputDev(); + + void setFontHinting(FontHinting hinting) { m_fontHinting = hinting; } + + //----- get info about output device + + // Does this device use upside-down coordinates? + // (Upside-down means (0,0) is the top left corner of the page.) + virtual GBool upsideDown() { return gTrue; } + + // Does this device use drawChar() or drawString()? + virtual GBool useDrawChar() { return gTrue; } + + // Does this device use beginType3Char/endType3Char? Otherwise, + // text in Type 3 fonts will be drawn with drawChar/drawString. + virtual GBool interpretType3Chars() { return gTrue; } + + //----- initialization and control + + // Start a page. + virtual void startPage(int pageNum, GfxState *state, XRef *xref); + + // End a page. + virtual void endPage(); + + //----- save/restore graphics state + virtual void saveState(GfxState *state); + virtual void restoreState(GfxState *state); + + //----- update graphics state + virtual void updateAll(GfxState *state); + virtual void updateCTM(GfxState *state, double m11, double m12, + double m21, double m22, double m31, double m32); + virtual void updateLineDash(GfxState *state); + virtual void updateFlatness(GfxState *state); + virtual void updateLineJoin(GfxState *state); + virtual void updateLineCap(GfxState *state); + virtual void updateMiterLimit(GfxState *state); + virtual void updateLineWidth(GfxState *state); + virtual void updateFillColor(GfxState *state); + virtual void updateStrokeColor(GfxState *state); + virtual void updateFillOpacity(GfxState *state); + virtual void updateStrokeOpacity(GfxState *state); + + //----- update text state + virtual void updateFont(GfxState *state); + + //----- path painting + virtual void stroke(GfxState *state); + virtual void fill(GfxState *state); + virtual void eoFill(GfxState *state); + + //----- path clipping + virtual void clip(GfxState *state); + virtual void eoClip(GfxState *state); + + //----- text drawing + // virtual void drawString(GfxState *state, GooString *s); + virtual void drawChar(GfxState *state, double x, double y, + double dx, double dy, + double originX, double originY, + CharCode code, int nBytes, Unicode *u, int uLen); + virtual GBool beginType3Char(GfxState *state, double x, double y, + double dx, double dy, + CharCode code, Unicode *u, int uLen); + virtual void endType3Char(GfxState *state); + virtual void endTextObject(GfxState *state); + + //----- image drawing + virtual void drawImageMask(GfxState *state, Object *ref, Stream *str, + int width, int height, GBool invert, + GBool interpolate, GBool inlineImg); + virtual void drawImage(GfxState *state, Object *ref, Stream *str, + int width, int height, GfxImageColorMap *colorMap, + GBool interpolate, int *maskColors, GBool inlineImg); + + //----- Type 3 font operators + virtual void type3D0(GfxState *state, double wx, double wy); + virtual void type3D1(GfxState *state, double wx, double wy, + double llx, double lly, double urx, double ury); + + //----- special access + + // Called to indicate that a new PDF document has been loaded. + void startDoc(XRef *xrefA); + + GBool isReverseVideo() { return gFalse; } + +private: + QPainter *m_painter; + FontHinting m_fontHinting; + QFont m_currentFont; + QPen m_currentPen; + QBrush m_currentBrush; + GBool m_needFontUpdate; // set when the font needs to be updated + SplashFontEngine *m_fontEngine; + SplashFont *m_font; // current font + XRef *xref; // xref table for current document +}; + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-annotation-helper.h b/dependencies/poppler/include/qt5/poppler-annotation-helper.h new file mode 100644 index 00000000..5f335c04 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-annotation-helper.h @@ -0,0 +1,198 @@ +/* poppler-annotation-helper.h: qt interface to poppler + * Copyright (C) 2006, 2008, Albert Astals Cid + * Copyright (C) 2008, Pino Toscano + * Copyright (C) 2012, Fabio D'Urso + * Adapting code from + * Copyright (C) 2004 by Enrico Ros + * + * 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, 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. + */ + +#include + +#include + +class QColor; + +class AnnotColor; + +namespace Poppler { + +class XPDFReader +{ + public: + // find named symbol and parse it + static inline void lookupName( Dict *, char *, QString & dest ); + static inline void lookupString( Dict *, char *, QString & dest ); + static inline void lookupBool( Dict *, char *, bool & dest ); + static inline void lookupInt( Dict *, char *, int & dest ); + static inline void lookupNum( Dict *, char *, double & dest ); + static inline int lookupNumArray( Dict *, char *, double * dest, int len ); + static inline void lookupColor( Dict *, char *, QColor & color ); + static inline void lookupIntRef( Dict *, char *, int & dest ); + static inline void lookupDate( Dict *, char *, QDateTime & dest ); + // transform from user coords to normalized ones using the matrix M + static inline void transform( double * M, double x, double y, QPointF &res ); + static inline void invTransform( double * M, const QPointF &p, double &x, double &y ); +}; + +void XPDFReader::lookupName( Dict * dict, char * type, QString & dest ) +{ + Object nameObj; + dict->lookup( type, &nameObj ); + if ( nameObj.isNull() ) + return; + if ( nameObj.isName() ) + dest = nameObj.getName(); + else + qDebug() << type << " is not Name." << endl; + nameObj.free(); +} + +void XPDFReader::lookupString( Dict * dict, char * type, QString & dest ) +{ + Object stringObj; + dict->lookup( type, &stringObj ); + if ( stringObj.isNull() ) + return; + if ( stringObj.isString() ) + dest = stringObj.getString()->getCString(); + else + qDebug() << type << " is not String." << endl; + stringObj.free(); +} + +void XPDFReader::lookupBool( Dict * dict, char * type, bool & dest ) +{ + Object boolObj; + dict->lookup( type, &boolObj ); + if ( boolObj.isNull() ) + return; + if ( boolObj.isBool() ) + dest = boolObj.getBool() == gTrue; + else + qDebug() << type << " is not Bool." << endl; + boolObj.free(); +} + +void XPDFReader::lookupInt( Dict * dict, char * type, int & dest ) +{ + Object intObj; + dict->lookup( type, &intObj ); + if ( intObj.isNull() ) + return; + if ( intObj.isInt() ) + dest = intObj.getInt(); + else + qDebug() << type << " is not Int." << endl; + intObj.free(); +} + +void XPDFReader::lookupNum( Dict * dict, char * type, double & dest ) +{ + Object numObj; + dict->lookup( type, &numObj ); + if ( numObj.isNull() ) + return; + if ( numObj.isNum() ) + dest = numObj.getNum(); + else + qDebug() << type << " is not Num." << endl; + numObj.free(); +} + +int XPDFReader::lookupNumArray( Dict * dict, char * type, double * dest, int len ) +{ + Object arrObj; + dict->lookup( type, &arrObj ); + if ( arrObj.isNull() ) + return 0; + Object numObj; + if ( arrObj.isArray() ) + { + len = qMin( len, arrObj.arrayGetLength() ); + for ( int i = 0; i < len; i++ ) + { + dest[i] = arrObj.arrayGet( i, &numObj )->getNum(); + numObj.free(); + } + } + else + { + len = 0; + qDebug() << type << "is not Array." << endl; + } + arrObj.free(); + return len; +} + +void XPDFReader::lookupColor( Dict * dict, char * type, QColor & dest ) +{ + double c[3]; + if ( XPDFReader::lookupNumArray( dict, type, c, 3 ) == 3 ) + dest = QColor( (int)(c[0]*255.0), (int)(c[1]*255.0), (int)(c[2]*255.0)); +} + +void XPDFReader::lookupIntRef( Dict * dict, char * type, int & dest ) +{ + Object refObj; + dict->lookupNF( type, &refObj ); + if ( refObj.isNull() ) + return; + if ( refObj.isRef() ) + dest = refObj.getRefNum(); + else + qDebug() << type << " is not Ref." << endl; + refObj.free(); +} + +void XPDFReader::lookupDate( Dict * dict, char * type, QDateTime & dest ) +{ + Object dateObj; + dict->lookup( type, &dateObj ); + if ( dateObj.isNull() ) + return; + if ( dateObj.isString() ) + { + dest = convertDate( dateObj.getString()->getCString() ); + } + else + qDebug() << type << " is not Date" << endl; + dateObj.free(); +} + +void XPDFReader::transform( double * M, double x, double y, QPointF &res ) +{ + res.setX( M[0] * x + M[2] * y + M[4] ); + res.setY( M[1] * x + M[3] * y + M[5] ); +} + +void XPDFReader::invTransform( double * M, const QPointF &p, double &x, double &y ) +{ + const double det = M[0]*M[3] - M[1]*M[2]; + Q_ASSERT(det != 0); + + const double invM[4] = { M[3]/det, -M[1]/det, -M[2]/det, M[0]/det }; + const double xt = p.x() - M[4]; + const double yt = p.y() - M[5]; + + x = invM[0] * xt + invM[2] * yt; + y = invM[1] * xt + invM[3] * yt; +} + +QColor convertAnnotColor( AnnotColor *color ); +AnnotColor* convertQColor( const QColor &color ); + +} diff --git a/dependencies/poppler/include/qt5/poppler-annotation-private.h b/dependencies/poppler/include/qt5/poppler-annotation-private.h new file mode 100644 index 00000000..c755eb35 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-annotation-private.h @@ -0,0 +1,112 @@ +/* poppler-annotation-private.h: qt interface to poppler + * Copyright (C) 2007, Pino Toscano + * Copyright (C) 2012, Tobias Koenig + * Copyright (C) 2012, 2013 Fabio D'Urso + * Copyright (C) 2012, Albert Astals Cid + * + * 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, 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. + */ + +#ifndef _POPPLER_ANNOTATION_PRIVATE_H_ +#define _POPPLER_ANNOTATION_PRIVATE_H_ + +#include +#include +#include + +#include "poppler-annotation.h" + +#include + +class Annot; +class AnnotPath; +class Link; +class Page; +class PDFRectangle; + +namespace Poppler +{ +class DocumentData; + +class AnnotationPrivate : public QSharedData +{ + public: + AnnotationPrivate(); + virtual ~AnnotationPrivate(); + + void addRevision(Annotation *ann, Annotation::RevScope scope, Annotation::RevType type); + + /* Returns an Annotation of the right subclass whose d_ptr points to + * this AnnotationPrivate */ + virtual Annotation * makeAlias() = 0; + + /* properties: contents related */ + QString author; + QString contents; + QString uniqueName; + QDateTime modDate; // before or equal to currentDateTime() + QDateTime creationDate; // before or equal to modifyDate + + /* properties: look/interaction related */ + int flags; + QRectF boundary; + + /* style and popup */ + Annotation::Style style; + Annotation::Popup popup; + + /* revisions */ + Annotation::RevScope revisionScope; + Annotation::RevType revisionType; + QList revisions; + + /* After this call, the Annotation object will behave like a wrapper for + * the specified Annot object. All cached values are discarded */ + void tieToNativeAnnot(Annot *ann, ::Page *page, DocumentData *doc); + + /* Creates a new Annot object on the specified page, flushes current + * values to that object and ties this Annotation to that object */ + virtual Annot* createNativeAnnot(::Page *destPage, DocumentData *doc) = 0; + + /* Inited to 0 (i.e. untied annotation) */ + Annot *pdfAnnot; + ::Page *pdfPage; + DocumentData * parentDoc; + + /* The following helpers only work if pdfPage is set */ + void flushBaseAnnotationProperties(); + void fillNormalizationMTX(double MTX[6], int pageRotation) const; + void fillTransformationMTX(double MTX[6]) const; + QRectF fromPdfRectangle(const PDFRectangle &r) const; + PDFRectangle boundaryToPdfRectangle(const QRectF &r, int flags) const; + AnnotPath * toAnnotPath(const QLinkedList &l) const; + + /* Scan page for annotations, parentId=0 searches for root annotations */ + static QList findAnnotations(::Page *pdfPage, DocumentData *doc, int parentId = 0); + + /* Add given annotation to given page */ + static void addAnnotationToPage(::Page *pdfPage, DocumentData *doc, const Annotation * ann); + + /* Remove annotation from page and destroy ann */ + static void removeAnnotationFromPage(::Page *pdfPage, const Annotation * ann); + + Ref pdfObjectReference() const; + + Link* additionalAction( Annotation::AdditionalActionType type ) const; +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-annotation.h b/dependencies/poppler/include/qt5/poppler-annotation.h new file mode 100644 index 00000000..bbcb9de0 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-annotation.h @@ -0,0 +1,1030 @@ +/* poppler-annotation.h: qt interface to poppler + * Copyright (C) 2006-2008, 2012, 2013 Albert Astals Cid + * Copyright (C) 2006, 2008 Pino Toscano + * Copyright (C) 2007, Brad Hards + * Copyright (C) 2010, Philip Lorenz + * Copyright (C) 2012, Tobias Koenig + * Copyright (C) 2012, Guillermo A. Amaral B. + * Copyright (C) 2012, 2013 Fabio D'Urso + * Copyright (C) 2013, Anthony Granger + * Adapting code from + * Copyright (C) 2004 by Enrico Ros + * + * 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, 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. + */ + +#ifndef _POPPLER_ANNOTATION_H_ +#define _POPPLER_ANNOTATION_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "poppler-export.h" + +namespace Poppler { + +class Annotation; +class AnnotationPrivate; +class TextAnnotationPrivate; +class LineAnnotationPrivate; +class GeomAnnotationPrivate; +class HighlightAnnotationPrivate; +class StampAnnotationPrivate; +class InkAnnotationPrivate; +class LinkAnnotationPrivate; +class CaretAnnotationPrivate; +class FileAttachmentAnnotationPrivate; +class SoundAnnotationPrivate; +class MovieAnnotationPrivate; +class ScreenAnnotationPrivate; +class WidgetAnnotationPrivate; +class EmbeddedFile; +class Link; +class SoundObject; +class MovieObject; +class LinkRendition; +class Page; + +/** + * \short Helper class for (recursive) Annotation retrieval/storage. + * + */ +class POPPLER_QT5_EXPORT AnnotationUtils +{ + public: + /** + * Restore an Annotation (with revisions if needed) from the DOM + * element \p annElement. + * \returns a pointer to the complete Annotation or 0 if element is + * invalid. + */ + static Annotation * createAnnotation( const QDomElement & annElement ); + + /** + * Save the Annotation \p ann as a child of \p annElement taking + * care of saving all revisions if \p ann has any. + */ + static void storeAnnotation( const Annotation * ann, + QDomElement & annElement, QDomDocument & document ); + + /** + * Returns an element called \p name from the direct children of + * \p parentNode or a null element if not found. + */ + static QDomElement findChildElement( const QDomNode & parentNode, + const QString & name ); +}; + + +/** + * \short Annotation class holding properties shared by all annotations. + * + * An Annotation is an object (text note, highlight, sound, popup window, ..) + * contained by a Page in the document. + * + * \warning Different Annotation objects might point to the same annotation. + * + * \section annotCreation How to add annotations + * + * Create an Annotation object of the desired subclass (for example + * TextAnnotation) and set its properties: + * @code + * Poppler::TextAnnotation* myann = new Poppler::TextAnnotation(Poppler::TextAnnotation::InPlace); + * myann->setBoundary(QRectF(0.1, 0.1, 0.2, 0.2)); // normalized coordinates: (0,0) is top-left, (1,1) is bottom-right + * myann->setContents("Hello, world!"); + * @endcode + * \note Always set a boundary rectangle, or nothing will be shown! + * + * Obtain a pointer to the Page where you want to add the annotation (refer to + * \ref req for instructions) and add the annotation: + * @code + * Poppler::Page* mypage = ...; + * mypage->addAnnotation(myann); + * @endcode + * + * You can keep on editing the annotation after it has been added to the page: + * @code + * myann->setContents("World, hello!"); // Let's change text... + * myann->setAuthor("Your name here"); // ...and set an author too + * @endcode + * + * When you're done with editing the annotation, you must destroy the Annotation + * object: + * @code + * delete myann; + * @endcode + * + * Use the PDFConverter class to save the modified document. + * + * \section annotFixedRotation FixedRotation flag specifics + * + * According to the PDF specification, annotations whose + * Annotation::FixedRotation flag is set must always be shown in their original + * orientation, no matter what the current rendering rotation or the page's + * Page::orientation() values are. In comparison with regular annotations, such + * annotations should therefore be transformed by an extra rotation at rendering + * time to "undo" such context-related rotations, which is equal to + * -(rendering_rotation + page_orientation). The rotation pivot + * is the top-left corner of the boundary rectangle. + * + * In practice, %Poppler's \ref Page::renderToImage only "unrotates" the + * page orientation, and does not unrotate the rendering rotation. + * This ensures consistent renderings at different Page::Rotation values: + * annotations are always positioned as if they were being positioned at the + * default page orientation. + * + * Just like regular annotations, %Poppler Qt4 exposes normalized coordinates + * relative to the page's default orientation. However, behind the scenes, the + * coordinate system is different and %Poppler transparently transforms each + * shape. If you never call either Annotation::setFlags or + * Annotation::setBoundary, you don't need to worry about this; but if you do + * call them, then you need to adhere to the following rules: + * - Whenever you toggle the Annotation::FixedRotation flag, you must + * set again the boundary rectangle first, and then you must set + * again any other geometry-related property. + * - Whenever you modify the boundary rectangle of an annotation whose + * Annotation::FixedRotation flag is set, you must set again any other + * geometry-related property. + * + * These two rules are necessary to make %Poppler's transparent coordinate + * conversion work properly. + */ +class POPPLER_QT5_EXPORT Annotation +{ + friend class AnnotationUtils; + friend class LinkMovie; + friend class LinkRendition; + + public: + // enum definitions + /** + * Annotation subclasses + * + * \sa subType() + */ + // WARNING!!! oKular uses that very same values so if you change them notify the author! + enum SubType + { + AText = 1, ///< TextAnnotation + ALine = 2, ///< LineAnnotation + AGeom = 3, ///< GeomAnnotation + AHighlight = 4, ///< HighlightAnnotation + AStamp = 5, ///< StampAnnotation + AInk = 6, ///< InkAnnotation + ALink = 7, ///< LinkAnnotation + ACaret = 8, ///< CaretAnnotation + AFileAttachment = 9, ///< FileAttachmentAnnotation + ASound = 10, ///< SoundAnnotation + AMovie = 11, ///< MovieAnnotation + AScreen = 12, ///< ScreenAnnotation \since 0.20 + AWidget = 13, ///< WidgetAnnotation \since 0.22 + A_BASE = 0 + }; + + /** + * Annotation flags + * + * They can be OR'd together (e.g. Annotation::FixedRotation | Annotation::DenyPrint). + * + * \sa flags(), setFlags(int) + */ + // NOTE: Only flags that are known to work are documented + enum Flag + { + Hidden = 1, ///< Do not display or print the annotation + FixedSize = 2, + FixedRotation = 4, ///< Do not rotate the annotation according to page orientation and rendering rotation \warning Extra care is needed with this flag: see \ref annotFixedRotation + DenyPrint = 8, ///< Do not print the annotation + DenyWrite = 16, + DenyDelete = 32, + ToggleHidingOnMouse = 64, + External = 128 + }; + + enum LineStyle { Solid = 1, Dashed = 2, Beveled = 4, Inset = 8, Underline = 16 }; + enum LineEffect { NoEffect = 1, Cloudy = 2}; + enum RevScope { Root = 0 /** \since 0.20 */, Reply = 1, Group = 2, Delete = 4 }; + enum RevType { None = 1, Marked = 2, Unmarked = 4, Accepted = 8, Rejected = 16, Cancelled = 32, Completed = 64 }; + + /** + * Returns the author of the annotation. + */ + QString author() const; + /** + * Sets a new author for the annotation. + */ + void setAuthor( const QString &author ); + + QString contents() const; + void setContents( const QString &contents ); + + /** + * Returns the unique name (ID) of the annotation. + */ + QString uniqueName() const; + /** + * Sets a new unique name for the annotation. + * + * \note no check of the new uniqueName is done + */ + void setUniqueName( const QString &uniqueName ); + + QDateTime modificationDate() const; + void setModificationDate( const QDateTime &date ); + + QDateTime creationDate() const; + void setCreationDate( const QDateTime &date ); + + /** + * Returns this annotation's flags + * + * \sa Flag, setFlags(int) + */ + int flags() const; + /** + * Sets this annotation's flags + * + * \sa Flag, flags(), \ref annotFixedRotation + */ + void setFlags( int flags ); + + /** + * Returns this annotation's boundary rectangle in normalized coordinates + * + * \sa setBoundary(const QRectF&) + */ + QRectF boundary() const; + /** + * Sets this annotation's boundary rectangle + * + * The boundary rectangle is the smallest rectangle that contains the + * annotation. + * + * \warning This property is mandatory: you must always set this. + * + * \sa boundary(), \ref annotFixedRotation + */ + void setBoundary( const QRectF &boundary ); + + /** + * \short Container class for Annotation style information + * + * \since 0.20 + */ + class POPPLER_QT5_EXPORT Style + { + public: + Style(); + Style( const Style &other ); + Style& operator=( const Style &other ); + ~Style(); + + // appearance properties + QColor color() const; // black + void setColor(const QColor &color); + double opacity() const; // 1.0 + void setOpacity(double opacity); + + // pen properties + double width() const; // 1.0 + void setWidth(double width); + LineStyle lineStyle() const; // LineStyle::Solid + void setLineStyle(LineStyle style); + double xCorners() const; // 0.0 + void setXCorners(double radius); + double yCorners() const; // 0.0 + void setYCorners(double radius); + const QVector& dashArray() const; // [ 3 ] + void setDashArray(const QVector &array); + + // pen effects + LineEffect lineEffect() const; // LineEffect::NoEffect + void setLineEffect(LineEffect effect); + double effectIntensity() const; // 1.0 + void setEffectIntensity(double intens); + + private: + class Private; + QSharedDataPointer d; + }; + + /// \since 0.20 + Style style() const; + /// \since 0.20 + void setStyle( const Style& style ); + + /** + * \short Container class for Annotation pop-up window information + * + * \since 0.20 + */ + class POPPLER_QT5_EXPORT Popup + { + public: + Popup(); + Popup( const Popup &other ); + Popup& operator=( const Popup &other ); + ~Popup(); + + // window state (Hidden, FixedRotation, Deny* flags allowed) + int flags() const; // -1 (never initialized) -> 0 (if inited and shown) + void setFlags( int flags ); + + // geometric properties + QRectF geometry() const; // no default + void setGeometry( const QRectF &geom ); + + // window contens/override properties + QString title() const; // '' text in the titlebar (overrides author) + void setTitle( const QString &title ); + QString summary() const; // '' short description (displayed if not empty) + void setSummary( const QString &summary ); + QString text() const; // '' text for the window (overrides annot->contents) + void setText( const QString &text ); + + private: + class Private; + QSharedDataPointer d; + }; + + /// \since 0.20 + Popup popup() const; + /// \warning Currently does nothing \since 0.20 + void setPopup( const Popup& popup ); + + /// \since 0.20 + RevScope revisionScope() const; // Root + + /// \since 0.20 + RevType revisionType() const; // None + + /** + * Returns the revisions of this annotation + * + * \note The caller owns the returned annotations and they should + * be deleted when no longer required. + * + * \since 0.20 + */ + QList revisions() const; + + /** + * The type of the annotation. + */ + virtual SubType subType() const = 0; + + /** + * Destructor. + */ + virtual ~Annotation(); + + /** + * Describes the flags from an annotations 'AA' dictionary. + * + * This flag is used by the additionalAction() method for ScreenAnnotation + * and WidgetAnnotation. + * + * \since 0.22 + */ + enum AdditionalActionType + { + CursorEnteringAction, ///< Performed when the cursor enters the annotation's active area + CursorLeavingAction, ///< Performed when the cursor exists the annotation's active area + MousePressedAction, ///< Performed when the mouse button is pressed inside the annotation's active area + MouseReleasedAction, ///< Performed when the mouse button is released inside the annotation's active area + FocusInAction, ///< Performed when the annotation receives the input focus + FocusOutAction, ///< Performed when the annotation loses the input focus + PageOpeningAction, ///< Performed when the page containing the annotation is opened + PageClosingAction, ///< Performed when the page containing the annotation is closed + PageVisibleAction, ///< Performed when the page containing the annotation becomes visible + PageInvisibleAction ///< Performed when the page containing the annotation becomes invisible + }; + + protected: + /// \cond PRIVATE + Annotation( AnnotationPrivate &dd ); + Annotation( AnnotationPrivate &dd, const QDomNode &description ); + void storeBaseAnnotationProperties( QDomNode & parentNode, QDomDocument & document ) const; + Q_DECLARE_PRIVATE( Annotation ) + QExplicitlySharedDataPointer d_ptr; + /// \endcond + + private: + virtual void store( QDomNode & parentNode, QDomDocument & document ) const = 0; + Q_DISABLE_COPY( Annotation ) +}; + +/** + * \short Annotation containing text. + * + * A text annotation is an object showing some text directly on the page, or + * linked to the contents using an icon shown on a page. + */ +class POPPLER_QT5_EXPORT TextAnnotation : public Annotation +{ + friend class AnnotationUtils; + friend class AnnotationPrivate; + + public: + // local enums + enum TextType { Linked, InPlace }; + enum InplaceIntent { Unknown, Callout, TypeWriter }; + + TextAnnotation( TextType type ); + virtual ~TextAnnotation(); + virtual SubType subType() const; + + /** + The type of text annotation represented by this object + */ + TextType textType() const; + + /** + The name of the icon for this text annotation. + + Standard names for text annotation icons are: + - Comment + - Help + - Insert + - Key + - NewParagraph + - Note (this is the default icon to use) + - Paragraph + */ + QString textIcon() const; + + /** + Set the name of the icon to use for this text annotation. + + \sa textIcon for the list of standard names + */ + void setTextIcon( const QString &icon ); + + QFont textFont() const; + void setTextFont( const QFont &font ); + + int inplaceAlign() const; + void setInplaceAlign( int align ); + + QPointF calloutPoint( int id ) const; + /// \since 0.20 + QVector calloutPoints() const; + /// \since 0.20 + void setCalloutPoints( const QVector &points ); + + InplaceIntent inplaceIntent() const; + void setInplaceIntent( InplaceIntent intent ); + + private: + TextAnnotation( const QDomNode &node ); + TextAnnotation( TextAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + void setTextType( TextType type ); + Q_DECLARE_PRIVATE( TextAnnotation ) + Q_DISABLE_COPY( TextAnnotation ) +}; + +/** + * \short Polygon/polyline annotation. + * + * This annotation represents a polygon (or polyline) to be drawn on a page. + */ +class POPPLER_QT5_EXPORT LineAnnotation : public Annotation +{ + friend class AnnotationUtils; + friend class AnnotationPrivate; + + public: + // local enums + /// \since 0.20 + enum LineType { StraightLine, Polyline }; + enum TermStyle { Square, Circle, Diamond, OpenArrow, ClosedArrow, None, + Butt, ROpenArrow, RClosedArrow, Slash }; + enum LineIntent { Unknown, Arrow, Dimension, PolygonCloud }; + + /// \since 0.20 + LineAnnotation( LineType type ); + virtual ~LineAnnotation(); + virtual SubType subType() const; + + /// \since 0.20 + LineType lineType() const; + + QLinkedList linePoints() const; + void setLinePoints( const QLinkedList &points ); + + TermStyle lineStartStyle() const; + void setLineStartStyle( TermStyle style ); + + TermStyle lineEndStyle() const; + void setLineEndStyle( TermStyle style ); + + bool isLineClosed() const; + void setLineClosed( bool closed ); + + QColor lineInnerColor() const; + void setLineInnerColor( const QColor &color ); + + double lineLeadingForwardPoint() const; + void setLineLeadingForwardPoint( double point ); + + double lineLeadingBackPoint() const; + void setLineLeadingBackPoint( double point ); + + bool lineShowCaption() const; + void setLineShowCaption( bool show ); + + LineIntent lineIntent() const; + void setLineIntent( LineIntent intent ); + + private: + LineAnnotation( const QDomNode &node ); + LineAnnotation( LineAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + void setLineType( LineType type ); + Q_DECLARE_PRIVATE( LineAnnotation ) + Q_DISABLE_COPY( LineAnnotation ) +}; + +/** + * \short Geometric annotation. + * + * The geometric annotation represents a geometric figure, like a rectangle or + * an ellipse. + */ +class POPPLER_QT5_EXPORT GeomAnnotation : public Annotation +{ + friend class AnnotationUtils; + friend class AnnotationPrivate; + + public: + GeomAnnotation(); + virtual ~GeomAnnotation(); + virtual SubType subType() const; + + // common enums + enum GeomType { InscribedSquare, InscribedCircle }; + + GeomType geomType() const; + void setGeomType( GeomType style ); + + QColor geomInnerColor() const; + void setGeomInnerColor( const QColor &color ); + + private: + GeomAnnotation( const QDomNode &node ); + GeomAnnotation( GeomAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + Q_DECLARE_PRIVATE( GeomAnnotation ) + Q_DISABLE_COPY( GeomAnnotation ) +}; + +/** + * \short Text highlight annotation. + * + * The higlight annotation represents some areas of text being "highlighted". + */ +class POPPLER_QT5_EXPORT HighlightAnnotation : public Annotation +{ + friend class AnnotationUtils; + friend class AnnotationPrivate; + + public: + HighlightAnnotation(); + virtual ~HighlightAnnotation(); + virtual SubType subType() const; + + /** + The type of highlight + */ + enum HighlightType { Highlight, ///< highlighter pen style annotation + Squiggly, ///< jagged or squiggly underline + Underline, ///< straight line underline + StrikeOut ///< straight line through-line + }; + + /** + Structure corresponding to a QuadPoints array. This matches a + quadrilateral that describes the area around a word (or set of + words) that are to be highlighted. + */ + struct Quad + { + QPointF points[4]; // 8 valid coords + bool capStart; // false (vtx 1-4) [K] + bool capEnd; // false (vtx 2-3) [K] + double feather; // 0.1 (in range 0..1) [K] + }; + + /** + The type (style) of highlighting to use for this area + or these areas. + */ + HighlightType highlightType() const; + + /** + Set the type of highlighting to use for the given area + or areas. + */ + void setHighlightType( HighlightType type ); + + /** + The list of areas to highlight. + */ + QList< Quad > highlightQuads() const; + + /** + Set the areas to highlight. + */ + void setHighlightQuads( const QList< Quad > &quads ); + + private: + HighlightAnnotation( const QDomNode &node ); + HighlightAnnotation( HighlightAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + Q_DECLARE_PRIVATE( HighlightAnnotation ) + Q_DISABLE_COPY( HighlightAnnotation ) +}; + +/** + * \short Stamp annotation. + * + * A simple annotation drawing a stamp on a page. + */ +class POPPLER_QT5_EXPORT StampAnnotation : public Annotation +{ + friend class AnnotationUtils; + friend class AnnotationPrivate; + + public: + StampAnnotation(); + virtual ~StampAnnotation(); + virtual SubType subType() const; + + /** + The name of the icon for this stamp annotation. + + Standard names for stamp annotation icons are: + - Approved + - AsIs + - Confidential + - Departmental + - Draft (this is the default icon type) + - Experimental + - Expired + - Final + - ForComment + - ForPublicRelease + - NotApproved + - NotForPublicRelease + - Sold + - TopSecret + */ + QString stampIconName() const; + + /** + Set the icon type for this stamp annotation. + + \sa stampIconName for the list of standard icon names + */ + void setStampIconName( const QString &name ); + + private: + StampAnnotation( const QDomNode &node ); + StampAnnotation( StampAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + Q_DECLARE_PRIVATE( StampAnnotation ) + Q_DISABLE_COPY( StampAnnotation ) +}; + +/** + * \short Ink Annotation. + * + * Annotation representing an ink path on a page. + */ +class POPPLER_QT5_EXPORT InkAnnotation : public Annotation +{ + friend class AnnotationUtils; + friend class AnnotationPrivate; + + public: + InkAnnotation(); + virtual ~InkAnnotation(); + virtual SubType subType() const; + + QList< QLinkedList > inkPaths() const; + void setInkPaths( const QList< QLinkedList > &paths ); + + private: + InkAnnotation( const QDomNode &node ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + InkAnnotation(InkAnnotationPrivate &dd); + Q_DECLARE_PRIVATE( InkAnnotation ) + Q_DISABLE_COPY( InkAnnotation ) +}; + +class POPPLER_QT5_EXPORT LinkAnnotation : public Annotation +{ + friend class AnnotationUtils; + friend class AnnotationPrivate; + + public: + virtual ~LinkAnnotation(); + virtual SubType subType() const; + + // local enums + enum HighlightMode { None, Invert, Outline, Push }; + + /** \since 0.20 */ + Link* linkDestination() const; + void setLinkDestination( Link *link ); + + HighlightMode linkHighlightMode() const; + void setLinkHighlightMode( HighlightMode mode ); + + QPointF linkRegionPoint( int id ) const; + void setLinkRegionPoint( int id, const QPointF &point ); + + private: + LinkAnnotation(); + LinkAnnotation( const QDomNode &node ); + LinkAnnotation( LinkAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + Q_DECLARE_PRIVATE( LinkAnnotation ) + Q_DISABLE_COPY( LinkAnnotation ) +}; + +/** + * \short Caret annotation. + * + * The caret annotation represents a symbol to indicate the presence of text. + */ +class POPPLER_QT5_EXPORT CaretAnnotation : public Annotation +{ + friend class AnnotationUtils; + friend class AnnotationPrivate; + + public: + CaretAnnotation(); + virtual ~CaretAnnotation(); + virtual SubType subType() const; + + /** + * The symbols for the caret annotation. + */ + enum CaretSymbol { None, P }; + + CaretSymbol caretSymbol() const; + void setCaretSymbol( CaretSymbol symbol ); + + private: + CaretAnnotation( const QDomNode &node ); + CaretAnnotation( CaretAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + Q_DECLARE_PRIVATE( CaretAnnotation ) + Q_DISABLE_COPY( CaretAnnotation ) +}; + +/** + * \short File attachment annotation. + * + * The file attachment annotation represents a file embedded in the document. + * + * \since 0.10 + */ +class POPPLER_QT5_EXPORT FileAttachmentAnnotation : public Annotation +{ + friend class AnnotationPrivate; + + public: + virtual ~FileAttachmentAnnotation(); + virtual SubType subType() const; + + /** + * Returns the name of the icon of this annotation. + */ + QString fileIconName() const; + /** + * Sets a new name for the icon of this annotation. + */ + void setFileIconName( const QString &icon ); + + /** + * Returns the EmbeddedFile of this annotation. + */ + EmbeddedFile* embeddedFile() const; + /** + * Sets a new EmbeddedFile for this annotation. + * + * \note FileAttachmentAnnotation takes ownership of the object + */ + void setEmbeddedFile( EmbeddedFile *ef ); + + private: + FileAttachmentAnnotation(); + FileAttachmentAnnotation( const QDomNode &node ); + FileAttachmentAnnotation( FileAttachmentAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + Q_DECLARE_PRIVATE( FileAttachmentAnnotation ) + Q_DISABLE_COPY( FileAttachmentAnnotation ) +}; + +/** + * \short Sound annotation. + * + * The sound annotation represents a sound to be played when activated. + * + * \since 0.10 + */ +class POPPLER_QT5_EXPORT SoundAnnotation : public Annotation +{ + friend class AnnotationPrivate; + + public: + virtual ~SoundAnnotation(); + virtual SubType subType() const; + + /** + * Returns the name of the icon of this annotation. + */ + QString soundIconName() const; + /** + * Sets a new name for the icon of this annotation. + */ + void setSoundIconName( const QString &icon ); + + /** + * Returns the SoundObject of this annotation. + */ + SoundObject* sound() const; + /** + * Sets a new SoundObject for this annotation. + * + * \note SoundAnnotation takes ownership of the object + */ + void setSound( SoundObject *ef ); + + private: + SoundAnnotation(); + SoundAnnotation( const QDomNode &node ); + SoundAnnotation( SoundAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + Q_DECLARE_PRIVATE( SoundAnnotation ) + Q_DISABLE_COPY( SoundAnnotation ) +}; + +/** + * \short Movie annotation. + * + * The movie annotation represents a movie to be played when activated. + * + * \since 0.10 + */ +class POPPLER_QT5_EXPORT MovieAnnotation : public Annotation +{ + friend class AnnotationPrivate; + + public: + virtual ~MovieAnnotation(); + virtual SubType subType() const; + + /** + * Returns the MovieObject of this annotation. + */ + MovieObject* movie() const; + /** + * Sets a new MovieObject for this annotation. + * + * \note MovieAnnotation takes ownership of the object + */ + void setMovie( MovieObject *movie ); + + /** + * Returns the title of the movie of this annotation. + */ + QString movieTitle() const; + /** + * Sets a new title for the movie of this annotation. + */ + void setMovieTitle( const QString &title ); + + private: + MovieAnnotation(); + MovieAnnotation( const QDomNode &node ); + MovieAnnotation( MovieAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; + Q_DECLARE_PRIVATE( MovieAnnotation ) + Q_DISABLE_COPY( MovieAnnotation ) +}; + +/** + * \short Screen annotation. + * + * The screen annotation represents a screen to be played when activated. + * + * \since 0.20 + */ +class POPPLER_QT5_EXPORT ScreenAnnotation : public Annotation +{ + friend class AnnotationPrivate; + + public: + virtual ~ScreenAnnotation(); + + virtual SubType subType() const; + + /** + * Returns the LinkRendition of this annotation. + */ + LinkRendition* action() const; + + /** + * Sets a new LinkRendition for this annotation. + * + * \note ScreenAnnotation takes ownership of the object + */ + void setAction( LinkRendition *action ); + + /** + * Returns the title of the screen of this annotation. + */ + QString screenTitle() const; + + /** + * Sets a new title for the screen of this annotation. + */ + void setScreenTitle( const QString &title ); + + /** + * Returns the additional action of the given @p type fo the annotation or + * @c 0 if no action has been defined. + * + * \since 0.22 + */ + Link* additionalAction( AdditionalActionType type ) const; + + private: + ScreenAnnotation(); + ScreenAnnotation( ScreenAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; // stub + Q_DECLARE_PRIVATE( ScreenAnnotation ) + Q_DISABLE_COPY( ScreenAnnotation ) +}; + +/** + * \short Widget annotation. + * + * The widget annotation represents a widget (form field) on a page. + * + * \note This class is just provided for consistency of the annotation API, + * use the FormField classes to get all the form-related information. + * + * \since 0.22 + */ +class POPPLER_QT5_EXPORT WidgetAnnotation : public Annotation +{ + friend class AnnotationPrivate; + + public: + virtual ~WidgetAnnotation(); + + virtual SubType subType() const; + + /** + * Returns the additional action of the given @p type fo the annotation or + * @c 0 if no action has been defined. + * + * \since 0.22 + */ + Link* additionalAction( AdditionalActionType type ) const; + + private: + WidgetAnnotation(); + WidgetAnnotation( WidgetAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; // stub + Q_DECLARE_PRIVATE( WidgetAnnotation ) + Q_DISABLE_COPY( WidgetAnnotation ) +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-converter-private.h b/dependencies/poppler/include/qt5/poppler-converter-private.h new file mode 100644 index 00000000..1340d354 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-converter-private.h @@ -0,0 +1,49 @@ +/* poppler-converter-private.h: Qt interface to poppler + * Copyright (C) 2007, 2009, Albert Astals Cid + * Copyright (C) 2008, Pino Toscano + * + * 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, 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. + */ + +#ifndef POPPLER_QT5_CONVERTER_PRIVATE_H +#define POPPLER_QT5_CONVERTER_PRIVATE_H + +#include + +class QIODevice; + +namespace Poppler { + +class DocumentData; + +class BaseConverterPrivate +{ + public: + BaseConverterPrivate(); + virtual ~BaseConverterPrivate(); + + QIODevice* openDevice(); + void closeDevice(); + + DocumentData *document; + QString outputFileName; + QIODevice *iodev; + bool ownIodev : 1; + BaseConverter::Error lastError; +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-embeddedfile-private.h b/dependencies/poppler/include/qt5/poppler-embeddedfile-private.h new file mode 100644 index 00000000..ff1388ec --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-embeddedfile-private.h @@ -0,0 +1,42 @@ +/* poppler-embeddedfile-private.h: Qt interface to poppler + * Copyright (C) 2005, 2008, 2009, 2012, Albert Astals Cid + * Copyright (C) 2005, Brad Hards + * Copyright (C) 2008, 2011, Pino Toscano + * + * 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, 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. + */ + +#ifndef POPPLER_EMBEDDEDFILE_PRIVATE_H +#define POPPLER_EMBEDDEDFILE_PRIVATE_H + +class FileSpec; + +namespace Poppler +{ + +class EmbeddedFileData +{ +public: + EmbeddedFileData(FileSpec *fs); + ~EmbeddedFileData(); + + EmbFile *embFile() const; + + FileSpec *filespec; +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-export.h b/dependencies/poppler/include/qt5/poppler-export.h new file mode 100644 index 00000000..fdce95c7 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-export.h @@ -0,0 +1,17 @@ +/* +* This file is used to set the poppler_qt5_EXPORT macros right. +* This is needed for setting the visibility on windows, it will have no effect on other platforms. +*/ +#if defined(_WIN32) +# define LIB_EXPORT __declspec(dllexport) +# define LIB_IMPORT __declspec(dllimport) +#else +# define LIB_EXPORT +# define LIB_IMPORT +#endif + +#ifdef poppler_qt5_EXPORTS +# define POPPLER_QT5_EXPORT LIB_EXPORT +#else +# define POPPLER_QT5_EXPORT LIB_IMPORT +#endif diff --git a/dependencies/poppler/include/qt5/poppler-form.h b/dependencies/poppler/include/qt5/poppler-form.h new file mode 100644 index 00000000..3481ce7b --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-form.h @@ -0,0 +1,343 @@ +/* poppler-form.h: qt interface to poppler + * Copyright (C) 2007-2008, Pino Toscano + * Copyright (C) 2008, 2011, Albert Astals Cid + * Copyright (C) 2012, Adam Reichold + * + * 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, 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. + */ + +#ifndef _POPPLER_QT5_FORM_H_ +#define _POPPLER_QT5_FORM_H_ + +#include +#include +#include "poppler-export.h" + +class Page; +class FormWidget; +class FormWidgetButton; +class FormWidgetText; +class FormWidgetChoice; + +namespace Poppler { + + class DocumentData; + class Link; + + class FormFieldData; + /** + The base class representing a form field. + + \since 0.6 + */ + class POPPLER_QT5_EXPORT FormField { + public: + + /** + The different types of form field. + */ + enum FormType { + FormButton, ///< A button field. See \ref Poppler::FormFieldButton::ButtonType "ButtonType" + FormText, ///< A text field. See \ref Poppler::FormFieldText::TextType "TextType" + FormChoice, ///< A single choice field. See \ref Poppler::FormFieldChoice::ChoiceType "ChoiceType" + FormSignature ///< A signature field. + }; + + virtual ~FormField(); + + /** + The type of the field. + */ + virtual FormType type() const = 0; + + /** + \return The size of the field, in normalized coordinates, i.e. + [0..1] with regard to the dimensions (cropbox) of the page + */ + QRectF rect() const; + + /** + The ID of the field. + */ + int id() const; + + /** + The internal name of the field. + */ + QString name() const; + + /** + The internal fully qualified name of the field. + \since 0.18 + */ + QString fullyQualifiedName() const; + + /** + The name of the field to be used in user interface (eg messages to + the user). + */ + QString uiName() const; + + /** + Whether this form field is read-only. + */ + bool isReadOnly() const; + + /** + Whether this form field is visible. + */ + bool isVisible() const; + + /** + The activation action of this form field. + + \note It may be null. + */ + Link* activationAction() const; + + protected: + /// \cond PRIVATE + FormField(FormFieldData &dd); + + FormFieldData *m_formData; + /// \endcond + + private: + Q_DISABLE_COPY(FormField) + }; + + /** + A form field that represents a "button". + + \since 0.8 + */ + class POPPLER_QT5_EXPORT FormFieldButton : public FormField { + public: + + /** + * The types of button field. + */ + enum ButtonType + { + Push, ///< A simple push button. + CheckBox, ///< A check box. + Radio ///< A radio button. + }; + + /// \cond PRIVATE + FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w); + /// \endcond + virtual ~FormFieldButton(); + + virtual FormType type() const; + + /** + The particular type of the button field. + */ + ButtonType buttonType() const; + + /** + * The caption to be used for the button. + */ + QString caption() const; + + /** + The state of the button. + */ + bool state() const; + + /** + Sets the state of the button to the new \p state . + */ + void setState( bool state ); + + /** + The list with the IDs of siblings (ie, buttons belonging to the same + group as the current one. + + Valid only for \ref Radio buttons, an empty list otherwise. + */ + QList siblings() const; + + private: + Q_DISABLE_COPY(FormFieldButton) + }; + + /** + A form field that represents a text input. + + \since 0.6 + */ + class POPPLER_QT5_EXPORT FormFieldText : public FormField { + public: + + /** + The particular type of this text field. + */ + enum TextType { + Normal, ///< A simple singleline text field. + Multiline, ///< A multiline text field. + FileSelect ///< An input field to select the path of a file on disk. + }; + + /// \cond PRIVATE + FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w); + /// \endcond + virtual ~FormFieldText(); + + virtual FormType type() const; + + /** + The text type of the text field. + */ + TextType textType() const; + + /** + The text associated with the text field. + */ + QString text() const; + + /** + Sets the text associated with the text field to the specified + \p text. + */ + void setText( const QString& text ); + + /** + Whether this text field is a password input, eg its text \b must be + replaced with asterisks. + + Always false for \ref FileSelect text fields. + */ + bool isPassword() const; + + /** + Whether this text field should allow rich text. + */ + bool isRichText() const; + + /** + The maximum length for the text of this field, or -1 if not set. + */ + int maximumLength() const; + + /** + The horizontal alignment for the text of this text field. + */ + Qt::Alignment textAlignment() const; + + /** + Whether the text inserted manually in the field (where possible) + can be spell-checked. + */ + bool canBeSpellChecked() const; + + private: + Q_DISABLE_COPY(FormFieldText) + }; + + /** + A form field that represents a choice field. + + \since 0.6 + */ + class POPPLER_QT5_EXPORT FormFieldChoice : public FormField { + public: + + /** + The particular type of this choice field. + */ + enum ChoiceType { + ComboBox, ///< A simple singleline text field. + ListBox ///< A multiline text field. + }; + + /// \cond PRIVATE + FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w); + /// \endcond + virtual ~FormFieldChoice(); + + virtual FormType type() const; + + /** + The choice type of the choice field. + */ + ChoiceType choiceType() const; + + /** + The possible choices of the choice field. + */ + QStringList choices() const; + + /** + Whether this FormFieldChoice::ComboBox is editable, i.e. the user + can type in a custom value. + + Always false for the other types of choices. + */ + bool isEditable() const; + + /** + Whether more than one choice of this FormFieldChoice::ListBox + can be selected at the same time. + + Always false for the other types of choices. + */ + bool multiSelect() const; + + /** + The currently selected choices. + */ + QList currentChoices() const; + + /** + Sets the selected choices to \p choice. + */ + void setCurrentChoices( const QList &choice ); + + /** + The text entered into an editable combo box choice field. Otherwise a null string. + + \since 0.22 + */ + QString editChoice() const; + + /** + Sets the text entered into an editable combo box choice field. Otherwise does nothing. + + \since 0.22 + */ + void setEditChoice(const QString& text); + + /** + The horizontal alignment for the text of this text field. + */ + Qt::Alignment textAlignment() const; + + /** + Whether the text inserted manually in the field (where possible) + can be spell-checked. + + Returns false if the field is not an editable text field. + */ + bool canBeSpellChecked() const; + + private: + Q_DISABLE_COPY(FormFieldChoice) + }; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-link-extractor-private.h b/dependencies/poppler/include/qt5/poppler-link-extractor-private.h new file mode 100644 index 00000000..32ddd038 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-link-extractor-private.h @@ -0,0 +1,57 @@ +/* poppler-link-extractor_p.h: qt interface to poppler + * Copyright (C) 2007, 2008, 2011, Pino Toscano + * + * 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, 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. + */ + +#ifndef _POPPLER_LINK_EXTRACTOR_H_ +#define _POPPLER_LINK_EXTRACTOR_H_ + +#include +#include + +#include + +namespace Poppler +{ + +class Link; +class PageData; + +class LinkExtractorOutputDev : public OutputDev +{ + public: + LinkExtractorOutputDev(PageData *data); + virtual ~LinkExtractorOutputDev(); + + // inherited from OutputDev + virtual GBool upsideDown() { return gFalse; } + virtual GBool useDrawChar() { return gFalse; } + virtual GBool interpretType3Chars() { return gFalse; } + virtual void processLink(::AnnotLink *link); + + // our stuff + QList< Link* > links(); + + private: + PageData *m_data; + double m_pageCropWidth; + double m_pageCropHeight; + QList< Link* > m_links; +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-link.h b/dependencies/poppler/include/qt5/poppler-link.h new file mode 100644 index 00000000..172effa2 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-link.h @@ -0,0 +1,602 @@ +/* poppler-link.h: qt interface to poppler + * Copyright (C) 2006, 2013, Albert Astals Cid + * Copyright (C) 2007-2008, 2010, Pino Toscano + * Copyright (C) 2010, 2012, Guillermo Amaral + * Copyright (C) 2012, Tobias Koenig + * Copyright (C) 2013, Anthony Granger + * Adapting code from + * Copyright (C) 2004 by Enrico Ros + * + * 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, 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. + */ + +#ifndef _POPPLER_LINK_H_ +#define _POPPLER_LINK_H_ + +#include +#include +#include +#include "poppler-export.h" + +struct Ref; +class MediaRendition; + +namespace Poppler { + +class LinkPrivate; +class LinkGotoPrivate; +class LinkExecutePrivate; +class LinkBrowsePrivate; +class LinkActionPrivate; +class LinkSoundPrivate; +class LinkJavaScriptPrivate; +class LinkMoviePrivate; +class LinkDestinationData; +class LinkDestinationPrivate; +class LinkRenditionPrivate; +class MediaRendition; +class SoundObject; + +/** + * \short A destination. + * + * The LinkDestination class represent a "destination" (in terms of visual + * viewport to be displayed) for \link Poppler::LinkGoto GoTo\endlink links, + * and items in the table of contents (TOC) of a document. + * + * Coordinates are in 0..1 range + */ +class POPPLER_QT5_EXPORT LinkDestination +{ + public: + /** + * The possible kind of "viewport destination". + */ + enum Kind + { + /** + * The new viewport is specified in terms of: + * - possibile new left coordinate (see isChangeLeft() ) + * - possibile new top coordinate (see isChangeTop() ) + * - possibile new zoom level (see isChangeZoom() ) + */ + destXYZ = 1, + destFit = 2, + destFitH = 3, + destFitV = 4, + destFitR = 5, + destFitB = 6, + destFitBH = 7, + destFitBV = 8 + }; + + /// \cond PRIVATE + LinkDestination(const LinkDestinationData &data); + LinkDestination(const QString &description); + /// \endcond + /** + * Copy constructor. + */ + LinkDestination(const LinkDestination &other); + /** + * Destructor. + */ + ~LinkDestination(); + + // Accessors. + /** + * The kind of destination. + */ + Kind kind() const; + /** + * Which page is the target of this destination. + * + * \note this number is 1-based, so for a 5 pages document the + * valid page numbers go from 1 to 5 (both included). + */ + int pageNumber() const; + /** + * The new left for the viewport of the target page, in case + * it is specified to be changed (see isChangeLeft() ) + */ + double left() const; + double bottom() const; + double right() const; + /** + * The new top for the viewport of the target page, in case + * it is specified to be changed (see isChangeTop() ) + */ + double top() const; + double zoom() const; + /** + * Whether the left of the viewport on the target page should + * be changed. + * + * \see left() + */ + bool isChangeLeft() const; + /** + * Whether the top of the viewport on the target page should + * be changed. + * + * \see top() + */ + bool isChangeTop() const; + /** + * Whether the zoom level should be changed. + * + * \see zoom() + */ + bool isChangeZoom() const; + + /** + * Return a string repesentation of this destination. + */ + QString toString() const; + + /** + * Return the name of this destination. + * + * \since 0.12 + */ + QString destinationName() const; + + /** + * Assignment operator. + */ + LinkDestination& operator=(const LinkDestination &other); + + private: + QSharedDataPointer< LinkDestinationPrivate > d; +}; + +/** + * \short Encapsulates data that describes a link. + * + * This is the base class for links. It makes mandatory for inherited + * kind of links to reimplement the linkType() method and return the type of + * the link described by the reimplemented class. + */ +class POPPLER_QT5_EXPORT Link +{ + public: + /// \cond PRIVATE + Link( const QRectF &linkArea ); + /// \endcond + + /** + * The possible kinds of link. + * + * Inherited classes must return an unique identifier + */ + enum LinkType + { + None, ///< Unknown link + Goto, ///< A "Go To" link + Execute, ///< A command to be executed + Browse, ///< An URL to be browsed (eg "http://poppler.freedesktop.org") + Action, ///< A "standard" action to be executed in the viewer + Sound, ///< A link representing a sound to be played + Movie, ///< An action to be executed on a movie + Rendition, ///< A rendition link \since 0.20 + JavaScript ///< A JavaScript code to be interpreted \since 0.10 + }; + + /** + * The type of this link. + */ + virtual LinkType linkType() const; + + /** + * Destructor. + */ + virtual ~Link(); + + /** + * The area of a Page where the link should be active. + * + * \note this can be a null rect, in this case the link represents + * a general action. The area is given in 0..1 range + */ + QRectF linkArea() const; + + protected: + /// \cond PRIVATE + Link( LinkPrivate &dd ); + Q_DECLARE_PRIVATE( Link ) + LinkPrivate *d_ptr; + /// \endcond + + private: + Q_DISABLE_COPY( Link ) +}; + + +/** + * \brief Viewport reaching request. + * + * With a LinkGoto link, the document requests the specified viewport to be + * reached (aka, displayed in a viewer). Furthermore, if a file name is specified, + * then the destination refers to that document (and not to the document the + * current LinkGoto belongs to). + */ +class POPPLER_QT5_EXPORT LinkGoto : public Link +{ + public: + /** + * Create a new Goto link. + * + * \param linkArea the active area of the link + * \param extFileName if not empty, the file name to be open + * \param destination the destination to be reached + */ + LinkGoto( const QRectF &linkArea, QString extFileName, const LinkDestination & destination ); + /** + * Destructor. + */ + ~LinkGoto(); + + /** + * Whether the destination is in an external document + * (i.e. not the current document) + */ + bool isExternal() const; + // query for goto parameters + /** + * The file name of the document the destination() refers to, + * or an empty string in case it refers to the current document. + */ + QString fileName() const; + /** + * The destination to reach. + */ + LinkDestination destination() const; + LinkType linkType() const; + + private: + Q_DECLARE_PRIVATE( LinkGoto ) + Q_DISABLE_COPY( LinkGoto ) +}; + +/** + * \brief Generic execution request. + * + * The LinkExecute link represent a "file name" execution request. The result + * depends on the \link fileName() file name\endlink: + * - if it is a document, then it is requested to be open + * - otherwise, it represents an executable to be run with the specified parameters + */ +class POPPLER_QT5_EXPORT LinkExecute : public Link +{ + public: + /** + * The file name to be executed + */ + QString fileName() const; + /** + * The parameters for the command. + */ + QString parameters() const; + + /** + * Create a new Execute link. + * + * \param linkArea the active area of the link + * \param file the file name to be open, or the program to be execute + * \param params the parameters for the program to execute + */ + LinkExecute( const QRectF &linkArea, const QString & file, const QString & params ); + /** + * Destructor. + */ + ~LinkExecute(); + LinkType linkType() const; + + private: + Q_DECLARE_PRIVATE( LinkExecute ) + Q_DISABLE_COPY( LinkExecute ) +}; + +/** + * \brief An URL to browse. + * + * The LinkBrowse link holds a URL (eg 'http://poppler.freedesktop.org', + * 'mailto:john@some.org', etc) to be open. + * + * The format of the URL is specified by RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt) + */ +class POPPLER_QT5_EXPORT LinkBrowse : public Link +{ + public: + /** + * The URL to open + */ + QString url() const; + + /** + * Create a new browse link. + * + * \param linkArea the active area of the link + * \param url the URL to be open + */ + LinkBrowse( const QRectF &linkArea, const QString &url ); + /** + * Destructor. + */ + ~LinkBrowse(); + LinkType linkType() const; + + private: + Q_DECLARE_PRIVATE( LinkBrowse ) + Q_DISABLE_COPY( LinkBrowse ) +}; + +/** + * \brief "Standard" action request. + * + * The LinkAction class represents a link that request a "standard" action + * to be performed by the viewer on the displayed document. + */ +class POPPLER_QT5_EXPORT LinkAction : public Link +{ + public: + /** + * The possible types of actions + */ + enum ActionType { PageFirst = 1, + PagePrev = 2, + PageNext = 3, + PageLast = 4, + HistoryBack = 5, + HistoryForward = 6, + Quit = 7, + Presentation = 8, + EndPresentation = 9, + Find = 10, + GoToPage = 11, + Close = 12, + Print = 13 ///< \since 0.16 + }; + + /** + * The action of the current LinkAction + */ + ActionType actionType() const; + + /** + * Create a new Action link, that executes a specified action + * on the document. + * + * \param linkArea the active area of the link + * \param actionType which action should be executed + */ + LinkAction( const QRectF &linkArea, ActionType actionType ); + /** + * Destructor. + */ + ~LinkAction(); + LinkType linkType() const; + + private: + Q_DECLARE_PRIVATE( LinkAction ) + Q_DISABLE_COPY( LinkAction ) +}; + +/** + * Sound: a sound to be played. + * + * \since 0.6 + */ +class POPPLER_QT5_EXPORT LinkSound : public Link +{ + public: + // create a Link_Sound + LinkSound( const QRectF &linkArea, double volume, bool sync, bool repeat, bool mix, SoundObject *sound ); + /** + * Destructor. + */ + virtual ~LinkSound(); + + LinkType linkType() const; + + /** + * The volume to be used when playing the sound. + * + * The volume is in the range [ -1, 1 ], where: + * - a negative number: no volume (mute) + * - 1: full volume + */ + double volume() const; + /** + * Whether the playback of the sound should be synchronous + * (thus blocking, waiting for the end of the sound playback). + */ + bool synchronous() const; + /** + * Whether the sound should be played continuously (that is, + * started again when it ends) + */ + bool repeat() const; + /** + * Whether the playback of this sound can be mixed with + * playbacks with other sounds of the same document. + * + * \note When false, any other playback must be stopped before + * playing the sound. + */ + bool mix() const; + /** + * The sound object to be played + */ + SoundObject *sound() const; + + private: + Q_DECLARE_PRIVATE( LinkSound ) + Q_DISABLE_COPY( LinkSound ) +}; + +/** + * Rendition: Rendition link. + * + * \since 0.20 + */ +class POPPLER_QT5_EXPORT LinkRendition : public Link +{ + public: + /** + * Describes the possible rendition actions. + * + * \since 0.22 + */ + enum RenditionAction { + NoRendition, + PlayRendition, + StopRendition, + PauseRendition, + ResumeRendition + }; + + /** + * Create a new rendition link. + * + * \param linkArea the active area of the link + * \param rendition the media rendition object. Ownership is taken + * \param operation the numeric operation (action) (@see ::LinkRendition::RenditionOperation) + * \param script the java script code + * \param annotationReference the object reference of the screen annotation associated with this rendition action + * \since 0.22 + */ + LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition, int operation, const QString &script, const Ref &annotationReference ); + + /** + * Destructor. + */ + virtual ~LinkRendition(); + + LinkType linkType() const; + + /** + * Returns the media rendition object if the redition provides one, @c 0 otherwise + */ + MediaRendition *rendition() const; + + /** + * Returns the action that should be executed if a rendition object is provided. + * + * \since 0.22 + */ + RenditionAction action() const; + + /** + * The JS code that shall be executed or an empty string. + * + * \since 0.22 + */ + QString script() const; + + /** + * Returns whether the given @p annotation is the referenced screen annotation for this rendition @p link. + * + * \since 0.22 + */ + bool isReferencedAnnotation( const ScreenAnnotation *annotation ) const; + + private: + Q_DECLARE_PRIVATE( LinkRendition ) + Q_DISABLE_COPY( LinkRendition ) +}; + +/** + * JavaScript: a JavaScript code to be interpreted. + * + * \since 0.10 + */ +class POPPLER_QT5_EXPORT LinkJavaScript : public Link +{ + public: + /** + * Create a new JavaScript link. + * + * \param linkArea the active area of the link + * \param js the JS code to be interpreted + */ + LinkJavaScript( const QRectF &linkArea, const QString &js ); + /** + * Destructor. + */ + virtual ~LinkJavaScript(); + + LinkType linkType() const; + + /** + * The JS code + */ + QString script() const; + + private: + Q_DECLARE_PRIVATE( LinkJavaScript ) + Q_DISABLE_COPY( LinkJavaScript ) +}; + +/** + * Movie: a movie to be played. + * + * \since 0.20 + */ +class POPPLER_QT5_EXPORT LinkMovie : public Link +{ + public: + /** + * Describes the operation to be performed on the movie. + */ + enum Operation { Play, + Stop, + Pause, + Resume + }; + + /** + * Create a new Movie link. + * + * \param linkArea the active area of the link + * \param operation the operation to be performed on the movie + * \param annotationTitle the title of the movie annotation identifying the movie to be played + * \param annotationReference the object reference of the movie annotation identifying the movie to be played + * + * Note: This constructor is supposed to be used by Poppler::Page only. + */ + LinkMovie( const QRectF &linkArea, Operation operation, const QString &annotationTitle, const Ref &annotationReference ); + /** + * Destructor. + */ + ~LinkMovie(); + LinkType linkType() const; + /** + * Returns the operation to be performed on the movie. + */ + Operation operation() const; + /** + * Returns whether the given @p annotation is the referenced movie annotation for this movie @p link. + */ + bool isReferencedAnnotation( const MovieAnnotation *annotation ) const; + + private: + Q_DECLARE_PRIVATE( LinkMovie ) + Q_DISABLE_COPY( LinkMovie ) +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-media.h b/dependencies/poppler/include/qt5/poppler-media.h new file mode 100644 index 00000000..40b8cae3 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-media.h @@ -0,0 +1,100 @@ +/* poppler-media.h: qt interface to poppler + * Copyright (C) 2012 Guillermo A. Amaral B. + * Copyright (C) 2012, 2013 Albert Astals Cid + * + * 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, 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. + */ + +#ifndef __POPPLER_MEDIARENDITION_H__ +#define __POPPLER_MEDIARENDITION_H__ + +#include "poppler-export.h" + +#include +#include + +class MediaRendition; +class QIODevice; + +namespace Poppler +{ + class MediaRenditionPrivate; + + /** + Qt wrapper for MediaRendition. + + \since 0.20 + */ + class POPPLER_QT5_EXPORT MediaRendition { + public: + /** + Constructs a MediaRendition. Takes ownership of the passed rendition + */ + MediaRendition(::MediaRendition *rendition); + ~MediaRendition(); + + /** + Check if wrapper is holding a valid rendition object. + */ + bool isValid() const; + + /** + Returns content type. + */ + QString contentType() const; + + /** + Returns file name. + */ + QString fileName() const; + + /** + Returns true if media is embedded. + */ + bool isEmbedded() const; + + /** + Returns data buffer. + */ + QByteArray data() const; + + /** + Convenience accessor for auto-play parameter. + */ + bool autoPlay() const; + + /** + Convenience accessor for show controls parameter. + */ + bool showControls() const; + + /** + Convenience accessor for repeat count parameter. + */ + float repeatCount() const; + + /** + Convenience accessor for size parameter. + */ + QSize size() const; + + private: + Q_DECLARE_PRIVATE( MediaRendition ) + MediaRenditionPrivate *d_ptr; + Q_DISABLE_COPY( MediaRendition ) + }; +} + +#endif /* __POPPLER_MEDIARENDITION_H__ */ diff --git a/dependencies/poppler/include/qt5/poppler-optcontent-private.h b/dependencies/poppler/include/qt5/poppler-optcontent-private.h new file mode 100644 index 00000000..98eda073 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-optcontent-private.h @@ -0,0 +1,121 @@ +/* poppler-optcontent-private.h: qt interface to poppler + * + * Copyright (C) 2007, Brad Hards + * Copyright (C) 2008, Pino Toscano + * + * 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, 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. + */ + +#ifndef POPPLER_OPTCONTENT_PRIVATE_H +#define POPPLER_OPTCONTENT_PRIVATE_H + +#include +#include +#include + +class Array; +class OCGs; +class OptionalContentGroup; + +class QModelIndex; + +namespace Poppler +{ + class OptContentItem; + class OptContentModel; + class OptContentModelPrivate; + + class RadioButtonGroup + { + public: + RadioButtonGroup( OptContentModelPrivate *ocModel, Array *rbarray); + ~RadioButtonGroup(); + QSet setItemOn( OptContentItem *itemToSetOn ); + + private: + QList itemsInGroup; + }; + + class OptContentItem + { + public: + enum ItemState { On, Off, HeadingOnly }; + + OptContentItem( OptionalContentGroup *group ); + OptContentItem( const QString &label ); + OptContentItem(); + ~OptContentItem(); + + QString name() const { return m_name; } + ItemState state() const { return m_stateBackup; } + bool setState(ItemState state, QSet &changedItems); + + QList childList() { return m_children; } + + void setParent( OptContentItem* parent) { m_parent = parent; } + OptContentItem* parent() { return m_parent; } + + void addChild( OptContentItem *child ); + + void appendRBGroup( RadioButtonGroup *rbgroup ); + + bool isEnabled() const { return m_enabled; } + + QSet recurseListChildren(bool includeMe = false) const; + + private: + OptionalContentGroup *m_group; + QString m_name; + ItemState m_state; // true for ON, false for OFF + ItemState m_stateBackup; + QList m_children; + OptContentItem *m_parent; + QList m_rbGroups; + bool m_enabled; + }; + + class OptContentModelPrivate + { + public: + OptContentModelPrivate( OptContentModel *qq, OCGs *optContent ); + ~OptContentModelPrivate(); + + void parseRBGroupsArray( Array *rBGroupArray ); + OptContentItem *nodeFromIndex(const QModelIndex &index, bool canBeNull = false) const; + QModelIndex indexFromItem(OptContentItem *node, int column) const; + + /** + Get the OptContentItem corresponding to a given reference value. + + \param ref the reference number (e.g. from Object.getRefNum()) to look up + + \return the matching optional content item, or null if the reference wasn't found + */ + OptContentItem *itemFromRef( const QString &ref ) const; + void setRootNode(OptContentItem *node); + + OptContentModel *q; + + QMap m_optContentItems; + QList m_rbgroups; + OptContentItem *m_rootNode; + + private: + void addChild( OptContentItem *parent, OptContentItem *child); + void parseOrderArray( OptContentItem *parentNode, Array *orderArray ); + }; +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-optcontent.h b/dependencies/poppler/include/qt5/poppler-optcontent.h new file mode 100644 index 00000000..ad75da8c --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-optcontent.h @@ -0,0 +1,77 @@ +/* poppler-optcontent.h: qt interface to poppler + * + * Copyright (C) 2007, Brad Hards + * Copyright (C) 2008, Pino Toscano + * Copyright (C) 2013, Anthony Granger + * + * 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, 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. + */ + +#ifndef POPPLER_OPTCONTENT_H +#define POPPLER_OPTCONTENT_H + +#include + +#include "poppler-export.h" + +class OCGs; + +namespace Poppler +{ + class Document; + class OptContentModelPrivate; + + /** + * \brief Model for optional content + * + * OptContentModel is an item model representing the optional content items + * that can be found in PDF documents. + * + * The model offers a mostly read-only display of the data, allowing to + * enable/disable some contents setting the Qt::CheckStateRole data role. + * + * \since 0.8 + */ + class POPPLER_QT5_EXPORT OptContentModel : public QAbstractItemModel + { + friend class Document; + + Q_OBJECT + + public: + virtual ~OptContentModel(); + + QModelIndex index(int row, int column, const QModelIndex &parent) const; + QModelIndex parent(const QModelIndex &child) const; + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent) const; + + QVariant data(const QModelIndex &index, int role) const; + virtual bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); + + Qt::ItemFlags flags ( const QModelIndex & index ) const; + + virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; + + private: + OptContentModel( OCGs *optContent, QObject *parent = 0); + + friend class OptContentModelPrivate; + OptContentModelPrivate *d; + }; +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-page-private.h b/dependencies/poppler/include/qt5/poppler-page-private.h new file mode 100644 index 00000000..91955e09 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-page-private.h @@ -0,0 +1,54 @@ +/* poppler-page.cc: qt interface to poppler + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2007, 2012, Albert Astals Cid + * Copyright (C) 2008, Pino Toscano + * + * 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, 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. + */ + +#ifndef _POPPLER_PAGE_PRIVATE_H_ +#define _POPPLER_PAGE_PRIVATE_H_ + +#include "CharTypes.h" + +class QRectF; + +class LinkAction; +class Page; +class TextPage; + +namespace Poppler +{ + +class DocumentData; +class PageTransition; + +class PageData { +public: + Link* convertLinkActionToLink(::LinkAction * a, const QRectF &linkArea); + + DocumentData *parentDoc; + ::Page *page; + int index; + PageTransition *transition; + + static Link* convertLinkActionToLink(::LinkAction * a, DocumentData *parentDoc, const QRectF &linkArea); + + TextPage *prepareTextSearch(const QString &text, Page::SearchMode caseSensitive, Page::Rotation rotate, GBool *sCase, QVector *u); +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-page-transition-private.h b/dependencies/poppler/include/qt5/poppler-page-transition-private.h new file mode 100644 index 00000000..63febb09 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-page-transition-private.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2005, Albert Astals Cid + * + * 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, 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. + */ + +class Object; + +namespace Poppler { + +class PageTransitionParams { + public: + Object *dictObj; +}; + +} diff --git a/dependencies/poppler/include/qt5/poppler-page-transition.h b/dependencies/poppler/include/qt5/poppler-page-transition.h new file mode 100644 index 00000000..2d408a51 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-page-transition.h @@ -0,0 +1,148 @@ +/* PageTransition.h + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005, Brad Hards + * + * 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, 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. + */ + +#ifndef __PAGETRANSITION_X_H__ +#define __PAGETRANSITION_X_H__ + +#include "poppler-export.h" + +namespace Poppler { + +class PageTransitionParams; +class PageTransitionData; + +/** + \brief Describes how a PDF file viewer shall perform the transition + from one page to another + + In PDF files there is a way to specify if the viewer shall use + certain effects to perform the transition from one page to + another. This feature can be used, e.g., in a PDF-based beamer + presentation. + + This utility class represents the transition effect, and can be + used to extract the information from a PDF object. +*/ + + +class POPPLER_QT5_EXPORT PageTransition { + public: + + /** \brief transition effect that shall be used + */ + // if changed remember to keep in sync with PageTransition.h enum + enum Type { + Replace = 0, + Split, + Blinds, + Box, + Wipe, + Dissolve, + Glitter, + Fly, + Push, + Cover, + Uncover, + Fade + }; + + /** \brief alignment of the transition effect that shall be used + */ + // if changed remember to keep in sync with PageTransition.h enum + enum Alignment { + Horizontal = 0, + Vertical + }; + + /** \brief direction of the transition effect that shall be used + */ + // if changed remember to keep in sync with PageTransition.h enum + enum Direction { + Inward = 0, + Outward + }; + + /** \brief Construct a new PageTransition object from a page dictionary. + + Users of the library will rarely need to construct a + PageTransition object themselves. Instead, the method + Poppler::Page::transition() can be used to find out if a certain + transition effect is specified. + + @warning In case or error, this method will print an error message to stderr, + and construct a default object. + + @param params an object whose dictionary will be read and + parsed. This must be a valid object, whose dictionaries are + accessed by the constructor. The object is only accessed by this + constructor, and may be deleted after the constructor returns. + */ + PageTransition(const PageTransitionParams ¶ms); + + /** \brief copy constructor */ + PageTransition(const PageTransition &pt); + + /** + Destructor + */ + ~PageTransition(); + + /** + \brief Get type of the transition. + */ + Type type() const; + + /** + \brief Get duration of the transition in seconds. + */ + int duration() const; + + /** + \brief Get dimension in which the transition effect occurs. + */ + Alignment alignment() const; + + /** + \brief Get direction of motion of the transition effect. + */ + Direction direction() const; + + /** + \brief Get direction in which the transition effect moves. + */ + int angle() const; + + /** + \brief Get starting or ending scale. + */ + double scale() const; + + /** + \brief Returns true if the area to be flown is rectangular and + opaque. + */ + bool isRectangular() const; + + private: + PageTransitionData *data; +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-private.h b/dependencies/poppler/include/qt5/poppler-private.h new file mode 100644 index 00000000..0a132f07 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-private.h @@ -0,0 +1,240 @@ +/* poppler-private.h: qt interface to poppler + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005, 2008, Brad Hards + * Copyright (C) 2006-2009, 2011, 2012 by Albert Astals Cid + * Copyright (C) 2007-2009, 2011 by Pino Toscano + * Copyright (C) 2011 Andreas Hartmetz + * Copyright (C) 2011 Hib Eris + * Copyright (C) 2012, 2013 Thomas Freitag + * Copyright (C) 2013 Anthony Granger + * Inspired on code by + * Copyright (C) 2004 by Albert Astals Cid + * Copyright (C) 2004 by Enrico Ros + * + * 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, 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. + */ + +#ifndef _POPPLER_PRIVATE_H_ +#define _POPPLER_PRIVATE_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#if defined(HAVE_SPLASH) +#include +#endif + +#include "poppler-qt5.h" +#include "poppler-embeddedfile-private.h" + +class LinkDest; +class FormWidget; + +namespace Poppler { + + /* borrowed from kpdf */ + QString unicodeToQString(Unicode* u, int len); + + QString UnicodeParsedString(GooString *s1); + + GooString *QStringToUnicodeGooString(const QString &s); + + GooString *QStringToGooString(const QString &s); + + void qt5ErrorFunction(int pos, char *msg, va_list args); + + class LinkDestinationData + { + public: + LinkDestinationData( LinkDest *l, GooString *nd, Poppler::DocumentData *pdfdoc, bool external ) + : ld(l), namedDest(nd), doc(pdfdoc), externalDest(external) + { + } + + LinkDest *ld; + GooString *namedDest; + Poppler::DocumentData *doc; + bool externalDest; + }; + + class DocumentData { + public: + DocumentData(const QString &filePath, GooString *ownerPassword, GooString *userPassword) + { + init(); + m_filePath = filePath; + +#if defined(_WIN32) + wchar_t *fileName = new WCHAR[filePath.length()]; + int length = filePath.toWCharArray(fileName); + doc = new PDFDoc(fileName, length, ownerPassword, userPassword); + delete[] fileName; +#else + GooString *fileName = new GooString(QFile::encodeName(filePath)); + doc = new PDFDoc(fileName, ownerPassword, userPassword); +#endif + + delete ownerPassword; + delete userPassword; + } + + DocumentData(const QByteArray &data, GooString *ownerPassword, GooString *userPassword) + { + Object obj; + fileContents = data; + obj.initNull(); + MemStream *str = new MemStream((char*)fileContents.data(), 0, fileContents.length(), &obj); + init(); + doc = new PDFDoc(str, ownerPassword, userPassword); + delete ownerPassword; + delete userPassword; + } + + void init(); + + ~DocumentData(); + + void addTocChildren( QDomDocument * docSyn, QDomNode * parent, GooList * items ); + + void setPaperColor(const QColor &color) + { + paperColor = color; + } + + void fillMembers() + { + m_fontInfoIterator = new FontIterator(0, this); + int numEmb = doc->getCatalog()->numEmbeddedFiles(); + if (!(0 == numEmb)) { + // we have some embedded documents, build the list + for (int yalv = 0; yalv < numEmb; ++yalv) { + FileSpec *fs = doc->getCatalog()->embeddedFile(yalv); + m_embeddedFiles.append(new EmbeddedFile(*new EmbeddedFileData(fs))); + } + } + } + + static Document *checkDocument(DocumentData *doc); + + PDFDoc *doc; + QString m_filePath; + QByteArray fileContents; + bool locked; + FontIterator *m_fontInfoIterator; + Document::RenderBackend m_backend; + QList m_embeddedFiles; + QPointer m_optContentModel; + QColor paperColor; + int m_hints; + static int count; + }; + + class FontInfoData + { + public: + FontInfoData() + { + isEmbedded = false; + isSubset = false; + type = FontInfo::unknown; + } + + FontInfoData( const FontInfoData &fid ) + { + fontName = fid.fontName; + fontFile = fid.fontFile; + isEmbedded = fid.isEmbedded; + isSubset = fid.isSubset; + type = fid.type; + embRef = fid.embRef; + } + + FontInfoData( ::FontInfo* fi ) + { + if (fi->getName()) fontName = fi->getName()->getCString(); + if (fi->getFile()) fontFile = fi->getFile()->getCString(); + isEmbedded = fi->getEmbedded(); + isSubset = fi->getSubset(); + type = (Poppler::FontInfo::Type)fi->getType(); + embRef = fi->getEmbRef(); + } + + QString fontName; + QString fontFile; + bool isEmbedded : 1; + bool isSubset : 1; + FontInfo::Type type; + Ref embRef; + }; + + class FontIteratorData + { + public: + FontIteratorData( int startPage, DocumentData *dd ) + : fontInfoScanner( dd->doc, startPage ) + , totalPages( dd->doc->getNumPages() ) + , currentPage( qMax( startPage, 0 ) - 1 ) + { + } + + ~FontIteratorData() + { + } + + FontInfoScanner fontInfoScanner; + int totalPages; + int currentPage; + }; + + class TextBoxData + { + public: + TextBoxData() + : nextWord(0), hasSpaceAfter(false) + { + } + + QString text; + QRectF bBox; + TextBox *nextWord; + QVector charBBoxes; // the boundingRect of each character + bool hasSpaceAfter; + }; + + class FormFieldData + { + public: + FormFieldData(DocumentData *_doc, ::Page *p, ::FormWidget *w) : + doc(_doc), page(p), fm(w) + { + } + + DocumentData *doc; + ::Page *page; + ::FormWidget *fm; + QRectF box; + }; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-qiodeviceoutstream-private.h b/dependencies/poppler/include/qt5/poppler-qiodeviceoutstream-private.h new file mode 100644 index 00000000..af0d46b1 --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-qiodeviceoutstream-private.h @@ -0,0 +1,47 @@ +/* poppler-qiodevicestream-private.h: Qt5 interface to poppler + * Copyright (C) 2008, Pino Toscano + * Copyright (C) 2013 Adrian Johnson + * + * 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, 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. + */ + +#ifndef POPPLER_QIODEVICESTREAM_PRIVATE_H +#define POPPLER_QIODEVICESTREAM_PRIVATE_H + +#include "Object.h" +#include "Stream.h" + +class QIODevice; + +namespace Poppler { + +class QIODeviceOutStream : public OutStream +{ + public: + QIODeviceOutStream(QIODevice* device); + virtual ~QIODeviceOutStream(); + + virtual void close(); + virtual Goffset getPos(); + virtual void put(char c); + virtual void printf(const char *format, ...); + + private: + QIODevice *m_device; +}; + +} + +#endif diff --git a/dependencies/poppler/include/qt5/poppler-qt5.h b/dependencies/poppler/include/qt5/poppler-qt5.h new file mode 100644 index 00000000..0eb0b44a --- /dev/null +++ b/dependencies/poppler/include/qt5/poppler-qt5.h @@ -0,0 +1,1771 @@ +/* poppler-qt.h: qt interface to poppler + * Copyright (C) 2005, Net Integration Technologies, Inc. + * Copyright (C) 2005, 2007, Brad Hards + * Copyright (C) 2005-2013, Albert Astals Cid + * Copyright (C) 2005, Stefan Kebekus + * Copyright (C) 2006-2011, Pino Toscano + * Copyright (C) 2009 Shawn Rutledge + * Copyright (C) 2010 Suzuki Toshiya + * Copyright (C) 2010 Matthias Fauconneau + * Copyright (C) 2011 Andreas Hartmetz + * Copyright (C) 2011 Glad Deschrijver + * Copyright (C) 2012, Guillermo A. Amaral B. + * Copyright (C) 2012, Fabio D'Urso + * Copyright (C) 2012, Tobias Koenig + * Copyright (C) 2012 Adam Reichold + * Copyright (C) 2012, 2013 Thomas Freitag + * Copyright (C) 2013 Anthony Granger + * + * 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, 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. + */ + +#ifndef __POPPLER_QT_H__ +#define __POPPLER_QT_H__ + +#include "poppler-annotation.h" +#include "poppler-link.h" +#include "poppler-optcontent.h" +#include "poppler-page-transition.h" + +#include +#include +#include +#include +#include "poppler-export.h" + +class EmbFile; +class Sound; +class AnnotMovie; + +/** + The %Poppler Qt5 binding. +*/ +namespace Poppler { + + class Document; + class DocumentData; + + class PageData; + + class FormField; + + class TextBoxData; + + class PDFConverter; + class PSConverter; + + /** + Debug/error function. + + This function type is used for debugging & error output; + the first parameter is the actual message, the second is the unaltered + closure argument which was passed to the setDebugErrorFunction call. + + \since 0.16 + */ + typedef void (*PopplerDebugFunc)(const QString & /*message*/, const QVariant & /*closure*/); + + /** + Set a new debug/error output function. + + If not set, by default error and debug messages will be sent to the + Qt \p qDebug() function. + + \param debugFunction the new debug function + \param closure user data which will be passes as-is to the debug function + + \since 0.16 + */ + POPPLER_QT5_EXPORT void setDebugErrorFunction(PopplerDebugFunc debugFunction, const QVariant &closure); + + /** + Describes the physical location of text on a document page + + This very simple class describes the physical location of text + on the page. It consists of + - a QString that contains the text + - a QRectF that gives a box that describes where on the page + the text is found. + */ + class POPPLER_QT5_EXPORT TextBox { + friend class Page; + public: + /** + The default constructor sets the \p text and the rectangle that + contains the text. Coordinates for the \p bBox are in points = + 1/72 of an inch. + */ + TextBox(const QString& text, const QRectF &bBox); + /** + Destructor. + */ + ~TextBox(); + + /** + Returns the text of this text box + */ + QString text() const; + + /** + Returns the position of the text, in point, i.e., 1/72 of + an inch + + \since 0.8 + */ + QRectF boundingBox() const; + + /** + Returns the pointer to the next text box, if there is one. + + Otherwise, it returns a null pointer. + */ + TextBox *nextWord() const; + + /** + Returns the bounding box of the \p i -th characted of the word. + */ + QRectF charBoundingBox(int i) const; + + /** + Returns whether there is a space character after this text box + */ + bool hasSpaceAfter() const; + + private: + Q_DISABLE_COPY(TextBox) + + TextBoxData *m_data; + }; + + + class FontInfoData; + /** + Container class for information about a font within a PDF + document + */ + class POPPLER_QT5_EXPORT FontInfo { + friend class Document; + public: + /** + The type of font. + */ + enum Type { + unknown, + Type1, + Type1C, + Type1COT, + Type3, + TrueType, + TrueTypeOT, + CIDType0, + CIDType0C, + CIDType0COT, + CIDTrueType, + CIDTrueTypeOT + }; + + /// \cond PRIVATE + /** + Create a new font information container. + */ + FontInfo(); + + /** + Create a new font information container. + */ + FontInfo( const FontInfoData &fid ); + /// \endcond + + /** + Copy constructor. + */ + FontInfo( const FontInfo &fi ); + + /** + Destructor. + */ + ~FontInfo(); + + /** + The name of the font. Can be QString::null if the font has no name + */ + QString name() const; + + /** + The path of the font file used to represent this font on this system, + or a null string is the font is embedded + */ + QString file() const; + + /** + Whether the font is embedded in the file, or not + + \return true if the font is embedded + */ + bool isEmbedded() const; + + /** + Whether the font provided is only a subset of the full + font or not. This only has meaning if the font is embedded. + + \return true if the font is only a subset + */ + bool isSubset() const; + + /** + The type of font encoding + + \return a enumerated value corresponding to the font encoding used + + \sa typeName for a string equivalent + */ + Type type() const; + + /** + The name of the font encoding used + + \note if you are looking for the name of the font (as opposed to the + encoding format used), you probably want name(). + + \sa type for a enumeration version + */ + QString typeName() const; + + /** + Standard assignment operator + */ + FontInfo& operator=( const FontInfo &fi ); + + private: + FontInfoData *m_data; + }; + + + class FontIteratorData; + /** + Iterator for reading the fonts in a document. + + FontIterator provides a Java-style iterator for reading the fonts in a + document. + + You can use it in the following way: + \code +Poppler::FontIterator* it = doc->newFontIterator(); +while (it->hasNext()) { + QList fonts = it->next(); + // do something with the fonts +} +// after doing the job, the iterator must be freed +delete it; + \endcode + + \since 0.12 + */ + class POPPLER_QT5_EXPORT FontIterator { + friend class Document; + friend class DocumentData; + public: + /** + Destructor. + */ + ~FontIterator(); + + /** + Returns the fonts of the current page and then advances the iterator + to the next page. + */ + QList next(); + + /** + Checks whether there is at least one more page to iterate, ie returns + false when the iterator is beyond the last page. + */ + bool hasNext() const; + + /** + Returns the current page where the iterator is. + */ + int currentPage() const; + + private: + Q_DISABLE_COPY( FontIterator ) + FontIterator( int, DocumentData *dd ); + + FontIteratorData *d; + }; + + + class EmbeddedFileData; + /** + Container class for an embedded file with a PDF document + */ + class POPPLER_QT5_EXPORT EmbeddedFile { + friend class DocumentData; + friend class AnnotationPrivate; + public: + /// \cond PRIVATE + EmbeddedFile(EmbFile *embfile); + /// \endcond + + /** + Destructor. + */ + ~EmbeddedFile(); + + /** + The name associated with the file + */ + QString name() const; + + /** + The description associated with the file, if any. + + This will return an empty QString if there is no description element + */ + QString description() const; + + /** + The size of the file. + + This will return < 0 if there is no size element + */ + int size() const; + + /** + The modification date for the embedded file, if known. + */ + QDateTime modDate() const; + + /** + The creation date for the embedded file, if known. + */ + QDateTime createDate() const; + + /** + The MD5 checksum of the file. + + This will return an empty QByteArray if there is no checksum element. + */ + QByteArray checksum() const; + + /** + The MIME type of the file, if known. + + \since 0.8 + */ + QString mimeType() const; + + /** + The data as a byte array + */ + QByteArray data(); + + /** + Is the embedded file valid? + + \since 0.12 + */ + bool isValid() const; + + /** + A QDataStream for the actual data? + */ + //QDataStream dataStream() const; + + private: + Q_DISABLE_COPY(EmbeddedFile) + EmbeddedFile(EmbeddedFileData &dd); + + EmbeddedFileData *m_embeddedFile; + }; + + + /** + \brief A page in a document. + + The Page class represents a single page within a PDF document. + + You cannot construct a Page directly, but you have to use the Document + functions that return a new Page out of an index or a label. + */ + class POPPLER_QT5_EXPORT Page { + friend class Document; + public: + /** + Destructor. + */ + ~Page(); + + /** + The type of rotation to apply for an operation + */ + enum Rotation { Rotate0 = 0, ///< Do not rotate + Rotate90 = 1, ///< Rotate 90 degrees clockwise + Rotate180 = 2, ///< Rotate 180 degrees + Rotate270 = 3 ///< Rotate 270 degrees clockwise (90 degrees counterclockwise) + }; + + /** + The kinds of page actions + */ + enum PageAction { + Opening, ///< The action when a page is "opened" + Closing ///< The action when a page is "closed" + }; + + /** + How the text is going to be returned + \since 0.16 + */ + enum TextLayout { + PhysicalLayout, ///< The text is layouted to resemble the real page layout + RawOrderLayout ///< The text is returned without any type of processing + }; + + /** + Additional flags for the renderToPainter method + \since 0.16 + */ + enum PainterFlag { + /** + Do not save/restore the caller-owned painter. + + renderToPainter() by default preserves, using save() + restore(), + the state of the painter specified; if this is not needed, this + flag can avoid this job + */ + DontSaveAndRestore = 0x00000001 + }; + Q_DECLARE_FLAGS( PainterFlags, PainterFlag ) + + /** + Render the page to a QImage using the current + \link Document::renderBackend() Document renderer\endlink. + + If \p x = \p y = \p w = \p h = -1, the method will automatically + compute the size of the image from the horizontal and vertical + resolutions specified in \p xres and \p yres. Otherwise, the + method renders only a part of the page, specified by the + parameters (\p x, \p y, \p w, \p h) in pixel coordinates. The returned + QImage then has size (\p w, \p h), independent of the page + size. + + \param x specifies the left x-coordinate of the box, in + pixels. + + \param y specifies the top y-coordinate of the box, in + pixels. + + \param w specifies the width of the box, in pixels. + + \param h specifies the height of the box, in pixels. + + \param xres horizontal resolution of the graphics device, + in dots per inch + + \param yres vertical resolution of the graphics device, in + dots per inch + + \param rotate how to rotate the page + + \warning The parameter (\p x, \p y, \p w, \p h) are not + well-tested. Unusual or meaningless parameters may lead to + rather unexpected results. + + \returns a QImage of the page, or a null image on failure. + + \since 0.6 + */ + QImage renderToImage(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1, Rotation rotate = Rotate0) const; + + /** + Render the page to the specified QPainter using the current + \link Document::renderBackend() Document renderer\endlink. + + If \p x = \p y = \p w = \p h = -1, the method will automatically + compute the size of the page area from the horizontal and vertical + resolutions specified in \p xres and \p yres. Otherwise, the + method renders only a part of the page, specified by the + parameters (\p x, \p y, \p w, \p h) in pixel coordinates. + + \param painter the painter to paint on + + \param x specifies the left x-coordinate of the box, in + pixels. + + \param y specifies the top y-coordinate of the box, in + pixels. + + \param w specifies the width of the box, in pixels. + + \param h specifies the height of the box, in pixels. + + \param xres horizontal resolution of the graphics device, + in dots per inch + + \param yres vertical resolution of the graphics device, in + dots per inch + + \param rotate how to rotate the page + + \param flags additional painter flags + + \warning The parameter (\p x, \p y, \p w, \p h) are not + well-tested. Unusual or meaningless parameters may lead to + rather unexpected results. + + \returns whether the painting succeeded + + \note This method is only supported for Arthur + + \since 0.16 + */ + bool renderToPainter(QPainter* painter, double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1, + Rotation rotate = Rotate0, PainterFlags flags = 0) const; + + /** + Get the page thumbnail if it exists. + + \return a QImage of the thumbnail, or a null image + if the PDF does not contain one for this page + + \since 0.12 + */ + QImage thumbnail() const; + + /** + Returns the text that is inside a specified rectangle + + \param rect the rectangle specifying the area of interest, + with coordinates given in points, i.e., 1/72th of an inch. + If rect is null, all text on the page is given + + \since 0.16 + **/ + QString text(const QRectF &rect, TextLayout textLayout) const; + + /** + Returns the text that is inside a specified rectangle. + The text is returned using the physical layout of the page + + \param rect the rectangle specifying the area of interest, + with coordinates given in points, i.e., 1/72th of an inch. + If rect is null, all text on the page is given + **/ + QString text(const QRectF &rect) const; + + /** + The starting point for a search + */ + enum SearchDirection { FromTop, ///< Start sorting at the top of the document + NextResult, ///< Find the next result, moving "down the page" + PreviousResult ///< Find the previous result, moving "up the page" + }; + + /** + The type of search to perform + */ + enum SearchMode { CaseSensitive, ///< Case differences cause no match in searching + CaseInsensitive ///< Case differences are ignored in matching + }; + + /** + Returns true if the specified text was found. + + \param text the text the search + \param rectXXX in all directions is used to return where the text was found, for NextResult and PreviousResult + indicates where to continue searching for + \param direction in which direction do the search + \param caseSensitive be case sensitive? + \param rotate the rotation to apply for the search order + \since 0.14 + **/ + bool search(const QString &text, double &rectLeft, double &rectTop, double &rectRight, double &rectBottom, SearchDirection direction, SearchMode caseSensitive, Rotation rotate = Rotate0) const; + + /** + Returns a list of all occurrences of the specified text on the page. + + \param text the text to search + \param caseSensitive whether to be case sensitive + \param rotate the rotation to apply for the search order + + \warning Do not use the returned QRectF as arguments of another search call because of truncation issues if qreal is defined as float. + + \since 0.22 + **/ + QList search(const QString &text, SearchMode caseSensitive, Rotation rotate = Rotate0) const; + + /** + Returns a list of text of the page + + This method returns a QList of TextBoxes that contain all + the text of the page, with roughly one text word of text + per TextBox item. + + For text written in western languages (left-to-right and + up-to-down), the QList contains the text in the proper + order. + + \note The caller owns the text boxes and they should + be deleted when no longer required. + + \warning This method is not tested with Asian scripts + */ + QList textList(Rotation rotate = Rotate0) const; + + /** + \return The dimensions (cropbox) of the page, in points (i.e. 1/72th of an inch) + */ + QSizeF pageSizeF() const; + + /** + \return The dimensions (cropbox) of the page, in points (i.e. 1/72th of an inch) + */ + QSize pageSize() const; + + /** + Returns the transition of this page + + \returns a pointer to a PageTransition structure that + defines how transition to this page shall be performed. + + \note The PageTransition structure is owned by this page, and will + automatically be destroyed when this page class is + destroyed. + **/ + PageTransition *transition() const; + + /** + Gets the page action specified, or NULL if there is no action. + + \since 0.6 + **/ + Link *action( PageAction act ) const; + + /** + Types of orientations that are possible + */ + enum Orientation { + Landscape, ///< Landscape orientation (portrait, with 90 degrees clockwise rotation ) + Portrait, ///< Normal portrait orientation + Seascape, ///< Seascape orientation (portrait, with 270 degrees clockwise rotation) + UpsideDown ///< Upside down orientation (portrait, with 180 degrees rotation) + }; + + /** + The orientation of the page + */ + Orientation orientation() const; + + /** + The default CTM + */ + void defaultCTM(double *CTM, double dpiX, double dpiY, int rotate, bool upsideDown); + + /** + Gets the links of the page + */ + QList links() const; + + /** + Returns the annotations of the page + + \note If you call this method twice, you get different objects + pointing to the same annotations (see Annotation). + The caller owns the returned objects and they should be deleted + when no longer required. + */ + QList annotations() const; + + /** + Adds an annotation to the page + + \note Ownership of the annotation object stays with the caller, who can + delete it at any time. + \since 0.20 + */ + void addAnnotation( const Annotation *ann ); + + /** + Removes an annotation from the page and destroys the annotation object + + \note There mustn't be other Annotation objects pointing this annotation + \since 0.20 + */ + void removeAnnotation( const Annotation *ann ); + + /** + Returns the form fields on the page + The caller gets the ownership of the returned objects. + + \since 0.6 + */ + QList formFields() const; + + /** + Returns the page duration. That is the time, in seconds, that the page + should be displayed before the presentation automatically advances to the next page. + Returns < 0 if duration is not set. + + \since 0.6 + */ + double duration() const; + + /** + Returns the label of the page, or a null string is the page has no label. + + \since 0.6 + **/ + QString label() const; + + private: + Q_DISABLE_COPY(Page) + + Page(DocumentData *doc, int index); + PageData *m_page; + }; + +/** + \brief PDF document. + + The Document class represents a PDF document: its pages, and all the global + properties, metadata, etc. + + \section ownership Ownership of the returned objects + + All the functions that returns class pointers create new object, and the + responsability of those is given to the callee. + + The only exception is \link Poppler::Page::transition() Page::transition()\endlink. + + \section document-loading Loading + + To get a Document, you have to load it via the load() & loadFromData() + functions. + + In all the functions that have passwords as arguments, they \b must be Latin1 + encoded. If you have a password that is a UTF-8 string, you need to use + QString::toLatin1() (or similar) to convert the password first. + If you have a UTF-8 character array, consider converting it to a QString first + (QString::fromUtf8(), or similar) before converting to Latin1 encoding. + + \section document-rendering Rendering + + To render pages of a document, you have different Document functions to set + various options. + + \subsection document-rendering-backend Backends + + %Poppler offers a different backends for rendering the pages. Currently + there are two backends (see #RenderBackend), but only the Splash engine works + well and has been tested. + + The available rendering backends can be discovered via availableRenderBackends(). + The current rendering backend can be changed using setRenderBackend(). + Please note that setting a backend not listed in the available ones + will always result in null QImage's. + + \section document-cms Color management support + + %Poppler, if compiled with this support, provides functions to handle color + profiles. + + To know whether the %Poppler version you are using has support for color + management, you can query Poppler::isCmsAvailable(). In case it is not + avilable, all the color management-related functions will either do nothing + or return null. +*/ + class POPPLER_QT5_EXPORT Document { + friend class Page; + friend class DocumentData; + + public: + /** + The page mode + */ + enum PageMode { + UseNone, ///< No mode - neither document outline nor thumbnail images are visible + UseOutlines, ///< Document outline visible + UseThumbs, ///< Thumbnail images visible + FullScreen, ///< Fullscreen mode (no menubar, windows controls etc) + UseOC, ///< Optional content group panel visible + UseAttach ///< Attachments panel visible + }; + + /** + The page layout + */ + enum PageLayout { + NoLayout, ///< Layout not specified + SinglePage, ///< Display a single page + OneColumn, ///< Display a single column of pages + TwoColumnLeft, ///< Display the pages in two columns, with odd-numbered pages on the left + TwoColumnRight, ///< Display the pages in two columns, with odd-numbered pages on the right + TwoPageLeft, ///< Display the pages two at a time, with odd-numbered pages on the left + TwoPageRight ///< Display the pages two at a time, with odd-numbered pages on the right + }; + + /** + The render backends available + + \since 0.6 + */ + enum RenderBackend { + SplashBackend, ///< Splash backend + ArthurBackend ///< Arthur (Qt) backend + }; + + /** + The render hints available + + \since 0.6 + */ + enum RenderHint { + Antialiasing = 0x00000001, ///< Antialiasing for graphics + TextAntialiasing = 0x00000002, ///< Antialiasing for text + TextHinting = 0x00000004, ///< Hinting for text \since 0.12.1 + TextSlightHinting = 0x00000008, ///< Lighter hinting for text when combined with TextHinting \since 0.18 + OverprintPreview = 0x00000010, ///< Overprint preview \since 0.22 + ThinLineSolid = 0x00000020, ///< Enhance thin lines solid \since 0.24 + ThinLineShape = 0x00000040 ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 + }; + Q_DECLARE_FLAGS( RenderHints, RenderHint ) + + /** + Form types + + \since 0.22 + */ + enum FormType { + NoForm, ///< Document doesn't contain forms + AcroForm, ///< AcroForm + XfaForm ///< Adobe XML Forms Architecture (XFA), currently unsupported + }; + + /** + Set a color display profile for the current document. + + \param outputProfileA is a \c cmsHPROFILE of the LCMS library. + + \since 0.12 + */ + void setColorDisplayProfile(void *outputProfileA); + /** + Set a color display profile for the current document. + + \param name is the name of the display profile to set. + + \since 0.12 + */ + void setColorDisplayProfileName(const QString &name); + /** + Return the current RGB profile. + + \return a \c cmsHPROFILE of the LCMS library. + + \since 0.12 + */ + void* colorRgbProfile() const; + /** + Return the current display profile. + + \return a \c cmsHPROFILE of the LCMS library. + + \since 0.12 + */ + void *colorDisplayProfile() const; + + /** + Load the document from a file on disk + + \param filePath the name (and path, if required) of the file to load + \param ownerPassword the Latin1-encoded owner password to use in + loading the file + \param userPassword the Latin1-encoded user ("open") password + to use in loading the file + + \return the loaded document, or NULL on error + + \note The caller owns the pointer to Document, and this should + be deleted when no longer required. + + \warning The returning document may be locked if a password is required + to open the file, and one is not provided (as the userPassword). + */ + static Document *load(const QString & filePath, + const QByteArray &ownerPassword=QByteArray(), + const QByteArray &userPassword=QByteArray()); + + /** + Load the document from memory + + \param fileContents the file contents. They are copied so there is no need + to keep the byte array around for the full life time of + the document. + \param ownerPassword the Latin1-encoded owner password to use in + loading the file + \param userPassword the Latin1-encoded user ("open") password + to use in loading the file + + \return the loaded document, or NULL on error + + \note The caller owns the pointer to Document, and this should + be deleted when no longer required. + + \warning The returning document may be locked if a password is required + to open the file, and one is not provided (as the userPassword). + + \since 0.6 + */ + static Document *loadFromData(const QByteArray &fileContents, + const QByteArray &ownerPassword=QByteArray(), + const QByteArray &userPassword=QByteArray()); + + /** + Get a specified Page + + Note that this follows the PDF standard of being zero based - if you + want the first page, then you need an index of zero. + + The caller gets the ownership of the returned object. + + \param index the page number index + */ + Page *page(int index) const; + + /** + \overload + + + The intent is that you can pass in a label like \c "ix" and + get the page with that label (which might be in the table of + contents), or pass in \c "1" and get the page that the user + expects (which might not be the first page, if there is a + title page and a table of contents). + + \param label the page label + */ + Page *page(const QString &label) const; + + /** + The number of pages in the document + */ + int numPages() const; + + /** + The type of mode that should be used by the application + when the document is opened. Note that while this is + called page mode, it is really viewer application mode. + */ + PageMode pageMode() const; + + /** + The layout that pages should be shown in when the document + is first opened. This basically describes how pages are + shown relative to each other. + */ + PageLayout pageLayout() const; + + /** + Provide the passwords required to unlock the document + + \param ownerPassword the Latin1-encoded owner password to use in + loading the file + \param userPassword the Latin1-encoded user ("open") password + to use in loading the file + */ + bool unlock(const QByteArray &ownerPassword, const QByteArray &userPassword); + + /** + Determine if the document is locked + */ + bool isLocked() const; + + /** + The date associated with the document + + You would use this method with something like: + \code +QDateTime created = m_doc->date("CreationDate"); +QDateTime modified = m_doc->date("ModDate"); + \endcode + + The available dates are: + - CreationDate: the date of creation of the document + - ModDate: the date of the last change in the document + + \param data the type of date that is required + */ + QDateTime date( const QString & data ) const; + + /** + Get specified information associated with the document + + You would use this method with something like: + \code +QString title = m_doc->info("Title"); +QString subject = m_doc->info("Subject"); + \endcode + + In addition to \c Title and \c Subject, other information that may + be available include \c Author, \c Keywords, \c Creator and \c Producer. + + \param data the information that is required + + \sa infoKeys() to get a list of the available keys + */ + QString info( const QString & data ) const; + + /** + Obtain a list of the available string information keys. + */ + QStringList infoKeys() const; + + /** + Test if the document is encrypted + */ + bool isEncrypted() const; + + /** + Test if the document is linearised + + In some cases, this is called "fast web view", since it + is mostly an optimisation for viewing over the Web. + */ + bool isLinearized() const; + + /** + Test if the permissions on the document allow it to be + printed + */ + bool okToPrint() const; + + /** + Test if the permissions on the document allow it to be + printed at high resolution + */ + bool okToPrintHighRes() const; + + /** + Test if the permissions on the document allow it to be + changed. + + \note depending on the type of change, it may be more + appropriate to check other properties as well. + */ + bool okToChange() const; + + /** + Test if the permissions on the document allow the + contents to be copied / extracted + */ + bool okToCopy() const; + + /** + Test if the permissions on the document allow annotations + to be added or modified, and interactive form fields (including + signature fields) to be completed. + */ + bool okToAddNotes() const; + + /** + Test if the permissions on the document allow interactive + form fields (including signature fields) to be completed. + + \note this can be true even if okToAddNotes() is false - this + means that only form completion is permitted. + */ + bool okToFillForm() const; + + /** + Test if the permissions on the document allow interactive + form fields (including signature fields) to be set, created and + modified + */ + bool okToCreateFormFields() const; + + /** + Test if the permissions on the document allow content extraction + (text and perhaps other content) for accessibility usage (eg for + a screen reader) + */ + bool okToExtractForAccessibility() const; + + /** + Test if the permissions on the document allow it to be + "assembled" - insertion, rotation and deletion of pages; + or creation of bookmarks and thumbnail images. + + \note this can be true even if okToChange() is false + */ + bool okToAssemble() const; + + /** + The version of the PDF specification that the document + conforms to + + \param major an optional pointer to a variable where store the + "major" number of the version + \param minor an optional pointer to a variable where store the + "minor" number of the version + + \since 0.12 + */ + void getPdfVersion(int *major, int *minor) const; + + /** + The fonts within the PDF document. + + This is a shorthand for getting all the fonts at once. + + \note this can take a very long time to run with a large + document. You may wish to use a FontIterator if you have more + than say 20 pages + + \see newFontIterator() + */ + QList fonts() const; + + /** + Creates a new FontIterator object for font scanning. + + The new iterator can be used for reading the font information of the + document, reading page by page. + + The caller is responsible for the returned object, ie it should freed + it when no more useful. + + \param startPage the initial page from which start reading fonts + + \see fonts() + + \since 0.12 + */ + FontIterator* newFontIterator( int startPage = 0 ) const; + + /** + The font data if the font is an embedded one. + + \since 0.10 + */ + QByteArray fontData(const FontInfo &font) const; + + /** + The documents embedded within the PDF document. + + \note there are two types of embedded document - this call + only accesses documents that are embedded at the document level. + */ + QList embeddedFiles() const; + + /** + Whether there are any documents embedded in this PDF document. + */ + bool hasEmbeddedFiles() const; + + /** + Gets the table of contents (TOC) of the Document. + + The caller is responsable for the returned object. + + In the tree the tag name is the 'screen' name of the entry. A tag can have + attributes. Here follows the list of tag attributes with meaning: + - Destination: A string description of the referred destination + - DestinationName: A 'named reference' to the viewport + - ExternalFileName: A link to a external filename + - Open: A bool value that tells whether the subbranch of the item is open or not + + Resolving the final destination for each item can be done in the following way: + - first, checking for 'Destination': if not empty, then a LinkDestination + can be constructed straight with it + - as second step, if the 'DestinationName' is not empty, then the destination + can be resolved using linkDestination() + + Note also that if 'ExternalFileName' is not emtpy, then the destination refers + to that document (and not to the current one). + + \returns the TOC, or NULL if the Document does not have one + */ + QDomDocument *toc() const; + + /** + Tries to resolve the named destination \p name. + + \note this operation starts a search through the whole document + + \returns a new LinkDestination object if the named destination was + actually found, or NULL otherwise + */ + LinkDestination *linkDestination( const QString &name ); + + /** + Sets the paper color + + \param color the new paper color + */ + void setPaperColor(const QColor &color); + /** + The paper color + + The default color is white. + */ + QColor paperColor() const; + + /** + Sets the backend used to render the pages. + + \param backend the new rendering backend + + \since 0.6 + */ + void setRenderBackend( RenderBackend backend ); + /** + The currently set render backend + + The default backend is \ref SplashBackend + + \since 0.6 + */ + RenderBackend renderBackend() const; + + /** + The available rendering backends. + + \since 0.6 + */ + static QSet availableRenderBackends(); + + /** + Sets the render \p hint . + + \note some hints may not be supported by some rendering backends. + + \param on whether the flag should be added or removed. + + \since 0.6 + */ + void setRenderHint( RenderHint hint, bool on = true ); + /** + The currently set render hints. + + \since 0.6 + */ + RenderHints renderHints() const; + + /** + Gets a new PS converter for this document. + + The caller gets the ownership of the returned converter. + + \since 0.6 + */ + PSConverter *psConverter() const; + + /** + Gets a new PDF converter for this document. + + The caller gets the ownership of the returned converter. + + \since 0.8 + */ + PDFConverter *pdfConverter() const; + + /** + Gets the metadata stream contents + + \since 0.6 + */ + QString metadata() const; + + /** + Test whether this document has "optional content". + + Optional content is used to optionally turn on (display) + and turn off (not display) some elements of the document. + The most common use of this is for layers in design + applications, but it can be used for a range of things, + such as not including some content in printing, and + displaying content in the appropriate language. + + \since 0.8 + */ + bool hasOptionalContent() const; + + /** + Itemviews model for optional content. + + The model is owned by the document. + + \since 0.8 + */ + OptContentModel *optionalContentModel(); + + /** + Document-level JavaScript scripts. + + Returns the list of document level JavaScript scripts to be always + executed before any other script. + + \since 0.10 + */ + QStringList scripts() const; + + /** + The PDF identifiers. + + \param permanentId an optional pointer to a variable where store the + permanent ID of the document + \param updateId an optional pointer to a variable where store the + update ID of the document + + \return whether the document has the IDs + + \since 0.16 + */ + bool getPdfId(QByteArray *permanentId, QByteArray *updateId) const; + + /** + Returns the type of forms contained in the document + + \since 0.22 + */ + FormType formType() const; + + /** + Destructor. + */ + ~Document(); + + private: + Q_DISABLE_COPY(Document) + + DocumentData *m_doc; + + Document(DocumentData *dataA); + }; + + class BaseConverterPrivate; + class PSConverterPrivate; + class PDFConverterPrivate; + /** + \brief Base converter. + + This is the base class for the converters. + + \since 0.8 + */ + class POPPLER_QT5_EXPORT BaseConverter + { + friend class Document; + public: + /** + Destructor. + */ + virtual ~BaseConverter(); + + /** Sets the output file name. You must set this or the output device. */ + void setOutputFileName(const QString &outputFileName); + + /** + * Sets the output device. You must set this or the output file name. + * + * \since 0.8 + */ + void setOutputDevice(QIODevice *device); + + /** + Does the conversion. + + \return whether the conversion succeeded + */ + virtual bool convert() = 0; + + enum Error + { + NoError, + FileLockedError, + OpenOutputError, + NotSupportedInputFileError + }; + + /** + Returns the last error + \since 0.12.1 + */ + Error lastError() const; + + protected: + /// \cond PRIVATE + BaseConverter(BaseConverterPrivate &dd); + Q_DECLARE_PRIVATE(BaseConverter) + BaseConverterPrivate *d_ptr; + /// \endcond + + private: + Q_DISABLE_COPY(BaseConverter) + }; + + /** + Converts a PDF to PS + + Sizes have to be in Points (1/72 inch) + + If you are using QPrinter you can get paper size by doing: + \code +QPrinter dummy(QPrinter::PrinterResolution); +dummy.setFullPage(true); +dummy.setPageSize(myPageSize); +width = dummy.width(); +height = dummy.height(); + \endcode + + \since 0.6 + */ + class POPPLER_QT5_EXPORT PSConverter : public BaseConverter + { + friend class Document; + public: + /** + Options for the PS export. + + \since 0.10 + */ + enum PSOption { + Printing = 0x00000001, ///< The PS is generated for printing purposes + StrictMargins = 0x00000002, + ForceRasterization = 0x00000004, + PrintToEPS = 0x00000008, ///< Output EPS instead of PS \since 0.20 + HideAnnotations = 0x00000010 ///< Don't print annotations \since 0.20 + }; + Q_DECLARE_FLAGS( PSOptions, PSOption ) + + /** + Destructor. + */ + ~PSConverter(); + + /** Sets the list of pages to print. Mandatory. */ + void setPageList(const QList &pageList); + + /** + Sets the title of the PS Document. Optional + */ + void setTitle(const QString &title); + + /** + Sets the horizontal DPI. Defaults to 72.0 + */ + void setHDPI(double hDPI); + + /** + Sets the vertical DPI. Defaults to 72.0 + */ + void setVDPI(double vDPI); + + /** + Sets the rotate. Defaults to not rotated + */ + void setRotate(int rotate); + + /** + Sets the output paper width. Has to be set. + */ + void setPaperWidth(int paperWidth); + + /** + Sets the output paper height. Has to be set. + */ + void setPaperHeight(int paperHeight); + + /** + Sets the output right margin. Defaults to 0 + */ + void setRightMargin(int marginRight); + + /** + Sets the output bottom margin. Defaults to 0 + */ + void setBottomMargin(int marginBottom); + + /** + Sets the output left margin. Defaults to 0 + */ + void setLeftMargin(int marginLeft); + + /** + Sets the output top margin. Defaults to 0 + */ + void setTopMargin(int marginTop); + + /** + Defines if margins have to be strictly followed (even if that + means changing aspect ratio), or if the margins can be adapted + to keep aspect ratio. + + Defaults to false. + */ + void setStrictMargins(bool strictMargins); + + /** Defines if the page will be rasterized to an image before printing. Defaults to false */ + void setForceRasterize(bool forceRasterize); + + /** + Sets the options for the PS export. + + \since 0.10 + */ + void setPSOptions(PSOptions options); + + /** + The currently set options for the PS export. + + The default flags are: Printing. + + \since 0.10 + */ + PSOptions psOptions() const; + + /** + Sets a function that will be called each time a page is converted. + + The payload belongs to the caller. + + \since 0.16 + */ + void setPageConvertedCallback(void (* callback)(int page, void *payload), void *payload); + + bool convert(); + + private: + Q_DECLARE_PRIVATE(PSConverter) + Q_DISABLE_COPY(PSConverter) + + PSConverter(DocumentData *document); + }; + + /** + Converts a PDF to PDF (thus saves a copy of the document). + + \since 0.8 + */ + class POPPLER_QT5_EXPORT PDFConverter : public BaseConverter + { + friend class Document; + public: + /** + Options for the PDF export. + */ + enum PDFOption { + WithChanges = 0x00000001 ///< The changes done to the document are saved as well + }; + Q_DECLARE_FLAGS( PDFOptions, PDFOption ) + + /** + Destructor. + */ + virtual ~PDFConverter(); + + /** + Sets the options for the PDF export. + */ + void setPDFOptions(PDFOptions options); + /** + The currently set options for the PDF export. + */ + PDFOptions pdfOptions() const; + + bool convert(); + + private: + Q_DECLARE_PRIVATE(PDFConverter) + Q_DISABLE_COPY(PDFConverter) + + PDFConverter(DocumentData *document); + }; + + /** + Conversion from PDF date string format to QDateTime + */ + POPPLER_QT5_EXPORT QDateTime convertDate( char *dateString ); + + /** + Whether the color management functions are available. + + \since 0.12 + */ + POPPLER_QT5_EXPORT bool isCmsAvailable(); + + /** + Whether the overprint preview functionality is available. + + \since 0.22 + */ + POPPLER_QT5_EXPORT bool isOverprintPreviewAvailable(); + + class SoundData; + /** + Container class for a sound file in a PDF document. + + A sound can be either External (in that case should be loaded the file + whose url is represented by url() ), or Embedded, and the player has to + play the data contained in data(). + + \since 0.6 + */ + class POPPLER_QT5_EXPORT SoundObject { + public: + /** + The type of sound + */ + enum SoundType { + External, ///< The real sound file is external + Embedded ///< The sound is contained in the data + }; + + /** + The encoding format used for the sound + */ + enum SoundEncoding { + Raw, ///< Raw encoding, with unspecified or unsigned values in the range [ 0, 2^B - 1 ] + Signed, ///< Twos-complement values + muLaw, ///< mu-law-encoded samples + ALaw ///< A-law-encoded samples + }; + + /// \cond PRIVATE + SoundObject(Sound *popplersound); + /// \endcond + + ~SoundObject(); + + /** + Is the sound embedded (SoundObject::Embedded) or external (SoundObject::External)? + */ + SoundType soundType() const; + + /** + The URL of the sound file to be played, in case of SoundObject::External + */ + QString url() const; + + /** + The data of the sound, in case of SoundObject::Embedded + */ + QByteArray data() const; + + /** + The sampling rate of the sound + */ + double samplingRate() const; + + /** + The number of sound channels to use to play the sound + */ + int channels() const; + + /** + The number of bits per sample value per channel + */ + int bitsPerSample() const; + + /** + The encoding used for the sound + */ + SoundEncoding soundEncoding() const; + + private: + Q_DISABLE_COPY(SoundObject) + + SoundData *m_soundData; + }; + + class MovieData; + /** + Container class for a movie object in a PDF document. + + \since 0.10 + */ + class POPPLER_QT5_EXPORT MovieObject { + friend class AnnotationPrivate; + public: + /** + The play mode for playing the movie + */ + enum PlayMode { + PlayOnce, ///< Play the movie once, closing the movie controls at the end + PlayOpen, ///< Like PlayOnce, but leaving the controls open + PlayRepeat, ///< Play continuously until stopped + PlayPalindrome ///< Play forward, then backward, then again foward and so on until stopped + }; + + ~MovieObject(); + + /** + The URL of the movie to be played + */ + QString url() const; + + /** + The size of the movie + */ + QSize size() const; + + /** + The rotation (either 0, 90, 180, or 270 degrees clockwise) for the movie, + */ + int rotation() const; + + /** + Whether show a bar with movie controls + */ + bool showControls() const; + + /** + How to play the movie + */ + PlayMode playMode() const; + + /** + Returns whether a poster image should be shown if the movie is not playing. + \since 0.22 + */ + bool showPosterImage() const; + + /** + Returns the poster image that should be shown if the movie is not playing. + If the image is null but showImagePoster() returns @c true, the first frame of the movie + should be used as poster image. + \since 0.22 + */ + QImage posterImage() const; + + private: + /// \cond PRIVATE + MovieObject( AnnotMovie *ann ); + /// \endcond + + Q_DISABLE_COPY(MovieObject) + + MovieData *m_movieData; + }; + +} + +Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Page::PainterFlags) +Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::Document::RenderHints) +Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PDFConverter::PDFOptions) +Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PSConverter::PSOptions) + +#endif diff --git a/dependencies/poppler/lib/poppler-qt5.lib b/dependencies/poppler/lib/poppler-qt5.lib new file mode 100644 index 00000000..66b82cdf Binary files /dev/null and b/dependencies/poppler/lib/poppler-qt5.lib differ diff --git a/files/about.html b/files/about.html new file mode 100644 index 00000000..07d1b1fd --- /dev/null +++ b/files/about.html @@ -0,0 +1,102 @@ + + + + + +

+ +

General Information

+

+YACReader - Yet Another Comic Reader - version %1
+by Luis Ãngel San Martín Rodríguez +

Contact

+
    +
  • support: support@yacreader.com
  • +
  • suggestions and general information: info@yacreader.com
  • +
  • developer e-mail: luisangelsm@gmail.com
  • +
  • users' forum: http://www.yacreader.com/forum +
+

Web site

+web site: http://www.yacreader.com +

License

+Published under GPL v3 license. + +

+ +

Donations

+

YACReader is free and open source

+

+If you like YACReader, please, consider to make a donation Donate! +

+ + +

Go social

+

+Find other users and help at: +

+

+ +

Contributors

+

Translators

+ +

Packages

+
    +
  • alperenelhan : Arch Linux binaries
  • +
  • Felix Kauselmann : Arch Linux binaries (7.x)
  • +
  • Alexander Alemayhu : involved in Linux packaging
  • +
  • Yoann Gauthier : man pages for Linux
  • +
  • Robbie Holmes (robbiethegeek) : brew cask install
  • +
+ +

Developers

+
    +
  • Felix Kauselmann : Linux/Unix build system and other improvements.
  • +
+ +

Thank you to Elia Gregorio Méndez for developing the websites

+ + +

Third-party software and resources

+

+Compressed files are loaded using 7zip (Windows version) and p7zip (Linux/MacOS X versions) +

+

+Server info QR codes are generated using qrencode and qrencode-win32 +

+

+SW flow effect uses a modified version of PictureFlow. +

+

+Some icons were desinged by Mattahan. +

+ + diff --git a/files/about_es_ES.html b/files/about_es_ES.html new file mode 100644 index 00000000..3a6f5e7d --- /dev/null +++ b/files/about_es_ES.html @@ -0,0 +1,101 @@ + + + + + +

+ +

Información general

+

+YACReader - Yet Another Comic Reader - versión %1
+por Luis Ãngel San Martín Rodríguez +

Contacto

+
    +
  • soporte: support@yacreader.com
  • +
  • sugerencias e información general: info@yacreader.com
  • +
  • desarrollador e-mail: luisangelsm@gmail.com
  • +
  • foro de usuarios: http://www.yacreader.com/forum +
+

Sitio web

+sitio web: http://www.yacreader.com +

Licencia

+Publicado bajo licencia GPL v3. + +

+ +

Donaciones

+

YACReader es gratis y open source

+

+Si te gusta YACReader, por favor, considera realizar una donación ¡Dona! +

+ + +

Social

+

+Encuentra otros usuarios y ayuda en: +

+

+ +

Contribuidores

+

Traductores

+ +

Paquetes

+
    +
  • alperenelhan : Arch Linux binaries
  • +
  • Felix Kauselmann : Arch Linux binaries (7.x)
  • +
  • Alexander Alemayhu : involved in Linux packaging
  • +
  • Yoann Gauthier : man pages for Linux
  • +
  • Robbie Holmes (robbiethegeek) : brew cask install
  • +
+ +

Developers

+
    +
  • Felix Kauselmann : Linux/Unix build system and other improvements.
  • +
+ +

Gracias a Elia Gregorio Méndez por desarrollar los sitios web

+ +

Software de terceros y recursos

+

+Los archivos comprimidos se cargan usando 7zip (Windows) y p7zip (Linux/MacOS X) +

+

+Los códigos QR con la información del servidor se generan con qrencode y qrencode-win32 +

+

+SW flow usa una versión modificada de PictureFlow. +

+

+Algunos iconos han sido diseñados por Mattahan. +

+ + diff --git a/files/helpYACReader.html b/files/helpYACReader.html new file mode 100644 index 00000000..09919e39 --- /dev/null +++ b/files/helpYACReader.html @@ -0,0 +1,145 @@ + + + + + +

Quick start guide

+

This guide is outdated, get more help on http://www.yacreader.com

+

Features

+

+ YACReader is a fast and simple comic reader with the following features: +

    +
  • Multiplatform, there are Windows, Linux and MacOS X versions.
  • +
  • cbr, cbz, rar, zip, tar and folders support
  • +
  • jpeg, gif, png, tiff and bmp image support
  • +
  • comic reading using keyboard and mouse
  • +
  • fast open and comic navigation
  • +
  • fullscreen mode
  • +
  • configurable magnifying glass for improved reading, since 0.2.0 version is available in windowed mode
  • +
  • fit width (also adjust to an specific width) and fit height modes.
  • +
  • configurable CoverFlow like effect for "go to page" function.
  • +
  • image rotation for comfortable reading even in tablet PCs
  • +
  • double page reading
  • +
  • Comic bookmarks
  • +
+

+

Functions and sortcuts

+

+ General functions: +

    +
  • Open comic : 'O' key
  • +
  • Open folder : 'Ctrl' + 'O' key
  • +
  • Open next cómic : 'Ctrl' + 'Right'
  • +
  • Open previous comic : 'Ctrl' + 'Left' key
  • +
  • Exit : 'Esc' key
  • +
  • Go to previous page : 'Left' key
  • +
  • Go to next page : 'Right' key
  • +
  • Scroll up : 'Wheel mouse up' or 'Up' key
  • +
  • Scroll down : 'Wheel mouse down' or 'Down' key
  • +
  • Auto Scroll down : 'Space Bar'
  • +
  • Auto Scroll up : 'B' key
  • +
  • Rotate to the left : 'L' key
  • +
  • Rotate to the rigth : 'R' key
  • +
  • Open "Go to" dialog : 'G' key
  • +
  • Change between fit width/height modes : 'A' key
  • +
  • Double page mode : 'D' key
  • +
  • Toggle Full Screen mode : 'F' key or double click
  • +
  • For "Go to flow" mode aproximate mouse cursor to bottom border or press 'S' key (show/hide switch).
  • +
  • Show magnifying glass (only in fullscreen mode) : 'Z' key
  • +
  • Show options : 'C' key
  • +
  • Show/hide tool bar : 'H' key
  • +
  • Show information ("current page/number of pages - current time"): 'I' key
  • +
  • Show bookmarks dialog : 'M' key
  • +
  • Set bookmark: 'Ctrl' + 'M' key
  • +
+

+

+ "Go to flow" functions: +

    +
  • Hide / show : 'S' key.
  • + +
  • Go to current central page on the flow : 'Return' or 'Enter'
  • +
  • Next flow page : 'Right' key or left mouse click on the right area of the flow
  • +
  • Previous flow page : 'Left' key or left mouse click on the left area of the flow
  • +
  • Fast forward : 'Ctrl' + 'Right'
  • +
  • Fast backward : 'Ctrl' + 'Left'
  • +
  • Scroll flow : Wheel mouse
  • +
+

+

+ Magnifying glass functions: +

    +
  • Show/hide : 'Z' key.
  • +
  • Resize : Wheel mouse or '+'/'-' keys.
  • +
  • Resize height : 'Ctrl' + Wheel mouse.
  • +
  • Resize width : 'Alt' + Wheel mouse.
  • +
  • Adjust zoom level : 'Shift' + Wheel mouse or 'Shift' + '+'/'-' keys.
  • +
+

+

+ Configuration dialog +

    +
  • "My comics path" : set your favourite comic path. Open comic dialog will open that path by default.
  • +
  • "Go to flow size" : move the slider to set your preferred go to flow size
  • +
  • "How to show pages in GoToFlow" : since version 0.2.0, you can choose between three diferent styles: +
      +
    • Cover Flow : the classic style
    • +
    • Strip : a strip of pages flowing horizontaly
    • +
    • Overlapped Strip : a strip of pages with overlap effect
    • +
        + +
      • "Page width stretch" : move the slider to set your preferred page width stretch. This takes effect in "fit to width" reading mode.
      • +
      +

      + +

      + Bookmarks +

        +
      • You can add three bookmarks per comic (using thumbtack icon or pressing 'Ctrl'+M). New bookmarks replace oldest bookmarks.
      • +
      • YACReader saves automatically the latest page read (the current page when closing).
      • +
      • To go to any bookmark (last page included), open de bookmarks dialog and click on the desired page
      • +
      +

      + +

      Usage and considerations

      +

      + The usual way to read a comic with YACReader is press 'O' to open a comic, + and then use 'Space' and 'B' for autoscrolling pages, you can use 'UP', 'DOWN' or + 'Mouse Wheel' too, when you reach page limit (top or bottom) next page is loaded + automatically, moreover, you can go to next or previous page using 'RIGTH' and 'LEFT'. +

      +

      + Jumping between pages is possible using "Go To..." dialog ('G' key) or "Go To Flow" widget ('S' key). + You don't have to wait until all pages are loaded to use these functions, because pages are shown as soon + as they are ready. +

      +

      + YACReader loads all comic compresed images in memory, when it needs to show one page, only that one is rendered. + Since all pages are in memory YACReader uses aproximately the same RAM as the comic size, so take care if you want to view huge + comics with YACReader (comics larger than your RAM). +

      +

      + The "Go To flow" widget needs to render only the images which will be shown, + doing it in a lazy way to reduce memory consumption, in any case, + it takes a significant amount of RAM (RAM consumption depends on how many images and + how larger are them). So, if you don't have enough RAM, please, reduce 'Slide' size on the 'Options' dialog. +

      + + \ No newline at end of file diff --git a/files/helpYACReaderLibrary.html b/files/helpYACReaderLibrary.html new file mode 100644 index 00000000..cdc6344d --- /dev/null +++ b/files/helpYACReaderLibrary.html @@ -0,0 +1,94 @@ + + + + + +

      Quick start guide

      +

      This guide is outdated, get more help on http://www.yacreader.com

      +

      Features

      +

      + YACReader Library is a comic library browser with the following features: +

        +
      • Three different effects for cover viewing (Cover Flow like, Strip and Overlapped Strip)
      • +
      • Create, add existing, update, delete or rename various comic collections
      • +
      • Export and import covers of your libraries.
      • +
      • Fast navigation between comics ussing tree and list views
      • +
      • Open your comics on YACReader directly from your collection
      • +
      • Fullscreen mode
      • +
      • Search folders in your collections
      • +
      +

      +

      Functions and shortcuts

      +

      +

        +
      • Create a new library: Set a name to your library, select your comics folder and start the creation process
      • +
      • Open an existing library: This funcions allows you to select a folder with a comic library previously created
      • +
      • Export
      • +
      • Import
      • +
      • Update current library: Update the selected library, adding covers to the library if new comics were added, or deleting them if comics were removed
      • +
      • Rename current library: This funcions allows you to rename the selected library. +
      • Remove current library from your collection: delete the selected library from YACReaderLibrary, although library will not be removed from file system
      • +
      • Delete current library from your disk: delete the selected library from YACReaderLibrary and erase it from disk (only covers, comics will never be deleted from disk)
      • +
      • Open current comic on YACReader (Enter):Open for reading the centred comic in the cover flow.
      • +
      • Comic properties: shows a full quality cover, comic file name, number of pages and size comic
      • +
      • Switching to fullscreen mode: you can view your covers bigger in fullscreen mode using 'F' key
      • +
      • Browsing your collection: +
          +
        • Select a library: you can select a library from the combo box clicking on it.
        • +
        • Browse a library: there are three views. +
            +
          • On the left, there is a treeview with the folders existing in your library, + you can select any folder, it is possible to expand or collapse it by double clicking on a folder. Also, you can expand or collapse all folders using '+' and '-' buttons. Root folder + can be selected clicking on "Select root node" button.
          • +
          • On the top right, there is the covers view. This view shows the comics on the selected folder. You can browse them using left and right cursors (pressing CTRL allows you to fast fordward/backward), or clicking on the right/left of the central cover.
          • +
          • On the bottom right, there is the list view. This view shows the comics on the selected folder as a list. You can select any comic clicking on it.
          • +
          +
        • +
        • Search: you can search an especific folder using the text field on the left-bottom corner. If you type "sp", the search will match with "Spiderman - vol 7" and "The dark ages - Spawn". In any case, the search will be case insensitive. +
        +
      • +
      • Configuration dialog: +
          +
        • "How to show covers" : since version 0.2.0, you can choose between three diferent styles: +
            +
          • Cover Flow : the classic style
          • +
          • Strip : a strip of covers flowing horizontaly
          • +
          • Overlapped Strip : a strip of covers with overlap effect
          • +
              + +
            + + +
          +

          +

          Usage and considerations

          +

          You can create a collection in any folder (write privilieges are needed). Creation process involves looking for image files in any + rar,zip,cbr,cbz and tar files. If images are found, the first one (alfabetically) is taken as the comic cover and added + to the collection.

          + +

          The hidden folder .yacreaderlibrary is created in the root path of your comics folder. This folder stores + the library with cover's tumbnails, so please, don't mess with it.

          + +

          .yacreaderlibrary folder can be copied in order to share your comic library with your friends. To do that, you + can copy .yacreaderlibrary to any folder, and then "Open an existing library" from this folder (Note: + if you update that library, all covers will be removed). Is intended that this task could be done automatically from YACReaderLibrary in a later version.

          + + + diff --git a/files/helpYACReaderLibrary_es_ES.html b/files/helpYACReaderLibrary_es_ES.html new file mode 100644 index 00000000..6303d379 --- /dev/null +++ b/files/helpYACReaderLibrary_es_ES.html @@ -0,0 +1,92 @@ + + + + + +

          Guía de comienzo rápido

          +

          Esta guía está desactualizada, obtén más ayuda en http://www.yacreader.com

          +

          Características

          +

          + YACReader Library es un navegador de bibliotecas de cómics con las siguiente caraterísticas: +

            +
          • Tres modos diferentes de ver las portadas de tus cómics (Cover Flow, Strip and Overlapped Strip)
          • +
          • Crea, añade, actauliza, renombra y borra varias colecciones de comics
          • +
          • Exporta e importa tus biblitecas (solo las portadas).
          • +
          • Navegación rápida entre tus cómics utilizando árboles y listas
          • +
          • Permite abrir directamente tus cómics en YACReader
          • +
          • Modo a pantalla completa
          • +
          • Permite realizar búsquedas de directorios en tus bibliotecas
          • +
          +

          +

          Funciones y atajos

          +

          +

            +
          • Crear una nueva biblioteca: Set a name to your library, select your comics folder and start the creation process
          • +
          • Abrir una biblioteca existente: This funcions allows you to select a folder with a comic library previously created
          • +
          • Empaquetar
          • +
          • Desempaquetar
          • +
          • Actualizar la biblioteca actual: Update the selected library, adding covers to the library if new comics were added, or deleting them if comics were removed
          • +
          • Renombrar la biblioteca actual: This funcions allows you to rename the selected library. +
          • Eliminar la biblioteca actual de tu colección: delete the selected library from YACReaderLibrary, although library will not be removed from file system
          • +
          • Eliminar la biblioteca actual de tu disco: delete the selected library from YACReaderLibrary and erase it from disk (only covers, comics will never be deleted from disk)
          • +
          • Abrir el cómic actual en YACReader (Enter):Open for reading the centred comic in the cover flow.
          • +
          • Mostrar las propiedades del cómic: shows a full quality cover, comic file name, number of pages and size comic
          • +
          • Cambiar a modo a pantalla completa: you can view your covers bigger in fullscreen mode using 'F' key
          • +
          • Navegar por tu colección: +
              +
            • Selecciona una biblioteca: puedes seleccionar una biblioteca haciendo click en el campo desplegable de la parte superior izquierda.
            • +
            • Navega en una biblitoca: existen tres vistas. +
                +
              • A la izquierda hay un árbol que contiene todos las carpetas de tu biblioteca, puedes seleccionar cualquier carpeta, además es posible expandir o contraer mediante doble click cualquier +carpeta que contenga otras en su interior. Además, también es posible expandir o contraer el árbol completo usando los botones '+' y '-'. La carpeta raíz puede ser seleccionada pulsando en el botón "Seleccionar nodo raíz".
              • +
              • En la parte superior derecha está la vista de las portadas the covers view. Esta vista muestra los cómics que hay en la carpeta seleccionada actualmente. Puedes navegar por los cómics usando los cursores izquierda y derecha (pulsando CTRL podrás además avanzar y retroceder rápido), también se puede navegar pulsando en las partes izquierda y derecha de la vista o simplemente usando la rueda del ratón.
              • +
              • En la parte inferior derecha hay una lista de cómics que se corresponde con los mostrados en la vista superior. Se puede seleccionar cualquier cómic pulsando en él
              • +
              +
            • +
            • Búsqueda: puedes buscar una carpeta en concreto usando el campo de texto situado en la parte inferior izquierda. Por ejemplo, si escribes "sp", la búsqueda coincidirá con "Spiderman - vol 7" y "The dark ages - Spawn". La busqueda siempre será insensible a las mayúsculas. +
            +
          • +
          • Diálogo de configuración: +
              +
            • "How to show covers" : a partir de la versión 0.2.0, se pueden elegir tres estilos para mostrar las carátulas. +
                +
              • Cover Flow : el estilo clásico
              • +
              • Strip : una tira de imágenes deslizándose horizontalmente
              • +
              • Overlapped Strip : una tira de imagenes parcialmente solapadas a izquierda y derecha de la imagen central
              • +
                  + +
                + + +
              +

              +

              Uso y consideraciones

              +

              Se puede crear una colección en cualquier directorio (con permisos de escritura). El proceso de creación implica buscar imágenes en cualquier archivo + rar,zip,cbr,cbz o tar. Si se encuentran imágenes, la primera (alfabéticamente) es elegida como la portada del cómic y será añadida a tu biblioteca.

              + +

              La carpeta .yacreaderlibrary es creada en la carpeta raíz de cómics elegida. Esta carpeta alamecena copias de las carátulas de los cómics de la biblioteca, así que por favor, no enredes con ella ;).

              + +

              La función de exportar las carátulas de una biblioteca es ideal para compartir la información de las bibliotecas con otras personas

              +

              .yacreaderlibrary folder can be copied in order to share your comic library with your friends. To do that, you + can copy .yacreaderlibrary to any folder, and then "Open an existing library" from this folder (Note: + if you update that library, all covers will be removed). Is intended that this task could be done automatically from YACReaderLibrary in a later version.

              + + + diff --git a/files/helpYACReader_es_ES.html b/files/helpYACReader_es_ES.html new file mode 100644 index 00000000..58175d84 --- /dev/null +++ b/files/helpYACReader_es_ES.html @@ -0,0 +1,145 @@ + + + + + +

              Guía de comienzo rápido

              +

              Esta guía está desactualizada, obtén más ayuda en http://www.yacreader.com

              +

              Características

              +

              + YACReader es un visor de cómics rápido y sencillo con las siguiente características: +

                +
              • Multiplataforma, hay versiones para Windows, Linux y MacOS X.
              • +
              • Soporta archivos cbr,cbz,rar,zip y tar, también permite visualizar imágenes almacenadas en un directorio
              • +
              • Soporta imágenes bmp,jpeg,gif,png y tiff
              • +
              • Lectura usando teclado y ratón
              • +
              • Apertura y navegación rápida
              • +
              • Modo a pantalla completa
              • +
              • Lupa configurable para mejorar la lectura
              • +
              • Ajuste de página en altura y anchura (con nivel de anchura configurable)
              • +
              • Modo de lectura a doble página
              • +
              • Permite añadir marcadores a tus cómics y recordar la última página leida
              • +
              • Efecto CoverFlow para navegar entre las páginas y la función "ir a..."
              • +
              • Rotación de imagen para la lectura confortable incluso en tablet PCs
              • +
              +

              +

              Funciones y atajos

              +

              + Funciones generales: +

                +
              • Abrir cómic : tecla 'O'
              • +
              • Abrir carpeta : 'Ctrl+O'
              • +
              • Abrir siguiente cómic : 'Ctrl' + 'Right'
              • +
              • Abrir siguiente comic : 'Ctrl' + 'Left' key
              • +
              • Salir : 'Esc'
              • +
              • Ir a la página anterior : 'Cursor izquierdo'
              • +
              • Ir a la página siguiente : 'Cursor derecho'
              • +
              • Scroll hacía arriba : 'Rueda del ratón arriba' o 'Cursor arriba'
              • +
              • Scroll hacía abajo : 'Rueda del ratón abajo' o 'Cursor arriba'
              • +
              • Auto Scroll abajo : 'Barra espaciadora'
              • +
              • AutoAuto Scroll arriba : 'B'
              • +
              • Rotar a la izquierda : 'L'
              • +
              • Rotar a la derecha : 'R'
              • +
              • Abrir el diálogo "Ir a": 'G'
              • +
              • Cambiar entre los modos ajustar en altura/anchura : 'A'
              • +
              • Modo a doble página : 'D'
              • +
              • Cambiar a pantalla completa : 'F' o doble click
              • +
              • Para usar la función "Go to flow" aproximar el cursor del ratón a la parte baja del visor o pulsar 'S'(mostrar/ocultar).
              • +
              • Mostrar lupa : 'Z'
              • +
              • Mostrar opciones : 'C'
              • +
              • Mostrar/ocultar la barra de herramientas : 'H'
              • +
              • Mostrar información ("página actual/numero de páginas - hora actual"): 'I'
              • +
              • Mostrar el diálogo de marcadores : 'M'
              • +
              • Poner un marcador en la página actual : 'CTRL' + 'M'
              • +
              + +

              +

              + Funciones "Go to flow": +

                +
              • Mostrar / Ocultar : 'S'.
              • + +
              • Ir a la página central : 'Return' o 'Enter'
              • +
              • Avanzar a la siguiente página : 'Cursor derecha' o click en la parte derecha del diálogo
              • +
              • Retroceder a la página anterior : 'Cursor izquierda' o click en la parte izquierda del diálogo
              • +
              • Avance rápido : 'Ctrl' + 'Cursor derecha'
              • +
              • Retroceso rápido : 'Ctrl' + 'Cursor izquierda'
              • +
              • Scroll : Rueda del ratón
              • +
              +

              +

              + Funciones de lupa: +

                +
              • Mostrar / Ocultar : 'Z'.
              • +
              • Redimensionar : Rueda del ratón o '+'/'-'.
              • +
              • Ajustar altura : 'Ctrl' + Rueda de ratón.
              • +
              • Ajustar anchura : 'Alt' + Rueda de ratón.
              • +
              • Ajustar el nivel de zoom : 'Shift' + Rueda del ratón o 'Shift' + '+'/'-'.
              • +
              +

              +

              + Diálogo de configuración +

                +
              • "Ruta a mis cómics" : configura la ruta a tu directorio de cómics favorito. El diálogo de abrir cómic se abrirá en esa ruta por defecto.
              • +
              • Tamaño de "Go to flow" : usa el deslizador para establecer el tamaño deseado
              • +
              • "Aspecto de GoToFlow" : desde la versión 0.2.0, puedes elegir entre tres estilos diferentes: +
                  +
                • Cover Flow : el estilo clásico
                • +
                • Strip : una tira de imágenes deslizándose horizontalmente
                • +
                • Overlapped Strip : una tira de imagenes parcialmente solapadas a izquierda y derecha de la imagen central
                • +
                    + +
                  • "Ajuste en anchura de la página" : mueve el deslizador para establecer tu ajuste en anchura preferido. La configuración tiene efecto en el modo de lectura ajuste en anchura
                  • +
                  +

                  + +

                  + Marcadores +

                    +
                  • Se pueden añadir tres marcadores por cómic (usando el botón marcador o pulsando 'Ctrl'+M). Los nuevos marcadores reemplanzan a los antiguos.
                  • +
                  • YACReader guarda automáticamente la última página leida (la página actual cuando el programa es cerrado).
                  • +
                  • Para ir a cualquier marcador (la última página incluida), basta con abrir el diálogo de marcadores y pulsar sobre la página deseada.
                  • +
                  +

                  + +

                  Uso y consideraciones

                  +

                  + La manera habitual de leer un cómic con YACReader es pulsar 'O' para abrir un cómic, + y después usar la barra espaciadora y la tecla 'B' para avanzar y retroceder automáticamente, tambien se pueden usar las teclas 'Cursor ARRIBA', 'Cursor ABAJO' o + la rueda del ratón, Cuando se alcanza el limite superior o inferior de la páginat la siguiente página es cargada automáticamente + , además, se puede avanzar o retroceder entre páginas con las teclas 'Cursor DERECHA' y cursor 'IZQUIERDA'. +

                  +

                  + Para saltar entre páginas se pueden usar las funciones "Ir a" (tecla G) y "Go To Flow" (tecla S). + No es necesario esperar a que todas las páginas del cómic estén cargadas para usar estas funciones, ya que cuando una página se carga, se muestra inmediatamente si el usuario está esperando para verla. +

                  +

                  + YACReader carga todas las páginas del cómic en memoria, cuando necesita mostrar una, solo esa es renderizada. + Puesto que todas las páginas están en memoria, YACReader usa una cantidad mínima de RAM igual al tamaño del cómic, así que deberías tener cuidado si intentar leer cómics enormes (de tamaño superior a la cantidad de RAM instalada) +

                  +

                  + El widget "Go To flow" solo necesita renderizar las imágenes que muestre, cargándolas según las necesita con el fin de consumir la minima cantidad de RAM posible. Aún así, si se desean ver todas las páginas del cómic + de este modo, esta función consumirá una cantidad significativa de RAM (El consumo de RAM depende de la calidad y el tamaño de las imágenes). Si no tienes suficiente RAM, por favor, reduce el tamaño de "Go To Flow" en el diálogo de opciones. +

                  + + \ No newline at end of file diff --git a/files/shortcuts.html b/files/shortcuts.html new file mode 100644 index 00000000..3ae57af5 --- /dev/null +++ b/files/shortcuts.html @@ -0,0 +1,94 @@ + + + + + + + + + + + +
                  + +

                  General functions:

                  +
                  +
                  + C: Open options
                  + Ctrl+M : Set/Unset bookmark
                  + Esc : Exit
                  + F : Fullscreen mode on/off
                  + F1 : Show About/Help dialog
                  + H : Show/Hide toolbar
                  + I : Show/Hide information (pages/current time)
                  + M : Show bookmarks
                  + O : Open comic
                  + Ctrl + O : Open folder
                  + T : Show/Hide YACReader Translator
                  +
                  + +

                  Reading functions:

                  +
                  +
                  + B : Auto Scroll up
                  + Down : Scroll down
                  + End : Go to last page
                  + G : Open "Go to" dialog
                  + Home : Go to first page
                  + Left : Go to previous page
                  + Mouse drag: Scroll
                  + Right : Go to next page
                  + Space Bar : Auto Scroll down
                  + Up : Scroll up
                  + Wheel mouse up : Scroll up
                  + Wheel mouse down : Scroll down
                  +
                  +
                  + +

                  Image adjust functions:

                  +
                  +
                  + A : Fit to width / height
                  + D : Double page mode
                  + L : Rotate to the left
                  + R : Rotate to the rigth
                  + W : Show pages at full size
                  +
                  +

                  Magnifying glass:

                  +
                  +
                  + Alt + Wheel mouse up : Decrease horizontal size
                  + Alt + Wheel mouse down : Increase Horizontal size
                  + Ctrl + Wheel mouse up : Decrease vertical size
                  + Ctrl + Wheel mouse down : Increase vertical size
                  + Shift + Wheel mouse up : Zoom out
                  + Shift + Wheel mouse down : Zoom in
                  + Wheel mouse up : Decrease size
                  + Wheel mouse down : Increase size
                  + Z : Show/hide
                  +
                  + +

                  GoTo Flow functions:

                  +
                  +
                  + S : Show/hide
                  + Wheel mouse up : Next flow page
                  + Wheel mouse down : Previous flow page
                  + Enter : Go to current page
                  +
                  +
                  + + \ No newline at end of file diff --git a/files/shortcuts2.html b/files/shortcuts2.html new file mode 100644 index 00000000..53dfc01c --- /dev/null +++ b/files/shortcuts2.html @@ -0,0 +1,38 @@ + + + + +
                  Image adjust functions:
                  +
                  +
                  + A : Fit to width / height
                  + L : Rotate to the left
                  + Q : Always on Top
                  + R : Rotate to the rigth
                  + W : Show pages at full size
                  +
                  +
                  Magnifying glass:
                  +
                  +
                  + Alt + Wheel mouse up : Decrease horizontal size
                  + Alt + Wheel mouse down : Increase Horizontal size
                  + Ctrl + Wheel mouse up : Decrease vertical size
                  + Ctrl + Wheel mouse down : Increase vertical size
                  + Shift + Wheel mouse up : Zoom out
                  + Shift + Wheel mouse down : Zoom in
                  + Wheel mouse up : Decrease size
                  + Wheel mouse down : Increase size
                  + Z : Show/hide
                  +
                  + +
                  GoTo Flow functions:
                  +
                  +
                  + S : Show/hide
                  + Wheel mouse up : Next flow page
                  + Wheel mouse down : Previous flow page
                  + Enter : Go to current page
                  +
                  + + + \ No newline at end of file diff --git a/files/translator.html b/files/translator.html new file mode 100644 index 00000000..05711fc6 --- /dev/null +++ b/files/translator.html @@ -0,0 +1,639 @@ + + + + + YACReader translator (beta) + + + + + + + + + + + + + +

                  YACReader translator (beta)

                  +
                  + +
                  +
                  + +
                  +
                  + +
                  +
                   
                  +
                  + +
                  +
                  +
                   
                  +
                  +
                  +

                  Pronunciation

                  +

                  +

                  + +
                  +
                   
                  +
                  +

                  +
                  +
                  +
                  +
                  +
                  +
                  +

                  + Translation +

                  +

                  +

                  +
                  +
                  + + + + + + + \ No newline at end of file diff --git a/generateVS2010Projects.bat b/generateVS2010Projects.bat new file mode 100644 index 00000000..23f8ce59 --- /dev/null +++ b/generateVS2010Projects.bat @@ -0,0 +1,31 @@ + +echo Setting up a Qt environment... + +set QTDIR=D:\Desarrollo\Qt\4.8.5 +echo -- QTDIR set to D:\Desarrollo\Qt\4.8.5 +set PATH=D:\Desarrollo\Qt\4.8.5\bin;%PATH% +echo -- Added D:\Desarrollo\Qt\4.8.5\bin to PATH +set QMAKESPEC=win32-msvc2010 +echo -- QMAKESPEC set to "win32-msvc2010" + +if not "%1"=="vsvars" goto ENDVSVARS +call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat" +:ENDVSVARS + +if not "%1"=="vsstart" goto ENDVSSTART +call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat" +devenv /useenv +:ENDVSSTART + + +cd YACReader +echo Entering YACReader +qmake -spec win32-msvc2010 -tp vc YACReader.pro +echo qmake -spec win32-msvc2010 -tp vc YACReader.pro +cd .. +echo leaving YACReader +cd YACReaderLibrary +echo Entering YACReaderLibrary +qmake -spec win32-msvc2010 -tp vc YACReaderLibrary.pro +echo qmake -spec win32-msvc2010 -tp vc YACReaderLibrary.pro +cd .. \ No newline at end of file diff --git a/icon.icns b/icon.icns new file mode 100755 index 00000000..fc39f1ad Binary files /dev/null and b/icon.icns differ diff --git a/images/accept_shortcut.png b/images/accept_shortcut.png new file mode 100644 index 00000000..dc0017b9 Binary files /dev/null and b/images/accept_shortcut.png differ diff --git a/images/adjustToFullSize.png b/images/adjustToFullSize.png new file mode 100644 index 00000000..9c9d11d6 Binary files /dev/null and b/images/adjustToFullSize.png differ diff --git a/images/alwaysOnTop.png b/images/alwaysOnTop.png new file mode 100644 index 00000000..b932de0a Binary files /dev/null and b/images/alwaysOnTop.png differ diff --git a/images/asignNumber.png b/images/asignNumber.png new file mode 100644 index 00000000..06fe03a1 Binary files /dev/null and b/images/asignNumber.png differ diff --git a/images/bookmark.png b/images/bookmark.png new file mode 100644 index 00000000..d8d4c078 Binary files /dev/null and b/images/bookmark.png differ diff --git a/images/busy_background.png b/images/busy_background.png new file mode 100644 index 00000000..4bc83d5b Binary files /dev/null and b/images/busy_background.png differ diff --git a/images/center.png b/images/center.png new file mode 100644 index 00000000..80385bbd Binary files /dev/null and b/images/center.png differ diff --git a/images/clearSearch.png b/images/clearSearch.png new file mode 100644 index 00000000..1db15e7b Binary files /dev/null and b/images/clearSearch.png differ diff --git a/images/clearSearchNew.png b/images/clearSearchNew.png new file mode 100644 index 00000000..20de2f16 Binary files /dev/null and b/images/clearSearchNew.png differ diff --git a/images/clear_shortcut.png b/images/clear_shortcut.png new file mode 100644 index 00000000..1ffbf449 Binary files /dev/null and b/images/clear_shortcut.png differ diff --git a/images/close.png b/images/close.png new file mode 100644 index 00000000..54d51b35 Binary files /dev/null and b/images/close.png differ diff --git a/images/comicFolder.png b/images/comicFolder.png new file mode 100644 index 00000000..3acc14f9 Binary files /dev/null and b/images/comicFolder.png differ diff --git a/images/comic_vine/downArrow.png b/images/comic_vine/downArrow.png new file mode 100644 index 00000000..ef5be7af Binary files /dev/null and b/images/comic_vine/downArrow.png differ diff --git a/images/comic_vine/nextPage.png b/images/comic_vine/nextPage.png new file mode 100644 index 00000000..46aaa8c6 Binary files /dev/null and b/images/comic_vine/nextPage.png differ diff --git a/images/comic_vine/previousPage.png b/images/comic_vine/previousPage.png new file mode 100644 index 00000000..01365a89 Binary files /dev/null and b/images/comic_vine/previousPage.png differ diff --git a/images/comic_vine/radioChecked.png b/images/comic_vine/radioChecked.png new file mode 100644 index 00000000..a6134f92 Binary files /dev/null and b/images/comic_vine/radioChecked.png differ diff --git a/images/comic_vine/radioUnchecked.png b/images/comic_vine/radioUnchecked.png new file mode 100644 index 00000000..13c0a7bd Binary files /dev/null and b/images/comic_vine/radioUnchecked.png differ diff --git a/images/comic_vine/rowDown.png b/images/comic_vine/rowDown.png new file mode 100644 index 00000000..c89a816d Binary files /dev/null and b/images/comic_vine/rowDown.png differ diff --git a/images/comic_vine/rowUp.png b/images/comic_vine/rowUp.png new file mode 100644 index 00000000..00c4b548 Binary files /dev/null and b/images/comic_vine/rowUp.png differ diff --git a/images/comic_vine/upArrow.png b/images/comic_vine/upArrow.png new file mode 100644 index 00000000..a0c1303d Binary files /dev/null and b/images/comic_vine/upArrow.png differ diff --git a/images/coversPackage.png b/images/coversPackage.png new file mode 100644 index 00000000..fb852ea4 Binary files /dev/null and b/images/coversPackage.png differ diff --git a/images/db.png b/images/db.png new file mode 100644 index 00000000..3ff7f463 Binary files /dev/null and b/images/db.png differ diff --git a/images/defaultCover.png b/images/defaultCover.png new file mode 100644 index 00000000..32d6bc19 Binary files /dev/null and b/images/defaultCover.png differ diff --git a/images/deleteLibrary.png b/images/deleteLibrary.png new file mode 100644 index 00000000..c6aac781 Binary files /dev/null and b/images/deleteLibrary.png differ diff --git a/images/deleting_progress/icon.png b/images/deleting_progress/icon.png new file mode 100644 index 00000000..70774190 Binary files /dev/null and b/images/deleting_progress/icon.png differ diff --git a/images/deleting_progress/imgBottomLeft.png b/images/deleting_progress/imgBottomLeft.png new file mode 100644 index 00000000..9c2f77ec Binary files /dev/null and b/images/deleting_progress/imgBottomLeft.png differ diff --git a/images/deleting_progress/imgBottomMiddle.png b/images/deleting_progress/imgBottomMiddle.png new file mode 100644 index 00000000..da7fbc49 Binary files /dev/null and b/images/deleting_progress/imgBottomMiddle.png differ diff --git a/images/deleting_progress/imgBottomRight.png b/images/deleting_progress/imgBottomRight.png new file mode 100644 index 00000000..c33e6aee Binary files /dev/null and b/images/deleting_progress/imgBottomRight.png differ diff --git a/images/deleting_progress/imgLeftMiddle.png b/images/deleting_progress/imgLeftMiddle.png new file mode 100644 index 00000000..84cb9241 Binary files /dev/null and b/images/deleting_progress/imgLeftMiddle.png differ diff --git a/images/deleting_progress/imgRightMiddle.png b/images/deleting_progress/imgRightMiddle.png new file mode 100644 index 00000000..f29c1b1e Binary files /dev/null and b/images/deleting_progress/imgRightMiddle.png differ diff --git a/images/deleting_progress/imgTopLeft.png b/images/deleting_progress/imgTopLeft.png new file mode 100644 index 00000000..ea44e354 Binary files /dev/null and b/images/deleting_progress/imgTopLeft.png differ diff --git a/images/deleting_progress/imgTopMiddle.png b/images/deleting_progress/imgTopMiddle.png new file mode 100644 index 00000000..a4ad9904 Binary files /dev/null and b/images/deleting_progress/imgTopMiddle.png differ diff --git a/images/deleting_progress/imgTopRight.png b/images/deleting_progress/imgTopRight.png new file mode 100644 index 00000000..c528653e Binary files /dev/null and b/images/deleting_progress/imgTopRight.png differ diff --git a/images/dictionary.png b/images/dictionary.png new file mode 100644 index 00000000..7edab2c6 Binary files /dev/null and b/images/dictionary.png differ diff --git a/images/doublePage.png b/images/doublePage.png new file mode 100644 index 00000000..f270e1a4 Binary files /dev/null and b/images/doublePage.png differ diff --git a/images/down.png b/images/down.png new file mode 100644 index 00000000..44d91d42 Binary files /dev/null and b/images/down.png differ diff --git a/images/dropDownArrow.png b/images/dropDownArrow.png new file mode 100644 index 00000000..db5ea8d8 Binary files /dev/null and b/images/dropDownArrow.png differ diff --git a/images/edit.png b/images/edit.png new file mode 100644 index 00000000..7ac38c8c Binary files /dev/null and b/images/edit.png differ diff --git a/images/editComic.png b/images/editComic.png new file mode 100644 index 00000000..8dcc2deb Binary files /dev/null and b/images/editComic.png differ diff --git a/images/editIcon.png b/images/editIcon.png new file mode 100644 index 00000000..a90fbd9d Binary files /dev/null and b/images/editIcon.png differ diff --git a/images/empty_current_readings.png b/images/empty_current_readings.png new file mode 100644 index 00000000..776fb0c3 Binary files /dev/null and b/images/empty_current_readings.png differ diff --git a/images/empty_favorites.png b/images/empty_favorites.png new file mode 100644 index 00000000..c0fce602 Binary files /dev/null and b/images/empty_favorites.png differ diff --git a/images/empty_folder.png b/images/empty_folder.png new file mode 100644 index 00000000..fa3b13cd Binary files /dev/null and b/images/empty_folder.png differ diff --git a/images/empty_folder_osx.png b/images/empty_folder_osx.png new file mode 100644 index 00000000..f33e65e0 Binary files /dev/null and b/images/empty_folder_osx.png differ diff --git a/images/empty_label.png b/images/empty_label.png new file mode 100644 index 00000000..4c085723 Binary files /dev/null and b/images/empty_label.png differ diff --git a/images/empty_reading_list.png b/images/empty_reading_list.png new file mode 100644 index 00000000..36669888 Binary files /dev/null and b/images/empty_reading_list.png differ diff --git a/images/empty_reading_list_osx.png b/images/empty_reading_list_osx.png new file mode 100644 index 00000000..59667e1f Binary files /dev/null and b/images/empty_reading_list_osx.png differ diff --git a/images/empty_search.png b/images/empty_search.png new file mode 100644 index 00000000..f012d8ec Binary files /dev/null and b/images/empty_search.png differ diff --git a/images/empty_search_osx.png b/images/empty_search_osx.png new file mode 100644 index 00000000..d9b8cee5 Binary files /dev/null and b/images/empty_search_osx.png differ diff --git a/images/exportComicsInfo.png b/images/exportComicsInfo.png new file mode 100644 index 00000000..5299eb71 Binary files /dev/null and b/images/exportComicsInfo.png differ diff --git a/images/exportComicsInfoIcon.png b/images/exportComicsInfoIcon.png new file mode 100644 index 00000000..e1c22eda Binary files /dev/null and b/images/exportComicsInfoIcon.png differ diff --git a/images/exportLibrary.png b/images/exportLibrary.png new file mode 100644 index 00000000..67d23757 Binary files /dev/null and b/images/exportLibrary.png differ diff --git a/images/exportLibraryIcon.png b/images/exportLibraryIcon.png new file mode 100644 index 00000000..d176e495 Binary files /dev/null and b/images/exportLibraryIcon.png differ diff --git a/images/f.png b/images/f.png new file mode 100644 index 00000000..232a785d Binary files /dev/null and b/images/f.png differ diff --git a/images/f_overlayed.png b/images/f_overlayed.png new file mode 100644 index 00000000..eb53bca4 Binary files /dev/null and b/images/f_overlayed.png differ diff --git a/images/f_overlayed_retina.png b/images/f_overlayed_retina.png new file mode 100644 index 00000000..d613de82 Binary files /dev/null and b/images/f_overlayed_retina.png differ diff --git a/images/f_retina.png b/images/f_retina.png new file mode 100644 index 00000000..b8eeddcf Binary files /dev/null and b/images/f_retina.png differ diff --git a/images/find_folder.png b/images/find_folder.png new file mode 100644 index 00000000..f645dfe4 Binary files /dev/null and b/images/find_folder.png differ diff --git a/images/fit.png b/images/fit.png new file mode 100644 index 00000000..13bf08e4 Binary files /dev/null and b/images/fit.png differ diff --git a/images/flow1.png b/images/flow1.png new file mode 100644 index 00000000..2da32278 Binary files /dev/null and b/images/flow1.png differ diff --git a/images/flow2.png b/images/flow2.png new file mode 100644 index 00000000..2259b90b Binary files /dev/null and b/images/flow2.png differ diff --git a/images/flow3.png b/images/flow3.png new file mode 100644 index 00000000..37881559 Binary files /dev/null and b/images/flow3.png differ diff --git a/images/flow4.png b/images/flow4.png new file mode 100644 index 00000000..2dbcc759 Binary files /dev/null and b/images/flow4.png differ diff --git a/images/flow5.png b/images/flow5.png new file mode 100644 index 00000000..311e7aba Binary files /dev/null and b/images/flow5.png differ diff --git a/images/flow_to_grid.gif b/images/flow_to_grid.gif new file mode 100644 index 00000000..f78228cf Binary files /dev/null and b/images/flow_to_grid.gif differ diff --git a/images/flow_to_grid_osx.gif b/images/flow_to_grid_osx.gif new file mode 100644 index 00000000..99a73ed6 Binary files /dev/null and b/images/flow_to_grid_osx.gif differ diff --git a/images/folder_finished_macosx.png b/images/folder_finished_macosx.png new file mode 100644 index 00000000..e1dc09ec Binary files /dev/null and b/images/folder_finished_macosx.png differ diff --git a/images/fromTo.png b/images/fromTo.png new file mode 100644 index 00000000..87ec680d Binary files /dev/null and b/images/fromTo.png differ diff --git a/images/getInfo.png b/images/getInfo.png new file mode 100644 index 00000000..c62c0639 Binary files /dev/null and b/images/getInfo.png differ diff --git a/images/glowLine.png b/images/glowLine.png new file mode 100644 index 00000000..13ee7b3b Binary files /dev/null and b/images/glowLine.png differ diff --git a/images/goto.png b/images/goto.png new file mode 100644 index 00000000..d99a3d01 Binary files /dev/null and b/images/goto.png differ diff --git a/images/grid_to_flow.gif b/images/grid_to_flow.gif new file mode 100644 index 00000000..10bc6d23 Binary files /dev/null and b/images/grid_to_flow.gif differ diff --git a/images/grid_to_flow_osx.gif b/images/grid_to_flow_osx.gif new file mode 100644 index 00000000..7bf2fbc4 Binary files /dev/null and b/images/grid_to_flow_osx.gif differ diff --git a/images/help.png b/images/help.png new file mode 100644 index 00000000..752b36c4 Binary files /dev/null and b/images/help.png differ diff --git a/images/helpImages/bookmark.png b/images/helpImages/bookmark.png new file mode 100644 index 00000000..673aadad Binary files /dev/null and b/images/helpImages/bookmark.png differ diff --git a/images/helpImages/center.png b/images/helpImages/center.png new file mode 100644 index 00000000..d7cc6980 Binary files /dev/null and b/images/helpImages/center.png differ diff --git a/images/helpImages/colapse.png b/images/helpImages/colapse.png new file mode 100644 index 00000000..298c0b75 Binary files /dev/null and b/images/helpImages/colapse.png differ diff --git a/images/helpImages/comicFolder.png b/images/helpImages/comicFolder.png new file mode 100644 index 00000000..0cfbbae9 Binary files /dev/null and b/images/helpImages/comicFolder.png differ diff --git a/images/helpImages/coversPackage.png b/images/helpImages/coversPackage.png new file mode 100644 index 00000000..03be8b92 Binary files /dev/null and b/images/helpImages/coversPackage.png differ diff --git a/images/helpImages/deleteLibrary.png b/images/helpImages/deleteLibrary.png new file mode 100644 index 00000000..c17fd99c Binary files /dev/null and b/images/helpImages/deleteLibrary.png differ diff --git a/images/helpImages/doublePage.png b/images/helpImages/doublePage.png new file mode 100644 index 00000000..7a271ba0 Binary files /dev/null and b/images/helpImages/doublePage.png differ diff --git a/images/helpImages/edit.png b/images/helpImages/edit.png new file mode 100644 index 00000000..63beab17 Binary files /dev/null and b/images/helpImages/edit.png differ diff --git a/images/helpImages/expand.png b/images/helpImages/expand.png new file mode 100644 index 00000000..02124ec1 Binary files /dev/null and b/images/helpImages/expand.png differ diff --git a/images/helpImages/exportLibrary.png b/images/helpImages/exportLibrary.png new file mode 100644 index 00000000..fffcc14c Binary files /dev/null and b/images/helpImages/exportLibrary.png differ diff --git a/images/helpImages/fit.png b/images/helpImages/fit.png new file mode 100644 index 00000000..8ef45dcb Binary files /dev/null and b/images/helpImages/fit.png differ diff --git a/images/helpImages/flow1.png b/images/helpImages/flow1.png new file mode 100644 index 00000000..7b5659df Binary files /dev/null and b/images/helpImages/flow1.png differ diff --git a/images/helpImages/flow2.png b/images/helpImages/flow2.png new file mode 100644 index 00000000..f4e1ad7c Binary files /dev/null and b/images/helpImages/flow2.png differ diff --git a/images/helpImages/flow3.png b/images/helpImages/flow3.png new file mode 100644 index 00000000..42d862f4 Binary files /dev/null and b/images/helpImages/flow3.png differ diff --git a/images/helpImages/folder.png b/images/helpImages/folder.png new file mode 100644 index 00000000..86a097d7 Binary files /dev/null and b/images/helpImages/folder.png differ diff --git a/images/helpImages/goto.png b/images/helpImages/goto.png new file mode 100644 index 00000000..f6684586 Binary files /dev/null and b/images/helpImages/goto.png differ diff --git a/images/helpImages/help.png b/images/helpImages/help.png new file mode 100644 index 00000000..1cf94d84 Binary files /dev/null and b/images/helpImages/help.png differ diff --git a/images/helpImages/icon.png b/images/helpImages/icon.png new file mode 100644 index 00000000..69b9ab79 Binary files /dev/null and b/images/helpImages/icon.png differ diff --git a/images/helpImages/importLibrary.png b/images/helpImages/importLibrary.png new file mode 100644 index 00000000..fb4164d1 Binary files /dev/null and b/images/helpImages/importLibrary.png differ diff --git a/images/helpImages/keyboard.png b/images/helpImages/keyboard.png new file mode 100644 index 00000000..40d51bca Binary files /dev/null and b/images/helpImages/keyboard.png differ diff --git a/images/helpImages/mouse.png b/images/helpImages/mouse.png new file mode 100644 index 00000000..be14c68c Binary files /dev/null and b/images/helpImages/mouse.png differ diff --git a/images/helpImages/new.png b/images/helpImages/new.png new file mode 100644 index 00000000..65ed48d1 Binary files /dev/null and b/images/helpImages/new.png differ diff --git a/images/helpImages/next.png b/images/helpImages/next.png new file mode 100644 index 00000000..c64575cd Binary files /dev/null and b/images/helpImages/next.png differ diff --git a/images/helpImages/nextComic.png b/images/helpImages/nextComic.png new file mode 100644 index 00000000..7be06463 Binary files /dev/null and b/images/helpImages/nextComic.png differ diff --git a/images/helpImages/notCover.png b/images/helpImages/notCover.png new file mode 100644 index 00000000..b3043734 Binary files /dev/null and b/images/helpImages/notCover.png differ diff --git a/images/helpImages/open.png b/images/helpImages/open.png new file mode 100644 index 00000000..6ee29cb8 Binary files /dev/null and b/images/helpImages/open.png differ diff --git a/images/helpImages/openFolder.png b/images/helpImages/openFolder.png new file mode 100644 index 00000000..58d5d54b Binary files /dev/null and b/images/helpImages/openFolder.png differ diff --git a/images/helpImages/openLibrary.png b/images/helpImages/openLibrary.png new file mode 100644 index 00000000..331a8922 Binary files /dev/null and b/images/helpImages/openLibrary.png differ diff --git a/images/helpImages/options.png b/images/helpImages/options.png new file mode 100644 index 00000000..d87004e6 Binary files /dev/null and b/images/helpImages/options.png differ diff --git a/images/helpImages/prev.png b/images/helpImages/prev.png new file mode 100644 index 00000000..412e109e Binary files /dev/null and b/images/helpImages/prev.png differ diff --git a/images/helpImages/previousComic.png b/images/helpImages/previousComic.png new file mode 100644 index 00000000..8efa2c0d Binary files /dev/null and b/images/helpImages/previousComic.png differ diff --git a/images/helpImages/properties.png b/images/helpImages/properties.png new file mode 100644 index 00000000..3dccd0d5 Binary files /dev/null and b/images/helpImages/properties.png differ diff --git a/images/helpImages/removeLibrary.png b/images/helpImages/removeLibrary.png new file mode 100644 index 00000000..74046661 Binary files /dev/null and b/images/helpImages/removeLibrary.png differ diff --git a/images/helpImages/rotateL.png b/images/helpImages/rotateL.png new file mode 100644 index 00000000..65803536 Binary files /dev/null and b/images/helpImages/rotateL.png differ diff --git a/images/helpImages/rotateR.png b/images/helpImages/rotateR.png new file mode 100644 index 00000000..b00f5a2d Binary files /dev/null and b/images/helpImages/rotateR.png differ diff --git a/images/helpImages/save.png b/images/helpImages/save.png new file mode 100644 index 00000000..a6b23d1f Binary files /dev/null and b/images/helpImages/save.png differ diff --git a/images/helpImages/setBookmark.png b/images/helpImages/setBookmark.png new file mode 100644 index 00000000..1ee8c652 Binary files /dev/null and b/images/helpImages/setBookmark.png differ diff --git a/images/helpImages/setRoot.png b/images/helpImages/setRoot.png new file mode 100644 index 00000000..2c6c314d Binary files /dev/null and b/images/helpImages/setRoot.png differ diff --git a/images/helpImages/shortcuts.png b/images/helpImages/shortcuts.png new file mode 100644 index 00000000..371ffde5 Binary files /dev/null and b/images/helpImages/shortcuts.png differ diff --git a/images/helpImages/speaker.png b/images/helpImages/speaker.png new file mode 100644 index 00000000..b0e76fa1 Binary files /dev/null and b/images/helpImages/speaker.png differ diff --git a/images/helpImages/updateLibrary.png b/images/helpImages/updateLibrary.png new file mode 100644 index 00000000..570c3700 Binary files /dev/null and b/images/helpImages/updateLibrary.png differ diff --git a/images/helpImages/zoom.png b/images/helpImages/zoom.png new file mode 100644 index 00000000..cb082f6d Binary files /dev/null and b/images/helpImages/zoom.png differ diff --git a/images/hiddenCovers.png b/images/hiddenCovers.png new file mode 100644 index 00000000..8689db16 Binary files /dev/null and b/images/hiddenCovers.png differ diff --git a/images/hideComicFlow.png b/images/hideComicFlow.png new file mode 100644 index 00000000..3dd949d2 Binary files /dev/null and b/images/hideComicFlow.png differ diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 00000000..16e9a9ef Binary files /dev/null and b/images/icon.png differ diff --git a/images/iconLibrary.png b/images/iconLibrary.png new file mode 100644 index 00000000..4c4d8a69 Binary files /dev/null and b/images/iconLibrary.png differ diff --git a/images/iconSearch.png b/images/iconSearch.png new file mode 100644 index 00000000..8d6a5f63 Binary files /dev/null and b/images/iconSearch.png differ diff --git a/images/iconSearchNew.png b/images/iconSearchNew.png new file mode 100644 index 00000000..08b23b82 Binary files /dev/null and b/images/iconSearchNew.png differ diff --git a/images/imgBottomLeft.png b/images/imgBottomLeft.png new file mode 100644 index 00000000..27fa1709 Binary files /dev/null and b/images/imgBottomLeft.png differ diff --git a/images/imgBottomMiddle.png b/images/imgBottomMiddle.png new file mode 100644 index 00000000..142bf3ac Binary files /dev/null and b/images/imgBottomMiddle.png differ diff --git a/images/imgBottomRight.png b/images/imgBottomRight.png new file mode 100644 index 00000000..e9417476 Binary files /dev/null and b/images/imgBottomRight.png differ diff --git a/images/imgCenterSlide.png b/images/imgCenterSlide.png new file mode 100644 index 00000000..4e531b98 Binary files /dev/null and b/images/imgCenterSlide.png differ diff --git a/images/imgCenterSlidePressed.png b/images/imgCenterSlidePressed.png new file mode 100644 index 00000000..53ce692b Binary files /dev/null and b/images/imgCenterSlidePressed.png differ diff --git a/images/imgEdit.png b/images/imgEdit.png new file mode 100644 index 00000000..c18d8ec9 Binary files /dev/null and b/images/imgEdit.png differ diff --git a/images/imgGoToSlide.png b/images/imgGoToSlide.png new file mode 100644 index 00000000..9a31acba Binary files /dev/null and b/images/imgGoToSlide.png differ diff --git a/images/imgGoToSlidePressed.png b/images/imgGoToSlidePressed.png new file mode 100644 index 00000000..f7f5370c Binary files /dev/null and b/images/imgGoToSlidePressed.png differ diff --git a/images/imgTopLeft.png b/images/imgTopLeft.png new file mode 100644 index 00000000..57c0ee49 Binary files /dev/null and b/images/imgTopLeft.png differ diff --git a/images/imgTopMiddle.png b/images/imgTopMiddle.png new file mode 100644 index 00000000..9d23bef8 Binary files /dev/null and b/images/imgTopMiddle.png differ diff --git a/images/imgTopRight.png b/images/imgTopRight.png new file mode 100644 index 00000000..d20ae2a9 Binary files /dev/null and b/images/imgTopRight.png differ diff --git a/images/importBottomCoversDecoration.png b/images/importBottomCoversDecoration.png new file mode 100644 index 00000000..3e0b2906 Binary files /dev/null and b/images/importBottomCoversDecoration.png differ diff --git a/images/importComicsInfo.png b/images/importComicsInfo.png new file mode 100644 index 00000000..6830bc07 Binary files /dev/null and b/images/importComicsInfo.png differ diff --git a/images/importComicsInfoIcon.png b/images/importComicsInfoIcon.png new file mode 100644 index 00000000..fbf7c7ee Binary files /dev/null and b/images/importComicsInfoIcon.png differ diff --git a/images/importCover.png b/images/importCover.png new file mode 100644 index 00000000..ae814ec8 Binary files /dev/null and b/images/importCover.png differ diff --git a/images/importLibrary.png b/images/importLibrary.png new file mode 100644 index 00000000..fa9366bf Binary files /dev/null and b/images/importLibrary.png differ diff --git a/images/importLibraryIcon.png b/images/importLibraryIcon.png new file mode 100644 index 00000000..ea1e0798 Binary files /dev/null and b/images/importLibraryIcon.png differ diff --git a/images/importTopCoversDecoration.png b/images/importTopCoversDecoration.png new file mode 100644 index 00000000..0343fdb4 Binary files /dev/null and b/images/importTopCoversDecoration.png differ diff --git a/images/importingIcon.png b/images/importingIcon.png new file mode 100644 index 00000000..a53e768a Binary files /dev/null and b/images/importingIcon.png differ diff --git a/images/iphoneConfig.png b/images/iphoneConfig.png new file mode 100644 index 00000000..c5b4797c Binary files /dev/null and b/images/iphoneConfig.png differ diff --git a/images/lists/default_0.png b/images/lists/default_0.png new file mode 100644 index 00000000..b00a0b6f Binary files /dev/null and b/images/lists/default_0.png differ diff --git a/images/lists/default_0_osx.png b/images/lists/default_0_osx.png new file mode 100644 index 00000000..0473058d Binary files /dev/null and b/images/lists/default_0_osx.png differ diff --git a/images/lists/default_0_osx@2x.png b/images/lists/default_0_osx@2x.png new file mode 100644 index 00000000..b623e0d0 Binary files /dev/null and b/images/lists/default_0_osx@2x.png differ diff --git a/images/lists/default_1.png b/images/lists/default_1.png new file mode 100644 index 00000000..93b55e47 Binary files /dev/null and b/images/lists/default_1.png differ diff --git a/images/lists/default_1_osx.png b/images/lists/default_1_osx.png new file mode 100644 index 00000000..da69a01d Binary files /dev/null and b/images/lists/default_1_osx.png differ diff --git a/images/lists/default_1_osx@2x.png b/images/lists/default_1_osx@2x.png new file mode 100644 index 00000000..963abad8 Binary files /dev/null and b/images/lists/default_1_osx@2x.png differ diff --git a/images/lists/label_blue.png b/images/lists/label_blue.png new file mode 100644 index 00000000..fb4d538a Binary files /dev/null and b/images/lists/label_blue.png differ diff --git a/images/lists/label_blue_osx.png b/images/lists/label_blue_osx.png new file mode 100644 index 00000000..fb4d538a Binary files /dev/null and b/images/lists/label_blue_osx.png differ diff --git a/images/lists/label_blue_osx@2x.png b/images/lists/label_blue_osx@2x.png new file mode 100644 index 00000000..35190ea7 Binary files /dev/null and b/images/lists/label_blue_osx@2x.png differ diff --git a/images/lists/label_cyan.png b/images/lists/label_cyan.png new file mode 100644 index 00000000..c750224c Binary files /dev/null and b/images/lists/label_cyan.png differ diff --git a/images/lists/label_cyan_osx.png b/images/lists/label_cyan_osx.png new file mode 100644 index 00000000..c750224c Binary files /dev/null and b/images/lists/label_cyan_osx.png differ diff --git a/images/lists/label_cyan_osx@2x.png b/images/lists/label_cyan_osx@2x.png new file mode 100644 index 00000000..9c430a0c Binary files /dev/null and b/images/lists/label_cyan_osx@2x.png differ diff --git a/images/lists/label_dark.png b/images/lists/label_dark.png new file mode 100644 index 00000000..5ae096ba Binary files /dev/null and b/images/lists/label_dark.png differ diff --git a/images/lists/label_dark_osx.png b/images/lists/label_dark_osx.png new file mode 100644 index 00000000..5ae096ba Binary files /dev/null and b/images/lists/label_dark_osx.png differ diff --git a/images/lists/label_dark_osx@2x.png b/images/lists/label_dark_osx@2x.png new file mode 100644 index 00000000..179ef5c2 Binary files /dev/null and b/images/lists/label_dark_osx@2x.png differ diff --git a/images/lists/label_green.png b/images/lists/label_green.png new file mode 100644 index 00000000..d791c59e Binary files /dev/null and b/images/lists/label_green.png differ diff --git a/images/lists/label_green_osx.png b/images/lists/label_green_osx.png new file mode 100644 index 00000000..d791c59e Binary files /dev/null and b/images/lists/label_green_osx.png differ diff --git a/images/lists/label_green_osx@2x.png b/images/lists/label_green_osx@2x.png new file mode 100644 index 00000000..4a75b5bb Binary files /dev/null and b/images/lists/label_green_osx@2x.png differ diff --git a/images/lists/label_light.png b/images/lists/label_light.png new file mode 100644 index 00000000..a1111a81 Binary files /dev/null and b/images/lists/label_light.png differ diff --git a/images/lists/label_light_osx.png b/images/lists/label_light_osx.png new file mode 100644 index 00000000..a1111a81 Binary files /dev/null and b/images/lists/label_light_osx.png differ diff --git a/images/lists/label_light_osx@2x.png b/images/lists/label_light_osx@2x.png new file mode 100644 index 00000000..eb875990 Binary files /dev/null and b/images/lists/label_light_osx@2x.png differ diff --git a/images/lists/label_orange.png b/images/lists/label_orange.png new file mode 100644 index 00000000..19d6dcb4 Binary files /dev/null and b/images/lists/label_orange.png differ diff --git a/images/lists/label_orange_osx.png b/images/lists/label_orange_osx.png new file mode 100644 index 00000000..19d6dcb4 Binary files /dev/null and b/images/lists/label_orange_osx.png differ diff --git a/images/lists/label_orange_osx@2x.png b/images/lists/label_orange_osx@2x.png new file mode 100644 index 00000000..eeb72ee4 Binary files /dev/null and b/images/lists/label_orange_osx@2x.png differ diff --git a/images/lists/label_pink.png b/images/lists/label_pink.png new file mode 100644 index 00000000..f17df136 Binary files /dev/null and b/images/lists/label_pink.png differ diff --git a/images/lists/label_pink_osx.png b/images/lists/label_pink_osx.png new file mode 100644 index 00000000..f17df136 Binary files /dev/null and b/images/lists/label_pink_osx.png differ diff --git a/images/lists/label_pink_osx@2x.png b/images/lists/label_pink_osx@2x.png new file mode 100644 index 00000000..4089a47b Binary files /dev/null and b/images/lists/label_pink_osx@2x.png differ diff --git a/images/lists/label_purple.png b/images/lists/label_purple.png new file mode 100644 index 00000000..3864b692 Binary files /dev/null and b/images/lists/label_purple.png differ diff --git a/images/lists/label_purple_osx.png b/images/lists/label_purple_osx.png new file mode 100644 index 00000000..3864b692 Binary files /dev/null and b/images/lists/label_purple_osx.png differ diff --git a/images/lists/label_purple_osx@2x.png b/images/lists/label_purple_osx@2x.png new file mode 100644 index 00000000..c2fbded9 Binary files /dev/null and b/images/lists/label_purple_osx@2x.png differ diff --git a/images/lists/label_red.png b/images/lists/label_red.png new file mode 100644 index 00000000..53e17209 Binary files /dev/null and b/images/lists/label_red.png differ diff --git a/images/lists/label_red_osx.png b/images/lists/label_red_osx.png new file mode 100644 index 00000000..53e17209 Binary files /dev/null and b/images/lists/label_red_osx.png differ diff --git a/images/lists/label_red_osx@2x.png b/images/lists/label_red_osx@2x.png new file mode 100644 index 00000000..694f0959 Binary files /dev/null and b/images/lists/label_red_osx@2x.png differ diff --git a/images/lists/label_violet.png b/images/lists/label_violet.png new file mode 100644 index 00000000..067104d7 Binary files /dev/null and b/images/lists/label_violet.png differ diff --git a/images/lists/label_violet_osx.png b/images/lists/label_violet_osx.png new file mode 100644 index 00000000..067104d7 Binary files /dev/null and b/images/lists/label_violet_osx.png differ diff --git a/images/lists/label_violet_osx@2x.png b/images/lists/label_violet_osx@2x.png new file mode 100644 index 00000000..d1607a6f Binary files /dev/null and b/images/lists/label_violet_osx@2x.png differ diff --git a/images/lists/label_white.png b/images/lists/label_white.png new file mode 100644 index 00000000..c4c3f855 Binary files /dev/null and b/images/lists/label_white.png differ diff --git a/images/lists/label_white_osx.png b/images/lists/label_white_osx.png new file mode 100644 index 00000000..c4c3f855 Binary files /dev/null and b/images/lists/label_white_osx.png differ diff --git a/images/lists/label_white_osx@2x.png b/images/lists/label_white_osx@2x.png new file mode 100644 index 00000000..b7a75773 Binary files /dev/null and b/images/lists/label_white_osx@2x.png differ diff --git a/images/lists/label_yellow.png b/images/lists/label_yellow.png new file mode 100644 index 00000000..91e89b46 Binary files /dev/null and b/images/lists/label_yellow.png differ diff --git a/images/lists/label_yellow_osx.png b/images/lists/label_yellow_osx.png new file mode 100644 index 00000000..91e89b46 Binary files /dev/null and b/images/lists/label_yellow_osx.png differ diff --git a/images/lists/label_yellow_osx@2x.png b/images/lists/label_yellow_osx@2x.png new file mode 100644 index 00000000..d588e587 Binary files /dev/null and b/images/lists/label_yellow_osx@2x.png differ diff --git a/images/lists/list.png b/images/lists/list.png new file mode 100644 index 00000000..9d890d42 Binary files /dev/null and b/images/lists/list.png differ diff --git a/images/lists/list_osx.png b/images/lists/list_osx.png new file mode 100644 index 00000000..0e9e496a Binary files /dev/null and b/images/lists/list_osx.png differ diff --git a/images/lists/list_osx@2x.png b/images/lists/list_osx@2x.png new file mode 100644 index 00000000..9e29a489 Binary files /dev/null and b/images/lists/list_osx@2x.png differ diff --git a/images/main_toolbar/back.png b/images/main_toolbar/back.png new file mode 100644 index 00000000..2677d99e Binary files /dev/null and b/images/main_toolbar/back.png differ diff --git a/images/main_toolbar/back_disabled.png b/images/main_toolbar/back_disabled.png new file mode 100644 index 00000000..9e09b69a Binary files /dev/null and b/images/main_toolbar/back_disabled.png differ diff --git a/images/main_toolbar/back_disabled_osx.png b/images/main_toolbar/back_disabled_osx.png new file mode 100644 index 00000000..92ef82c9 Binary files /dev/null and b/images/main_toolbar/back_disabled_osx.png differ diff --git a/images/main_toolbar/back_osx.png b/images/main_toolbar/back_osx.png new file mode 100644 index 00000000..e6e7724e Binary files /dev/null and b/images/main_toolbar/back_osx.png differ diff --git a/images/main_toolbar/back_osx@2x.png b/images/main_toolbar/back_osx@2x.png new file mode 100644 index 00000000..c56d5126 Binary files /dev/null and b/images/main_toolbar/back_osx@2x.png differ diff --git a/images/main_toolbar/divider.png b/images/main_toolbar/divider.png new file mode 100644 index 00000000..ed245eeb Binary files /dev/null and b/images/main_toolbar/divider.png differ diff --git a/images/main_toolbar/flow.png b/images/main_toolbar/flow.png new file mode 100644 index 00000000..eec316ee Binary files /dev/null and b/images/main_toolbar/flow.png differ diff --git a/images/main_toolbar/flow_osx.png b/images/main_toolbar/flow_osx.png new file mode 100644 index 00000000..261a8ebd Binary files /dev/null and b/images/main_toolbar/flow_osx.png differ diff --git a/images/main_toolbar/flow_osx@2x.png b/images/main_toolbar/flow_osx@2x.png new file mode 100644 index 00000000..69081e1e Binary files /dev/null and b/images/main_toolbar/flow_osx@2x.png differ diff --git a/images/main_toolbar/forward.png b/images/main_toolbar/forward.png new file mode 100644 index 00000000..b6473ae8 Binary files /dev/null and b/images/main_toolbar/forward.png differ diff --git a/images/main_toolbar/forward_disabled.png b/images/main_toolbar/forward_disabled.png new file mode 100644 index 00000000..1e4b070a Binary files /dev/null and b/images/main_toolbar/forward_disabled.png differ diff --git a/images/main_toolbar/forward_disabled_osx.png b/images/main_toolbar/forward_disabled_osx.png new file mode 100644 index 00000000..b62d0e76 Binary files /dev/null and b/images/main_toolbar/forward_disabled_osx.png differ diff --git a/images/main_toolbar/forward_osx.png b/images/main_toolbar/forward_osx.png new file mode 100644 index 00000000..dbe0779b Binary files /dev/null and b/images/main_toolbar/forward_osx.png differ diff --git a/images/main_toolbar/forward_osx@2x.png b/images/main_toolbar/forward_osx@2x.png new file mode 100644 index 00000000..20f67351 Binary files /dev/null and b/images/main_toolbar/forward_osx@2x.png differ diff --git a/images/main_toolbar/fullscreen.png b/images/main_toolbar/fullscreen.png new file mode 100644 index 00000000..4235184f Binary files /dev/null and b/images/main_toolbar/fullscreen.png differ diff --git a/images/main_toolbar/fullscreen_osx.png b/images/main_toolbar/fullscreen_osx.png new file mode 100644 index 00000000..0b3a1d49 Binary files /dev/null and b/images/main_toolbar/fullscreen_osx.png differ diff --git a/images/main_toolbar/grid.png b/images/main_toolbar/grid.png new file mode 100644 index 00000000..6bcf639d Binary files /dev/null and b/images/main_toolbar/grid.png differ diff --git a/images/main_toolbar/grid_osx.png b/images/main_toolbar/grid_osx.png new file mode 100644 index 00000000..986b5cba Binary files /dev/null and b/images/main_toolbar/grid_osx.png differ diff --git a/images/main_toolbar/grid_osx@2x.png b/images/main_toolbar/grid_osx@2x.png new file mode 100644 index 00000000..daa81e6c Binary files /dev/null and b/images/main_toolbar/grid_osx@2x.png differ diff --git a/images/main_toolbar/help.png b/images/main_toolbar/help.png new file mode 100644 index 00000000..b3ab9914 Binary files /dev/null and b/images/main_toolbar/help.png differ diff --git a/images/main_toolbar/help_osx.png b/images/main_toolbar/help_osx.png new file mode 100644 index 00000000..87cd4008 Binary files /dev/null and b/images/main_toolbar/help_osx.png differ diff --git a/images/main_toolbar/help_osx@2x.png b/images/main_toolbar/help_osx@2x.png new file mode 100644 index 00000000..398875a3 Binary files /dev/null and b/images/main_toolbar/help_osx@2x.png differ diff --git a/images/main_toolbar/server.png b/images/main_toolbar/server.png new file mode 100644 index 00000000..98b66e5a Binary files /dev/null and b/images/main_toolbar/server.png differ diff --git a/images/main_toolbar/server_osx.png b/images/main_toolbar/server_osx.png new file mode 100644 index 00000000..0ca28a41 Binary files /dev/null and b/images/main_toolbar/server_osx.png differ diff --git a/images/main_toolbar/server_osx@2x.png b/images/main_toolbar/server_osx@2x.png new file mode 100644 index 00000000..6150248b Binary files /dev/null and b/images/main_toolbar/server_osx@2x.png differ diff --git a/images/main_toolbar/settings.png b/images/main_toolbar/settings.png new file mode 100644 index 00000000..02e7df24 Binary files /dev/null and b/images/main_toolbar/settings.png differ diff --git a/images/main_toolbar/settings_osx.png b/images/main_toolbar/settings_osx.png new file mode 100644 index 00000000..14629c4e Binary files /dev/null and b/images/main_toolbar/settings_osx.png differ diff --git a/images/main_toolbar/settings_osx@2x.png b/images/main_toolbar/settings_osx@2x.png new file mode 100644 index 00000000..add7e7a7 Binary files /dev/null and b/images/main_toolbar/settings_osx@2x.png differ diff --git a/images/new.png b/images/new.png new file mode 100644 index 00000000..7ca94411 Binary files /dev/null and b/images/new.png differ diff --git a/images/next.png b/images/next.png new file mode 100644 index 00000000..e5cc102c Binary files /dev/null and b/images/next.png differ diff --git a/images/nextComic.png b/images/nextComic.png new file mode 100644 index 00000000..43a71383 Binary files /dev/null and b/images/nextComic.png differ diff --git a/images/nextCoverPage.png b/images/nextCoverPage.png new file mode 100644 index 00000000..67e06399 Binary files /dev/null and b/images/nextCoverPage.png differ diff --git a/images/noLibrariesIcon.png b/images/noLibrariesIcon.png new file mode 100644 index 00000000..cf11b95d Binary files /dev/null and b/images/noLibrariesIcon.png differ diff --git a/images/noLibrariesLine.png b/images/noLibrariesLine.png new file mode 100644 index 00000000..18599349 Binary files /dev/null and b/images/noLibrariesLine.png differ diff --git a/images/notCover.png b/images/notCover.png new file mode 100644 index 00000000..bbd7936b Binary files /dev/null and b/images/notCover.png differ diff --git a/images/notificationsLabel.png b/images/notificationsLabel.png new file mode 100644 index 00000000..95179ebb Binary files /dev/null and b/images/notificationsLabel.png differ diff --git a/images/numPagesLabel.png b/images/numPagesLabel.png new file mode 100644 index 00000000..509e4d36 Binary files /dev/null and b/images/numPagesLabel.png differ diff --git a/images/numPagesLabelBig.png b/images/numPagesLabelBig.png new file mode 100644 index 00000000..34ee0e45 Binary files /dev/null and b/images/numPagesLabelBig.png differ diff --git a/images/numPagesLabelMedium.png b/images/numPagesLabelMedium.png new file mode 100644 index 00000000..5bec00ed Binary files /dev/null and b/images/numPagesLabelMedium.png differ diff --git a/images/onStartFlowSelection.png b/images/onStartFlowSelection.png new file mode 100644 index 00000000..0675f9da Binary files /dev/null and b/images/onStartFlowSelection.png differ diff --git a/images/onStartFlowSelection_es.png b/images/onStartFlowSelection_es.png new file mode 100644 index 00000000..401736c9 Binary files /dev/null and b/images/onStartFlowSelection_es.png differ diff --git a/images/open.png b/images/open.png new file mode 100644 index 00000000..c4b71a29 Binary files /dev/null and b/images/open.png differ diff --git a/images/openFolder.png b/images/openFolder.png new file mode 100644 index 00000000..c7bcf399 Binary files /dev/null and b/images/openFolder.png differ diff --git a/images/openInYACReader.png b/images/openInYACReader.png new file mode 100644 index 00000000..caee5d52 Binary files /dev/null and b/images/openInYACReader.png differ diff --git a/images/openLibrary.png b/images/openLibrary.png new file mode 100644 index 00000000..320e6882 Binary files /dev/null and b/images/openLibrary.png differ diff --git a/images/options.png b/images/options.png new file mode 100644 index 00000000..d49a8335 Binary files /dev/null and b/images/options.png differ diff --git a/images/prev.png b/images/prev.png new file mode 100644 index 00000000..f25e34b5 Binary files /dev/null and b/images/prev.png differ diff --git a/images/previousComic.png b/images/previousComic.png new file mode 100644 index 00000000..04925ec4 Binary files /dev/null and b/images/previousComic.png differ diff --git a/images/previousCoverPage.png b/images/previousCoverPage.png new file mode 100644 index 00000000..5a99a7e9 Binary files /dev/null and b/images/previousCoverPage.png differ diff --git a/images/properties.png b/images/properties.png new file mode 100644 index 00000000..1b2a5b52 Binary files /dev/null and b/images/properties.png differ diff --git a/images/qrMessage.png b/images/qrMessage.png new file mode 100644 index 00000000..0a3a4f13 Binary files /dev/null and b/images/qrMessage.png differ diff --git a/images/rating0.png b/images/rating0.png new file mode 100644 index 00000000..ba09981f Binary files /dev/null and b/images/rating0.png differ diff --git a/images/rating1.png b/images/rating1.png new file mode 100644 index 00000000..5210caf7 Binary files /dev/null and b/images/rating1.png differ diff --git a/images/rating2.png b/images/rating2.png new file mode 100644 index 00000000..b7f59492 Binary files /dev/null and b/images/rating2.png differ diff --git a/images/rating3.png b/images/rating3.png new file mode 100644 index 00000000..d2c312d5 Binary files /dev/null and b/images/rating3.png differ diff --git a/images/rating4.png b/images/rating4.png new file mode 100644 index 00000000..2ce6f202 Binary files /dev/null and b/images/rating4.png differ diff --git a/images/rating5.png b/images/rating5.png new file mode 100644 index 00000000..23eee225 Binary files /dev/null and b/images/rating5.png differ diff --git a/images/readRibbon.png b/images/readRibbon.png new file mode 100644 index 00000000..43bbdf7a Binary files /dev/null and b/images/readRibbon.png differ diff --git a/images/readingRibbon.png b/images/readingRibbon.png new file mode 100644 index 00000000..816f2d81 Binary files /dev/null and b/images/readingRibbon.png differ diff --git a/images/removeLibrary.png b/images/removeLibrary.png new file mode 100644 index 00000000..0a7ec0a2 Binary files /dev/null and b/images/removeLibrary.png differ diff --git a/images/removeLibraryIcon.png b/images/removeLibraryIcon.png new file mode 100644 index 00000000..1e34630c Binary files /dev/null and b/images/removeLibraryIcon.png differ diff --git a/images/rotateL.png b/images/rotateL.png new file mode 100644 index 00000000..ff02b71b Binary files /dev/null and b/images/rotateL.png differ diff --git a/images/rotateR.png b/images/rotateR.png new file mode 100644 index 00000000..0f1433f9 Binary files /dev/null and b/images/rotateR.png differ diff --git a/images/save.png b/images/save.png new file mode 100644 index 00000000..67d4f4e5 Binary files /dev/null and b/images/save.png differ diff --git a/images/searching_icon.png b/images/searching_icon.png new file mode 100644 index 00000000..95355bfc Binary files /dev/null and b/images/searching_icon.png differ diff --git a/images/selectAll.png b/images/selectAll.png new file mode 100644 index 00000000..f71b06da Binary files /dev/null and b/images/selectAll.png differ diff --git a/images/server.png b/images/server.png new file mode 100644 index 00000000..bbc11134 Binary files /dev/null and b/images/server.png differ diff --git a/images/serverConfigBackground.png b/images/serverConfigBackground.png new file mode 100644 index 00000000..c89bf73b Binary files /dev/null and b/images/serverConfigBackground.png differ diff --git a/images/setAllRead.png b/images/setAllRead.png new file mode 100644 index 00000000..d96be956 Binary files /dev/null and b/images/setAllRead.png differ diff --git a/images/setAllUnread.png b/images/setAllUnread.png new file mode 100644 index 00000000..8563e99c Binary files /dev/null and b/images/setAllUnread.png differ diff --git a/images/setBookmark.png b/images/setBookmark.png new file mode 100644 index 00000000..de235f1a Binary files /dev/null and b/images/setBookmark.png differ diff --git a/images/setRead.png b/images/setRead.png new file mode 100644 index 00000000..d049e692 Binary files /dev/null and b/images/setRead.png differ diff --git a/images/setReadButton.png b/images/setReadButton.png new file mode 100644 index 00000000..4a081b84 Binary files /dev/null and b/images/setReadButton.png differ diff --git a/images/setUnread.png b/images/setUnread.png new file mode 100644 index 00000000..7f5356db Binary files /dev/null and b/images/setUnread.png differ diff --git a/images/shortcuts.png b/images/shortcuts.png new file mode 100644 index 00000000..4b59a0ed Binary files /dev/null and b/images/shortcuts.png differ diff --git a/images/shortcuts_group_comics.png b/images/shortcuts_group_comics.png new file mode 100644 index 00000000..b0c44cd9 Binary files /dev/null and b/images/shortcuts_group_comics.png differ diff --git a/images/shortcuts_group_folders.png b/images/shortcuts_group_folders.png new file mode 100644 index 00000000..968e5a20 Binary files /dev/null and b/images/shortcuts_group_folders.png differ diff --git a/images/shortcuts_group_general.png b/images/shortcuts_group_general.png new file mode 100644 index 00000000..81c8317a Binary files /dev/null and b/images/shortcuts_group_general.png differ diff --git a/images/shortcuts_group_libraries.png b/images/shortcuts_group_libraries.png new file mode 100644 index 00000000..7c7f9b19 Binary files /dev/null and b/images/shortcuts_group_libraries.png differ diff --git a/images/shortcuts_group_mglass.png b/images/shortcuts_group_mglass.png new file mode 100644 index 00000000..4d1dde7a Binary files /dev/null and b/images/shortcuts_group_mglass.png differ diff --git a/images/shortcuts_group_page.png b/images/shortcuts_group_page.png new file mode 100644 index 00000000..a482cebb Binary files /dev/null and b/images/shortcuts_group_page.png differ diff --git a/images/shortcuts_group_reading.png b/images/shortcuts_group_reading.png new file mode 100644 index 00000000..fd520f18 Binary files /dev/null and b/images/shortcuts_group_reading.png differ diff --git a/images/shortcuts_group_visualization.png b/images/shortcuts_group_visualization.png new file mode 100644 index 00000000..927418a9 Binary files /dev/null and b/images/shortcuts_group_visualization.png differ diff --git a/images/showMarks.png b/images/showMarks.png new file mode 100644 index 00000000..ab71f70c Binary files /dev/null and b/images/showMarks.png differ diff --git a/images/shownCovers.png b/images/shownCovers.png new file mode 100644 index 00000000..089baaf0 Binary files /dev/null and b/images/shownCovers.png differ diff --git a/images/sidebar/addLabelIcon.png b/images/sidebar/addLabelIcon.png new file mode 100644 index 00000000..3145a01a Binary files /dev/null and b/images/sidebar/addLabelIcon.png differ diff --git a/images/sidebar/addLabelIcon_osx.png b/images/sidebar/addLabelIcon_osx.png new file mode 100644 index 00000000..e1d4eee2 Binary files /dev/null and b/images/sidebar/addLabelIcon_osx.png differ diff --git a/images/sidebar/addLabelIcon_osx@2x.png b/images/sidebar/addLabelIcon_osx@2x.png new file mode 100644 index 00000000..6f688eab Binary files /dev/null and b/images/sidebar/addLabelIcon_osx@2x.png differ diff --git a/images/sidebar/addNew_sidebar.png b/images/sidebar/addNew_sidebar.png new file mode 100644 index 00000000..00cdef8f Binary files /dev/null and b/images/sidebar/addNew_sidebar.png differ diff --git a/images/sidebar/addNew_sidebar_osx.png b/images/sidebar/addNew_sidebar_osx.png new file mode 100644 index 00000000..454b9fc8 Binary files /dev/null and b/images/sidebar/addNew_sidebar_osx.png differ diff --git a/images/sidebar/addNew_sidebar_osx@2x.png b/images/sidebar/addNew_sidebar_osx@2x.png new file mode 100644 index 00000000..3baf3d1b Binary files /dev/null and b/images/sidebar/addNew_sidebar_osx@2x.png differ diff --git a/images/sidebar/branch-closed.png b/images/sidebar/branch-closed.png new file mode 100644 index 00000000..5903e65b Binary files /dev/null and b/images/sidebar/branch-closed.png differ diff --git a/images/sidebar/branch-open.png b/images/sidebar/branch-open.png new file mode 100644 index 00000000..4a25b96f Binary files /dev/null and b/images/sidebar/branch-open.png differ diff --git a/images/sidebar/colapse.png b/images/sidebar/colapse.png new file mode 100644 index 00000000..b70c8171 Binary files /dev/null and b/images/sidebar/colapse.png differ diff --git a/images/sidebar/colapse_osx.png b/images/sidebar/colapse_osx.png new file mode 100644 index 00000000..96bfa372 Binary files /dev/null and b/images/sidebar/colapse_osx.png differ diff --git a/images/sidebar/colapse_osx@2x.png b/images/sidebar/colapse_osx@2x.png new file mode 100644 index 00000000..eaf7a5f4 Binary files /dev/null and b/images/sidebar/colapse_osx@2x.png differ diff --git a/images/sidebar/collapsed_branch_osx.png b/images/sidebar/collapsed_branch_osx.png new file mode 100644 index 00000000..873c7048 Binary files /dev/null and b/images/sidebar/collapsed_branch_osx.png differ diff --git a/images/sidebar/collapsed_branch_selected.png b/images/sidebar/collapsed_branch_selected.png new file mode 100644 index 00000000..9c6c6a6d Binary files /dev/null and b/images/sidebar/collapsed_branch_selected.png differ diff --git a/images/sidebar/delete_sidebar.png b/images/sidebar/delete_sidebar.png new file mode 100644 index 00000000..c68fddd3 Binary files /dev/null and b/images/sidebar/delete_sidebar.png differ diff --git a/images/sidebar/delete_sidebar_osx.png b/images/sidebar/delete_sidebar_osx.png new file mode 100644 index 00000000..6a4808d2 Binary files /dev/null and b/images/sidebar/delete_sidebar_osx.png differ diff --git a/images/sidebar/delete_sidebar_osx@2x.png b/images/sidebar/delete_sidebar_osx@2x.png new file mode 100644 index 00000000..237e4982 Binary files /dev/null and b/images/sidebar/delete_sidebar_osx@2x.png differ diff --git a/images/sidebar/expand.png b/images/sidebar/expand.png new file mode 100644 index 00000000..36a41fba Binary files /dev/null and b/images/sidebar/expand.png differ diff --git a/images/sidebar/expand_osx.png b/images/sidebar/expand_osx.png new file mode 100644 index 00000000..e537efa3 Binary files /dev/null and b/images/sidebar/expand_osx.png differ diff --git a/images/sidebar/expand_osx@2x.png b/images/sidebar/expand_osx@2x.png new file mode 100644 index 00000000..135314f8 Binary files /dev/null and b/images/sidebar/expand_osx@2x.png differ diff --git a/images/sidebar/expanded_branch_osx.png b/images/sidebar/expanded_branch_osx.png new file mode 100644 index 00000000..bc812fc7 Binary files /dev/null and b/images/sidebar/expanded_branch_osx.png differ diff --git a/images/sidebar/expanded_branch_selected.png b/images/sidebar/expanded_branch_selected.png new file mode 100644 index 00000000..89669762 Binary files /dev/null and b/images/sidebar/expanded_branch_selected.png differ diff --git a/images/sidebar/folder.png b/images/sidebar/folder.png new file mode 100644 index 00000000..22262293 Binary files /dev/null and b/images/sidebar/folder.png differ diff --git a/images/sidebar/folder_finished.png b/images/sidebar/folder_finished.png new file mode 100644 index 00000000..8313e892 Binary files /dev/null and b/images/sidebar/folder_finished.png differ diff --git a/images/sidebar/libraryIcon.png b/images/sidebar/libraryIcon.png new file mode 100644 index 00000000..fdee3b28 Binary files /dev/null and b/images/sidebar/libraryIcon.png differ diff --git a/images/sidebar/libraryIconSelected.png b/images/sidebar/libraryIconSelected.png new file mode 100644 index 00000000..ecd31b01 Binary files /dev/null and b/images/sidebar/libraryIconSelected.png differ diff --git a/images/sidebar/libraryIcon_osx.png b/images/sidebar/libraryIcon_osx.png new file mode 100644 index 00000000..ce99dde6 Binary files /dev/null and b/images/sidebar/libraryIcon_osx.png differ diff --git a/images/sidebar/libraryOptions.png b/images/sidebar/libraryOptions.png new file mode 100644 index 00000000..761b5826 Binary files /dev/null and b/images/sidebar/libraryOptions.png differ diff --git a/images/sidebar/newLibraryIcon.png b/images/sidebar/newLibraryIcon.png new file mode 100644 index 00000000..f23c0676 Binary files /dev/null and b/images/sidebar/newLibraryIcon.png differ diff --git a/images/sidebar/newLibraryIcon_osx.png b/images/sidebar/newLibraryIcon_osx.png new file mode 100644 index 00000000..60e1eed9 Binary files /dev/null and b/images/sidebar/newLibraryIcon_osx.png differ diff --git a/images/sidebar/newLibraryIcon_osx@2x.png b/images/sidebar/newLibraryIcon_osx@2x.png new file mode 100644 index 00000000..3baf3d1b Binary files /dev/null and b/images/sidebar/newLibraryIcon_osx@2x.png differ diff --git a/images/sidebar/openLibraryIcon.png b/images/sidebar/openLibraryIcon.png new file mode 100644 index 00000000..1ab86322 Binary files /dev/null and b/images/sidebar/openLibraryIcon.png differ diff --git a/images/sidebar/openLibraryIcon_osx.png b/images/sidebar/openLibraryIcon_osx.png new file mode 100644 index 00000000..51eabbfb Binary files /dev/null and b/images/sidebar/openLibraryIcon_osx.png differ diff --git a/images/sidebar/openLibraryIcon_osx@2x.png b/images/sidebar/openLibraryIcon_osx@2x.png new file mode 100644 index 00000000..da93f1f9 Binary files /dev/null and b/images/sidebar/openLibraryIcon_osx@2x.png differ diff --git a/images/sidebar/renameListIcon.png b/images/sidebar/renameListIcon.png new file mode 100644 index 00000000..ec8098da Binary files /dev/null and b/images/sidebar/renameListIcon.png differ diff --git a/images/sidebar/renameListIcon_osx.png b/images/sidebar/renameListIcon_osx.png new file mode 100644 index 00000000..8f6fffda Binary files /dev/null and b/images/sidebar/renameListIcon_osx.png differ diff --git a/images/sidebar/renameListIcon_osx@2x.png b/images/sidebar/renameListIcon_osx@2x.png new file mode 100644 index 00000000..7270703c Binary files /dev/null and b/images/sidebar/renameListIcon_osx@2x.png differ diff --git a/images/sidebar/setRoot.png b/images/sidebar/setRoot.png new file mode 100644 index 00000000..da846f78 Binary files /dev/null and b/images/sidebar/setRoot.png differ diff --git a/images/sidebar/setRoot_osx.png b/images/sidebar/setRoot_osx.png new file mode 100644 index 00000000..6101b824 Binary files /dev/null and b/images/sidebar/setRoot_osx.png differ diff --git a/images/sidebar/setRoot_osx@2x.png b/images/sidebar/setRoot_osx@2x.png new file mode 100644 index 00000000..e4a110eb Binary files /dev/null and b/images/sidebar/setRoot_osx@2x.png differ diff --git a/images/sliderAddPage.png b/images/sliderAddPage.png new file mode 100644 index 00000000..dac9b0a0 Binary files /dev/null and b/images/sliderAddPage.png differ diff --git a/images/sliderBackground.png b/images/sliderBackground.png new file mode 100644 index 00000000..385d9ed5 Binary files /dev/null and b/images/sliderBackground.png differ diff --git a/images/sliderGround.png b/images/sliderGround.png new file mode 100644 index 00000000..294d6108 Binary files /dev/null and b/images/sliderGround.png differ diff --git a/images/sliderHandle.png b/images/sliderHandle.png new file mode 100644 index 00000000..033c8658 Binary files /dev/null and b/images/sliderHandle.png differ diff --git a/images/sliderSubPage.png b/images/sliderSubPage.png new file mode 100644 index 00000000..84017df7 Binary files /dev/null and b/images/sliderSubPage.png differ diff --git a/images/social_dialog/close.png b/images/social_dialog/close.png new file mode 100644 index 00000000..28e7c24f Binary files /dev/null and b/images/social_dialog/close.png differ diff --git a/images/social_dialog/facebook.png b/images/social_dialog/facebook.png new file mode 100644 index 00000000..3d7aa8de Binary files /dev/null and b/images/social_dialog/facebook.png differ diff --git a/images/social_dialog/google+.png b/images/social_dialog/google+.png new file mode 100644 index 00000000..1d0bc355 Binary files /dev/null and b/images/social_dialog/google+.png differ diff --git a/images/social_dialog/icon.png b/images/social_dialog/icon.png new file mode 100644 index 00000000..a15c47f3 Binary files /dev/null and b/images/social_dialog/icon.png differ diff --git a/images/social_dialog/separator.png b/images/social_dialog/separator.png new file mode 100644 index 00000000..4a3b73c4 Binary files /dev/null and b/images/social_dialog/separator.png differ diff --git a/images/social_dialog/shadow.png b/images/social_dialog/shadow.png new file mode 100644 index 00000000..49b5d588 Binary files /dev/null and b/images/social_dialog/shadow.png differ diff --git a/images/social_dialog/twitter.png b/images/social_dialog/twitter.png new file mode 100644 index 00000000..4a9df502 Binary files /dev/null and b/images/social_dialog/twitter.png differ diff --git a/images/speaker.png b/images/speaker.png new file mode 100644 index 00000000..e75be689 Binary files /dev/null and b/images/speaker.png differ diff --git a/images/translatorSearch.png b/images/translatorSearch.png new file mode 100644 index 00000000..066f21e9 Binary files /dev/null and b/images/translatorSearch.png differ diff --git a/images/trash.png b/images/trash.png new file mode 100644 index 00000000..482de4a6 Binary files /dev/null and b/images/trash.png differ diff --git a/images/up.png b/images/up.png new file mode 100644 index 00000000..cae28b7e Binary files /dev/null and b/images/up.png differ diff --git a/images/updateLibrary.png b/images/updateLibrary.png new file mode 100644 index 00000000..e828b863 Binary files /dev/null and b/images/updateLibrary.png differ diff --git a/images/updateLibraryIcon.png b/images/updateLibraryIcon.png new file mode 100644 index 00000000..ff68a204 Binary files /dev/null and b/images/updateLibraryIcon.png differ diff --git a/images/updatingIcon.png b/images/updatingIcon.png new file mode 100644 index 00000000..bb4f6afb Binary files /dev/null and b/images/updatingIcon.png differ diff --git a/images/useNewFlowButton.png b/images/useNewFlowButton.png new file mode 100644 index 00000000..bd224861 Binary files /dev/null and b/images/useNewFlowButton.png differ diff --git a/images/useOldFlowButton.png b/images/useOldFlowButton.png new file mode 100644 index 00000000..ee6ac75e Binary files /dev/null and b/images/useOldFlowButton.png differ diff --git a/images/viewer_toolbar/bookmark.png b/images/viewer_toolbar/bookmark.png new file mode 100644 index 00000000..5d3dc1a6 Binary files /dev/null and b/images/viewer_toolbar/bookmark.png differ diff --git a/images/viewer_toolbar/bookmark_osx.png b/images/viewer_toolbar/bookmark_osx.png new file mode 100755 index 00000000..42a5f24a Binary files /dev/null and b/images/viewer_toolbar/bookmark_osx.png differ diff --git a/images/viewer_toolbar/bookmark_osx@2x.png b/images/viewer_toolbar/bookmark_osx@2x.png new file mode 100644 index 00000000..85427aa9 Binary files /dev/null and b/images/viewer_toolbar/bookmark_osx@2x.png differ diff --git a/images/viewer_toolbar/close.png b/images/viewer_toolbar/close.png new file mode 100644 index 00000000..187eff20 Binary files /dev/null and b/images/viewer_toolbar/close.png differ diff --git a/images/viewer_toolbar/close_osx.png b/images/viewer_toolbar/close_osx.png new file mode 100755 index 00000000..760da504 Binary files /dev/null and b/images/viewer_toolbar/close_osx.png differ diff --git a/images/viewer_toolbar/close_osx@2x.png b/images/viewer_toolbar/close_osx@2x.png new file mode 100644 index 00000000..ef3c51c0 Binary files /dev/null and b/images/viewer_toolbar/close_osx@2x.png differ diff --git a/images/viewer_toolbar/doubleMangaPage.png b/images/viewer_toolbar/doubleMangaPage.png new file mode 100644 index 00000000..a280ebdc Binary files /dev/null and b/images/viewer_toolbar/doubleMangaPage.png differ diff --git a/images/viewer_toolbar/doubleMangaPage_osx.png b/images/viewer_toolbar/doubleMangaPage_osx.png new file mode 100644 index 00000000..4e5f241e Binary files /dev/null and b/images/viewer_toolbar/doubleMangaPage_osx.png differ diff --git a/images/viewer_toolbar/doubleMangaPage_osx@2x.png b/images/viewer_toolbar/doubleMangaPage_osx@2x.png new file mode 100644 index 00000000..ffdab790 Binary files /dev/null and b/images/viewer_toolbar/doubleMangaPage_osx@2x.png differ diff --git a/images/viewer_toolbar/doublePage.png b/images/viewer_toolbar/doublePage.png new file mode 100644 index 00000000..67344d3b Binary files /dev/null and b/images/viewer_toolbar/doublePage.png differ diff --git a/images/viewer_toolbar/doublePage_osx.png b/images/viewer_toolbar/doublePage_osx.png new file mode 100755 index 00000000..ed76ee97 Binary files /dev/null and b/images/viewer_toolbar/doublePage_osx.png differ diff --git a/images/viewer_toolbar/doublePage_osx@2x.png b/images/viewer_toolbar/doublePage_osx@2x.png new file mode 100644 index 00000000..950fd95f Binary files /dev/null and b/images/viewer_toolbar/doublePage_osx@2x.png differ diff --git a/images/viewer_toolbar/flow.png b/images/viewer_toolbar/flow.png new file mode 100644 index 00000000..6f8cf403 Binary files /dev/null and b/images/viewer_toolbar/flow.png differ diff --git a/images/viewer_toolbar/flow_osx.png b/images/viewer_toolbar/flow_osx.png new file mode 100644 index 00000000..3b90b92f Binary files /dev/null and b/images/viewer_toolbar/flow_osx.png differ diff --git a/images/viewer_toolbar/flow_osx@2x.png b/images/viewer_toolbar/flow_osx@2x.png new file mode 100644 index 00000000..eeba6d29 Binary files /dev/null and b/images/viewer_toolbar/flow_osx@2x.png differ diff --git a/images/viewer_toolbar/full.png b/images/viewer_toolbar/full.png new file mode 100644 index 00000000..34d6dfe0 Binary files /dev/null and b/images/viewer_toolbar/full.png differ diff --git a/images/viewer_toolbar/full_osx.png b/images/viewer_toolbar/full_osx.png new file mode 100755 index 00000000..ab8f2766 Binary files /dev/null and b/images/viewer_toolbar/full_osx.png differ diff --git a/images/viewer_toolbar/full_osx@2x.png b/images/viewer_toolbar/full_osx@2x.png new file mode 100644 index 00000000..5436dd03 Binary files /dev/null and b/images/viewer_toolbar/full_osx@2x.png differ diff --git a/images/viewer_toolbar/goto.png b/images/viewer_toolbar/goto.png new file mode 100644 index 00000000..e451b1b0 Binary files /dev/null and b/images/viewer_toolbar/goto.png differ diff --git a/images/viewer_toolbar/goto_osx.png b/images/viewer_toolbar/goto_osx.png new file mode 100644 index 00000000..75d810ca Binary files /dev/null and b/images/viewer_toolbar/goto_osx.png differ diff --git a/images/viewer_toolbar/goto_osx@2x.png b/images/viewer_toolbar/goto_osx@2x.png new file mode 100644 index 00000000..e7d4e2ba Binary files /dev/null and b/images/viewer_toolbar/goto_osx@2x.png differ diff --git a/images/viewer_toolbar/help.png b/images/viewer_toolbar/help.png new file mode 100644 index 00000000..a3ae397d Binary files /dev/null and b/images/viewer_toolbar/help.png differ diff --git a/images/viewer_toolbar/help_osx.png b/images/viewer_toolbar/help_osx.png new file mode 100755 index 00000000..9cb2574d Binary files /dev/null and b/images/viewer_toolbar/help_osx.png differ diff --git a/images/viewer_toolbar/help_osx@2x.png b/images/viewer_toolbar/help_osx@2x.png new file mode 100644 index 00000000..28865a05 Binary files /dev/null and b/images/viewer_toolbar/help_osx@2x.png differ diff --git a/images/viewer_toolbar/info.png b/images/viewer_toolbar/info.png new file mode 100644 index 00000000..0a97b1cf Binary files /dev/null and b/images/viewer_toolbar/info.png differ diff --git a/images/viewer_toolbar/info_osx.png b/images/viewer_toolbar/info_osx.png new file mode 100755 index 00000000..f3018893 Binary files /dev/null and b/images/viewer_toolbar/info_osx.png differ diff --git a/images/viewer_toolbar/info_osx@2x.png b/images/viewer_toolbar/info_osx@2x.png new file mode 100644 index 00000000..e079aa3d Binary files /dev/null and b/images/viewer_toolbar/info_osx@2x.png differ diff --git a/images/viewer_toolbar/magnifyingGlass.png b/images/viewer_toolbar/magnifyingGlass.png new file mode 100644 index 00000000..18afa28b Binary files /dev/null and b/images/viewer_toolbar/magnifyingGlass.png differ diff --git a/images/viewer_toolbar/magnifyingGlass_osx.png b/images/viewer_toolbar/magnifyingGlass_osx.png new file mode 100755 index 00000000..ef0a57ad Binary files /dev/null and b/images/viewer_toolbar/magnifyingGlass_osx.png differ diff --git a/images/viewer_toolbar/magnifyingGlass_osx@2x.png b/images/viewer_toolbar/magnifyingGlass_osx@2x.png new file mode 100644 index 00000000..9748a4b7 Binary files /dev/null and b/images/viewer_toolbar/magnifyingGlass_osx@2x.png differ diff --git a/images/viewer_toolbar/next.png b/images/viewer_toolbar/next.png new file mode 100644 index 00000000..233507cc Binary files /dev/null and b/images/viewer_toolbar/next.png differ diff --git a/images/viewer_toolbar/next_osx.png b/images/viewer_toolbar/next_osx.png new file mode 100755 index 00000000..eb76ac9a Binary files /dev/null and b/images/viewer_toolbar/next_osx.png differ diff --git a/images/viewer_toolbar/next_osx@2x.png b/images/viewer_toolbar/next_osx@2x.png new file mode 100644 index 00000000..9a32ec51 Binary files /dev/null and b/images/viewer_toolbar/next_osx@2x.png differ diff --git a/images/viewer_toolbar/open.png b/images/viewer_toolbar/open.png new file mode 100644 index 00000000..0cd51686 Binary files /dev/null and b/images/viewer_toolbar/open.png differ diff --git a/images/viewer_toolbar/openFolder.png b/images/viewer_toolbar/openFolder.png new file mode 100644 index 00000000..fd40f6bd Binary files /dev/null and b/images/viewer_toolbar/openFolder.png differ diff --git a/images/viewer_toolbar/openFolder_osx.png b/images/viewer_toolbar/openFolder_osx.png new file mode 100644 index 00000000..0ea0222f Binary files /dev/null and b/images/viewer_toolbar/openFolder_osx.png differ diff --git a/images/viewer_toolbar/openFolder_osx@2x.png b/images/viewer_toolbar/openFolder_osx@2x.png new file mode 100644 index 00000000..4eccb17e Binary files /dev/null and b/images/viewer_toolbar/openFolder_osx@2x.png differ diff --git a/images/viewer_toolbar/openNext.png b/images/viewer_toolbar/openNext.png new file mode 100644 index 00000000..4d65863e Binary files /dev/null and b/images/viewer_toolbar/openNext.png differ diff --git a/images/viewer_toolbar/openNext_osx.png b/images/viewer_toolbar/openNext_osx.png new file mode 100644 index 00000000..120e83b6 Binary files /dev/null and b/images/viewer_toolbar/openNext_osx.png differ diff --git a/images/viewer_toolbar/openNext_osx@2x.png b/images/viewer_toolbar/openNext_osx@2x.png new file mode 100644 index 00000000..4f2fa26e Binary files /dev/null and b/images/viewer_toolbar/openNext_osx@2x.png differ diff --git a/images/viewer_toolbar/openPrevious.png b/images/viewer_toolbar/openPrevious.png new file mode 100644 index 00000000..53c703f3 Binary files /dev/null and b/images/viewer_toolbar/openPrevious.png differ diff --git a/images/viewer_toolbar/openPrevious_osx.png b/images/viewer_toolbar/openPrevious_osx.png new file mode 100644 index 00000000..d68d878e Binary files /dev/null and b/images/viewer_toolbar/openPrevious_osx.png differ diff --git a/images/viewer_toolbar/openPrevious_osx@2x.png b/images/viewer_toolbar/openPrevious_osx@2x.png new file mode 100644 index 00000000..7cc39da2 Binary files /dev/null and b/images/viewer_toolbar/openPrevious_osx@2x.png differ diff --git a/images/viewer_toolbar/open_osx.png b/images/viewer_toolbar/open_osx.png new file mode 100644 index 00000000..36a97c13 Binary files /dev/null and b/images/viewer_toolbar/open_osx.png differ diff --git a/images/viewer_toolbar/open_osx@2x.png b/images/viewer_toolbar/open_osx@2x.png new file mode 100644 index 00000000..5ad3413a Binary files /dev/null and b/images/viewer_toolbar/open_osx@2x.png differ diff --git a/images/viewer_toolbar/options.png b/images/viewer_toolbar/options.png new file mode 100644 index 00000000..2eda3a5f Binary files /dev/null and b/images/viewer_toolbar/options.png differ diff --git a/images/viewer_toolbar/options_osx.png b/images/viewer_toolbar/options_osx.png new file mode 100755 index 00000000..30be20e5 Binary files /dev/null and b/images/viewer_toolbar/options_osx.png differ diff --git a/images/viewer_toolbar/options_osx@2x.png b/images/viewer_toolbar/options_osx@2x.png new file mode 100644 index 00000000..0aff0e1f Binary files /dev/null and b/images/viewer_toolbar/options_osx@2x.png differ diff --git a/images/viewer_toolbar/previous.png b/images/viewer_toolbar/previous.png new file mode 100644 index 00000000..b30acf76 Binary files /dev/null and b/images/viewer_toolbar/previous.png differ diff --git a/images/viewer_toolbar/previous_osx.png b/images/viewer_toolbar/previous_osx.png new file mode 100755 index 00000000..6ec8b86a Binary files /dev/null and b/images/viewer_toolbar/previous_osx.png differ diff --git a/images/viewer_toolbar/previous_osx@2x.png b/images/viewer_toolbar/previous_osx@2x.png new file mode 100644 index 00000000..c65f87cc Binary files /dev/null and b/images/viewer_toolbar/previous_osx@2x.png differ diff --git a/images/viewer_toolbar/rotateL.png b/images/viewer_toolbar/rotateL.png new file mode 100644 index 00000000..a696da3e Binary files /dev/null and b/images/viewer_toolbar/rotateL.png differ diff --git a/images/viewer_toolbar/rotateL_osx.png b/images/viewer_toolbar/rotateL_osx.png new file mode 100644 index 00000000..ecd5768b Binary files /dev/null and b/images/viewer_toolbar/rotateL_osx.png differ diff --git a/images/viewer_toolbar/rotateL_osx@2x.png b/images/viewer_toolbar/rotateL_osx@2x.png new file mode 100644 index 00000000..5e296332 Binary files /dev/null and b/images/viewer_toolbar/rotateL_osx@2x.png differ diff --git a/images/viewer_toolbar/rotateR.png b/images/viewer_toolbar/rotateR.png new file mode 100644 index 00000000..38d8620e Binary files /dev/null and b/images/viewer_toolbar/rotateR.png differ diff --git a/images/viewer_toolbar/rotateR_osx.png b/images/viewer_toolbar/rotateR_osx.png new file mode 100644 index 00000000..4f39d11f Binary files /dev/null and b/images/viewer_toolbar/rotateR_osx.png differ diff --git a/images/viewer_toolbar/rotateR_osx@2x.png b/images/viewer_toolbar/rotateR_osx@2x.png new file mode 100644 index 00000000..18beffc7 Binary files /dev/null and b/images/viewer_toolbar/rotateR_osx@2x.png differ diff --git a/images/viewer_toolbar/save.png b/images/viewer_toolbar/save.png new file mode 100644 index 00000000..b48e2946 Binary files /dev/null and b/images/viewer_toolbar/save.png differ diff --git a/images/viewer_toolbar/save_osx.png b/images/viewer_toolbar/save_osx.png new file mode 100644 index 00000000..a0b1bd2f Binary files /dev/null and b/images/viewer_toolbar/save_osx.png differ diff --git a/images/viewer_toolbar/save_osx@2x.png b/images/viewer_toolbar/save_osx@2x.png new file mode 100644 index 00000000..ed23db66 Binary files /dev/null and b/images/viewer_toolbar/save_osx@2x.png differ diff --git a/images/viewer_toolbar/shortcuts.png b/images/viewer_toolbar/shortcuts.png new file mode 100644 index 00000000..43a88d5e Binary files /dev/null and b/images/viewer_toolbar/shortcuts.png differ diff --git a/images/viewer_toolbar/shortcuts_osx.png b/images/viewer_toolbar/shortcuts_osx.png new file mode 100755 index 00000000..b57f7ae1 Binary files /dev/null and b/images/viewer_toolbar/shortcuts_osx.png differ diff --git a/images/viewer_toolbar/shortcuts_osx@2x.png b/images/viewer_toolbar/shortcuts_osx@2x.png new file mode 100644 index 00000000..7e8e5f92 Binary files /dev/null and b/images/viewer_toolbar/shortcuts_osx@2x.png differ diff --git a/images/viewer_toolbar/showBookmarks.png b/images/viewer_toolbar/showBookmarks.png new file mode 100644 index 00000000..5c3cbe36 Binary files /dev/null and b/images/viewer_toolbar/showBookmarks.png differ diff --git a/images/viewer_toolbar/showBookmarks_osx.png b/images/viewer_toolbar/showBookmarks_osx.png new file mode 100755 index 00000000..34d3b5ac Binary files /dev/null and b/images/viewer_toolbar/showBookmarks_osx.png differ diff --git a/images/viewer_toolbar/showBookmarks_osx@2x.png b/images/viewer_toolbar/showBookmarks_osx@2x.png new file mode 100644 index 00000000..f7cd5014 Binary files /dev/null and b/images/viewer_toolbar/showBookmarks_osx@2x.png differ diff --git a/images/viewer_toolbar/toHeight.png b/images/viewer_toolbar/toHeight.png new file mode 100644 index 00000000..82d0121b Binary files /dev/null and b/images/viewer_toolbar/toHeight.png differ diff --git a/images/viewer_toolbar/toHeight_osx.png b/images/viewer_toolbar/toHeight_osx.png new file mode 100755 index 00000000..96b85efc Binary files /dev/null and b/images/viewer_toolbar/toHeight_osx.png differ diff --git a/images/viewer_toolbar/toHeight_osx@2x.png b/images/viewer_toolbar/toHeight_osx@2x.png new file mode 100644 index 00000000..b4eda55f Binary files /dev/null and b/images/viewer_toolbar/toHeight_osx@2x.png differ diff --git a/images/viewer_toolbar/toWidth.png b/images/viewer_toolbar/toWidth.png new file mode 100644 index 00000000..819c5811 Binary files /dev/null and b/images/viewer_toolbar/toWidth.png differ diff --git a/images/viewer_toolbar/toWidthSlider_osx.png b/images/viewer_toolbar/toWidthSlider_osx.png new file mode 100644 index 00000000..469b702b Binary files /dev/null and b/images/viewer_toolbar/toWidthSlider_osx.png differ diff --git a/images/viewer_toolbar/toWidthSlider_osx@2x.png b/images/viewer_toolbar/toWidthSlider_osx@2x.png new file mode 100644 index 00000000..a952762e Binary files /dev/null and b/images/viewer_toolbar/toWidthSlider_osx@2x.png differ diff --git a/images/viewer_toolbar/toWidth_osx.png b/images/viewer_toolbar/toWidth_osx.png new file mode 100755 index 00000000..988348c3 Binary files /dev/null and b/images/viewer_toolbar/toWidth_osx.png differ diff --git a/images/viewer_toolbar/toWidth_osx@2x.png b/images/viewer_toolbar/toWidth_osx@2x.png new file mode 100644 index 00000000..cea0b4be Binary files /dev/null and b/images/viewer_toolbar/toWidth_osx@2x.png differ diff --git a/images/viewer_toolbar/translator.png b/images/viewer_toolbar/translator.png new file mode 100644 index 00000000..05026239 Binary files /dev/null and b/images/viewer_toolbar/translator.png differ diff --git a/images/viewer_toolbar/translator_osx.png b/images/viewer_toolbar/translator_osx.png new file mode 100755 index 00000000..dc30f36f Binary files /dev/null and b/images/viewer_toolbar/translator_osx.png differ diff --git a/images/viewer_toolbar/translator_osx@2x.png b/images/viewer_toolbar/translator_osx@2x.png new file mode 100644 index 00000000..16c641c4 Binary files /dev/null and b/images/viewer_toolbar/translator_osx@2x.png differ diff --git a/images/zoom.png b/images/zoom.png new file mode 100644 index 00000000..3da230a7 Binary files /dev/null and b/images/zoom.png differ diff --git a/mktarball.sh b/mktarball.sh new file mode 100755 index 00000000..d1a84f8c --- /dev/null +++ b/mktarball.sh @@ -0,0 +1,22 @@ +#! /bin/bash +#Script to create a source tarball for YACReader distribution and packaging +#This should be run from YACReaders top source directory + +YACVERSION=8.0 +if [ -f Makefile ] +then + make distclean +fi +if [ ! -f "yacreader-${YACVERSION}-src.tar.xz" ] +then + echo "Building source tarball" +else + echo "Updating source tarball" + rm yacreader-${YACVERSION}-src.tar* #delete old tarball, since tar can't update compressed archives +fi +#Use tar's --exclude feature to make sure we get a pristine tar for distribution. +#Exclude all version control system related files and rename the top directory in the tarball using --transform. +tar cfJ yacreader-${YACVERSION}-src.tar.xz --exclude '*.rej' --exclude '*.orig' --exclude '*.gch' --exclude 'dependencies' --exclude '*.o' \ +--exclude 'yacreader*tar*' --exclude '.hg*' --exclude 'lib7zip' --exclude 'libp7zip' --exclude 'unarr-master' --exclude-vcs ./* --transform s/./yacreader-${YACVERSION}/ +#Calculate checksum to enable packagers to verify whether they are using the original tarball. +md5sum yacreader-${YACVERSION}-src.tar.xz > yacreader-${YACVERSION}-src.tar.xz.md5sum \ No newline at end of file diff --git a/release/languages/yacreader_de.qm b/release/languages/yacreader_de.qm new file mode 100644 index 00000000..0d4bdacd Binary files /dev/null and b/release/languages/yacreader_de.qm differ diff --git a/release/languages/yacreader_es.qm b/release/languages/yacreader_es.qm new file mode 100644 index 00000000..b2cee2ed Binary files /dev/null and b/release/languages/yacreader_es.qm differ diff --git a/release/languages/yacreader_fr.qm b/release/languages/yacreader_fr.qm new file mode 100644 index 00000000..cdce6a89 Binary files /dev/null and b/release/languages/yacreader_fr.qm differ diff --git a/release/languages/yacreader_nl.qm b/release/languages/yacreader_nl.qm new file mode 100644 index 00000000..aa7de11d Binary files /dev/null and b/release/languages/yacreader_nl.qm differ diff --git a/release/languages/yacreader_pt.qm b/release/languages/yacreader_pt.qm new file mode 100644 index 00000000..7a52c016 Binary files /dev/null and b/release/languages/yacreader_pt.qm differ diff --git a/release/languages/yacreader_ru.qm b/release/languages/yacreader_ru.qm new file mode 100644 index 00000000..48657328 Binary files /dev/null and b/release/languages/yacreader_ru.qm differ diff --git a/release/languages/yacreader_tr.qm b/release/languages/yacreader_tr.qm new file mode 100644 index 00000000..6f965538 Binary files /dev/null and b/release/languages/yacreader_tr.qm differ diff --git a/release/languages/yacreaderlibrary_de.qm b/release/languages/yacreaderlibrary_de.qm new file mode 100644 index 00000000..4fc47c8a Binary files /dev/null and b/release/languages/yacreaderlibrary_de.qm differ diff --git a/release/languages/yacreaderlibrary_es.qm b/release/languages/yacreaderlibrary_es.qm new file mode 100644 index 00000000..370934a5 Binary files /dev/null and b/release/languages/yacreaderlibrary_es.qm differ diff --git a/release/languages/yacreaderlibrary_fr.qm b/release/languages/yacreaderlibrary_fr.qm new file mode 100644 index 00000000..52ac0747 Binary files /dev/null and b/release/languages/yacreaderlibrary_fr.qm differ diff --git a/release/languages/yacreaderlibrary_nl.qm b/release/languages/yacreaderlibrary_nl.qm new file mode 100644 index 00000000..ef8a4669 Binary files /dev/null and b/release/languages/yacreaderlibrary_nl.qm differ diff --git a/release/languages/yacreaderlibrary_pt.qm b/release/languages/yacreaderlibrary_pt.qm new file mode 100644 index 00000000..1fcb82da Binary files /dev/null and b/release/languages/yacreaderlibrary_pt.qm differ diff --git a/release/languages/yacreaderlibrary_ru.qm b/release/languages/yacreaderlibrary_ru.qm new file mode 100644 index 00000000..e3562bfc Binary files /dev/null and b/release/languages/yacreaderlibrary_ru.qm differ diff --git a/release/languages/yacreaderlibrary_tr.qm b/release/languages/yacreaderlibrary_tr.qm new file mode 100644 index 00000000..f9493959 Binary files /dev/null and b/release/languages/yacreaderlibrary_tr.qm differ diff --git a/release/server/docroot/css/reset.css b/release/server/docroot/css/reset.css new file mode 100644 index 00000000..c269b0b5 --- /dev/null +++ b/release/server/docroot/css/reset.css @@ -0,0 +1,46 @@ +html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td +{ + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-weight: inherit; + font-style: inherit; + font-size: 100%; + font-family: inherit; + vertical-align: baseline; +} +/* remember to define focus styles! */ +:focus +{ + outline: 0; +} +body +{ + line-height: 1; + color: black; +} +ol, ul +{ + list-style: none; +} +/* tables still need 'cellspacing="0"' in the markup */ +table, td, tr +{ + border: 0; + border-collapse: separate; + border-spacing: 0; +} +caption, th, td +{ + text-align: left; + font-weight: normal; +} +blockquote:before, blockquote:after, q:before, q:after +{ + content: ""; +} +blockquote, q +{ + quotes: "" ""; +} diff --git a/release/server/docroot/css/styles_ipad.css b/release/server/docroot/css/styles_ipad.css new file mode 100644 index 00000000..1419c4b2 --- /dev/null +++ b/release/server/docroot/css/styles_ipad.css @@ -0,0 +1,466 @@ +body{ + background-color: #F5F5F5; + font-family: Arial, Helvetica, sans-serif; +} + +/* libraries */ +#contentLibraries{ + width: 400px; + border: 1px solid #C6C6C6; + background-color: white; + margin-left: auto; + margin-right: auto; + margin-top: 9px; +} + +#contentLibraries .library-icon +{ + float: left; + background-color: white; + height: 18px; + padding: 11px 19px 10px 19px; + display:block; +} + +#contentLibraries li +{ + border-bottom: 1px solid #e2e2e2; + position: relative; + list-style: none; +} + +#contentLibraries li:last-child +{ + border: none; +} + +#contentLibraries .library-link +{ + width: 311px; + height: 28px; + border: none; + padding: 11px 0 0 0px; + background-color: white; + display: block; + float:left; + font-family: Arial; + font-size: 16px; + text-decoration: none; + color: #525252 ; + overflow: hidden; +} + + #contentLibraries a +{ + position: absolute; + height: 39px; + width: 100%; + z-index: 10; + display: block; + top 0; + text-decoration: none; +} + +#contentLibraries .library-indicator +{ + float: left; + background-color: white; + height: 8px; + padding: 16px 16px 15px 16px; + display:block; +} + + +#content h1 +{ + color: #292929; + text-align: center; + font-size: 21px; +} + +#contentLibraries h1{ + color: #292929; + text-align: center; + border-bottom: 1px solid #C6C6C6; + font-size: 21px; + padding: 15px 0 16px 0; +} + +#folder-header +{ + position: fixed; + width: 100%; + height: 88px; + background-color: rgba(255,255,255,0.9); + border-bottom: 1px solid #C6C6C6; + z-index: 999; +} + +#folder-subheader1 +{ + width: 100%; + height: 40px; + margin-top: 18px; + +} + +#folder-subheader2 +{ + width: 100%; + padding-left: 16px; +} + +#topIndex +{ + position: absolute; + left: 16px; + top: 19px; +} + +#topIndex a +{ + float: left; +} + +.indicator { + margin: 0 9px; +} + +.path { + text-decoration: none; + color: #5C5C5C; + font-family: Arial, Helvetica; + font-size: 15px; + +} + +#header-combos +{ + position: absolute; + right: 15px; + top: 15px; + color: #a3a3a3; + width: 160px; +} + +#topIndex .next{ + width: 25px; + height: 19px; + border: none; + margin: 0 21px 4px 0; + padding: 5px 0 0 0; + display: block; + background: url("/images/next.png") no-repeat scroll 0 0 transparent; + background-size: 25px 19px; + padding: 0; + text-indent: -99999px; +} + +#topIndex .previous{ + width: 25px; + height: 19px; + border: none; + margin: 0 14px 4px 0; + padding: 5px 0 0 0; + display: block; + background: url("/images/prev.png") no-repeat scroll 0 0 transparent; + background-size: 25px 19px; + padding: 0; + text-indent: -99999px; +} + +#topIndex .up{ + width: 15px; + height: 19px; + border: none; + background: url("/images/up.png") no-repeat scroll 0 0 transparent; + background-size: 15px 19px; + color: #FFF; + display: block; + text-indent: -99999px; +} + +#itemContainer li +{ +float: left; +width: 242px; +height: 120px; +border: 1px solid #E2E2E2; +margin: 9px 9px 0px 0; +background-color: white; +overflow: hidden; +position: relative; +} + +.folderContent +{ + padding-top: 90px; + padding-left: 9px; +} +/* hasta aquí */ + +.folder +{ +float: left; + +} + +.cover +{ +float: left; +overflow: hidden; +} + +.mark +{ + position: absolute; + top: 0px; + margin-left: 55px; +} + +.info +{ +padding: 8px 0px 0px 0px; +float: left; +position: relative; +height: 115px; +width: 158px; + +} + +.buttons +{ + position:absolute; + bottom:0px; + left:0px; + border-top: 1px solid #e2e2e2; + padding-top: 3px; + height: 25px; + width: 162px; + font-family: Arial; + color: #6e6e6e; + font-size: 10px; +} + +.elementInfo +{ + position:absolute; + bottom:24px; + padding-top: 3px; + height: 25px; + width: 162px; + font-family: Arial; + color: #adadad; + font-size: 10px; +} + +.numPages +{ + float: left; + padding-left:8px; +} + +.comicSize +{ + float: right; + padding-right: 9px; +} + + + +#itemContainer a +{ + text-decoration: none; + + +} + +.browseButton +{ + width: 60px; + background: url("/images/browse.png") no-repeat scroll 0 0 transparent; + background-position: 1px 6px; + background-size: 7px 7px; + border: none; + text-align:right; + display: block; + float: right; + padding: 4px 10px 0 0; + color: #6e6e6e; +} + +.importButton +{ + width: 60px; + background: url("/images/download.png") no-repeat scroll 0 0 transparent; + background-position: 3px 5px; + background-size: 7px 8px; + border: none; + text-align:left; + display: block; + float: left; + margin: 0 0 0 4px; + padding: 4px 0 0 16px; + color: #6e6e6e; +} + +.readButton +{ + width: 60px; + background: url("/images/read.png") no-repeat scroll 0 0 transparent; + background-position: 18px 5px; + background-size: 7px 9px; + border: none; + text-align:right; + display: block; + float: right; + padding: 4px 10px 0 0; + color: #6e6e6e; +} + +.importedButton +{ + width: 60px; + background: url("/images/imported.png") no-repeat scroll 0 0 transparent; + background-position: 2px 6px; + background-size: 8px 6px; + border: none; + text-align:left; + display: block; + float: left; + margin: 0 0 0 4px; + padding: 4px 0 0 16px; + color: #6e6e6e; +} + + +#indexes{ + border-top: 1px solid #C6C6C6; + background-color: white; + padding: 0px; + margin: 9px 0 0 0; +} + +.index{ + background-color: white; + margin: 9px 0 9px 0; +} + + +#alphaIndex a, #pageIndex a{ + width: 29px; + height: 24px; + border: none; + margin: 0 0 9px 9px; + padding: 5px 0 0 0px; + color: #5C5C5C; + font-size: 20px; + text-align: center; + display: block; + text-decoration: none; + font-family: Arial; + border: 1px solid #E2E2E2; + text-align:center; +} + +#alphaIndex li, #pageIndex li{ + float: left; +} + +#pageIndex .current{ + color: white; + background-color: #A2A2A2; + border: 1px solid #A2A2A2; + +} + + #content h2, #contentLibraries h2{ + color: #000; + font-weight: bold; + font-size: 12px; + margin: 0 0 16px 0; + } + + .inputs_login{ + width: 256px; + height: 64px; + background: url("/images/fnd_inputs.jpg") no-repeat scroll 0 0 #FFF; + margin: 0 0 18px 0; + } + .username{ + width: 200px; + height: 24px; + background: url("/images/fnd_input_username.jpg") no-repeat scroll 0 0 #2b2b2b; + border: none; + padding: 0 0 0 44px; + margin: 5px 0 6px 8px; + font-size: 14px; + color: #6e6e6e; + } + .pass{ + width: 200px; + height: 24px; + background: url("/images/fnd_input_pass.jpg") no-repeat scroll 0 0 #2b2b2b; + border: none; + padding: 0 0 0 44px; + margin: 0 0 0 8px; + font-size: 14px; + color: #6e6e6e; + } + .button_sign{ + width: 86px; + height: 30px; + background: url("/images/bt_login.jpg") no-repeat scroll 0 0 transparent; + border: none; + margin: 0; + padding: 0; + color: #FFF; + font-size: 14px; + float: left; + } + .infor{ + color: #666; + font-size: 8px; + float: left; + width: 112px; + margin: 0 0 0 8px; + line-height: 120%; + } + +.clear{ + height: 2px; + clear: both; +} + +.title{ + font-family: Arial; + font-size: 12px; + margin: 0 0 0 6px; + color: #555555 ; + overflow: hidden; + word-wrap: break-word; + height: 80px; + text-decoration: none; +} + +#indexalpha, #indexnumber{ + + -webkit-appearance: none; + background-color: rgba(255,255,255,0); + border-radius: 0px; + border: none; + color: #a3a3a3; + font-size: 16px; + font-family: Arial, Helvetica; + height: 30px; + margin: 0 0 0 10px; + padding:0; + float: right; +} + +.comboIndicator { + float: right; + padding: 14px 0 0 0; + margin: 0 0 0 4px; + width: 5px; +} \ No newline at end of file diff --git a/release/server/docroot/css/styles_iphone.css b/release/server/docroot/css/styles_iphone.css new file mode 100644 index 00000000..200ce45f --- /dev/null +++ b/release/server/docroot/css/styles_iphone.css @@ -0,0 +1,463 @@ +body{ + background-color: #F5F5F5; + font-family: Arial, Helvetica, sans-serif; +} + +/* libraries */ +#contentLibraries{ + border: 1px solid #C6C6C6; + background-color: white; + margin-left: 20px; + margin-right: 20px; + margin-top: 9px; +} + +#contentLibraries .library-icon +{ + float: left; + background-color: white; + height: 18px; + padding: 11px 19px 10px 19px; + display:block; +} + +#contentLibraries li +{ + border-bottom: 1px solid #e2e2e2; + position: relative; + list-style: none; +} + +#contentLibraries li:last-child +{ + border: none; +} + +#contentLibraries .library-link +{ + width: 65%; + height: 28px; + border: none; + padding: 11px 0 0 0px; + background-color: white; + display: block; + float:left; + font-family: Arial; + font-size: 16px; + text-decoration: none; + color: #525252 ; + overflow: hidden; +} + + #contentLibraries a +{ + position: absolute; + height: 39px; + width: 100%; + z-index: 10; + display: block; + top 0; + text-decoration: none; +} + +#contentLibraries .library-indicator +{ + float: right; + background-color: white; + height: 8px; + padding: 16px 16px 15px 16px; + display:block; +} + + +#content h1 +{ + color: #292929; + text-align: center; + font-size: 21px; +} + +#contentLibraries h1{ + color: #292929; + text-align: center; + border-bottom: 1px solid #C6C6C6; + font-size: 21px; + padding: 15px 0 16px 0; +} + +#folder-header +{ + position: fixed; + width: 100%; + height: 88px; + background-color: rgba(255,255,255,0.9); + border-bottom: 1px solid #C6C6C6; + z-index: 999; +} + +#folder-subheader1 +{ + width: 100%; + height: 40px; + margin-top: 18px; + +} + +#folder-subheader2 +{ + width: 100%; + padding-left: 16px; +} + +#topIndex +{ + position: absolute; + left: 16px; + top: 19px; +} + +#topIndex a +{ + float: left; +} + +.indicator { + margin: 0 5px; +} + +.path { + text-decoration: none; + color: #5C5C5C; + font-family: Arial, Helvetica; + font-size: 15px; + +} + +#header-combos +{ + position: absolute; + right: 10px; + top: 15px; + color: #a3a3a3; + width: 160px; +} + +#topIndex .next{ + width: 25px; + height: 19px; + border: none; + margin: 0 21px 4px 0; + padding: 5px 0 0 0; + display: block; + background: url("/images/next.png") no-repeat scroll 0 0 transparent; + background-size: 25px 19px; + padding: 0; + text-indent: -99999px; +} + +#topIndex .previous{ + width: 25px; + height: 19px; + border: none; + margin: 0 14px 4px 0; + padding: 5px 0 0 0; + display: block; + background: url("/images/prev.png") no-repeat scroll 0 0 transparent; + background-size: 25px 19px; + padding: 0; + text-indent: -99999px; +} + +#topIndex .up{ + width: 15px; + height: 19px; + border: none; + background: url("/images/up.png") no-repeat scroll 0 0 transparent; + background-size: 15px 19px; + color: #FFF; + display: block; + text-indent: -99999px; +} + +#itemContainer li +{ + +height: 120px; +border: 1px solid #E2E2E2; +margin: 9px 10px 0px 10px; +background-color: white; +overflow: hidden; +position: relative; +} + +.folderContent +{ + padding-top: 90px; +} +/* hasta aquí */ + +.folder +{ +float: left; + +} + +.cover +{ +float: left; +overflow: hidden; +} + +.mark +{ + position: absolute; + top: 0px; + margin-left: 55px; +} + +.info +{ +padding: 8px 0px 0px 0px; + +position: relative; +height: 115px; + +padding-left: 82px; +} + +.buttons +{ + position:absolute; + bottom:0px; + left:80px; + right: 0px; + border-top: 1px solid #e2e2e2; + padding-top: 3px; + height: 25px; + font-family: Arial; + color: #6e6e6e; + font-size: 10px; +} + +.elementInfo +{ + position:absolute; + bottom:24px; + padding-top: 3px; + height: 25px; + width: 100%; + font-family: Arial; + color: #adadad; + font-size: 10px; +} + +.numPages +{ + float: left; + padding-left:8px; +} + +.comicSize +{ + float: right; + padding-right: 9px; +} + + + +#itemContainer a +{ + text-decoration: none; + + +} + +.browseButton +{ + width: 60px; + background: url("/images/browse.png") no-repeat scroll 0 0 transparent; + background-position: 1px 6px; + background-size: 7px 7px; + border: none; + text-align:right; + display: block; + float: right; + padding: 4px 10px 0 0; + color: #6e6e6e; +} + +.importButton +{ + width: 60px; + background: url("/images/download.png") no-repeat scroll 0 0 transparent; + background-position: 3px 5px; + background-size: 7px 8px; + border: none; + text-align:left; + display: block; + float: left; + margin: 0 0 0 4px; + padding: 4px 0 0 16px; + color: #6e6e6e; +} + +.readButton +{ + width: 60px; + background: url("/images/read.png") no-repeat scroll 0 0 transparent; + background-position: 18px 5px; + background-size: 7px 9px; + border: none; + text-align:right; + display: block; + float: right; + padding: 4px 10px 0 0; + color: #6e6e6e; +} + +.importedButton +{ + width: 60px; + background: url("/images/imported.png") no-repeat scroll 0 0 transparent; + background-position: 2px 6px; + background-size: 8px 6px; + border: none; + text-align:left; + display: block; + float: left; + margin: 0 0 0 4px; + padding: 4px 0 0 16px; + color: #6e6e6e; +} + + +#indexes{ + border-top: 1px solid #C6C6C6; + background-color: white; + padding: 0px; + margin: 9px 0 0 0; +} + +.index{ + background-color: white; + margin: 9px 0 9px 0; +} + + +#alphaIndex a, #pageIndex a{ + width: 29px; + height: 24px; + border: none; + margin: 0 0 9px 9px; + padding: 5px 0 0 0px; + color: #5C5C5C; + font-size: 20px; + text-align: center; + display: block; + text-decoration: none; + font-family: Arial; + border: 1px solid #E2E2E2; + text-align:center; +} + +#alphaIndex li, #pageIndex li{ + float: left; +} + +#pageIndex .current{ + color: white; + background-color: #A2A2A2; + border: 1px solid #A2A2A2; + +} + + #content h2, #contentLibraries h2{ + color: #000; + font-weight: bold; + font-size: 12px; + margin: 0 0 16px 0; + } + + .inputs_login{ + width: 256px; + height: 64px; + background: url("/images/fnd_inputs.jpg") no-repeat scroll 0 0 #FFF; + margin: 0 0 18px 0; + } + .username{ + width: 200px; + height: 24px; + background: url("/images/fnd_input_username.jpg") no-repeat scroll 0 0 #2b2b2b; + border: none; + padding: 0 0 0 44px; + margin: 5px 0 6px 8px; + font-size: 14px; + color: #6e6e6e; + } + .pass{ + width: 200px; + height: 24px; + background: url("/images/fnd_input_pass.jpg") no-repeat scroll 0 0 #2b2b2b; + border: none; + padding: 0 0 0 44px; + margin: 0 0 0 8px; + font-size: 14px; + color: #6e6e6e; + } + .button_sign{ + width: 86px; + height: 30px; + background: url("/images/bt_login.jpg") no-repeat scroll 0 0 transparent; + border: none; + margin: 0; + padding: 0; + color: #FFF; + font-size: 14px; + float: left; + } + .infor{ + color: #666; + font-size: 8px; + float: left; + width: 112px; + margin: 0 0 0 8px; + line-height: 120%; + } + +.clear{ + height: 2px; + clear: both; +} + +.title{ + font-family: Arial; + font-size: 12px; + margin: 0 0 0 6px; + color: #555555 ; + overflow: hidden; + word-wrap: break-word; + height: 65px; + text-decoration: none; +} + +#indexalpha, #indexnumber{ + + -webkit-appearance: none; + background-color: rgba(255,255,255,0); + border-radius: 0px; + border: none; + color: #a3a3a3; + font-size: 16px; + font-family: Arial, Helvetica; + height: 30px; + margin: 0 0 0 10px; + padding:0; + float: right; +} + +.comboIndicator { + float: right; + padding: 14px 0 0 0; + margin: 0 0 0 4px; + width: 5px; +} \ No newline at end of file diff --git a/release/server/docroot/images/browse.png b/release/server/docroot/images/browse.png new file mode 100644 index 00000000..9043aa9d Binary files /dev/null and b/release/server/docroot/images/browse.png differ diff --git a/release/server/docroot/images/browse@2x.png b/release/server/docroot/images/browse@2x.png new file mode 100644 index 00000000..06d5f058 Binary files /dev/null and b/release/server/docroot/images/browse@2x.png differ diff --git a/release/server/docroot/images/combo.png b/release/server/docroot/images/combo.png new file mode 100644 index 00000000..54edc9fa Binary files /dev/null and b/release/server/docroot/images/combo.png differ diff --git a/release/server/docroot/images/combo@2x.png b/release/server/docroot/images/combo@2x.png new file mode 100644 index 00000000..39e5c700 Binary files /dev/null and b/release/server/docroot/images/combo@2x.png differ diff --git a/release/server/docroot/images/download.png b/release/server/docroot/images/download.png new file mode 100644 index 00000000..10b43d66 Binary files /dev/null and b/release/server/docroot/images/download.png differ diff --git a/release/server/docroot/images/download@2x.png b/release/server/docroot/images/download@2x.png new file mode 100644 index 00000000..98c6ae38 Binary files /dev/null and b/release/server/docroot/images/download@2x.png differ diff --git a/release/server/docroot/images/f.png b/release/server/docroot/images/f.png new file mode 100644 index 00000000..32fb3867 Binary files /dev/null and b/release/server/docroot/images/f.png differ diff --git a/release/server/docroot/images/f@2x.png b/release/server/docroot/images/f@2x.png new file mode 100644 index 00000000..e388d804 Binary files /dev/null and b/release/server/docroot/images/f@2x.png differ diff --git a/release/server/docroot/images/imported.png b/release/server/docroot/images/imported.png new file mode 100644 index 00000000..1eaf45d4 Binary files /dev/null and b/release/server/docroot/images/imported.png differ diff --git a/release/server/docroot/images/imported@2x.png b/release/server/docroot/images/imported@2x.png new file mode 100644 index 00000000..41b9ad4e Binary files /dev/null and b/release/server/docroot/images/imported@2x.png differ diff --git a/release/server/docroot/images/indicator.png b/release/server/docroot/images/indicator.png new file mode 100644 index 00000000..138c77a8 Binary files /dev/null and b/release/server/docroot/images/indicator.png differ diff --git a/release/server/docroot/images/indicator@2x.png b/release/server/docroot/images/indicator@2x.png new file mode 100644 index 00000000..9f30e704 Binary files /dev/null and b/release/server/docroot/images/indicator@2x.png differ diff --git a/release/server/docroot/images/library.png b/release/server/docroot/images/library.png new file mode 100644 index 00000000..1a185057 Binary files /dev/null and b/release/server/docroot/images/library.png differ diff --git a/release/server/docroot/images/library@2x.png b/release/server/docroot/images/library@2x.png new file mode 100644 index 00000000..131046c7 Binary files /dev/null and b/release/server/docroot/images/library@2x.png differ diff --git a/release/server/docroot/images/next.png b/release/server/docroot/images/next.png new file mode 100644 index 00000000..06efccc3 Binary files /dev/null and b/release/server/docroot/images/next.png differ diff --git a/release/server/docroot/images/next@2x.png b/release/server/docroot/images/next@2x.png new file mode 100644 index 00000000..ec4feb22 Binary files /dev/null and b/release/server/docroot/images/next@2x.png differ diff --git a/release/server/docroot/images/prev.png b/release/server/docroot/images/prev.png new file mode 100644 index 00000000..43e4805e Binary files /dev/null and b/release/server/docroot/images/prev.png differ diff --git a/release/server/docroot/images/prev@2x.png b/release/server/docroot/images/prev@2x.png new file mode 100644 index 00000000..d505f4f5 Binary files /dev/null and b/release/server/docroot/images/prev@2x.png differ diff --git a/release/server/docroot/images/read.png b/release/server/docroot/images/read.png new file mode 100644 index 00000000..9465a7d5 Binary files /dev/null and b/release/server/docroot/images/read.png differ diff --git a/release/server/docroot/images/read@2x.png b/release/server/docroot/images/read@2x.png new file mode 100644 index 00000000..68ed8715 Binary files /dev/null and b/release/server/docroot/images/read@2x.png differ diff --git a/release/server/docroot/images/readMark.png b/release/server/docroot/images/readMark.png new file mode 100644 index 00000000..b672027d Binary files /dev/null and b/release/server/docroot/images/readMark.png differ diff --git a/release/server/docroot/images/readMark@2x.png b/release/server/docroot/images/readMark@2x.png new file mode 100644 index 00000000..1d9d0d3e Binary files /dev/null and b/release/server/docroot/images/readMark@2x.png differ diff --git a/release/server/docroot/images/readingMark.png b/release/server/docroot/images/readingMark.png new file mode 100644 index 00000000..e37f3c80 Binary files /dev/null and b/release/server/docroot/images/readingMark.png differ diff --git a/release/server/docroot/images/readingMark@2x.png b/release/server/docroot/images/readingMark@2x.png new file mode 100644 index 00000000..589e2e9b Binary files /dev/null and b/release/server/docroot/images/readingMark@2x.png differ diff --git a/release/server/docroot/images/up.png b/release/server/docroot/images/up.png new file mode 100644 index 00000000..b039b35f Binary files /dev/null and b/release/server/docroot/images/up.png differ diff --git a/release/server/docroot/images/up@2x.png b/release/server/docroot/images/up@2x.png new file mode 100644 index 00000000..d990ce0d Binary files /dev/null and b/release/server/docroot/images/up@2x.png differ diff --git a/release/server/docroot/login.html b/release/server/docroot/login.html new file mode 100644 index 00000000..9d5e625d --- /dev/null +++ b/release/server/docroot/login.html @@ -0,0 +1,26 @@ + + + + + + Login + + +
                  + +

                  LOGIN

                  +

                  YACREADER LIBRARY

                  + +
                  + + +

                  If you have forgotten your login information, please reset it on the YACReaderLibrary

                  +
                   
                  +
                  +
                  +
                   
                  + + \ No newline at end of file diff --git a/release/server/templates/folder_ipad.tpl b/release/server/templates/folder_ipad.tpl new file mode 100644 index 00000000..3dc57109 --- /dev/null +++ b/release/server/templates/folder_ipad.tpl @@ -0,0 +1,115 @@ + + + + + + + Folder + + +
                  +
                  + +
                  +
                  {if pageIndex} {end pageIndex} up
                  + + +
                  +

                  {folder.name}

                  +
                  + +
                  + Libraries {library.name} {loop path} {path.name} {end path} +
                  +
                  + {if pageIndex} + + + {end pageIndex} + + {if alphaIndex} + + + {end alphaIndex} + +
                  +
                  + + +
                  +
                    + {loop element} +
                  • +
                    + {element.cover.browse} {element.cover.browse.end} +
                    +
                    +

                    {element.name}

                    +
                    +
                    {element.pages} {element.size} +
                    +
                    {element.download} {element.read} {element.browse} +
                    +
                    + {element.status} +
                  • + {end element} +
                  +
                   
                  +
                  +
                  + + {if index} +
                  + {if alphaIndex} + +
                  + +
                   
                  +
                  + + {end alphaIndex} + + + {if pageIndex} + +
                  + +
                   
                  +
                  + {end pageIndex} +
                  + {end index} + + + + + diff --git a/release/server/templates/folder_iphone.tpl b/release/server/templates/folder_iphone.tpl new file mode 100644 index 00000000..86c39b76 --- /dev/null +++ b/release/server/templates/folder_iphone.tpl @@ -0,0 +1,114 @@ + + + + + + + Folder + + +
                  +
                  + +
                  +
                  {if pageIndex} {end pageIndex} up
                  + + +
                  +
                  + +
                  + Libraries {loop path} {path.name} {end path} +
                  +
                  + {if pageIndex} + + + {end pageIndex} + + {if alphaIndex} + + + {end alphaIndex} + +
                  +
                  + + +
                  +
                    + {loop element} +
                  • +
                    + {element.cover.browse} {element.cover.browse.end} +
                    +
                    +

                    {element.name}

                    +
                    +
                    {element.pages} {element.size} +
                    +
                    {element.download} {element.read} {element.browse} +
                    +
                    + {element.status} +
                  • + {end element} +
                  +
                   
                  +
                  +
                  + + {if index} +
                  + {if alphaIndex} + +
                  + +
                   
                  +
                  + + {end alphaIndex} + + + {if pageIndex} + +
                  + +
                   
                  +
                  + {end pageIndex} +
                  + {end index} + + + + + diff --git a/release/server/templates/libraries_ipad.tpl b/release/server/templates/libraries_ipad.tpl new file mode 100644 index 00000000..bd32db14 --- /dev/null +++ b/release/server/templates/libraries_ipad.tpl @@ -0,0 +1,27 @@ + + + + + + + Libraries + + +
                  +

                  Libraries

                  +

                  +

                    + {loop library} +
                  • +
                    + +
                    +   +
                     
                    +
                  • + {end library} +
                  +

                  +
                  + + \ No newline at end of file diff --git a/release/server/templates/libraries_iphone.tpl b/release/server/templates/libraries_iphone.tpl new file mode 100644 index 00000000..bd32db14 --- /dev/null +++ b/release/server/templates/libraries_iphone.tpl @@ -0,0 +1,27 @@ + + + + + + + Libraries + + +
                  +

                  Libraries

                  +

                  +

                    + {loop library} +
                  • +
                    + +
                    +   +
                     
                    +
                  • + {end library} +
                  +

                  +
                  + + \ No newline at end of file diff --git a/releaseOSX.sh b/releaseOSX.sh new file mode 100755 index 00000000..79e82966 --- /dev/null +++ b/releaseOSX.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +/Users/luisangel/my_dev/Qt5.5.0/5.5/clang_64/bin/macdeployqt YACReader.app +/Users/luisangel/my_dev/Qt5.5.0/5.5/clang_64/bin/macdeployqt YACReaderLibrary.app -qmldir=./YACReaderLibrary/qml + +#macdeployqt YACReader.app +#macdeployqt YACReaderLibrary.app + +cp -R ./utils ./YACReader.app/Contents/MacOS/ +cp -R ./utils ./YACReaderLibrary.app/Contents/MacOS/ +cp -R ./release/server ./YACReaderLibrary.app/Contents/MacOS/ +cp -R ./release/languages ./YACReader.app/Contents/MacOS/ +cp -R ./release/languages ./YACReaderLibrary.app/Contents/MacOS/ +#cd ./YACReaderLibrary.app/Contents/MacOS/ +#touch YACReaderLibrary.ini +#ln -s ../../../YACReader.app/Contents/MacOS/YACReader + diff --git a/shortcuts_management/actions_groups_model.cpp b/shortcuts_management/actions_groups_model.cpp new file mode 100644 index 00000000..cc5e1488 --- /dev/null +++ b/shortcuts_management/actions_groups_model.cpp @@ -0,0 +1,80 @@ +#include "actions_groups_model.h" + +ActionsGroupsModel::ActionsGroupsModel(QObject *parent) : + QAbstractItemModel(parent) +{ +} + +int ActionsGroupsModel::rowCount(const QModelIndex &parent) const +{ + return groups.length(); +} + +int ActionsGroupsModel::columnCount(const QModelIndex &parent) const +{ + return 1; +} + +QModelIndex ActionsGroupsModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + return createIndex(row, column); +} + +QVariant ActionsGroupsModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DecorationRole) + return QVariant(groups.at(index.row()).getIcon()); + + if (role != Qt::DisplayRole) + return QVariant(); + + return QVariant(groups[index.row()].getName()); +} + +QModelIndex ActionsGroupsModel::parent(const QModelIndex &index) const +{ + return QModelIndex(); +} + +void ActionsGroupsModel::addActionsGroup(const ActionsGroup &group) +{ + beginInsertRows(QModelIndex(),groups.length(),groups.length()); + groups.push_back(group); + endInsertRows(); +} + +QList ActionsGroupsModel::getActions(const QModelIndex &mi) +{ + if(mi.isValid()) + return groups[mi.row()].getActions(); + return QList(); +} + +//------------------------------------------------------------------- + +ActionsGroup::ActionsGroup(const QString &name, const QIcon &icon, QList &actions) + :name(name), icon(icon), actions(actions) +{ + +} + +QString ActionsGroup::getName() const +{ + return name; +} + +QIcon ActionsGroup::getIcon() const +{ + return icon; +} + +QList ActionsGroup::getActions() const +{ + return actions; +} diff --git a/shortcuts_management/actions_groups_model.h b/shortcuts_management/actions_groups_model.h new file mode 100644 index 00000000..91fb5a7c --- /dev/null +++ b/shortcuts_management/actions_groups_model.h @@ -0,0 +1,44 @@ +#ifndef ACTIONS_GROUPS_MODEL_H +#define ACTIONS_GROUPS_MODEL_H + +#include +#include + +class QAction; + +class ActionsGroup +{ +public: + ActionsGroup(const QString & name, const QIcon & icon, QList & actions); + QString getName() const; + QIcon getIcon() const; + QList getActions() const; +protected: + QString name; + QIcon icon; + QList actions; +}; + +class ActionsGroupsModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit ActionsGroupsModel(QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QModelIndex parent(const QModelIndex &index) const; + + void addActionsGroup(const ActionsGroup & group); + QList getActions(const QModelIndex & mi); +signals: + +public slots: + +protected: + QList groups; +}; + +#endif // ACTIONS_GROUPS_MODEL_H diff --git a/shortcuts_management/actions_shortcuts_model.cpp b/shortcuts_management/actions_shortcuts_model.cpp new file mode 100644 index 00000000..ba9b98bc --- /dev/null +++ b/shortcuts_management/actions_shortcuts_model.cpp @@ -0,0 +1,106 @@ +#include "actions_shortcuts_model.h" +#include "shortcuts_manager.h" + +#include + +ActionsShortcutsModel::ActionsShortcutsModel(QObject *parent) : + QAbstractItemModel(parent) +{ + +} + +int ActionsShortcutsModel::rowCount(const QModelIndex &parent) const +{ + return actions.length(); +} + +int ActionsShortcutsModel::columnCount(const QModelIndex &parent) const +{ + return 3; +} + +QModelIndex ActionsShortcutsModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + return createIndex(row, column, actions[row]); +} + +Qt::ItemFlags ActionsShortcutsModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + if(index.column() == KEYS) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant ActionsShortcutsModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DecorationRole && index.column() == ICON) + return QVariant(actions[index.row()]->icon()); + + if (role == Qt::TextAlignmentRole) + { + switch(index.column()) + { + case ICON: + return QVariant(Qt::AlignHCenter | Qt::AlignVCenter); + case NAME: + return QVariant(Qt::AlignLeft | Qt::AlignVCenter); + case KEYS: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + } + } + + if(role == Qt::ForegroundRole && index.column() == KEYS && actions[index.row()]->shortcut().isEmpty()) + return QBrush(QColor("#AAAAAA")); + + if (role != Qt::DisplayRole) + return QVariant(); + + if (index.column() == NAME) + return QVariant(actions[index.row()]->toolTip()); + if (index.column() == KEYS) + { + QKeySequence ks = actions[index.row()]->shortcut(); + if(ks.isEmpty()) + return tr("None"); + return QVariant(ks.toString(QKeySequence::NativeText)); + } + + return QVariant(); +} + +bool ActionsShortcutsModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if(index.column() == KEYS) + { + ShortcutsManager sm = ShortcutsManager::getShortcutsManager(); + if(sm.checkConflicts(value.toString(), actions[index.row()])) + emit conflict(value.toString()); + else + { + actions[index.row()]->setShortcut(value.toString()); + ShortcutsManager::getShortcutsManager().saveShortcut(actions[index.row()]); + return true; + } + } + return false; +} + +QModelIndex ActionsShortcutsModel::parent(const QModelIndex &index) const +{ + return QModelIndex(); +} + +void ActionsShortcutsModel::addActions(const QList actions) +{ + beginResetModel(); + this->actions = actions; + endResetModel(); +} diff --git a/shortcuts_management/actions_shortcuts_model.h b/shortcuts_management/actions_shortcuts_model.h new file mode 100644 index 00000000..03e3bde6 --- /dev/null +++ b/shortcuts_management/actions_shortcuts_model.h @@ -0,0 +1,38 @@ +#ifndef ACTIONS_SHORTCUTS_MODEL_H +#define ACTIONS_SHORTCUTS_MODEL_H + +#include + +class QAction; + +class ActionsShortcutsModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit ActionsShortcutsModel(QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + bool setData(const QModelIndex &index, const QVariant &value, int role); + QModelIndex parent(const QModelIndex &index) const; + + void addActions(const QList actions); + Qt::ItemFlags flags(const QModelIndex &index) const; + + + enum Columns { + ICON = 0, + NAME, + KEYS + }; +signals: + void conflict(QString); +public slots: + +protected: + QList actions; +}; + +#endif // ACTIONS_SHORTCUTS_MODEL_H diff --git a/shortcuts_management/edit_shortcut_item_delegate.cpp b/shortcuts_management/edit_shortcut_item_delegate.cpp new file mode 100644 index 00000000..14c8e906 --- /dev/null +++ b/shortcuts_management/edit_shortcut_item_delegate.cpp @@ -0,0 +1,145 @@ +#include "edit_shortcut_item_delegate.h" + +#include + +EditShortcutItemDelegate::EditShortcutItemDelegate(QObject *parent) : + QItemDelegate(parent) +{ +} + +QWidget *EditShortcutItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + KeySequenceLineEdit * editor = new KeySequenceLineEdit(parent); + connect(editor,SIGNAL(editingFinished()),this,SLOT(closeShortcutEditor())); + return editor; +} + +void EditShortcutItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + QString value = index.model()->data(index, Qt::DisplayRole).toString(); + + KeySequenceLineEdit * lineEdit = static_cast(editor); + lineEdit->setText(value); +} + +void EditShortcutItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + KeySequenceLineEdit *lineEdit = static_cast(editor); + + model->setData(index, lineEdit->text(), Qt::EditRole); +} + +void EditShortcutItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &mi) const +{ + editor->setGeometry(option.rect); +} + +bool EditShortcutItemDelegate::eventFilter(QObject* editor, QEvent* event) +{ + if(event->type()==QEvent::KeyPress) + return false; + return QItemDelegate::eventFilter(editor, event); +} + +void EditShortcutItemDelegate::closeShortcutEditor() +{ + emit commitData(static_cast(sender())); + emit closeEditor(static_cast(sender()),QAbstractItemDelegate::NoHint); +} + +//TODO uncoment commented code for enabling concatenated shortcuts +KeySequenceLineEdit::KeySequenceLineEdit(QWidget *parent) + :QLineEdit(parent)//,numKeys(0) +{ + //keys[0] = keys[1] = keys[2] = keys[3] = 0; + setAlignment(Qt::AlignRight); + + QPixmap clearPixmap(":/images/clear_shortcut.png"); + QPixmap acceptPixmap(":/images/accept_shortcut.png"); + + clearButton = new QToolButton(this); + acceptButton = new QToolButton(this); + QString buttonsStyle = "QToolButton { border: none; padding: 0px; }"; + + clearButton->setIcon(QIcon(clearPixmap)); + clearButton->setIconSize(clearPixmap.size()); + clearButton->setCursor(Qt::ArrowCursor); + clearButton->setStyleSheet(buttonsStyle); + + acceptButton->setIcon(QIcon(acceptPixmap)); + acceptButton->setIconSize(acceptPixmap.size()); + acceptButton->setCursor(Qt::ArrowCursor); + acceptButton->setStyleSheet(buttonsStyle); + + connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); + connect(acceptButton, SIGNAL(clicked()), this, SIGNAL(editingFinished())); +} + +void KeySequenceLineEdit::resizeEvent(QResizeEvent * e) +{ + QSize szClear = clearButton->sizeHint(); + //int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + int leftMargin = style()->pixelMetric(QStyle::PM_LayoutLeftMargin); + //int topMargin = style()->pixelMetric(QStyle::PM_LayoutTopMargin); + clearButton->move(0 + leftMargin,(e->size().height()-19)/2); //16 is the icon height+1blank pixel + + acceptButton->move( leftMargin + szClear.width(),(e->size().height()-19)/2); + +} + +void KeySequenceLineEdit::keyPressEvent(QKeyEvent * e) +{ + int key = e->key(); + + + //if ( numKeys > 3 || + if ( key == Qt::Key_Control || + key == Qt::Key_Shift || + key == Qt::Key_Meta || + key == Qt::Key_Alt ) + return; + + key |= translateModifiers(e->modifiers(), e->text()); + + /*switch (numKeys) { + case 0: + keys[0] = nextKey; + break; + case 1: + keys[1] = nextKey; + break; + case 2: + keys[2] = nextKey; + break; + case 3: + keys[3] = nextKey; + break; + default: + break; + }*/ + //numKeys++; + QKeySequence keySequence = QKeySequence(key); + setText(keySequence.toString(QKeySequence::NativeText)); + e->accept(); +} + +int KeySequenceLineEdit::translateModifiers(Qt::KeyboardModifiers state, + const QString &text) +{ + int result = 0; + // The shift modifier only counts when it is not used to type a symbol + // that is only reachable using the shift key anyway + if ((state & Qt::ShiftModifier) && (text.size() == 0 + || !text.at(0).isPrint() + || text.at(0).isLetterOrNumber() + || text.at(0).isSpace())) + result |= Qt::SHIFT; + if (state & Qt::ControlModifier) + result |= Qt::CTRL; + if (state & Qt::MetaModifier) + result |= Qt::META; + if (state & Qt::AltModifier) + result |= Qt::ALT; + return result; +} + diff --git a/shortcuts_management/edit_shortcut_item_delegate.h b/shortcuts_management/edit_shortcut_item_delegate.h new file mode 100644 index 00000000..7cc1e4e8 --- /dev/null +++ b/shortcuts_management/edit_shortcut_item_delegate.h @@ -0,0 +1,48 @@ +#ifndef EDIT_SHORTCUT_ITEM_DELEGATE_H +#define EDIT_SHORTCUT_ITEM_DELEGATE_H + +#include +#include +#include +#include +#include + +class KeySequenceLineEdit : public QLineEdit +{ + Q_OBJECT +public: + explicit KeySequenceLineEdit(QWidget *parent = 0); + +protected: + //int numKeys; + //int keys[4]; + void keyPressEvent(QKeyEvent *); + int translateModifiers(Qt::KeyboardModifiers state, const QString &text); + void resizeEvent(QResizeEvent *); + +private: + QToolButton *clearButton; + QToolButton *acceptButton; +}; + +class EditShortcutItemDelegate : public QItemDelegate +{ + Q_OBJECT +public: + explicit EditShortcutItemDelegate(QObject *parent = 0); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & mi) const; + bool eventFilter(QObject *editor, QEvent *event); +signals: + +public slots: + void closeShortcutEditor(); + +}; + +#endif // EDIT_SHORTCUT_ITEM_DELEGATE_H diff --git a/shortcuts_management/edit_shortcuts_dialog.cpp b/shortcuts_management/edit_shortcuts_dialog.cpp new file mode 100644 index 00000000..46dea7a6 --- /dev/null +++ b/shortcuts_management/edit_shortcuts_dialog.cpp @@ -0,0 +1,95 @@ +#include "edit_shortcuts_dialog.h" + +#include "actions_groups_model.h" +#include "actions_shortcuts_model.h" +#include "edit_shortcut_item_delegate.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "QsLog.h" + +EditShortcutsDialog::EditShortcutsDialog(QWidget *parent) : + QDialog(parent) +{ + QPushButton * resetButton = new QPushButton(tr("Restore defaults"),this); + QLabel * infoLabel = new QLabel(tr("To change a shortcut, double click in the key combination and type the new keys.")); + QVBoxLayout * layout = new QVBoxLayout(this); + QSplitter * splitter = new QSplitter(this); + actionsGroupsListView = new QListView(this); + + actionsTableView = new QTableView(this); + actionsTableView->verticalHeader()->setHidden(true); + actionsTableView->horizontalHeader()->setHidden(true); + splitter->addWidget(actionsGroupsListView); + splitter->addWidget(actionsTableView); + splitter->setStretchFactor(1,1); + splitter->setSizes(QList() << 200 << 400); + + layout->addWidget(infoLabel,0); + layout->addWidget(splitter,1); + layout->addWidget(resetButton,0,Qt::AlignRight); + + setLayout(layout); + + groupsModel = new ActionsGroupsModel(); + actionsModel = new ActionsShortcutsModel(); + actionsGroupsListView->setModel(groupsModel); + actionsGroupsListView->setFocus(); + actionsTableView->setModel(actionsModel); + actionsTableView->setColumnWidth(0,30); + actionsTableView->setColumnWidth(1,360); + //actionsTableView->horizontalHeader()->sectionResizeMode(QHeaderView::Custom); + actionsTableView->horizontalHeader()->setStretchLastSection(true); + actionsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); + actionsTableView->setShowGrid(false); + actionsTableView->setItemDelegateForColumn(ActionsShortcutsModel::KEYS,new EditShortcutItemDelegate(this)); + actionsTableView->installEventFilter(this); + /*actionsTableView->setStyleSheet("QTableView {outline: 0px;}" + "QTableView::item {outline: 0px;}"); + "QTableView {border:0px;}" + "QTableView::item:selected {outline: 0px; border: 0px;}" + "");*/ + + + connect(resetButton,SIGNAL(clicked()),this,SLOT(resetToDefaults())); + connect(actionsGroupsListView->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(loadShortcuts(QModelIndex,QModelIndex))); //clicked(QModelIndex) doesn't work :S + connect(actionsModel,SIGNAL(conflict(QString)),this,SLOT(processConflict(QString))); + +#ifdef Q_OS_MAC + setFixedSize(760,500); +#else + setFixedSize(804,500); //extra width for modifiers +#endif + setWindowTitle(tr("Shortcuts settings")); + + setModal(true); +} + +void EditShortcutsDialog::addActionsGroup(const QString &name, const QIcon &ico, QList &group) +{ + groupsModel->addActionsGroup(ActionsGroup(name,ico,group)); + if(actionsTableView->model()->rowCount()==0)//first group added + actionsGroupsListView->selectionModel()->select(groupsModel->index(0,0),QItemSelectionModel::Select); +} + +void EditShortcutsDialog::resetToDefaults() +{ + +} + +void EditShortcutsDialog::loadShortcuts(const QModelIndex &mi,const QModelIndex &mi2) +{ + actionsModel->addActions(groupsModel->getActions(mi)); +} + +void EditShortcutsDialog::processConflict(const QString &shortcutInConflict) +{ + QMessageBox::warning(this,tr("Shortcut in use"), QString(tr("The shortcut \"%1\" is already assigned to other function")).arg(shortcutInConflict)); +} diff --git a/shortcuts_management/edit_shortcuts_dialog.h b/shortcuts_management/edit_shortcuts_dialog.h new file mode 100644 index 00000000..e0debf98 --- /dev/null +++ b/shortcuts_management/edit_shortcuts_dialog.h @@ -0,0 +1,33 @@ +#ifndef EDIT_SHORTCUTS_DIALOG_H +#define EDIT_SHORTCUTS_DIALOG_H + +#include +#include + +class QListView; +class QTableView; + +class ActionsGroupsModel; +class ActionsShortcutsModel; + +class EditShortcutsDialog : public QDialog +{ + Q_OBJECT +public: + explicit EditShortcutsDialog(QWidget * parent = 0); + void addActionsGroup(const QString & name, const QIcon & ico, QList & group); +signals: + +public slots: + void resetToDefaults(); + void loadShortcuts(const QModelIndex & mi,const QModelIndex &mi2); + void processConflict(const QString & shortcutInConflict); + +protected: + QListView * actionsGroupsListView; + QTableView * actionsTableView; + ActionsGroupsModel * groupsModel; + ActionsShortcutsModel * actionsModel; +}; + +#endif // EDIT_SHORTCUTS_DIALOG_H diff --git a/shortcuts_management/shortcuts_management.pri b/shortcuts_management/shortcuts_management.pri new file mode 100644 index 00000000..d12f8fa0 --- /dev/null +++ b/shortcuts_management/shortcuts_management.pri @@ -0,0 +1,16 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +HEADERS += \ + $$PWD/edit_shortcuts_dialog.h \ + $$PWD/actions_groups_model.h \ + $$PWD/actions_shortcuts_model.h \ + $$PWD/edit_shortcut_item_delegate.h \ + $$PWD/shortcuts_manager.h + +SOURCES += \ + $$PWD/edit_shortcuts_dialog.cpp \ + $$PWD/actions_groups_model.cpp \ + $$PWD/actions_shortcuts_model.cpp \ + $$PWD/edit_shortcut_item_delegate.cpp \ + $$PWD/shortcuts_manager.cpp diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp new file mode 100644 index 00000000..bbde5df5 --- /dev/null +++ b/shortcuts_management/shortcuts_manager.cpp @@ -0,0 +1,126 @@ +#include "shortcuts_manager.h" + +#include +#include +#include "yacreader_global.h" + +ShortcutsManager::ShortcutsManager() +{ + initDefaultShorcuts(); +} + +void ShortcutsManager::initDefaultShorcuts() +{ +#ifdef YACREADER_LIBRARY + //ACTIONS + defaultShorcuts.insert(CREATE_LIBRARY_ACTION_YL,Qt::Key_A); + defaultShorcuts.insert(OPEN_LIBRARY_ACTION_YL,Qt::Key_O); + defaultShorcuts.insert(UPDATE_LIBRARY_ACTION_YL,Qt::Key_U); + defaultShorcuts.insert(RENAME_LIBRARY_ACTION_YL,Qt::Key_R); + defaultShorcuts.insert(OPEN_COMIC_ACTION_YL,Qt::Key_Return); + defaultShorcuts.insert(SHOW_HIDE_MARKS_ACTION_YL,Qt::Key_M); + defaultShorcuts.insert(TOGGLE_FULL_SCREEN_ACTION_YL,Qt::Key_F); + defaultShorcuts.insert(HELP_ABOUT_ACTION_YL,Qt::Key_F1); + defaultShorcuts.insert(SET_ROOT_INDEX_ACTION_YL,Qt::Key_0); + defaultShorcuts.insert(EXPAND_ALL_NODES_ACTION_YL,Qt::Key_Plus); + defaultShorcuts.insert(COLAPSE_ALL_NODES_ACTION_YL,Qt::Key_Minus); + defaultShorcuts.insert(OPTIONS_ACTION_YL,Qt::Key_C); + defaultShorcuts.insert(SERVER_CONFIG_ACTION_YL,Qt::Key_S); + defaultShorcuts.insert(TOGGLE_COMICS_VIEW_ACTION_YL,Qt::Key_V); + + //COMMANDS (used in keypressevent) +#else + defaultShorcuts.insert(OPEN_ACTION_Y, Qt::Key_O); + defaultShorcuts.insert(OPEN_FOLDER_ACTION_Y, Qt::CTRL | Qt::Key_O); + defaultShorcuts.insert(OPEN_PREVIOUS_COMIC_ACTION_Y, Qt::CTRL | Qt::Key_Left); + defaultShorcuts.insert(OPEN_NEXT_COMIC_ACTION_Y, Qt::CTRL | Qt::Key_Right); + defaultShorcuts.insert(PREV_ACTION_Y, Qt::Key_Left); + defaultShorcuts.insert(NEXT_ACTION_Y, Qt::Key_Right); + defaultShorcuts.insert(LEFT_ROTATION_ACTION_Y, Qt::Key_L); + defaultShorcuts.insert(RIGHT_ROTATION_ACTION_Y, Qt::Key_R); + defaultShorcuts.insert(DOUBLE_PAGE_ACTION_Y, Qt::Key_D); + defaultShorcuts.insert(DOUBLE_MANGA_PAGE_ACTION_Y, Qt::Key_J); + defaultShorcuts.insert(GO_TO_PAGE_ACTION_Y, Qt::Key_G); + defaultShorcuts.insert(OPTIONS_ACTION_Y, Qt::Key_C); + defaultShorcuts.insert(HELP_ABOUT_ACTION_Y, Qt::Key_F1); + defaultShorcuts.insert(SHOW_MAGNIFYING_GLASS_ACTION_Y, Qt::Key_Z); + defaultShorcuts.insert(SET_BOOKMARK_ACTION_Y, Qt::CTRL | Qt::Key_M); + defaultShorcuts.insert(SHOW_BOOKMARKS_ACTION_Y, Qt::Key_M); + defaultShorcuts.insert(SHOW_INFO_ACTION_Y, Qt::Key_I); + defaultShorcuts.insert(CLOSE_ACTION_Y, Qt::Key_Escape); + defaultShorcuts.insert(SHOW_DICTIONARY_ACTION_Y, Qt::Key_T); + defaultShorcuts.insert(ALWAYS_ON_TOP_ACTION_Y, Qt::Key_Q); //deprecated + defaultShorcuts.insert(ADJUST_TO_FULL_SIZE_ACTION_Y, Qt::Key_W); + defaultShorcuts.insert(SHOW_FLOW_ACTION_Y, Qt::Key_S); + + //main_window_viewer + defaultShorcuts.insert(TOGGLE_FULL_SCREEN_ACTION_Y, Qt::Key_F); + defaultShorcuts.insert(TOGGLE_TOOL_BARS_ACTION_Y, Qt::Key_H); + defaultShorcuts.insert(CHANGE_FIT_ACTION_Y, Qt::Key_A); + //viewer + defaultShorcuts.insert(AUTO_SCROLL_FORWARD_ACTION_Y, Qt::Key_Space); + defaultShorcuts.insert(AUTO_SCROLL_BACKWARD_ACTION_Y, Qt::Key_B); + defaultShorcuts.insert(MOVE_DOWN_ACTION_Y, Qt::Key_Down); + defaultShorcuts.insert(MOVE_UP_ACTION_Y, Qt::Key_Up); + defaultShorcuts.insert(GO_TO_FIRST_PAGE_ACTION_Y, Qt::Key_Home); + defaultShorcuts.insert(GO_TO_LAST_PAGE_ACTION_Y, Qt::Key_End); + //mglass + defaultShorcuts.insert(SIZE_UP_MGLASS_ACTION_Y, Qt::Key_Plus); + defaultShorcuts.insert(SIZE_DOWN_MGLASS_ACTION_Y, Qt::Key_Minus); + defaultShorcuts.insert(ZOOM_IN_MGLASS_ACTION_Y, Qt::Key_Asterisk); + defaultShorcuts.insert(ZOOM_OUT_MGLASS_ACTION_Y, Qt::Key_Underscore); + +#endif + +} + +void ShortcutsManager::resetToDefaults() +{ + //TODO reset to defaults +} + +QString ShortcutsManager::getShortcut(const QString &name) +{ +#ifdef YACREADER + QString filePath = "/YACReader.ini"; +#else + QString filePath = "/YACReaderLibrary.ini"; +#endif + QSettings s(YACReader::getSettingsPath()+filePath,QSettings::IniFormat); + s.beginGroup("shortcuts"); + + return s.value(name,defaultShorcuts.value(name)).toString(); +} + +void ShortcutsManager::saveShortcut(QAction *action) +{ +#ifdef YACREADER + QString filePath = "/YACReader.ini"; +#else + QString filePath = "/YACReaderLibrary.ini"; +#endif + QSettings s(YACReader::getSettingsPath()+filePath,QSettings::IniFormat); + s.beginGroup("shortcuts"); + + return s.setValue(action->data().toString() , action->shortcut().toString()); +} + +void ShortcutsManager::registerActions(const QList &a) +{ + actions = a; +} + +bool ShortcutsManager::checkConflicts(const QKeySequence & shortcut, const QAction *dest) +{ + if(shortcut.isEmpty()) + return false; + + foreach(QAction * action, actions) + { + if(action != dest) //if the same shortcut is setted there is no conflict + if(action->shortcut() == shortcut) + return true; + } + + return false; +} diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h new file mode 100644 index 00000000..a67851cc --- /dev/null +++ b/shortcuts_management/shortcuts_manager.h @@ -0,0 +1,136 @@ +#ifndef SHORTCUTS_MANAGER_H +#define SHORTCUTS_MANAGER_H + +#include +#include +#include +#include + + +class QAction; + +//QAction: used setData() and data() for storing (userData) an identifier for each QAction. This value is ussed in QSettings + +class ShortcutsManager +{ +private: + ShortcutsManager(); + QMap defaultShorcuts; + QList actions; //all actions registered, used for checking conflicts + + void initDefaultShorcuts(); +public: + static ShortcutsManager & getShortcutsManager() + { + static ShortcutsManager manager; + return manager; + } + + void resetToDefaults(); + QString getShortcut(const QString & name); + void saveShortcut(QAction * action); + void registerActions(const QList & actions); + bool checkConflicts(const QKeySequence &shortcut, const QAction *dest); +}; + +//ACTION NAMES YACReaderLibrary +#define BACK_ACTION_YL "BACK_ACTION_YL" +#define FORWARD_ACTION_YL "FORWARD_ACTION_YL" +#define CREATE_LIBRARY_ACTION_YL "CREATE_LIBRARY_ACTION_YL" +#define OPEN_LIBRARY_ACTION_YL "OPEN_LIBRARY_ACTION_YL" +#define EXPORT_COMICS_INFO_ACTION_YL "EXPORT_COMICS_INFO_ACTION_YL" +#define IMPORT_COMICS_INFO_ACTION_YL "IMPORT_COMICS_INFO_ACTION_YL" +#define EXPORT_LIBRARY_ACTION_YL "EXPORT_LIBRARY_ACTION_YL" +#define IMPORT_LIBRARY_ACTION_YL "IMPORT_LIBRARY_ACTION_YL" +#define UPDATE_LIBRARY_ACTION_YL "UPDATE_LIBRARY_ACTION_YL" +#define RENAME_LIBRARY_ACTION_YL "RENAME_LIBRARY_ACTION_YL" +#define REMOVE_LIBRARY_ACTION_YL "REMOVE_LIBRARY_ACTION_YL" +#define OPEN_COMIC_ACTION_YL "OPEN_COMIC_ACTION_YL" +#define SET_AS_READ_ACTION_YL "SET_AS_READ_ACTION_YL" +#define SET_AS_NON_READ_ACTION_YL "SET_AS_NON_READ_ACTION_YL" +#define SHOW_HIDE_MARKS_ACTION_YL "SHOW_HIDE_MARKS_ACTION_YL" +#define TOGGLE_FULL_SCREEN_ACTION_YL "TOGGLE_FULL_SCREEN_ACTION_YL" +#define HELP_ABOUT_ACTION_YL "HELP_ABOUT_ACTION_YL" +#define SET_ROOT_INDEX_ACTION_YL "SET_ROOT_INDEX_ACTION_YL" +#define EXPAND_ALL_NODES_ACTION_YL "EXPAND_ALL_NODES_ACTION_YL" +#define COLAPSE_ALL_NODES_ACTION_YL "COLAPSE_ALL_NODES_ACTION_YL" +#define OPTIONS_ACTION_YL "OPTIONS_ACTION_YL" +#define SERVER_CONFIG_ACTION_YL "SERVER_CONFIG_ACTION_YL" +#define TOGGLE_COMICS_VIEW_ACTION_YL "TOGGLE_COMICS_VIEW_ACTION_YL" +#define OPEN_CONTAINING_FOLDER_ACTION_YL "OPEN_CONTAINING_FOLDER_ACTION_YL" +#define SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL "SET_FOLDER_AS_NOT_COMPLETED_ACTION_YL" +#define SET_FOLDER_AS_COMPLETED_ACTION_YL "SET_FOLDER_AS_COMPLETED_ACTION_YL" +#define SET_FOLDER_AS_READ_ACTION_YL "SET_FOLDER_AS_READ_ACTION_YL" +#define SET_FOLDER_AS_UNREAD_ACTION_YL "SET_FOLDER_AS_UNREAD_ACTION_YL" +#define OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL "OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL" +#define RESET_COMIC_RATING_ACTION_YL "RESET_COMIC_RATING_ACTION_YL" +#define SELECT_ALL_COMICS_ACTION_YL "SELECT_ALL_COMICS_ACTION_YL" +#define EDIT_SELECTED_COMICS_ACTION_YL "EDIT_SELECTED_COMICS_ACTION_YL" +#define ASIGN_ORDER_ACTION_YL "ASIGN_ORDER_ACTION_YL" +#define FORCE_COVER_EXTRACTED_ACTION_YL "FORCE_COVER_EXTRACTED_ACTION_YL" +#define DELETE_COMICS_ACTION_YL "DELETE_COMICS_ACTION_YL" +#define HIDE_COMIC_VIEW_ACTION_YL "HIDE_COMIC_VIEW_ACTION_YL" +#define GET_INFO_ACTION_YL "GET_INFO_ACTION_YL" +#define SHOW_EDIT_SHORTCUTS_ACTION_YL "SHOW_EDIT_SHORTCUTS_ACTION_YL" +#define UPDATE_CURRENT_FOLDER_ACTION_YL "UPDATE_CURRENT_FOLDER_ACTION_YL" +#define ADD_FOLDER_ACTION_YL "ADD_FOLDER_ACTION_YL" +#define REMOVE_FOLDER_ACTION_YL "REMOVE_FOLDER_ACTION_YL" +#define ADD_READING_LIST_ACTION_YL "ADD_READING_LIST_ACTION_YL" +#define REMOVE_READING_LIST_ACTION_YL "REMOVE_READING_LIST_ACTION_YL" +#define ADD_LABEL_ACTION_YL "ADD_LABEL_ACTION_YL" +#define RENAME_LIST_ACTION_YL "RENAME_LIST_ACTION_YL" +#define ADD_TO_FAVORITES_ACTION_YL "ADD_TO_FAVORITES_ACTION_YL" +#define SAVE_COVERS_TO_ACTION_YL "SAVE_COVERS_TO_ACTION_YL" +//COMMANDS YACReaderLibrary + + +//ACTION NAMES YACReader +#define OPEN_ACTION_Y "OPEN_ACTION_Y" +#define OPEN_FOLDER_ACTION_Y "OPEN_FOLDER_ACTION_Y" +#define SAVE_IMAGE_ACTION_Y "SAVE_IMAGE_ACTION_Y" +#define OPEN_PREVIOUS_COMIC_ACTION_Y "OPEN_PREVIOUS_COMIC_ACTION_Y" +#define OPEN_NEXT_COMIC_ACTION_Y "OPEN_NEXT_COMIC_ACTION_Y" +#define PREV_ACTION_Y "PREV_ACTION_Y" +#define NEXT_ACTION_Y "NEXT_ACTION_Y" +#define ADJUST_HEIGHT_ACTION_Y "ADJUST_HEIGHT_Y" +#define ADJUST_WIDTH_ACTION_Y "ADJUST_WIDTH_Y" +#define LEFT_ROTATION_ACTION_Y "LEFT_ROTATION_ACTION_Y" +#define RIGHT_ROTATION_ACTION_Y "RIGHT_ROTATION_ACTION_Y" +#define DOUBLE_PAGE_ACTION_Y "DOUBLE_PAGE_ACTION_Y" +#define DOUBLE_MANGA_PAGE_ACTION_Y "DOUBLE_MANGA_PAGE_ACTION_Y" +#define GO_TO_PAGE_ACTION_Y "GO_TO_PAGE_ACTION_Y" +#define OPTIONS_ACTION_Y "OPTIONS_ACTION_Y" +#define HELP_ABOUT_ACTION_Y "HELP_ABOUT_ACTION_Y" +#define SHOW_MAGNIFYING_GLASS_ACTION_Y "SHOW_MAGNIFYING_GLASS_ACTION_Y" +#define SET_BOOKMARK_ACTION_Y "SET_BOOKMARK_ACTION_Y" +#define SHOW_BOOKMARKS_ACTION_Y "SHOW_BOOKMARKS_ACTION_Y" +#define SHOW_SHORCUTS_ACTION_Y "SHOW_SHORCUTS_ACTION_Y" +#define SHOW_INFO_ACTION_Y "SHOW_INFO_ACTION_Y" +#define CLOSE_ACTION_Y "CLOSE_ACTION_Y" +#define SHOW_DICTIONARY_ACTION_Y "SHOW_DICTIONARY_ACTION_Y" +#define ALWAYS_ON_TOP_ACTION_Y "ALWAYS_ON_TOP_ACTION_Y" +#define ADJUST_TO_FULL_SIZE_ACTION_Y "ADJUST_TO_FULL_SIZE_ACTION_Y" +#define SHOW_FLOW_ACTION_Y "SHOW_FLOW_ACTION_Y" +#define SHOW_EDIT_SHORTCUTS_ACTION_Y "SHOW_EDIT_SHORTCUTS_ACTION_Y" + +//COMMANDS YACReader +//main_viewer_window +#define TOGGLE_FULL_SCREEN_ACTION_Y "TOGGLE_FULL_SCREEN_ACTION_Y" +#define TOGGLE_TOOL_BARS_ACTION_Y "TOGGLE_TOOL_BARS_ACTION_Y" +#define CHANGE_FIT_ACTION_Y "CHANGE_FIT_ACTION_Y" +//viewer +#define AUTO_SCROLL_FORWARD_ACTION_Y "AUTO_SCROLL_FORWARD_ACTION_Y" +#define AUTO_SCROLL_BACKWARD_ACTION_Y "AUTO_SCROLL_BACKWARD_ACTION_Y" +#define MOVE_DOWN_ACTION_Y "MOVE_DOWN_ACTION_Y" +#define MOVE_UP_ACTION_Y "MOVE_UP_ACTION_Y" +#define MOVE_LEFT_ACTION_Y "MOVE_LEFT_ACTION_Y" +#define MOVE_RIGHT_ACTION_Y "MOVE_RIGHT_ACTION_Y" +#define GO_TO_FIRST_PAGE_ACTION_Y "GO_TO_FIRST_PAGE_ACTION_Y" +#define GO_TO_LAST_PAGE_ACTION_Y "GO_TO_LAST_PAGE_ACTION_Y" +//mglass +#define SIZE_UP_MGLASS_ACTION_Y "SIZE_UP_MGLASS_ACTION_Y" +#define SIZE_DOWN_MGLASS_ACTION_Y "SIZE_DOWN_MGLASS_ACTION_Y" +#define ZOOM_IN_MGLASS_ACTION_Y "ZOOM_IN_MGLASS_ACTION_Y" +#define ZOOM_OUT_MGLASS_ACTION_Y "ZOOM_OUT_MGLASS_ACTION_Y" + +#endif // SHORTCUTS_MANAGER_H diff --git a/tests/compressed_archive_test/compressed_archive_test.pro b/tests/compressed_archive_test/compressed_archive_test.pro new file mode 100644 index 00000000..a6c55cc4 --- /dev/null +++ b/tests/compressed_archive_test/compressed_archive_test.pro @@ -0,0 +1,23 @@ +TEMPLATE = app +CONFIG += console + +SOURCES += \ + main.cpp \ + +QT += core + +win32 { + LIBS += -loleaut32 -lole32 + QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT + QMAKE_LFLAGS_RELEASE += /LTCG + CONFIG -= embed_manifest_exe +} + +!CONFIG(unarr){ + include(../../compressed_archive/wrapper.pri) +} else { + include(../../compressed_archive/unarr/unarr-wrapper.pri) +} + + + diff --git a/tests/compressed_archive_test/main.cpp b/tests/compressed_archive_test/main.cpp new file mode 100644 index 00000000..f2686a51 --- /dev/null +++ b/tests/compressed_archive_test/main.cpp @@ -0,0 +1,86 @@ + +#include +#include +#include + +#include "compressed_archive.h" + +#include + +using namespace std; + + +//This program uses PROTOS Genome Test Suite c10-archive [0] for testing the CompressedArchive wrapper files support +//It tests the following formats: RAR, ZIP, TAR +//Arter downloading c10-archive-r1.iso, open it and full extract RAR_TAR.BZ2, ZIP_TAR.BZ2, TAR_TAR.BZ2 files into a folder +//This program takes the path to that folder as an argument +// +// [0] https://www.ee.oulu.fi/research/ouspg/PROTOS_Test-Suite_c10-archive#Download +// +int main(int argc, char *argv[]) +{ + if(argc < 2) + { + cout << "Usage: compressed_archive_test PATH" << endl; + return 0; + } + + //QCoreApplication app(argc, argv); + + QString s(argv[1]); + + QStringList supportedFormats; + supportedFormats << "rar"<< "zip" << "tar"; + + QElapsedTimer timer; + timer.start(); + + quint32 totalFiles = 0; + foreach (QString format, supportedFormats) { + QDir rootDir(s); + if(!rootDir.cd(format)) + { + cout << "Folder for format '" << format.toStdString() << "' not found" << endl; + continue; + } + rootDir.setFilter(QDir::Files | QDir::NoDotAndDotDot); + + QFileInfoList files = rootDir.entryInfoList(); + quint32 totalFormat = 0; + quint32 errors = 0; + quint64 init = timer.elapsed(); + + foreach(QFileInfo fileInfo, files) + { + totalFiles++; + totalFormat++; + CompressedArchive archive(fileInfo.filePath()); + if(!archive.isValid()) + errors++; + else + { + int i = archive.getNumFiles(); + cerr << i; + QList filenames = archive.getFileNames(); + if (!filenames.isEmpty()) + { + cerr << archive.getFileNames().at(0).toStdString(); + } + } + } + quint64 end = timer.elapsed(); + + + cout << "Format '" << format.toStdString() <<"'" << endl; + cout << "Total files : " << totalFormat << endl; + cout << "Errors : " << errors << endl; + cout << "Elapsed time : " << (end - init) / 1000 <<"s" << endl; + cout << endl; + } + + cout << endl; + cout << "Total time : " << timer.elapsed() / 1000 <<"s" <