Changeset 61

Show
Ignore:
Timestamp:
10/08/07 20:54:56 (11 months ago)
Author:
cmccurdy
Message:

* src/database.c:

fixed account retrievals to only get un-purged accounts

* src/widgets.c:

changed function check_account_list to account_list_empty
added function launch_new_account_dialog
changed remove_account_from_combo to automatically select another account so we aren't left with a NULL account selected

* src/account_dialog.c:

incorporated fixes to notify the user if an account name is already in use
disallow the window to be closed if there are no accounts that are active

* src/main.c:

changed the calling of check_account_list to account_list_empty & launch_new_account_dialog

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/account_dialog.c

    r60 r61  
    135135{ 
    136136    GtkWidget *dialog = account_dialog_new(GTK_WINDOW(data)); 
    137     if ( gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT ) 
    138     { 
    139         char *name = (char *)gtk_entry_get_text(GTK_ENTRY(name_entry)); 
     137 
     138    bool keep_going = true; 
     139    while ( keep_going ) 
     140    { 
     141        // break if the window closes or cancel is pressed 
     142        if ( gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT ) 
     143        { 
     144            gtk_widget_hide(dialog); 
     145            if ( !account_list_empty() ) 
     146            { 
     147                gtk_widget_destroy(dialog); 
     148                keep_going = false; 
     149            } 
     150            continue; 
     151        } 
     152     
     153        const char *name = (char *)gtk_entry_get_text(GTK_ENTRY(name_entry)); 
    140154        if ( strlen(name) < 1 ) 
    141155        { 
    142             gtk_widget_destroy(dialog); 
    143             return; 
     156            if ( !account_list_empty() ) 
     157            { 
     158                gtk_widget_destroy(dialog); 
     159                keep_going = false; 
     160            } 
     161            continue; 
    144162        } 
    145163        double bal = (double)atof(gtk_entry_get_text(GTK_ENTRY(balance_entry))); 
     
    148166        if ( id == -1 ) 
    149167        { 
    150             gtk_widget_destroy(dialog); 
    151             check_account_list(); 
    152             return; 
     168            char a_name[101]; 
     169            strcpy( a_name, name ); 
     170            double a_bal; 
     171            int a_id; 
     172            get_account_by_name( a_name, &a_id, &a_bal ); 
     173            if ( &a_id == NULL ) 
     174            { 
     175                GtkWidget *error = gtk_message_dialog_new( GTK_WINDOW(dialog), 
     176                        GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,  
     177                        GTK_BUTTONS_CLOSE, "Unknown error creating account" ); 
     178                gtk_dialog_run( GTK_DIALOG(error) ); 
     179                gtk_widget_destroy(error); 
     180                keep_going = false; 
     181                gtk_widget_destroy(dialog); 
     182                if ( account_list_empty() ) 
     183                    launch_new_account_dialog(); 
     184            } 
     185            else 
     186            { 
     187                GtkWidget *error = gtk_message_dialog_new( GTK_WINDOW(dialog), 
     188                        GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, 
     189                        GTK_BUTTONS_CLOSE, "An account with the name '%s' already \ 
     190exists. Please use a different name.", name ); 
     191                gtk_dialog_run( GTK_DIALOG(error) ); 
     192                gtk_widget_destroy(error); 
     193                continue; 
     194            } 
    153195        } 
    154196 
    155197        add_account_to_combo(id); 
    156     } 
    157      
    158     gtk_widget_destroy(dialog); 
    159  
    160     check_account_list(); 
     198        keep_going = false; 
     199        gtk_widget_destroy(dialog); 
     200    } 
    161201} 
    162202 
     
    199239    gtk_widget_destroy(dialog); 
    200240 
    201     check_account_list(); 
    202 
    203  
     241    if ( account_list_empty() ) 
     242        launch_new_account_dialog(); 
     243
     244 
  • trunk/src/database.c

    r56 r61  
    425425    sqlite3_stmt *stmt; 
    426426 
    427     char *query = sqlite3_mprintf( "select name from accounts order by id asc" ); 
     427    char *query = sqlite3_mprintf( "select name from accounts where purged = 0 \ 
     428            order by id asc" ); 
    428429    if ( sqlite3_prepare_v2( db, query, -1, &stmt, NULL ) ) 
    429430    { 
     
    460461    sqlite3_stmt *stmt; 
    461462 
    462     char *query = sqlite3_mprintf( "select id from accounts order by id asc" ); 
     463    char *query = sqlite3_mprintf( "select id from accounts where purged = 0 \ 
     464            order by id asc" ); 
    463465    if ( sqlite3_prepare_v2( db, query, -1, &stmt, NULL ) ) 
    464466    { 
  • trunk/src/main.c

    r60 r61  
    8787    gtk_widget_show(vbox); 
    8888    gtk_widget_show(window); 
    89     check_account_list(); 
     89    if ( account_list_empty() ) 
     90        launch_new_account_dialog(); 
    9091 
    9192    gtk_main(); 
  • trunk/src/widgets.c

    r60 r61  
    802802} 
    803803 
    804 void check_account_list() 
     804bool account_list_empty() 
    805805{ 
    806806    GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(account_combo)); 
    807807    GtkTreeIter iter; 
    808808 
    809     if ( !gtk_tree_model_get_iter_first( model, &iter ) ) 
    810     { 
    811         GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(tree))); 
    812         account_dialog_new_cb( NULL, window ); 
    813     } 
     809    return !gtk_tree_model_get_iter_first( model, &iter ); 
     810
     811 
     812void launch_new_account_dialog() 
     813
     814    GtkWindow *window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(tree))); 
     815    account_dialog_new_cb( NULL, window ); 
    814816} 
    815817 
     
    908910        if ( cur_id == id ) 
    909911        { 
    910             gtk_list_store_remove( GTK_LIST_STORE(model), &iter ); 
    911             model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER( 
    912                         gtk_tree_view_get_model(GTK_TREE_VIEW(tree)))); 
    913             gtk_list_store_clear(GTK_LIST_STORE(model)); 
     912            if ( !gtk_list_store_remove( GTK_LIST_STORE(model), &iter ) ) 
     913                gtk_tree_model_get_iter_first( model, &iter ); 
     914            gtk_combo_box_set_active_iter( GTK_COMBO_BOX(account_combo), &iter ); 
     915            GtkTreeModel *list = gtk_tree_model_filter_get_model( 
     916                        GTK_TREE_MODEL_FILTER(gtk_tree_view_get_model( 
     917                                GTK_TREE_VIEW(tree)))); 
     918            gtk_list_store_clear(GTK_LIST_STORE(list)); 
     919 
    914920            return; 
    915921        } 
  • trunk/src/widgets.h

    r60 r61  
    1111void refilter_tree(GtkEditable*, gpointer); 
    1212 
    13 void check_account_list(); 
     13bool account_list_empty(); 
     14void launch_new_account_dialog(); 
    1415void load_account_list(); 
    1516void add_account_to_combo(int);