From 3816808cdda6bad1b19c827c99673cf7f3743968 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Mon, 1 Feb 2010 01:51:48 +0100 Subject: [PATCH] Check for empty text; add show_banner() helper function --- src/ui/callbacks.c | 99 ++++++++++++++++++++++++++++++++---------------------- src/ui/callbacks.h | 8 +++++ 2 files changed, 67 insertions(+), 40 deletions(-) diff --git a/src/ui/callbacks.c b/src/ui/callbacks.c index 284c8a1..830cf06 100644 --- a/src/ui/callbacks.c +++ b/src/ui/callbacks.c @@ -476,7 +476,7 @@ void saveDataToNode(MainView * mainview, nodeData *selnode) g_free(sketchdata); if (goterr == TRUE) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Error saving memo")); + show_banner(mainview, _("Error saving memo")); } busy_leave(mainview); } @@ -838,7 +838,7 @@ void callback_treeview_change(GtkTreeSelection * selection, gpointer data) if (goterr == TRUE) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Error loading memo")); + show_banner(mainview, _("Error loading memo")); } } @@ -1152,7 +1152,7 @@ void add_new_node(nodeData * node, MainView * mainview, gboolean ischild) g_free(node); if (path) gtk_tree_path_free(path); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, "Error creating node"); + show_banner(mainview, _("Error creating node")); return; } @@ -1291,7 +1291,7 @@ void callback_file_delete_node(GtkAction * action, gpointer data) g_assert(mainview != NULL && mainview->data != NULL); if (getSelectedNode(mainview) == NULL) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Select a node first")); + show_banner(mainview, _("Select a node first")); return; } @@ -1313,13 +1313,13 @@ void callback_file_rename_node(GtkAction * action, gpointer data) nodeData *sel_node = getSelectedNode(mainview); if (sel_node == NULL) { /* Do nothing, if no node has been selected */ - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Select a node first")); + show_banner(mainview, _("Select a node first")); return; } if (sel_node->namepix != NULL) { /* the memo has a graphical label, cannot edit! */ - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Cannot rename memos with sketch name")); + show_banner(mainview, _("Cannot rename memos with sketch name")); return; } @@ -1398,7 +1398,7 @@ void callback_file_export_node(GtkAction * action, gpointer data) nodeData *nd=getSelectedNode(mainview); if (nd == NULL) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Select a memo first")); + show_banner(mainview, _("Select a memo first")); return; } @@ -1419,7 +1419,7 @@ void callback_file_export_node(GtkAction * action, gpointer data) if (text==NULL || !strcmp(text, "")) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Memo is empty")); + show_banner(mainview, _("Memo is empty")); } else { @@ -1431,14 +1431,14 @@ void callback_file_export_node(GtkAction * action, gpointer data) GnomeVFSFileSize out_bytes; vfs_result = gnome_vfs_create(&handle, fn, GNOME_VFS_OPEN_WRITE, 0, 0600); if ( vfs_result != GNOME_VFS_OK ) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Export failed")); + show_banner(mainview, _("Export failed")); } else { gnome_vfs_write(handle, text, textlen, &out_bytes); gnome_vfs_close(handle); - if (out_bytes==strlen(text)) hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Exported")); - else hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Export incomplete")); + if (out_bytes==strlen(text)) show_banner(mainview, _("Exported")); + else show_banner(mainview, _("Export incomplete")); } g_free(fn); } @@ -1452,7 +1452,7 @@ void callback_file_export_node(GtkAction * action, gpointer data) GdkPixbuf *pixbuf = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE(skpix), NULL, 0, 0, 0, 0, skdr->allocation.width, skdr->allocation.height); if (pixbuf==NULL) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Memo is empty")); + show_banner(mainview, _("Memo is empty")); } else { @@ -1461,11 +1461,11 @@ void callback_file_export_node(GtkAction * action, gpointer data) { if (gdk_pixbuf_save(pixbuf, fn, "png", NULL, NULL)==FALSE) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Export failed")); + show_banner(mainview, _("Export failed")); } else { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Exported")); + show_banner(mainview, _("Exported")); } g_free(fn); } @@ -1474,7 +1474,7 @@ void callback_file_export_node(GtkAction * action, gpointer data) } else if (nd->typ == NODE_CHECKLIST) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Unimplemented")); + show_banner(mainview, _("Export of checklists not possible yet")); } } @@ -2013,10 +2013,10 @@ void callback_edit_cut(GtkAction * action, gpointer data) else if (nd->typ == NODE_SKETCH) { if (sketchwidget_cut(mainview->sk, mainview->clipboard)==FALSE) - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Error cutting")); + show_banner(mainview, _("Error cutting")); } else if (nd->typ == NODE_CHECKLIST) - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Unimplemented")); + show_banner(mainview, _("Unimplemented")); } @@ -2035,7 +2035,7 @@ void callback_edit_copy(GtkAction * action, gpointer data) else if (nd->typ == NODE_SKETCH) { if (sketchwidget_copy(mainview->sk, mainview->clipboard)==FALSE) - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Error copying")); + show_banner(mainview, _("Error copying")); } else if (nd->typ == NODE_CHECKLIST) { @@ -2071,7 +2071,7 @@ void callback_edit_copy(GtkAction * action, gpointer data) g_free(str_data); str_data = g_strdup_printf(_("Copied %d entries"), selected_rows); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, str_data); + show_banner(mainview, str_data); g_free(str_data); } @@ -2092,7 +2092,7 @@ void callback_edit_paste(GtkAction * action, gpointer data) else if (nd->typ == NODE_SKETCH) { if (sketchwidget_paste(mainview->sk, mainview->clipboard)==FALSE) - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Error pasting")); + show_banner(mainview, _("Error pasting")); } else if (nd->typ == NODE_CHECKLIST) { /* Paste string from clipboard as new item */ @@ -2207,7 +2207,7 @@ void callback_file_new(GtkAction * action, gpointer data) rc = sqlite3_open(filename, &mainview->db); if (rc) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Error 1")); + show_banner(mainview, _("Cannot create database")); fprintf(stderr, "Can't create database %s: %s\n", filename, sqlite3_errmsg(mainview->db)); break; } @@ -2223,7 +2223,7 @@ void callback_file_new(GtkAction * action, gpointer data) if (sqlite3_exec(mainview->db, tq, NULL, NULL, NULL) != 0) { fprintf(stderr, "ERROR creating data table\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Error 2")); + show_banner(mainview, _("Error creating data table")); break; } @@ -2231,7 +2231,7 @@ void callback_file_new(GtkAction * action, gpointer data) if (sqlite3_exec(mainview->db, tq, NULL, NULL, NULL) != 0) { fprintf(stderr, "ERROR creating checklist table\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Error 3")); + show_banner(mainview, _("Error creating checklist table")); break; } @@ -2953,7 +2953,7 @@ gboolean key_press_cb(GtkWidget * widget, GdkEventKey * event, MainView * mainvi nodeData *selnode = getSelectedNode(mainview); if (selnode!=NULL && selnode->typ==NODE_SKETCH) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Squared shapes ON")); + show_banner(mainview, _("Squared shapes ON")); sketchwidget_set_shift(mainview->sk, TRUE); return TRUE; } @@ -2964,7 +2964,7 @@ gboolean key_press_cb(GtkWidget * widget, GdkEventKey * event, MainView * mainvi nodeData *selnode = getSelectedNode(mainview); if (selnode!=NULL && selnode->typ==NODE_SKETCH) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Squared shapes OFF")); + show_banner(mainview, _("Squared shapes OFF")); sketchwidget_set_shift(mainview->sk, FALSE); return TRUE; } @@ -2975,7 +2975,7 @@ gboolean key_press_cb(GtkWidget * widget, GdkEventKey * event, MainView * mainvi nodeData *selnode = getSelectedNode(mainview); if (selnode!=NULL && selnode->typ==NODE_SKETCH) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Filled shapes OFF")); + show_banner(mainview, _("Filled shapes OFF")); sketchwidget_set_fillmode(mainview->sk, FALSE); return TRUE; } @@ -2986,7 +2986,7 @@ gboolean key_press_cb(GtkWidget * widget, GdkEventKey * event, MainView * mainvi nodeData *selnode = getSelectedNode(mainview); if (selnode!=NULL && selnode->typ==NODE_SKETCH) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Filled shapes ON")); + show_banner(mainview, _("Filled shapes ON")); sketchwidget_set_fillmode(mainview->sk, TRUE); return TRUE; } @@ -3044,7 +3044,7 @@ void hw_event_handler(osso_hw_state_t * state, gpointer data) if (state->save_unsaved_data_ind) { fprintf(stderr, "Saving unsaved data!\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, "Saving unsaved data!"); + show_banner(mainview, _("Saving unsaved data")); callback_file_save(NULL, mainview); } @@ -3537,7 +3537,7 @@ void write_buffer_to_file(MainView * mainview) if (sqlite3_exec(mainview->db, tq, NULL, NULL, NULL) != 0) { fprintf(stderr, "ERROR creating backup table!\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, "Error 1"); + show_banner(mainview, _("Error creating backup table")); busy_leave(mainview); return; @@ -3546,7 +3546,7 @@ void write_buffer_to_file(MainView * mainview) if (sqlite3_exec(mainview->db, tq, NULL, NULL, NULL) != 0) { fprintf(stderr, "ERROR backing up table!\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, "Error 2"); + show_banner(mainview, _("Error creating backup table")); busy_leave(mainview); return; @@ -3558,7 +3558,7 @@ void write_buffer_to_file(MainView * mainview) if (sqlite3_exec(mainview->db, tq, NULL, NULL, NULL) != 0) { fprintf(stderr, "ERROR saving table!\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, "Error 3"); + show_banner(mainview, _("Error saving table")); g_snprintf(tq, sizeof(tq), "DELETE FROM %s", datatable_name); sqlite3_exec(mainview->db, tq, NULL, NULL, NULL); @@ -3583,7 +3583,7 @@ void write_buffer_to_file(MainView * mainview) if (sqlite3_exec(mainview->db, tq, NULL, NULL, NULL) != 0) { fprintf(stderr, "ERROR creating backup table! (checklist)\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, "Error 4"); + show_banner(mainview, _("Error creating checklist backup table")); busy_leave(mainview); return; @@ -3593,7 +3593,7 @@ void write_buffer_to_file(MainView * mainview) if (sqlite3_exec(mainview->db, tq, NULL, NULL, NULL) != 0) { fprintf(stderr, "ERROR backing up table! (checklist)\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, "Error 5"); + show_banner(mainview, _("Error creating checklist backup table")); busy_leave(mainview); return; @@ -3605,7 +3605,7 @@ void write_buffer_to_file(MainView * mainview) if (sqlite3_exec(mainview->db, tq, NULL, NULL, NULL) != 0) { fprintf(stderr, "ERROR saving table! (checklist)\n"); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, "Error 6"); + show_banner(mainview, _("Error saving checklist table")); g_snprintf(tq, sizeof(tq), "DELETE FROM %s", checklisttable_name); sqlite3_exec(mainview->db, tq, NULL, NULL, NULL); @@ -3624,7 +3624,7 @@ void write_buffer_to_file(MainView * mainview) mainview->file_edited = FALSE; busy_leave(mainview); - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), GTK_STOCK_SAVE, _("Changes saved")); + show_banner(mainview, _("Changes saved")); } void callback_checklist_change(GtkTreeSelection *selection, MainView *mainview) @@ -3733,7 +3733,7 @@ void callback_checklist_edit(GtkAction *action, MainView *mainview) GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview->listview)); if (gtk_tree_selection_count_selected_rows(selection) == 0) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Select items first")); + show_banner(mainview, _("Select items first")); return; } @@ -3762,7 +3762,7 @@ void callback_checklist_delete(GtkAction *action, MainView *mainview) g_assert(mainview != NULL && mainview->data != NULL); if (gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(mainview->listview)))==0) { - hildon_banner_show_information(GTK_WIDGET(mainview->data->main_view), NULL, _("Select items first")); + show_banner(mainview, _("Select items first")); return; } @@ -3818,7 +3818,8 @@ g_object_unref(model); } /* Ask the user for confirmation of a specific action */ -gboolean show_confirmation(MainView* mainview, gchar* question) +gboolean +show_confirmation(MainView* mainview, gchar* question) { GtkDialog* dialog = GTK_DIALOG(hildon_note_new_confirmation( GTK_WINDOW(mainview->data->main_view), question)); @@ -3830,6 +3831,12 @@ gboolean show_confirmation(MainView* mainview, gchar* question) return (response == GTK_RESPONSE_OK); } +/* Show a information banner to the user (non-modal) */ +void +show_banner(MainView* mainview, const gchar* text) +{ + hildon_banner_show_information(GTK_WIDGET(mainview_get_dialog_parent(mainview)), NULL, text); +} /* Let the user enter or edit a line of text */ gchar* @@ -3863,8 +3870,20 @@ show_line_edit_dialog(MainView* mainview, const gchar* title, const gchar* label gtk_widget_show_all(GTK_WIDGET(hbox)); - if (gtk_dialog_run(GTK_DIALOG(edit_dialog)) == GTK_RESPONSE_OK) { - result = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); + while (TRUE) { + if (gtk_dialog_run(GTK_DIALOG(edit_dialog)) == GTK_RESPONSE_OK) { + result = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); + if (strcmp(result, "") != 0) { + break; + } else { + show_banner(mainview, _("Please enter a non-empty text")); + g_free(result); + result = NULL; + } + } else { + result = NULL; + break; + } } gtk_widget_destroy(GTK_WIDGET(edit_dialog)); diff --git a/src/ui/callbacks.h b/src/ui/callbacks.h index 7d9970c..dabb5f7 100644 --- a/src/ui/callbacks.h +++ b/src/ui/callbacks.h @@ -133,6 +133,13 @@ void callback_buffer_modified(GtkAction * action, gpointer data); void hw_event_handler(osso_hw_state_t * state, gpointer data); +/* UI helper functions needed in callbacks */ +gboolean +show_confirmation(MainView* mainview, gchar* question); + +void +show_banner(MainView* mainview, const gchar* text); + gchar* show_line_edit_dialog(MainView* mainview, const gchar* title, @@ -140,4 +147,5 @@ show_line_edit_dialog(MainView* mainview, const gchar* action, const gchar* text); + #endif -- 2.11.4.GIT