diff options
Add completion
1 files changed, 45 insertions, 0 deletions
| -rw-r--r-- | bookmarks.c | 45 |
diff --git a/bookmarks.c b/bookmarks.c new file mode 100644 index 0000000..f43ed46 --- /dev/null +++ b/bookmarks.c @@ -0,0 +1,45 @@ +#include "badwolf.h" +#include "bookmarks.h" + +#include <gtk/gtk.h> +#include <glib/gprintf.h> /* g_fprintf() */ + +void +location_completion_init() +{ + GtkTreeIter iter; + GtkListStore *list_store; + GIOChannel *file_channel; + GError *file_err = NULL; + gchar *file_line; + + location_completion = gtk_entry_completion_new(); + + list_store = gtk_list_store_new(1, G_TYPE_STRING); + + gchar *filename = g_build_filename(g_get_user_data_dir(), "badwolf", "URLs.txt", NULL); + g_fprintf(stderr, "URL Completion: loading at %s\n", filename); + file_channel = g_io_channel_new_file(filename, "r", &file_err); + + if(file_channel != NULL) + { + while(G_IO_STATUS_NORMAL == + g_io_channel_read_line(file_channel, &file_line, NULL, NULL, &file_err)) + { + gtk_list_store_append(list_store, &iter); + gtk_list_store_set(list_store, &iter, 0, g_strchomp(file_line), -1); + } + g_free(file_line); + g_io_channel_unref(file_channel); + //g_io_channel_shutdown(file_channel, FALSE, &file_err); + g_fprintf(stderr, "URL Completion: Done.\n"); + } + else + g_fprintf(stderr, "URL Completion: Failed to load file.\n"); + + gtk_list_store_append(list_store, &iter); + gtk_list_store_set(list_store, &iter, 0, homepage, -1); + + gtk_entry_completion_set_model(location_completion, GTK_TREE_MODEL(list_store)); + gtk_entry_completion_set_text_column(location_completion, 0); +} |