diff --git a/LICENSE b/LICENSE index 86cd459..e8fa58b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,504 +1,504 @@ -GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -(This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.) - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - {description} - Copyright (C) {year} {fullname} - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random - Hacker. - - {signature of Ty Coon}, 1 April 1990 - Ty Coon, President of Vice - +GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +(This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.) + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + {signature of Ty Coon}, 1 April 1990 + Ty Coon, President of Vice + That's all there is to it! \ No newline at end of file diff --git a/README.md b/README.md index 7d3a755..bef87f1 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,29 @@ -jceAverageCalculator -==================== - -Compile with QT - - Launch, insert your JCE username and password.
- Once your logged in, go to Coure Tab and hit "ADD"
- Now you will see all your courses in a table content
-
- Edit your grade and see the average difference.
- -Optional:
- hit setting tab to select the date interval
- p.s -> you need to clear the table before.
- - Thanks to
- - - - Made by - - - - +jceAverageCalculator +==================== + +Compile with QT + + Launch, insert your JCE username and password.
+ Once your logged in, go to Coure Tab and hit "ADD"
+ Now you will see all your courses in a table content
+
+ Edit your grade and see the average difference.
+ +Optional:
+ hit setting tab to select the date interval
+ p.s -> you need to clear the table before.
+ + Thanks to
+ + + + Made by + + + + diff --git a/jceGrade.pro b/jceGrade.pro index bbb4f5e..a7183ec 100644 --- a/jceGrade.pro +++ b/jceGrade.pro @@ -1,51 +1,51 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2014-05-31T19:49:42 -# -#------------------------------------------------- - -QT += core gui network - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -TARGET = jceGrade -TEMPLATE = app -RC_FILE = appConfigure.rc -CONFIG += c++11 static console - -SOURCES += main/coursestablemanager.cpp \ - main/loginhandler.cpp \ - main/main.cpp \ - main/mainscreen.cpp \ - src/connection/qtsslsocket.cpp \ - src/user.cpp \ - src/grades/Course.cpp \ - src/grades/GradePage.cpp \ - src/grades/Page.cpp \ - src/jce/jcedate.cpp \ - src/jce/jcelogin.cpp \ - src/data/savedata.cpp - - - -HEADERS += main/coursestablemanager.h \ - main/loginhandler.h \ - main/mainscreen.h \ - src/connection/qtsslsocket.h \ - src/user.h \ - src/grades/Course.h \ - src/grades/GradePage.h \ - src/grades/Page.h \ - src/jce/jcedate.h \ - src/jce/jcelogin.h \ - src/jce/jceLoginHtmlScripts.h \ - src/data/savedata.h - - - -FORMS += \ - main/mainscreen.ui - -OTHER_FILES += - -RESOURCES += \ - resources/connectionstatus.qrc +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-31T19:49:42 +# +#------------------------------------------------- + +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +TARGET = jceGrade +TEMPLATE = app +RC_FILE = appConfigure.rc +CONFIG += c++11 static + +SOURCES += main/coursestablemanager.cpp \ + main/loginhandler.cpp \ + main/main.cpp \ + main/mainscreen.cpp \ + src/connection/qtsslsocket.cpp \ + src/user.cpp \ + src/grades/Course.cpp \ + src/grades/GradePage.cpp \ + src/grades/Page.cpp \ + src/jce/jcedate.cpp \ + src/jce/jcelogin.cpp \ + src/data/savedata.cpp + + + +HEADERS += main/coursestablemanager.h \ + main/loginhandler.h \ + main/mainscreen.h \ + src/connection/qtsslsocket.h \ + src/user.h \ + src/grades/Course.h \ + src/grades/GradePage.h \ + src/grades/Page.h \ + src/jce/jcedate.h \ + src/jce/jcelogin.h \ + src/jce/jceLoginHtmlScripts.h \ + src/data/savedata.h + + + +FORMS += \ + main/mainscreen.ui + +OTHER_FILES += + +RESOURCES += \ + resources/connectionstatus.qrc diff --git a/main/coursestablemanager.cpp b/main/coursestablemanager.cpp index 276702a..dd935bc 100644 --- a/main/coursestablemanager.cpp +++ b/main/coursestablemanager.cpp @@ -1,252 +1,252 @@ -#include "coursestablemanager.h" - -coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr) -{ - this->gp = NULL; - this->us = usrPtr; - this->courseTBL = ptr; - - /* - * Initilizing Table - */ - courseTBL->setRowCount(0); - courseTBL->setColumnCount(COURSE_FIELDS); - QStringList mz; - mz << "Serial" << "Name" << "Type" << "Points" << "Hours" << "Grade" << "Additions"; - courseTBL->setHorizontalHeaderLabels(mz); - courseTBL->verticalHeader()->setVisible(true); - courseTBL->setSelectionMode(QAbstractItemView::SingleSelection); - courseTBL->setShowGrid(true); - courseTBL->setStyleSheet("QTableView {selection-background-color: red;}"); - -} - -coursesTableManager::~coursesTableManager() -{ - courseTBL = NULL; - delete gp; - gp=NULL; -} -/** - * @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table - */ -void coursesTableManager::insertJceCoursesIntoTable() -{ - for (Course *c: *gp->getCourses()) - { - if (us->getInfluenceCourseOnly()) - { - if (isCourseInfluence(c)) - addRow(c); - } - else - addRow(c); - } -} -/** - * @brief coursesTableManager::setCoursesList creating courses list with given html page - * @param html - */ -void coursesTableManager::setCoursesList(std::string &html) -{ - gp = new GradePage(html); -} -/** - * @brief coursesTableManager::changes when user changes the table manually it updates it - * @param change string change - * @param row row index - * @param col col index - * @return if change has been done - */ -bool coursesTableManager::changes(QString change, int row, int col) -{ - - bool isNumFlag = true; - - int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt(); - for (Course *c: *gp->getCourses()) - { - if (c->getSerialNum() == serialCourse) - { - switch (col) - { - case (Course::CourseScheme::NAME): - c->setName(change.toStdString()); - break; - case (Course::CourseScheme::TYPE): - c->setType(change.toStdString()); - break; - case (Course::CourseScheme::POINTS): - { - change.toDouble(&isNumFlag); - - if (!isNumFlag) - { - courseTBL->item(row,col)->setText(QString::number(c->getPoints())); - } - else - c->setPoints(change.toDouble()); - break; - } - case (Course::CourseScheme::HOURS): - { - change.toDouble(&isNumFlag); - - if (!isNumFlag) - { - courseTBL->item(row,col)->setText(QString::number(c->getHours())); - } - else - c->setHours(change.toDouble()); - break; - } - case (Course::CourseScheme::GRADE): - { - change.toDouble(&isNumFlag); - - if (!isNumFlag) - { - courseTBL->item(row,col)->setText(QString::number(c->getGrade())); - } - else - { - if ((change.toDouble() >= 0) && (change.toDouble() <= 100)) - c->setGrade(change.toDouble()); - else - courseTBL->item(row,col)->setText(QString::number(c->getGrade())); - } - break; - } - case (Course::CourseScheme::ADDITION): - c->setAdditions(change.toStdString()); - break; - } - break; - } - } - return isNumFlag; - -} -/** - * @brief coursesTableManager::addRow adds row with given information - * @param courseToAdd if exists, add its information to table - */ -void coursesTableManager::addRow(const Course *courseToAdd) -{ - int i,j; - i = courseTBL->rowCount(); - j = 0; - QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition; - const Course * c; - if (courseToAdd != NULL) - { - c = courseToAdd; - if (!isCourseAlreadyInserted(c->getSerialNum())) - { - courseTBL->setRowCount(courseTBL->rowCount()+1); - serial = new QTableWidgetItem(QString::number(c->getSerialNum())); - serial->setFlags(serial->flags() & ~Qt::ItemIsEditable); - points = new QTableWidgetItem(QString::number(c->getPoints())); - points->setFlags(serial->flags() & ~Qt::ItemIsEditable); - hours = new QTableWidgetItem(QString::number(c->getHours())); - hours->setFlags(serial->flags() & ~Qt::ItemIsEditable); - grade = new QTableWidgetItem(QString::number(c->getGrade())); - name = new QTableWidgetItem(QString::fromStdString(c->getName())); - name->setFlags(serial->flags() & ~Qt::ItemIsEditable); - type = new QTableWidgetItem(QString::fromStdString(c->getType())); - type->setFlags(serial->flags() & ~Qt::ItemIsEditable); - addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions())); - - courseTBL->setItem(i,j++,serial); - courseTBL->setItem(i,j++,name); - courseTBL->setItem(i,j++,type); - courseTBL->setItem(i,j++,points); - courseTBL->setItem(i,j++,hours); - courseTBL->setItem(i,j++,grade); - courseTBL->setItem(i,j,addition); - - } - } - else - { - } - courseTBL->resizeColumnsToContents(); - -} -double coursesTableManager::getAvg() -{ - if (this->gp != NULL) - return gp->getAvg(); - return 0; -} - - -void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus) -{ - if (ignoreCourseStatus) - { - int i = 0; - while (i < courseTBL->rowCount()) - { - if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0) - courseTBL->removeRow(i--); - i++; - } - } - else - { - for (Course *c: *gp->getCourses()) - { - if (!(isCourseAlreadyInserted(c->getSerialNum()))) - if (c->getPoints() == 0) - addRow(c); - } - } - -} - -void coursesTableManager::clearTable() -{ - if (courseTBL->rowCount() == 0) - return; - - int i = 0; //starting point - while (courseTBL->rowCount() > i) - { - gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString()); - courseTBL->removeRow(i); - } - gp = NULL; - courseTBL->repaint(); -} - -Course *coursesTableManager::getCourseByRow(int row) -{ - QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text(); - for (Course *c: *gp->getCourses()) - { - if (c->getSerialNum() == courseSerial.toDouble()) - return c; - } - return NULL; -} - -bool coursesTableManager::isCourseAlreadyInserted(double courseID) -{ - int i=0; - for (i = 0; i < courseTBL->rowCount(); ++i) - { - QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text(); - if (QString::number(courseID) == courseSerial) - return true; - } - return false; -} - -bool coursesTableManager::isCourseInfluence(const Course *courseToCheck) -{ - if (courseToCheck->getPoints() > 0) - return true; - return false; - -} +#include "coursestablemanager.h" + +coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr) +{ + this->gp = NULL; + this->us = usrPtr; + this->courseTBL = ptr; + + /* + * Initilizing Table + */ + courseTBL->setRowCount(0); + courseTBL->setColumnCount(COURSE_FIELDS); + QStringList mz; + mz << "Serial" << "Name" << "Type" << "Points" << "Hours" << "Grade" << "Additions"; + courseTBL->setHorizontalHeaderLabels(mz); + courseTBL->verticalHeader()->setVisible(true); + courseTBL->setSelectionMode(QAbstractItemView::SingleSelection); + courseTBL->setShowGrid(true); + courseTBL->setStyleSheet("QTableView {selection-background-color: red;}"); + +} + +coursesTableManager::~coursesTableManager() +{ + courseTBL = NULL; + delete gp; + gp=NULL; +} +/** + * @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table + */ +void coursesTableManager::insertJceCoursesIntoTable() +{ + for (Course *c: *gp->getCourses()) + { + if (us->getInfluenceCourseOnly()) + { + if (isCourseInfluence(c)) + addRow(c); + } + else + addRow(c); + } +} +/** + * @brief coursesTableManager::setCoursesList creating courses list with given html page + * @param html + */ +void coursesTableManager::setCoursesList(std::string &html) +{ + gp = new GradePage(html); +} +/** + * @brief coursesTableManager::changes when user changes the table manually it updates it + * @param change string change + * @param row row index + * @param col col index + * @return if change has been done + */ +bool coursesTableManager::changes(QString change, int row, int col) +{ + + bool isNumFlag = true; + + int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt(); + for (Course *c: *gp->getCourses()) + { + if (c->getSerialNum() == serialCourse) + { + switch (col) + { + case (Course::CourseScheme::NAME): + c->setName(change.toStdString()); + break; + case (Course::CourseScheme::TYPE): + c->setType(change.toStdString()); + break; + case (Course::CourseScheme::POINTS): + { + change.toDouble(&isNumFlag); + + if (!isNumFlag) + { + courseTBL->item(row,col)->setText(QString::number(c->getPoints())); + } + else + c->setPoints(change.toDouble()); + break; + } + case (Course::CourseScheme::HOURS): + { + change.toDouble(&isNumFlag); + + if (!isNumFlag) + { + courseTBL->item(row,col)->setText(QString::number(c->getHours())); + } + else + c->setHours(change.toDouble()); + break; + } + case (Course::CourseScheme::GRADE): + { + change.toDouble(&isNumFlag); + + if (!isNumFlag) + { + courseTBL->item(row,col)->setText(QString::number(c->getGrade())); + } + else + { + if ((change.toDouble() >= 0) && (change.toDouble() <= 100)) + c->setGrade(change.toDouble()); + else + courseTBL->item(row,col)->setText(QString::number(c->getGrade())); + } + break; + } + case (Course::CourseScheme::ADDITION): + c->setAdditions(change.toStdString()); + break; + } + break; + } + } + return isNumFlag; + +} +/** + * @brief coursesTableManager::addRow adds row with given information + * @param courseToAdd if exists, add its information to table + */ +void coursesTableManager::addRow(const Course *courseToAdd) +{ + int i,j; + i = courseTBL->rowCount(); + j = 0; + QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition; + const Course * c; + if (courseToAdd != NULL) + { + c = courseToAdd; + if (!isCourseAlreadyInserted(c->getSerialNum())) + { + courseTBL->setRowCount(courseTBL->rowCount()+1); + serial = new QTableWidgetItem(QString::number(c->getSerialNum())); + serial->setFlags(serial->flags() & ~Qt::ItemIsEditable); + points = new QTableWidgetItem(QString::number(c->getPoints())); + points->setFlags(serial->flags() & ~Qt::ItemIsEditable); + hours = new QTableWidgetItem(QString::number(c->getHours())); + hours->setFlags(serial->flags() & ~Qt::ItemIsEditable); + grade = new QTableWidgetItem(QString::number(c->getGrade())); + name = new QTableWidgetItem(QString::fromStdString(c->getName())); + name->setFlags(serial->flags() & ~Qt::ItemIsEditable); + type = new QTableWidgetItem(QString::fromStdString(c->getType())); + type->setFlags(serial->flags() & ~Qt::ItemIsEditable); + addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions())); + + courseTBL->setItem(i,j++,serial); + courseTBL->setItem(i,j++,name); + courseTBL->setItem(i,j++,type); + courseTBL->setItem(i,j++,points); + courseTBL->setItem(i,j++,hours); + courseTBL->setItem(i,j++,grade); + courseTBL->setItem(i,j,addition); + + } + } + else + { + } + courseTBL->resizeColumnsToContents(); + +} +double coursesTableManager::getAvg() +{ + if (this->gp != NULL) + return gp->getAvg(); + return 0; +} + + +void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus) +{ + if (ignoreCourseStatus) + { + int i = 0; + while (i < courseTBL->rowCount()) + { + if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0) + courseTBL->removeRow(i--); + i++; + } + } + else + { + for (Course *c: *gp->getCourses()) + { + if (!(isCourseAlreadyInserted(c->getSerialNum()))) + if (c->getPoints() == 0) + addRow(c); + } + } + +} + +void coursesTableManager::clearTable() +{ + if (courseTBL->rowCount() == 0) + return; + + int i = 0; //starting point + while (courseTBL->rowCount() > i) + { + gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString()); + courseTBL->removeRow(i); + } + gp = NULL; + courseTBL->repaint(); +} + +Course *coursesTableManager::getCourseByRow(int row) +{ + QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text(); + for (Course *c: *gp->getCourses()) + { + if (c->getSerialNum() == courseSerial.toDouble()) + return c; + } + return NULL; +} + +bool coursesTableManager::isCourseAlreadyInserted(double courseID) +{ + int i=0; + for (i = 0; i < courseTBL->rowCount(); ++i) + { + QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text(); + if (QString::number(courseID) == courseSerial) + return true; + } + return false; +} + +bool coursesTableManager::isCourseInfluence(const Course *courseToCheck) +{ + if (courseToCheck->getPoints() > 0) + return true; + return false; + +} diff --git a/main/coursestablemanager.h b/main/coursestablemanager.h index 5ce2e85..21262a1 100644 --- a/main/coursestablemanager.h +++ b/main/coursestablemanager.h @@ -1,44 +1,44 @@ -#ifndef COURSESTABLEMANAGER_H -#define COURSESTABLEMANAGER_H - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "src/grades/Course.h" -#include "src/grades/GradePage.h" -#include "src/user.h" - -class coursesTableManager -{ -public: - coursesTableManager(QTableWidget *, user *usrPtr); - ~coursesTableManager(); - void insertJceCoursesIntoTable(); - void setCoursesList(std::string &htmlPage); - bool changes(QString change, int row, int col); - void addRow(const Course * courseToAdd = 0); - double getAvg(); - - void influnceCourseChanged(bool status); - void clearTable(); - -private: - QTableWidget *courseTBL; - GradePage *gp; - user *us; - - Course * getCourseByRow(int row); - bool isCourseAlreadyInserted(double courseID); - bool isCourseInfluence(const Course *courseToCheck); -}; - -#endif // COURSESTABLEMANAGER_H +#ifndef COURSESTABLEMANAGER_H +#define COURSESTABLEMANAGER_H + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "src/grades/Course.h" +#include "src/grades/GradePage.h" +#include "src/user.h" + +class coursesTableManager +{ +public: + coursesTableManager(QTableWidget *, user *usrPtr); + ~coursesTableManager(); + void insertJceCoursesIntoTable(); + void setCoursesList(std::string &htmlPage); + bool changes(QString change, int row, int col); + void addRow(const Course * courseToAdd = 0); + double getAvg(); + + void influnceCourseChanged(bool status); + void clearTable(); + +private: + QTableWidget *courseTBL; + GradePage *gp; + user *us; + + Course * getCourseByRow(int row); + bool isCourseAlreadyInserted(double courseID); + bool isCourseInfluence(const Course *courseToCheck); +}; + +#endif // COURSESTABLEMANAGER_H diff --git a/main/loginhandler.cpp b/main/loginhandler.cpp index a7531b6..4483d22 100644 --- a/main/loginhandler.cpp +++ b/main/loginhandler.cpp @@ -1,67 +1,67 @@ -#include "loginhandler.h" - -loginHandler::loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr) -{ - this->jceLog = ptr; - this->statusLabelPtr = statusLabelPtr; - this->pswdEditPtr = pswdEditPtr; - this->usrnmEditPtr = usrnmEditPtr; -} - -bool loginHandler::makeConnection() -{ - if (this->jceLog == NULL) - { - return false; - } - try - { - jceLog->makeConnection(); - } - catch (jceLogin::jceStatus &a) - { - - if (a == jceLogin::JCE_YOU_ARE_IN) - { - return true; - } - else if (a == jceLogin::ERROR_ON_VALIDATION) - { - popMessage("check your password"); - - usrnmEditPtr->setDisabled(false); - pswdEditPtr->setDisabled(false); - - pswdEditPtr->selectAll(); - pswdEditPtr->setFocus(); - return false; - } - else if (a == jceLogin::ERROR_ON_OPEN_SOCKET) - { - popMessage("Please check your internet status"); - - jceLog->closeAll(); - - return false; - } - else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED) - { - std::cout << "error!!!!!!" << (jceLog->getPage()) << std::endl; - popMessage("You were blocked, please wait couple of minutes or contact JCE"); - jceLog->closeAll(); - - return false; - } - } - return false; -} -void loginHandler::popMessage(QString message) -{ - QMessageBox msgBox; - msgBox.setWindowTitle("Error"); - msgBox.setText(message); - msgBox.exec(); - msgBox.setFocus(); -} - - +#include "loginhandler.h" + +loginHandler::loginHandler() +{ + +} +void loginHandler::setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr) +{ + this->jceLog = ptr; + this->statusLabelPtr = statusLabelPtr; + this->pswdEditPtr = pswdEditPtr; + this->usrnmEditPtr = usrnmEditPtr; +} + +bool loginHandler::makeConnection() +{ + if (this->jceLog == NULL) + return false; + + try + { + jceLog->makeConnection(); + } + catch (jceLogin::jceStatus &a) + { + + if (a == jceLogin::JCE_YOU_ARE_IN) + { + return true; + } + else if (a == jceLogin::ERROR_ON_VALIDATION) + { + popMessage("check your password"); + + usrnmEditPtr->setDisabled(false); + pswdEditPtr->setDisabled(false); + + pswdEditPtr->selectAll(); + pswdEditPtr->setFocus(); + return false; + } + else if (a == jceLogin::ERROR_ON_OPEN_SOCKET) + { + popMessage("Please check your Internet status"); + jceLog->closeAll(); + return false; + } + else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED) + { + popMessage("You were blocked, please wait couple of minutes or contact JCE"); + jceLog->closeAll(); + + return false; + } + } + return false; +} +void loginHandler::popMessage(QString message) +{ + QMessageBox msgBox; + msgBox.setWindowTitle("Error"); + msgBox.setText(message); + msgBox.exec(); + msgBox.setFocus(); +} + + diff --git a/main/loginhandler.h b/main/loginhandler.h index 2e88fa8..d60bcec 100644 --- a/main/loginhandler.h +++ b/main/loginhandler.h @@ -1,29 +1,31 @@ -#ifndef LOGINHANDLER_H -#define LOGINHANDLER_H -#include -#include -#include -#include -#include - -#include "src/jce/jcelogin.h" - -class loginHandler -{ -public: - loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); - bool makeConnection(); - -private: - - void popMessage(QString message); - - - jceLogin *jceLog; - - QLabel *statusLabelPtr; - QLineEdit *pswdEditPtr; - QLineEdit *usrnmEditPtr; -}; - -#endif // LOGINHANDLER_H +#ifndef LOGINHANDLER_H +#define LOGINHANDLER_H +#include +#include +#include +#include +#include + +#include "src/jce/jcelogin.h" +#include "./src/data/savedata.h" + +class loginHandler +{ +public: + loginHandler(); + void setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); + bool makeConnection(); + +private: + + void popMessage(QString message); + + + jceLogin *jceLog; + + QLabel *statusLabelPtr; + QLineEdit *pswdEditPtr; + QLineEdit *usrnmEditPtr; +}; + +#endif // LOGINHANDLER_H diff --git a/main/main.cpp b/main/main.cpp index f1a5f93..db7f78f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,11 +1,11 @@ -#include "mainscreen.h" -#include - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainScreen w; - w.show(); - - return a.exec(); -} +#include "mainscreen.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainScreen w; + w.show(); + + return a.exec(); +} diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index 803fad7..8689104 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -1,268 +1,286 @@ -#include "mainscreen.h" -#include "ui_mainscreen.h" - - -MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen) -{ - ui->setupUi(this); - - this->setFixedSize(this->size()); //main not resizeable - - //Login Tab - ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); - - //Status Bar - ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); - ButtomStatusLabel = new QLabel(this); - statusLabel = new QLabel(this); - ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight); - ui->statusBar->addPermanentWidget(ButtomStatusLabel,0); - ui->statusBar->addPermanentWidget(statusLabel,1); - setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); - - //Course and Setting Tab - ui->CoursesTab->setDisabled(true); - ui->SettingsTab->setDisabled(true); - ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); - - - - //Pointer allocating - this->jceLog = NULL; - this->userLoginSetting = new user("",""); - this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); - - - updateDates(); - -} - -MainScreen::~MainScreen() -{ - delete userLoginSetting; - delete jceLog; - delete ui; -} -void MainScreen::on_ratesButton_clicked() -{ - QTextEdit phrase; - std::string pageString; - if (this->jceLog != NULL) - { - if (jceLog->getGrades()) - { - phrase.setText(QString::fromStdString(jceLog->getPage())); - pageString = phrase.toPlainText().toStdString(); - courseTableMgr->setCoursesList(pageString); - courseTableMgr->insertJceCoursesIntoTable(); - } - } - -} - -void MainScreen::on_spinBoxFromYear_editingFinished() -{ - if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) - { - ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value()); - ui->spinBoxFromYear->setFocus(); - updateDates(); - } - else - updateDates(); -} -void MainScreen::on_spinBoxToYear_editingFinished() -{ - if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) - { - ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value()); - ui->spinBoxToYear->setFocus(); - updateDates(); - } - else - updateDates(); -} -void MainScreen::on_spinBoxFromSem_editingFinished() -{ - if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) - { - if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) - { - ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value()); - ui->spinBoxFromSem->setFocus(); - } - } - updateDates(); -} -void MainScreen::on_spinBoxToSemester_editingFinished() -{ - if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) - { - if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) - { - ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value()); - ui->spinBoxToSemester->setFocus(); - } - } - updateDates(); -} - -void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) -{ - if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) - ui->avgLCD->display(courseTableMgr->getAvg()); - else - QMessageBox::critical(this,"Error","Missmatching data"); -} - -void MainScreen::on_loginButton_clicked() -{ - if (this->jceLog == NULL) - uiSetConnectMode(); - else - { - if (jceLog->isLoginFlag() == true) - uiSetDisconnectMode(); - else - uiSetConnectMode(); - } - -} - -void MainScreen::on_checkBox_toggled(bool checked) -{ - this->userLoginSetting->setInfluenceCourseOnly(checked); - this->courseTableMgr->influnceCourseChanged(checked); -} -void MainScreen::on_usrnmLineEdit_editingFinished() -{ - ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); -} -void MainScreen::updateDates() -{ - std::string fy,ty,fs,ts; - fy = std::to_string(ui->spinBoxFromYear->value()); - ty = std::to_string(ui->spinBoxToYear->value()); - fs = std::to_string(ui->spinBoxFromSem->value()); - ts = std::to_string(ui->spinBoxToSemester->value()); - userLoginSetting->setDate(fy,fs,ty,ts); -} - -void MainScreen::uiSetDisconnectMode() -{ - setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); - ui->usrnmLineEdit->setText(""); - ui->pswdLineEdit->setText(""); - ui->usrnmLineEdit->setEnabled(true); - ui->pswdLineEdit->setEnabled(true); - - delete jceLog; - jceLog = NULL; - ui->loginButton->setText("&Login"); - this->ui->ratesButton->setDisabled(true); - return; -} - -void MainScreen::uiSetConnectMode() -{ - std::string page; - - if (this->jceLog != NULL) - delete jceLog; - - string username; - string password; - if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) - { - //add icon near to username and password to mark it - return; - } - setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS); - - username = ui->usrnmLineEdit->text().toStdString(); - password = ui->pswdLineEdit->text().toStdString(); - - ui->usrnmLineEdit->setDisabled(true); - ui->pswdLineEdit->setDisabled(true); - - userLoginSetting->setUsername(username); - userLoginSetting->setPassword(password); - - this->repaint(); - page = "connecting with username "; - page = username; - page += "and password: "; - page += password; - ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page)); - - jceLog = new jceLogin(userLoginSetting); - this->loginHandel = new loginHandler(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit); - - if (loginHandel->makeConnection() == true) - { - page = this->jceLog->getPage(); - ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page)); - setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); - ui->loginButton->setText("&Logout"); - this->ui->ratesButton->setEnabled(true); - ui->CoursesTab->setEnabled(true); - ui->SettingsTab->setEnabled(true); - } - else - { - uiSetDisconnectMode(); - } -} -void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription) -{ - QPixmap iconPix; - switch (statusDescription) - { - - case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS: - iconPix.load(":/icons/blueStatusIcon.png"); - statusLabel->setText("Connecting"); - break; - case jceLogin::jceStatus::JCE_YOU_ARE_IN: - iconPix.load(":/icons/greenStatusIcon.png"); - statusLabel->setText("Connected"); - break; - default: - iconPix.load(":/icons/redStatusIcon.png"); - statusLabel->setText("Disconnected"); - break; - } - ButtomStatusLabel->setPixmap(iconPix); - - this->repaint(); -} -void MainScreen::on_actionCredits_triggered() -{ - QMessageBox::about(this, "About", "A tiny application to calculate your grades average.

" - "This software is licensed under Qt5's
GNU LESSER GENERAL PUBLIC LICENSE V2
" - "The source code is available at github:
" - "jceAverageCalculator Repository" - "

This front end is Powered by Jce Connection

" - "Made by:" - "" - "Thanks to: " - ""); -} - -void MainScreen::on_clearTableButton_clicked() -{ - - courseTableMgr->clearTable(); - ui->avgLCD->display(courseTableMgr->getAvg()); -} - -void MainScreen::on_actionExit_triggered() -{ - exit(0); -} - +#include "mainscreen.h" +#include "ui_mainscreen.h" + + +MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen) +{ + ui->setupUi(this); + + this->setFixedSize(this->size()); //main not resizeable + + //Login Tab + ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); + + //Status Bar + ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); + ButtomStatusLabel = new QLabel(this); + statusLabel = new QLabel(this); + ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight); + ui->statusBar->addPermanentWidget(ButtomStatusLabel,0); + ui->statusBar->addPermanentWidget(statusLabel,1); + setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); + + //Course and Setting Tab + ui->CoursesTab->setDisabled(true); + ui->SettingsTab->setDisabled(true); + ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); + + + + //Pointer allocating + this->jceLog = NULL; + this->userLoginSetting = new user("",""); + this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); + this->loginHandel = new loginHandler(); + + updateDates(); + + //check login File + SaveData::init(); + if (SaveData::isSaved()) + { + ui->usrnmLineEdit->setText(SaveData::getUsername()); + ui->pswdLineEdit->setText(SaveData::getPassword()); + ui->keepLogin->setChecked(true); + } +} + +MainScreen::~MainScreen() +{ + delete userLoginSetting; + delete jceLog; + delete loginHandel; + delete ui; +} +void MainScreen::on_ratesButton_clicked() +{ + QTextEdit phrase; + std::string pageString; + if (this->jceLog != NULL) + { + if (jceLog->getGrades()) + { + phrase.setText(QString::fromStdString(jceLog->getPage())); + pageString = phrase.toPlainText().toStdString(); + courseTableMgr->setCoursesList(pageString); + courseTableMgr->insertJceCoursesIntoTable(); + } + } + +} + +void MainScreen::on_spinBoxFromYear_editingFinished() +{ + if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) + { + ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value()); + ui->spinBoxFromYear->setFocus(); + updateDates(); + } + else + updateDates(); +} +void MainScreen::on_spinBoxToYear_editingFinished() +{ + if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) + { + ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value()); + ui->spinBoxToYear->setFocus(); + updateDates(); + } + else + updateDates(); +} +void MainScreen::on_spinBoxFromSem_editingFinished() +{ + if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) + { + if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) + { + ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value()); + ui->spinBoxFromSem->setFocus(); + } + } + updateDates(); +} +void MainScreen::on_spinBoxToSemester_editingFinished() +{ + if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) + { + if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) + { + ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value()); + ui->spinBoxToSemester->setFocus(); + } + } + updateDates(); +} + +void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) +{ + if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) + ui->avgLCD->display(courseTableMgr->getAvg()); + else + QMessageBox::critical(this,"Error","Missmatching data"); +} + +void MainScreen::on_loginButton_clicked() +{ + if (this->jceLog == NULL) + uiSetConnectMode(); + else + { + if (jceLog->isLoginFlag() == true) + uiSetDisconnectMode(); + else + uiSetConnectMode(); + } + +} + +void MainScreen::on_checkBox_toggled(bool checked) +{ + this->userLoginSetting->setInfluenceCourseOnly(checked); + this->courseTableMgr->influnceCourseChanged(checked); +} +void MainScreen::on_usrnmLineEdit_editingFinished() +{ + ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); +} +void MainScreen::updateDates() +{ + std::string fy,ty,fs,ts; + fy = std::to_string(ui->spinBoxFromYear->value()); + ty = std::to_string(ui->spinBoxToYear->value()); + fs = std::to_string(ui->spinBoxFromSem->value()); + ts = std::to_string(ui->spinBoxToSemester->value()); + userLoginSetting->setDate(fy,fs,ty,ts); +} + +void MainScreen::uiSetDisconnectMode() +{ + setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); + ui->usrnmLineEdit->setText(""); + ui->pswdLineEdit->setText(""); + ui->usrnmLineEdit->setEnabled(true); + ui->pswdLineEdit->setEnabled(true); + + delete jceLog; + jceLog = NULL; + ui->loginButton->setText("&Login"); + this->ui->ratesButton->setDisabled(true); + return; +} + +void MainScreen::uiSetConnectMode() //fix before distrbute +{ + std::string page; + + if (this->jceLog != NULL) + delete jceLog; + + string username; + string password; + if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) + { + //add icon near to username and password to mark it + return; + } + setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS); + + username = ui->usrnmLineEdit->text().toStdString(); + password = ui->pswdLineEdit->text().toStdString(); + + ui->usrnmLineEdit->setDisabled(true); + ui->pswdLineEdit->setDisabled(true); + + userLoginSetting->setUsername(username); + userLoginSetting->setPassword(password); + + this->repaint(); + page = "connecting with username "; + page = username; + page += "and password: "; + page += password; + ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page)); + + jceLog = new jceLogin(userLoginSetting); + this->loginHandel->setPointers(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit); + + if (loginHandel->makeConnection() == true) + { + page = this->jceLog->getPage(); + ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page)); + setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); + ui->loginButton->setText("&Logout"); + this->ui->ratesButton->setEnabled(true); + ui->CoursesTab->setEnabled(true); + ui->SettingsTab->setEnabled(true); + } + else + { + uiSetDisconnectMode(); + } +} +void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription) +{ + QPixmap iconPix; + switch (statusDescription) + { + + case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS: + iconPix.load(":/icons/blueStatusIcon.png"); + statusLabel->setText("Connecting"); + break; + case jceLogin::jceStatus::JCE_YOU_ARE_IN: + iconPix.load(":/icons/greenStatusIcon.png"); + statusLabel->setText("Connected"); + break; + default: + iconPix.load(":/icons/redStatusIcon.png"); + statusLabel->setText("Disconnected"); + break; + } + ButtomStatusLabel->setPixmap(iconPix); + + this->repaint(); +} +void MainScreen::on_actionCredits_triggered() +{ + QMessageBox::about(this, "About", "A tiny application to calculate your grades average.

" + "This software is licensed under Qt5's
GNU LESSER GENERAL PUBLIC LICENSE V2
" + "The source code is available at github:
" + "jceAverageCalculator Repository" + "

This front end is Powered by Jce Connection

" + "Made by:" + "" + "Thanks to: " + ""); +} + +void MainScreen::on_clearTableButton_clicked() +{ + + courseTableMgr->clearTable(); + ui->avgLCD->display(courseTableMgr->getAvg()); +} + +void MainScreen::on_actionExit_triggered() +{ + exit(0); +} + + +void MainScreen::on_keepLogin_clicked() +{ + if (ui->keepLogin->isChecked()) + SaveData::save(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()); + + else + SaveData::deleteData(); +} diff --git a/main/mainscreen.h b/main/mainscreen.h index 2da50a4..cb4368f 100644 --- a/main/mainscreen.h +++ b/main/mainscreen.h @@ -1,78 +1,80 @@ -#ifndef MAINSCREEN_H -#define MAINSCREEN_H - -#include -#include -#include -#include -#include - -#include -#include - - -#include "src/grades/GradePage.h" -#include "src/jce/jcelogin.h" -#include "coursestablemanager.h" -#include "loginhandler.h" - -#define StatusIconHeight 35 -namespace Ui { -class MainScreen; -} - -class MainScreen : public QMainWindow -{ - Q_OBJECT - -public: - MainScreen(QWidget *parent = 0); - ~MainScreen(); - -private slots: - - void on_ratesButton_clicked(); - - void on_spinBoxFromYear_editingFinished(); - - void on_spinBoxFromSem_editingFinished(); - - void on_spinBoxToYear_editingFinished(); - - void on_spinBoxToSemester_editingFinished(); - - void on_loginButton_clicked(); - - void on_checkBox_toggled(bool checked); - - void on_usrnmLineEdit_editingFinished(); - - void on_actionCredits_triggered(); - - void on_clearTableButton_clicked(); - - void on_actionExit_triggered(); - - void on_coursesTable_itemChanged(QTableWidgetItem *item); - -private: - - void updateDates(); - void uiSetDisconnectMode(); - void uiSetConnectMode(); - void setLabelConnectionStatus(jceLogin::jceStatus statusDescription); - - Ui::MainScreen *ui; - - jceLogin *jceLog; - user *userLoginSetting; - - coursesTableManager *courseTableMgr; - loginHandler *loginHandel; - - QLabel *ButtomStatusLabel; - QLabel *statusLabel; - -}; - -#endif // MAINSCREEN_H +#ifndef MAINSCREEN_H +#define MAINSCREEN_H + +#include +#include +#include +#include +#include + +#include +#include + + +#include "src/grades/GradePage.h" +#include "src/jce/jcelogin.h" +#include "coursestablemanager.h" +#include "loginhandler.h" + +#define StatusIconHeight 35 +namespace Ui { +class MainScreen; +} + +class MainScreen : public QMainWindow +{ + Q_OBJECT + +public: + MainScreen(QWidget *parent = 0); + ~MainScreen(); + +private slots: + + void on_ratesButton_clicked(); + + void on_spinBoxFromYear_editingFinished(); + + void on_spinBoxFromSem_editingFinished(); + + void on_spinBoxToYear_editingFinished(); + + void on_spinBoxToSemester_editingFinished(); + + void on_loginButton_clicked(); + + void on_checkBox_toggled(bool checked); + + void on_usrnmLineEdit_editingFinished(); + + void on_actionCredits_triggered(); + + void on_clearTableButton_clicked(); + + void on_actionExit_triggered(); + + void on_coursesTable_itemChanged(QTableWidgetItem *item); + + void on_keepLogin_clicked(); + +private: + + void updateDates(); + void uiSetDisconnectMode(); + void uiSetConnectMode(); + void setLabelConnectionStatus(jceLogin::jceStatus statusDescription); + + Ui::MainScreen *ui; + + jceLogin *jceLog; + user *userLoginSetting; + + coursesTableManager *courseTableMgr; + loginHandler *loginHandel; + + QLabel *ButtomStatusLabel; + QLabel *statusLabel; + +}; + +#endif // MAINSCREEN_H diff --git a/main/mainscreen.ui b/main/mainscreen.ui index 3c4e301..71fd677 100644 --- a/main/mainscreen.ui +++ b/main/mainscreen.ui @@ -1,743 +1,737 @@ - - - MainScreen - - - - 0 - 0 - 855 - 636 - - - - - 0 - 0 - - - - JCE Avg Calculator - - - - :/icons/icon.png:/icons/icon.png - - - #centralWidget -{ -background: qlineargradient(spread:pad, x1:0.496, y1:0, x2:0.508, y2:1, stop:0 rgba(195, 231, 224, 218), stop:1 rgba(255, 255, 255, 255)); -} - - - - 48 - 48 - - - - false - - - false - - - - - - - - - - true - - - - - - QTabWidget::North - - - QTabWidget::Rounded - - - 0 - - - false - - - false - - - false - - - - - - - - - - - - - Login - - - - QLayout::SetMinimumSize - - - 200 - - - 100 - - - 200 - - - 100 - - - 0 - - - - - - 0 - 0 - - - - #LoginFrame { -border: 3px solid rgb(160, 165, 170); -border-radius: 40px; - -} -#loginButton { -color: white; -background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #77c, stop: 0.5 #66b, stop: 1 #77c); -border-width: 1px; -border-color: #339; -border-style: solid; -border-radius: 7; -padding: 3px; -font-size: 12px; -padding-left: 5px; -padding-right: 5px; -min-width: 60px; -max-width: 60px; -min-height: 20px; -max-height: 20px; -} -#loginButton:pressed { -background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #88c, stop: 0.5 #77b, stop: 1 #88c); -} - -#pswdLabel { -font-weight: bold; -font-size: 15px; -} -#usrnmLabel { -font-weight: bold; -font-size: 15px; -} - - - QFrame::StyledPanel - - - QFrame::Raised - - - - QLayout::SetDefaultConstraint - - - 20 - - - 15 - - - 20 - - - 15 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - - - Login - - - - - - - - - 0 - - - - - - - - 0 - 0 - - - - Qt::ImhLatinOnly|Qt::ImhNoPredictiveText - - - 20 - - - true - - - - - - - - 0 - 0 - - - - <color=#000000>Username - - - Qt::RichText - - - - - - - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Password - - - Qt::RichText - - - - - - - - 0 - 0 - - - - Qt::ImhHiddenText|Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText|Qt::ImhSensitiveData - - - 20 - - - QLineEdit::Password - - - true - - - - - - - - - - - - - - - - - - false - - - - - - Courses - - - - - - 0 - - - - - - 0 - 0 - - - - Qt::RightToLeft - - - QAbstractItemView::SingleSelection - - - true - - - - - - - - - - - false - - - <html><head/><body><p><span style=" font-weight:600;">Get your grades</span></p></body></html> - - - Add - - - - - - - <html><head/><body><p><span style=" font-weight:600;">Clear table</span></p></body></html> - - - Clear - - - - - - - - - Qt::Horizontal - - - - 378 - 20 - - - - - - - - - - Average: - - - - - - - - 75 - true - - - - - - - 0 - - - 0 - - - false - - - QLCDNumber::Filled - - - - - - - - - - - - - - false - - - - 0 - 0 - - - - Settings - - - - - 20 - 20 - 251 - 141 - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 48 - 20 - - - - - - - - - - Semester - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 50 - 20 - - - - - - - - Year - - - - - - - - - - - - - QLayout::SetMinimumSize - - - 0 - - - - - - 0 - 0 - - - - - 40 - 16777215 - - - - From - - - - - - - - 0 - 0 - - - - - 40 - 16777215 - - - - To - - - - - - - - - - - - - 3 - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - false - - - 2009 - - - 2015 - - - 2009 - - - false - - - - - - - - - - - 3 - - - 3 - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - 2010 - - - 2026 - - - 2015 - - - - - - - - - - - - - - - Only influences Courses - - - false - - - - - - - - - - - - - - - - - 0 - 0 - 855 - 21 - - - - - &About - - - - - - - - - - 0 - 0 - - - - - 16777215 - 50 - - - - - - Credits - - - - - Exit - - - - - - usrnmLineEdit - pswdLineEdit - loginButton - tabWidget - ratesButton - clearTableButton - checkBox - spinBoxFromSem - coursesTable - spinBoxFromYear - spinBoxToSemester - spinBoxToYear - - - - - - + + + MainScreen + + + + 0 + 0 + 855 + 649 + + + + + 0 + 0 + + + + JCE Avg Calculator + + + + :/icons/icon.png:/icons/icon.png + + + #centralWidget +{ +background: qlineargradient(spread:pad, x1:0.496, y1:0, x2:0.508, y2:1, stop:0 rgba(195, 231, 224, 218), stop:1 rgba(255, 255, 255, 255)); +} + + + + 48 + 48 + + + + false + + + false + + + + + + + + + + true + + + + + + QTabWidget::North + + + QTabWidget::Rounded + + + 0 + + + false + + + false + + + false + + + + + + + + + + + + + Login + + + + QLayout::SetMinimumSize + + + 200 + + + 100 + + + 200 + + + 100 + + + 0 + + + + + + 0 + 0 + + + + #LoginFrame { +border: 3px solid rgb(160, 165, 170); +border-radius: 40px; + +} +#loginButton { +color: white; +background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #77c, stop: 0.5 #66b, stop: 1 #77c); +border-width: 1px; +border-color: #339; +border-style: solid; +border-radius: 7; +padding: 3px; +font-size: 12px; +padding-left: 5px; +padding-right: 5px; +min-width: 60px; +max-width: 60px; +min-height: 20px; +max-height: 20px; +} +#loginButton:pressed { +background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #88c, stop: 0.5 #77b, stop: 1 #88c); +} + +#pswdLabel { +font-weight: bold; +font-size: 15px; +} +#usrnmLabel { +font-weight: bold; +font-size: 15px; +} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + QLayout::SetDefaultConstraint + + + 20 + + + 15 + + + 20 + + + 15 + + + + + + + Keep login + + + + + + + + 0 + 0 + + + + + + + Login + + + + + + + + + 0 + + + + + + + + 0 + 0 + + + + Qt::ImhLatinOnly|Qt::ImhNoPredictiveText + + + 20 + + + true + + + + + + + + 0 + 0 + + + + <color=#000000>Username + + + Qt::RichText + + + + + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Password + + + Qt::RichText + + + + + + + + 0 + 0 + + + + Qt::ImhHiddenText|Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText|Qt::ImhSensitiveData + + + 20 + + + QLineEdit::Password + + + true + + + + + + + + + + + + + + + + + + false + + + + + + Courses + + + + + + 0 + + + + + + 0 + 0 + + + + Qt::RightToLeft + + + QAbstractItemView::SingleSelection + + + true + + + + + + + + + + + false + + + <html><head/><body><p><span style=" font-weight:600;">Get your grades</span></p></body></html> + + + Add + + + + + + + <html><head/><body><p><span style=" font-weight:600;">Clear table</span></p></body></html> + + + Clear + + + + + + + + + Qt::Horizontal + + + + 378 + 20 + + + + + + + + + + Average: + + + + + + + + 75 + true + + + + + + + 0 + + + 0 + + + false + + + QLCDNumber::Filled + + + + + + + + + + + + + + false + + + + 0 + 0 + + + + Settings + + + + + 20 + 20 + 251 + 159 + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 48 + 20 + + + + + + + + + + Semester + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 50 + 20 + + + + + + + + Year + + + + + + + + + + + + + QLayout::SetMinimumSize + + + 0 + + + + + + 0 + 0 + + + + + 40 + 16777215 + + + + From + + + + + + + + 0 + 0 + + + + + 40 + 16777215 + + + + To + + + + + + + + + + + + + 3 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + false + + + false + + + 2009 + + + 2015 + + + 2009 + + + + + + + + + + + 3 + + + 3 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + 2010 + + + 2026 + + + 2015 + + + + + + + + + + + + + + + Only influences Courses + + + false + + + + + + + + + + + + + + + + + 0 + 0 + 855 + 29 + + + + + &About + + + + + + + + + + 0 + 0 + + + + + 16777215 + 50 + + + + + + Credits + + + + + Exit + + + + + + usrnmLineEdit + pswdLineEdit + loginButton + tabWidget + ratesButton + clearTableButton + checkBox + spinBoxFromSem + coursesTable + spinBoxFromYear + spinBoxToSemester + spinBoxToYear + + + + + + diff --git a/resources/connectionstatus.qrc b/resources/connectionstatus.qrc index 61cb0fd..10dd52c 100644 --- a/resources/connectionstatus.qrc +++ b/resources/connectionstatus.qrc @@ -1,8 +1,8 @@ - - - blueStatusIcon.png - greenStatusIcon.png - redStatusIcon.png - icon.png - - + + + blueStatusIcon.png + greenStatusIcon.png + redStatusIcon.png + icon.png + + diff --git a/src/connection/qtsslsocket.cpp b/src/connection/qtsslsocket.cpp index ad8cd96..e936bd8 100644 --- a/src/connection/qtsslsocket.cpp +++ b/src/connection/qtsslsocket.cpp @@ -1,37 +1,66 @@ #include "qtsslsocket.h" -qtsslsocket::qtsslsocket(std::string server,int port) : flag(false) + +bool qtsslsocket::makeConnect(std::string server,int port) +{ + if (this->socket != NULL) //already connected? + { + socket->close(); + socket = NULL; + } + + if (this->socket == NULL) //if was connected, we deleted it and remake it + socket = new QSslSocket(); + + + if (this->socket != NULL) //now we will connect it to host + { + socket->connectToHostEncrypted(server.c_str(), port); + if (socket->waitForEncrypted()) //waiting for encryption + flag = true; + } + + return isCon(); //return true/false upon isCon function +} + +qtsslsocket::qtsslsocket() : flag(false) { socket = new QSslSocket(); - socket->connectToHostEncrypted(server.c_str(), port); - if (socket->waitForEncrypted()) - flag = true; +} + +qtsslsocket::~qtsslsocket() { + socket->close(); + socket = NULL; } bool qtsslsocket::isCon() { - return flag; + return ((flag) && (this->socket != NULL)); } - +//need to fix the method bool qtsslsocket::send(std::string str) { + int status; bool flag = isCon(); - if (flag) - this->socket->write(str.c_str()); - + if (flag) //if connected + { + status = socket->write(str.c_str(),str.length()); + while (socket->waitForBytesWritten()); + } return flag; } - bool qtsslsocket::recieve(std::string &str) { bool flag = false; QString s = ""; while (socket->waitForReadyRead(milisTimeOut)) - s.append((socket->readAll().data())); + s.append(socket->readAll()); + str = s.toStdString(); if (s.size() > 0) flag = true; + return flag; } diff --git a/src/connection/qtsslsocket.h b/src/connection/qtsslsocket.h index d0dadce..8953bbc 100644 --- a/src/connection/qtsslsocket.h +++ b/src/connection/qtsslsocket.h @@ -7,24 +7,24 @@ #include #include #include -#define milisTimeOut 5000 +#define milisTimeOut 3000 class qtsslsocket : public QObject { Q_OBJECT public: - qtsslsocket(std::string server,int port); - ~qtsslsocket() { - socket->close(); - socket = NULL; - } + qtsslsocket(); + ~qtsslsocket(); + + bool makeConnect(std::string server,int port); bool isCon(); bool send(std::string str); bool recieve(std::string &str); private: + QSslSocket *socket; bool flag; }; diff --git a/src/data/savedata.cpp b/src/data/savedata.cpp index 89900da..4cab10a 100644 --- a/src/data/savedata.cpp +++ b/src/data/savedata.cpp @@ -1,200 +1,200 @@ -#include "savedata.h" - - - -/** - * @brief Checks the status tag in the file - * @return boolean the status - */ -bool SaveData::isSaved() -{ - QString status; - QFile* file = new QFile(FILE_NAME); - /* Opening file for read */ - if(file->open(QIODevice::ReadOnly|QIODevice::Text)) - { - status = getValViaTag("status", file); - if(status == "true") - { - file->close(); //close & return - return true; - } - return false; //close & return - file->close(); - } - /* If Faild to open */ - std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl; - return false; -} - - -/** - * @brief This Function will modify the file, and save the data. - * @param username - QString - * @param password - QString - * @return true if saved - false if error - */ -bool SaveData::save(QString username, QString password) -{ - std::cout << "Trying to save data..." << std::endl; - QFile file(FILE_NAME); - if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) - return false; /* IO Error! */ - QTextStream output(&file); - QString hash_pass = hashPassword(password); - output << "[status]true[/]\n[username]"<open(QIODevice::ReadOnly|QIODevice::Text)) - username = getValViaTag("username", file); - file->close(); - return username; - -} - -/** - * @brief getter for password - * @return QString - password - */ -QString SaveData::getPassword() -{ - QString pass = ""; - QFile* file = new QFile(FILE_NAME); - /* Opening file for read */ - if(file->open(QIODevice::ReadOnly|QIODevice::Text)) - pass = getValViaTag("password", file); - file->close(); - pass = deHashPasword(pass); - return pass; - -} - -/** - * @brief This is A functions that will init the tags file. - * if it exist - do nothing - * if there is no file, it will create it and run the deleteData function - * so tags will be set. - */ -void SaveData::init() -{ - QFile file(FILE_NAME); - if(!file.exists()) - { - file.open(QIODevice::ReadWrite | QIODevice::Text); - file.close(); - deleteData(); - } -} - -/** - * @brief This function will return the vale of a given tag name. - * NOTE: valid tag names are : "status", "username", "password" - * if tag is invalid - will return "" - an empty QString! - * @param tag - QString, the tag name - * @param file - a QFile pointer - * @return QString - the value in tag - * NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!) - */ -QString SaveData::getValViaTag(QString tag, QFile* file) -{ - QString val, line , tmpTag; - QTextStream textStream( file); - while((line = textStream.readLine()) != NULL) - { - std::cout << "DEBUG: line => " << line.toStdString() << std::endl; - for(int i = 0 ; i< line.length() ;++i) - { - if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/") - { - i++; - tmpTag = line.mid(i, tag.length()); - if(tmpTag == tag) - { - i+= tag.length()+1; // i is now right after '[' - int j = i; - while(line[j] != '[')// put j at the end of the value - j++; - /* Then... the value is :*/ - val = line.mid(i, j-i); - std::cout << "DEBUG: ["<open(QIODevice::ReadOnly|QIODevice::Text)) + { + status = getValViaTag("status", file); + if(status == "true") + { + file->close(); //close & return + return true; + } + return false; //close & return + file->close(); + } + /* If Faild to open */ + std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl; + return false; +} + + +/** + * @brief This Function will modify the file, and save the data. + * @param username - QString + * @param password - QString + * @return true if saved - false if error + */ +bool SaveData::save(QString username, QString password) +{ + std::cout << "Trying to save data..." << std::endl; + QFile file(FILE_NAME); + if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) + return false; /* IO Error! */ + QTextStream output(&file); + QString hash_pass = hashPassword(password); + output << "[status]true[/]\n[username]"<open(QIODevice::ReadOnly|QIODevice::Text)) + username = getValViaTag("username", file); + file->close(); + return username; + +} + +/** + * @brief getter for password + * @return QString - password + */ +QString SaveData::getPassword() +{ + QString pass = ""; + QFile* file = new QFile(FILE_NAME); + /* Opening file for read */ + if(file->open(QIODevice::ReadOnly|QIODevice::Text)) + pass = getValViaTag("password", file); + file->close(); + pass = deHashPasword(pass); + return pass; + +} + +/** + * @brief This is A functions that will init the tags file. + * if it exist - do nothing + * if there is no file, it will create it and run the deleteData function + * so tags will be set. + */ +void SaveData::init() +{ + QFile file(FILE_NAME); + if(!file.exists()) + { + file.open(QIODevice::ReadWrite | QIODevice::Text); + file.close(); + deleteData(); + } +} + +/** + * @brief This function will return the vale of a given tag name. + * NOTE: valid tag names are : "status", "username", "password" + * if tag is invalid - will return "" - an empty QString! + * @param tag - QString, the tag name + * @param file - a QFile pointer + * @return QString - the value in tag + * NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!) + */ +QString SaveData::getValViaTag(QString tag, QFile* file) +{ + QString val, line , tmpTag; + QTextStream textStream( file); + while((line = textStream.readLine()) != NULL) + { + std::cout << "DEBUG: line => " << line.toStdString() << std::endl; + for(int i = 0 ; i< line.length() ;++i) + { + if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/") + { + i++; + tmpTag = line.mid(i, tag.length()); + if(tmpTag == tag) + { + i+= tag.length()+1; // i is now right after '[' + int j = i; + while(line[j] != '[')// put j at the end of the value + j++; + /* Then... the value is :*/ + val = line.mid(i, j-i); + std::cout << "DEBUG: ["< -#include -#include - -/* C/C++ libs */ -#include -#include -#include - -#define FILE_NAME "JAC_DB.dat" -#define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]" - -class SaveData -{ -public: - bool static isSaved(); - bool static save(QString username, QString password); - bool static deleteData(); - QString static getUsername(); - QString static getPassword(); - void static init(); -private: - QString static getValViaTag(QString tag, QFile *file); - QString static hashPassword(QString pass); - QString static deHashPasword(QString pass); -}; - -#endif // SAVEDATA_H +#ifndef SAVEDATA_H +#define SAVEDATA_H + +/** + * SaveData Class + * -------------------------------------- + * + * all functions in this class are static! + * no need to create an object! + * + * provides all the needed functions + * for saving user data for JCE login. + * + * the class will enteract with a file formated by tags for storing the valus. + * the file format is as sutch: + * + * [status]Status Value[/] + * [username]usernaem vale[/] + * [password]hashed(not really) password vale[/] + * + * the class will create a file if not exists by calling Save Data::init() function. + * + * for more info about functions - see implantation + */ + +/* QT libs */ +#include +#include +#include + +/* C/C++ libs */ +#include +#include +#include + +#define FILE_NAME "JAC_DB.dat" +#define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]" + +class SaveData +{ +public: + bool static isSaved(); + bool static save(QString username, QString password); + bool static deleteData(); + QString static getUsername(); + QString static getPassword(); + void static init(); +private: + QString static getValViaTag(QString tag, QFile *file); + QString static hashPassword(QString pass); + QString static deHashPasword(QString pass); +}; + +#endif // SAVEDATA_H diff --git a/src/grades/Course.cpp b/src/grades/Course.cpp index bc08f75..c57a774 100644 --- a/src/grades/Course.cpp +++ b/src/grades/Course.cpp @@ -1,55 +1,55 @@ -#include "Course.h" - -Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions) -{ - this->serialNum = serial; - this->name = name; - this->type = type; - this->points = points; - this->hours = hours; - this->grade = grade; - this->additions = additions; -} - -Course::~Course() -{ - -} -double Course::getGrade() const -{ - double noGrade = NO_GRADE_YET; - if (grade == noGrade) - return 0; - else - return this->grade; -} - -void Course::setName(std::string name) -{ - this->name = name; -} - -void Course::setType(std::string type) -{ - this->type = type; -} - -void Course::setPoints(double points) -{ - this->points=points; -} - -void Course::setHours(double hours) -{ - this->hours = hours; -} - -void Course::setGrade(double grade) -{ - this->grade = grade; -} - -void Course::setAdditions(std::string additions) -{ - this->additions = additions; -} +#include "Course.h" + +Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions) +{ + this->serialNum = serial; + this->name = name; + this->type = type; + this->points = points; + this->hours = hours; + this->grade = grade; + this->additions = additions; +} + +Course::~Course() +{ + +} +double Course::getGrade() const +{ + double noGrade = NO_GRADE_YET; + if (grade == noGrade) + return 0; + else + return this->grade; +} + +void Course::setName(std::string name) +{ + this->name = name; +} + +void Course::setType(std::string type) +{ + this->type = type; +} + +void Course::setPoints(double points) +{ + this->points=points; +} + +void Course::setHours(double hours) +{ + this->hours = hours; +} + +void Course::setGrade(double grade) +{ + this->grade = grade; +} + +void Course::setAdditions(std::string additions) +{ + this->additions = additions; +} diff --git a/src/grades/Course.h b/src/grades/Course.h index b577d31..af15424 100644 --- a/src/grades/Course.h +++ b/src/grades/Course.h @@ -1,64 +1,64 @@ -#ifndef COURSE_H -#define COURSE_H - -/* This Code Made By Sagi Dayan - * SagiDayan@gmail.com - * - * Minor changes has been made by Liran Ben Gida - * LiranBG@gmail.com -*/ - -#include -#include -#include - -#define COURSE_FIELDS 7 -#define NO_GRADE_YET 101; - - -class Course{ - -public: - enum CourseScheme - { - SERIAL, - NAME, - TYPE, - POINTS, - HOURS, - GRADE, - ADDITION - }; - - Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions); - ~Course(); - - int getSerialNum() const {return this->serialNum;} - std::string getName() const {return this->name;} - std::string getType() const {return this->type;} - double getPoints() const {return this->points;} - double getHours() const {return this->hours;} - double getGrade() const ; - std::string getAddidtions() const {return this->additions;} - - void setName(std::string name); - void setType(std::string type); - void setPoints(double points); - void setHours(double hours); - void setGrade(double grade); - void setAdditions(std::string additions); - -private: - - int serialNum; - std::string name; - std::string type; - double points; - double hours; - double grade; - std::string additions; -}; - - - -#endif +#ifndef COURSE_H +#define COURSE_H + +/* This Code Made By Sagi Dayan + * SagiDayan@gmail.com + * + * Minor changes has been made by Liran Ben Gida + * LiranBG@gmail.com +*/ + +#include +#include +#include + +#define COURSE_FIELDS 7 +#define NO_GRADE_YET 101; + + +class Course{ + +public: + enum CourseScheme + { + SERIAL, + NAME, + TYPE, + POINTS, + HOURS, + GRADE, + ADDITION + }; + + Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions); + ~Course(); + + int getSerialNum() const {return this->serialNum;} + std::string getName() const {return this->name;} + std::string getType() const {return this->type;} + double getPoints() const {return this->points;} + double getHours() const {return this->hours;} + double getGrade() const ; + std::string getAddidtions() const {return this->additions;} + + void setName(std::string name); + void setType(std::string type); + void setPoints(double points); + void setHours(double hours); + void setGrade(double grade); + void setAdditions(std::string additions); + +private: + + int serialNum; + std::string name; + std::string type; + double points; + double hours; + double grade; + std::string additions; +}; + + + +#endif diff --git a/src/grades/GradePage.cpp b/src/grades/GradePage.cpp index 315a2f9..aef8fc3 100644 --- a/src/grades/GradePage.cpp +++ b/src/grades/GradePage.cpp @@ -1,178 +1,178 @@ -#include "GradePage.h" - -GradePage::GradePage(std::string html) : Page(html) -{ - courses = new std::list(); - tempHtml = getString(); - genList(); - -} -GradePage::~GradePage() -{ - for(Course* c : *courses) - delete c; - delete courses; -} -void GradePage::genList() -{ - - this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA ); - - coursesListInit(this->tempHtml); - -} -void GradePage::addCourse(Course *a) -{ - GradePage::courses->push_back(a); - return; -} - -void GradePage::removeCourse(std::string courseSerialID) -{ - for(Course* c : *courses) - { - if (c->getSerialNum() == stoi(courseSerialID)) - { - courses->remove(c); - delete c; - return; - } - } - -} -void GradePage::coursesListInit(std::string& linesTokinzedString) -{ - std::list stringHolder; - std::string temp; - Course* cTemp = NULL; - char* tok; - char* textToTok = strdup(linesTokinzedString.c_str()); - tok = strtok(textToTok,"\n"); - while (tok != NULL) - { - temp = tok; - stringHolder.push_back(temp); - tok = strtok(NULL, "\n"); - } - for(std::string temp: stringHolder) - { - cTemp = lineToCourse(temp); - if (cTemp != NULL) - addCourse(cTemp); - } -} - -std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine) -{ - int ctr = 0; - std::string temp = ""; - char *tok; - char* textToTok = strdup(textToPhrase.c_str()); - tok = strtok(textToTok, "\n"); - while(tok != NULL) - { - //amount of data before the actual needed data and no empty lines - if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0)) - { - temp += tok; - temp += "\n"; - } - ctr++; - tok = strtok(NULL, "\n"); - } - return temp; - -} -Course* GradePage::lineToCourse(std::string line) -{ - Course *tempC = NULL; - std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions] - int serial; - double points,hours,grade; - std::string name,type, additions; - std::string tempS = ""; - int i = 0; - char* tok; - char* cLine = strdup(line.c_str()); - tok = strtok(cLine, "\t"); - while(tok != NULL) - { - - tempS = tok; - if (i == 1) //skip the tokenizing loop just once - { - tempS = ""; - char *tokTemp; - tokTemp = tok; - - while (!(isdigit((int)*tokTemp))) - tokTemp++; - - while (isdigit((int)*tokTemp)) - { - tempS += *tokTemp; - tokTemp++; - } - templinearray[i-1] = tempS; - templinearray[i] = tokTemp; - - } - else if (i > 1) - templinearray[i] = tempS; - i++; - tok=strtok(NULL, "\t"); - } - if (templinearray[0] == "") //empty phrasing - return NULL; - - serial = stoi(templinearray[Course::CourseScheme::SERIAL]); - - name = templinearray[Course::CourseScheme::NAME]; - type = templinearray[Course::CourseScheme::TYPE]; - - points = stod(templinearray[Course::CourseScheme::POINTS]); - hours = stod(templinearray[Course::CourseScheme::HOURS]); - - if (isGradedYet(templinearray[Course::CourseScheme::GRADE])) - grade = stod(templinearray[Course::CourseScheme::GRADE]); - else - grade = NO_GRADE_YET; - - additions = templinearray[Course::CourseScheme::ADDITION]; - - tempC = new Course(serial,name,type,points,hours,grade,additions); - return tempC; -} - -//checking if one of the chars inside grade is not a number -bool GradePage::isGradedYet(std::string grade) -{ - if (strlen(grade.c_str()) <= 1) - return false; - - for (char c: grade) - { - if (c == '\0') - break; - if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9 - return false; - - } - return true; -} -double GradePage::getAvg() -{ - double avg = 0; - double points = 0; - for(Course* c : *courses) - { - if ((c->getGrade() != 0)) - { - avg += c->getGrade() * c->getPoints(); - points += c->getPoints(); - } - } - - avg /= points; - return avg; -} +#include "GradePage.h" + +GradePage::GradePage(std::string html) : Page(html) +{ + courses = new std::list(); + tempHtml = getString(); + genList(); + +} +GradePage::~GradePage() +{ + for(Course* c : *courses) + delete c; + delete courses; +} +void GradePage::genList() +{ + + this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA ); + + coursesListInit(this->tempHtml); + +} +void GradePage::addCourse(Course *a) +{ + GradePage::courses->push_back(a); + return; +} + +void GradePage::removeCourse(std::string courseSerialID) +{ + for(Course* c : *courses) + { + if (c->getSerialNum() == stoi(courseSerialID)) + { + courses->remove(c); + delete c; + return; + } + } + +} +void GradePage::coursesListInit(std::string& linesTokinzedString) +{ + std::list stringHolder; + std::string temp; + Course* cTemp = NULL; + char* tok; + char* textToTok = strdup(linesTokinzedString.c_str()); + tok = strtok(textToTok,"\n"); + while (tok != NULL) + { + temp = tok; + stringHolder.push_back(temp); + tok = strtok(NULL, "\n"); + } + for(std::string temp: stringHolder) + { + cTemp = lineToCourse(temp); + if (cTemp != NULL) + addCourse(cTemp); + } +} + +std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine) +{ + int ctr = 0; + std::string temp = ""; + char *tok; + char* textToTok = strdup(textToPhrase.c_str()); + tok = strtok(textToTok, "\n"); + while(tok != NULL) + { + //amount of data before the actual needed data and no empty lines + if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0)) + { + temp += tok; + temp += "\n"; + } + ctr++; + tok = strtok(NULL, "\n"); + } + return temp; + +} +Course* GradePage::lineToCourse(std::string line) +{ + Course *tempC = NULL; + std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions] + int serial; + double points,hours,grade; + std::string name,type, additions; + std::string tempS = ""; + int i = 0; + char* tok; + char* cLine = strdup(line.c_str()); + tok = strtok(cLine, "\t"); + while(tok != NULL) + { + + tempS = tok; + if (i == 1) //skip the tokenizing loop just once + { + tempS = ""; + char *tokTemp; + tokTemp = tok; + + while (!(isdigit((int)*tokTemp))) + tokTemp++; + + while (isdigit((int)*tokTemp)) + { + tempS += *tokTemp; + tokTemp++; + } + templinearray[i-1] = tempS; + templinearray[i] = tokTemp; + + } + else if (i > 1) + templinearray[i] = tempS; + i++; + tok=strtok(NULL, "\t"); + } + if (templinearray[0] == "") //empty phrasing + return NULL; + + serial = stoi(templinearray[Course::CourseScheme::SERIAL]); + + name = templinearray[Course::CourseScheme::NAME]; + type = templinearray[Course::CourseScheme::TYPE]; + + points = stod(templinearray[Course::CourseScheme::POINTS]); + hours = stod(templinearray[Course::CourseScheme::HOURS]); + + if (isGradedYet(templinearray[Course::CourseScheme::GRADE])) + grade = stod(templinearray[Course::CourseScheme::GRADE]); + else + grade = NO_GRADE_YET; + + additions = templinearray[Course::CourseScheme::ADDITION]; + + tempC = new Course(serial,name,type,points,hours,grade,additions); + return tempC; +} + +//checking if one of the chars inside grade is not a number +bool GradePage::isGradedYet(std::string grade) +{ + if (strlen(grade.c_str()) <= 1) + return false; + + for (char c: grade) + { + if (c == '\0') + break; + if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9 + return false; + + } + return true; +} +double GradePage::getAvg() +{ + double avg = 0; + double points = 0; + for(Course* c : *courses) + { + if ((c->getGrade() != 0)) + { + avg += c->getGrade() * c->getPoints(); + points += c->getPoints(); + } + } + + avg /= points; + return avg; +} diff --git a/src/grades/GradePage.h b/src/grades/GradePage.h index 355dc1a..2a60481 100644 --- a/src/grades/GradePage.h +++ b/src/grades/GradePage.h @@ -1,48 +1,48 @@ -#ifndef GRADE_PAGE_H -#define GRADE_PAGE_H - -/* This Code Made By Sagi Dayan - * SagiDayan@gmail.com - * - * Minor changes has been made by Liran Ben Gida - * LiranBG@gmail.com -*/ - -#include "Page.h" -#include "Course.h" - -#include -#include //strlen and strtok to phrase the html file -#include //checks if character is numeric - -#define INFO_DATA_LINES_BEFORE_GRADES_DATA 5 - -class GradePage : public Page -{ - -public: - GradePage(std::string html); - ~GradePage(); - - void addCourse(Course *); - void removeCourse(std::string courseSerialID); - double getAvg(); - - std::list* getCourses() { return courses; } - -private: - - void genList(); - std::string tokenToLines(std::string& textToPhrase,int fromLine = 0); - void coursesListInit(std::string& linesTokinzedString); - Course* lineToCourse(std::string line); - - bool isGradedYet(std::string grade); - - std::list* courses; - std::string tempHtml; - -}; - - -#endif +#ifndef GRADE_PAGE_H +#define GRADE_PAGE_H + +/* This Code Made By Sagi Dayan + * SagiDayan@gmail.com + * + * Minor changes has been made by Liran Ben Gida + * LiranBG@gmail.com +*/ + +#include "Page.h" +#include "Course.h" + +#include +#include //strlen and strtok to phrase the html file +#include //checks if character is numeric + +#define INFO_DATA_LINES_BEFORE_GRADES_DATA 5 + +class GradePage : public Page +{ + +public: + GradePage(std::string html); + ~GradePage(); + + void addCourse(Course *); + void removeCourse(std::string courseSerialID); + double getAvg(); + + std::list* getCourses() { return courses; } + +private: + + void genList(); + std::string tokenToLines(std::string& textToPhrase,int fromLine = 0); + void coursesListInit(std::string& linesTokinzedString); + Course* lineToCourse(std::string line); + + bool isGradedYet(std::string grade); + + std::list* courses; + std::string tempHtml; + +}; + + +#endif diff --git a/src/grades/Page.cpp b/src/grades/Page.cpp index 066cf7f..f32bc4a 100644 --- a/src/grades/Page.cpp +++ b/src/grades/Page.cpp @@ -1,164 +1,164 @@ -#include "Page.h" - -Page::Page(std::string& html) -{ - makeText(html); -} -void Page::makeText(std::string& html) -{ - int index = 0; - index = findTitle(html, index); - index = runToActualText(html, index); //set index into the actual place where the data is - manageTableContent(html, index); -} - -int Page::findTitle(std::string& from, int index) -{ - std::string temp; - while(index < (int)from.length()) - { - if(from[index] == '<') - { - //title> - index++; - std::string titleTag = from.substr(index, 5); //legth of title - if(titleTag == "title") //check if the tag is title - { - while(from[index] != '>') - index++; - index++; - while(from[index] != '<') - { - temp += from[index]; - index++; - } - this->title = temp; //sets the title - return index; - } - } - - index++; - } - return -1; -} - -int Page::runToActualText(std::string& from, int index) -{ - while(index < (int)from.length()) - { - if(from[index] == '<') - { - index++; - if(from[index] == '!') - { - //!--FileName - std::string bodyTag = from.substr(index, 11); //!--FileName - - if(bodyTag == "!--FileName") //check if the tag is body tag - { - while(from[index] != '>') - index++; - return index; - } - } - } - index++; - } - return -1; -} - -void Page::manageTableContent(std::string& html, int index) -{ - std::string temp; - for (int i = index; i < (int)html.length(); i++) - { - if(html[i] == '<') - { - // / / - std::string endofTable = ""; - std::string tableTag = html.substr(i, 4); //legth of "tr/td" - if(tableTag == "") - { - temp += "\n"; //new row -> new line - i = stitchText(html, temp, i+4); - if(i == -1) //EOF - break; - } - else if(tableTag == "" || tableTag == "") - { - temp += "\t"; // new cell -> tab between data - i = stitchText(html, temp, i+4); - if (i == -1) //EOF - break; - } - else if(tableTag == "text = temp; -} - -int Page::stitchText(std::string& from, std::string& to, int index) -{ - if (from[index] == '<') - { - std::string bTag = from.substr(index, 3); - if (bTag != "") - return index-1; //go back one step - for the main function to inc i - index += 3; - } - - while (from[index] != '<' && index < (int)from.length()) - { - if (from[index] == '&') - { - //  - std::string nbspChr = from.substr(index, 6); - if (nbspChr == " ") - { - index += 5; - from.at(index) = ' '; - } - - } - - if (endOfString(index,(int) from.length())) - return -1; //EOF - - else if (from[index] == '<') - return index - 1; //go back one step - for the main function to inc i - - if (from[index] != '\n') //check the actuall data before continue - to += from[index]; - index++; - } - - return index-1; -} -bool Page::endOfString(int index, int length) -{ - if(index < length) - return false; - return true; -} - -std::string Page::getString() -{ - return this->text; -} - -std::string Page::getTitle() -{ - return this->title; -} +#include "Page.h" + +Page::Page(std::string& html) +{ + makeText(html); +} +void Page::makeText(std::string& html) +{ + int index = 0; + index = findTitle(html, index); + index = runToActualText(html, index); //set index into the actual place where the data is + manageTableContent(html, index); +} + +int Page::findTitle(std::string& from, int index) +{ + std::string temp; + while(index < (int)from.length()) + { + if(from[index] == '<') + { + //title> + index++; + std::string titleTag = from.substr(index, 5); //legth of title + if(titleTag == "title") //check if the tag is title + { + while(from[index] != '>') + index++; + index++; + while(from[index] != '<') + { + temp += from[index]; + index++; + } + this->title = temp; //sets the title + return index; + } + } + + index++; + } + return -1; +} + +int Page::runToActualText(std::string& from, int index) +{ + while(index < (int)from.length()) + { + if(from[index] == '<') + { + index++; + if(from[index] == '!') + { + //!--FileName + std::string bodyTag = from.substr(index, 11); //!--FileName + + if(bodyTag == "!--FileName") //check if the tag is body tag + { + while(from[index] != '>') + index++; + return index; + } + } + } + index++; + } + return -1; +} + +void Page::manageTableContent(std::string& html, int index) +{ + std::string temp; + for (int i = index; i < (int)html.length(); i++) + { + if(html[i] == '<') + { + // / / + std::string endofTable = ""; + std::string tableTag = html.substr(i, 4); //legth of "tr/td" + if(tableTag == "") + { + temp += "\n"; //new row -> new line + i = stitchText(html, temp, i+4); + if(i == -1) //EOF + break; + } + else if(tableTag == "" || tableTag == "") + { + temp += "\t"; // new cell -> tab between data + i = stitchText(html, temp, i+4); + if (i == -1) //EOF + break; + } + else if(tableTag == "text = temp; +} + +int Page::stitchText(std::string& from, std::string& to, int index) +{ + if (from[index] == '<') + { + std::string bTag = from.substr(index, 3); + if (bTag != "") + return index-1; //go back one step - for the main function to inc i + index += 3; + } + + while (from[index] != '<' && index < (int)from.length()) + { + if (from[index] == '&') + { + //  + std::string nbspChr = from.substr(index, 6); + if (nbspChr == " ") + { + index += 5; + from.at(index) = ' '; + } + + } + + if (endOfString(index,(int) from.length())) + return -1; //EOF + + else if (from[index] == '<') + return index - 1; //go back one step - for the main function to inc i + + if (from[index] != '\n') //check the actuall data before continue + to += from[index]; + index++; + } + + return index-1; +} +bool Page::endOfString(int index, int length) +{ + if(index < length) + return false; + return true; +} + +std::string Page::getString() +{ + return this->text; +} + +std::string Page::getTitle() +{ + return this->title; +} diff --git a/src/grades/Page.h b/src/grades/Page.h index 5796487..da6cf2d 100644 --- a/src/grades/Page.h +++ b/src/grades/Page.h @@ -1,42 +1,42 @@ -#ifndef PAGE_H -#define PAGE_H - -/* This Code Made By Sagi Dayan - * SagiDayan@gmail.com - * - * Minor changes has been made by Liran Ben Gida - * LiranBG@gmail.com -*/ - -#include -#include - -class Page -{ - -public: - - ~Page() {} - -protected: - Page(std::string& html); - std::string getString(); - std::string getTitle(); - void makeText(std::string& html); - - -private: - - - int findTitle(std::string& from, int index); - int runToActualText(std::string& from, int index); - void manageTableContent(std::string& html, int index); - int stitchText(std::string& from, std::string& to, int index); - bool endOfString(int index, int length); - - std::string text; - std::string title; - -}; - -#endif +#ifndef PAGE_H +#define PAGE_H + +/* This Code Made By Sagi Dayan + * SagiDayan@gmail.com + * + * Minor changes has been made by Liran Ben Gida + * LiranBG@gmail.com +*/ + +#include +#include + +class Page +{ + +public: + + ~Page() {} + +protected: + Page(std::string& html); + std::string getString(); + std::string getTitle(); + void makeText(std::string& html); + + +private: + + + int findTitle(std::string& from, int index); + int runToActualText(std::string& from, int index); + void manageTableContent(std::string& html, int index); + int stitchText(std::string& from, std::string& to, int index); + bool endOfString(int index, int length); + + std::string text; + std::string title; + +}; + +#endif diff --git a/src/jce/jceLoginHtmlScripts.h b/src/jce/jceLoginHtmlScripts.h index 148a918..8700049 100644 --- a/src/jce/jceLoginHtmlScripts.h +++ b/src/jce/jceLoginHtmlScripts.h @@ -1,72 +1,72 @@ -#ifndef JCELOGINHTMLSCRIPTS_H -#define JCELOGINHTMLSCRIPTS_H - -#include - -#define dst_host "yedion.jce.ac.il" -#define dst_port 443 - -#include "../user.h" - -class jceLoginHtmlScripts -{ - -private: - - jceLoginHtmlScripts(); - -public: - - static std::string makeRequest(std::string parameters) - { - std::string msg; - msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n"; - msg += "Host: " + std::string(dst_host) + "\r\n"; - msg += "Content-Type: application/x-www-form-urlencoded\r\n"; - msg += "Content-Length: " + to_string(parameters.length()) + "\r\n"; - msg += "Proxy-Connection: Keep-Alive\r\n"; - msg += "Accept-Charset: utf-8"; - msg += "Accept: text/plain\r\n"; - msg += "Connection: Keep-Alive\r\n"; - msg += "\r\n"; - msg += parameters; - return msg; - } - - const static std::string getFirstValidationStep(const user &usr) - { - std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N"; - parameters += usr.getUsername(); - parameters += ",-N"; - parameters += usr.getPassword(); - return parameters; - } - - const static std::string getSecondValidationStep(const user &usr) - { - std::string parameters; - parameters = "prgname=LoginValidtion1&Arguments=-N"; - parameters += usr.getUserID(); - parameters += ",-A,-N"; - parameters += usr.getHashedPassword(); - parameters += ",-A,-A"; - return parameters; - } - const static std::string getGradesPath(const user &usr) - { - std::string parameters; - parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&"; - parameters += "TZ=" + usr.getUserID() + "&"; - parameters += "UNIQ=" + usr.getHashedPassword() + "&"; - parameters += "R1C2=" + usr.date->getFYear() + "&"; - parameters += "R1C1=" + usr.date->getTYear() + "&"; - parameters += "R1C3=" + usr.date->getTSemester() + "&"; - parameters += "R1C4=" + usr.date->getFSemester() + "&"; - parameters += "R1C5=0"; - return parameters; - } - - -}; - -#endif // JCELOGINHTMLSCRIPTS_H +#ifndef JCELOGINHTMLSCRIPTS_H +#define JCELOGINHTMLSCRIPTS_H + +#include + +#define dst_host "yedion.jce.ac.il" +#define dst_port 443 + +#include "../user.h" + +class jceLoginHtmlScripts +{ + +private: + + jceLoginHtmlScripts(); + +public: + + static std::string makeRequest(std::string parameters) + { + std::string msg; + msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n"; + msg += "Host: " + std::string(dst_host) + "\r\n"; + msg += "Content-Type: application/x-www-form-urlencoded\r\n"; + msg += "Content-Length: " + to_string(parameters.length()) + "\r\n"; + msg += "Proxy-Connection: Keep-Alive\r\n"; + msg += "Accept-Charset: utf-8"; + msg += "Accept: text/plain\r\n"; + msg += "Connection: Keep-Alive\r\n"; + msg += "\r\n"; + msg += parameters; + return msg; + } + + const static std::string getFirstValidationStep(const user &usr) + { + std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N"; + parameters += usr.getUsername(); + parameters += ",-N"; + parameters += usr.getPassword(); + return parameters; + } + + const static std::string getSecondValidationStep(const user &usr) + { + std::string parameters; + parameters = "prgname=LoginValidtion1&Arguments=-N"; + parameters += usr.getUserID(); + parameters += ",-A,-N"; + parameters += usr.getHashedPassword(); + parameters += ",-A,-A"; + return parameters; + } + const static std::string getGradesPath(const user &usr) + { + std::string parameters; + parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&"; + parameters += "TZ=" + usr.getUserID() + "&"; + parameters += "UNIQ=" + usr.getHashedPassword() + "&"; + parameters += "R1C2=" + usr.date->getFYear() + "&"; + parameters += "R1C1=" + usr.date->getTYear() + "&"; + parameters += "R1C3=" + usr.date->getTSemester() + "&"; + parameters += "R1C4=" + usr.date->getFSemester() + "&"; + parameters += "R1C5=0"; + return parameters; + } + + +}; + +#endif // JCELOGINHTMLSCRIPTS_H diff --git a/src/jce/jcedate.cpp b/src/jce/jcedate.cpp index 1638890..af59cc5 100644 --- a/src/jce/jcedate.cpp +++ b/src/jce/jcedate.cpp @@ -1,34 +1,34 @@ -#include "jcedate.h" - -jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester) -{ - this->fSemester = fromSemester; - this->fYear = fromYear; - this->tSemester = toSemester; - this->tYear = toYear; -} - -void jceDate::setFYear(std::string fromYear) -{ - this->fYear = fromYear; -} - -void jceDate::setTYear(std::string toYear) -{ - this->tYear = toYear; -} - -void jceDate::setFSemester(std::string fromSemester) -{ - this->fSemester = fromSemester; -} - -void jceDate::setTSemester(std::string toSemester) -{ - this->tSemester = toSemester; -} - -jceDate::~jceDate() -{ - -} +#include "jcedate.h" + +jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester) +{ + this->fSemester = fromSemester; + this->fYear = fromYear; + this->tSemester = toSemester; + this->tYear = toYear; +} + +void jceDate::setFYear(std::string fromYear) +{ + this->fYear = fromYear; +} + +void jceDate::setTYear(std::string toYear) +{ + this->tYear = toYear; +} + +void jceDate::setFSemester(std::string fromSemester) +{ + this->fSemester = fromSemester; +} + +void jceDate::setTSemester(std::string toSemester) +{ + this->tSemester = toSemester; +} + +jceDate::~jceDate() +{ + +} diff --git a/src/jce/jcedate.h b/src/jce/jcedate.h index 46d965b..9a3fa55 100644 --- a/src/jce/jcedate.h +++ b/src/jce/jcedate.h @@ -1,33 +1,33 @@ -#ifndef JCEDATE_H -#define JCEDATE_H - -#include - -class jceDate -{ - -public: - - jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); - ~jceDate(); - - void setFYear(std::string fromYear); - void setTYear(std::string toYear); - void setFSemester(std::string fromSemester); - void setTSemester(std::string toSemester); - - std::string getFYear() { return this->fYear;} - std::string getTYear() { return this->tYear;} - std::string getFSemester() { return this->fSemester;} - std::string getTSemester() { return this->tSemester;} - -private: - std::string fYear; //from - std::string fSemester; - - std::string tYear; //to - std::string tSemester; - -}; - -#endif // JCEDATE_H +#ifndef JCEDATE_H +#define JCEDATE_H + +#include + +class jceDate +{ + +public: + + jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); + ~jceDate(); + + void setFYear(std::string fromYear); + void setTYear(std::string toYear); + void setFSemester(std::string fromSemester); + void setTSemester(std::string toSemester); + + std::string getFYear() { return this->fYear;} + std::string getTYear() { return this->tYear;} + std::string getFSemester() { return this->fSemester;} + std::string getTSemester() { return this->tSemester;} + +private: + std::string fYear; //from + std::string fSemester; + + std::string tYear; //to + std::string tSemester; + +}; + +#endif // JCEDATE_H diff --git a/src/jce/jcelogin.cpp b/src/jce/jcelogin.cpp index dd559be..08eb1ae 100644 --- a/src/jce/jcelogin.cpp +++ b/src/jce/jcelogin.cpp @@ -1,187 +1,184 @@ -#include "jcelogin.h" - -jceLogin::jceLogin(user * username) -{ - this->recieverPage = new std::string(); - this->jceA = username; - this->JceConnector = new qtsslsocket(dst_host, dst_port); -} - -jceLogin::~jceLogin() -{ - this->jceA = NULL; - delete recieverPage; - delete JceConnector; - JceConnector = NULL; - recieverPage = NULL; -} -/** - * @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it. - * throws error upon the given error from JCE website or Socket error - */ -void jceLogin::makeConnection() throw (jceStatus) -{ - jceStatus status = jceStatus::JCE_NOT_CONNECTED; - - if (checkConnection() == true) //connected to host - { - if (makeFirstVisit() == true) //requst and send first validation - { - std::cout << "visit 1\n"; - std::cout << *(this->recieverPage); - status = jceStatus::JCE_FIRST_VALIDATION_PASSED; - if (checkValidation() == true) //check if username and password are matching - { - std::cout << "visit 2\n"; - std::cout << *(this->recieverPage); - status = jceStatus::JCE_SECOND_VALIDATION_PASSED; - if (makeSecondVisit() == true) //siging in the website - { - std::cout << "visit 3\n"; - std::cout << *(this->recieverPage); - status = jceStatus::JCE_YOU_ARE_IN; - setLoginFlag(true); - } - else - status = jceStatus::ERROR_ON_VALIDATION; - } - else - status = jceStatus::ERROR_ON_VALIDATION; - - } - else - status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; - - } - else - status = jceStatus::ERROR_ON_OPEN_SOCKET; - - //we throw status even if we are IN! - throw status; - -} - -bool jceLogin::checkConnection() -{ - if (JceConnector->isCon()) - return true; - - return false; -} - -void jceLogin::reConnect() throw (jceStatus) -{ - closeAll(); - this->recieverPage = new std::string(); - this->JceConnector = new qtsslsocket(dst_host, dst_port); - try - { - makeConnection(); - } - catch (jceLogin::jceStatus &a) - { - throw a; - } -} - -void jceLogin::closeAll() -{ - delete recieverPage; - recieverPage = NULL; - JceConnector = NULL; - -} - -int jceLogin::makeFirstVisit() -{ - std::string usr = jceA->getUsername(); - std::string psw = jceA->getPassword(); - if (JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) - { - if (!JceConnector->recieve(*recieverPage)) - return jceLogin::ERROR_ON_GETTING_INFO; - } - else - return jceLogin::ERROR_ON_SEND_REQUEST; - - return true; -} - -int jceLogin::makeSecondVisit() -{ - std::string usrid=jceA->getUserID(); - std::string pswid=jceA->getHashedPassword(); - if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) - { - if (!(JceConnector->recieve(*recieverPage))) - return jceLogin::ERROR_ON_GETTING_INFO; - - return true; - } - else - return jceLogin::ERROR_ON_SEND_REQUEST; - - return true; -} - -int jceLogin::getGrades() -{ - if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA))))) - { - if (!(JceConnector->recieve(*recieverPage))) - return jceLogin::ERROR_ON_GETTING_GRADES; - - return true; - } - else - return jceLogin::ERROR_ON_SEND_REQUEST; - - return true; - -} - -void jceLogin::setLoginFlag(bool x) -{ - this->loginFlag = x; -} -bool jceLogin::isLoginFlag() const -{ - return this->loginFlag; -} - -std::string jceLogin::getPage() -{ - return *recieverPage; -} - -/** - * @brief jceLogin::checkValidation Made by Nadav Luzzato - * @return true if second validation step is right - */ -bool jceLogin::checkValidation() -{ - //finds the hashed password - std::cout << *recieverPage << std::endl; - - std::size_t hasspass_position1 = recieverPage->find("-A,-N"); - hasspass_position1 += 5; - std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1); - if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos)) - { - std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1); - jceA->setHashedPassword(hasspass); - } - //finds the user id - std::size_t id_position1 = recieverPage->find("value=\"-N", 0); - id_position1 += 9; - std::size_t id_position2 = recieverPage->find(",-A", id_position1); - if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos)) - { - std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1); - jceA->setUserID(hassid); - } - if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty())) - return false; - - return true; -} +#include "jcelogin.h" + +jceLogin::jceLogin(user * username) +{ + this->recieverPage = new std::string(); + this->jceA = username; + this->JceConnector = new qtsslsocket(); +} + +jceLogin::~jceLogin() +{ + this->jceA = NULL; + delete recieverPage; + delete JceConnector; + JceConnector = NULL; + recieverPage = NULL; +} +/** + * @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it. + * throws error upon the given error from JCE website or Socket error + */ +void jceLogin::makeConnection() throw (jceStatus) +{ + if (JceConnector->makeConnect(dst_host,dst_port) == false) + throw jceStatus::ERROR_ON_OPEN_SOCKET; + + jceStatus status = jceStatus::JCE_NOT_CONNECTED; + + if (checkConnection() == true) //connected to host + { + if (makeFirstVisit() == true) //requst and send first validation + { + status = jceStatus::JCE_FIRST_VALIDATION_PASSED; + if (checkValidation() == true) //check if username and password are matching + { + status = jceStatus::JCE_SECOND_VALIDATION_PASSED; + if (makeSecondVisit() == true) //siging in the website + { + status = jceStatus::JCE_YOU_ARE_IN; + setLoginFlag(true); + } + else + status = jceStatus::ERROR_ON_VALIDATION; + } + else + status = jceStatus::ERROR_ON_VALIDATION; + + } + else + status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; + + } + else + status = jceStatus::ERROR_ON_OPEN_SOCKET; + + //we throw status even if we are IN! + throw status; + +} + +bool jceLogin::checkConnection() +{ + if (JceConnector->isCon()) + return true; + + return false; +} + +void jceLogin::reConnect() throw (jceStatus) +{ + closeAll(); + if (this->JceConnector != NULL) + delete JceConnector; + this->recieverPage = new std::string(); + this->JceConnector = new qtsslsocket(); + try + { + makeConnection(); + } + catch (jceLogin::jceStatus &a) + { + throw a; + } +} + +void jceLogin::closeAll() +{ + delete recieverPage; + recieverPage = NULL; + JceConnector = NULL; + +} + +int jceLogin::makeFirstVisit() +{ + std::string usr = jceA->getUsername(); + std::string psw = jceA->getPassword(); + if (JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) + { + if (!JceConnector->recieve(*recieverPage)) + return jceLogin::ERROR_ON_GETTING_INFO; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; +} + +int jceLogin::makeSecondVisit() +{ + std::string usrid=jceA->getUserID(); + std::string pswid=jceA->getHashedPassword(); + if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) + { + if (!(JceConnector->recieve(*recieverPage))) + return jceLogin::ERROR_ON_GETTING_INFO; + + return true; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; +} + +int jceLogin::getGrades() +{ + if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA))))) + { + if (!(JceConnector->recieve(*recieverPage))) + return jceLogin::ERROR_ON_GETTING_GRADES; + + return true; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; + +} + +void jceLogin::setLoginFlag(bool x) +{ + this->loginFlag = x; +} +bool jceLogin::isLoginFlag() const +{ + return this->loginFlag; +} + +std::string jceLogin::getPage() +{ + return *recieverPage; +} + +/** + * @brief jceLogin::checkValidation Made by Nadav Luzzato + * @return true if second validation step is right + */ +bool jceLogin::checkValidation() +{ + //finds the hashed password + std::size_t hasspass_position1 = recieverPage->find("-A,-N"); + hasspass_position1 += 5; + std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1); + if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos)) + { + std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1); + jceA->setHashedPassword(hasspass); + } + //finds the user id + std::size_t id_position1 = recieverPage->find("value=\"-N", 0); + id_position1 += 9; + std::size_t id_position2 = recieverPage->find(",-A", id_position1); + if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos)) + { + std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1); + jceA->setUserID(hassid); + } + if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty())) + return false; + + return true; +} diff --git a/src/jce/jcelogin.h b/src/jce/jcelogin.h index 8d804a8..f9a9638 100644 --- a/src/jce/jcelogin.h +++ b/src/jce/jcelogin.h @@ -1,61 +1,61 @@ -#ifndef JCELOGIN_H -#define JCELOGIN_H - -#include -#include - -#include "../connection/qtsslsocket.h" -#include "../user.h" -#include "jceLoginHtmlScripts.h" - - - - -class jceLogin -{ -public: - - enum jceStatus { - JCE_NOT_CONNECTED, - ERROR_ON_VALIDATION, - ERROR_ON_VALIDATION_USER_BLOCKED, - ERROR_ON_INPUT, - ERROR_ON_CONNECTING, - ERROR_ON_OPEN_SOCKET, - ERROR_ON_GETTING_INFO, - ERROR_ON_GETTING_GRADES, - ERROR_ON_SEND_REQUEST, - JCE_START_VALIDATING_PROGRESS, - JCE_FIRST_VALIDATION_PASSED, - JCE_SECOND_VALIDATION_PASSED, - JCE_YOU_ARE_IN, - JCE_GRADE_PAGE_PASSED - }; - - jceLogin(user* username); - ~jceLogin(); - void makeConnection() throw (jceStatus); - bool checkConnection(); - void reConnect() throw (jceStatus); - void closeAll(); - int getGrades(); - bool isLoginFlag() const; - - std::string getPage(); - - - -private: - int makeFirstVisit(); - bool checkValidation(); - int makeSecondVisit(); - void setLoginFlag(bool x); - - bool loginFlag; - std::string * recieverPage; - user * jceA; - qtsslsocket * JceConnector; - -}; - -#endif // JCELOGIN_H +#ifndef JCELOGIN_H +#define JCELOGIN_H + +#include +#include + +#include "../connection/qtsslsocket.h" +#include "../user.h" +#include "jceLoginHtmlScripts.h" + + + + +class jceLogin +{ +public: + + enum jceStatus { + JCE_NOT_CONNECTED, + ERROR_ON_VALIDATION, + ERROR_ON_VALIDATION_USER_BLOCKED, + ERROR_ON_INPUT, + ERROR_ON_CONNECTING, + ERROR_ON_OPEN_SOCKET, + ERROR_ON_GETTING_INFO, + ERROR_ON_GETTING_GRADES, + ERROR_ON_SEND_REQUEST, + JCE_START_VALIDATING_PROGRESS, + JCE_FIRST_VALIDATION_PASSED, + JCE_SECOND_VALIDATION_PASSED, + JCE_YOU_ARE_IN, + JCE_GRADE_PAGE_PASSED + }; + + jceLogin(user* username); + ~jceLogin(); + void makeConnection() throw (jceStatus); + bool checkConnection(); + void reConnect() throw (jceStatus); + void closeAll(); + int getGrades(); + bool isLoginFlag() const; + + std::string getPage(); + + + +private: + int makeFirstVisit(); + bool checkValidation(); + int makeSecondVisit(); + void setLoginFlag(bool x); + + bool loginFlag; + std::string * recieverPage; + user * jceA; + qtsslsocket * JceConnector; + +}; + +#endif // JCELOGIN_H diff --git a/src/user.cpp b/src/user.cpp index 5bb944a..934a9c3 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -1,52 +1,52 @@ -#include "user.h" - - -user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false) -{ - - this->username = username; - this->password = password; -} -user::~user() -{ - delete date; -} -void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester) -{ - date->setFYear(fromYear); - date->setFSemester(fromSemester); - date->setTYear(toYear); - date->setTSemester(toSemester); -} - -void user::setInfluenceCourseOnly(bool status) -{ - this->influenceCourseOnly = status; -} - -bool user::getInfluenceCourseOnly() const -{ - return this->influenceCourseOnly; -} - -void user::setUsername(string& username) { - this->username=username; -} - -void user::setPassword(string& password) { - this->password=password; -} - -void user::setUserID(string& ID) -{ - this->userID = ID; -} -void user::setHashedPassword(string& hashpass) -{ - this->hashedPassword = hashpass; -} - -string user::getPassword() const { return password; } -string user::getUsername() const { return username; } -string user::getUserID() const { return userID; } -string user::getHashedPassword() const { return hashedPassword; } +#include "user.h" + + +user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false) +{ + + this->username = username; + this->password = password; +} +user::~user() +{ + delete date; +} +void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester) +{ + date->setFYear(fromYear); + date->setFSemester(fromSemester); + date->setTYear(toYear); + date->setTSemester(toSemester); +} + +void user::setInfluenceCourseOnly(bool status) +{ + this->influenceCourseOnly = status; +} + +bool user::getInfluenceCourseOnly() const +{ + return this->influenceCourseOnly; +} + +void user::setUsername(string& username) { + this->username=username; +} + +void user::setPassword(string& password) { + this->password=password; +} + +void user::setUserID(string& ID) +{ + this->userID = ID; +} +void user::setHashedPassword(string& hashpass) +{ + this->hashedPassword = hashpass; +} + +string user::getPassword() const { return password; } +string user::getUsername() const { return username; } +string user::getUserID() const { return userID; } +string user::getHashedPassword() const { return hashedPassword; } diff --git a/src/user.h b/src/user.h index 4eaeecd..8895024 100644 --- a/src/user.h +++ b/src/user.h @@ -1,48 +1,48 @@ -#ifndef user_H -#define user_H - -#include -#include -#include "jce/jcedate.h" - -using namespace std; -class user -{ -public: - user(string username,string password); - ~user(); - void setUsername(string& username); - void setPassword(string& password); - - string getPassword() const; - string getUsername() const; - - void setUserID(string& ID); - void setHashedPassword(string& hashpass); - - string getUserID() const; - string getHashedPassword() const; - - void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); - - void setInfluenceCourseOnly(bool status); - bool getInfluenceCourseOnly() const; - - jceDate * const date = new jceDate("","","",""); //we do not change the pointer - -private: - - string username; - string password; - - string hashedPassword; - string userID; - - bool influenceCourseOnly; - - - -}; -#endif - - +#ifndef user_H +#define user_H + +#include +#include +#include "jce/jcedate.h" + +using namespace std; +class user +{ +public: + user(string username,string password); + ~user(); + void setUsername(string& username); + void setPassword(string& password); + + string getPassword() const; + string getUsername() const; + + void setUserID(string& ID); + void setHashedPassword(string& hashpass); + + string getUserID() const; + string getHashedPassword() const; + + void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); + + void setInfluenceCourseOnly(bool status); + bool getInfluenceCourseOnly() const; + + jceDate * const date = new jceDate("","","",""); //we do not change the pointer + +private: + + string username; + string password; + + string hashedPassword; + string userID; + + bool influenceCourseOnly; + + + +}; +#endif + +