From 7855b19ce0241a7b7b4fc72e3a8ddd9bf73b0a77 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Thu, 04 Nov 2004 10:33:04 +0000 Subject: opie-qashmoney is now unsupported --- (limited to 'noncore/unsupported') diff --git a/noncore/unsupported/qashmoney/.cvsignore b/noncore/unsupported/qashmoney/.cvsignore new file mode 100644 index 0000000..e737538 --- a/dev/null +++ b/noncore/unsupported/qashmoney/.cvsignore @@ -0,0 +1,3 @@ +Makefile* +.moc +.obj diff --git a/noncore/unsupported/qashmoney/CHANGES b/noncore/unsupported/qashmoney/CHANGES new file mode 100755 index 0000000..a3ac224 --- a/dev/null +++ b/noncore/unsupported/qashmoney/CHANGES @@ -0,0 +1,32 @@ +QashMoney - Budget Software for the Sharp Zaurus + +CHANGES + +0.76 - 5/21/03 + + Updated postinst file so app will install on new Sharp ROM 3.1 + Improved algorithm for selecting cleared transaction + Fixed budget display bug + +---------------------------------------------------------------------------------- + +11/1/02 - Initial release of 0.2 version. Considered stable beta version. +11/16/02 - Release of version 0.3. This is a stable version adding function to + transfer money between accounts. Several bugs fixes and speed enhancements + have been done. +11/21/02 - 0.31 news tabs working but not yet displaying accounts +12/15/02 - QashMoney gets a complete face lift and now has a date picker. +12/29/02 - Version 0.41 released. This release fixes more bugs and adds a + function to manage transaction memory items. +12/31/02 - Version 0.42 released. Maintenance release fixing soem rather nasty + bugs that screw up account, transaction, and transfer displays. +03/03/03 - Version 0.60 released. QashMoney has undergone quite a transformation. + A new GUI that incorporates all of Qts excellent layout capabilities should + display nicely in all formats. A new embedded SQL database should make QashMoney +very extensible. +4/25/03 - Version 0.70 released. This version includes many new features over 0.60 including +currency support for accounts, a function to limit transaction views, and an all new budgeting +tab that allows multiple budgets and currency support. +5/7/03 - Version 0.73 released. Few minor bugfixes and feature enhancements. QashMoney now +right justifies all numbers and remembers the sate in which you leave the account window. So, if you +collapse a parent account, it will stay collapsed (even between QashMoney restarts). diff --git a/noncore/unsupported/qashmoney/LICENSE b/noncore/unsupported/qashmoney/LICENSE new file mode 100755 index 0000000..421cfb2 --- a/dev/null +++ b/noncore/unsupported/qashmoney/LICENSE @@ -0,0 +1,348 @@ +QashMoney - Budget/Finance Software for the Sharp Zaurus Copyright (C) 2002 Allen Forsythe + + You may use, distribute and copy the this software under the terms of + GNU General Public License version 2, which is displayed below. + +------------------------------------------------------------------------- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. + +------------------------------------------------------------------------- diff --git a/noncore/unsupported/qashmoney/README b/noncore/unsupported/qashmoney/README new file mode 100755 index 0000000..ef004f7 --- a/dev/null +++ b/noncore/unsupported/qashmoney/README @@ -0,0 +1,71 @@ +QashMoney - Budget Software for the Sharp Zaurus + +README + +This file lists all the important files in the qashmoney CVS directory and how +to make the IPK file that goes on the Zaurus. When you checkout the +qashmoney-source module from CVS, it will create a directory on your hard drive called +qashmoney-source. These instructions assume you are in this directory. + +The first thing you need to do is have all the necessary cross-compile software +and Qtopia installed on your system. I assume you have already done this since +you are downloading CVS, but if not, go to: + +http://docs.zaurus.com + +and download the RPMS that you need for development. + +You also must have sqlite installed on your system to successfully compile +QashMoney. Go to: + +http://www.sqlite.org + +to download this progam. + +After that, set the correct environment variables for the package you +are developing. Two scripts in the qashmoney-source directory are used for that purpose: x86.sh +and arm.sh. If you are building for x86 type: + +source x86.sh + +and press enter. To make binaries that run on the Zaurus, type: + +source arm.sh + +Next, construct the makefile by typing: + +tmake -o Makefile qashmoney.pro + +tmake is Trolltech's program for constructing a typical GNU Makefile from the +project file (qashmoney.pro for this application). If you get an "error: tmake +command not found", you either don't have all the correct RPMS installed or your +environment variables are not correctly set. If all is well type: + +make + +and the program should be constructed and you will be left with a qashmoney +binary in this directory. If you compiled for x86, you can see the application +by using the Qt Virtual Frame Buffer which emulates the Qtopia environment on +your computer. First, copy all the files from the databasefiles directory within the +qashmoney directory. Otherwise, the program will not function. + +To run QashMoney in the Qtopia Virtual Frame Buffer, type: + +qvfb & +./qashmoney -qws + +and QashMoney should appear in the frambuffer. You can use and test qashmoney +here as you would on the Zaurus. + +If you want to compile the app and make the IPK file, check out the qashmoney-build module and see the README file in that module. + +I hope the program can be useful. If you have any questions or comments, please +contact me at qashmoneyman@attbi.com + +Thanks! + +Allen + +Disclaimer: Altough I've tried to make this application tight and well +functioning, it comes with absolutely no warranty and I will not be liable for +any damage it may cause. diff --git a/noncore/unsupported/qashmoney/TODO b/noncore/unsupported/qashmoney/TODO new file mode 100755 index 0000000..c85b0d2 --- a/dev/null +++ b/noncore/unsupported/qashmoney/TODO @@ -0,0 +1,15 @@ +QashMoney Budget Software for the Sharp Zaurus + +TODO + +Planned features for QashtMoney include: + +- Go to another account from within the transactionwindow +- Move a transaction from one account to another +- Purge transactions (remove them without effecting the account balances). +- Add difference account types such as stocks, etc. Basically I want it to + becoming a full featured money app, hence the name!! +- Open Financial Exchange protocol support +- Allow limiting the number of transactions that are displayed when showing cleared transactions. + This will become important when a database becomes very large as the program will + slow greatly if it retrieves serveral hundred transactions to view. diff --git a/noncore/unsupported/qashmoney/account.cpp b/noncore/unsupported/qashmoney/account.cpp new file mode 100755 index 0000000..f21598e --- a/dev/null +++ b/noncore/unsupported/qashmoney/account.cpp @@ -0,0 +1,374 @@ +#include "account.h" +#include "preferences.h" + +#include +#include + +extern Preferences *preferences; + +Account::Account () + { + adb = sqlite_open ( "qmaccounts.db", 0, NULL ); + } + +Account::~Account () + { + sqlite_close ( adb ); + } + +void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit, + int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency ) + { + sqlite_exec_printf ( adb, "insert into accounts2 values ( '%q', %i, %.2f, %i, '%q', %.2f, %i, %i, %i, %.2f, '%q', 0, 0, 0, 0, 0, NULL );", 0, 0, 0, + (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency ); + } + +void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid ) + { + sqlite_exec_printf ( adb, "update accounts2 set name = '%q', description = '%q', currency = '%q' where accountid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currencycode, accountid ); + } + +void Account::deleteAccount ( int accountid ) + { + sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid ); + } + +void Account::setAccountExpanded ( int expanded, int accountid ) + { + sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid ); + } + +int Account::getAccountExpanded ( int id ) + { + char **results; + sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id ); + if ( strlen ( results [1] ) == 0 ) + return 0; + else + return atoi ( results [ 1 ] ); + } + +int Account::getNumberOfAccounts () + { + char **results; + sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL ); + return atoi ( results [ 1 ] ); + } + +int Account::getNumberOfChildAccounts ( int id ) + { + char **results; + sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id ); + return atoi ( results [ 1 ] ); + } + +void Account::updateAccountBalance ( int accountid ) + { + // Here, we'll get a balance for the transactions in an account + sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); + int rows, columns; + char **results; + sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid ); + float transactionsbalance = strtod ( results [ 1 ], 0 ); + sqlite_close ( tdb ); + + // next, we'll get a balance for all the transfers from the account + sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL ); + rows = 0; + columns = 0; + char **results2; + sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid ); + float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 ); + + // finally, we'll get a balance for all the transfers into the account + rows = 0; + columns= 0; + char **results3; + sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid ); + float totransfersbalance = strtod ( results3 [ 1 ], 0 ); + + sqlite_close ( trdb ); + + // calculate and update new balance + sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, + ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid ); + } + +void Account::changeParentAccountBalance ( int parentid ) + { + // select all child balances that share the parent of the current child account + char **results; + int rows; + sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid ); + sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid ); + } + +int Account::getParentAccountID ( int id ) + { + char **results; + sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id ); + return atoi ( results [ 1 ] ); + } + +int Account::getParentAccountID ( QString accountname ) + { + char **results; + sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname ); + return atoi ( results [ 1 ] ); + } + +void Account::displayAccounts ( QListView *listview ) + { + char **results; + int rows, columns; + sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 ); + + // determine if we are using currency support + int currency = preferences->getPreference ( 4 ); + + // remove all columns from the account display + int counter; + for ( counter = 0; counter <= columns; counter++ ) + listview->removeColumn ( 0 ); + + // add columns to the account display + listview->addColumn ( "Account", 0 ); + int columntoalign = 1; + if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it + { + listview->addColumn ( "C", 0 ); + columntoalign = 2; + } + listview->addColumn ( "Balance", 0 ); + listview->addColumn ( "", 0 ); + listview->setColumnAlignment ( columntoalign, Qt::AlignRight ); + counter = 5; + int total = ( rows + 1 ) * columns; + while ( counter < total ) + { + int accountid = atoi ( results [ counter + 3 ] ); + if ( atoi ( results [ counter + 1 ] ) == -1 ) + { + QListViewItem *parent = new QListViewItem ( listview ); + parent->setText ( 0, results [ counter ] ); + if ( currency == 0 ) + { + parent->setText ( 1, results [ counter + 2 ] ); + parent->setText ( 2, results [ counter + 3 ] ); + } + else + { + if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children + { + // create the string we'll use to set the currency pixmap + QString filename = "/opt/QtPalmtop/pics/flags/"; + QString flag = results [ counter + 4 ]; + filename.append ( flag ); + filename.append ( ".png" ); + parent->setPixmap ( 1, QPixmap ( filename ) ); + parent->setText ( 1, flag ); + } + parent->setText ( 2, results [ counter + 2 ] ); + parent->setText ( 3, results [ counter + 3 ] ); + } + + if ( getAccountExpanded ( accountid ) == 1 ) + parent->setOpen ( TRUE ); + + //Start display child accounts for this parent + int childcounter = 5; + while ( childcounter < total ) + { + if ( atoi ( results [ childcounter + 1 ] ) == accountid ) + { + if ( currency == 0 ) + QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] ); + else + { + // create the string we'll use to set the currency pixmap + QString filename = "/opt/QtPalmtop/pics/flags/"; + QString flag = results [ childcounter + 4 ]; + filename.append ( flag ); + filename.append ( ".png" ); + QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] ); + child->setPixmap ( 1, QPixmap ( filename ) ); + child->setText ( 1, flag ); + } + } + childcounter = childcounter + 5; + } + //End display child accounts + } + counter = counter + 5; + } + + // resize all columns appropriately + if ( preferences->getPreference ( 4 ) == 0 ) + { + listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); + listview->setColumnWidthMode ( 0, QListView::Manual ); + listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); + listview->setColumnWidthMode ( 1, QListView::Manual ); + listview->setColumnWidthMode ( 2, QListView::Manual ); + } + else + { + listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) ); + listview->setColumnWidthMode ( 0, QListView::Manual ); + listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) ); + listview->setColumnWidthMode ( 1, QListView::Manual ); + listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) ); + listview->setColumnWidthMode ( 2, QListView::Manual ); + listview->setColumnWidthMode ( 3, QListView::Manual ); + } + + // Now reset the column sorting to user preference + int column = 0; + int direction = 0; + preferences->getSortingPreference ( 1, &column, &direction ); + listview->setSorting ( column, direction ); + } + +int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring ) + { + char **results; + int rows, columns, index; + index = 0; + sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL ); + int counter = 1; + int indexcounter = 1; + int total = ( rows + 1 ) * columns; + while ( counter < total ) + { + if ( getParentAccountID ( results [ counter ] ) == -1 ) + { + combobox->insertItem ( results [ counter ], -1 ); + if ( strcmp ( results [ counter ], indexstring ) == 0 ) + index = indexcounter; + indexcounter++; + } + counter ++; + } + return index; + } + +int Account::getAccountType ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); + return atoi ( results [ 1 ] ); + } + +int Account::getStatementDay ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); + return atoi ( results [ 1 ] ); + } + +int Account::getStatementMonth ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); + return atoi ( results [ 1 ] ); + } + +int Account::getStatementYear ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); + return atoi ( results [ 1 ] ); + } + +QString Account::getAccountDescription ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); + return ( QString ) results [ 1 ]; + } + +QString Account::getCurrencyCode ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); + return ( QString ) results [ 1 ]; + } + +QString Account::getAccountName ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); + return ( QString ) results [ 1 ]; + } + +QString Account::getAccountBalance ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); + return ( QString ) results [ 1 ]; + } + +float Account::getAccountCreditLimit ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); + return strtod ( results [ 1 ], NULL ); + } + +float Account::getStatementBalance ( int accountid ) + { + char **results; + sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); + return strtod ( results [ 1 ], NULL ); + } + +GreyBackgroundItem::GreyBackgroundItem ( QListView *parent ) + : QListViewItem ( parent ) + { + } + +GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ) + : QListViewItem ( parent, label1, label2, label3 ) + { + } + +GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) + : QListViewItem ( parent, label1, label2, label3, label4 ) + { + } + +GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) + : QListViewItem ( parent, label1, label2, label3, label4, label5 ) + { + } + +void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) + { + QColorGroup _cg ( cg ); + _cg.setColor ( QColorGroup::Base, Qt::lightGray ); + QListViewItem::paintCell ( p, _cg, column, width, alignment ); + } + +QStringList Account::getAccountNames () + { + QStringList accountnames; + char **results; + int rows, counter; + sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 ); + for ( counter = 0; counter < rows; counter++ ) + accountnames.append ( results [ counter+1 ] ); + return accountnames; + } + +QStringList Account::getAccountIDs () + { + QStringList accountids; + char **results; + int rows, counter; + sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 ); + for ( counter = 0; counter < rows; counter++ ) + accountids.append ( results [ counter+1 ] ); + return accountids; + } + + diff --git a/noncore/unsupported/qashmoney/account.h b/noncore/unsupported/qashmoney/account.h new file mode 100755 index 0000000..5bad4a1 --- a/dev/null +++ b/noncore/unsupported/qashmoney/account.h @@ -0,0 +1,100 @@ +#ifndef ACCOUNT_H +#define ACCOUNT_H + +#include +#include +#include +#include + +class Account + { + public: + + Account (); + ~Account (); + + // This function adds a new account to the database. It takes the account name, parent, + // initial balance and the account type, description, credit limit, statementbalancedate + // as three integers, and the statementbalance amount + // The parent is an integer account id. Its -1 if there is no parent + // The account types (so far) are 0=not defined 1=parent checking 2=child checking + void addAccount ( QString, int, float, int, QString, float, int, int, int, float, const char * ); + + // updates certain parts of an account + void updateAccount ( QString name, QString description, QString currencycode, int accountid ); + + void setAccountExpanded ( int expanded, int accountid ); + int getAccountExpanded ( int id ); + + // Deletes an account + // Takes the accountid as its parameter + void deleteAccount ( int ); + + // Returns the number of accounts + int getNumberOfAccounts (); + + // returns number of child accounts for a given parent + // this function is useless for child accounts. It will + // always return 0 + int getNumberOfChildAccounts ( int ); + + // This function retrieves all transactions for an account and updates the + // account balance based on the transactions + void updateAccountBalance ( int accountid ); + //void changeAccountBalance ( int accountid, float amount ); + + // updates a parent account + void changeParentAccountBalance ( int parentid ); + + // Returns the parent account ID for an account + // Takes the account name as its parameter or the account id + int getParentAccountID ( QString accountname ); + int getParentAccountID ( int id ); + + // This takes a QListView and puts parents and children memorys + // into the list view + void displayAccounts ( QListView * ); + + // This function displays a sorted list of account names in a combobox + // Takes the combobox address for its parameter + int displayParentAccountNames ( QComboBox *, QString ); + + int getAccountType ( int ); // returns account type for given account id + + // The next three collectively return a date or balance + // They take the accountid as their parameters + int getStatementDay ( int ); + int getStatementMonth ( int ); + int getStatementYear ( int ); + float getStatementBalance ( int ); + + // Returns account description and name + QString getAccountDescription ( int accountid ); + QString getCurrencyCode ( int accountid ); + QString getAccountName ( int accountid ); + QStringList getAccountNames (); + QStringList getAccountIDs (); + QString getAccountBalance ( int accountid ); + + // returns account credit limit + float getAccountCreditLimit ( int ); + + // The primary database that stores all our data + sqlite3 *adb; + }; + +class GreyBackgroundItem : public QListViewItem + { + public: + + GreyBackgroundItem ( QListView *parent ); + GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ); + GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ); + GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ); + + virtual void paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); + + }; + +#endif + diff --git a/noncore/unsupported/qashmoney/accountdisplay.cpp b/noncore/unsupported/qashmoney/accountdisplay.cpp new file mode 100755 index 0000000..046d997 --- a/dev/null +++ b/noncore/unsupported/qashmoney/accountdisplay.cpp @@ -0,0 +1,451 @@ +#include "accountdisplay.h" +#include "newaccount.h" +#include "transaction.h" +#include "transferdialog.h" +#include "transfer.h" + +/* OPIE */ +#include +using namespace Opie::Core; + +/* QT */ +#include +#include + +extern Account *account; +extern Transaction *transaction; +extern Transfer *transfer; +extern Preferences *preferences; + +AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) + { + cleared = 0; + + firstline = new QHBox ( this ); + firstline->setSpacing ( 2 ); + + newaccount = new QPushButton ( firstline ); + newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); + connect ( newaccount, SIGNAL ( released() ), this, SLOT ( addAccount() ) ); + + editaccount = new QPushButton ( firstline ); + editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); + connect ( editaccount, SIGNAL ( released() ), this, SLOT ( editAccount() ) ); + + deleteaccount = new QPushButton ( firstline ); + deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); + connect ( deleteaccount, SIGNAL ( released() ), this, SLOT ( deleteAccount() ) ); + + transferbutton = new QPushButton ( firstline ); + transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); + transferbutton->setToggleButton ( TRUE ); + connect ( transferbutton, SIGNAL ( toggled(bool) ), this, SLOT ( accountTransfer(bool) ) ); + + listview = new QListView ( this ); + listview->setAllColumnsShowFocus ( TRUE ); + listview->setShowSortIndicator ( TRUE ); + listview->setRootIsDecorated ( TRUE ); + listview->setMultiSelection ( FALSE ); + connect ( listview, SIGNAL ( expanded(QListViewItem*) ), this, SLOT ( setAccountExpanded(QListViewItem*) ) ); + connect ( listview, SIGNAL ( collapsed(QListViewItem*) ), this, SLOT ( setAccountCollapsed(QListViewItem*) ) ); + + listview->header()->setTracking ( FALSE ); + connect ( listview->header(), SIGNAL ( sizeChange(int,int,int) ), this, SLOT ( saveColumnSize(int,int,int) ) ); + connect ( listview->header(), SIGNAL ( clicked(int) ), this, SLOT ( saveSortingPreference(int) ) ); + + layout = new QVBoxLayout ( this, 2, 5 ); + layout->addWidget ( firstline ); + layout->addWidget ( listview ); + } + +void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) + { + tab2 = newtab2; + maintabs = newtabs; + } + +void AccountDisplay::addAccount () + { + // initialize local variables + int parentid = 0; + type = 0; + QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; + + // create new account window for entering data + NewAccount *newaccount = new NewAccount ( this ); + int width = this->width(); + newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); + newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); + newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); + newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); + newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); + + // if there are no accounts, disable the child check box + if ( account->getNumberOfAccounts () == 0 ) + newaccount->childcheckbox->setEnabled ( FALSE ); + + // if there are accounts, fill up the pulldown menu for + // selecting a parent account. We should only add those parents without transactions + else + { + int c = 0; + QListViewItemIterator it ( listview ); + for ( ; it.current(); ++it ) + { + int id = it.current()->text ( getIDColumn() ).toInt(); + // iterate through accountdisplay listview and add parents with no transactions + // add this item to the list box only if it is a parent and has no transactions + if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 ) + { + newaccount->childbox->insertItem ( it.current()->text ( 0 ) ); + parentlist [ c ] [ 0 ] = it.current()->text ( 0 ); + parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() ); + parentlist [ c ] [ 2 ] = QString::number ( c ); + c++; + } + } + } + + if ( preferences->getPreference ( 4 ) == 0 ) + newaccount->currencybox->setEnabled ( FALSE ); + + // enter today's date in the date box as default + QDate today = QDate::currentDate (); + int defaultday = today.day(); + int defaultmonth = today.month(); + int defaultyear = today.year(); + newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); + + //add account information if user pushes OK button + if ( newaccount->exec() == QDialog::Accepted ) + { + if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account + { + // go through the parentlist we created and determine the parent accountid + // we can't use the name of the account because there may be two accounts + // with the same name. This function does it all by accountid + int counter; + for ( counter = 0; counter < listview->childCount() + 1; counter++ ) + if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() ) + { + parentid = parentlist [ counter ] [ 1 ].toInt(); + break; + } + type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types + } + else + { + parentid = -1; + type = newaccount->accounttype->currentItem(); // sets account ids for parent accounts + } + + // add the new account + if ( newaccount->getDateEdited () == TRUE ) + account->addAccount ( newaccount->accountname->text(), parentid, newaccount->accountbalance->text().toFloat(), type, + newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), newaccount->getYear(), + newaccount->getMonth(), newaccount->getDay(), newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); + else + account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type, + newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear, + defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); + + if ( parentid != -1 ) + account->changeParentAccountBalance ( parentid ); + + // redisplay accounts + // this function clears the account display first + account->displayAccounts ( listview ); + setToggleButton(); + } + maintabs->setTabEnabled ( tab2, FALSE ); + } + +void AccountDisplay::deleteAccount () + { + if ( listview->selectedItem() == 0 ) + QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete."); + else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 ) + QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children"); + else + { + QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton ); + if ( mb.exec() == QMessageBox::Ok ) + { + int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt (); + int parentid = account->getParentAccountID ( accountid ); + + // delete all the transactions and transfers for the account + transaction->deleteAllTransactions ( accountid ); + transfer->deleteAllTransfers ( accountid ); + + // delete the account + account->deleteAccount ( accountid ); + + // update account balances + if ( parentid != -1 ) + account->changeParentAccountBalance ( parentid ); + + //redisplay accounts + account->displayAccounts ( listview ); + + //remove all the columns from the accountdisplay if there are not any accounts + if ( account->getNumberOfAccounts() == 0 ) + { + int columns = listview->columns(); + int counter; + for ( counter = 0; counter <= columns; counter++ ) + listview->removeColumn ( 0 ); + } + + setToggleButton(); + } + } + maintabs->setTabEnabled ( tab2, FALSE ); + } + +void AccountDisplay::setToggleButton () + { + // iterate through account display and determine how many "transferable" accounts we have + // if there are less than two, disable the transfer button + QListViewItemIterator it ( listview ); + int counter = 0; + for ( ; it.current(); ++it ) + { + // add one to counter if we find a transferable account + if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) + counter++; + } + if ( counter > 1 ) + transferbutton->show(); + else + transferbutton->hide(); + } + +void AccountDisplay::accountTransfer ( bool state ) + { + if ( state == TRUE ) + { + firstaccountid = -1; + secondaccountid = -1; + listview->clearSelection (); + listview->setMultiSelection ( TRUE ); + disableParentsWithChildren (); + connect ( listview, SIGNAL ( clicked(QListViewItem*) ), this, SLOT ( getTransferAccounts(QListViewItem*) ) ); + } + else + { + firstaccountid = -1; + secondaccountid = -1; + listview->clearSelection (); + listview->setMultiSelection ( FALSE ); + enableAccounts (); + disconnect ( listview, SIGNAL ( clicked(QListViewItem*) ), this, SLOT ( getTransferAccounts(QListViewItem*) ) ); + } + } + +void AccountDisplay::getTransferAccounts ( QListViewItem * item ) + { + if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children + { + if ( firstaccountid == -1 ) + firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account + else + if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first + secondaccountid = item->text ( getIDColumn() ).toInt(); + } + + // open transfer window if both accounts are set + if ( firstaccountid != -1 && secondaccountid != -1 ) + { + // construct the transferdialog window + TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); + + // enter today's date in the date box as default + QDate today = QDate::currentDate (); + int defaultday = today.day(); + int defaultmonth = today.month(); + int defaultyear = today.year(); + td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); + + if ( td->exec() == QDialog::Accepted ) + { + // set the cleared integer if the checkbox is checked + if ( td->clearedcheckbox->isChecked() == TRUE ) + cleared = 1; + odebug << "Year from transferdialog = " << td->getYear() << "" << oendl; + // add the transfer with a new date if its been edited or use the default date + if ( td->getDateEdited () == TRUE ) + transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); + else + transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); + + // update account balances of both accounts and parents if necessary + account->updateAccountBalance ( firstaccountid ); + if ( account->getParentAccountID ( firstaccountid ) != -1 ) + account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); + account->updateAccountBalance ( secondaccountid ); + if ( account->getParentAccountID ( secondaccountid ) != -1 ) + account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); + + // redisplay accounts + account->displayAccounts ( listview ); + } + else + { + firstaccountid = -1; + secondaccountid = -1; + listview->clearSelection (); + listview->setMultiSelection ( FALSE ); + disconnect ( listview, SIGNAL ( clicked(QListViewItem*) ), this, SLOT ( getTransferAccounts(QListViewItem*) ) ); + } + + // reset the accounts display window + transferbutton->toggle(); // toggling this button with clear the window as well + + // reenable all the accounts so the transaction tab will be properly set + enableAccounts (); + } + } + +void AccountDisplay::disableParentsWithChildren () + { + // iterate through accountdisplay listview and disable all the parents that have children + QListViewItemIterator it ( listview ); + for ( ; it.current(); ++it ) + { + if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) + it.current()->setSelectable ( FALSE ); + } + } + +void AccountDisplay::enableAccounts () + { + // iterate through accountdisplay listview and enable all accounts + QListViewItemIterator it ( listview ); + for ( ; it.current(); ++it ) + it.current()->setSelectable ( TRUE ); + } + +void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize ) + { + switch ( column ) + { + case 0: + if ( listview->columns() == 3 ) + preferences->changeColumnPreference ( 1, newsize ); + else + preferences->changeColumnPreference ( 10, newsize ); + break; + case 1: + if ( listview->columns() == 3 ) + preferences->changeColumnPreference ( 2, newsize ); + else + preferences->changeColumnPreference ( 11, newsize ); + break; + case 2: + preferences->changeColumnPreference ( 12, newsize ); + break; + } + + } + +void AccountDisplay::saveSortingPreference ( int column ) + { + preferences->changeSortingPreference ( 1, column ); + } + +int AccountDisplay::getIDColumn () + { + int counter; + int columns = listview->columns(); + for ( counter = 0; counter <= columns; counter++ ) + if ( listview->header()->label ( counter ).length() == 0 ) + return counter; + } + +void AccountDisplay::editAccount () + { + if ( listview->selectedItem() == 0 ) + QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit."); + else + { + // set the accountid + int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt(); + + //construct new dialog box + QDialog *editaccountwindow = new QDialog ( this, 0, TRUE ); + editaccountwindow->setCaption ( "Edit Account" ); + + // construct the items which will go in the dialog bix + QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow ); + QLineEdit *accountname = new QLineEdit ( editaccountwindow ); + QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow ); + QLineEdit *accountdescription = new QLineEdit ( editaccountwindow ); + Currency *currencybox = new Currency ( editaccountwindow ); + + QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 ); + layout->addWidget ( namelabel ); + layout->addWidget ( accountname ); + layout->addWidget ( descriptionlabel ); + layout->addWidget ( accountdescription ); + layout->addWidget ( currencybox ); + + //set the account name + accountname->setText ( listview->selectedItem()->text ( 0 ) ); + + //set the account description + accountdescription->setText ( account->getAccountDescription ( accountid ) ); + + if ( preferences->getPreference ( 4 ) == 1 ) + { + // get currency code for this account then iterate through the currency box + // to find the one we want + int count = currencybox->currencybox->count(); + QString code = account->getCurrencyCode ( accountid ); + for ( int counter = 0; count - 1; counter++ ) + { + if ( QString::compare ( currencybox->currencybox->text ( counter ), code ) == 0 ) + { + currencybox->currencybox->setCurrentItem ( counter ); + break; + } + } + } + else + currencybox->setEnabled ( FALSE ); + + //execute the dialog box + int response = editaccountwindow->exec(); + if ( response == 1 ) + { + account->updateAccount ( accountname->text(), accountdescription->text(), currencybox->currencybox->currentText(), accountid ); + account->displayAccounts ( listview ); + + // Try and select the same account that was just edited + QListViewItemIterator it ( listview ); + for ( ; it.current(); ++it ) + { + if ( it.current()->text ( 0 ) == accountname->text() ) + { + listview->setSelected ( it.current(), TRUE ); + return; + } + } + maintabs->setTabEnabled ( tab2, FALSE ); + } + } + } + +void AccountDisplay::setAccountExpanded ( QListViewItem *item ) + { + int accountid = item->text ( getIDColumn() ).toInt(); + account->setAccountExpanded ( 1, accountid ); + } + +void AccountDisplay::setAccountCollapsed ( QListViewItem *item ) + { + int accountid = item->text ( getIDColumn() ).toInt(); + account->setAccountExpanded ( 0, accountid ); + } + + diff --git a/noncore/unsupported/qashmoney/accountdisplay.h b/noncore/unsupported/qashmoney/accountdisplay.h new file mode 100755 index 0000000..6d67b9b --- a/dev/null +++ b/noncore/unsupported/qashmoney/accountdisplay.h @@ -0,0 +1,54 @@ +#ifndef ACCOUNTDISPLAY_H +#define ACCOUNTDISPLAY_H + +#include +#include +#include +#include +#include + +class AccountDisplay : public QWidget + { + Q_OBJECT + + public: + AccountDisplay ( QWidget *parent ); + + QHBox *firstline; + + QPushButton* newaccount; + QPushButton* editaccount; + QPushButton* deleteaccount; + QPushButton* transferbutton; + + QListView* listview; + + QBoxLayout *layout; + + void setTabs ( QWidget *newtab2, QTabWidget *newtabs ); + int getIDColumn (); + void setToggleButton (); + + public slots: + void addAccount (); + void editAccount (); + void deleteAccount (); + void accountTransfer ( bool state ); + void getTransferAccounts ( QListViewItem * item ); + void disableParentsWithChildren (); + void enableAccounts (); + + private slots: + void saveColumnSize ( int column, int oldsize, int newsize ); + void setAccountExpanded ( QListViewItem *item ); + void setAccountCollapsed ( QListViewItem *item ); + void saveSortingPreference ( int column ); + + private: + int type, firstaccountid, secondaccountid, cleared; + QWidget *tab2; + QTabWidget *maintabs; +}; + +#endif // ACCOUNTDISPLAY_H + diff --git a/noncore/unsupported/qashmoney/budget.cpp b/noncore/unsupported/qashmoney/budget.cpp new file mode 100755 index 0000000..2cec329 --- a/dev/null +++ b/noncore/unsupported/qashmoney/budget.cpp @@ -0,0 +1,221 @@ +#include "budget.h" +#include "transaction.h" +#include + +extern Transaction *transaction; + +Budget::Budget () + { + bdb = sqlite_open ( "qmbudgets.db", 0, NULL ); + } + +Budget::~Budget () + { + sqlite_close ( bdb ); + } + +int Budget::addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview ) + { + sqlite_exec_printf ( bdb, "insert into budgets values ( '%q', %i, '%q', '%q', %i, %i, %i, %i, %i, %i, %i, NULL );", 0, 0, 0, ( const char * ) name, type, ( const char * ) description, ( const char * ) currency, startday, startmonth, startyear, endday, endmonth, endyear, defaultview ); + char **results; + sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL ); + QString tablename = "table"; + tablename.append ( results [ 1 ] ); + sqlite_exec_printf ( bdb, "create table '%q' ( name, lineitemamount, type, lineitemid integer primary key );", 0, 0, 0, ( const char* ) tablename ); + return atoi ( results [ 1 ] ); + } + +void Budget::updateBudget ( QString name, QString description, QString currency, int budgetid ) + { + sqlite_exec_printf ( bdb, "update budgets set name = '%q', description = '%q', currency = '%q' where budgetid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currency, budgetid ); + } + +void Budget::deleteBudget ( int budgetid ) + { + if ( getNumberOfBudgets() != 0 ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + sqlite_exec_printf ( bdb, "delete from budgets where budgetid = %i;", 0, 0, 0, budgetid ); + sqlite_exec_printf ( bdb, "drop table '%q';", 0, 0, 0, ( const char* ) tablename ); + } + } + +int Budget::getNumberOfBudgets () + { + char **results; + sqlite_get_table ( bdb, "select count() from budgets;", &results, NULL, NULL, NULL ); + return atoi ( results [ 1 ] ); + } + +int Budget::getNumberOfLineItems ( int budgetid ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + char **results; + sqlite_get_table_printf ( bdb, "select count() from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename ); + return atoi ( results [ 1 ] ); + } + +QStringList* Budget::getBudgetNames () + { + QStringList *names = new QStringList (); + char **results; + int rows, counter; + sqlite_get_table ( bdb, "select name from budgets;", &results, &rows, NULL, NULL ); + names->append ( "None" ); + for ( counter = 0; counter < rows; counter++ ) + names->append ( results [ counter+1 ] ); + return names; + } + +QString Budget::getBudgetName ( int budgetid ) + { + char **results; + sqlite_get_table_printf ( bdb, "select name from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); + return ( QString ) results [ 1 ]; + } + +QString Budget::getBudgetDescription ( int budgetid ) + { + char **results; + sqlite_get_table_printf ( bdb, "select description from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); + return ( QString ) results [ 1 ]; + } + +QString Budget::getCurrency ( int budgetid ) + { + char **results; + sqlite_get_table_printf ( bdb, "select currency from budgets where budgetid= %i;", &results, NULL, NULL, NULL, budgetid ); + return ( QString ) results [ 1 ]; + } + +QStringList* Budget::getBudgetIDs () + { + QStringList *ids = new QStringList (); + char **results; + int rows, counter; + sqlite_get_table ( bdb, "select budgetid from budgets;", &results, &rows, NULL, NULL ); + for ( counter = 0; counter < rows; counter++ ) + ids->append ( results [ counter+1 ] ); + return ids; + } + +int Budget::addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + sqlite_exec_printf ( bdb, "insert into '%q' values ( '%q', %.2f, %i, NULL );", 0, 0, 0, ( const char* ) tablename, ( const char* ) lineitemname, lineitemamount, lineitemtype ); + char **results; + sqlite_get_table_printf ( bdb, "select last_insert_rowid() from '%q';", &results, NULL, NULL, NULL, ( const char* ) tablename ); + return atoi ( results [ 1 ] ); + } + +void Budget::updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + sqlite_exec_printf ( bdb, "update '%q' set name = '%q', lineitemamount = %f, type = %i where lineitemid = %i;", 0, 0, 0, ( const char* ) tablename, ( const char * ) lineitemname, lineitemamount, lineitemtype, lineitemid ); + } + +void Budget::deleteLineItem ( int budgetid, int lineitemid ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + sqlite_exec_printf ( bdb, "delete from '%q' where lineitemid = %i;", 0, 0, 0, ( const char * ) tablename, lineitemid ); + } + +void Budget::displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + char **results; + int rows, columns, counter; + sqlite_get_table_printf ( bdb, "select name, lineitemamount, lineitemid from '%q';", &results, &rows, &columns, NULL, ( const char * ) tablename ); + int total = ( ( rows + 1 ) * columns ); + for ( counter = 3; counter < total; counter = counter + 3 ) + { + float amount = 0; + if ( viewtype == 0 ) + { + QString lineitemamount = results [ counter + 1 ]; + amount = lineitemamount.toFloat() / 12; + } + else + { + QString lineitemamount = results [ counter + 1 ]; + amount = lineitemamount.toFloat(); + } + QListViewItem *item = new QListViewItem ( listview, results [ counter ], QString::number ( amount, 'f', 2 ), transaction->getBudgetTotal ( budgetid, atoi ( results [ counter + 2 ] ), year, month, viewtype ), results [ counter + 2 ] ); + } + } + +QStringList Budget::getLineItems ( int budgetid ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + QStringList lineitems; + char **results; + int rows, counter; + sqlite_get_table_printf ( bdb, "select name from '%q';", &results, &rows, NULL, NULL, (const char*) tablename ); + for ( counter = 0; counter < rows; counter++ ) + lineitems.append ( results [ counter + 1 ] ); + return lineitems; + } + +QStringList Budget::getLineItemIDs ( int budgetid ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + QStringList lineitemids; + char **results; + int rows, counter; + sqlite_get_table_printf ( bdb, "select lineitemid from '%q';", &results, &rows, NULL, NULL, (const char*) tablename ); + for ( counter = 0; counter < rows; counter++ ) + lineitemids.append ( results [ counter + 1 ] ); + return lineitemids; + } + +int Budget::getLineItemTime ( int budgetid, int lineitemid ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + char **results; + sqlite_get_table_printf ( bdb, "select type from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char * ) tablename, lineitemid ); + return atoi ( results [ 1 ] ); + } + +float Budget::getLineItemAmount ( int budgetid, int lineitemid ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + char **results; + sqlite_get_table_printf ( bdb, "select lineitemamount from '%q' where lineitemid= %i;", &results, NULL, NULL, NULL, ( const char* ) tablename, lineitemid ); + return strtod ( results [ 1 ], 0 ); + } + +QString Budget::getBudgetTotal ( int budgetid, int viewtype ) + { + QString tablename = "table"; + tablename.append ( QString::number ( budgetid ) ); + // determine if we are viewing a years, months, or days budget + // we have to pick a different sum for each + char **results; + sqlite_get_table_printf ( bdb, "select sum ( lineitemamount ) from '%q';", &results, NULL, NULL, NULL, ( const char * ) tablename ); + QString amount = results [ 1 ]; + float total = amount.toFloat(); + if ( viewtype == 0 ) + total = total / 12; + amount.setNum ( total, 'f', 2 ); + return amount; + } + +int Budget::getLastAdded () + { + char **results; + sqlite_get_table ( bdb, "select last_insert_rowid() from budgets;", &results, NULL, NULL, NULL ); + return atoi ( results [ 1 ] ); + } + + + diff --git a/noncore/unsupported/qashmoney/budget.h b/noncore/unsupported/qashmoney/budget.h new file mode 100755 index 0000000..f82e048 --- a/dev/null +++ b/noncore/unsupported/qashmoney/budget.h @@ -0,0 +1,45 @@ +#ifndef BUDGET_H +#define BUDGET_H + +#include +#include +#include +#include + +class Budget + { + public: + + Budget (); + ~Budget (); + + int addBudget ( QString name, int type, QString description, QString currency, int startday, int startmonth, int startyear, int endday, int endmonth, int endyear, int defaultview ); + void updateBudget ( QString name, QString description, QString currency, int budgetid ); + void deleteBudget ( int budgetid ); + int getNumberOfBudgets (); + int getNumberOfLineItems ( int budgetid ); + + QStringList* getBudgetNames (); + QStringList* getBudgetIDs (); + QStringList getLineItems ( int budgetid ); + QStringList getLineItemIDs ( int budgetid ); + QString getBudgetName ( int budgetid ); + QString getBudgetDescription ( int budgetid ); + QString getCurrency ( int budgetid ); + QString getBudgetTotal ( int budgetid, int viewtype ); + + int getLastAdded (); + + int addLineItem ( int budgetid, QString lineitemname, float lineitemamount, int lineitemtype ); + void updateLineItem ( QString lineitemname, float lineitemamount, int lineitemtype, int budgetid, int lineitemid ); + void displayLineItems ( int budgetid, QListView *listview, int month, int year, int viewtype ); + void deleteLineItem ( int budgetid, int lineitemid ); + int getLineItemTime ( int budgetid, int lineitemid ); + float getLineItemAmount ( int budgetid, int lineitemid ); + + private: + sqlite3 *bdb; + }; + +#endif + diff --git a/noncore/unsupported/qashmoney/budgetdisplay.cpp b/noncore/unsupported/qashmoney/budgetdisplay.cpp new file mode 100755 index 0000000..b83eb46 --- a/dev/null +++ b/noncore/unsupported/qashmoney/budgetdisplay.cpp @@ -0,0 +1,417 @@ +#include +#include +#include + +#include "budgetdisplay.h" +#include "budget.h" +#include "datepicker.h" +#include "transaction.h" + +extern Preferences *preferences; +extern Budget *budget; +extern Transaction *transaction; + +BudgetDisplay::BudgetDisplay ( QWidget *parent ) : QWidget ( parent ) + { + QFont font = this->font(); + font.setWeight ( QFont::Bold ); + + //set the default date to today + newDate = QDate::currentDate (); + year = newDate.year(); + month = newDate.month(); + day = newDate.day(); + datelabel = preferences->getDate ( year, month ); + + setCaption ( "Budget" ); + + firstline = new QHBox ( this ); + firstline->setSpacing ( 2 ); + secondline = new QHBox ( this ); + secondline->setSpacing ( 10 ); + + menu = new QMenuBar ( this ); + menu->setFrameStyle ( QFrame::Box | QFrame::Sunken ); + budgetmenu = new QPopupMenu ( this ); + lineitemsmenu = new QPopupMenu ( this ); + datemenu = new QPopupMenu ( this ); + menu->insertItem ( "Budget", budgetmenu ); + menu->insertItem ( "Line Item", lineitemsmenu ); + menu->insertItem ( "Date", datemenu ); + budgetmenu->insertItem ( "New", this, SLOT ( newBudget() ), 0, 1 ); + budgetmenu->insertItem ( "Edit", this, SLOT ( editBudget() ), 0, 2 ); + budgetmenu->insertItem ( "Delete", this, SLOT ( deleteBudget() ), 0, 3 ); + lineitemsmenu->insertItem ( "New", this, SLOT ( newLineItem() ), 0, 1 ); + lineitemsmenu->insertItem ( "Edit", this, SLOT ( editLineItem() ), 0, 2 ); + lineitemsmenu->insertItem ( "Delete", this, SLOT ( deleteLineItem() ), 0, 3 ); + datemenu->insertItem ( "Change", this, SLOT ( showCalendar() ) ); + + budgetbox = new QComboBox ( firstline ); + connect ( budgetbox, SIGNAL ( activated(int) ), this, SLOT ( setCurrentBudget(int) ) ); + + budgetview = new QComboBox ( firstline ); + budgetview->insertItem ( "Month" ); + budgetview->insertItem ( "Year" ); + connect ( budgetview, SIGNAL ( activated(int) ), this, SLOT ( setCurrentView(int) ) ); + + budgeted = new QLabel ( secondline ); + budgeted->setFont ( font ); + actual = new QLabel ( secondline ); + actual->setFont ( font ); + date = new QLabel ( secondline ); + date->setFont ( font ); + + listview = new QListView ( this ); + listview->setAllColumnsShowFocus ( TRUE ); + listview->setShowSortIndicator ( TRUE ); + listview->setRootIsDecorated ( TRUE ); + listview->setMultiSelection ( FALSE ); + listview->addColumn ( "Line Item", preferences->getColumnPreference ( 13 ) ); // column id 13 + listview->addColumn ( "Budget", preferences->getColumnPreference ( 14 ) ); // column id 14 + listview->addColumn ( "Actual", preferences->getColumnPreference ( 15 ) ); // column id 15 + listview->addColumn ( "", 0 ); // line item ids + listview->setColumnWidthMode ( 0, QListView::Manual ); + listview->setColumnWidthMode ( 1, QListView::Manual ); + listview->setColumnWidthMode ( 2, QListView::Manual ); + listview->setColumnAlignment ( 1, Qt::AlignRight ); + listview->setColumnAlignment ( 2, Qt::AlignRight ); + listview->setColumnWidthMode ( 3, QListView::Manual ); + + listview->header()->setTracking ( FALSE ); + connect ( listview->header(), SIGNAL ( sizeChange(int,int,int) ), this, SLOT ( saveColumnSize(int,int,int) ) ); + connect ( listview->header(), SIGNAL ( clicked(int) ), this, SLOT ( saveSortingPreference(int) ) ); + + // pull the column sorting preference from the preferences table, and configure the listview accordingly + int column = 0; + int direction = 0; + preferences->getSortingPreference ( 3, &column, &direction ); + listview->setSorting ( column, direction ); + + displayBudgetNames(); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->setMenuBar ( menu ); + layout->addWidget ( firstline ); + layout->addWidget ( secondline ); + layout->addWidget ( listview ); + } + +void BudgetDisplay::deleteBudget () + { + listview->clear(); + transaction->clearBudgetIDs ( currentbudget ); + budget->deleteBudget ( currentbudget ); + if ( budgetbox->count() != 0 ) + displayBudgetNames(); + checkBudgets(); + } + +void BudgetDisplay::saveColumnSize ( int column, int oldsize, int newsize ) + { + switch ( column ) + { + case 0: + preferences->changeColumnPreference ( 13, newsize ); + break; + case 1: + preferences->changeColumnPreference ( 14, newsize ); + break; + case 2: + preferences->changeColumnPreference ( 15, newsize ); + break; + } + } + +void BudgetDisplay::saveSortingPreference ( int column ) + { + preferences->changeSortingPreference ( 3, column ); + } + +int BudgetDisplay::getIDColumn () + { + int counter; + int columns = listview->columns(); + for ( counter = 0; counter <= columns; counter++ ) + if ( listview->header()->label ( counter ).length() == 0 ) + return counter; + } + +void BudgetDisplay::newBudget () + { + constructBudgetWindow(); + int response = nb->exec(); + if ( response == 1 ) + { + // open a new budget object + int addedbudget = budget->addBudget ( budgetname->text(), 0, description->text(), currencybox->currencybox->currentText(), day, month, year, day, month, year, 0 ); + transaction->clearBudgetIDs ( addedbudget ); + displayBudgetNames(); + } + checkBudgets(); + } + +void BudgetDisplay::constructBudgetWindow () + { + //construct and format the new budget window + nb = new QDialog ( this, 0, TRUE ); + nb->setCaption ( "Budget" ); + QLabel *namelabel = new QLabel ( "Budget Name", nb ); + budgetname = new QLineEdit ( nb ); + QLabel *descriptionlabel = new QLabel ( "Description", nb ); + description = new QLineEdit ( nb ); + currencybox = new Currency ( nb ); + QBoxLayout *layout = new QVBoxLayout ( nb, 2, 2 ); + layout->addWidget ( namelabel ); + layout->addWidget ( budgetname ); + layout->addWidget ( descriptionlabel ); + layout->addWidget ( description ); + layout->addWidget ( currencybox ); + } + +void BudgetDisplay::displayBudgetNames () + { + budgetbox->clear(); + if ( budget->getNumberOfBudgets() != 0 ) + { + ids = budget->getBudgetIDs(); + for ( QStringList::Iterator it = ids->begin(); it != ids->end(); ++it ) + { + QString flag = "/opt/QtPalmtop/pics/flags/"; + flag.append ( budget->getCurrency ( (*it).toInt() ) ); + flag.append ( ".png" ); + budgetbox->insertItem ( QPixmap ( flag ), budget->getBudgetName ( (*it).toInt() ) ); + } + setCurrentBudget ( 0 ); + } + else + checkBudgets(); + } + +void BudgetDisplay::setCurrentBudget ( int index ) + { + currentbudget = ( ids->operator[] ( index ).toInt() ); + displayLineItems(); + } + +void BudgetDisplay::setCurrentView ( int index ) + { + displayLineItems(); + } + +void BudgetDisplay::showCalendar () + { + // create new calendar object and show it + DatePicker *dp = new DatePicker ( QDate ( year, month, day ) ); + dp->daylabel->hide(); + dp->daybox->hide(); + if ( budgetview->currentItem() == 1 ) + { + dp->monthlabel->hide(); + dp->monthbox->hide(); + } + dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); + + int response = dp->exec(); + if ( response == 1 ) + { + // Set date integers + year = dp->getYear(); + if ( budgetview->currentItem() == 0 ) + month = dp->getMonth(); + else + month = newDate.month(); + datelabel = preferences->getDate ( year, month ); + displayLineItems(); + } + } + +void BudgetDisplay::newLineItem () + { + //construct and format the new line item window + constructLineItemWindow (); + + int response = newlineitem->exec(); + if ( response == 1 ) + { + float amount; + if ( lineitemtime->currentItem() == 0 ) + amount = lineitemamount->text().toFloat(); + else if ( lineitemtime->currentItem() == 1 ) + amount = lineitemamount->text().toFloat() * 12; + else + amount = lineitemamount->text().toFloat() * 52; + int lineitemadded = budget->addLineItem ( currentbudget, lineitemname->text(), amount, lineitemtime->currentItem() ); + transaction->clearBudgetIDs ( currentbudget, lineitemadded ); + displayLineItems(); + } + checkBudgets(); + } + +void BudgetDisplay::constructLineItemWindow () + { + //construct and format the new budget window + newlineitem = new QDialog ( this, 0, TRUE ); + newlineitem->setCaption ( "Line Item" ); + QLabel *namelabel = new QLabel ( "Line Item Name", newlineitem ); + lineitemname = new QLineEdit ( newlineitem ); + QLabel *budgetamountlabel = new QLabel ( "Budget Amount", newlineitem ); + lineitemamount = new QLineEdit ( newlineitem ); + QLabel *lineitemtimelabel = new QLabel ( "Per:", newlineitem ); + lineitemtime = new QComboBox ( newlineitem ); + lineitemtime->insertItem ( "Year" ); // type 0 + lineitemtime->insertItem ( "Month" ); // type 1 + lineitemtime->insertItem ( "Week" ); // type 2 + QBoxLayout *layout = new QVBoxLayout ( newlineitem, 2, 2 ); + layout->addWidget ( namelabel ); + layout->addWidget ( lineitemname ); + layout->addWidget ( budgetamountlabel ); + layout->addWidget ( lineitemamount ); + layout->addWidget ( lineitemtimelabel ); + layout->addWidget ( lineitemtime ); + } + +void BudgetDisplay::deleteLineItem () + { + if ( listview->selectedItem() != 0 ) + { + int lineitemid = listview->selectedItem()->text ( getIDColumn() ).toInt(); + transaction->clearBudgetIDs ( currentbudget, lineitemid ); + budget->deleteLineItem ( currentbudget, lineitemid ); + displayBudgetNames(); + } + else + QMessageBox::warning ( this, "QashMoney", "Please select a line item to delete." ); + checkBudgets(); + } + +void BudgetDisplay::displayLineItems () + { + listview->clear(); + if ( budget->getNumberOfBudgets() != 0 ) + { + QString budgettable = budgetbox->currentText(); + budgettable.append ( QString::number ( currentbudget ) ); + budget->displayLineItems ( currentbudget, listview, month, year, budgetview->currentItem() ); + totalactual = transaction->getActualTotal ( currentbudget, year, month, budgetview->currentItem() ); + totalbudget = budget->getBudgetTotal ( currentbudget, budgetview->currentItem() ); + updateBudgetInformation(); + } + } + +void BudgetDisplay::checkBudgets () + { + if ( budget->getNumberOfBudgets() == 0 ) + { + budgetview->setEnabled ( FALSE ); + budgetmenu->setItemEnabled ( 2, FALSE ); + budgetmenu->setItemEnabled ( 3, FALSE ); + lineitemsmenu->setItemEnabled ( 1, FALSE ); + lineitemsmenu->setItemEnabled ( 2, FALSE ); + lineitemsmenu->setItemEnabled ( 3, FALSE ); + } + else + { + budgetview->setEnabled ( TRUE ); + budgetmenu->setItemEnabled ( 2, TRUE ); + budgetmenu->setItemEnabled ( 3, TRUE ); + lineitemsmenu->setItemEnabled ( 1, TRUE ); + lineitemsmenu->setItemEnabled ( 2, FALSE ); + lineitemsmenu->setItemEnabled ( 3, FALSE ); + + if ( budget->getNumberOfLineItems ( currentbudget ) != 0 ) + { + lineitemsmenu->setItemEnabled ( 2, TRUE ); + lineitemsmenu->setItemEnabled ( 3, TRUE ); + } + } + } + +void BudgetDisplay::updateBudgetInformation () + { + if ( budgetview->currentItem() == 0 ) + { + datelabel = preferences->getDate ( year, month ); + datelabel.prepend ( "Date: " ); + date->setText ( datelabel ); + } + else + date->setText ( QString::number ( year ) ); + + QString budget = "Budget: "; + budget.append ( totalbudget ); + budgeted->setText ( budget ); + + QString actualamount = "Actual: "; + actualamount.append ( totalactual ); + actual->setText ( actualamount ); + } + +void BudgetDisplay::editBudget () + { + constructBudgetWindow(); + + //set the title + budgetname->setText ( budget->getBudgetName ( currentbudget ) ); + //set the description + description->setText ( budget->getBudgetDescription ( currentbudget ) ); + // retrieve the two character currency code then + // go through the currencty box and find the code + //set the currency box to that index number + int count = currencybox->currencybox->count(); + QString code = budget->getCurrency ( currentbudget ); + for ( int counter = 0; count - 1; counter++ ) + { + if ( QString::compare (currencybox->currencybox->text ( counter ), code ) == 0 ) + { + currencybox->currencybox->setCurrentItem ( counter ); + break; + } + } + int response = nb->exec(); + if ( response == 1 ) + { + budget->updateBudget ( budgetname->text(), description->text(), currencybox->currencybox->currentText(), currentbudget ); + displayBudgetNames(); + } + } + +void BudgetDisplay::editLineItem () + { + if ( listview->selectedItem() != 0 ) + { + constructLineItemWindow(); + + // set the line item name + lineitemname->setText ( listview->selectedItem()->text( 0 ) ); + + // set the line item time combobox + int lineitemtype = budget->getLineItemTime ( currentbudget, listview->selectedItem()->text ( 3 ).toInt() ); + lineitemtime->setCurrentItem ( lineitemtype ); + + // set the line item amount + float amount = budget->getLineItemAmount ( currentbudget, listview->selectedItem()->text ( 3 ).toInt() ); + if ( lineitemtype == 1 ) + amount = amount / 12; + else if ( lineitemtype == 2 ) + amount = amount / 52; + lineitemamount->setText ( QString::number ( amount ) ); + + int response = newlineitem->exec(); + if ( response == 1 ) + { + float amount; + if ( lineitemtime->currentItem() == 0 ) + amount = lineitemamount->text().toFloat(); + else if ( lineitemtime->currentItem() == 1 ) + amount = lineitemamount->text().toFloat() * 12; + else + amount = lineitemamount->text().toFloat() * 52; + budget->updateLineItem ( lineitemname->text(), amount, lineitemtime->currentItem(), currentbudget, listview->selectedItem()->text ( 3 ).toInt() ); + displayLineItems(); + } + } + else + QMessageBox::warning ( this, "QashMoney", "Please select a line item to edit." ); + } + + diff --git a/noncore/unsupported/qashmoney/budgetdisplay.h b/noncore/unsupported/qashmoney/budgetdisplay.h new file mode 100755 index 0000000..a4e806c --- a/dev/null +++ b/noncore/unsupported/qashmoney/budgetdisplay.h @@ -0,0 +1,86 @@ +#ifndef BUDGETDISPLAY_H +#define BUDGETDISPLAY_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "currency.h" + +class BudgetDisplay : public QWidget + { + Q_OBJECT + + public: + BudgetDisplay ( QWidget *parent ); + + QMenuBar *menu; + QPopupMenu *budgetmenu; + QPopupMenu *lineitemsmenu; + QPopupMenu *datemenu; + + QHBox *firstline; + QHBox *secondline; + + QLabel *budgeted; + QLabel *actual; + QLabel *date; + + QLineEdit *budgetname; + QLineEdit *description; + Currency *currencybox; + + QLineEdit *lineitemname; + QLineEdit *lineitemamount; + QComboBox *lineitemtime; + + QListView *listview; + QComboBox *budgetbox; + QComboBox *budgetview; + + QBoxLayout *layout; + + int getIDColumn (); + + public slots: + void displayBudgetNames (); + void displayLineItems (); + void updateBudgetInformation (); + + private slots: + void saveColumnSize ( int column, int oldsize, int newsize ); + void newBudget (); + void deleteBudget (); + void setCurrentBudget ( int ); + void setCurrentView ( int ); + void showCalendar (); + void newLineItem (); + void deleteLineItem (); + void checkBudgets (); + void editBudget (); + void editLineItem (); + void constructBudgetWindow (); + void constructLineItemWindow (); + void saveSortingPreference ( int column ); + + private: + QStringList *names; + QStringList *ids; + int currentbudget, year, month, day; + QDate newDate; + QString totalbudget, totalactual; + QString datelabel; + QDialog *nb; + QDialog *newlineitem; +}; + +#endif // BUDGETDISPLAY_H + diff --git a/noncore/unsupported/qashmoney/calculator.cpp b/noncore/unsupported/qashmoney/calculator.cpp new file mode 100755 index 0000000..2c92103 --- a/dev/null +++ b/noncore/unsupported/qashmoney/calculator.cpp @@ -0,0 +1,113 @@ +#include "calculator.h" + +#include + +Calculator::Calculator ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) + { + + display = new QLineEdit ( this, "display" ); + display->setFrame ( FALSE ); + display->setAlignment ( Qt::AlignRight ); + + QPushButton *one = new QPushButton ( "1", this, "one" ); // make buttons for first row + one->setFlat ( TRUE ); + connect ( one, SIGNAL ( released() ), this, SLOT ( displayOne() ) ); + + QPushButton *two = new QPushButton ( "2", this, "two" ); + two->setFlat ( TRUE ); + connect ( two, SIGNAL ( released() ), this, SLOT ( displayTwo() ) ); + + QPushButton *three = new QPushButton ( "3", this, "three" ); + three->setFlat ( TRUE ); + connect ( three, SIGNAL ( released() ), this, SLOT ( displayThree() ) ); + + QPushButton *four = new QPushButton ( "4", this, "four" ); // make buttons for second row + four->setFlat ( TRUE ); + connect ( four, SIGNAL ( released() ), this, SLOT ( displayFour() ) ); + + QPushButton *five = new QPushButton ( "5", this, "five" ); + five->setFlat ( TRUE ); + connect ( five, SIGNAL ( released() ), this, SLOT ( displayFive() ) ); + + QPushButton *six = new QPushButton ( "6", this, "six" ); + six->setFlat ( TRUE ); + connect ( six, SIGNAL ( released() ), this, SLOT ( displaySix() ) ); + + QPushButton *seven = new QPushButton ( "7", this, "seven" ); // make buttons for third row + seven->setFlat ( TRUE ); + connect ( seven, SIGNAL ( released() ), this, SLOT ( displaySeven() ) ); + + QPushButton *eight = new QPushButton ( "8", this, "eight" ); + eight->setFlat ( TRUE ); + connect ( eight, SIGNAL ( released() ), this, SLOT ( displayEight() ) ); + + QPushButton *nine = new QPushButton ( "9", this, "nine" ); + nine->setFlat ( TRUE ); + connect ( nine, SIGNAL ( released() ), this, SLOT ( displayNine() ) ); + + QPushButton *zero = new QPushButton ( "0", this, "zero" ); + zero->setFlat ( TRUE ); + connect ( zero, SIGNAL ( released() ), this, SLOT ( displayZero() ) ); + + QPushButton *dp = new QPushButton ( ".", this, "dp" ); + dp->setFlat ( TRUE ); + connect ( dp, SIGNAL ( released() ), this, SLOT ( displayPoint() ) ); + + QPushButton *back = new QPushButton ( "<-", this, "back" ); + back->setFlat ( TRUE ); + connect ( back, SIGNAL ( released() ), this, SLOT ( back() ) ); + + layout = new QGridLayout ( this, 5, 3, 5, 1, "calculatorlayout" ); + layout->addMultiCellWidget ( display, 0, 0, 0, 2 ); + layout->addWidget ( one, 1, 0 ); + layout->addWidget ( two, 1, 1 ); + layout->addWidget ( three, 1, 2 ); + layout->addWidget ( four, 2, 0 ); + layout->addWidget ( five, 2, 1 ); + layout->addWidget ( six, 2, 2 ); + layout->addWidget ( seven, 3, 0 ); + layout->addWidget ( eight, 3, 1 ); + layout->addWidget ( nine, 3, 2 ); + layout->addWidget ( zero, 4, 0 ); + layout->addWidget ( dp, 4, 1 ); + layout->addWidget ( back, 4, 2 ); + + } + +void Calculator::displayOne () + { display->insert ( "1" ); } + +void Calculator::displayTwo () + { display->insert ( "2" ); } + +void Calculator::displayThree () + { display->insert ( "3" ); } + +void Calculator::displayFour () + { display->insert ( "4" ); } + +void Calculator::displayFive () + { display->insert ( "5" ); } + +void Calculator::displaySix () + { display->insert ( "6" ); } + +void Calculator::displaySeven () + { display->insert ( "7" ); } + +void Calculator::displayEight () + { display->insert ( "8" ); } + +void Calculator::displayNine () + { display->insert ( "9" ); } + +void Calculator::displayZero () + { display->insert ( "0" ); } + +void Calculator::displayPoint () + { display->insert ( "." ); } + +void Calculator::back () + { display->backspace(); } + + diff --git a/noncore/unsupported/qashmoney/calculator.h b/noncore/unsupported/qashmoney/calculator.h new file mode 100755 index 0000000..56dc1bc --- a/dev/null +++ b/noncore/unsupported/qashmoney/calculator.h @@ -0,0 +1,50 @@ +#ifndef CALCULATOR_H +#define CALCULATOR_H + +#include +#include +#include + +class Calculator : public QDialog +{ + Q_OBJECT + + public: + + Calculator ( QWidget* parent ); + + QLineEdit* display; + + private slots: + + void displayOne (); + void displayTwo (); + void displayThree (); + void displayFour (); + void displayFive (); + void displaySix (); + void displaySeven (); + void displayEight (); + void displayNine (); + void displayZero (); + void displayPoint (); + void back (); + + private: + + QGridLayout *layout; + +}; + +#endif + + + + + + + + + + + diff --git a/noncore/unsupported/qashmoney/currency.cpp b/noncore/unsupported/qashmoney/currency.cpp new file mode 100755 index 0000000..20412a7 --- a/dev/null +++ b/noncore/unsupported/qashmoney/currency.cpp @@ -0,0 +1,80 @@ +#include "currency.h" + +Currency::Currency ( QWidget *parent ) : QWidget ( parent ) + { + currencylabel = new QLabel ( "Currency", this ); + currencybox = new QComboBox ( this ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/AE.png"), "AE" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/AR.png"), "AR" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/AT.png"), "AT" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/AU.png"), "AU" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/BD.png"), "BD" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/BE.png"), "BE" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/BH.png"), "BH" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/BR.png"), "BR" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/BW.png"), "BW" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/CA.png"), "CA" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/CH.png"), "CH" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/CL.png"), "CL" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/CN.png"), "CN" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/CO.png"), "CO" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/CZ.png"), "CZ" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/DE.png"), "DE" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/DK.png"), "DK" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/DO.png"), "DO" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/EG.png"), "EG" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/ES.png"), "ES" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/EU.png"), "EU" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/FL.png"), "FL" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/FR.png"), "FR" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/GB.png"), "GB" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/GR.png"), "GR" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/HK.png"), "HK" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/HU.png"), "HU" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/ID.png"), "ID" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/IE.png"), "IE" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/IL.png"), "IL" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/IN.png"), "IN" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/IQ.png"), "IQ" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/IS.png"), "IS" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/IT.png"), "IT" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/JO.png"), "JO" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/JP.png"), "JP" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/KR.png"), "KR" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/LB.png"), "LB" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/LK.png"), "LK" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/LU.png"), "LU" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/MX.png"), "MX" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/MY.png"), "MY" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/NL.png"), "NL" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/NO.png"), "NO" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/NP.png"), "NP" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/NZ.png"), "NZ" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/OM.png"), "OM" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/PE.png"), "PE" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/PH.png"), "PH" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/PK.png"), "PK" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/PL.png"), "PL" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/PT.png"), "PT" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/QA.png"), "QA" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/SA.png"), "SA" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/SE.png"), "SE" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/SG.png"), "SG" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/SI.png"), "SK" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/TH.png"), "TH" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/TR.png"), "TR" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/TW.png"), "TW" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/US.png"), "US" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/UY.png"), "UY" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/VE.png"), "VE" ); + currencybox->insertItem ( QPixmap ( "/opt/QtPalmtop/pics/flags/ZA.png"), "ZA" ); + + layout = new QVBoxLayout ( this ); + layout->addWidget ( currencylabel ); + layout->addWidget ( currencybox ); + } + + + + + diff --git a/noncore/unsupported/qashmoney/currency.h b/noncore/unsupported/qashmoney/currency.h new file mode 100755 index 0000000..08bb3c1 --- a/dev/null +++ b/noncore/unsupported/qashmoney/currency.h @@ -0,0 +1,23 @@ +#ifndef CURRENCY_H +#define CURRENCY_H + +#include +#include +#include +#include +#include + +class Currency : public QWidget + { + Q_OBJECT + + public: + + Currency ( QWidget *parent ); + QLabel *currencylabel; + QComboBox *currencybox; + QBoxLayout *layout; + }; + +#endif + diff --git a/noncore/unsupported/qashmoney/datepicker.cpp b/noncore/unsupported/qashmoney/datepicker.cpp new file mode 100755 index 0000000..7997c0b --- a/dev/null +++ b/noncore/unsupported/qashmoney/datepicker.cpp @@ -0,0 +1,95 @@ +#include "datepicker.h" + +DatePicker::DatePicker ( QDate entrydate ) : QDialog ( 0, 0, TRUE ) + { + setCaption ( "Select Date" ); + date = entrydate; + day = date.day(); + month = date.month(); + year = date.year(); + + daylabel = new QLabel ( "Day", this ); + monthlabel = new QLabel ( "Month", this ); + yearlabel = new QLabel ( "Year", this ); + + daybox = new QComboBox ( this, "daybox" ); + connect ( daybox, SIGNAL ( activated(int) ), this, SLOT ( setDay(int) ) ); + displayDays ( daybox ); + monthbox = new QComboBox ( this, "monthbox" ); + connect ( monthbox, SIGNAL ( activated(int) ), this, SLOT ( setMonth(int) ) ); + displayMonths ( monthbox ); + yearbox = new QComboBox ( this, "yearbox" ); + connect ( yearbox, SIGNAL ( activated(int) ), this, SLOT ( setYear(int) ) ); + displayYears ( yearbox ); + + layout = new QGridLayout ( this, 2, 3, 5, 5, "datepickerlayout" ); + layout->addWidget ( daylabel, 0, 2 ); + layout->addWidget ( monthlabel, 0, 1 ); + layout->addWidget ( yearlabel, 0, 0 ); + layout->addWidget ( daybox, 1, 2 ); + layout->addWidget ( monthbox, 1, 1 ); + layout->addWidget ( yearbox, 1, 0 ); + } + +void DatePicker::displayDays ( QComboBox *daybox ) + { + int counter; + int days = date.daysInMonth(); + for ( counter = 1; counter <= days; counter++ ) + daybox->insertItem ( QString::number ( counter ) ); + daybox->setCurrentItem ( ( date.day() ) - 1 ); + } + +void DatePicker::displayMonths ( QComboBox *monthbox ) + { + int counter; + for ( counter = 1; counter <= 12; counter++ ) + monthbox->insertItem ( QString::number ( counter ) ); + monthbox->setCurrentItem ( ( date.month() ) - 1 ); + } + +void DatePicker::displayYears ( QComboBox *yearbox ) + { + int counter; + int indexcounter = 0; + int yearindex = 0; + int year = date.year(); + for ( counter = ( year - 1 ); counter <= ( year + 1 ); counter++ ) + { + yearbox->insertItem ( QString::number ( counter ) ); + if ( date.year() == counter ) + yearindex = indexcounter; + indexcounter ++; + } + yearbox->setCurrentItem ( yearindex ); + } + +void DatePicker::setDay ( int index ) + { + day = daybox->text ( index ).toInt(); + } + +void DatePicker::setMonth ( int index ) + { + month = monthbox->text( index ).toInt(); + } + +void DatePicker::setYear ( int index ) + { + year = yearbox->text ( index ).toInt(); + } + +int DatePicker::getDay () + { return day; } + +int DatePicker::getMonth () + { return month; } + +int DatePicker::getYear () + { return year; } + + + + + + diff --git a/noncore/unsupported/qashmoney/datepicker.h b/noncore/unsupported/qashmoney/datepicker.h new file mode 100755 index 0000000..67e63e9 --- a/dev/null +++ b/noncore/unsupported/qashmoney/datepicker.h @@ -0,0 +1,60 @@ +#ifndef DATEPICKER_H +#define DATEPICKER_H + +#include +#include +#include +#include +#include + +class DatePicker : public QDialog + + { + Q_OBJECT + + public: + QLabel *daylabel; + QComboBox *daybox; + + QLabel *monthlabel; + QComboBox *monthbox; + + DatePicker ( QDate entrydate ); + int getDay (); + int getMonth (); + int getYear (); + + private slots: + void setDay ( int ); + void setMonth ( int ); + void setYear ( int ); + + private: + void displayDays ( QComboBox *daybox ); + void displayMonths ( QComboBox *monthbox ); + void displayYears ( QComboBox *yearbox ); + + QDate date; + + QLabel *yearlabel; + QComboBox *yearbox; + + QGridLayout *layout; + + int day, month, year; + + }; + +#endif + + + + + + + + + + + + diff --git a/noncore/unsupported/qashmoney/main.cpp b/noncore/unsupported/qashmoney/main.cpp new file mode 100755 index 0000000..f86be89 --- a/dev/null +++ b/noncore/unsupported/qashmoney/main.cpp @@ -0,0 +1,13 @@ +#include +#include "qashmoney.h" + +int main( int argc, char **argv ) + { + QPEApplication a ( argc, argv ); + QashMoney qashmoney; + a.showMainWidget ( &qashmoney ); + return a.exec(); + } + + + diff --git a/noncore/unsupported/qashmoney/memory.cpp b/noncore/unsupported/qashmoney/memory.cpp new file mode 100755 index 0000000..b5155b3 --- a/dev/null +++ b/noncore/unsupported/qashmoney/memory.cpp @@ -0,0 +1,62 @@ +#include "memory.h" + +#include + +Memory::Memory () + { + db = sqlite_open ( "qmmemory.db", 0, NULL ); + } + +Memory::~Memory () + { + sqlite_close ( db ); + } + +void Memory::addMemoryItem ( QString item ) + { + sqlite_exec_printf ( db, "insert into memory values ( '%q', 0, 0 );", 0, 0, 0, ( const char * ) item ); + } + +void Memory::deleteMemoryItem ( QString item ) + { + sqlite_exec_printf ( db, "delete from memory where item = '%q';", 0, 0, 0, ( const char * ) item ); + } + +int Memory::getNumberOfMemoryItems () + { + char **results; + sqlite_get_table ( db, "select count() from memory;", &results, NULL, NULL, NULL ); + return atoi ( results [ 1 ] ); + } + +void Memory::changeMemoryName ( QString item ) + { + sqlite_exec_printf ( db, "update memory set item = '%q' where item = '%q';", 0, 0, 0, ( const char * ) item ); + } + +void Memory::displayMemoryItems ( QListBox *listbox ) + { + char **results; + int rows; + sqlite_get_table ( db, "select item from memory order by item asc;", &results, &rows, NULL, NULL ); + int counter = 1; + while ( counter < ( rows + 1 ) ) + { + listbox->insertItem ( results [ counter ] ); + counter ++; + } + } + +void Memory::displayMemoryItems ( QComboBox *box ) + { + char **results; + int rows; + sqlite_get_table ( db, "select item from memory order by item asc;", &results, &rows, NULL, NULL ); + int counter = 1; + while ( counter < ( rows + 1 ) ) + { + box->insertItem ( results [ counter ] ); + counter ++; + } + } + diff --git a/noncore/unsupported/qashmoney/memory.h b/noncore/unsupported/qashmoney/memory.h new file mode 100755 index 0000000..6e8ae46 --- a/dev/null +++ b/noncore/unsupported/qashmoney/memory.h @@ -0,0 +1,45 @@ +#ifndef MEMORY_H +#define MEMORY_H + +#include +#include +#include +#include + +class Memory : public QObject + { + + Q_OBJECT + + public: + + Memory (); + ~Memory (); + + // This function adds a new memory to the database. It takes the memory name, parent, + // initial balance, a displayed variable, and the memory type + // The parent is an integer memory id. Its -1 if there is not parent + // The memory types are 0=not defined 1=parent 2=child + void addMemoryItem ( QString ); + + // Returns the number of checking memorys + int getNumberOfMemoryItems (); + + void changeMemoryName ( QString ); + + // This takes a QListView and puts parents and children memorys + // into the list view + void displayMemoryItems ( QListBox * ); + void displayMemoryItems ( QComboBox * ); + + // The primary database that stores all our data + sqlite3 *db; + + public slots: + + // Deletes a memory item. Takes the memoryid as its parameter + void deleteMemoryItem ( QString ); + }; + +#endif + diff --git a/noncore/unsupported/qashmoney/memorydialog.cpp b/noncore/unsupported/qashmoney/memorydialog.cpp new file mode 100755 index 0000000..ba11540 --- a/dev/null +++ b/noncore/unsupported/qashmoney/memorydialog.cpp @@ -0,0 +1,86 @@ +#include "memorydialog.h" +#include "memory.h" +#include + +extern Memory *memory; + +MemoryDialog::MemoryDialog () : QDialog ( 0, 0, TRUE ) +{ + setCaption ( tr ( "Edit Memory" ) ); + + listbox = new QListBox ( this, "listbox" ); + memory->displayMemoryItems ( listbox ); + listbox->clearSelection(); + + secondline = new QHBox ( this ); + + newbutton = new QPushButton ( secondline ); + newbutton->setPixmap( QPixmap ("/opt/QtPalmtop/pics/new.png") ); + connect ( newbutton, SIGNAL ( released() ), this, SLOT ( addItem() ) ); + + editbutton = new QPushButton ( secondline ); + editbutton->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); + connect ( editbutton, SIGNAL ( released() ), this, SLOT ( editItem() ) ); + + deletebutton = new QPushButton( secondline ); + deletebutton->setPixmap( QPixmap ("/opt/QtPalmtop/pics/delete.png") ); + connect ( deletebutton, SIGNAL ( released() ), this, SLOT ( deleteItem() ) ); + + lineedit = new QLineEdit ( this ); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->addWidget ( listbox ); + layout->addWidget ( secondline ); + layout->addWidget ( lineedit ); +} + +MemoryDialog::~MemoryDialog() + { + } + +void MemoryDialog::addItem () + { + if ( lineedit->text().length() != 0 ) + { + memory->addMemoryItem ( lineedit->text() ); + listbox->clear (); + memory->displayMemoryItems ( listbox ); + listbox->clearFocus(); + listbox->clearSelection (); + lineedit->clear(); + } + } + +void MemoryDialog::editItem () + { + if ( listbox->currentItem() != -1 ) + { + lineedit->setText ( listbox->currentText() ); + memory->deleteMemoryItem ( listbox->currentText() ); + listbox->clear (); + memory->displayMemoryItems ( listbox ); + listbox->clearSelection(); + } + else + QMessageBox::warning ( this, "QashMoney", "Please select an item to edit." ); + } + +void MemoryDialog::deleteItem () + { + if ( listbox->currentItem() != -1 ) + { + memory->deleteMemoryItem ( listbox->currentText() ); + listbox->clear (); + memory->displayMemoryItems ( listbox ); + listbox->clearSelection(); + } + else + QMessageBox::warning ( this, "QashMoney", "Please select an item to delete." ); + } + + + + + + + diff --git a/noncore/unsupported/qashmoney/memorydialog.h b/noncore/unsupported/qashmoney/memorydialog.h new file mode 100755 index 0000000..3491823 --- a/dev/null +++ b/noncore/unsupported/qashmoney/memorydialog.h @@ -0,0 +1,40 @@ +#ifndef MEMORYDIALOG_H +#define MEMORYDIALOG_H + +#include +#include +#include +#include +#include +#include +#include + +class MemoryDialog : public QDialog + { + Q_OBJECT + + public: + MemoryDialog(); + ~MemoryDialog(); + + private slots: + void addItem(); + void editItem(); + void deleteItem(); + + private: + + QHBox *secondline; + + QListBox* listbox; + + QLineEdit* lineedit; + + QPushButton* newbutton; + QPushButton* editbutton; + QPushButton* deletebutton; + + QBoxLayout *layout; +}; + +#endif diff --git a/noncore/unsupported/qashmoney/newaccount.cpp b/noncore/unsupported/qashmoney/newaccount.cpp new file mode 100755 index 0000000..5932182 --- a/dev/null +++ b/noncore/unsupported/qashmoney/newaccount.cpp @@ -0,0 +1,206 @@ +#include "newaccount.h" +#include "calculator.h" +#include "datepicker.h" +#include + +extern Preferences *preferences; + +NewAccount::NewAccount ( QWidget *parent, const char *name, bool modal ) : QDialog ( parent, name, modal ) + { + accountdescription = ""; + dateedited = FALSE; + setCaption( tr( "Account" ) ); + + namelabel = new QLabel ( "Account Name", this ); + + accountbox = new QHBox ( this ); + accountname = new QLineEdit ( accountbox ); + descriptionbutton = new QPushButton ( accountbox ); + descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) ); + + datelabel = new QLabel ( "Date", this ); + + datebox = new QHBox ( this ); + startdate = new QLineEdit ( datebox ); + startdate->setDisabled ( TRUE ); + datebutton = new QPushButton ( datebox ); + datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); + + childcheckbox = new QCheckBox ( this ); + childcheckbox->setText( tr ( "Child Account" ) ); + + childlabel = new QLabel ( "Child of", this ); + childbox = new QComboBox ( FALSE, this ); + hideChildPulldownMenu (); + + balancelabel = new QLabel ( "Balance", this ); + + balancebox = new QHBox ( this ); + accountbalance = new QLineEdit ( balancebox ); + accountbalance->setText ( "0.00" ); + balancecalculator = new QPushButton( balancebox ); + balancecalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); + + creditlimitlabel = new QLabel ( "Credit Limit", this ); + + creditlimitbox = new QHBox ( this ); + creditlimit = new QLineEdit ( creditlimitbox ); + creditlimitbox->setEnabled ( FALSE ); + creditlimitcalculator = new QPushButton( creditlimitbox ); + creditlimitcalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); + + currencybox = new Currency ( this ); + + typelabel = new QLabel ( "Type", this ); + accounttype = new QComboBox ( FALSE, this ); + accounttype->insertItem( tr( "Bank" ) ); + accounttype->insertItem( tr( "Cash" ) ); + accounttype->insertItem( tr( "Credit Card" ) ); + accounttype->insertItem( tr( "Equity" ) ); + accounttype->insertItem( tr( "Asset" ) ); + accounttype->insertItem( tr( "Liability" ) ); + + layout = new QGridLayout ( this, 7, 2, 4, 2 ); + layout->addWidget ( namelabel , 0, 0, Qt::AlignLeft ); + layout->addWidget ( accountbox, 1, 0, Qt::AlignLeft ); + layout->addWidget ( datelabel, 2, 0, Qt::AlignLeft ); + layout->addWidget ( datebox, 3, 0, Qt::AlignLeft ); + layout->addWidget ( childcheckbox, 4, 0, Qt::AlignLeft ); + layout->addWidget ( childlabel, 5, 0, Qt::AlignLeft ); + layout->addWidget ( childbox, 6, 0, Qt::AlignLeft ); + layout->addWidget ( balancelabel, 0, 1, Qt::AlignLeft ); + layout->addWidget ( balancebox, 1, 1, Qt::AlignLeft ); + layout->addWidget ( creditlimitlabel, 2, 1, Qt::AlignLeft ); + layout->addWidget ( creditlimitbox, 3, 1, Qt::AlignLeft ); + layout->addWidget ( currencybox, 4, 1, Qt::AlignLeft ); + layout->addWidget ( typelabel, 5, 1, Qt::AlignLeft ); + layout->addWidget ( accounttype, 6, 1, Qt::AlignLeft ); + + connect ( childcheckbox, SIGNAL ( clicked() ), this, SLOT ( showChildPulldownMenu() ) ); + connect ( balancecalculator, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); + connect ( creditlimitcalculator, SIGNAL ( released() ), this, SLOT ( showCreditLimitCalculator() ) ); + connect ( accounttype, SIGNAL ( activated(int) ), this, SLOT ( activateCreditLimit(int) ) ); + connect ( datebutton, SIGNAL ( released() ), this, SLOT ( showCalendar() ) ); + connect ( descriptionbutton, SIGNAL ( released() ), this, SLOT ( addAccountDescription() ) ); +} + +NewAccount::~NewAccount () + { + } + +void NewAccount::showChildPulldownMenu () + { + if ( childcheckbox->isChecked() == TRUE ) + { + childlabel->setEnabled ( TRUE ); + childbox->setEnabled ( TRUE ); + } + else + hideChildPulldownMenu(); + } + +void NewAccount::hideChildPulldownMenu () + { + childlabel->setEnabled ( FALSE ); + childbox->setEnabled ( FALSE ); + } + +void NewAccount::showCalculator () + { + Calculator *calculator = new Calculator ( this ); + calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); + if ( calculator->exec () == QDialog::Accepted ) + accountbalance->setText ( calculator->display->text() ); + } + +void NewAccount::showCreditLimitCalculator () + { + Calculator *calculator = new Calculator ( this ); + calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); + if ( calculator->exec () == QDialog::Accepted ) + creditlimit->setText ( calculator->display->text() ); + } + +void NewAccount::activateCreditLimit ( int index ) + { + if ( index == 2 || index == 5 ) + creditlimitbox->setEnabled ( TRUE ); + else + { + creditlimit->clear (); + creditlimitbox->setEnabled ( FALSE ); + } + } + +void NewAccount::showCalendar () + { + QDate newDate = QDate::currentDate (); + DatePicker *dp = new DatePicker ( newDate ); + dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); + + int response = dp->exec(); + if ( response == QDialog::Accepted ) + { + // Set date integers + year = dp->getYear(); + month = dp->getMonth(); + day = dp->getDay(); + + // Set dateedited to TRUE + // This tells the accountdisplay object that the user edited an account + // and did change the date + dateedited = TRUE; + + // Display date with our selected format + startdate->setText ( preferences->getDate ( year, month, day ) ); + } + } + +bool NewAccount::getDateEdited () + { + return dateedited; + } + +int NewAccount::getDay () + { + return day; + } + +int NewAccount::getMonth () + { + return month; + } + +int NewAccount::getYear () + { + return year; + } + +QString NewAccount::getDescription () + { + return accountdescription; + } + +void NewAccount::setDescription ( QString description ) + { + accountdescription = description; + } + +void NewAccount::addAccountDescription () + { + // Function for adding or editing an account description. + QDialog *description = new QDialog ( this, "description", TRUE ); + description->setCaption ( "Notes" ); + QMultiLineEdit *enter = new QMultiLineEdit ( description ); + enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); + enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); + enter->setWordWrap ( QMultiLineEdit::WidgetWidth ); + if ( accountdescription != "(NULL)" ) + enter->setText ( accountdescription ); + if ( description->exec () == QDialog::Accepted ) + accountdescription = enter->text (); + } + + + + diff --git a/noncore/unsupported/qashmoney/newaccount.h b/noncore/unsupported/qashmoney/newaccount.h new file mode 100755 index 0000000..f8235d5 --- a/dev/null +++ b/noncore/unsupported/qashmoney/newaccount.h @@ -0,0 +1,87 @@ +#ifndef NEWACCOUNT_H +#define NEWACCOUNT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "account.h" +#include "preferences.h" +#include "currency.h" + +class NewAccount : public QDialog + { + Q_OBJECT + + public: + NewAccount ( QWidget *parent = 0, const char *name = 0, bool modal = TRUE ); + ~NewAccount(); + + QLabel *namelabel; + QHBox *accountbox; + QLineEdit* accountname; + QPushButton* descriptionbutton; + + QHBox *datebox; + QLabel *datelabel; + QLineEdit* startdate; + QPushButton* datebutton; + + QCheckBox* childcheckbox; + + QLabel *childlabel; + QComboBox *childbox; + + QLabel *balancelabel; + QHBox *balancebox; + QLineEdit* accountbalance; + QPushButton* balancecalculator; + + QLabel *creditlimitlabel; + QHBox *creditlimitbox; + QLineEdit* creditlimit; + QPushButton* creditlimitcalculator; + + Currency *currencybox; + + QLabel *typelabel; + QComboBox* accounttype; + + QGridLayout *layout; + + int getDay (); + int getMonth (); + int getYear (); + QString getDescription (); + void setDescription ( QString ); + + // When a user edits an account and edits the date, this flag + // is set to TRUE adding the new date to the account. Otherwise, + // the old date is used for the edited account. This prevents a date + // from reverting to 0/0/0 if the date is not edited + bool getDateEdited (); + + public slots: + void showChildPulldownMenu(); + void hideChildPulldownMenu(); + void showCalculator(); + void showCreditLimitCalculator (); + void activateCreditLimit ( int ); + void showCalendar (); + void addAccountDescription (); + + private: + int index, year, month, day, currencypreference; + QString accountdescription; + bool dateedited; +}; + +#endif + diff --git a/noncore/unsupported/qashmoney/newtransaction.cpp b/noncore/unsupported/qashmoney/newtransaction.cpp new file mode 100755 index 0000000..87b7f7e --- a/dev/null +++ b/noncore/unsupported/qashmoney/newtransaction.cpp @@ -0,0 +1,274 @@ +#include "newtransaction.h" +#include "calculator.h" +#include "datepicker.h" +#include "budget.h" + +#include + +extern Budget *budget; +extern Preferences *preferences; + +NewTransaction::NewTransaction ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) + { + transactiondescription = ""; + currentlineitem = -1; + currentbudget = -1; + dateedited = FALSE; + setCaption( tr( "Transaction" ) ); + + // START FIRST COLUMN + + namelabel = new QLabel ( "Transaction", this ); + + transactionnamebox = new QHBox ( this ); + transactionname = new QComboBox ( transactionnamebox ); + transactionname->setEditable ( TRUE ); + descriptionbutton = new QPushButton ( transactionnamebox ); + descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) ); + connect ( descriptionbutton, SIGNAL ( released() ), this, SLOT ( addTransactionDescription() ) ); + + amountlabel = new QLabel ( "Amount", this ); + + transactionamountbox = new QHBox ( this ); + transactionamount = new QLineEdit ( transactionamountbox ); + transactionamount->setAlignment ( Qt::AlignRight ); + transactionamount->setText ( "0.00" ); + calculatorbutton = new QPushButton( transactionamountbox ); + calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); + connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); + + datelabel = new QLabel ( "Date", this ); + + transactiondatebox = new QHBox ( this ); + transactiondate = new QLineEdit ( transactiondatebox ); + transactiondate->setAlignment ( Qt::AlignRight ); + transactiondate->setDisabled ( TRUE ); + datebutton = new QPushButton( transactiondatebox ); + datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); + connect ( datebutton, SIGNAL ( released() ), this, SLOT ( showCalendar() ) ); + + clearedcheckbox = new QCheckBox ( "Cleared", this ); + depositbox = new QCheckBox ( "Credit", this ); + + // START SECOND COLUMN + + numberlabel = new QLabel ( "Number", this ); + transactionnumber = new QLineEdit ( this ); + + budgetlabel = new QLabel ( "Budget", this ); + budgetbox = new QComboBox ( FALSE, this ); + + lineitemlabel = new QLabel ( "LineItem", this ); + lineitembox = new QComboBox ( FALSE, this ); + + layout = new QGridLayout ( this, 7, 2, 2, 2 ); + layout->addWidget ( namelabel, 0, 0, Qt::AlignLeft ); + layout->addWidget ( transactionnamebox, 1, 0, Qt::AlignLeft ); + layout->addWidget ( amountlabel, 2, 0, Qt::AlignLeft ); + layout->addWidget ( transactionamountbox, 3, 0, Qt::AlignLeft ); + layout->addWidget ( datelabel, 4, 0, Qt::AlignLeft ); + layout->addWidget ( transactiondatebox, 5, 0, Qt::AlignLeft ); + layout->addWidget ( clearedcheckbox, 6, 0, Qt::AlignLeft ); + layout->addWidget ( numberlabel, 0, 1, Qt::AlignLeft ); + layout->addWidget ( transactionnumber, 1, 1, Qt::AlignLeft ); + layout->addWidget ( budgetlabel, 2, 1, Qt::AlignLeft ); + layout->addWidget ( budgetbox, 3, 1, Qt::AlignLeft ); + layout->addWidget ( lineitemlabel, 4, 1, Qt::AlignLeft ); + layout->addWidget ( lineitembox, 5, 1, Qt::AlignLeft ); + layout->addWidget ( depositbox, 6, 1, Qt::AlignLeft ); + + if ( budget->getNumberOfBudgets() != 0 ) + { + budgetnameslist = budget->getBudgetNames(); + budgetidslist = budget->getBudgetIDs(); + budgetbox->insertStringList ( *budgetnameslist ); + lineitemlabel->setEnabled ( FALSE ); + lineitembox->setEnabled ( FALSE ); + connect ( budgetbox, SIGNAL ( activated(int) ), this, SLOT ( setCurrentBudget(int) ) ); + connect ( lineitembox, SIGNAL ( activated(int) ), this, SLOT ( setCurrentLineItem(int) ) ); + } + else + { + budgetlabel->setEnabled ( FALSE ); + budgetbox->setEnabled ( FALSE ); + lineitemlabel->setEnabled ( FALSE ); + lineitembox->setEnabled ( FALSE ); + } + +} + +NewTransaction::~NewTransaction () + { + } + +void NewTransaction::showCalculator () +{ + Calculator *calculator = new Calculator ( this ); + calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); + if ( calculator->exec () == QDialog::Accepted ) + transactionamount->setText ( calculator->display->text() ); +} + +void NewTransaction::showCalendar () + { + QDate newDate = QDate::currentDate (); + DatePicker *dp = new DatePicker ( newDate ); + dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); + + int response = dp->exec(); + if ( response == QDialog::Accepted ) + { + // Set date integers + year = dp->getYear(); + month = dp->getMonth(); + day = dp->getDay(); + + // Set dateedited to TRUE + // This tells the transactiondisplay object that the user edited an transaction + // and did change the date3 + dateedited = TRUE; + + // Display date with our selected format + transactiondate->setText ( preferences->getDate ( year, month, day ) ); + } + } + +bool NewTransaction::getDateEdited () + { + return dateedited; + } + +int NewTransaction::getDay () + { + return day; + } + +int NewTransaction::getMonth () + { + return month; + } + +int NewTransaction::getYear () + { + return year; + } + +QString NewTransaction::getDescription () + { + return transactiondescription; + } + +void NewTransaction::setDescription ( QString description ) + { + transactiondescription = description; + } + +void NewTransaction::addTransactionDescription () + { + // Function for adding or editing an transaction description. + QDialog *description = new QDialog ( this, "description", TRUE ); + description->setCaption ( "Notes" ); + QMultiLineEdit *enter = new QMultiLineEdit ( description ); + enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); + enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); + enter->setWordWrap ( QMultiLineEdit::WidgetWidth ); + if ( transactiondescription != "(NULL)" ) + enter->setText ( transactiondescription ); + if ( description->exec () == QDialog::Accepted ) + transactiondescription = enter->text (); + } + +int NewTransaction::getNameIndex ( QString name ) + { + int counter; + int items = transactionname->count(); + for ( counter = 0; ( items - 1 ); counter++ ) + { + if ( name == transactionname->text ( counter ) ) + { + return counter; + break; + } + } + return 0; + } + +void NewTransaction::setCurrentBudget ( int index ) + { + if ( index != 0 ) + { + currentbudget = budgetidslist->operator[] ( index - 1 ).toInt(); + lineitemslist = budget->getLineItems ( currentbudget ); + lineitemidslist = budget->getLineItemIDs ( currentbudget ); + lineitemlabel->setEnabled ( TRUE ); + lineitembox->setEnabled ( TRUE ); + lineitembox->clear(); + lineitembox->insertStringList ( lineitemslist ); + setCurrentLineItem ( 0 ); + } + else + { + lineitembox->clear(); + lineitemlabel->setEnabled ( FALSE ); + lineitembox->setEnabled ( FALSE ); + currentlineitem = -1; + currentbudget = -1; + } + } + +void NewTransaction::setCurrentLineItem ( int index ) + { + currentlineitem = ( lineitemidslist.operator[] ( index ).toInt() ); + } + +int NewTransaction::getCurrentBudget () + { + return currentbudget; + } + +int NewTransaction::getBudgetIndex ( int budgetid ) + { + currentbudget = budgetid; + const QString budget = QString::number ( budgetid ); + return budgetidslist->findIndex ( budget ); + } + +int NewTransaction::getLineItemIndex ( int lineitemid ) + { + currentlineitem = lineitemid; + const QString lineitem = QString::number ( lineitemid ); + return lineitemidslist.findIndex ( lineitem ); + } + +void NewTransaction::setLineItems () + { + lineitemslist = budget->getLineItems ( currentbudget ); + lineitemidslist = budget->getLineItemIDs ( currentbudget ); + lineitemlabel->setEnabled ( TRUE ); + lineitembox->setEnabled ( TRUE ); + lineitembox->clear(); + lineitembox->insertStringList ( lineitemslist ); + } + +int NewTransaction::getCurrentLineItem () + { + return currentlineitem; + } + +void NewTransaction::setComboBoxes ( int budgetid, int lineitemid ) + { + const QString budgetname = QString::number ( budgetid ); + budgetbox->setCurrentItem ( ( budgetidslist->findIndex ( budgetname ) ) ); + currentbudget = budgetidslist->operator[] ( budgetbox->currentItem() - 1 ).toInt(); + + lineitemslist = budget->getLineItems ( currentbudget ); + lineitemidslist = budget->getLineItemIDs ( currentbudget ); + lineitemlabel->setEnabled ( TRUE ); + lineitembox->setEnabled ( TRUE ); + lineitembox->clear(); + lineitembox->insertStringList ( lineitemslist ); + + const QString lineitem = QString::number ( lineitemid ); + lineitembox->setCurrentItem ( lineitemidslist.findIndex ( lineitem ) ); + currentlineitem = ( lineitemidslist.operator[] ( lineitembox->currentItem() ).toInt() ); + } diff --git a/noncore/unsupported/qashmoney/newtransaction.h b/noncore/unsupported/qashmoney/newtransaction.h new file mode 100755 index 0000000..db3a5ad --- a/dev/null +++ b/noncore/unsupported/qashmoney/newtransaction.h @@ -0,0 +1,96 @@ +#ifndef NEWTRANSACTION_H +#define NEWTRANSACTION_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "transaction.h" +#include "preferences.h" + +class NewTransaction : public QDialog +{ + Q_OBJECT + + public: + + int year, month, day; + + NewTransaction ( QWidget* parent ); + ~NewTransaction(); + + QLabel *namelabel; + QHBox *transactionnamebox; + QComboBox* transactionname; + QPushButton* descriptionbutton; + + QLabel *amountlabel; + QHBox *transactionamountbox; + QLineEdit* transactionamount; + QPushButton* calculatorbutton; + + QLabel *datelabel; + QHBox *transactiondatebox; + QLineEdit* transactiondate; + QPushButton* datebutton; + + QCheckBox *clearedcheckbox; + + QLabel *numberlabel; + QLineEdit *transactionnumber; + + QLabel *budgetlabel; + QComboBox *budgetbox; + + QLabel *lineitemlabel; + QComboBox *lineitembox; + + QCheckBox *depositbox; + + QGridLayout *layout; + + int getDay (); + int getMonth (); + int getYear (); + QString getDescription (); + void setDescription ( QString ); + void setComboBoxes ( int, int ); + + // When a user edits an transaction and edits the date, this flag + // is set to TRUE adding the new date to the transaction. Otherwise, + // the old date is used for the edited transaction. This prevents a date + // from reverting to 0/0/0 if the date is not edited + bool getDateEdited (); + + public slots: + + void showCalculator(); + void showCalendar (); + void addTransactionDescription (); + int getNameIndex ( QString name ); + int getCurrentBudget (); + int getCurrentLineItem (); + int getBudgetIndex ( int budgetid ); + int getLineItemIndex ( int lineitemid ); + void setLineItems (); + + private slots: + void setCurrentBudget ( int index ); + void setCurrentLineItem ( int index ); + + private: + bool dateedited; + int index, currentbudget, currentlineitem; + QString transactiondescription; + QStringList *budgetnameslist, *budgetidslist; + QStringList lineitemslist, lineitemidslist; + +}; + +#endif diff --git a/noncore/unsupported/qashmoney/preferencedialogs.cpp b/noncore/unsupported/qashmoney/preferencedialogs.cpp new file mode 100755 index 0000000..b83c957 --- a/dev/null +++ b/noncore/unsupported/qashmoney/preferencedialogs.cpp @@ -0,0 +1,216 @@ +#include "preferencedialogs.h" +#include "preferences.h" + +extern Preferences *preferences; + +DatePreferences::DatePreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) + { + setCaption( tr( "Date" ) ); + + QLabel *datelabel = new QLabel ( "Format", this ); + dateformat = new QComboBox ( this ); + dateformat->setEditable ( FALSE ); + dateformat->insertItem ( "yyyymmdd" ); + dateformat->insertItem ( "yymmdd" ); + dateformat->insertItem ( "mmddyyyy" ); + dateformat->insertItem ( "mmddyy" ); + dateformat->insertItem ( "yyyyddmm" ); + dateformat->insertItem ( "yyddmm" ); + dateformat->insertItem ( "ddmmyyyy" ); + dateformat->insertItem ( "ddmmyy" ); + connect ( dateformat, SIGNAL ( activated(int) ), this, SLOT ( changeDateFormat(int) ) ); + + QLabel *dateseparatorlabel = new QLabel ( "Separator", this ); + dateseparator = new QComboBox ( this ); + dateseparator->insertItem ( "/" ); + dateseparator->insertItem ( "-" ); + dateseparator->insertItem ( "." ); + connect ( dateseparator, SIGNAL ( activated(int) ), this, SLOT ( changeDateSeparator(int) ) ); + + defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); + connect ( defaults, SIGNAL ( released() ), this, SLOT ( setDefaultDatePreferences() ) ); + + dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 ); + dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 ); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->addWidget ( datelabel ); + layout->addWidget ( dateformat ); + layout->addWidget ( dateseparatorlabel ); + layout->addWidget ( dateseparator ); + layout->insertSpacing ( 4, 5 ); + layout->addWidget ( defaults ); + + } + +DatePreferences::~DatePreferences () + { + } + +void DatePreferences::changeDateFormat ( int index ) + { + index ++; + preferences->changePreference ( 1, index ); + } + +void DatePreferences::changeDateSeparator ( int index ) + { + index ++; + preferences->changePreference ( 2, index ); + } + +void DatePreferences::setDefaultDatePreferences () + { + preferences->setDefaultDatePreferences (); + dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 ); + dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 ); + } + +// START TRANSACTION PREFERENCES + +TransactionPreferences::TransactionPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) +{ + setCaption( tr ( "Transaction" ) ); + + showclearedtransactions = new QCheckBox ( this ); + showclearedtransactions->setText ( "Show Cleared Transactions" ); + + limittransactionsbox = new QHBox ( this ); + limittransactionsbox->setSpacing ( 2 ); + limittransactionslabel = new QLabel ( "Show ", limittransactionsbox ); + limittransactions = new QComboBox ( limittransactionsbox ); + QLabel *limittransactionslabel2 = new QLabel ( "of cleared transactions. ", limittransactionsbox ); + limittransactions->insertItem ( "14 days" ); + limittransactions->insertItem ( "30 days" ); + limittransactions->insertItem ( "90 days" ); + limittransactions->insertItem ( "180 days" ); + limittransactions->insertItem ( "365 days" ); + limittransactions->insertItem ( "All" ); + limittransactions->setCurrentItem ( preferences->getPreference ( 7 ) ); + + excludetransfers = new QCheckBox ( this ); + excludetransfers->setText ( "Include Transfers In Limit View" ); + + if ( preferences->getPreference ( 3 ) == 1 ) + showclearedtransactions->setChecked ( TRUE ); + else + showclearedtransactions->setChecked ( FALSE ); + + if ( preferences->getPreference ( 6 ) == 1 ) + excludetransfers->setChecked ( TRUE ); + else + excludetransfers->setChecked ( FALSE ); + + defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); + connect ( defaults, SIGNAL ( released() ), this, SLOT ( setDefaultTransactionPreferences() ) ); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->addWidget ( showclearedtransactions ); + layout->addWidget ( limittransactionsbox ); + layout->addWidget ( excludetransfers ); + layout->insertSpacing ( 3, 5 ); + layout->addWidget ( defaults ); + + connect ( showclearedtransactions, SIGNAL ( toggled(bool) ), this, SLOT ( changeShowClearedPreference(bool) ) ); + connect ( excludetransfers, SIGNAL ( toggled(bool) ), this, SLOT ( changeExcludeTranfersPreference(bool) ) ); + connect ( limittransactions, SIGNAL ( activated(int) ), this, SLOT ( changeLimitTransactionsPreference(int) ) ); +} + +TransactionPreferences::~TransactionPreferences () + { + } + +void TransactionPreferences::changeLimitTransactionsPreference ( int pref ) + { + preferences->changePreference ( 7, pref ); + } + +void TransactionPreferences::changeShowClearedPreference ( bool state ) + { + if ( state == TRUE ) + preferences->changePreference ( 3, 1 ); + else + preferences->changePreference ( 3, 0 ); + } + +void TransactionPreferences::changeExcludeTranfersPreference ( bool state ) + { + if ( state == TRUE ) + preferences->changePreference ( 6, 1 ); + else + preferences->changePreference ( 6, 0 ); + } + +void TransactionPreferences::setDefaultTransactionPreferences () + { + preferences->changePreference ( 3, 0 ); + preferences->changePreference ( 6, 0 ); + preferences->changePreference ( 7, 0 ); + showclearedtransactions->setChecked ( FALSE ); + limittransactions->setCurrentItem ( 0 ); + } + +// START ACCOUNT PREFERNCES + +AccountPreferences::AccountPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) +{ + + setCaption( tr ( "Account" ) ); + + currencysupport = new QCheckBox ( this ); + currencysupport->setText ( "Enable Currency Support" ); + + onetouch = new QCheckBox ( this ); + onetouch->setText ( "One Touch Account Viewing" ); + + if ( preferences->getPreference ( 4 ) == 1 ) + currencysupport->setChecked ( TRUE ); + else + currencysupport->setChecked ( FALSE ); + + if ( preferences->getPreference ( 5 ) == 1 ) + onetouch->setChecked ( TRUE ); + else + onetouch->setChecked ( FALSE ); + + defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); + connect ( defaults, SIGNAL ( released() ), this, SLOT ( setDefaultAccountPreferences() ) ); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->addWidget ( currencysupport ); + layout->addWidget ( onetouch ); + layout->insertSpacing ( 2, 5 ); + layout->addWidget ( defaults ); + + connect ( currencysupport, SIGNAL ( toggled(bool) ), this, SLOT ( changeCurrencySupport(bool) ) ); + connect ( onetouch, SIGNAL ( toggled(bool) ), this, SLOT ( changeOneTouchViewing(bool) ) ); +} + +AccountPreferences::~AccountPreferences () + { + } + +void AccountPreferences::changeCurrencySupport ( bool state ) + { + if ( state == TRUE ) + preferences->changePreference ( 4, 1 ); + else + preferences->changePreference ( 4, 0 ); + } + +void AccountPreferences::changeOneTouchViewing ( bool state ) + { + if ( state == TRUE ) + preferences->changePreference ( 5, 1 ); + else + preferences->changePreference ( 5, 0 ); + } + +void AccountPreferences::setDefaultAccountPreferences () + { + preferences->changePreference ( 4, 0 ); + preferences->changePreference ( 5, 0 ); + currencysupport->setChecked ( FALSE ); + onetouch->setChecked ( FALSE ); + } + diff --git a/noncore/unsupported/qashmoney/preferencedialogs.h b/noncore/unsupported/qashmoney/preferencedialogs.h new file mode 100755 index 0000000..88281b8 --- a/dev/null +++ b/noncore/unsupported/qashmoney/preferencedialogs.h @@ -0,0 +1,90 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef DATEPREFERENCES_H +#define DATEPREFERENCES_H + +class DatePreferences : public QDialog + { + Q_OBJECT + + public: + DatePreferences ( QWidget * parent ); + ~DatePreferences(); + + QPushButton *defaults; + QComboBox *dateformat; + QComboBox *dateseparator; + QBoxLayout *layout; + + public slots: + void changeDateFormat ( int ); + void changeDateSeparator ( int ); + void setDefaultDatePreferences (); +}; + +#endif + +#ifndef TRANSACTIONPREFERENCES_H +#define TRANSACTIONPREFERENCES_H + +class TransactionPreferences : public QDialog + { + Q_OBJECT + + public: + TransactionPreferences ( QWidget * parent ); + ~TransactionPreferences(); + + QCheckBox *showclearedtransactions; + QCheckBox *excludetransfers; + QHBox *limittransactionsbox; + QLabel *limittransactionslabel; + QComboBox *limittransactions; + QPushButton *defaults; + QBoxLayout *layout; + + public slots: + void changeShowClearedPreference ( bool ); + void changeExcludeTranfersPreference ( bool ); + void setDefaultTransactionPreferences (); + void changeLimitTransactionsPreference ( int ); +}; + +#endif + +#ifndef ACCOUNTPREFERENCES_H +#define ACCOUNTPREFERENCES_H + +class AccountPreferences : public QDialog + { + Q_OBJECT + + public: + AccountPreferences ( QWidget * parent ); + ~AccountPreferences(); + + QCheckBox *currencysupport; + QCheckBox *onetouch; + QPushButton *defaults; + QBoxLayout *layout; + + public slots: + void changeCurrencySupport ( bool ); + void changeOneTouchViewing ( bool ); + void setDefaultAccountPreferences (); +}; + +#endif + + + + diff --git a/noncore/unsupported/qashmoney/preferences.cpp b/noncore/unsupported/qashmoney/preferences.cpp new file mode 100755 index 0000000..880807a --- a/dev/null +++ b/noncore/unsupported/qashmoney/preferences.cpp @@ -0,0 +1,352 @@ +#include "preferences.h" +#include + +Preferences::Preferences () + { + db = sqlite_open ( "qmpreferences.db", 0, NULL ); + } + +Preferences::~Preferences () + { + sqlite_close ( db ); + } + +void Preferences::addPreferences () + { + // This function checks the preferences database for existing preferences and adds + // them if they are not there. First we set up variables. Preferences are always set + // to non-zero numbers because when we check to see if a preference has been + // added to the database, the result is zero if it hasn't + int rows = 0; + int columns = 0; + char **results; + + sqlite_get_table ( db, "select count() from preferences;", &results, 0, 0, 0 ); + if ( atoi ( results [ 1 ] ) != 7 ) + { + // dateformat preference 1 = yyyymmdd 2 = yymmdd 3 = mmddyyyy 4 = mmddyy + // 5 = yyyyddmm 6 = yyddmm 7 = ddmmyyyy 8 = ddmmyy + sqlite_get_table ( db, "select preference from preferences where id = 1;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 4, 'dateformat', 0, 0, 0, NULL );", 0, 0, 0 ); + + // dateseparator preference 1 = / ( forward slash ) 2 = - ( dash ) 3 = . ( period ) + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 2;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 1, 'dateseparator', 0, 0, 0, NULL );", 0, 0, 0 ); + + // showclearedtransactions preference 0 = no 1 = yes + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 3;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'showclearedtransactions', 0, 0, 0, NULL );", 0, 0, 0 ); + + // enable currency support preference 0 = no 1 = yes + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 4;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'enablecurrencysupport', 0, 0, 0, NULL );", 0, 0, 0 ); + + // one touch account viewing preference 0 = no 1 = yes + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 5;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'onetouchviewing', 0, 0, 0, NULL );", 0, 0, 0 ); + + // exclude transfers from limit view 0 = no 1 = yes + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 6;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'excludetransfersfromlimit', 0, 0, 0, NULL );", 0, 0, 0 ); + + // limit number of transactions to 0 = 14 days 1 = 30 days, 2 = 90 days, 3 = 180 days, 4 = 365 days 5 = all + rows = 0; + sqlite_get_table ( db, "select preference from preferences where id = 7;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into preferences values ( 0, 'limittransactions', 0, 0, 0, NULL );", 0, 0, 0 ); + } + } + +void Preferences::initializeColumnPreferences () + { + int rows = 0; + int columns = 0; + char **results; + + // initialize accountname column width + sqlite_get_table ( db, "select width from columns where id = 1;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'accountname', 90, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize accountbalance column width + sqlite_get_table ( db, "select width from columns where id = 2;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'accountbalance', 90, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactiondate column width + sqlite_get_table ( db, "select width from columns where id = 3;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'normaltransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionname column width + sqlite_get_table ( db, "select width from columns where id = 4;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'normaltransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionamount column width + sqlite_get_table ( db, "select width from columns where id = 5;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'normaltransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactiondate column width + sqlite_get_table ( db, "select width from columns where id = 6;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'extendedtransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionname column width + sqlite_get_table ( db, "select width from columns where id = 7;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'extendedtransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionamount column width + sqlite_get_table ( db, "select width from columns where id = 8;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'extendedtransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize transactionaccount column width + sqlite_get_table ( db, "select width from columns where id = 9;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'transactionaccount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize account name with currency column width + sqlite_get_table ( db, "select width from columns where id = 10;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'accountnamewithcurrency', 100, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize account currency column width + sqlite_get_table ( db, "select width from columns where id = 11;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'currencycolumn', 10, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize account balance with currency column width + sqlite_get_table ( db, "select width from columns where id = 12;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'accountbalancewithcurrency', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize budget line item column + sqlite_get_table ( db, "select width from columns where id = 13;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'budgetlineitem', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize budget budget column + sqlite_get_table ( db, "select width from columns where id = 14;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'budgetbudget', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + + // initialize budget actual column + sqlite_get_table ( db, "select width from columns where id = 15;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into columns values ( 'budgetactual', 50, 0, 0, 0, NULL );", 0, 0, 0 ); + } + +void Preferences::initializeSortingPreferences () + { + int rows = 0; + int columns = 0; + char **results; + + if ( sqlite_get_table ( db, "select count() from sorting;", 0, 0, 0, 0 ) != 0 ) + sqlite_exec ( db, "create table sorting ( listbox, column, direction, id integer primary key );", 0, 0, 0 ); + + // initialize account listbox sorting. Set direction = 1 here so ascending sort is default. + sqlite_get_table ( db, "select column, direction from sorting where id = 1;", &results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into sorting values ( 'accounts', 0, 1, NULL );", 0, 0, 0 ); + + // initialize transaction listbox sorting + sqlite_get_table ( db, "select column, direction from sorting where id = 2;", &results, &rows, &columns, 0); + if ( rows == 0 ) + sqlite_exec ( db, "insert into sorting values ( 'transactions', 0, 1, NULL );", 0, 0, 0 ); + + // initialize budgets listbox sorting + sqlite_get_table ( db, "select column, direction from sorting where id = 3;", & results, &rows, &columns, 0 ); + if ( rows == 0 ) + sqlite_exec ( db, "insert into sorting values ( 'budgets', 0, 1, NULL );", 0, 0, 0 ); + } + +void Preferences::changeColumnPreference ( int id, int width ) + { + sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id ); + } + +int Preferences::getColumnPreference ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select width from columns where id = %i;", &results, NULL, NULL, NULL, id ); + return atoi ( results [ 1 ] ); + } + +void Preferences::changeSortingPreference ( int id, int column ) + { + int pColumn = 0; // column setting coming from the prefs object + int pDirection = 0; // direction setting coming from the prefs object + + // because there appears to be no way to query the QT header object directly for it's current sort settings, we have + // to maintain track of them ourselves. So start by pulling the current saved setting for this view. + getSortingPreference ( id, &pColumn, &pDirection ); + + // if the current saved column == the new column, then the user wants to toggle the sort order. + // otherwise we behave like QT does by default, which is to select the new column and default to an ascending sort. + if ( column == pColumn ) + sqlite_exec_printf ( db, "update sorting set direction = %i where id = %i;", 0, 0, 0, !pDirection, id ); + else + sqlite_exec_printf ( db, "update sorting set column = %i, direction = 1 where id = %i;", 0, 0, 0, column, id ); + } + +void Preferences::getSortingPreference ( int id, int *column, int *direction ) + { + char **results; + sqlite_get_table_printf ( db, "select column, direction from sorting where id = %i;", &results, NULL, NULL, NULL, id ); + *column = atoi ( results [ 2 ] ); + *direction = atoi ( results [ 3 ] ); + } + +int Preferences::getPreference ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select preference from preferences where id = %i;", &results, NULL, NULL, NULL, id ); + return atoi ( results [ 1 ] ); + } + +QString Preferences::getSeparator ( ) + { + int s = getPreference ( 2 ); + if ( s == 1 ) + return "/"; + if ( s ==2 ) + return "-"; + else + return "."; + } + +void Preferences::changePreference ( int id, int newpreference ) + { + sqlite_exec_printf ( db, "update preferences set preference = %i where id = %i;", 0, 0, 0, newpreference, id ); + } + +void Preferences::setDefaultDatePreferences () + { + sqlite_exec ( db, "update preferences set preference = 4 where id = 1;", 0, 0, 0 ); + sqlite_exec ( db, "update preferences set preference = 1 where id = 2;", 0, 0, 0 ); + } + +QString Preferences::getDate ( int y, int m, int d ) + { + QString date; + int format = getPreference ( 1 ); + QString separator = getSeparator(); + + // Convert all date integers to QStrings + QString year = QString::number ( y ); + QString month = QString::number ( m ); + if ( m < 10 ) + month.prepend ( "0" ); + QString day = QString::number ( d ); + if ( d < 10 ) + day.prepend ( "0" ); + + // Truncate four digit year if necessary + if ( format == 2 || format == 4 || format == 6 || format == 8 ) + year.remove ( 0, 2 ); + + // Concatenate dates as necessary + if ( format == 1 || format == 2 ) + { + date = year; + date.append ( separator ); + date.append ( month ); + date.append ( separator ); + date.append ( day ); + return date; + } + if ( format == 3 || format == 4 ) + { + date = month; + date.append ( separator ); + date.append ( day ); + date.append ( separator ); + date.append ( year ); + return date; + } + if ( format == 5 || format == 6 ) + { + date = year; + date.append ( separator ); + date.append ( day ); + date.append ( separator ); + date.append ( month ); + return date; + } + if ( format == 7 || format == 8 ) + { + date = day; + date.append ( separator ); + date.append ( month ); + date.append ( separator ); + date.append ( year ); + return date; + } + } + +QString Preferences::getDate ( int y, int m ) + { + QString date; + int format = getPreference ( 1 ); + QString separator = getSeparator(); + + // Convert all date integers to QStrings + QString year = QString::number ( y ); + QString month = QString::number ( m ); + if ( m < 10 ) + month.prepend ( "0" ); + + // Truncate four digit year if necessary + if ( format == 2 || format == 4 || format == 6 || format == 8 ) + year.remove ( 0, 2 ); + + // Concatenate dates as necessary + if ( format == 1 || format == 2 ) + { + date = year; + date.append ( separator ); + date.append ( month ); + return date; + } + if ( format == 3 || format == 4 ) + { + date = month; + date.append ( separator ); + date.append ( year ); + return date; + } + if ( format == 5 || format == 6 ) + { + date = year; + date.append ( separator ); + date.append ( month ); + return date; + } + if ( format == 7 || format == 8 ) + { + date.append ( month ); + date.append ( separator ); + date.append ( year ); + return date; + } + } + + + + + diff --git a/noncore/unsupported/qashmoney/preferences.h b/noncore/unsupported/qashmoney/preferences.h new file mode 100755 index 0000000..38579ad --- a/dev/null +++ b/noncore/unsupported/qashmoney/preferences.h @@ -0,0 +1,53 @@ +#include +#include + +#ifndef PREFERENCES_H +#define PREFERENCES_H + +class Preferences + { + public: + Preferences (); + ~Preferences (); + + void addPreferences (); + void initializeColumnPreferences (); + void initializeSortingPreferences (); + + // Returns a preference value for the given preferences ID + int getPreference ( int ); + int getColumnPreference ( int id ); + void getSortingPreference ( int id, int *column, int *direction ); + + // Convenience for getting date separator with one function + // call. Takes the preference id as its argument + QString getSeparator ( ); + + // Changes a preference for the given ID + void changePreference ( int , int ); + void changeColumnPreference ( int id, int width ); + void changeSortingPreference ( int id, int column ); + + // The primary database that stores all our data + sqlite3 *db; + + // This function returns a Qstring for the year first date formats + // for displaying. It takes the date numbers + QString getDate ( int, int, int ); + QString getDate ( int y, int m ); + + void setDefaultDatePreferences (); + }; + +#endif + + + + + + + + + + + diff --git a/noncore/unsupported/qashmoney/qashmoney.cpp b/noncore/unsupported/qashmoney/qashmoney.cpp new file mode 100755 index 0000000..1455eb0 --- a/dev/null +++ b/noncore/unsupported/qashmoney/qashmoney.cpp @@ -0,0 +1,402 @@ +#include "qashmoney.h" +#include "preferencedialogs.h" +#include "memorydialog.h" + +#include + +Budget *budget = new Budget (); +Preferences *preferences = new Preferences (); +Account *account = new Account (); +Transaction *transaction = new Transaction (); +Transfer *transfer = new Transfer (); +Memory *memory = new Memory (); + +QashMoney::QashMoney () : QWidget () + { + preferences->addPreferences (); + preferences->initializeColumnPreferences (); + preferences->initializeSortingPreferences (); + + // set the text in the upper part of the frame + setCaption ( tr ( "QashMoney" ) ); + + // Create new menubar for our mainwindow + // and add menu items + mainmenu = new QMenuBar ( this ); + mainmenu->setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); + preferencesmenu = new QPopupMenu ( this ); + utilitiesmenu = new QPopupMenu ( this ); + mainmenu->insertItem ( "Preferences", preferencesmenu ); + mainmenu->insertItem ( "Utilities", utilitiesmenu ); + preferencesmenu->insertItem ( "Date", this, SLOT ( displayDatePreferencesDialog() ) ); + preferencesmenu->insertItem ( "Account", this, SLOT ( displayAccountPreferencesDialog() ) ); + preferencesmenu->insertItem ( "Transaction", this, SLOT ( displayTransactionPreferencesDialog() ) ); + utilitiesmenu->insertItem ( "Memory", this, SLOT ( displayMemoryDialog() ) ); + + // create the main tabwidget for displaying accounts and transactions + maintabs = new QTabWidget ( this ); + tab = new QWidget ( this ); + tab_2 = new QWidget ( this ); + tab_3 = new QWidget ( this ); + maintabs->addTab ( tab, "Accounts" ); + maintabs->addTab ( tab_2, "Transactions" ); + maintabs->addTab ( tab_3, "Budgets" ); + tabheight = tab->height(); + maintabs->setTabEnabled ( tab_2, FALSE ); + + // create a new account display object + accountdisplay = new AccountDisplay ( maintabs ); + accountdisplay->setTabs ( tab_2, maintabs ); + connect ( accountdisplay->listview, SIGNAL ( selectionChanged() ), this, SLOT ( setTransactionTab() ) ); + + // set the connection to disable the one touch account viewing if we are transfering money + connect ( accountdisplay->transferbutton, SIGNAL ( toggled(bool) ), this, SLOT ( toggleOneTouchViewing(bool) ) ); + + // create a new transactiondisplay object + transactiondisplay = new TransactionDisplay ( maintabs ); + transactiondisplay->hide(); + + // create new budgetdisplay object + budgetdisplay = new BudgetDisplay ( maintabs ); + budgetdisplay->hide(); + + tabslayout = new QVBoxLayout ( maintabs, 4, 2 ); + tabslayout->addSpacing ( tabheight ); + tabslayout->addWidget ( accountdisplay ); + tabslayout->addWidget ( transactiondisplay ); + tabslayout->addWidget ( budgetdisplay ); + + // connect a change in the maintabs with changing the tab display + connect ( maintabs, SIGNAL ( currentChanged(QWidget*) ), this, SLOT ( changeTabDisplay() ) ); + + // create layout that will contain the menubar and the maintabs + layout = new QVBoxLayout ( this, 2, 2 ); + layout->setMenuBar ( mainmenu ); + layout->addWidget ( maintabs ); + } + +QashMoney::~QashMoney () + { + delete budget; + delete preferences; + delete account; + delete transaction; + delete transfer; + delete memory; + } + +void QashMoney::changeTabDisplay () + { + // if the user pressed the transactions tab, hide the account display + // object and create a new transaction display + if ( maintabs->currentPageIndex() == 1 ) + { + // initialize variables + bool children = FALSE; + + // hide the account display and define accountid + int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); + + //remove all the columns from the transactiondisplay + int columns = transactiondisplay->listview->columns(); + int counter; + for ( counter = 0; counter <= columns; counter++ ) + transactiondisplay->listview->removeColumn ( 0 ); + + // set the account name and account balance + QString name = account->getAccountName ( accountid ); + QString balance = account->getAccountBalance ( accountid ); + transactiondisplay->name->setText ( name ); + transactiondisplay->balance->setText ( balance ); + + // clear the limitbox + transactiondisplay->limitbox->clear(); + + // get parent account id + int parentaccountid = account->getParentAccountID ( accountid ); + + // add columns based on which account is selected + // this first if determines if we selected a parent with no children or a child + // in these cases, we add standard three columns for date, transaction, amount + transactiondisplay->listview->addColumn ( "Date", 0 ); + transactiondisplay->listview->addColumn ( "Transaction", 0 ); + transactiondisplay->listview->addColumn ( "Amt", 0); + transactiondisplay->listview->setColumnAlignment ( 2, Qt::AlignRight ); + transactiondisplay->listview->addColumn ( "", 0 ); + + if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) // we selected a parent with children + { + // add an extra column for the account name for eac child transaction + transactiondisplay->listview->addColumn ( "Acct", 0 ); + children = TRUE; + + // hide the new transaction button + transactiondisplay->newtransaction->setEnabled ( FALSE ); + } + else //we selected a parent without children or a child + transactiondisplay->newtransaction->setEnabled ( TRUE ); + + // disable the transactionid column so it can't be red + transactiondisplay->listview->header()->setResizeEnabled ( FALSE, 3 ); + + // set the accountid and children variables + transactiondisplay->setChildren ( children ); + transactiondisplay->setAccountID ( accountid ); + + setTransactionDisplayDate (); + + // display transactions + transactiondisplay->listview->clear(); + QString displaytext = "%"; + displaytext.prepend ( transactiondisplay->limitbox->text() ); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); + + // display transfers + transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); + + // open a new preferences object and resize the transaction display columns + // each column will have a different size based on whether we are looking at a child + // account or children through a parent + if ( parentaccountid != -1 || accountdisplay->listview->selectedItem()->childCount() == 0 ) // a parent with no children or a child - three columns + { + transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 3 ) ); // normal transaction date width + transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); + transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 4 ) ); // normal transaction name width + transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); + transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 5 ) ); // normal transaction amount width + transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); + } + else + { + transactiondisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 6 ) ); // extended transaction date width + transactiondisplay->listview->setColumnWidthMode ( 0, QListView::Manual ); + transactiondisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 7 ) ); // extended transaction name width + transactiondisplay->listview->setColumnWidthMode ( 1, QListView::Manual ); + transactiondisplay->listview->setColumnWidth ( 2, preferences->getColumnPreference ( 8 ) ); // extended transaction amount width + transactiondisplay->listview->setColumnWidthMode ( 2, QListView::Manual ); + transactiondisplay->listview->setColumnWidth ( 4, preferences->getColumnPreference ( 9 ) ); // transaction account width + transactiondisplay->listview->setColumnWidthMode ( 4, QListView::Manual ); + } + + // pull the column sorting preference from the preferences table, and configure the listview accordingly + int column = 0; + int direction = 0; + preferences->getSortingPreference ( 2, &column, &direction ); + transactiondisplay->listview->setSorting ( column, direction ); + + // show the window + transactiondisplay->show(); + // hide the account display and define accountid + accountdisplay->hide(); + // hide the budget display + budgetdisplay->hide(); + } + else if ( maintabs->currentPageIndex() == 0 ) + { + disableOneTouchViewing(); + + // clear the account display selection + accountdisplay->listview->clearSelection(); + + // resize the account display columns + accountdisplay->listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); + accountdisplay->listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); + + // set sorting preference on account display columns + int column = 0; + int direction = 0; + preferences->getSortingPreference ( 1, &column, &direction ); + accountdisplay->listview->setSorting ( column, direction ); + + // display the accounts + if ( account->getNumberOfAccounts() != 0 ) + account->displayAccounts ( accountdisplay->listview ); + maintabs->setTabEnabled ( tab_2, FALSE ); + + // set the toggle button + accountdisplay->setToggleButton (); + + // show the account display + accountdisplay->show(); + + // hide the transaction display + transactiondisplay->hide(); + + // hide the budget display + budgetdisplay->hide(); + + + enableOneTouchViewing (); + } + else + { + budgetdisplay->displayLineItems(); + budgetdisplay->show(); + transactiondisplay->hide(); + accountdisplay->hide(); + } + } + +void QashMoney::setTransactionTab () + { + if ( accountdisplay->listview->selectedItem() == 0 ) + maintabs->setTabEnabled ( tab_2, FALSE ); + else + maintabs->setTabEnabled ( tab_2, TRUE ); + } + +void QashMoney::displayDatePreferencesDialog () + { + // this shows a dialog to set preferences for formatting the date + DatePreferences *pd = new DatePreferences ( this ); + pd->exec (); + if ( transactiondisplay->isVisible() ) + { + // set the account id + int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); + + // set children so we can let displayTransfers know if there are children for the selected account + bool children; + if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) + children = TRUE; + else + children = FALSE; + + // redisplay transactions if they are visible incorporating + // any changes to the date format + transactiondisplay->listview->clear(); + QString displaytext = "%"; + displaytext.prepend ( transactiondisplay->limitbox->text() ); + + setTransactionDisplayDate(); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); + + if ( transfer->getNumberOfTransfers() != 0 ) + transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); + } + else if ( accountdisplay->isVisible() ) + { + accountdisplay->listview->clearSelection(); + maintabs->setTabEnabled ( tab_2, FALSE ); + } + else + budgetdisplay->updateBudgetInformation(); + } + +void QashMoney::displayTransactionPreferencesDialog () + { + // display a dialog for setting preferences for transactions + TransactionPreferences *td = new TransactionPreferences ( this ); + td->exec (); + if ( transactiondisplay->isVisible() ) + { + // set the account id + int accountid = accountdisplay->listview->selectedItem()->text ( accountdisplay->getIDColumn() ).toInt(); + + // set children so we can let displayTransfers know if there are children for the selected account + bool children; + if ( accountdisplay->listview->selectedItem()->parent() == 0 && accountdisplay->listview->selectedItem()->childCount() != 0 ) + children = TRUE; + else + children = FALSE; + + // redisplay transactions incorporating any transaction preference changes + transactiondisplay->listview->clear(); + QString displaytext = "%"; + displaytext.prepend ( transactiondisplay->limitbox->text() ); + + setTransactionDisplayDate(); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( transactiondisplay->listview, accountid, children, displaytext, newdate ); + + if ( transfer->getNumberOfTransfers() != 0 ) + transfer->displayTransfers ( transactiondisplay->listview, accountid, children, newdate ); + } + else + { + accountdisplay->listview->clearSelection(); + maintabs->setTabEnabled ( tab_2, FALSE ); + } + } + +void QashMoney::displayAccountPreferencesDialog () + { + // display a dialog for setting preferences for accounts + AccountPreferences *ap = new AccountPreferences ( this ); + ap->exec (); + + if ( accountdisplay->isVisible() && account->getNumberOfAccounts() != 0 ) + { + accountdisplay->listview->clear(); + account->displayAccounts ( accountdisplay->listview ); + accountdisplay->listview->clearSelection(); + maintabs->setTabEnabled ( tab_2, FALSE ); + } + changeTabDisplay(); + } + +void QashMoney::displayMemoryDialog () + { + // opens a dialog to add, edit and delete memory items + MemoryDialog *md = new MemoryDialog (); + md->exec(); + } + +void QashMoney::showTransactions () + { + maintabs->setCurrentPage ( 1 ); + } + +void QashMoney::enableOneTouchViewing () + { + if ( preferences->getPreference ( 5 ) == 1 ) + connect ( accountdisplay->listview, SIGNAL ( selectionChanged() ), this, SLOT ( showTransactions() ) ); + else + disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged() ), this, SLOT ( showTransactions() ) ); + } + +void QashMoney::disableOneTouchViewing () + { + disconnect ( accountdisplay->listview, SIGNAL ( selectionChanged() ), this, SLOT ( showTransactions() ) ); + } + +void QashMoney::toggleOneTouchViewing ( bool state ) + { + if ( state == TRUE ) + disableOneTouchViewing(); + else + enableOneTouchViewing(); + } + +void QashMoney::setTransactionDisplayDate () + { + // determine how many days of transactions to show + int limittype = preferences->getPreference ( 7 ); + if ( limittype != 5 ) // set today's date if we are not showing all transactions + { + QDate today = QDate::currentDate (); + switch ( limittype ) // if we are not showing all transactions + { + case 0: // viewing two weeks + newdate = today.addDays ( -14 ); + break; + case 1: // viewing one month + newdate = today.addDays ( -30 ); + break; + case 2: // three months + newdate = today.addDays ( -90 ); + break; + case 3: // six months + newdate = today.addDays ( -180 ); + break; + case 4: // one year + newdate = today.addDays ( -365 ); + break; + } + } + else + newdate = QDate ( 1900, 1, 1 ); + } + diff --git a/noncore/unsupported/qashmoney/qashmoney.h b/noncore/unsupported/qashmoney/qashmoney.h new file mode 100755 index 0000000..f2c456c --- a/dev/null +++ b/noncore/unsupported/qashmoney/qashmoney.h @@ -0,0 +1,64 @@ +#ifndef QASHMONEY_H +#define QASHMONEY_H + +#include +#include +#include +#include +#include + +#include "accountdisplay.h" +#include "transactiondisplay.h" +#include "budgetdisplay.h" +#include "account.h" +#include "preferences.h" +#include "transaction.h" +#include "transfer.h" +#include "memory.h" +#include "budget.h" + +class QashMoney : public QWidget + { + Q_OBJECT + + public: + QashMoney (); + ~QashMoney(); + + QTabWidget* maintabs; + QWidget* tab; + QWidget* tab_2; + QWidget* tab_3; + + QMenuBar *mainmenu; + QPopupMenu *preferencesmenu; + QPopupMenu *utilitiesmenu; + + public slots: + void displayDatePreferencesDialog (); + void displayTransactionPreferencesDialog (); + void displayAccountPreferencesDialog (); + void displayMemoryDialog (); + void setTransactionTab (); + + private slots: + void changeTabDisplay (); + void showTransactions (); + void enableOneTouchViewing (); + void disableOneTouchViewing (); + void toggleOneTouchViewing ( bool ); + void setTransactionDisplayDate (); + + private: + QVBoxLayout *layout; + QVBoxLayout *tabslayout; + AccountDisplay *accountdisplay; + TransactionDisplay *transactiondisplay; + BudgetDisplay *budgetdisplay; + int tabheight; + QDate newdate; + + }; + +#endif + diff --git a/noncore/unsupported/qashmoney/qashmoney.pro b/noncore/unsupported/qashmoney/qashmoney.pro new file mode 100755 index 0000000..faa898b --- a/dev/null +++ b/noncore/unsupported/qashmoney/qashmoney.pro @@ -0,0 +1,55 @@ +TEMPLATE = app +CONFIG = qt warn_on +HEADERS = qashmoney.h \ + accountdisplay.h \ + account.h \ + transaction.h \ + transactiondisplay.h \ + newtransaction.h \ + transfer.h \ + transferdialog.h \ + preferences.h \ + preferencedialogs.h \ + memory.h \ + memorydialog.h \ + newaccount.h \ + calculator.h \ + datepicker.h \ + budget.h \ + budgetdisplay.h \ + currency.h +SOURCES = qashmoney.cpp \ + accountdisplay.cpp \ + account.cpp \ + transaction.cpp \ + transactiondisplay.cpp \ + newtransaction.cpp \ + transfer.cpp \ + transferdialog.cpp \ + preferences.cpp \ + preferencedialogs.cpp \ + memory.cpp \ + memorydialog.cpp \ + newaccount.cpp \ + calculator.cpp \ + datepicker.cpp \ + main.cpp \ + budget.cpp \ + budgetdisplay.cpp \ + currency.cpp +INCLUDEPATH = $(OPIEDIR)/include +DEPENDPATH = $(OPIEDIR)/include +TARGET = qashmoney +DESTDIR = $(OPIEDIR)/bin + +unix:LIBS += -lm +LIBS += -lqpe -lopiecore2 -lsqlite3 + +include ( $(OPIEDIR)/include.pro ) + +!isEmpty( LIBSQLITE_INC_DIR ) { + INCLUDEPATH = $$LIBSQLITE_INC_DIR $$INCLUDEPATH +} +!isEmpty( LIBSQLITE_LIB_DIR ) { + LIBS = -L$$LIBSQLITE_LIB_DIR $$LIBS +} diff --git a/noncore/unsupported/qashmoney/transaction.cpp b/noncore/unsupported/qashmoney/transaction.cpp new file mode 100755 index 0000000..d008a4f --- a/dev/null +++ b/noncore/unsupported/qashmoney/transaction.cpp @@ -0,0 +1,345 @@ +// RESERVEDONE COLUMN NAME REPRESENTS THE LINEITEMID AND SHOULD BE CHANGED IN +// FUTURE VERSIONS OF QASHMONEY + +// RESERVEDTWO REPRESENTS THE TRANSACTION DESCRIPTION + +#include "transaction.h" +#include "account.h" +#include "transactiondisplay.h" + +#include + +extern Account *account; +extern Preferences *preferences; + +Transaction::Transaction () + { + tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); + } + +Transaction::~Transaction () + { + sqlite_close ( tdb ); + } + +void Transaction::addTransaction ( QString description, QString payee, int accountid, int parentid, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid ) + { + sqlite_exec_printf ( tdb, "insert into transactions values ( '%q', %i, %i, %i, %i, %i, %i, %.2f, %i, %i, 0, 0, 0, 0, 0, 0, %i, '%q', 0, " + "0, 0, 0, NULL );", 0, 0, 0, ( const char * ) payee, accountid, parentid, number, day, month, year, amount, cleared, budgetid, lineitemid, ( const char * ) description ); + } + +void Transaction::updateTransaction ( QString description, QString payee, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid, int transactionid ) + { + sqlite_exec_printf ( tdb, "update transactions set reservedtwo = '%q', payee = '%q', number = %i, day = %i, month = %i, year = %i, amount = %.2f," + "cleared = %i, budgetid = %i, reservedone = %i where transid = %i;", 0, 0, 0, ( const char * ) description, ( const char * ) payee, number, day, month, year, + amount, cleared, budgetid, lineitemid, transactionid ); + } + +void Transaction::deleteTransaction ( int transid ) + { + sqlite_exec_printf ( tdb, "delete from transactions where transid = %i;", 0, 0, 0, transid ); + } + +void Transaction::deleteAllTransactions ( int accountid ) + { + sqlite_exec_printf ( tdb, "delete from transactions where accountid = %i;", 0, 0, 0, accountid ); + } + +int Transaction::getAccountID ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select accountid from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + return atol ( results [ 1 ] ); + } + +int Transaction::getNumberOfTransactions () + { + char **results; + sqlite_get_table ( tdb, "select count() from transactions;", &results, NULL, NULL, NULL ); + return atoi ( results [ 1 ] ); + } + +int Transaction::getNumberOfTransactions ( int accountid ) + { + char **results; + sqlite_get_table_printf ( tdb, "select count() from transactions where accountid = %i;", &results, NULL, NULL, NULL, accountid ); + return atol ( results [ 1 ] ); + } + +QString Transaction::getPayee ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select payee from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + return results [ 1 ]; + } + +QString Transaction::getTransactionDescription ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select reservedtwo from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + return results [ 1 ]; + } + +QString Transaction::getNumber ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select number from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + return results [ 1 ]; + } + +QString Transaction::getAmount ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select amount from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + return results [ 1 ]; + } + +QString Transaction::getAbsoluteAmount ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select abs ( amount ) from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + return results [ 1 ]; + } + +int Transaction::getCleared ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select cleared from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + QString cleared = results [ 1 ]; + return cleared.toInt(); + } + +void Transaction::setCleared ( int id, int cleared ) + { + sqlite_exec_printf ( tdb, "update transactions set cleared = %i where transid = %i;", 0, 0, 0, cleared, id ); + } + +int Transaction::getBudgetID ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select budgetid from transactions where transid = %i;", &results, NULL, NULL, NULL, id ); + QString budgetid = results [ 1 ]; + return budgetid.toInt(); + } + +int Transaction::getLineItemID ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select reservedone from transactions where transid = %i;", &results, NULL, NULL, NULL, id ); + QString lineitemid = results [ 1 ]; + return lineitemid.toInt(); + } + +int Transaction::getDay ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select day from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + QString daystring = results [ 1 ]; + return daystring.toInt(); + } + +int Transaction::getMonth ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select month from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + QString monthstring = results [ 1 ]; + return monthstring.toInt(); + } + +int Transaction::getYear ( int id ) + { + char **results; + sqlite_get_table_printf ( tdb, "select year from transactions where transid= %i;", &results, NULL, NULL, NULL, id ); + QString yearstring = results [ 1 ]; + return yearstring.toInt(); + } + +char ** Transaction::selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id ) + { + // initialize variables + char **results; + int showcleared = preferences->getPreference ( 3 ); + QDate today = QDate::currentDate(); + int fromyear = fromdate.year(); + int toyear = today.year(); + int frommonth = fromdate.month(); + int tomonth = today.month(); + int fromday = fromdate.day(); + + // construct the first part of the string + QString query = "select day, month, year, payee, amount, transid, accountid from transactions where"; + + if ( frommonth == tomonth && fromyear == toyear ) // our dates cross neither a month nor a year + { + query.append ( " year = " ); + query.append ( QString::number ( toyear ) ); + query.append ( " and month = " ); + query.append ( QString::number ( tomonth ) ); + query.append ( " and day >= " ); + query.append ( QString::number ( fromday ) ); + query.append ( " and" ); + } + else if ( frommonth != tomonth && fromyear == toyear ) // our dates cross a month within the same year + { + query.append ( " year = " ); + query.append ( QString::number ( toyear ) ); + query.append ( " and ( ( month <= " ); + query.append ( QString::number ( tomonth ) ); + query.append ( " and month > " ); + query.append ( QString::number ( frommonth ) ); + query.append ( " ) or ( month = " ); + query.append ( QString::number ( frommonth ) ); + query.append ( " and day >= " ); + query.append ( QString::number ( fromday ) ); + query.append ( " ) ) and " ); + } + else if ( fromyear != toyear && fromyear != 1900 ) // here we are showing transactions from an entire year + { + // divide this taks into two parts - get the transactions from the prior and then the current year + // current year part + int tmpfrommonth = 1; // set temporary from months and days to Jan. 1 + int tmpfromday = 1; + query.append ( " ( year >= " ); + query.append ( QString::number ( fromyear ) ); + query.append ( " and ( month <= " ); + query.append ( QString::number ( tomonth ) ); + query.append ( " and month > " ); + query.append ( QString::number ( tmpfrommonth ) ); + query.append ( " ) or ( month = " ); + query.append ( QString::number ( tmpfrommonth ) ); + query.append ( " and day >= " ); + query.append ( QString::number ( tmpfromday ) ); + query.append ( " ) ) or" ); + + // prior year part + int tmptomonth = 12; + query.append ( " ( year = " ); + query.append ( QString::number ( fromyear ) ); + query.append ( " and ( ( month <= " ); + query.append ( QString::number ( tmptomonth ) ); + query.append ( " and month > " ); + query.append ( QString::number ( frommonth ) ); + query.append ( " ) or ( month = " ); + query.append ( QString::number ( frommonth ) ); + query.append ( " and day >= " ); + query.append ( QString::number ( fromday ) ); + query.append ( " ) ) ) and " ); + } + + if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) + query.append ( " parentid = %i and payee like '%q';" ); + else + query.append ( " accountid = %i and payee like '%q';" ); + + sqlite_get_table_printf ( tdb, query, &results, &rows, &columns, NULL, id, limit ); + return results; + } + +char ** Transaction::selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id ) + { + char **results; + if ( account->getParentAccountID ( id ) == -1 && children == TRUE ) + sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and parentid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); + else + sqlite_get_table_printf ( tdb, "select day, month, year, payee, amount, transid, accountid from transactions where cleared = 0 and accountid = %i and payee like '%q';", &results, &rows, &columns, NULL, id, limit ); + return results; + } + +void Transaction::displayTransactions ( QListView *listview, int id, bool children, const char *limit, QDate displaydate ) + { + int showcleared = preferences->getPreference ( 3 ); + + char **results; + if ( showcleared == 0 ) + results = selectNonClearedTransactions ( displaydate, children, limit, id ); + else + results = selectAllTransactions ( displaydate, children, limit, id ); + + // iterate through the result list and display each item + int counter = 7; + while ( counter < ( ( rows + 1 ) * columns ) ) + { + //QDate testdate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); + QString date = preferences->getDate ( atoi ( results [ counter + 2 ] ), atoi ( results [ counter + 1 ] ), atoi ( results [ counter ] ) ); + + // construct transaction name, amount, id + QString payee = results [ counter + 3 ]; + QString amount = results [ counter + 4 ]; + QString transferid = results [ counter + 5 ]; + + //determine the account name of the child accounts that we're displaying + QString accountname = account->getAccountName ( atoi ( results [ counter + 6 ] ) ); + + // fill in values + if ( account->getParentAccountID ( id ) != -1 ) // use these constructors if we're showing a child account + { + if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) + ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid ); + else + QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid ); + } + else + { + if ( showcleared == 1 && getCleared ( transferid.toInt() ) == 1 ) + ColorListItem *item = new ColorListItem ( listview, date, payee, amount, transferid, accountname ); + else + QListViewItem *item = new QListViewItem ( listview, date, payee, amount, transferid, accountname ); + } + + // advance counter + counter = counter + 7; + } + } + +QString Transaction::getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype ) + { + // determine if we are viewing a years, months, or days budget + // we have to pick a different sum for each + char **results; + switch ( viewtype ) + { + case 1: // we are viewing a year + sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and amount < 0 and budgetid = %i and reservedone = %i;", &results, NULL, NULL, NULL, year, budgetid, lineitemid ); + break; + + case 0: // we are viewing a month + sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and month = %i and amount < 0 and budgetid = %i and reservedone = %i;", &results, NULL, NULL, NULL, year, month, budgetid, lineitemid ); + break; + } + QString amount = results [ 1 ]; + float total = amount.toFloat(); + amount.setNum ( total, 'f', 2 ); + return amount; + } + +QString Transaction::getActualTotal ( int budgetid, int year, int month, int viewtype ) + { + // determine if we are viewing a years, months, or days budget + // we have to pick a different sum for each + char **results; + switch ( viewtype ) + { + case 1: // we are viewing a year + sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and amount < 0 and budgetid = %i;", &results, NULL, NULL, NULL, year, budgetid ); + break; + + case 0: // we are viewing a month + sqlite_get_table_printf ( tdb, "select abs ( sum ( amount ) ) from transactions where year = %i and month = %i and amount < 0 and budgetid = %i;", &results, NULL, NULL, NULL, year, month, budgetid ); + break; + } + QString amount = results [ 1 ]; + float total = amount.toFloat(); + amount.setNum ( total, 'f', 2 ); + return amount; + } + +void Transaction::clearBudgetIDs ( int budgetid, int lineitemid ) + { + sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i and reservedone = %i;", 0, 0, 0, budgetid, lineitemid ); + } + +void Transaction::clearBudgetIDs ( int budgetid ) + { + sqlite_exec_printf ( tdb, "update transactions set budgetid = -1 where budgetid = %i;", 0, 0, 0, budgetid ); + } + diff --git a/noncore/unsupported/qashmoney/transaction.h b/noncore/unsupported/qashmoney/transaction.h new file mode 100755 index 0000000..3df43a8 --- a/dev/null +++ b/noncore/unsupported/qashmoney/transaction.h @@ -0,0 +1,73 @@ +#ifndef TRANSACTION_H +#define TRANSACTION_H + +#include +#include +#include +#include + +#include "preferences.h" + +class Transaction + { + public: + + Transaction (); + ~Transaction (); + + // This function adds a new transaction to the database. It takes the payee, accountid, + // budgetid, number, day, month, year, amount, cleared + void addTransaction ( QString description, QString payee, int accountid, int parentid, int number, int day, int month, int year, float amount, int cleared, int budgetid, int lineitemid ); + + // This updates an already existing transaction + void updateTransaction ( QString, QString, int, int, int, int, float, int, int, int, int ); + + // Deletes a transaction. Takes the transid as its parameter + void deleteTransaction ( int ); + + // Returns the number of transactions + int getNumberOfTransactions (); + + // this is an overloaded function that returns the number of + // transactions for an account + int getNumberOfTransactions ( int ); + + // deletes all transactions for the provided accountid + void deleteAllTransactions ( int accountid ); + + QString getBudgetTotal ( int budgetid, int lineitemid, int year, int month, int viewtype ); + QString getActualTotal ( int budgetid, int year, int month, int viewtype ); + + // These two functions clear budget ids is either a line item or an entire budget is deleted + void clearBudgetIDs ( int, int ); + void clearBudgetIDs ( int ); + + public slots: + + void displayTransactions ( QListView *, int, bool, const char *, QDate ); + char ** selectAllTransactions ( QDate fromdate, bool children, const char *limit, int id ); + char ** selectNonClearedTransactions ( QDate fromdate, bool children, const char *limit, int id ); + QString getPayee ( int ); + QString getTransactionDescription ( int ); + QString getNumber ( int ); + QString getAmount ( int ); + QString getAbsoluteAmount ( int ); + int getCleared ( int ); + void setCleared ( int id, int cleared ); + int getBudgetID ( int id ); + int getLineItemID ( int id ); + int getDay ( int ); + int getMonth ( int ); + int getYear ( int ); + int getAccountID ( int id ); + + private: + + sqlite3 *tdb; + int rows, columns; + }; + +#endif + + + diff --git a/noncore/unsupported/qashmoney/transactiondisplay.cpp b/noncore/unsupported/qashmoney/transactiondisplay.cpp new file mode 100755 index 0000000..0b94d62 --- a/dev/null +++ b/noncore/unsupported/qashmoney/transactiondisplay.cpp @@ -0,0 +1,625 @@ +#include "transactiondisplay.h" +#include "newtransaction.h" +#include "account.h" +#include "budget.h" +#include "memory.h" +#include "transfer.h" +#include "calculator.h" +#include "datepicker.h" + +#include +#include +#include + +extern Transaction *transaction; +extern Budget *budget; +extern Account *account; +extern Preferences *preferences; +extern Memory *memory; +extern Transfer *transfer; + +TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent ) + { + // set transactiondisplay variables; + accountid = 0; + children = TRUE; + + firstline = new QHBox ( this ); + firstline->setSpacing ( 2 ); + + newtransaction = new QPushButton ( firstline ); + newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); + connect ( newtransaction, SIGNAL ( released() ), this, SLOT ( addTransaction() ) ); + + edittransaction = new QPushButton ( firstline ); + edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); + connect ( edittransaction, SIGNAL ( released() ), this, SLOT ( checkListViewEdit() ) ); + + deletetransaction = new QPushButton ( firstline ); + deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); + connect ( deletetransaction, SIGNAL ( released() ), this, SLOT ( checkListViewDelete() ) ); + + toggletransaction = new QPushButton ( firstline ); + toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") ); + connect ( toggletransaction, SIGNAL ( released() ), this, SLOT ( checkListViewToggle() ) ); + + viewtransactionnotes = new QPushButton ( firstline ); + viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") ); + connect ( viewtransactionnotes, SIGNAL ( released() ), this, SLOT ( showTransactionNotes() ) ); + + secondline = new QHBox ( this ); + secondline->setSpacing ( 5 ); + + name = new QLabel ( secondline ); + balance = new QLabel ( secondline ); + + QLabel *limit = new QLabel ( "Limit", secondline ); + limitbox = new QLineEdit ( secondline ); + limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) ); + connect ( limitbox, SIGNAL ( textChanged(const QString&) ), this, SLOT ( limitDisplay(const QString&) ) ); + + listview = new QListView ( this ); + listview->setAllColumnsShowFocus ( TRUE ); + listview->setShowSortIndicator ( TRUE ); + listview->header()->setTracking ( FALSE ); + connect ( listview->header(), SIGNAL ( sizeChange(int,int,int) ), this, SLOT ( saveColumnSize(int,int,int) ) ); + connect ( listview->header(), SIGNAL ( clicked(int) ), this, SLOT ( saveSortingPreference(int) ) ); + + layout = new QVBoxLayout ( this, 2, 2 ); + layout->addWidget ( firstline ); + layout->addWidget ( secondline ); + layout->addWidget ( listview ); + } + +void TransactionDisplay::addTransaction () + { + // create local variables + int cleared = -1; + + // create new transaction window + NewTransaction *newtransaction = new NewTransaction ( this ); + int width = this->size().width(); + newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); + newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); + newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); + newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); + newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); + newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); + + // enter today's date in the date box as defaul + QDate today = QDate::currentDate (); + int defaultday = today.day(); + int defaultmonth = today.month(); + int defaultyear = today.year(); + newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); + + // add memory items to the transactionname combobox + memory->displayMemoryItems ( newtransaction->transactionname ); + newtransaction->transactionname->insertItem ( "", 0 ); + + if ( newtransaction->exec () == QDialog::Accepted ) + { + if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction + cleared = 1; + else + cleared = 0; + + float amount = newtransaction->transactionamount->text().toFloat(); + if ( newtransaction->depositbox->isChecked() == FALSE ) + amount = amount * -1; + + // add the transaction name to the memory items + memory->addMemoryItem ( newtransaction->transactionname->currentText() ); + + // add the transaction + if ( newtransaction->getDateEdited () == TRUE ) + transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), + newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), + newtransaction->getCurrentLineItem() ); + else + transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), + newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); + + // redisplay transactions + listview->clear(); + QString displaytext = "%"; + displaytext.prepend ( limitbox->text() ); + setTransactionDisplayDate (); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); + + // redisplay transfers + if ( transfer->getNumberOfTransfers() > 0 ) + transfer->displayTransfers ( listview, accountid, children, displaydate ); + + // add the transaction amount to the account it's associated with + // and update its parent account balance if necessary + account->updateAccountBalance ( accountid ); + if ( account->getParentAccountID ( accountid ) != -1 ) + account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); + + // format then reset the account balance + redisplayAccountBalance (); + } + } + +void TransactionDisplay::checkListViewEdit () + { + if ( listview->selectedItem() == 0 ) + QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit."); + else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) + editTransfer (); + else + editTransaction(); + } + +void TransactionDisplay::showCalculator () + { + Calculator *calculator = new Calculator ( this ); + if ( calculator->exec () == QDialog::Accepted ) + amount->setText ( calculator->display->text() ); + } + +void TransactionDisplay::showCalendar () + { + QDate newDate = QDate::currentDate (); + DatePicker *dp = new DatePicker ( newDate ); + if ( dp->exec () == QDialog::Accepted ) + { + year = dp->getYear(); + month = dp->getMonth(); + day = dp->getDay(); + date->setText ( preferences->getDate ( year, month, day ) ); + } + } + +void TransactionDisplay::editTransfer () + { + transferid = listview->currentItem()->text ( getIDColumn() ).toInt(); + fromaccount = transfer->getFromAccountID ( transferid ); + toaccount = transfer->getToAccountID ( transferid ); + year = transfer->getYear ( transferid ); + month = transfer->getMonth ( transferid ); + day = transfer->getDay ( transferid ); + + QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE ); + editransfer->setCaption ( "Transfer" ); + + QStringList accountnames = account->getAccountNames(); + QStringList accountids = account->getAccountIDs(); + + QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer ); + QFont f = this->font(); + f.setWeight ( QFont::Bold ); + fromaccountlabel->setFont ( f ); + + QComboBox *fromaccountbox = new QComboBox ( editransfer ); + fromaccountbox->insertStringList ( accountnames ); + fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) ); + + QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer ); + toaccountlabel->setFont ( f ); + + QComboBox *toaccountbox = new QComboBox ( editransfer ); + toaccountbox->insertStringList ( accountnames ); + toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) ); + + QLabel *datelabel = new QLabel ( "Date", editransfer ); + QHBox *datebox = new QHBox ( editransfer ); + datebox->setSpacing ( 2 ); + date = new QLineEdit ( datebox ); + date->setAlignment ( Qt::AlignRight ); + date->setDisabled ( TRUE ); + date->setText ( preferences->getDate ( year, month, day ) ); + QPushButton *datebutton = new QPushButton ( datebox ); + datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); + connect ( datebutton, SIGNAL ( released() ), this, SLOT ( showCalendar() ) ); + + QLabel *amounttlabel = new QLabel ( "Amount", editransfer ); + + QHBox *amountbox = new QHBox ( editransfer ); + amountbox->setSpacing ( 2 ); + amount = new QLineEdit ( amountbox ); + amount->setAlignment ( Qt::AlignRight ); + amount->setText ( transfer->getAmount ( transferid ) ); + QPushButton *calculatorbutton = new QPushButton( amountbox ); + calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); + connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); + + QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer ); + + QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 ); + layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); + layout->addWidget ( fromaccountbox, Qt::AlignLeft ); + layout->addWidget ( toaccountlabel, Qt::AlignLeft ); + layout->addWidget ( toaccountbox, Qt::AlignLeft ); + layout->addSpacing ( 5 ); + layout->addWidget ( datelabel, Qt::AlignLeft ); + layout->addWidget ( datebox, Qt::AlignLeft ); + layout->addWidget ( amounttlabel, Qt::AlignLeft ); + layout->addWidget ( amountbox, Qt::AlignLeft ); + layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); + + if ( editransfer->exec() == QDialog::Accepted ) + { + //get fromaccount + fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt(); + + //get to account + toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt(); + + //set cleared flag + int cleared = 0; + if ( clearedcheckbox->isChecked() == TRUE ) + cleared = 1; + + //update transfer + transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ), + day, month, year, amount->text().toFloat(), cleared, transferid ); + + account->updateAccountBalance ( fromaccount ); + if ( account->getParentAccountID ( fromaccount ) != -1 ) + account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) ); + + updateAndDisplay ( toaccount ); + } + } + +void TransactionDisplay::editTransaction () + { + int cleared; + + // set the transaction id and budgetid + int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); + int budgetid = transaction->getBudgetID ( transactionid ); + int lineitemid = transaction->getLineItemID ( transactionid ); + + // create edit transaction window + NewTransaction *newtransaction = new NewTransaction ( this ); + int width = this->width(); + newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); + newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); + newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); + newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); + newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); + newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); + + // enter the date in the date box + newtransaction->year = transaction->getYear ( transactionid ); + newtransaction->month = transaction->getMonth ( transactionid ); + newtransaction->day = transaction->getDay ( transactionid ); + newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) ); + + // set the description + newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) ); + + // add memory items to the transactionname combobox + memory->displayMemoryItems ( newtransaction->transactionname ); + + // add correct transaction name + newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) ); + + // add transaction number + newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) ); + + // add transaction amount + newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) ); + + // check for and set the correct budget + if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item + { + newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 ); + if ( lineitemid >= 1 ) + { + newtransaction->setLineItems (); + newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) ); + } + else + { + newtransaction->lineitemlabel->setEnabled ( FALSE ); + newtransaction->lineitembox->setEnabled ( FALSE ); + } + } + else + { + newtransaction->lineitemlabel->setEnabled ( FALSE ); + newtransaction->lineitembox->setEnabled ( FALSE ); + } + + // check cleared checkbox if necessary + if ( transaction->getCleared ( transactionid ) == 1 ) + newtransaction->clearedcheckbox->setChecked ( TRUE ); + + // check deposit box if necessary + if ( transaction->getAmount ( transactionid ).toFloat() > 0 ) + newtransaction->depositbox->setChecked ( TRUE ); + + if ( newtransaction->exec () == QDialog::Accepted ) + { + if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) + cleared = 1; + else + cleared = 0; + + float amount = newtransaction->transactionamount->text().toFloat(); + if ( newtransaction->depositbox->isChecked() == FALSE ) + amount = amount * -1; + + // add the transaction name to the memory items + memory->addMemoryItem ( newtransaction->transactionname->currentText() ); + + // update the transaction + transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(), + newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), + amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid ); + + updateAndDisplay ( transaction->getAccountID ( transactionid ) ); + } + } + +void TransactionDisplay::updateAndDisplay ( int id ) + { + // redisplay transactions + listview->clear(); + QString displaytext = "%"; + displaytext.prepend ( limitbox->text() ); + setTransactionDisplayDate (); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); + + // redisplay transfers + if ( transfer->getNumberOfTransfers() > 0 ) + transfer->displayTransfers ( listview, accountid, children, displaydate ); + + // add the transaction amount to the account it's associated with + // and update its parent account balance if necessary + account->updateAccountBalance ( id ); + if ( account->getParentAccountID ( id ) != -1 ) + account->changeParentAccountBalance ( account->getParentAccountID ( id ) ); + + // format then reset the account balance + redisplayAccountBalance (); + } + +void TransactionDisplay::checkListViewDelete () + { + if ( listview->selectedItem() == 0 ) + QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete."); + else + deleteTransaction (); + } + +void TransactionDisplay::deleteTransaction () + { + int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); + + if ( transactionid > 0 ) // takes care of deleting transactions + { + // check if we are viewing child transactions through a parent + // in that case we will have to update balances for the parent + // which is represented by accountid and the child account + // which will be represented by childaccountid + int childaccountid = -1; + if ( listview->columns() == 5 ) + childaccountid = transaction->getAccountID ( transactionid ); + + transaction->deleteTransaction ( transactionid ); + + listview->clear(); + QString displaytext = "%"; + displaytext.prepend ( limitbox->text() ); + setTransactionDisplayDate (); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); + + if ( transfer->getNumberOfTransfers() > 0 ) + transfer->displayTransfers ( listview, accountid, children, displaydate ); + + // if we are viewing different child accounts through the parent account + // ie if there are five columns and the parentid is -1 + // update the accountid ( which is the parent ) and update the child account + // balance. Get its accountid from the transactionid + account->updateAccountBalance ( accountid ); // will update either a parent or child + if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one + account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); + if ( childaccountid != -1 ) // we've set childaccountid + account->updateAccountBalance ( childaccountid ); + + // format then reset the account balance + redisplayAccountBalance (); + } + else // takes care of deleting transfers + { + // get the accountids before we delete the transfer + int fromaccountid = transfer->getFromAccountID ( transactionid ); + int toaccountid = transfer->getToAccountID ( transactionid ); + + // delete the transfer and redisplay transactions + transfer->deleteTransfer ( transactionid ); + + listview->clear(); + QString displaytext = "%"; + displaytext.prepend ( limitbox->text() ); + setTransactionDisplayDate (); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); + + if ( transfer->getNumberOfTransfers() > 0 ) + transfer->displayTransfers ( listview, accountid, children, displaydate ); + + // for the from account + account->updateAccountBalance ( fromaccountid ); + if ( account->getParentAccountID ( fromaccountid ) != -1 ) + account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) ); + + // for the to account + account->updateAccountBalance ( toaccountid ); + if ( account->getParentAccountID ( toaccountid ) != -1 ) + account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) ); + + // format then reset the account balance + redisplayAccountBalance (); + } + } + +void TransactionDisplay::checkListViewToggle () + { + if ( listview->selectedItem() == 0 ) + QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset."); + else + toggleTransaction (); + } + +void TransactionDisplay::toggleTransaction () + { + //get the transaction of the selected transaction to determine if its a transaction or transfer + int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); + + if ( transactionid > 0 ) // if this is a transaction + { + if ( transaction->getCleared ( transactionid ) == 0 ) + transaction->setCleared ( transactionid, 1 ); + else + transaction->setCleared ( transactionid, 0 ); + } + else + { + if ( transfer->getCleared ( transactionid ) == 0 ) + transfer->setCleared ( transactionid, 1 ); + else + transfer->setCleared ( transactionid, 0 ); + } + + listview->clear(); + QString displaytext = "%"; + displaytext.prepend ( limitbox->text() ); + setTransactionDisplayDate (); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); + + if ( transfer->getNumberOfTransfers() != 0 ) + transfer->displayTransfers ( listview, accountid, children, displaydate ); + } + +void TransactionDisplay::redisplayAccountBalance () + { + QString accountbalance = account->getAccountBalance ( accountid ); + balance->setText ( accountbalance ); + } + +void TransactionDisplay::setChildren ( bool c ) + { + children = c; + } + +void TransactionDisplay::setAccountID ( int id ) + { + accountid = id; + } + +ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent ) + { + } + +ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) + : QListViewItem ( parent, label1, label2, label3, label4 ) + { + } + +ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) + : QListViewItem ( parent, label1, label2, label3, label4, label5 ) + { + } + +void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) + { + QColorGroup _cg ( cg ); + _cg.setColor ( QColorGroup::Text, Qt::red ); + QListViewItem::paintCell ( p, _cg, column, width, alignment ); + } + +void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize ) + { + if ( listview->columns() == 4 ) + preferences->changeColumnPreference ( column + 3, newsize ); + else if ( listview->columns() == 5 && column != 4 ) + preferences->changeColumnPreference ( column + 6, newsize ); + else + preferences->changeColumnPreference ( 9, newsize ); + } + +void TransactionDisplay::saveSortingPreference ( int column ) + { + preferences->changeSortingPreference ( 2, column ); + } + +void TransactionDisplay::limitDisplay ( const QString &text ) + { + listview->clear (); + QString displaytext = "%"; + displaytext.prepend ( text ); + setTransactionDisplayDate (); + if ( transaction->getNumberOfTransactions() > 0 ) + transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); + + if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 ) + transfer->displayTransfers ( listview, accountid, children, displaydate ); + } + +int TransactionDisplay::getIDColumn () + { + int counter; + int columns = listview->columns(); + for ( counter = 0; counter <= columns; counter++ ) + if ( listview->header()->label ( counter ).length() == 0 ) + return counter; + } + +void TransactionDisplay::showTransactionNotes () + { + if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) + QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes."); + else + { + int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt (); + QDialog *description = new QDialog ( this, "description", TRUE ); + description->setCaption ( "Notes" ); + QMultiLineEdit *notes = new QMultiLineEdit ( description ); + notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); + notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); + notes->setWordWrap ( QMultiLineEdit::WidgetWidth ); + notes->setEnabled ( FALSE ); + notes->setText ( transaction->getTransactionDescription ( transactionid ) ); + description->show(); + } + } + +void TransactionDisplay::setTransactionDisplayDate () + { + // determine how many days of transactions to show + int limittype = preferences->getPreference ( 7 ); + if ( limittype != 5 ) // set today's date if we are not showing all transactions + { + QDate today = QDate::currentDate (); + switch ( limittype ) // if we are not showing all transactions + { + case 0: // viewing two weeks + displaydate = today.addDays ( -14 ); + break; + case 1: // viewing one month + displaydate = today.addDays ( -30 ); + break; + case 2: // three months + displaydate = today.addDays ( -90 ); + break; + case 3: // six months + displaydate = today.addDays ( -180 ); + break; + case 4: // one year + displaydate = today.addDays ( -365 ); + break; + } + } + else + displaydate = QDate ( 1900, 1, 1 ); + } diff --git a/noncore/unsupported/qashmoney/transactiondisplay.h b/noncore/unsupported/qashmoney/transactiondisplay.h new file mode 100755 index 0000000..594776a --- a/dev/null +++ b/noncore/unsupported/qashmoney/transactiondisplay.h @@ -0,0 +1,83 @@ +#ifndef TRANSACTIONDISPLAY_H +#define TRANSACTIONDISPLAY_H + +#include +#include +#include +#include +#include +#include +#include + +class TransactionDisplay : public QWidget + { + Q_OBJECT + + public: + TransactionDisplay ( QWidget* parent ); + + QListView* listview; + QPushButton* newtransaction; + QPushButton* edittransaction; + QPushButton* deletetransaction; + QPushButton* toggletransaction; + QPushButton* viewtransactionnotes; + + QLabel *name; + QLabel *balance; + QLineEdit *limitbox; + QLineEdit *amount; + QLineEdit *date; + + int getIDColumn (); + + public slots: + void setChildren ( bool ); + void setAccountID ( int ); + void showTransactionNotes (); + + private slots: + void addTransaction (); + void editTransaction (); + void editTransfer (); + void deleteTransaction (); + void toggleTransaction (); + void checkListViewDelete (); + void checkListViewEdit (); + void checkListViewToggle (); + void saveColumnSize ( int column, int oldsize, int newsize ); + void limitDisplay ( const QString & ); + void showCalculator (); + void showCalendar (); + void setTransactionDisplayDate (); + void saveSortingPreference ( int column ); + + private: + int accountid, fromaccount, fromparent, toaccount, toparent, day, month, year, transferid; + QDate displaydate; + bool children; + QBoxLayout *layout; + QHBox *firstline; + QHBox *secondline; + void redisplayAccountBalance (); + void updateAndDisplay ( int accountid ); + }; + +#endif + +#ifndef COLORLISTITEM_H +#define COLORLISTITEM_H + +class ColorListItem : public QListViewItem + { + public: + + ColorListItem ( QListView *parent ); + ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ); + ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ); + + virtual void paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); + }; + +#endif + diff --git a/noncore/unsupported/qashmoney/transfer.cpp b/noncore/unsupported/qashmoney/transfer.cpp new file mode 100755 index 0000000..ae1b748 --- a/dev/null +++ b/noncore/unsupported/qashmoney/transfer.cpp @@ -0,0 +1,259 @@ +#include "transfer.h" +#include "account.h" +#include "transactiondisplay.h" +#include + +extern Account *account; +extern Preferences *preferences; + +Transfer::Transfer () + { + db = sqlite_open ( "qmtransfers.db", 0, 0 ); + } + +Transfer::~Transfer () + { + sqlite_close ( db ); + } + +void Transfer::addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared ) + { + int nextrowid = -1; + char **results; + sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 ); + if ( atoi ( results [ 1 ] ) != 0 ) + { + char **results; + sqlite_get_table ( db, "select min ( rowid ) from transfers;", &results, 0, 0, 0 ); + nextrowid = ( atoi ( results [ 1 ] ) ) - 1; + } + sqlite_exec_printf ( db, "insert into transfers values ( %i, %i, %i, %i, %i, %i, %i, 0, 0, %.2f, %i, 0, 0, 0, 0, 0, %i );", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, nextrowid ); + } + +void Transfer::updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid ) + { + sqlite_exec_printf ( db, "update transfers set fromaccount = %i, fromparent = %i, toaccount = %i, toparent = %i, day = %i, month = %i, year = %i," + "amount = %.2f, cleared = %i where transferid = %i;", 0, 0, 0, fromaccount, fromparent, toaccount, toparent, day, month, year, amount, cleared, transferid ); + } + +void Transfer::deleteTransfer ( int transferid ) + { + sqlite_exec_printf ( db, "delete from transfers where transferid = %i;", 0, 0, 0, transferid ); + } + +void Transfer::deleteAllTransfers ( int accountid ) + { + sqlite_exec_printf ( db, "delete from transfers where fromaccount = %i;", 0, 0, 0, accountid ); + sqlite_exec_printf ( db, "delete from transfers where toaccount = %i;", 0, 0, 0, accountid ); + } + +int Transfer::getNumberOfTransfers () + { + char **results; + sqlite_get_table ( db, "select count() from transfers;", &results, 0, 0, 0 ); + return atoi ( results [ 1 ] ); + } + +int Transfer::getNumberOfTransfers ( int accountid ) + { + char **results; + sqlite_get_table_printf ( db, "select count() from transfers where fromaccount = %i;", &results, 0, 0, 0, accountid ); + int transfers = atoi ( results [ 1 ] ); + sqlite_get_table_printf ( db, "select count() from transfers where toaccount = %i;", &results, 0, 0, 0, accountid ); + transfers = transfers + atoi ( results [ 1 ] ); + return transfers; + } + +void Transfer::displayTransfers ( QListView *listview, int accountid, bool children, QDate displaydate ) + { + int showcleared = preferences->getPreference ( 3 ); + + // select the from transfers to display + char **results; + int rows, columns; + if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE ) + { + if ( showcleared == 0 ) + sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and toparent = %i;", &results, &rows, &columns, 0, accountid ); + else + sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toparent = %i;", &results, &rows, &columns, 0, accountid ); + } + else + { + if ( showcleared == 0 ) + sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and toaccount = %i;", &results, &rows, &columns, 0, accountid ); + else + sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where toaccount = %i;", &results, &rows, &columns, 0, accountid ); + } + + // iterate through the list and display the from items + int counter = 7; + int position = 0; + while ( counter < ( ( rows + 1 ) * columns ) ) + { + // construct the date + QString daystring = results [ counter ]; + int day = daystring.toInt (); + QString monthstring = results [ counter + 1 ]; + int month = monthstring.toInt (); + QString yearstring = results [ counter + 2 ]; + int year = yearstring.toInt (); + QString date = preferences->getDate ( year, month, day ); + QDate testdate ( year, month, day ); + + //construct the amount and id strings + QString amount = results [ counter + 3 ]; + QString id = results [ counter + 4 ]; + + // construct the transaction name + QString transactionname = "FROM: "; + QString temp1 = results [ counter + 5 ]; + transactionname.append ( account->getAccountName ( temp1.toInt() ) ); + + QString toaccount = account->getAccountName ( atol ( results [ counter + 6 ] ) ); + + if ( testdate >= displaydate || showcleared == 0 ) + { + // display this transfer + if ( account->getParentAccountID ( accountid ) == -1 ) + { + if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) + ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, toaccount ); + else + QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, toaccount ); + } + else + { + if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) + ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id ); + else + QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id ); + } + } + counter = counter + 7; + } + + // select the to transfers to display + char **toresults; + rows = 0; + columns = 0; + if ( account->getParentAccountID ( accountid ) == -1 && children == TRUE ) + { + if ( showcleared == 0 ) + sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and fromparent = %i;", &toresults, &rows, &columns, 0, accountid ); + else + sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromparent = %i;", &toresults, &rows, &columns, 0, accountid ); + } + else + { + if ( showcleared == 0 ) + sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where cleared = 0 and fromaccount = %i;", &toresults, &rows, &columns, 0, accountid ); + else + sqlite_get_table_printf ( db, "select day, month, year, amount, transferid, fromaccount, toaccount from transfers where fromaccount = %i;", &toresults, &rows, &columns, 0, accountid ); + } + + // iterate through the list and display the from items + counter = 7; + position = 0; + while ( counter < ( ( rows + 1 ) * columns ) ) + { + // construct the date + QString daystring = toresults [ counter ]; + int day = daystring.toInt (); + QString monthstring = toresults [ counter + 1 ]; + int month = monthstring.toInt (); + QString yearstring = toresults [ counter + 2 ]; + int year = yearstring.toInt (); + QString date = preferences->getDate ( year, month, day ); + QDate testdate ( year, month, day ); + + //construct the amount and id strings + QString amount = toresults [ counter + 3 ]; + amount.prepend ( "-" ); + QString id = toresults [ counter + 4 ]; + + // construct the transaction name + QString transactionname = "TO: "; + QString temp1 = toresults [ counter + 6 ]; + transactionname.append ( account->getAccountName ( temp1.toInt() ) ); + + QString fromaccount = account->getAccountName ( atol ( toresults [ counter + 5 ] ) ); + + if ( testdate >= displaydate || showcleared == 0 ) + { + // display this transfer + if ( account->getParentAccountID ( accountid ) == -1 ) + { + if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) + ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id, fromaccount ); + else + QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id, fromaccount ); + } + else + { + if ( showcleared == 1 && getCleared ( id.toInt() ) == 1 ) + ColorListItem *item = new ColorListItem ( listview, date, transactionname, amount, id ); + else + QListViewItem *item = new QListViewItem ( listview, date, transactionname, amount, id ); + } + } + + counter = counter + 7; + } + } + +int Transfer::getCleared ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select cleared from transfers where transferid= %i;", &results, 0, 0, 0, id ); + return atoi ( results [ 1 ] ); + } + +void Transfer::setCleared ( int id, int cleared ) + { + sqlite_exec_printf ( db, "update transfers set cleared = %i where transferid = %i;", 0, 0, 0, cleared, id ); + } + +int Transfer::getFromAccountID ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select fromaccount from transfers where transferid= %i;", &results, 0, 0, 0, id ); + return atoi ( results [ 1 ] ); + } + +int Transfer::getToAccountID ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select toaccount from transfers where transferid= %i;", &results, 0, 0, 0, id ); + return atoi ( results [ 1 ] ); + } + +int Transfer::getDay ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select day from transfers where transferid= %i;", &results, 0, 0, 0, id ); + return atoi ( results [ 1 ] ); + } + +int Transfer::getMonth ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select month from transfers where transferid= %i;", &results, 0, 0, 0, id ); + return atoi ( results [ 1 ] ); + } + +int Transfer::getYear ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select year from transfers where transferid= %i;", &results, 0, 0, 0, id ); + return atoi ( results [ 1 ] ); + } + +QString Transfer::getAmount ( int id ) + { + char **results; + sqlite_get_table_printf ( db, "select amount from transfers where transferid= %i;", &results, 0, 0, 0, id ); + return results [ 1 ]; + } + + diff --git a/noncore/unsupported/qashmoney/transfer.h b/noncore/unsupported/qashmoney/transfer.h new file mode 100755 index 0000000..cec3386 --- a/dev/null +++ b/noncore/unsupported/qashmoney/transfer.h @@ -0,0 +1,52 @@ +#ifndef TRANSFER_H +#define TRANSFER_H + +#include +#include +#include +#include + +#include "preferences.h" + +class Transfer + { + public: + + Transfer (); + ~Transfer (); + + // This function adds a new transfer to the database. It takes the fromaccount, toaccount, + // number, frombudget, tobudget, day, month, year, amount, cleared + void addTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared ); + void updateTransfer ( int fromaccount, int fromparent, int toaccount, int toparent, int day, int month, int year, float amount, int cleared, int transferid ); + + // Deletes a transfer. Takes the transferid as its parameter + void deleteTransfer ( int ); + + // Deletes all transfers for a given accountid + void deleteAllTransfers ( int accountid ); + + // Returns the number of checking transfers + int getNumberOfTransfers (); + int getNumberOfTransfers ( int accountid ); + + void displayTransfers ( QListView *listview, int accountid, bool children, QDate displaydate ); + int getCleared ( int id ); + void setCleared ( int id, int cleared ); + int getFromAccountID ( int id ); + int getToAccountID ( int id ); + + int getDay ( int id ); + int getMonth ( int id ); + int getYear ( int id ); + QString getAmount ( int id ); + + private: + + sqlite3 *db; + }; + +#endif + + + diff --git a/noncore/unsupported/qashmoney/transferdialog.cpp b/noncore/unsupported/qashmoney/transferdialog.cpp new file mode 100755 index 0000000..7a12fbf --- a/dev/null +++ b/noncore/unsupported/qashmoney/transferdialog.cpp @@ -0,0 +1,112 @@ +#include "transferdialog.h" +#include "datepicker.h" +#include "calculator.h" + + +extern Preferences *preferences; +extern Account *account; + +TransferDialog::TransferDialog ( QWidget *parent, int fromaccountid, int toaccountid ) : QDialog ( parent, 0, TRUE ) + { + dateedited = FALSE; + setCaption ( "Transfer" ); + + fromaccountlabel = new QLabel ( "From account:", this ); + QFont f = this->font(); + f.setWeight ( QFont::Bold ); + fromaccountlabel->setFont ( f ); + fromaccount = new QLabel ( account->getAccountName ( fromaccountid ), this ); + + toaccountlabel = new QLabel ( "To Account:", this ); + toaccountlabel->setFont ( f ); + toaccount = new QLabel ( account->getAccountName ( toaccountid ), this ); + + datelabel = new QLabel ( "Date", this ); + + datebox = new QHBox ( this ); + datebox->setSpacing ( 2 ); + date = new QLineEdit ( datebox ); + date->setAlignment ( Qt::AlignRight ); + date->setDisabled ( TRUE ); + datebutton = new QPushButton ( datebox ); + datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); + connect ( datebutton, SIGNAL ( released() ), this, SLOT ( showCalendar() ) ); + + amounttlabel = new QLabel ( "Amount", this ); + + amountbox = new QHBox ( this ); + amountbox->setSpacing ( 2 ); + amount = new QLineEdit ( amountbox ); + amount->setAlignment ( Qt::AlignRight ); + calculatorbutton = new QPushButton( amountbox ); + calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); + connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); + + clearedcheckbox = new QCheckBox ( "Cleared", this ); + + layout = new QVBoxLayout ( this, 4, 2 ); + layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); + layout->addWidget ( fromaccount, Qt::AlignLeft ); + layout->addWidget ( toaccountlabel, Qt::AlignLeft ); + layout->addWidget ( toaccount, Qt::AlignLeft ); + layout->addSpacing ( 5 ); + layout->addWidget ( datelabel, Qt::AlignLeft ); + layout->addWidget ( datebox, Qt::AlignLeft ); + layout->addWidget ( amounttlabel, Qt::AlignLeft ); + layout->addWidget ( amountbox, Qt::AlignLeft ); + layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); + } + +bool TransferDialog::getDateEdited () + { + return dateedited; + } + +void TransferDialog::showCalendar () + { + QDate newDate = QDate::currentDate (); + DatePicker *dp = new DatePicker ( newDate ); + if ( dp->exec () == QDialog::Accepted ) + { + // Set date integers + year = dp->getYear(); + month = dp->getMonth(); + day = dp->getDay(); + + // Set dateedited to TRUE + // This tells the accountdisplay object that the user edited an account + // and did change the date + dateedited = TRUE; + + // Display date with our selected format + date->setText ( preferences->getDate ( year, month, day ) ); + } + } + +int TransferDialog::getDay () + { + return day; + } + +int TransferDialog::getMonth () + { + return month; + } + +int TransferDialog::getYear () + { + return year; + } + +void TransferDialog::showCalculator () + { + Calculator *calculator = new Calculator ( this ); + if ( calculator->exec () == QDialog::Accepted ) + amount->setText ( calculator->display->text() ); + } + + + + + + diff --git a/noncore/unsupported/qashmoney/transferdialog.h b/noncore/unsupported/qashmoney/transferdialog.h new file mode 100755 index 0000000..dd55879 --- a/dev/null +++ b/noncore/unsupported/qashmoney/transferdialog.h @@ -0,0 +1,62 @@ +#ifndef TRANSFERDIALOG_H +#define TRANSFERDIALOG_H + +#include +#include +#include +#include +#include +#include +#include + +#include "preferences.h" +#include "account.h" + +class TransferDialog : public QDialog +{ + Q_OBJECT + +public: + TransferDialog ( QWidget *parent, int fromaccountid, int toaccountid ); + + QLabel *fromaccountlabel; + QLabel *fromaccount; + + QLabel *toaccountlabel; + QLabel *toaccount; + + QLabel *datelabel; + + QHBox *datebox; + QLineEdit *date; + QPushButton *datebutton; + + QLabel *amounttlabel; + + QHBox *amountbox; + QLineEdit *amount; + QPushButton *calculatorbutton; + + QCheckBox *clearedcheckbox; + + QBoxLayout *layout; + + bool getDateEdited (); + +public slots: + + void showCalendar (); + void showCalculator (); + int getDay (); + int getMonth (); + int getYear (); + +private: + + int fromaccountid; + int toaccountid; + int year, month, day; + bool dateedited; +}; + +#endif -- cgit v0.9.0.2