Summary Files Commits Branches @commit @diff @stats
path: root / bookmarks.c
blob: f43ed465fb8e4daa172e70aaa902cb8bcea3ba41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);
}