summaryrefslogtreecommitdiff
path: root/noncore/apps/qashmoney/preferences.cpp
Unidiff
Diffstat (limited to 'noncore/apps/qashmoney/preferences.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-xnoncore/apps/qashmoney/preferences.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/qashmoney/preferences.cpp b/noncore/apps/qashmoney/preferences.cpp
index 819d5cf..9bf64dd 100755
--- a/noncore/apps/qashmoney/preferences.cpp
+++ b/noncore/apps/qashmoney/preferences.cpp
@@ -1,255 +1,255 @@
1#include "preferences.h" 1#include "preferences.h"
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4Preferences::Preferences () 4Preferences::Preferences ()
5 { 5 {
6 db = sqlite_open ( "qmpreferences.db", 0, NULL ); 6 db = sqlite_open ( "qmpreferences.db", 0, NULL );
7 } 7 }
8 8
9Preferences::~Preferences () 9Preferences::~Preferences ()
10 { 10 {
11 sqlite_close ( db ); 11 sqlite_close ( db );
12 } 12 }
13 13
14void Preferences::addPreferences () 14void Preferences::addPreferences ()
15 { 15 {
16 // This function checks the preferences database for existing preferences and adds 16 // This function checks the preferences database for existing preferences and adds
17 // them if they are not there. First we set up variables. Preferences are always set 17 // them if they are not there. First we set up variables. Preferences are always set
18 // to non-zero numbers because when we check to see if a preference has been 18 // to non-zero numbers because when we check to see if a preference has been
19 // added to the database, the result is zero if it hasn't 19 // added to the database, the result is zero if it hasn't
20 int rows = 0; 20 int rows = 0;
21 int columns = 0; 21 int columns = 0;
22 char **results; 22 char **results;
23 23
24 sqlite_get_table ( db, "select count() from preferences;", &results, 0, 0, 0 ); 24 sqlite_get_table ( db, "select count() from preferences;", &results, 0, 0, 0 );
25 if ( atoi ( results [ 1 ] ) != 7 ) 25 if ( atoi ( results [ 1 ] ) != 7 )
26 { 26 {
27 // dateformat preference 1 = yyyymmdd 2 = yymmdd 3 = mmddyyyy 4 = mmddyy 27 // dateformat preference 1 = yyyymmdd 2 = yymmdd 3 = mmddyyyy 4 = mmddyy
28 // 5 = yyyyddmm 6 = yyddmm 7 = ddmmyyyy 8 = ddmmyy 28 // 5 = yyyyddmm 6 = yyddmm 7 = ddmmyyyy 8 = ddmmyy
29 sqlite_get_table ( db, "select preference from preferences where id = 1;", &results, &rows, &columns, 0 ); 29 sqlite_get_table ( db, "select preference from preferences where id = 1;", &results, &rows, &columns, 0 );
30 if ( rows == 0 ) 30 if ( rows == 0 )
31 sqlite_exec ( db, "insert into preferences values ( 4, 'dateformat', 0, 0, 0, NULL );", 0, 0, 0 ); 31 sqlite_exec ( db, "insert into preferences values ( 4, 'dateformat', 0, 0, 0, NULL );", 0, 0, 0 );
32 32
33 // dateseparator preference 1 = / ( forward slash ) 2 = - ( dash ) 3 = . ( period ) 33 // dateseparator preference 1 = / ( forward slash ) 2 = - ( dash ) 3 = . ( period )
34 rows = 0; 34 rows = 0;
35 sqlite_get_table ( db, "select preference from preferences where id = 2;", &results, &rows, &columns, 0 ); 35 sqlite_get_table ( db, "select preference from preferences where id = 2;", &results, &rows, &columns, 0 );
36 if ( rows == 0 ) 36 if ( rows == 0 )
37 sqlite_exec ( db, "insert into preferences values ( 1, 'dateseparator', 0, 0, 0, NULL );", 0, 0, 0 ); 37 sqlite_exec ( db, "insert into preferences values ( 1, 'dateseparator', 0, 0, 0, NULL );", 0, 0, 0 );
38 38
39 // showclearedtransactions preference 0 = no 1 = yes 39 // showclearedtransactions preference 0 = no 1 = yes
40 rows = 0; 40 rows = 0;
41 sqlite_get_table ( db, "select preference from preferences where id = 3;", &results, &rows, &columns, 0 ); 41 sqlite_get_table ( db, "select preference from preferences where id = 3;", &results, &rows, &columns, 0 );
42 if ( rows == 0 ) 42 if ( rows == 0 )
43 sqlite_exec ( db, "insert into preferences values ( 0, 'showclearedtransactions', 0, 0, 0, NULL );", 0, 0, 0 ); 43 sqlite_exec ( db, "insert into preferences values ( 0, 'showclearedtransactions', 0, 0, 0, NULL );", 0, 0, 0 );
44 44
45 // enable currency support preference 0 = no 1 = yes 45 // enable currency support preference 0 = no 1 = yes
46 rows = 0; 46 rows = 0;
47 sqlite_get_table ( db, "select preference from preferences where id = 4;", &results, &rows, &columns, 0 ); 47 sqlite_get_table ( db, "select preference from preferences where id = 4;", &results, &rows, &columns, 0 );
48 if ( rows == 0 ) 48 if ( rows == 0 )
49 sqlite_exec ( db, "insert into preferences values ( 0, 'enablecurrencysupport', 0, 0, 0, NULL );", 0, 0, 0 ); 49 sqlite_exec ( db, "insert into preferences values ( 0, 'enablecurrencysupport', 0, 0, 0, NULL );", 0, 0, 0 );
50 50
51 // one touch account viewing preference 0 = no 1 = yes 51 // one touch account viewing preference 0 = no 1 = yes
52 rows = 0; 52 rows = 0;
53 sqlite_get_table ( db, "select preference from preferences where id = 5;", &results, &rows, &columns, 0 ); 53 sqlite_get_table ( db, "select preference from preferences where id = 5;", &results, &rows, &columns, 0 );
54 if ( rows == 0 ) 54 if ( rows == 0 )
55 sqlite_exec ( db, "insert into preferences values ( 0, 'onetouchviewing', 0, 0, 0, NULL );", 0, 0, 0 ); 55 sqlite_exec ( db, "insert into preferences values ( 0, 'onetouchviewing', 0, 0, 0, NULL );", 0, 0, 0 );
56 56
57 // exclude transfers from limit view 0 = no 1 = yes 57 // exclude transfers from limit view 0 = no 1 = yes
58 rows = 0; 58 rows = 0;
59 sqlite_get_table ( db, "select preference from preferences where id = 6;", &results, &rows, &columns, 0 ); 59 sqlite_get_table ( db, "select preference from preferences where id = 6;", &results, &rows, &columns, 0 );
60 if ( rows == 0 ) 60 if ( rows == 0 )
61 sqlite_exec ( db, "insert into preferences values ( 0, 'excludetransfersfromlimit', 0, 0, 0, NULL );", 0, 0, 0 ); 61 sqlite_exec ( db, "insert into preferences values ( 0, 'excludetransfersfromlimit', 0, 0, 0, NULL );", 0, 0, 0 );
62 62
63 // limit number of transactions to 0 = 14 days 1 = 30 days, 2 = 60 days, 3 = 90 days, 4 = 180 days, 5 = 365 days, 6 = all 63 // limit number of transactions to 0 = 14 days 1 = 30 days, 2 = 90 days, 3 = 180 days, 4 = 365 days 5 = all
64 rows = 0; 64 rows = 0;
65 sqlite_get_table ( db, "select preference from preferences where id = 7;", &results, &rows, &columns, 0 ); 65 sqlite_get_table ( db, "select preference from preferences where id = 7;", &results, &rows, &columns, 0 );
66 if ( rows == 0 ) 66 if ( rows == 0 )
67 sqlite_exec ( db, "insert into preferences values ( 0, 'limittransactions', 0, 0, 0, NULL );", 0, 0, 0 ); 67 sqlite_exec ( db, "insert into preferences values ( 0, 'limittransactions', 0, 0, 0, NULL );", 0, 0, 0 );
68 } 68 }
69 } 69 }
70 70
71void Preferences::initializeColumnPreferences () 71void Preferences::initializeColumnPreferences ()
72 { 72 {
73 int rows = 0; 73 int rows = 0;
74 int columns = 0; 74 int columns = 0;
75 char **results; 75 char **results;
76 76
77 // initialize accountname column width 77 // initialize accountname column width
78 sqlite_get_table ( db, "select width from columns where id = 1;", &results, &rows, &columns, 0 ); 78 sqlite_get_table ( db, "select width from columns where id = 1;", &results, &rows, &columns, 0 );
79 if ( rows == 0 ) 79 if ( rows == 0 )
80 sqlite_exec ( db, "insert into columns values ( 'accountname', 90, 0, 0, 0, NULL );", 0, 0, 0 ); 80 sqlite_exec ( db, "insert into columns values ( 'accountname', 90, 0, 0, 0, NULL );", 0, 0, 0 );
81 81
82 // initialize accountbalance column width 82 // initialize accountbalance column width
83 sqlite_get_table ( db, "select width from columns where id = 2;", &results, &rows, &columns, 0 ); 83 sqlite_get_table ( db, "select width from columns where id = 2;", &results, &rows, &columns, 0 );
84 if ( rows == 0 ) 84 if ( rows == 0 )
85 sqlite_exec ( db, "insert into columns values ( 'accountbalance', 90, 0, 0, 0, NULL );", 0, 0, 0 ); 85 sqlite_exec ( db, "insert into columns values ( 'accountbalance', 90, 0, 0, 0, NULL );", 0, 0, 0 );
86 86
87 // initialize transactiondate column width 87 // initialize transactiondate column width
88 sqlite_get_table ( db, "select width from columns where id = 3;", &results, &rows, &columns, 0 ); 88 sqlite_get_table ( db, "select width from columns where id = 3;", &results, &rows, &columns, 0 );
89 if ( rows == 0 ) 89 if ( rows == 0 )
90 sqlite_exec ( db, "insert into columns values ( 'normaltransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 90 sqlite_exec ( db, "insert into columns values ( 'normaltransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 );
91 91
92 // initialize transactionname column width 92 // initialize transactionname column width
93 sqlite_get_table ( db, "select width from columns where id = 4;", &results, &rows, &columns, 0 ); 93 sqlite_get_table ( db, "select width from columns where id = 4;", &results, &rows, &columns, 0 );
94 if ( rows == 0 ) 94 if ( rows == 0 )
95 sqlite_exec ( db, "insert into columns values ( 'normaltransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 ); 95 sqlite_exec ( db, "insert into columns values ( 'normaltransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 );
96 96
97 // initialize transactionamount column width 97 // initialize transactionamount column width
98 sqlite_get_table ( db, "select width from columns where id = 5;", &results, &rows, &columns, 0 ); 98 sqlite_get_table ( db, "select width from columns where id = 5;", &results, &rows, &columns, 0 );
99 if ( rows == 0 ) 99 if ( rows == 0 )
100 sqlite_exec ( db, "insert into columns values ( 'normaltransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 100 sqlite_exec ( db, "insert into columns values ( 'normaltransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 );
101 101
102 // initialize transactiondate column width 102 // initialize transactiondate column width
103 sqlite_get_table ( db, "select width from columns where id = 6;", &results, &rows, &columns, 0 ); 103 sqlite_get_table ( db, "select width from columns where id = 6;", &results, &rows, &columns, 0 );
104 if ( rows == 0 ) 104 if ( rows == 0 )
105 sqlite_exec ( db, "insert into columns values ( 'extendedtransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 105 sqlite_exec ( db, "insert into columns values ( 'extendedtransactiondate', 50, 0, 0, 0, NULL );", 0, 0, 0 );
106 106
107 // initialize transactionname column width 107 // initialize transactionname column width
108 sqlite_get_table ( db, "select width from columns where id = 7;", &results, &rows, &columns, 0 ); 108 sqlite_get_table ( db, "select width from columns where id = 7;", &results, &rows, &columns, 0 );
109 if ( rows == 0 ) 109 if ( rows == 0 )
110 sqlite_exec ( db, "insert into columns values ( 'extendedtransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 ); 110 sqlite_exec ( db, "insert into columns values ( 'extendedtransactionname', 75, 0, 0, 0, NULL );", 0, 0, 0 );
111 111
112 // initialize transactionamount column width 112 // initialize transactionamount column width
113 sqlite_get_table ( db, "select width from columns where id = 8;", &results, &rows, &columns, 0 ); 113 sqlite_get_table ( db, "select width from columns where id = 8;", &results, &rows, &columns, 0 );
114 if ( rows == 0 ) 114 if ( rows == 0 )
115 sqlite_exec ( db, "insert into columns values ( 'extendedtransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 115 sqlite_exec ( db, "insert into columns values ( 'extendedtransactionamount', 50, 0, 0, 0, NULL );", 0, 0, 0 );
116 116
117 // initialize transactionaccount column width 117 // initialize transactionaccount column width
118 sqlite_get_table ( db, "select width from columns where id = 9;", &results, &rows, &columns, 0 ); 118 sqlite_get_table ( db, "select width from columns where id = 9;", &results, &rows, &columns, 0 );
119 if ( rows == 0 ) 119 if ( rows == 0 )
120 sqlite_exec ( db, "insert into columns values ( 'transactionaccount', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 120 sqlite_exec ( db, "insert into columns values ( 'transactionaccount', 50, 0, 0, 0, NULL );", 0, 0, 0 );
121 121
122 // initialize account name with currency column width 122 // initialize account name with currency column width
123 sqlite_get_table ( db, "select width from columns where id = 10;", &results, &rows, &columns, 0 ); 123 sqlite_get_table ( db, "select width from columns where id = 10;", &results, &rows, &columns, 0 );
124 if ( rows == 0 ) 124 if ( rows == 0 )
125 sqlite_exec ( db, "insert into columns values ( 'accountnamewithcurrency', 100, 0, 0, 0, NULL );", 0, 0, 0 ); 125 sqlite_exec ( db, "insert into columns values ( 'accountnamewithcurrency', 100, 0, 0, 0, NULL );", 0, 0, 0 );
126 126
127 // initialize account currency column width 127 // initialize account currency column width
128 sqlite_get_table ( db, "select width from columns where id = 11;", &results, &rows, &columns, 0 ); 128 sqlite_get_table ( db, "select width from columns where id = 11;", &results, &rows, &columns, 0 );
129 if ( rows == 0 ) 129 if ( rows == 0 )
130 sqlite_exec ( db, "insert into columns values ( 'currencycolumn', 10, 0, 0, 0, NULL );", 0, 0, 0 ); 130 sqlite_exec ( db, "insert into columns values ( 'currencycolumn', 10, 0, 0, 0, NULL );", 0, 0, 0 );
131 131
132 // initialize account balance with currency column width 132 // initialize account balance with currency column width
133 sqlite_get_table ( db, "select width from columns where id = 12;", &results, &rows, &columns, 0 ); 133 sqlite_get_table ( db, "select width from columns where id = 12;", &results, &rows, &columns, 0 );
134 if ( rows == 0 ) 134 if ( rows == 0 )
135 sqlite_exec ( db, "insert into columns values ( 'accountbalancewithcurrency', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 135 sqlite_exec ( db, "insert into columns values ( 'accountbalancewithcurrency', 50, 0, 0, 0, NULL );", 0, 0, 0 );
136 136
137 // initialize budget line item column 137 // initialize budget line item column
138 sqlite_get_table ( db, "select width from columns where id = 13;", &results, &rows, &columns, 0 ); 138 sqlite_get_table ( db, "select width from columns where id = 13;", &results, &rows, &columns, 0 );
139 if ( rows == 0 ) 139 if ( rows == 0 )
140 sqlite_exec ( db, "insert into columns values ( 'budgetlineitem', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 140 sqlite_exec ( db, "insert into columns values ( 'budgetlineitem', 50, 0, 0, 0, NULL );", 0, 0, 0 );
141 141
142 // initialize budget budget column 142 // initialize budget budget column
143 sqlite_get_table ( db, "select width from columns where id = 14;", &results, &rows, &columns, 0 ); 143 sqlite_get_table ( db, "select width from columns where id = 14;", &results, &rows, &columns, 0 );
144 if ( rows == 0 ) 144 if ( rows == 0 )
145 sqlite_exec ( db, "insert into columns values ( 'budgetbudget', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 145 sqlite_exec ( db, "insert into columns values ( 'budgetbudget', 50, 0, 0, 0, NULL );", 0, 0, 0 );
146 146
147 // initialize budget actual column 147 // initialize budget actual column
148 sqlite_get_table ( db, "select width from columns where id = 15;", &results, &rows, &columns, 0 ); 148 sqlite_get_table ( db, "select width from columns where id = 15;", &results, &rows, &columns, 0 );
149 if ( rows == 0 ) 149 if ( rows == 0 )
150 sqlite_exec ( db, "insert into columns values ( 'budgetactual', 50, 0, 0, 0, NULL );", 0, 0, 0 ); 150 sqlite_exec ( db, "insert into columns values ( 'budgetactual', 50, 0, 0, 0, NULL );", 0, 0, 0 );
151 } 151 }
152 152
153void Preferences::changeColumnPreference ( int id, int width ) 153void Preferences::changeColumnPreference ( int id, int width )
154 { 154 {
155 sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id ); 155 sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id );
156 } 156 }
157 157
158int Preferences::getColumnPreference ( int id ) 158int Preferences::getColumnPreference ( int id )
159 { 159 {
160 char **results; 160 char **results;
161 sqlite_get_table_printf ( db, "select width from columns where id = %i;", &results, NULL, NULL, NULL, id ); 161 sqlite_get_table_printf ( db, "select width from columns where id = %i;", &results, NULL, NULL, NULL, id );
162 return atoi ( results [ 1 ] ); 162 return atoi ( results [ 1 ] );
163 } 163 }
164 164
165int Preferences::getPreference ( int id ) 165int Preferences::getPreference ( int id )
166 { 166 {
167 char **results; 167 char **results;
168 sqlite_get_table_printf ( db, "select preference from preferences where id = %i;", &results, NULL, NULL, NULL, id ); 168 sqlite_get_table_printf ( db, "select preference from preferences where id = %i;", &results, NULL, NULL, NULL, id );
169 return atoi ( results [ 1 ] ); 169 return atoi ( results [ 1 ] );
170 } 170 }
171 171
172QString Preferences::getSeparator ( ) 172QString Preferences::getSeparator ( )
173 { 173 {
174 int s = getPreference ( 2 ); 174 int s = getPreference ( 2 );
175 if ( s == 1 ) 175 if ( s == 1 )
176 return "/"; 176 return "/";
177 if ( s ==2 ) 177 if ( s ==2 )
178 return "-"; 178 return "-";
179 else 179 else
180 return "."; 180 return ".";
181 } 181 }
182 182
183void Preferences::changePreference ( int id, int newpreference ) 183void Preferences::changePreference ( int id, int newpreference )
184 { 184 {
185 sqlite_exec_printf ( db, "update preferences set preference = %i where id = %i;", 0, 0, 0, newpreference, id ); 185 sqlite_exec_printf ( db, "update preferences set preference = %i where id = %i;", 0, 0, 0, newpreference, id );
186 } 186 }
187 187
188void Preferences::setDefaultDatePreferences () 188void Preferences::setDefaultDatePreferences ()
189 { 189 {
190 sqlite_exec ( db, "update preferences set preference = 4 where id = 1;", 0, 0, 0 ); 190 sqlite_exec ( db, "update preferences set preference = 4 where id = 1;", 0, 0, 0 );
191 sqlite_exec ( db, "update preferences set preference = 1 where id = 2;", 0, 0, 0 ); 191 sqlite_exec ( db, "update preferences set preference = 1 where id = 2;", 0, 0, 0 );
192 } 192 }
193 193
194QString Preferences::getDate ( int y, int m, int d ) 194QString Preferences::getDate ( int y, int m, int d )
195 { 195 {
196 QString date; 196 QString date;
197 int format = getPreference ( 1 ); 197 int format = getPreference ( 1 );
198 QString separator = getSeparator(); 198 QString separator = getSeparator();
199 199
200 // Convert all date integers to QStrings 200 // Convert all date integers to QStrings
201 QString year = QString::number ( y ); 201 QString year = QString::number ( y );
202 QString month = QString::number ( m ); 202 QString month = QString::number ( m );
203 if ( m < 10 ) 203 if ( m < 10 )
204 month.prepend ( "0" ); 204 month.prepend ( "0" );
205 QString day = QString::number ( d ); 205 QString day = QString::number ( d );
206 if ( d < 10 ) 206 if ( d < 10 )
207 day.prepend ( "0" ); 207 day.prepend ( "0" );
208 208
209 // Truncate four digit year if necessary 209 // Truncate four digit year if necessary
210 if ( format == 2 || format == 4 || format == 6 || format == 8 ) 210 if ( format == 2 || format == 4 || format == 6 || format == 8 )
211 year.remove ( 0, 2 ); 211 year.remove ( 0, 2 );
212 212
213 // Concatenate dates as necessary 213 // Concatenate dates as necessary
214 if ( format == 1 || format == 2 ) 214 if ( format == 1 || format == 2 )
215 { 215 {
216 date = year; 216 date = year;
217 date.append ( separator ); 217 date.append ( separator );
218 date.append ( month ); 218 date.append ( month );
219 date.append ( separator ); 219 date.append ( separator );
220 date.append ( day ); 220 date.append ( day );
221 return date; 221 return date;
222 } 222 }
223 if ( format == 3 || format == 4 ) 223 if ( format == 3 || format == 4 )
224 { 224 {
225 date = month; 225 date = month;
226 date.append ( separator ); 226 date.append ( separator );
227 date.append ( day ); 227 date.append ( day );
228 date.append ( separator ); 228 date.append ( separator );
229 date.append ( year ); 229 date.append ( year );
230 return date; 230 return date;
231 } 231 }
232 if ( format == 5 || format == 6 ) 232 if ( format == 5 || format == 6 )
233 { 233 {
234 date = year; 234 date = year;
235 date.append ( separator ); 235 date.append ( separator );
236 date.append ( day ); 236 date.append ( day );
237 date.append ( separator ); 237 date.append ( separator );
238 date.append ( month ); 238 date.append ( month );
239 return date; 239 return date;
240 } 240 }
241 if ( format == 7 || format == 8 ) 241 if ( format == 7 || format == 8 )
242 { 242 {
243 date = day; 243 date = day;
244 date.append ( separator ); 244 date.append ( separator );
245 date.append ( month ); 245 date.append ( month );
246 date.append ( separator ); 246 date.append ( separator );
247 date.append ( year ); 247 date.append ( year );
248 return date; 248 return date;
249 } 249 }
250 } 250 }
251 251
252QString Preferences::getDate ( int y, int m ) 252QString Preferences::getDate ( int y, int m )
253 { 253 {
254 QString date; 254 QString date;
255 int format = getPreference ( 1 ); 255 int format = getPreference ( 1 );