Skip to content

Commit

Permalink
Enabling completion of favourites.
Browse files Browse the repository at this point in the history
Also, minor fixes in loading new-style favourites.
  • Loading branch information
msdemlei committed Apr 18, 2015
1 parent 0616dd6 commit 9def345
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
18 changes: 10 additions & 8 deletions about.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ remove_favorite(struct tab *t, int index)
if (save_pagelist_to_disk(&favs, XT_FAVS_FILE)) {
update_favorite_tabs(NULL);
}

/* TODO: We should remove the URI from the list of completions here,
too */
}

int
Expand Down Expand Up @@ -629,6 +630,7 @@ add_favorite(struct tab *t, struct karg *args)
title = argtitle ? argtitle : get_title(t, FALSE);
uri = get_uri(t);
insert_pagelist_entry(&favs, uri, title, 0);
completion_add_uri(uri);

if ((retval = save_pagelist_to_disk(&favs, XT_FAVS_FILE))) {

Expand Down Expand Up @@ -683,7 +685,8 @@ to the new standard pagelist format.
int
restore_favorites(void)
{
char file[PATH_MAX], magic[5];
int retval;
char file[PATH_MAX], magic[4];
FILE *f;

empty_pagelist(&favs);
Expand All @@ -696,25 +699,24 @@ restore_favorites(void)
return (1);
}

magic[4] = 0;
if (4==fread(magic, 1, 4, f)
&& strcmp(magic, "http")) {
&& strncmp(magic, "http", 4)) {
/* doesn't start with http, try old-style favorite parsing */
int retval;

warnx("Warning: Suspecting old-style favorites file.");
rewind(f);
retval = load_legacy_favorites(f);
fclose(f);
return retval;

} else {
/* TODO: when we can reasonably assume all favourites files
are updated, remove everything in here but this: */
are updated, remove everything in here but this: */
/* file seems to start with URL, use new-style code */
fclose(f);
return load_pagelist_from_disk(&favs, XT_FAVS_FILE);
retval = load_pagelist_from_disk(&favs, XT_FAVS_FILE);
}

return retval;
}


Expand Down
26 changes: 23 additions & 3 deletions xombrero.c
Original file line number Diff line number Diff line change
Expand Up @@ -6177,6 +6177,21 @@ cmd_getlist(int id, char *key)

if (id >= 0) {
if (cmds[id].type & XT_URLARG) {
/* It'd be great if we could use the
completion_model here. Alas, GtkTreeModel apparently
has no API to access the char * in there; it seems
you only can get copies from there, which would
then have to be freed by the calling function.
Hence, we manually to through history and favourites
for now. */

RB_FOREACH_REVERSE(h, pagelist, &favs)
if (match_uri(h->uri, key)) {
cmd_status.list[c] = (char *)h->uri;
if (++c > 255)
break;
}

RB_FOREACH_REVERSE(h, pagelist, &hl)
if (match_uri(h->uri, key)) {
cmd_status.list[c] = (char *)h->uri;
Expand Down Expand Up @@ -8860,9 +8875,6 @@ main(int argc, char **argv)
if (enable_strict_transport)
strict_transport_init();

/* pull favorites into memory */
restore_favorites();

/* uri completion */
completion_model = gtk_list_store_new(1, G_TYPE_STRING);

Expand All @@ -8879,6 +8891,14 @@ main(int argc, char **argv)
if (save_global_history)
restore_global_history();

/* pull favorites into memory */
if (!restore_favorites()) {
struct pagelist_entry *item;
RB_FOREACH(item, pagelist, &favs) {
completion_add_uri(item->uri);
}
}

/* restore session list */
restore_sessions_list();

Expand Down

0 comments on commit 9def345

Please sign in to comment.