summaryrefslogtreecommitdiff
path: root/noncore/apps/qashmoney/preferences.cpp
Unidiff
Diffstat (limited to 'noncore/apps/qashmoney/preferences.cpp') (more/less context) (show whitespace changes)
-rwxr-xr-xnoncore/apps/qashmoney/preferences.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/noncore/apps/qashmoney/preferences.cpp b/noncore/apps/qashmoney/preferences.cpp
index 9bf64dd..880807a 100755
--- a/noncore/apps/qashmoney/preferences.cpp
+++ b/noncore/apps/qashmoney/preferences.cpp
@@ -150,6 +150,31 @@ void Preferences::initializeColumnPreferences ()
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::initializeSortingPreferences ()
154 {
155 int rows = 0;
156 int columns = 0;
157 char **results;
158
159 if ( sqlite_get_table ( db, "select count() from sorting;", 0, 0, 0, 0 ) != 0 )
160 sqlite_exec ( db, "create table sorting ( listbox, column, direction, id integer primary key );", 0, 0, 0 );
161
162 // initialize account listbox sorting. Set direction = 1 here so ascending sort is default.
163 sqlite_get_table ( db, "select column, direction from sorting where id = 1;", &results, &rows, &columns, 0 );
164 if ( rows == 0 )
165 sqlite_exec ( db, "insert into sorting values ( 'accounts', 0, 1, NULL );", 0, 0, 0 );
166
167 // initialize transaction listbox sorting
168 sqlite_get_table ( db, "select column, direction from sorting where id = 2;", &results, &rows, &columns, 0);
169 if ( rows == 0 )
170 sqlite_exec ( db, "insert into sorting values ( 'transactions', 0, 1, NULL );", 0, 0, 0 );
171
172 // initialize budgets listbox sorting
173 sqlite_get_table ( db, "select column, direction from sorting where id = 3;", & results, &rows, &columns, 0 );
174 if ( rows == 0 )
175 sqlite_exec ( db, "insert into sorting values ( 'budgets', 0, 1, NULL );", 0, 0, 0 );
176 }
177
153void Preferences::changeColumnPreference ( int id, int width ) 178void Preferences::changeColumnPreference ( int id, int width )
154 { 179 {
155 sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id ); 180 sqlite_exec_printf ( db, "update columns set width = %i where id = %i;", 0, 0, 0, width, id );
@@ -162,6 +187,31 @@ int Preferences::getColumnPreference ( int id )
162 return atoi ( results [ 1 ] ); 187 return atoi ( results [ 1 ] );
163 } 188 }
164 189
190void Preferences::changeSortingPreference ( int id, int column )
191 {
192 int pColumn = 0; // column setting coming from the prefs object
193 int pDirection = 0; // direction setting coming from the prefs object
194
195 // because there appears to be no way to query the QT header object directly for it's current sort settings, we have
196 // to maintain track of them ourselves. So start by pulling the current saved setting for this view.
197 getSortingPreference ( id, &pColumn, &pDirection );
198
199 // if the current saved column == the new column, then the user wants to toggle the sort order.
200 // otherwise we behave like QT does by default, which is to select the new column and default to an ascending sort.
201 if ( column == pColumn )
202 sqlite_exec_printf ( db, "update sorting set direction = %i where id = %i;", 0, 0, 0, !pDirection, id );
203 else
204 sqlite_exec_printf ( db, "update sorting set column = %i, direction = 1 where id = %i;", 0, 0, 0, column, id );
205 }
206
207void Preferences::getSortingPreference ( int id, int *column, int *direction )
208 {
209 char **results;
210 sqlite_get_table_printf ( db, "select column, direction from sorting where id = %i;", &results, NULL, NULL, NULL, id );
211 *column = atoi ( results [ 2 ] );
212 *direction = atoi ( results [ 3 ] );
213 }
214
165int Preferences::getPreference ( int id ) 215int Preferences::getPreference ( int id )
166 { 216 {
167 char **results; 217 char **results;